package ip
import "github.com/containernetworking/plugins/pkg/ip"
Index ¶
- Constants
- Variables
- func AddDefaultRoute(gw net.IP, dev netlink.Link) error
- func AddHostRoute(ipn *net.IPNet, gw net.IP, dev netlink.Link) error
- func AddRoute(ipn *net.IPNet, gw net.IP, dev netlink.Link) error
- func Cmp(a, b net.IP) int
- func DelLinkByName(ifName string) error
- func DelLinkByNameAddr(ifName string) ([]*net.IPNet, error)
- func EnableForward(ips []*current.IPConfig) error
- func EnableIP4Forward() error
- func EnableIP6Forward() error
- func GCIPMasqForNetwork(network string, attachments []types.GCAttachment) error
- func GetVethPeerIfindex(ifName string) (netlink.Link, int, error)
- func IsIPNetZero(ipnet *net.IPNet) bool
- func Network(ipn *net.IPNet) *net.IPNet
- func NextIP(ip net.IP) net.IP
- func PrevIP(ip net.IP) net.IP
- func RandomVethName() (string, error)
- func RenameLink(curName, newName string) error
- func SettleAddresses(ifName string, timeout time.Duration) error
- func SetupIPMasq(ipn *net.IPNet, chain string, comment string) error
- func SetupIPMasqForNetworks(backend *string, ipns []*net.IPNet, network, ifname, containerID string) error
- func SetupVeth(contVethName string, mtu int, contVethMac string, hostNS ns.NetNS) (net.Interface, net.Interface, error)
- func SetupVethWithName(contVethName, hostVethName string, mtu int, contVethMac string, hostNS ns.NetNS) (net.Interface, net.Interface, error)
- func TeardownIPMasq(ipn *net.IPNet, chain string, comment string) error
- func TeardownIPMasqForNetworks(ipns []*net.IPNet, network, ifname, containerID string) error
- func ValidateExpectedInterfaceIPs(ifName string, resultIPs []*current.IPConfig) error
- func ValidateExpectedRoute(resultRoutes []*types.Route) error
- type IP
Constants ¶
const SETTLE_INTERVAL = 50 * time.Millisecond
Variables ¶
Functions ¶
func AddDefaultRoute ¶
AddDefaultRoute sets the default route on the given gateway.
func AddHostRoute ¶
AddHostRoute adds a host-scoped route to a device.
func AddRoute ¶
AddRoute adds a universally-scoped route to a device.
func Cmp ¶
Cmp compares two IPs, returning the usual ordering: a < b : -1 a == b : 0 a > b : 1 incomparable : -2
func DelLinkByName ¶
DelLinkByName removes an interface link.
func DelLinkByNameAddr ¶
DelLinkByNameAddr remove an interface and returns its addresses
func EnableForward ¶
EnableForward will enable forwarding for all configured address families
func EnableIP4Forward ¶
func EnableIP4Forward() error
func EnableIP6Forward ¶
func EnableIP6Forward() error
func GCIPMasqForNetwork ¶
func GCIPMasqForNetwork(network string, attachments []types.GCAttachment) error
GCIPMasqForNetwork garbage collects stale IPMasq entries for network
func GetVethPeerIfindex ¶
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 IsIPNetZero ¶
IsIPNetZero check if the IPNet is "0.0.0.0/0" or "::/0" This is needed as go-netlink replaces nil Dst with a '0' IPNet since https://github.com/vishvananda/netlink/commit/acdc658b8613655ddb69f978e9fb4cf413e2b830
func Network ¶
Network masks off the host portion of the IP, if IPNet is invalid, return nil
func NextIP ¶
NextIP returns IP incremented by 1, if IP is invalid, return nil
func PrevIP ¶
PrevIP returns IP decremented by 1, if IP is invalid, return nil
func RandomVethName ¶
RandomVethName returns string "veth" with random prefix (hashed from entropy)
func RenameLink ¶
func SettleAddresses ¶
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 ¶
SetupIPMasq installs iptables rules to masquerade traffic coming from ip of ipn and going outside of ipn. Deprecated: This function only supports iptables. Use SetupIPMasqForNetworks, which supports both iptables and nftables.
func SetupIPMasqForNetworks ¶
func SetupIPMasqForNetworks(backend *string, ipns []*net.IPNet, network, ifname, containerID string) error
SetupIPMasqForNetworks installs rules to masquerade traffic coming from ips of ipns and going outside of ipns, using a chain name based on network, ifname, and containerID. The backend can be either "iptables" or "nftables"; if it is nil, then a suitable default implementation will be used.
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 ¶
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 ¶
TeardownIPMasq undoes the effects of SetupIPMasq. Deprecated: This function only supports iptables. Use TeardownIPMasqForNetworks, which supports both iptables and nftables.
func TeardownIPMasqForNetworks ¶
TeardownIPMasqForNetworks undoes the effects of SetupIPMasqForNetworks
func ValidateExpectedInterfaceIPs ¶
func ValidateExpectedRoute ¶
Types ¶
type IP ¶
IP is a CNI maintained type inherited from net.IPNet which can represent a single IP address with or without prefix.
func ParseIP ¶
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 ¶
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 ¶
String returns the string form of this IP.
func (*IP) ToIP ¶
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 ¶
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.
Source Files ¶
addr_linux.go cidr.go ip.go ipforward_linux.go ipmasq_iptables_linux.go ipmasq_linux.go ipmasq_nftables_linux.go link_linux.go route_linux.go utils_linux.go
- Version
- v1.7.1 (latest)
- Published
- Apr 25, 2025
- Platform
- linux/amd64
- Imports
- 21 packages
- Last checked
- 9 hours ago –
Tools for package owners.