network

package
v0.0.0-...-00587b8 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2020 License: Apache-2.0 Imports: 47 Imported by: 0

Documentation

Overview

Example (ParseIPRange)
_, allowedv4NetworkA, _ := net.ParseCIDR("192.168.1.0/24")
_, allowedv4NetworkB, _ := net.ParseCIDR("192.168.0.0/16")
_, allowedv6NetworkA, _ := net.ParseCIDR("fd22:c952:653e:3df6::/64")
_, allowedv6NetworkB, _ := net.ParseCIDR("fd22:c952:653e::/48")

ipRanges := []string{
	// Ranges within allowedv4NetworkA.
	"192.168.1.1-192.168.1.255",
	"0.0.0.1-192.168.1.255",
	"0.0.0.1-0.0.0.255",
	// Ranges outsde of allowedv4NetworkA but within allowedv4NetworkB.
	"192.168.0.1-192.168.0.255",
	"192.168.0.0-192.168.0.0",
	"0.0.2.0-0.0.2.255",
	// Invalid IP ranges.
	"0.0.0.0.1-192.168.1.255",
	"192.0.0.1-192.0.0.255",
	"0.0.0.1-01.0.0.255",
	"0.0.2.1-0.0.0.255",
	// Ranges within allowedv6NetworkA.
	"fd22:c952:653e:3df6::1-fd22:c952:653e:3df6::FFFF",
	"::1-::FFFF",
	// Ranges outsde of allowedv6NetworkA but within allowedv6NetworkB.
	"fd22:c952:653e:FFFF::1-fd22:c952:653e:FFFF::FFFF",
	"::AAAA:FFFF:FFFF:FFFF:1-::AAAA:FFFF:FFFF:FFFF:FFFF",
}

fmt.Println("With allowed networks")
for _, ipRange := range ipRanges {
	parsedRange, err := parseIPRange(ipRange, allowedv4NetworkA, allowedv4NetworkB, allowedv6NetworkA, allowedv6NetworkB)
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		continue
	}

	fmt.Printf("Start: %s, End: %s\n", parsedRange.Start.String(), parsedRange.End.String())
}

fmt.Println("Without allowed networks")
for _, ipRange := range ipRanges {
	parsedRange, err := parseIPRange(ipRange)
	if err != nil {
		fmt.Printf("Err: %v\n", err)
		continue
	}

	fmt.Printf("Start: %s, End: %s\n", parsedRange.Start.String(), parsedRange.End.String())
}
Output:

With allowed networks
Start: 192.168.1.1, End: 192.168.1.255
Start: 192.168.1.1, End: 192.168.1.255
Start: 192.168.1.1, End: 192.168.1.255
Start: 192.168.0.1, End: 192.168.0.255
Start: 192.168.0.0, End: 192.168.0.0
Start: 192.168.2.0, End: 192.168.2.255
Err: Start IP "0.0.0.0.1" is invalid
Err: IP range "192.0.0.1-192.0.0.255" does not fall within any of the allowed networks [192.168.1.0/24 192.168.0.0/16 fd22:c952:653e:3df6::/64 fd22:c952:653e::/48]
Err: IP range "0.0.0.1-01.0.0.255" does not fall within any of the allowed networks [192.168.1.0/24 192.168.0.0/16 fd22:c952:653e:3df6::/64 fd22:c952:653e::/48]
Err: Start IP "0.0.2.1" must be less than End IP "0.0.0.255"
Start: fd22:c952:653e:3df6::1, End: fd22:c952:653e:3df6::ffff
Start: fd22:c952:653e:3df6::1, End: fd22:c952:653e:3df6::ffff
Start: fd22:c952:653e:ffff::1, End: fd22:c952:653e:ffff::ffff
Start: fd22:c952:653e:aaaa:ffff:ffff:ffff:1, End: fd22:c952:653e:aaaa:ffff:ffff:ffff:ffff
Without allowed networks
Start: 192.168.1.1, End: 192.168.1.255
Start: 0.0.0.1, End: 192.168.1.255
Start: 0.0.0.1, End: 0.0.0.255
Start: 192.168.0.1, End: 192.168.0.255
Start: 192.168.0.0, End: 192.168.0.0
Start: 0.0.2.0, End: 0.0.2.255
Err: Start IP "0.0.0.0.1" is invalid
Start: 192.0.0.1, End: 192.0.0.255
Start: 0.0.0.1, End: 1.0.0.255
Err: Start IP "0.0.2.1" must be less than End IP "0.0.0.255"
Start: fd22:c952:653e:3df6::1, End: fd22:c952:653e:3df6::ffff
Start: ::1, End: ::ffff
Start: fd22:c952:653e:ffff::1, End: fd22:c952:653e:ffff::ffff
Start: ::aaaa:ffff:ffff:ffff:1, End: ::aaaa:ffff:ffff:ffff:ffff

Index

Examples

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 ErrUnknownDriver = fmt.Errorf("Unknown driver")

ErrUnknownDriver is the "Unknown driver" error

Functions

func AttachInterface

func AttachInterface(bridgeName string, devName string) error

AttachInterface attaches an interface to a bridge.

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 string) ([]net.IP, error)

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

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 InterfaceSetMTU

func InterfaceSetMTU(nic string, mtu string) error

InterfaceSetMTU sets the MTU of a network interface.

func IsNativeBridge

func IsNativeBridge(bridgeName string) bool

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

func OVNInstanceDevicePortAdd

func OVNInstanceDevicePortAdd(network Network, instanceID int, instanceName string, deviceName string, mac net.HardwareAddr, ips []net.IP) (openvswitch.OVNSwitchPort, error)

OVNInstanceDevicePortAdd adds a logical port to the OVN network's internal switch and returns the logical port name for use linking an OVS port on the integration bridge to the logical switch port.

func OVNInstanceDevicePortDelete

func OVNInstanceDevicePortDelete(network Network, instanceID int, deviceName string) error

OVNInstanceDevicePortDelete deletes a logical port from the OVN network's internal switch.

func OVNInstanceDevicePortDynamicIPs

func OVNInstanceDevicePortDynamicIPs(network Network, instanceID int, deviceName string) ([]net.IP, error)

OVNInstanceDevicePortDynamicIPs gets a logical port's dynamic IPs stored in the OVN network's internal switch.

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 UpdateDNSMasqStatic

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

UpdateDNSMasqStatic rebuilds the DNSMasq static allocations.

func UsedBy

func UsedBy(s *state.State, networkProjectName string, networkName 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 VLANInterfaceCreate

func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string) (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.
}

Info represents information about a network driver.

type Network

type Network interface {
	Type

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

	// Actions.
	Create(clientType cluster.ClientType) error
	Start() error
	Stop() error
	Rename(name string) error
	Update(newNetwork api.NetworkPut, targetNode string, clientType cluster.ClientType) error
	HandleHeartbeat(heartbeatData *cluster.APIHeartbeat) error
	Delete(clientType cluster.ClientType) 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 Type

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

Type represents an 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