v0.0.0-...-8dc6826 Latest Latest

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

Go to latest
Published: Dec 5, 2023 License: AGPL-3.0 Imports: 14 Imported by: 537




View Source
const (
	EOF = iota
View Source
const DefaultDockerBridge = "docker0"

DefaultDockerBridge is the bridge that is set up by Docker.

View Source
const DefaultKVMBridge = "virbr0"

DefaultKVMBridge is the bridge that is set up by installing libvirt-bin Note: we don't import this from 'container' to avoid import loops

View Source
const DefaultLXDBridge = "lxdbr0"

DefaultLXDBridge is the bridge that gets used for LXD containers

View Source
const UnknownId = ""

UnknownId can be used whenever an Id is needed but not known.


View Source
var AddressesForInterfaceName = func(name string) ([]string, error) {
	iface, err := net.InterfaceByName(name)
	if err != nil {
		return nil, errors.Trace(err)

	addrs, err := iface.Addrs()
	if err != nil {
		return nil, errors.Trace(err)

	res := make([]string, len(addrs))
	for i, addr := range addrs {
		res[i] = addr.String()
	return res, nil

AddressesForInterfaceName returns the addresses in string form for the given interface name. It's exported to facilitate cross-package testing.


func FilterBridgeAddresses

func FilterBridgeAddresses(addresses corenetwork.ProviderAddresses) corenetwork.ProviderAddresses

FilterBridgeAddresses removes addresses seen as a Bridge address (the IP address used only to connect to local containers), rather than a remote accessible address. This includes addresses used by the local Fan network.

func NaturallySortDeviceNames

func NaturallySortDeviceNames(names ...string) []string

NaturallySortDeviceNames returns an ordered list of names based on a natural ordering where 'natural' is an ordering of the string value in alphabetical order, execept that multi-digit numbers are ordered as a single character.

For example, sorting:

[ br-eth10 br-eth1 br-eth2 ]

would sort as:

[ br-eth1 br-eth2 br-eth10 ]

In purely alphabetical sorting "br-eth10" would be sorted before "br-eth2" because "1" is sorted as smaller than "2", while in natural sorting "br-eth2" is sorted before "br-eth10" because "2" is sorted as smaller than "10".

This also extends to multiply repeated numbers (e.g., VLANs).

For example, sorting:

[ br-eth2 br-eth10.10 br-eth200.0 br-eth1.0 br-eth2.0 ]

would sort as:

[ br-eth1.0 br-eth2 br-eth2.0 br-eth10.10 br-eth200.0 ]

func QuoteSpaceSet

func QuoteSpaceSet(vals set.Strings) string

QuoteSpaceSet is the same as QuoteSpaces, but ensures that a set.Strings gets sorted values output.

func QuoteSpaces

func QuoteSpaces(vals []string) string

QuoteSpaces takes a slice of space names, and returns a nicely formatted form so they show up legible in log messages, etc.

func SubnetInAnyRange

func SubnetInAnyRange(cidrs []*net.IPNet, subnet *net.IPNet) bool

SubnetInAnyRange returns true if the subnet's address range is fully contained in any of the specified subnet blocks.

func SupportsIPv6

func SupportsIPv6() bool

SupportsIPv6 reports whether the platform supports IPv6 networking functionality.



type Bridger

type Bridger interface {
	// Bridge turns existing devices into bridged devices.
	Bridge(devices []DeviceToBridge, reconfigureDelay int) error

Bridger creates network bridges to support addressable containers.

func DefaultEtcNetworkInterfacesBridger

func DefaultEtcNetworkInterfacesBridger(timeout time.Duration, filename string) (Bridger, error)

DefaultEtcNetworkInterfacesBridger returns a Bridger instance that can parse an interfaces(5) to transform existing devices into bridged devices.

func DefaultNetplanBridger

func DefaultNetplanBridger(timeout time.Duration, directory string) (Bridger, error)

DefaultNetplanBridger returns a Bridger instance that can parse a set of netplan yaml files to transform existing devices into bridged devices.

type DeviceToBridge

type DeviceToBridge struct {
	// DeviceName is the name of the device on the machine that should
	// be bridged.
	DeviceName string

	// BridgeName is the name of the bridge that we want created.
	BridgeName string

	// MACAddress is the MAC address of the device to be bridged
	MACAddress string

DeviceToBridge gives the information about a particular device that should be bridged.


Path Synopsis

Jump to

Keyboard shortcuts

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