network

package
v1.7.0-tar Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2020 License: Apache-2.0 Imports: 17 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 SupportedNetworkDrivers = []string{"bridge"}

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 FirstIPInSubnet

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

FirstIPInSubnet gets the first IP in a subnet

func GetBridgeNamesFromFileSystem

func GetBridgeNamesFromFileSystem() ([]string, error)

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

func GetCNIConfigPathByName

func GetCNIConfigPathByName(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() (string, error)

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

func GetFreeNetwork

func GetFreeNetwork() (*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() ([]string, error)

GetNetworkNamesFromFileSystem gets all the names from the cni network configuration files

func GetNetworksFromFilesystem

func GetNetworksFromFilesystem() ([]*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(name string) (map[string]interface{}, error)

InspectNetwork reads a CNI config and returns its configuration

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(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(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(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"`
}

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() (IPAMRoute, error)

NewIPAMDefaultRoute creates a new IPAMDefault route of 0.0.0.0/0

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