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.Address) []corenetwork.Address

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

func SortInterfaceInfo(interfaces []InterfaceInfo)

SortInterfaceInfo sorts a slice of InterfaceInfo on DeviceIndex in ascending order.

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.Address
    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 InterfaceConfigType Uses

type InterfaceConfigType string

InterfaceConfigType defines valid network interface configuration types. See interfaces(5) for details

const (
    ConfigUnknown  InterfaceConfigType = ""
    ConfigDHCP     InterfaceConfigType = "dhcp"
    ConfigStatic   InterfaceConfigType = "static"
    ConfigManual   InterfaceConfigType = "manual"
    ConfigLoopback InterfaceConfigType = "loopback"
)

type InterfaceInfo Uses

type InterfaceInfo struct {
    // DeviceIndex specifies the order in which the network interface
    // appears on the host. The primary interface has an index of 0.
    DeviceIndex int

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

    // CIDR of the network, in 123.45.67.89/24 format.
    CIDR string

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

    // ProviderSubnetId is the provider-specific id for the associated
    // subnet.
    ProviderSubnetId corenetwork.Id

    // ProviderNetworkId is the provider-specific id for the
    // associated network.
    ProviderNetworkId corenetwork.Id

    // ProviderSpaceId is the provider-specific id for the associated space, if
    // known and supported.
    ProviderSpaceId corenetwork.Id

    // ProviderVLANId is the provider-specific id of the VLAN for this
    // interface.
    ProviderVLANId corenetwork.Id

    // ProviderAddressId is the provider-specific id of the assigned address.
    ProviderAddressId corenetwork.Id

    // AvailabilityZones describes the availability zones the associated
    // subnet is in.
    AvailabilityZones []string

    // VLANTag needs to be between 1 and 4094 for VLANs and 0 for
    // normal networks. It's defined by IEEE 802.1Q standard.
    VLANTag int

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

    // ParentInterfaceName is the name of the parent interface to use, if known.
    ParentInterfaceName string

    // InterfaceType is the type of the interface.
    InterfaceType InterfaceType

    // Disabled is true when the interface needs to be disabled on the
    // machine, e.g. not to configure it.
    Disabled bool

    // NoAutoStart is true when the interface should not be configured
    // to start automatically on boot. By default and for
    // backwards-compatibility, interfaces are configured to
    // auto-start.
    NoAutoStart bool

    // ConfigType determines whether the interface should be
    // configured via DHCP, statically, manually, etc. See
    // interfaces(5) for more information.
    ConfigType InterfaceConfigType

    // Address contains an optional static IP address to configure for
    // this network interface. The subnet mask to set will be inferred
    // from the CIDR value.
    Address corenetwork.Address

    // DNSServers contains an optional list of IP addresses and/or
    // hostnames to configure as DNS servers for this network
    // interface.
    DNSServers []corenetwork.Address

    // MTU is the Maximum Transmission Unit controlling the maximum size of the
    // protocol packats that the interface can pass through. It is only used
    // when > 0.
    MTU int

    // DNSSearchDomains contains the default DNS domain to use for non-FQDN
    // lookups.
    DNSSearchDomains []string

    // Gateway address, if set, defines the default gateway to
    // configure for this network interface. For containers this
    // usually is (one of) the host address(es).
    GatewayAddress corenetwork.Address

    // Routes defines a list of routes that should be added when this interface
    // is brought up, and removed when this interface is stopped.
    Routes []Route

    // IsDefaultGateway is set if this device is a default gw on a machine.
    IsDefaultGateway bool
}

InterfaceInfo describes a single network interface available on an instance. For providers that support networks, this will be available at StartInstance() time. TODO(mue): Rename to InterfaceConfig due to consistency later.

func (*InterfaceInfo) ActualInterfaceName Uses

func (i *InterfaceInfo) ActualInterfaceName() string

ActualInterfaceName returns raw interface name for raw interface (e.g. "eth0") and virtual interface name for virtual interface (e.g. "eth0.42")

func (*InterfaceInfo) CIDRAddress Uses

func (i *InterfaceInfo) CIDRAddress() string

CIDRAddress returns Address.Value combined with CIDR mask.

func (*InterfaceInfo) IsVLAN Uses

func (i *InterfaceInfo) IsVLAN() bool

IsVLAN returns true when the interface is a VLAN interface.

func (*InterfaceInfo) IsVirtual Uses

func (i *InterfaceInfo) IsVirtual() bool

IsVirtual returns true when the interface is a virtual device, as opposed to a physical device (e.g. a VLAN or a network alias)

type InterfaceType Uses

type InterfaceType string

InterfaceType defines valid network interface types.

const (
    UnknownInterface    InterfaceType = ""
    LoopbackInterface   InterfaceType = "loopback"
    EthernetInterface   InterfaceType = "ethernet"
    VLAN_8021QInterface InterfaceType = "802.1q"
    BondInterface       InterfaceType = "bond"
    BridgeInterface     InterfaceType = "bridge"
)

func ParseInterfaceType Uses

func ParseInterfaceType(sysPath, interfaceName string) 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")

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

type Route struct {
    // DestinationCIDR is the subnet that we want a controlled route to.
    DestinationCIDR string
    // GatewayIP is the IP (v4 or v6) that should be used for traffic that is
    // bound for DestinationCIDR
    GatewayIP string
    // Metric is the weight to apply to this route.
    Metric int
}

Route defines a single route to a subnet via a defined gateway.

func (Route) Validate Uses

func (r Route) Validate() error

Validate that this Route is properly formed.

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 2746 packages. Updated 2019-08-19. Refresh now. Tools for package owners.