nettools

package
v0.9.5-test5 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2018 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FAMILY_ALL     = netlink.FAMILY_ALL
	FAMILY_V4      = netlink.FAMILY_V4
	RTPROT_KERNEL  = syscall.RTPROT_KERNEL
	SCOPE_LINK     = netlink.SCOPE_LINK
	SCOPE_UNIVERSE = netlink.SCOPE_UNIVERSE
)

these constants are only available on Linux

Variables

This section is empty.

Functions

func ConfigureLink(link netlink.Link, info *cnicurrent.Result) error

ConfigureLink configures a link according to the CNI result

func CreateEscapeVethPair

func CreateEscapeVethPair(innerNS ns.NetNS, ifName string, mtu int) (outerVeth, innerVeth netlink.Link, err error)

CreateEscapeVethPair creates a veth pair with innerVeth residing in the specified network namespace innerNS and outerVeth residing in the 'outer' (current) namespace. TBD: move this to test tools

func CreateTAP added in v0.9.4

func CreateTAP(devName string, mtu int) (netlink.Link, error)

CreateTAP sets up a tap link and brings it up

func DetectCalico added in v0.9.4

func DetectCalico(link netlink.Link) (bool, bool, error)

DetectCalico checks if the specified link in the current network namespace is configured by Calico. It returns two boolean values where the first one denotes whether Calico is used for the specified link and the second one denotes whether Calico's default route needs to be used. This approach is needed for multiple CNI use case when the types of individual CNI plugins are not available.

func ExtractLinkInfo

func ExtractLinkInfo(link netlink.Link, nsPath string) (*cnicurrent.Result, error)

ExtractLinkInfo extracts ip address and netmask from veth interface in the current namespace, together with routes for this interface. There must be exactly one veth interface in the namespace and exactly one address associated with veth. Returns interface info struct and error, if any.

func FindVeth

func FindVeth(links []netlink.Link) (netlink.Link, error)

FindVeth locates single veth link in the list of provided links. There must be exactly one veth interface in the list.

func FixCalicoNetworking added in v0.9.4

func FixCalicoNetworking(netConfig *cnicurrent.Result, getDummyNetwork func() (*cnicurrent.Result, string, error)) error

FixCalicoNetworking updates netConfig to make Calico work with Virtlet's DHCP-server based scheme. It does so by throwing away Calico's gateway and dev route and using a fake gateway instead. The fake gateway provided by getDummyGateway() is just an IP address allocated by Calico IPAM, it's needed for proper ARP responses for VMs. This function must be called from within the container network namespace.

func GenerateMacAddress

func GenerateMacAddress() (net.HardwareAddr, error)

GenerateMacAddress returns a random locally administrated unicast hardware address. Copied from: https://github.com/coreos/rkt/blob/56564bac090b44788684040f2ffd66463f29d5d0/stage1/init/kvm/network.go#L71

func GetContainerLinks(interfaces []*cnicurrent.Interface) ([]netlink.Link, error)

GetContainerLinks finds links that correspond to interfaces in the current network namespace

func OpenTAP

func OpenTAP(devName string) (*os.File, error)

OpenTAP opens a tap device and returns an os.File for it

func RandomVethName added in v0.8.0

func RandomVethName() (string, error)

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

func ReconstructVFs added in v0.9.4

func ReconstructVFs(csn *network.ContainerSideNetwork, netns ns.NetNS) error

ReconstructVFs iterates over stored PCI addresses, rebinding each corresponding interface to its host driver, changing its MAC address to the stored value and then moving it into the container namespace

func RecoverContainerSideNetwork added in v0.9.4

func RecoverContainerSideNetwork(csn *network.ContainerSideNetwork, nsPath string, allLinks []netlink.Link) error

RecoverContainerSideNetwork tries to populate ContainerSideNetwork structure based on a network namespace that was already adjusted for Virtlet

func SetHardwareAddr added in v0.9.4

func SetHardwareAddr(link netlink.Link, hwAddr net.HardwareAddr) error

SetHardwareAddr sets hardware address on provided link.

func SetupBridge

func SetupBridge(bridgeName string, links []netlink.Link) (*netlink.Bridge, error)

SetupBridge creates a bridge and adds specified links to it. It sets bridge's MTU to MTU value of the first link.

func SetupContainerSideNetwork

func SetupContainerSideNetwork(info *cnicurrent.Result, nsPath string, allLinks []netlink.Link) (*network.ContainerSideNetwork, error)

SetupContainerSideNetwork sets up networking in container namespace. It does so by preparing the following network interfaces in container ns:

tapX      - tap interface for the each interface to pass to VM
brX       - a bridge that joins above tapX and original CNI interface

with X denoting an link index in info.Interfaces list. Each bridge gets assigned a link-local address to be used for dhcp server. In case of SR-IOV VFs this function only sets up a device to be passed to VM. The function should be called from within container namespace. Returns container network struct and an error, if any.

func SetupVeth added in v0.8.0

func SetupVeth(contVethName string, mtu int, hostNS ns.NetNS) (netlink.Link, netlink.Link, 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 StripLink(link netlink.Link) error

StripLink removes addresses from the link along with any routes related to the link, except those created by the kernel

func Teardown added in v0.9.4

func Teardown(csn *network.ContainerSideNetwork) error

Teardown cleans up container network configuration. It does so by invoking teardown sequence which removes ebtables rules, links and addresses in an order opposite to that of their creation in SetupContainerSideNetwork. The end result is the same network configuration in the container network namespace as it was before SetupContainerSideNetwork() call.

func TeardownBridge

func TeardownBridge(bridge netlink.Link, links []netlink.Link) error

TeardownBridge removes links from bridge and sets it down

func ValidateAndFixCNIResult added in v0.9.4

func ValidateAndFixCNIResult(netConfig *cnicurrent.Result, nsPath string, allLinks []netlink.Link) (*cnicurrent.Result, error)

ValidateAndFixCNIResult verifies that netConfig contains proper list of ips, routes, interfaces and if something is missing it tries to complement that using patch for Weave or for plugins which return their netConfig in v0.2.0 version of CNI SPEC

Types

This section is empty.

Jump to

Keyboard shortcuts

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