nettools

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2017 License: Apache-2.0 Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SizeOfIfReq = 40
	IFNAMSIZ    = 16
)

Variables

This section is empty.

Functions

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

ConfigureLink adds to link ip address and routes based on info.

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 ExtractLinkInfo

func ExtractLinkInfo(link netlink.Link) (*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() (netlink.Link, error)

FindVeth locates veth link in the current network namespace. There must be exactly one veth interface in the namespace.

func OpenTAP

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

func RandomVethName added in v0.8.0

func RandomVethName() (string, error)

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

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 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 TeardownBridge

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

TeardownBridge removes links from bridge and sets it down

Types

type ContainerNetwork

type ContainerNetwork struct {
	Info   *cnicurrent.Result
	DhcpNS ns.NetNS
}

type ContainerSideNetwork

type ContainerSideNetwork struct {
	// Result contains CNI result object describing the network settings
	Result *cnicurrent.Result
	// TapFile contains an open File object pointing to Tap device inside
	// the network namespace
	TapFile *os.File
	// HardwareAddr stores the original hardware address of the
	// CNI veth interface
	HardwareAddr net.HardwareAddr
}

ContainerSideNetwork struct describes the container (VM) network namespace properties

func SetupContainerSideNetwork

func SetupContainerSideNetwork(info *cnicurrent.Result) (*ContainerSideNetwork, error)

SetupContainerSideNetwork sets up networking in container namespace. It does so by calling ExtractLinkInfo() first unless non-nil info argument is provided and then preparing the following network interfaces in container ns:

tap0      - tap interface for the VM
br0       - a bridge that joins tap0 and original CNI veth

The bridge (br0) gets assigned a link-local address to be used for dhcp server. The function should be called from within container namespace. Returns container network struct and an error, if any

func (*ContainerSideNetwork) Teardown

func (csn *ContainerSideNetwork) Teardown() 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.

type InterfaceInfo

type InterfaceInfo struct {
	IPNet  *net.IPNet
	Routes []Route
}

type Route

type Route struct {
	Destination *net.IPNet
	Via         net.IP
}

Jump to

Keyboard shortcuts

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