network

package
v2.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2020 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CNIConfigDir is the path where CNI config files exist
	CNIConfigDir = "/etc/cni/net.d"
	// CNIDeviceName is the default network device name and in
	// reality should have an int appended to it (cni-podman4)
	CNIDeviceName = "cni-podman"
	// DefaultPodmanDomainName is used for the dnsname plugin to define
	// a localized domain name for a created network
	DefaultPodmanDomainName = "dns.podman"
)

Variables

View Source
var DefaultNetworkDriver = "bridge"

DefaultNetworkDriver is the default network type used

View Source
var SupportedNetworkDrivers = []string{DefaultNetworkDriver}

SupportedNetworkDrivers describes the list of supported drivers

Functions

func CalcGatewayIP

func CalcGatewayIP(ipn *net.IPNet) net.IP

CalcGatewayIP takes a network and returns the first IP in it.

func Exists

func Exists(config *config.Config, name string) (bool, error)

Exists says whether a given network exists or not; it meant specifically for restful reponses so 404s can be used

func FirstIPInSubnet

func FirstIPInSubnet(addr *net.IPNet) (net.IP, error)

FirstIPInSubnet gets the first IP in a subnet

func GetBridgeNamesFromFileSystem

func GetBridgeNamesFromFileSystem(config *config.Config) ([]string, error)

GetBridgeNamesFromFileSystem is a convenience function to get all the bridge names from the configured networks

func GetCNIConfDir

func GetCNIConfDir(config *config.Config) string

func GetCNIConfigPathByName

func GetCNIConfigPathByName(config *config.Config, name string) (string, error)

GetCNIConfigPathByName finds a CNI network by name and returns its configuration file path

func GetCNIPlugins

func GetCNIPlugins(list *libcni.NetworkConfigList) string

GetCNIPlugins returns a list of plugins that a given network has in the form of a string

func GetDefaultPodmanNetwork

func GetDefaultPodmanNetwork() (*net.IPNet, error)

GetDefaultPodmanNetwork outputs the default network for podman

func GetFreeDeviceName

func GetFreeDeviceName(config *config.Config) (string, error)

GetFreeDeviceName returns a device name that is unused; used when no network name is provided by user

func GetFreeNetwork

func GetFreeNetwork(config *config.Config) (*net.IPNet, error)

GetFreeNetwork looks for a free network according to existing cni configuration files and network interfaces.

func GetInterfaceNameFromConfig

func GetInterfaceNameFromConfig(path string) (string, error)

GetInterfaceNameFromConfig returns the interface name for the bridge plugin

func GetLiveNetworkNames

func GetLiveNetworkNames() ([]string, error)

GetLiveNetworkNames returns a list of network interfaces on the system

func GetLiveNetworks

func GetLiveNetworks() ([]*net.IPNet, error)

GetLiveNetworks returns a slice of networks representing what the system has defined as network interfaces

func GetNetworkNamesFromFileSystem

func GetNetworkNamesFromFileSystem(config *config.Config) ([]string, error)

GetNetworkNamesFromFileSystem gets all the names from the cni network configuration files

func GetNetworksFromFilesystem

func GetNetworksFromFilesystem(config *config.Config) ([]*allocator.Net, error)

GetNetworksFromFilesystem gets all the networks from the cni configuration files

func HasDNSNamePlugin

func HasDNSNamePlugin(paths []string) bool

HasDNSNamePlugin looks to see if the dnsname cni plugin is present

func InspectNetwork

func InspectNetwork(config *config.Config, name string) (map[string]interface{}, error)

InspectNetwork reads a CNI config and returns its configuration

func IsIPv6 added in v2.0.5

func IsIPv6(netIP net.IP) bool

IsIPv6 returns if netIP is IPv6.

func IsSupportedDriver

func IsSupportedDriver(driver string) error

IsSupportedDriver checks if the user provided driver is supported

func LastIPInSubnet

func LastIPInSubnet(addr *net.IPNet) (net.IP, error)

LastIPInSubnet gets the last IP in a subnet

func LoadCNIConfsFromDir

func LoadCNIConfsFromDir(dir string) ([]*libcni.NetworkConfigList, error)

LoadCNIConfsFromDir loads all the CNI configurations from a dir

func NextSubnet

func NextSubnet(subnet *net.IPNet) (*net.IPNet, error)

NextSubnet returns subnet incremented by 1

func ReadRawCNIConfByName

func ReadRawCNIConfByName(config *config.Config, name string) ([]byte, error)

ReadRawCNIConfByName reads the raw CNI configuration for a CNI network by name

func RemoveInterface

func RemoveInterface(interfaceName string) error

RemoveInterface removes an interface by the given name

func RemoveNetwork

func RemoveNetwork(config *config.Config, name string) error

RemoveNetwork removes a given network by name. If the network has container associated with it, that must be handled outside the context of this.

func ValidateUserNetworkIsAvailable

func ValidateUserNetworkIsAvailable(config *config.Config, userNet *net.IPNet) error

ValidateUserNetworkIsAvailable returns via an error if a network is available to be used

Types

type CNIPlugins

type CNIPlugins interface {
	Bytes() ([]byte, error)
}

CNIPlugins is a way of marshalling a CNI network configuration to disk

type DNSNameConfig

type DNSNameConfig struct {
	PluginType string `json:"type"`
	DomainName string `json:"domainName"`
}

DNSNameConfig describes the dns container name resolution plugin config

func NewDNSNamePlugin

func NewDNSNamePlugin(domainName string) DNSNameConfig

NewDNSNamePlugin creates the dnsname config with a given domainname

func (DNSNameConfig) Bytes

func (d DNSNameConfig) Bytes() ([]byte, error)

Bytes outputs the configuration as []byte

type FirewallConfig

type FirewallConfig struct {
	PluginType string `json:"type"`
	Backend    string `json:"backend"`
}

FirewallConfig describes the firewall plugin

func NewFirewallPlugin

func NewFirewallPlugin() FirewallConfig

NewFirewallPlugin creates a generic firewall plugin

func (FirewallConfig) Bytes

func (f FirewallConfig) Bytes() ([]byte, error)

Bytes outputs the configuration as []byte

type HostLocalBridge

type HostLocalBridge struct {
	PluginType   string            `json:"type"`
	BrName       string            `json:"bridge,omitempty"`
	IsGW         bool              `json:"isGateway"`
	IsDefaultGW  bool              `json:"isDefaultGateway,omitempty"`
	ForceAddress bool              `json:"forceAddress,omitempty"`
	IPMasq       bool              `json:"ipMasq,omitempty"`
	MTU          int               `json:"mtu,omitempty"`
	HairpinMode  bool              `json:"hairpinMode,omitempty"`
	PromiscMode  bool              `json:"promiscMode,omitempty"`
	Vlan         int               `json:"vlan,omitempty"`
	IPAM         IPAMHostLocalConf `json:"ipam"`
}

HostLocalBridge describes a configuration for a bridge plugin https://github.com/containernetworking/plugins/tree/master/plugins/main/bridge#network-configuration-reference

func NewHostLocalBridge

func NewHostLocalBridge(name string, isGateWay, isDefaultGW, ipMasq bool, ipamConf IPAMHostLocalConf) *HostLocalBridge

NewHostLocalBridge creates a new LocalBridge for host-local

func (*HostLocalBridge) Bytes

func (h *HostLocalBridge) Bytes() ([]byte, error)

Bytes outputs []byte

type IPAMDHCP

type IPAMDHCP struct {
	DHCP string `json:"type"`
}

IPAMDHCP describes the ipamdhcp config

type IPAMHostLocalConf

type IPAMHostLocalConf struct {
	PluginType  string                     `json:"type"`
	Routes      []IPAMRoute                `json:"routes,omitempty"`
	ResolveConf string                     `json:"resolveConf,omitempty"`
	DataDir     string                     `json:"dataDir,omitempty"`
	Ranges      [][]IPAMLocalHostRangeConf `json:"ranges,omitempty"`
}

IPAMHostLocalConf describes an IPAM configuration https://github.com/containernetworking/plugins/tree/master/plugins/ipam/host-local#network-configuration-reference

func NewIPAMHostLocalConf

func NewIPAMHostLocalConf(subnet *net.IPNet, routes []IPAMRoute, ipRange net.IPNet, gw net.IP) (IPAMHostLocalConf, error)

NewIPAMHostLocalConf creates a new IPAMHostLocal configfuration

func (IPAMHostLocalConf) Bytes

func (i IPAMHostLocalConf) Bytes() ([]byte, error)

Bytes outputs the configuration as []byte

type IPAMLocalHostRangeConf

type IPAMLocalHostRangeConf struct {
	Subnet     string `json:"subnet"`
	RangeStart string `json:"rangeStart,omitempty"`
	RangeEnd   string `json:"rangeEnd,omitempty"`
	Gateway    string `json:"gateway,omitempty"`
}

IPAMLocalHostRangeConf describes the new style IPAM ranges

type IPAMRoute

type IPAMRoute struct {
	Dest string `json:"dst"`
}

IPAMRoute describes a route in an ipam config

func NewIPAMDefaultRoute

func NewIPAMDefaultRoute(isIPv6 bool) (IPAMRoute, error)

NewIPAMDefaultRoute creates a new IPAMDefault route of 0.0.0.0/0 for IPv4 or ::/0 for IPv6

func NewIPAMRoute

func NewIPAMRoute(r *net.IPNet) IPAMRoute

NewIPAMRoute creates a new IPAM route configuration

type MacVLANConfig

type MacVLANConfig struct {
	PluginType string   `json:"type"`
	Master     string   `json:"master"`
	IPAM       IPAMDHCP `json:"ipam"`
}

MacVLANConfig describes the macvlan config

func NewMacVLANPlugin

func NewMacVLANPlugin(device string) MacVLANConfig

NewMacVLANPlugin creates a macvlanconfig with a given device name

func (MacVLANConfig) Bytes

func (p MacVLANConfig) Bytes() ([]byte, error)

Bytes outputs the configuration as []byte

type NcList

type NcList map[string]interface{}

NcList describes a generic map

func NewNcList

func NewNcList(name, version string) NcList

NewNcList creates a generic map of values with string keys and adds in version and network name

type PortMapConfig

type PortMapConfig struct {
	PluginType   string          `json:"type"`
	Capabilities map[string]bool `json:"capabilities"`
}

PortMapConfig describes the default portmapping config

func NewPortMapPlugin

func NewPortMapPlugin() PortMapConfig

NewPortMapPlugin creates a predefined, default portmapping configuration

func (PortMapConfig) Bytes

func (p PortMapConfig) Bytes() ([]byte, error)

Bytes outputs the configuration as []byte

Jump to

Keyboard shortcuts

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