network

package
v0.0.0-...-54b8d16 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: AGPL-3.0 Imports: 59 Imported by: 0

Documentation

Index

Constants

View Source
const ForkdnsServersListFile = "servers.conf"

ForkdnsServersListFile file that contains the server candidates list.

View Source
const ForkdnsServersListPath = "forkdns.servers"

ForkdnsServersListPath defines the path that contains the forkdns server candidate file.

Variables

View Source
var ErrNotImplemented = fmt.Errorf("Not implemented")

ErrNotImplemented is the "Not implemented" error.

View Source
var ErrUnknownDriver = fmt.Errorf("Unknown driver")

ErrUnknownDriver is the "Unknown driver" error.

View Source
var SRIOVVirtualFunctionMutex sync.Mutex

SRIOVVirtualFunctionMutex used to coordinate access for finding and claiming free virtual functions.

Functions

func AttachInterface

func AttachInterface(bridgeName string, devName string) error

AttachInterface attaches an interface to a bridge.

func BridgeNetfilterEnabled

func BridgeNetfilterEnabled(ipVersion uint) error

BridgeNetfilterEnabled checks whether the bridge netfilter feature is loaded and enabled. If it is not an error is returned. This is needed in order for instances connected to a bridge to access DNAT listeners on the LXD host, as otherwise the packets from the bridge do have the SNAT netfilter rules applied.

func BridgeVLANDefaultPVID

func BridgeVLANDefaultPVID(interfaceName string) (string, error)

BridgeVLANDefaultPVID returns the VLAN default port VLAN ID (PVID).

func BridgeVLANFilterSetStatus

func BridgeVLANFilterSetStatus(interfaceName string, status string) error

BridgeVLANFilterSetStatus sets the status of VLAN filtering on a bridge interface.

func BridgeVLANFilteringStatus

func BridgeVLANFilteringStatus(interfaceName string) (string, error)

BridgeVLANFilteringStatus returns whether VLAN filtering is enabled on a bridge interface.

func BridgeVLANSetDefaultPVID

func BridgeVLANSetDefaultPVID(interfaceName string, vlanID string) error

BridgeVLANSetDefaultPVID sets the VLAN default port VLAN ID (PVID).

func DefaultGatewaySubnetV4

func DefaultGatewaySubnetV4() (*net.IPNet, string, error)

DefaultGatewaySubnetV4 returns subnet of default gateway interface.

func DetachInterface

func DetachInterface(bridgeName string, devName string) error

DetachInterface detaches an interface from a bridge.

func ForkdnsServersList

func ForkdnsServersList(networkName string) ([]string, error)

ForkdnsServersList reads the server list file and returns the list as a slice.

func GetDevMTU

func GetDevMTU(devName string) (uint32, error)

GetDevMTU retrieves the current MTU setting for a named network device.

func GetHostDevice

func GetHostDevice(parent string, vlan string) string

GetHostDevice returns the interface name to use for a combination of parent device name and VLAN ID. If no vlan ID supplied, parent name is returned unmodified. If non-empty VLAN ID is supplied then it will look for an existing VLAN device and return that, otherwise it will return the default "parent.vlan" format as name.

func GetLeaseAddresses

func GetLeaseAddresses(networkName string, hwaddr string) ([]net.IP, error)

GetLeaseAddresses returns the lease addresses for a network and hwaddr.

func GetMACSlice

func GetMACSlice(hwaddr string) []string

GetMACSlice parses MAC address.

func GetNeighbourIPs

func GetNeighbourIPs(interfaceName string, hwaddr net.HardwareAddr) ([]ip.Neigh, error)

GetNeighbourIPs returns the IP addresses in the neighbour cache for a particular interface and MAC.

func GetTXQueueLength

func GetTXQueueLength(devName string) (uint32, error)

GetTXQueueLength retrieves the current txqlen setting for a named network device.

func IPInSlice

func IPInSlice(key net.IP, list []net.IP) bool

IPInSlice returns true if slice has IP element.

func IPToNet

func IPToNet(ip net.IP) net.IPNet

IPToNet converts an IP to a single host IPNet.

func InterfaceExists

func InterfaceExists(nic string) bool

InterfaceExists returns true if network interface exists.

func InterfaceRemove

func InterfaceRemove(nic string) error

InterfaceRemove removes a network interface by name.

func InterfaceStatus

func InterfaceStatus(nicName string) ([]net.IP, bool, error)

InterfaceStatus returns the global unicast IP addresses configured on an interface and whether it is up or not.

func IsAvailable

func IsAvailable(projectName string, networkName string) bool

IsAvailable checks if a network is available.

func IsNativeBridge

func IsNativeBridge(bridgeName string) bool

IsNativeBridge returns whether the bridge name specified is a Linux native bridge.

func MACDevName

func MACDevName(mac net.HardwareAddr) string

MACDevName returns interface name with prefix 'lxd' and MAC without leading 2 digits.

func NICUsesNetwork

func NICUsesNetwork(nicDev map[string]string, networks ...*api.Network) bool

NICUsesNetwork returns true if the nicDev's "network" or "parent" property matches one of the networks names.

func ParseIPCIDRToNet

func ParseIPCIDRToNet(ipAddressCIDR string) (*net.IPNet, error)

ParseIPCIDRToNet parses an IP in CIDR format into a net.IPNet (with the IP field set to the IP supplied).

func ParseIPToNet

func ParseIPToNet(ipAddress string) (*net.IPNet, error)

ParseIPToNet parses a standalone IP address into a net.IPNet (with the IP field set to the IP supplied). The address family is detected and the subnet size set to /32 for IPv4 or /128 for IPv6.

func ParsePortRange

func ParsePortRange(r string) (base int64, size int64, err error)

ParsePortRange validates a port range in the form start-end.

func PatchPreCheck

func PatchPreCheck() error

PatchPreCheck checks if there are any unavailable networks.

func ProxyParseAddr

func ProxyParseAddr(data string) (*deviceConfig.ProxyAddress, error)

ProxyParseAddr validates a proxy address and parses it into its constituent parts.

func RandomDevName

func RandomDevName(prefix string) string

RandomDevName returns a random device name with prefix. If the random string combined with the prefix exceeds 13 characters then empty string is returned. This is to ensure we support buggy dhclient applications: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=858580

func SRIOVFindFreeVFAndRepresentor

func SRIOVFindFreeVFAndRepresentor(state *state.State, ovsBridgeName string) (port string, representorPort string, vfName string, vfID int, err error)

SRIOVFindFreeVFAndRepresentor tries to find a free SR-IOV virtual function of a PF connected to an OVS bridge. To do this it first looks at the ports on the OVS bridge specified and identifies which ones are PF ports in switchdev mode. It then tries to find a free VF on that PF and the representor port associated to the VF ID. It returns the PF name, representor port name, VF name, and VF ID.

func SRIOVFindFreeVirtualFunction

func SRIOVFindFreeVirtualFunction(s *state.State, parentDev string) (string, int, error)

SRIOVFindFreeVirtualFunction looks on the specified parent device for an unused virtual function. Returns the name of the interface and virtual function index ID if found, error if not.

func SRIOVFindRepresentorPort

func SRIOVFindRepresentorPort(nicEntries []fs.DirEntry, pfSwitchID string, pfID int, vfID int) string

SRIOVFindRepresentorPort finds the associated representor port name for a switchdev VF ID.

func SRIOVGetHostDevicesInUse

func SRIOVGetHostDevicesInUse(s *state.State) (map[string]struct{}, error)

SRIOVGetHostDevicesInUse returns a map of host device names that have been used by devices in other instances and networks on the local member. Used when selecting physical and SR-IOV VF devices to avoid conflicts.

func SRIOVGetSwitchAndPFID

func SRIOVGetSwitchAndPFID(parentDev string) (string, int, error)

SRIOVGetSwitchAndPFID returns the physical switch ID and PF id.

func SRIOVGetVFDevicePCISlot

func SRIOVGetVFDevicePCISlot(parentDev string, vfID string) (pci.Device, error)

SRIOVGetVFDevicePCISlot returns the PCI slot name for a network virtual function device.

func SRIOVSwitchdevEnabled

func SRIOVSwitchdevEnabled(deviceName string) bool

SRIOVSwitchdevEnabled returns true if switchdev mode is enabled on the given device.

func SubnetContains

func SubnetContains(outerSubnet *net.IPNet, innerSubnet *net.IPNet) bool

SubnetContains returns true if outerSubnet contains innerSubnet.

func SubnetContainsIP

func SubnetContainsIP(outerSubnet *net.IPNet, ip net.IP) bool

SubnetContainsIP returns true if outsetSubnet contains IP address.

func SubnetIterate

func SubnetIterate(subnet *net.IPNet, ipFunc func(ip net.IP) error) error

SubnetIterate iterates through each IP in a subnet calling a function for each IP. If the ipFunc returns a non-nil error then the iteration stops and the error is returned.

func SubnetParseAppend

func SubnetParseAppend(subnets []*net.IPNet, parseSubnet ...string) ([]*net.IPNet, error)

SubnetParseAppend parses one or more string CIDR subnets. Appends to the supplied slice. Returns subnets slice.

func UpdateDNSMasqStatic

func UpdateDNSMasqStatic(s *state.State, networkName string) error

UpdateDNSMasqStatic rebuilds the DNSMasq static allocations.

func UsedBy

func UsedBy(s *state.State, networkProjectName string, networkID int64, networkName string, networkType string, firstOnly bool) ([]string, error)

UsedBy returns list of API resources using network. Accepts firstOnly argument to indicate that only the first resource using network should be returned. This can help to quickly check if the network is in use.

func UsedByInstanceDevices

func UsedByInstanceDevices(s *state.State, networkProjectName string, networkName string, networkType string, usageFunc func(inst db.InstanceArgs, nicName string, nicConfig map[string]string) error, filters ...cluster.InstanceFilter) error

UsedByInstanceDevices looks for instance NIC devices using the network and runs the supplied usageFunc for each. Accepts optional filter arguments to specify a subset of instances.

func VLANInterfaceCreate

func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string, gvrp bool) (bool, error)

VLANInterfaceCreate creates a VLAN interface on parent interface (if needed). Returns boolean indicating if VLAN interface was created.

Types

type Info

type Info struct {
	Projects           bool // Indicates if driver can be used in network enabled projects.
	NodeSpecificConfig bool // Whether driver has cluster node specific config as a prerequisite for creation.
	AddressForwards    bool // Indicates if driver supports address forwards.
	LoadBalancers      bool // Indicates if driver supports load balancers.
	Peering            bool // Indicates if the driver supports network peering.
}

Info represents information about a network driver.

type Network

type Network interface {
	Type

	// Config.
	Validate(config map[string]string) error
	ID() int64
	Name() string
	Project() string
	Description() string
	Status() string
	LocalStatus() string
	Config() map[string]string
	Locations() []string
	IsUsed() (bool, error)
	IsManaged() bool
	DHCPv4Subnet() *net.IPNet
	DHCPv6Subnet() *net.IPNet
	DHCPv4Ranges() []shared.IPRange
	DHCPv6Ranges() []shared.IPRange

	// Actions.
	Create(clientType request.ClientType) error
	Start() error
	Stop() error
	Rename(name string) error
	Update(newNetwork api.NetworkPut, targetNode string, clientType request.ClientType) error
	HandleHeartbeat(heartbeatData *cluster.APIHeartbeat) error
	Delete(clientType request.ClientType) error

	// Status.
	State() (*api.NetworkState, error)
	Leases(projectName string, clientType request.ClientType) ([]api.NetworkLease, error)

	// Address Forwards.
	ForwardCreate(forward api.NetworkForwardsPost, clientType request.ClientType) (net.IP, error)
	ForwardUpdate(listenAddress string, newForward api.NetworkForwardPut, clientType request.ClientType) error
	ForwardDelete(listenAddress string, clientType request.ClientType) error

	// Load Balancers.
	LoadBalancerCreate(loadBalancer api.NetworkLoadBalancersPost, clientType request.ClientType) (net.IP, error)
	LoadBalancerUpdate(listenAddress string, newLoadBalancer api.NetworkLoadBalancerPut, clientType request.ClientType) error
	LoadBalancerDelete(listenAddress string, clientType request.ClientType) error

	// Peerings.
	PeerCreate(forward api.NetworkPeersPost) error
	PeerUpdate(peerName string, newPeer api.NetworkPeerPut) error
	PeerDelete(peerName string) error
	PeerUsedBy(peerName string) ([]string, error)
	// contains filtered or unexported methods
}

Network represents an instantiated LXD network.

func LoadByName

func LoadByName(s *state.State, projectName string, name string) (Network, error)

LoadByName loads an instantiated network from the database by project and name.

type OVNInstanceNICSetupOpts

type OVNInstanceNICSetupOpts struct {
	InstanceUUID string
	DeviceName   string
	DeviceConfig deviceConfig.Device
	UplinkConfig map[string]string
	DNSName      string
}

OVNInstanceNICSetupOpts options for starting an OVN Instance NIC.

type OVNInstanceNICStopOpts

type OVNInstanceNICStopOpts struct {
	InstanceUUID string
	DeviceName   string
	DeviceConfig deviceConfig.Device
}

OVNInstanceNICStopOpts options for stopping an OVN Instance NIC.

type ProjectNetwork

type ProjectNetwork struct {
	ProjectName string
	NetworkName string
}

ProjectNetwork is a composite type of project name and network name.

type Type

type Type interface {
	FillConfig(config map[string]string) error
	Info() Info
	ValidateName(name string) error
	Type() string
	DBType() db.NetworkType
}

Type represents a LXD network driver type.

func LoadByType

func LoadByType(driverType string) (Type, error)

LoadByType loads a network by driver type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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