v1.4.0 Latest Latest

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 17 Imported by: 0



Package util contains utility functions which are used in the agent implementation.



View Source
const (
	FamilyIPv4 uint8 = 4
	FamilyIPv6 uint8 = 6
View Source
const (
	ContainerVNICPrefix = "vEthernet"
	HNSNetworkType      = "Transparent"
	LocalHNSNetwork     = "antrea-hnsnetwork"
	OVSExtensionID      = "583CC151-73EC-4A6A-8B47-578297AD7623"

	MetricDefault = 256
	MetricHigh    = 50


This section is empty.


func AddNetNatStaticMapping added in v1.4.0

func AddNetNatStaticMapping(netNatName string, externalIPAddr string, externalPort uint16, internalIPAddr string, internalPort uint16, proto string) error

AddNetNatStaticMapping adds a static mapping to a NAT instance.

func ConfigureInterfaceAddress

func ConfigureInterfaceAddress(ifaceName string, ipConfig *net.IPNet) error

ConfigureInterfaceAddress adds IPAddress on the specified interface.

func ConfigureInterfaceAddressWithDefaultGateway

func ConfigureInterfaceAddressWithDefaultGateway(ifaceName string, ipConfig *net.IPNet, gateway string) error

ConfigureInterfaceAddressWithDefaultGateway adds IPAddress on the specified interface and sets the default gateway for the host.

func ConfigureLinkAddresses

func ConfigureLinkAddresses(idx int, ipNets []*net.IPNet) error

ConfigureLinkAddresses adds the provided addresses to the interface identified by index idx, if they are missing from the interface. Any other existing address already configured for the interface will be removed, unless it is a link-local address. At the moment, this function only supports IPv4 addresses and will ignore any address in ipNets that is not IPv4.

func CreateHNSNetwork

func CreateHNSNetwork(hnsNetName string, subnetCIDR *net.IPNet, nodeIP *net.IPNet, adapter *net.Interface) (*hcsshim.HNSNetwork, error)

CreateHNSNetwork creates a new HNS Network, whose type is "Transparent". The NetworkAdapter is using the host interface which is configured with Node IP. HNS Network properties "ManagementIP" and "SourceMac" are used to record the original IP and MAC addresses on the network adapter.

func DeleteHNSNetwork

func DeleteHNSNetwork(hnsNetName string) error

func DialLocalSocket

func DialLocalSocket(address string) (net.Conn, error)

DialLocalSocket connects to a Unix domain socket or a Windows named pipe. - If the specified address starts with "\\.\pipe\", connect to a Windows named pipe path. - Else connect to a Unix domain socket.

func EnableHNSNetworkExtension

func EnableHNSNetworkExtension(hnsNetID string, vSwitchExtension string) error

EnableHNSNetworkExtension enables the specified vSwitchExtension on the target HNS Network. Antrea calls this function to enable OVS Extension on the HNS Network.

func EnableHostInterface

func EnableHostInterface(ifaceName string) error

EnableHostInterface sets the specified interface status as UP.

func EnableIPForwarding

func EnableIPForwarding(ifaceName string) error

EnableIPForwarding enables the IP interface to forward packets that arrive on this interface to other interfaces.

func EnableRSCOnVSwitch

func EnableRSCOnVSwitch(vSwitch string) error

EnableRSCOnVSwitch enables RSC in the vSwitch to reduce host CPU utilization and increase throughput for virtual workloads by coalescing multiple TCP segments into fewer, but larger segments.

func ExtendCIDRWithIP added in v1.4.0

func ExtendCIDRWithIP(ipNet *net.IPNet, ip net.IP) (*net.IPNet, error)

ExtendCIDRWithIP is used for extending an IPNet with an IP.

func GenerateContainerInterfaceKey

func GenerateContainerInterfaceKey(containerID string) string

GenerateContainerInterfaceKey generates a unique string for a Pod's interface as: container/<Container-ID>. We must use ContainerID instead of PodNamespace + PodName because there could be more than one container associated with the same Pod at some point. For example, when deleting a StatefulSet Pod with 0 second grace period, the Pod will be removed from the Kubernetes API very quickly and a new Pod will be created immediately, and kubelet may process the deletion of the previous Pod and the addition of the new Pod simultaneously.

func GenerateContainerInterfaceName

func GenerateContainerInterfaceName(podName, podNamespace, containerID string) string

GenerateContainerInterfaceName generates a unique interface name using the Pod's namespace, name and containerID. The output should be deterministic (so that multiple calls to GenerateContainerInterfaceName with the same parameters return the same value). The output has the length of interfaceNameLength(15). The probability of collision should be neglectable.

func GenerateNodeTunnelInterfaceKey

func GenerateNodeTunnelInterfaceKey(nodeName string) string

GenerateNodeTunnelInterfaceKey generates a unique string for a Node's tunnel interface as: node/<Node-name>.

func GenerateNodeTunnelInterfaceName

func GenerateNodeTunnelInterfaceName(nodeName string) string

GenerateNodeTunnelInterfaceName generates a unique interface name for the tunnel to the Node, using the Node's name.

func GetAllNodeAddresses added in v1.4.0

func GetAllNodeAddresses(excludeDevices []string) ([]net.IP, []net.IP, error)

GetAllNodeAddresses gets all Node IP addresses (not including IPv6 link local address).

func GetDNServersByInterfaceIndex

func GetDNServersByInterfaceIndex(ifIndex int) (string, error)

GetDNServersByInterfaceIndex returns the DNS servers configured on the specified interface.

func GetDefaultGatewayByInterfaceIndex

func GetDefaultGatewayByInterfaceIndex(ifIndex int) (string, error)

GetDefaultGatewayByInterfaceIndex returns the default gateway configured on the specified interface.

func GetHostInterfaceStatus

func GetHostInterfaceStatus(ifaceName string) (string, error)

func GetIPNetDeviceByCIDRs added in v1.4.0

func GetIPNetDeviceByCIDRs(cidrsList []string) (v4IPNet, v6IPNet *net.IPNet, link *net.Interface, err error)

func GetIPNetDeviceByName added in v1.2.4

func GetIPNetDeviceByName(ifaceName string) (v4IPNet *net.IPNet, v6IPNet *net.IPNet, link *net.Interface, err error)

func GetIPNetDeviceFromIP

func GetIPNetDeviceFromIP(localIPs *ip.DualStackIPs) (v4IPNet *net.IPNet, v6IPNet *net.IPNet, iface *net.Interface, err error)

GetIPNetDeviceFromIP returns local IPs/masks and associated device from IP.

func GetIPWithFamily

func GetIPWithFamily(ips []net.IP, addrFamily uint8) (net.IP, error)

func GetIPv4Addr

func GetIPv4Addr(ips []net.IP) net.IP

func GetNSPath

func GetNSPath(containerNetNS string) (string, error)

func GetNetNatStaticMapping added in v1.4.0

func GetNetNatStaticMapping(netNatName string, externalIPAddr string, externalPort uint16, proto string) (string, error)

GetNetNatStaticMapping checks if a NetNatStaticMapping exists.

func HostInterfaceExists

func HostInterfaceExists(ifaceName string) bool

func IsVirtualAdapter added in v1.2.0

func IsVirtualAdapter(name string) (bool, error)

IsVirtualAdapter checks if the provided adapter is virtual.

func ListenLocalSocket

func ListenLocalSocket(address string) (net.Listener, error)

ListenLocalSocket creates a listener on a Unix domain socket or a Windows named pipe. - If the specified address starts with "\\.\pipe\", create a listener on the a Windows named pipe path. - Else create a listener on a local Unix domain socket.

func NewIPNet added in v1.4.0

func NewIPNet(ip net.IP) *net.IPNet

Copied from github.com/vishvananda/netlink/netlink.go NewIPNet generates an IPNet from an ip address using a netmask of 32 or 128.

func NewNetNat added in v1.4.0

func NewNetNat(netNatName string, subnetCIDR *net.IPNet) error

func NewNetNeighbor added in v1.4.0

func NewNetNeighbor(neighbor *Neighbor) error

NewNetNeighbor creates a new neighbor cache entry with New-NetNeighbor.

func NewNetRoute added in v1.2.0

func NewNetRoute(route *Route) error

func PrepareHNSNetwork

func PrepareHNSNetwork(subnetCIDR *net.IPNet, nodeIPNet *net.IPNet, uplinkAdapter *net.Interface) error

PrepareHNSNetwork creates HNS Network for containers.

func RemoveInterfaceAddress

func RemoveInterfaceAddress(ifaceName string, ipAddr net.IP) error

RemoveInterfaceAddress removes IPAddress from the specified interface.

func RemoveManagementInterface

func RemoveManagementInterface(networkName string) error

RemoveManagementInterface removes the management interface of the HNS Network, and then the physical interface can be added to the OVS bridge. This function is called only if Hyper-V feature is installed on the host.

func RemoveNetNatStaticMapping added in v1.4.0

func RemoveNetNatStaticMapping(netNatName string, externalIPAddr string, externalPort uint16, proto string) error

func RemoveNetNatStaticMappingByID added in v1.4.0

func RemoveNetNatStaticMappingByID(netNatName string, id int) error

func RemoveNetNeighbor added in v1.4.0

func RemoveNetNeighbor(neighbor *Neighbor) error

func RemoveNetRoute added in v1.2.0

func RemoveNetRoute(route *Route) error

func ReplaceNetNatStaticMapping added in v1.4.0

func ReplaceNetNatStaticMapping(netNatName string, externalIPAddr string, externalPort uint16, internalIPAddr string, internalPort uint16, proto string) error

func ReplaceNetNeighbor added in v1.4.0

func ReplaceNetNeighbor(neighbor *Neighbor) error

func ReplaceNetRoute added in v1.4.0

func ReplaceNetRoute(route *Route) error

func SetAdapterDNSServers

func SetAdapterDNSServers(adapterName, dnsServers string) error

SetAdapterDNSServers configures DNSServers on network adapter.

func SetAdapterMACAddress

func SetAdapterMACAddress(adapterName string, macConfig *net.HardwareAddr) error

ConfigureMACAddress set specified MAC address on interface.

func SetInterfaceMTU

func SetInterfaceMTU(ifaceName string, mtu int) error

SetInterfaceMTU configures interface MTU on host for Pods. MTU change cannot be realized with HNSEndpoint because there's no MTU field in HNSEndpoint: https://github.com/Microsoft/hcsshim/blob/4a468a6f7ae547974bc32911395c51fb1862b7df/internal/hns/hnsendpoint.go#L12

func SetLinkUp

func SetLinkUp(name string) (net.HardwareAddr, int, error)

func WindowsHyperVEnabled

func WindowsHyperVEnabled() (bool, error)

WindowsHyperVEnabled checks if the Hyper-V is enabled on the host. Hyper-V feature contains multiple components/sub-features. According to the test, OVS requires "Microsoft-Hyper-V" feature to be enabled.


type ExtensionsPolicy

type ExtensionsPolicy struct {
	Extensions []vSwitchExtensionPolicy `json:"Extensions"`

type LinkNotFound

type LinkNotFound struct {
	// contains filtered or unexported fields

type Neighbor added in v1.4.0

type Neighbor struct {
	LinkIndex        int
	IPAddress        net.IP
	LinkLayerAddress net.HardwareAddr
	State            string

func GetNetNeighbor added in v1.4.0

func GetNetNeighbor(neighbor *Neighbor) ([]Neighbor, error)

GetNetNeighbor gets neighbor cache entries with Get-NetNeighbor.

func (Neighbor) String added in v1.4.0

func (n Neighbor) String() string

type Route added in v1.2.0

type Route struct {
	LinkIndex         int
	DestinationSubnet *net.IPNet
	GatewayAddress    net.IP
	RouteMetric       int

func GetNetRoutes added in v1.2.0

func GetNetRoutes(linkIndex int, dstSubnet *net.IPNet) ([]Route, error)

func GetNetRoutesAll added in v1.2.0

func GetNetRoutesAll() ([]Route, error)

func (Route) String added in v1.4.0

func (r Route) String() string


Path Synopsis
Package ethtool provides Go wrappers for ioctl ethtool system calls on Linux
Package ethtool provides Go wrappers for ioctl ethtool system calls on Linux
Package ndp contains functions to send NDP neighbor advertisement on Linux.
Package ndp contains functions to send NDP neighbor advertisement on Linux.
Package systcl contains utility functions to read and write sysctl configuration on Linux.
Package systcl contains utility functions to read and write sysctl configuration on Linux.
Package winfirewall contains utility functions to configure the Windows firewall.
Package winfirewall contains utility functions to configure the Windows firewall.

Jump to

Keyboard shortcuts

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