juju: github.com/juju/juju/network Index | Files | Directories

package network

import "github.com/juju/juju/network"

Index

Package Files

bridge.go devicenames.go fan.go firewall.go gateway.go network.go scriptrunner.go utils.go

Constants

const (
    EOF = iota
    LITERAL
    NUMBER
)
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

const DefaultLXCBridge = "lxcbr0"

DefaultLXCBridge is the bridge that gets used for LXC containers

const DefaultLXDBridge = "lxdbr0"

DefaultLXDBridge is the bridge that gets used for LXD containers

const SysClassNetPath = "/sys/class/net"

SysClassNetRoot is the full Linux SYSFS path containing information about each network interface on the system. Used as argument to ParseInterfaceType().

const UnknownId = ""

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

Variables

var InterfaceByNameAddrs = func(name string) ([]net.Addr, error) {
    iface, err := net.InterfaceByName(name)
    if err != nil {
        return nil, err
    }
    return iface.Addrs()
}

InterfaceByNameAddrs returns the addresses for the given interface name. It's exported to facilitate cross-package testing.

var LXCNetDefaultConfig = "/etc/default/lxc-net"

LXCNetDefaultConfig is the location of the default network config of the lxc package. It's exported to allow cross-package testing.

var ResolverFunc = net.ResolveIPAddr

Export for testing

var SpaceInvalidChars = regexp.MustCompile("[^0-9a-z-]")

SpaceInvalidChars is a regexp for validating that space names contain no invalid characters.

func CalculateOverlaySegment Uses

func CalculateOverlaySegment(underlayCIDR string, fan FanConfigEntry) (*net.IPNet, error)

CalculateOverlaySegment takes underlay CIDR and FAN config entry and cuts the segment of overlay that corresponds to this underlay: eg. for FAN 172.31/16 -> 243/8 and physical subnet 172.31.64/20 we get FAN subnet 243.64/12.

func ConvertSpaceName Uses

func ConvertSpaceName(name string, existing set.Strings) string

ConvertSpaceName converts names between provider space names and valid juju space names. TODO(mfoord): once MAAS space name rules are in sync with juju space name rules this can go away.

func FilterBridgeAddresses Uses

func FilterBridgeAddresses(addresses []corenetwork.ProviderAddress) 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.

func FormatAsCIDR Uses

func FormatAsCIDR(addresses []string) ([]string, error)

FormatAsCIDR converts the specified IP addresses to a slice of CIDRs. It attempts to resolve any address represented as hostnames before formatting.

func GetBridgePorts Uses

func GetBridgePorts(sysPath, bridgeName string) []string

GetBridgePorts extracts and returns the names of all interfaces configured as ports of the given bridgeName from the Linux kernel userspace SYSFS location "<sysPath/<bridgeName>/brif/*". SysClassNetPath should be passed as sysPath. Returns an empty result if the ports cannot be determined reliably for any reason, or if there are no configured ports for the bridge.

Example call: network.GetBridgePorts(network.SysClassNetPath, "br-eth1")

func GetDefaultRoute Uses

func GetDefaultRoute() (net.IP, string, error)

GetDefaultRoute returns the IP address and device name of default gateway on the machine. If we don't support OS, or we don't have a default route, we return nothing (not an error!).

func IsNoAddressError Uses

func IsNoAddressError(err error) bool

IsNoAddressError reports whether err was created with NoAddressError().

func NaturallySortDeviceNames Uses

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 NoAddressError Uses

func NoAddressError(addressKind string) error

NoAddressError returns an error which satisfies IsNoAddressError(). The given addressKind specifies what kind of address(es) is(are) missing, usually "private" or "public".

func ParseInterfaceType Uses

func ParseInterfaceType(sysPath, interfaceName string) network.InterfaceType

ParseInterfaceType parses the DEVTYPE attribute from the Linux kernel userspace SYSFS location "<sysPath/<interfaceName>/uevent" and returns it as InterfaceType. SysClassNetPath should be passed as sysPath. Returns UnknownInterface if the type cannot be reliably determined for any reason.

Example call: network.ParseInterfaceType(network.SysClassNetPath, "br-eth1")

func QuoteSpaceSet Uses

func QuoteSpaceSet(vals set.Strings) string

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

func QuoteSpaces Uses

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 SortIngressRules Uses

func SortIngressRules(IngressRules []IngressRule)

SortIngressRules sorts the given rules, first by protocol, then by ports.

func SubnetInAnyRange Uses

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 Uses

func SupportsIPv6() bool

SupportsIPv6 reports whether the platform supports IPv6 networking functionality.

Source: https://github.com/golang/net/blob/master/internal/nettest/stack.go

type Bridger Uses

type Bridger interface {
    // Turns existing devices into bridged devices.
    // TODO(frobware) - we may want a different type to encompass
    // and reflect how bridging should be done vis-a-vis what
    // needs to be bridged.
    Bridge(devices []DeviceToBridge, reconfigureDelay int) error
}

Bridger creates network bridges to support addressable containers.

func DefaultEtcNetworkInterfacesBridger Uses

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 Uses

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 DNSConfig Uses

type DNSConfig struct {
    Nameservers   []network.ProviderAddress
    SearchDomains []string
}

DNSConfig holds a list of DNS nameserver addresses and default search domains.

func ParseResolvConf Uses

func ParseResolvConf(path string) (*DNSConfig, error)

ParseResolvConf parses a resolv.conf(5) file at the given path (usually "/etc/resolv.conf"), if present. Returns the values of any 'nameserver' stanzas, and the last 'search' stanza found. Values in the result will appear in the order found, including duplicates. Parsing errors will be returned in these cases:

1. if a 'nameserver' or 'search' without a value is found; 2. 'nameserver' with more than one value (trailing comments starting with '#'

or ';' after the value are allowed).

3. if any value containing '#' or ';' (e.g. 'nameserver 8.8.8.8#bad'), because

values and comments following them must be separated by whitespace.

No error is returned if the file is missing. See resolv.conf(5) man page for details.

type DeviceToBridge Uses

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.

type FanConfig Uses

type FanConfig []FanConfigEntry

FanConfig defines a set of fan configurations for the model.

func ParseFanConfig Uses

func ParseFanConfig(line string) (config FanConfig, err error)

ParseFanConfig parses fan configuration from model-config in the format: "underlay1=overlay1 underlay2=overlay2" eg. "172.16.0.0/16=253.0.0.0/8 10.0.0.0/12=254.0.0.0/7"

func (*FanConfig) String Uses

func (fc *FanConfig) String() (line string)

type FanConfigEntry Uses

type FanConfigEntry struct {
    Underlay *net.IPNet
    Overlay  *net.IPNet
}

FanConfigEntry defines a configuration for single fan.

type IngressRule Uses

type IngressRule struct {
    // PortRange is the range of ports for which incoming
    // packets are allowed.
    network.PortRange

    // SourceCIDRs is a list of IP address blocks expressed in CIDR format
    // to which this rule applies.
    SourceCIDRs []string
}

IngressRule represents a range of ports and sources from which to allow ingress by incoming packets.

func MustNewIngressRule Uses

func MustNewIngressRule(protocol string, from, to int, sourceCIDRs ...string) IngressRule

MustNewIngressRule returns an IngressRule for the specified port range. If no explicit source ranges are specified, there is no restriction from where incoming traffic originates. The method will panic if there is an error.

func NewIngressRule Uses

func NewIngressRule(protocol string, from, to int, sourceCIDRs ...string) (IngressRule, error)

NewIngressRule returns an IngressRule for the specified port range. If no explicit source ranges are specified, there is no restriction from where incoming traffic originates.

func NewOpenIngressRule Uses

func NewOpenIngressRule(protocol string, from, to int) IngressRule

NewOpenIngressRule returns an IngressRule for the specified port range. There is no restriction from where incoming traffic originates.

func (IngressRule) GoString Uses

func (r IngressRule) GoString() string

GoString is used to print values passed as an operand to a %#v format.

func (IngressRule) String Uses

func (r IngressRule) String() string

String is the string representation of IngressRule.

type IngressRuleSlice Uses

type IngressRuleSlice []IngressRule

func (IngressRuleSlice) Len Uses

func (p IngressRuleSlice) Len() int

func (IngressRuleSlice) Less Uses

func (p IngressRuleSlice) Less(i, j int) bool

func (IngressRuleSlice) Swap Uses

func (p IngressRuleSlice) Swap(i, j int)

type InterfaceAddress Uses

type InterfaceAddress struct {
    Address string
    CIDR    string
}

InterfaceAddress represents a single address attached to the interface.

type NetworkInfo Uses

type NetworkInfo struct {
    // MACAddress is the network interface's hardware MAC address
    // (e.g. "aa:bb:cc:dd:ee:ff").
    MACAddress string

    // InterfaceName is the OS-specific interface name, eg. "eth0" or "eno1.412"
    InterfaceName string

    // Addresses contains a list of addresses configured on the interface.
    Addresses []InterfaceAddress
}

NetworkInfo describes one interface with assigned IP addresses, it's a mirror of params.NetworkInfo.

type ProviderInterfaceInfo Uses

type ProviderInterfaceInfo struct {
    // InterfaceName is the raw OS-specific network device name (e.g.
    // "eth1", even for a VLAN eth1.42 virtual interface).
    InterfaceName string

    // ProviderId is a provider-specific NIC id.
    ProviderId corenetwork.Id

    // MACAddress is the network interface's hardware MAC address
    // (e.g. "aa:bb:cc:dd:ee:ff").
    MACAddress string
}

ProviderInterfaceInfo holds enough information to identify an interface or link layer device to a provider so that it can be queried or manipulated. Its initial purpose is to pass to provider.ReleaseContainerAddresses.

type ScriptResult Uses

type ScriptResult struct {
    Stdout   []byte
    Stderr   []byte
    Code     int
    TimedOut bool
}

Directories

PathSynopsis
containerizer
debinterfaces
iptables
netplan
ssh
ssh/testing

Package network imports 23 packages (graph) and is imported by 2822 packages. Updated 2019-11-29. Refresh now. Tools for package owners.