ip

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 17 Imported by: 303

Documentation

Index

Constants

View Source
const SETTLE_INTERVAL = 50 * time.Millisecond

Variables

View Source
var (
	ErrLinkNotFound = errors.New("link not found")
)

Functions

func AddDefaultRoute

func AddDefaultRoute(gw net.IP, dev netlink.Link) error

AddDefaultRoute sets the default route on the given gateway.

func AddHostRoute

func AddHostRoute(ipn *net.IPNet, gw net.IP, dev netlink.Link) error

AddHostRoute adds a host-scoped route to a device.

func AddRoute

func AddRoute(ipn *net.IPNet, gw net.IP, dev netlink.Link) error

AddRoute adds a universally-scoped route to a device.

func Cmp added in v0.6.0

func Cmp(a, b net.IP) int

Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1 incomparable : -2

func DelLinkByName

func DelLinkByName(ifName string) error

DelLinkByName removes an interface link.

func DelLinkByNameAddr

func DelLinkByNameAddr(ifName string) ([]*net.IPNet, error)

DelLinkByNameAddr remove an interface and returns its addresses

func EnableForward added in v0.6.0

func EnableForward(ips []*current.IPConfig) error

EnableForward will enable forwarding for all configured address families

func EnableIP4Forward

func EnableIP4Forward() error

func EnableIP6Forward

func EnableIP6Forward() error

func GetVethPeerIfindex added in v0.8.0

func GetVethPeerIfindex(ifName string) (netlink.Link, int, error)

GetVethPeerIfindex returns the veth link object, the peer ifindex of the veth, or an error. This peer ifindex will only be valid in the peer's network namespace.

func Network

func Network(ipn *net.IPNet) *net.IPNet

Network masks off the host portion of the IP, if IPNet is invalid, return nil

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns IP incremented by 1, if IP is invalid, return nil

func PrevIP

func PrevIP(ip net.IP) net.IP

PrevIP returns IP decremented by 1, if IP is invalid, return nil

func RandomVethName

func RandomVethName() (string, error)

RandomVethName returns string "veth" with random prefix (hashed from entropy)

func RenameLink(curName, newName string) error

func SettleAddresses added in v0.6.0

func SettleAddresses(ifName string, timeout int) error

SettleAddresses waits for all addresses on a link to leave tentative state. This is particularly useful for ipv6, where all addresses need to do DAD. There is no easy way to wait for this as an event, so just loop until the addresses are no longer tentative. If any addresses are still tentative after timeout seconds, then error.

func SetupIPMasq

func SetupIPMasq(ipn *net.IPNet, chain string, comment string) error

SetupIPMasq installs iptables rules to masquerade traffic coming from ip of ipn and going outside of ipn

func SetupVeth

func SetupVeth(contVethName string, mtu int, contVethMac string, hostNS ns.NetNS) (net.Interface, net.Interface, error)

SetupVeth sets up a pair of virtual ethernet devices. Call SetupVeth from inside the container netns. It will create both veth devices and move the host-side veth into the provided hostNS namespace. On success, SetupVeth returns (hostVeth, containerVeth, nil)

func SetupVethWithName added in v0.8.2

func SetupVethWithName(contVethName, hostVethName string, mtu int, contVethMac string, hostNS ns.NetNS) (net.Interface, net.Interface, error)

SetupVethWithName sets up a pair of virtual ethernet devices. Call SetupVethWithName from inside the container netns. It will create both veth devices and move the host-side veth into the provided hostNS namespace. hostVethName: If hostVethName is not specified, the host-side veth name will use a random string. On success, SetupVethWithName returns (hostVeth, containerVeth, nil)

func TeardownIPMasq

func TeardownIPMasq(ipn *net.IPNet, chain string, comment string) error

TeardownIPMasq undoes the effects of SetupIPMasq

func ValidateExpectedInterfaceIPs added in v0.8.0

func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig) error

func ValidateExpectedRoute added in v0.8.0

func ValidateExpectedRoute(resultRoutes []*types.Route) error

Types

type IP added in v1.0.0

type IP struct {
	net.IPNet
}

IP is a CNI maintained type inherited from net.IPNet which can represent a single IP address with or without prefix.

func ParseIP added in v1.0.0

func ParseIP(s string) *IP

ParseIP will parse string s as an IP, and return it. The string s must be formed like <ip>[/<prefix>]. If s is not a valid textual representation of an IP, will return nil.

func (*IP) MarshalText added in v1.0.0

func (i *IP) MarshalText() ([]byte, error)

MarshalText implements the encoding.TextMarshaler interface. The encoding is the same as returned by String, But when len(ip) is zero, will return an empty slice.

func (*IP) String added in v1.0.0

func (i *IP) String() string

String returns the string form of this IP.

func (*IP) ToIP added in v1.0.0

func (i *IP) ToIP() net.IP

ToIP will return a net.IP in standard form from this IP. If this IP can not be converted to a valid net.IP, will return nil.

func (*IP) UnmarshalText added in v1.0.0

func (i *IP) UnmarshalText(b []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface. The textual bytes are expected in a form accepted by Parse, But when len(b) is zero, will return an empty IP.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL