Documentation ¶
Overview ¶
Example (IpRangesOverlap) ¶
rangePairs := [][2]string{ {"10.1.1.1-10.1.1.2", "10.1.1.3-10.1.1.4"}, {"10.1.1.1-10.1.2.1", "10.1.1.254-10.1.1.255"}, {"10.1.1.1-10.1.1.6", "10.1.1.5-10.1.1.9"}, {"10.1.1.5-10.1.1.9", "10.1.1.1-10.1.1.6"}, {"::1-::2", "::3-::4"}, {"::1-::6", "::5-::9"}, {"::5-::9", "::1-::6"}, } for _, pair := range rangePairs { r0, _ := parseIPRange(pair[0]) r1, _ := parseIPRange(pair[1]) result := IPRangesOverlap(r0, r1) fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", r0, r1, result) } // also do a couple of tests with ranges that have no end singleIPRange := &iprange.Range{ Start: net.ParseIP("10.1.1.4"), } otherRange, _ := parseIPRange("10.1.1.1-10.1.1.6") fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", singleIPRange, otherRange, IPRangesOverlap(singleIPRange, otherRange)) fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", otherRange, singleIPRange, IPRangesOverlap(otherRange, singleIPRange)) fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", singleIPRange, singleIPRange, IPRangesOverlap(singleIPRange, singleIPRange)) otherRange, _ = parseIPRange("10.1.1.8-10.1.1.9") fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", singleIPRange, otherRange, IPRangesOverlap(singleIPRange, otherRange)) fmt.Printf("Range1: %v, Range2: %v, overlapped: %t\n", otherRange, singleIPRange, IPRangesOverlap(otherRange, singleIPRange))
Output: Range1: 10.1.1.1-10.1.1.2, Range2: 10.1.1.3-10.1.1.4, overlapped: false Range1: 10.1.1.1-10.1.2.1, Range2: 10.1.1.254-10.1.1.255, overlapped: true Range1: 10.1.1.1-10.1.1.6, Range2: 10.1.1.5-10.1.1.9, overlapped: true Range1: 10.1.1.5-10.1.1.9, Range2: 10.1.1.1-10.1.1.6, overlapped: true Range1: ::1-::2, Range2: ::3-::4, overlapped: false Range1: ::1-::6, Range2: ::5-::9, overlapped: true Range1: ::5-::9, Range2: ::1-::6, overlapped: true Range1: 10.1.1.4, Range2: 10.1.1.1-10.1.1.6, overlapped: true Range1: 10.1.1.1-10.1.1.6, Range2: 10.1.1.4, overlapped: true Range1: 10.1.1.4, Range2: 10.1.1.4, overlapped: true Range1: 10.1.1.4, Range2: 10.1.1.8-10.1.1.9, overlapped: false Range1: 10.1.1.8-10.1.1.9, Range2: 10.1.1.4, overlapped: false
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-1.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-1.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 ¶
- Variables
- func AttachInterface(bridgeName string, devName string) error
- func BridgeNetfilterEnabled(ipVersion uint) error
- func BridgeVLANDefaultPVID(interfaceName string) (string, error)
- func BridgeVLANFilterSetStatus(interfaceName string, status string) error
- func BridgeVLANFilteringStatus(interfaceName string) (string, error)
- func BridgeVLANSetDefaultPVID(interfaceName string, vlanID string) error
- func DefaultGatewaySubnetV4() (*net.IPNet, string, error)
- func DetachInterface(bridgeName string, devName string) error
- func GetDevMTU(devName string) (uint32, error)
- func GetHostDevice(parent string, vlan string) string
- func GetLeaseAddresses(networkName string, hwaddr string) ([]net.IP, error)
- func GetMACSlice(hwaddr string) []string
- func GetNeighbourIPs(interfaceName string, hwaddr net.HardwareAddr) ([]ip.Neigh, error)
- func GetTXQueueLength(devName string) (uint32, error)
- func IPInSlice(key net.IP, list []net.IP) bool
- func IPRangesOverlap(r1, r2 *iprange.Range) bool
- func IPToNet(ip net.IP) net.IPNet
- func InterfaceExists(nic string) bool
- func InterfaceRemove(nic string) error
- func InterfaceStatus(nicName string) ([]net.IP, bool, error)
- func IsAvailable(projectName string, networkName string) bool
- func IsNativeBridge(bridgeName string) bool
- func MACDevName(mac net.HardwareAddr) string
- func NICUsesNetwork(nicDev map[string]string, networks ...*api.Network) bool
- func ParseIPCIDRToNet(ipAddressCIDR string) (*net.IPNet, error)
- func ParseIPToNet(ipAddress string) (*net.IPNet, error)
- func ParsePortRange(r string) (int64, int64, error)
- func PatchPreCheck() error
- func ProxyParseAddr(data string) (*deviceConfig.ProxyAddress, error)
- func RandomDevName(prefix string) string
- func SRIOVFindFreeVFAndRepresentor(state *state.State, ovsBridgeName string) (string, string, string, int, error)
- func SRIOVFindFreeVirtualFunction(s *state.State, parentDev string) (string, int, error)
- func SRIOVFindRepresentorPort(nicEntries []fs.DirEntry, pfSwitchID string, pfID int, vfID int) string
- func SRIOVGetHostDevicesInUse(s *state.State) (map[string]struct{}, error)
- func SRIOVGetSwitchAndPFID(parentDev string) (string, int, error)
- func SRIOVGetVFDevicePCISlot(parentDev string, vfID string) (pci.Device, error)
- func SRIOVSwitchdevEnabled(deviceName string) bool
- func SubnetContains(outerSubnet *net.IPNet, innerSubnet *net.IPNet) bool
- func SubnetContainsIP(outerSubnet *net.IPNet, ip net.IP) bool
- func SubnetIterate(subnet *net.IPNet, ipFunc func(ip net.IP) error) error
- func SubnetParseAppend(subnets []*net.IPNet, parseSubnet ...string) ([]*net.IPNet, error)
- func UpdateDNSMasqStatic(s *state.State, networkName string) error
- func UsedBy(s *state.State, networkProjectName string, networkID int64, networkName string, ...) ([]string, error)
- func UsedByInstanceDevices(s *state.State, networkProjectName string, networkName string, ...) error
- func VLANInterfaceCreate(parent string, vlanDevice string, vlanID string, gvrp bool) (bool, error)
- type Info
- type Network
- type OVNInstanceNICSetupOpts
- type OVNInstanceNICStopOpts
- type ProjectNetwork
- type Type
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotImplemented = fmt.Errorf("Not implemented")
ErrNotImplemented is the "Not implemented" error.
var ErrUnknownDriver = fmt.Errorf("Unknown driver")
ErrUnknownDriver is the "Unknown driver" error.
var SRIOVVirtualFunctionMutex sync.Mutex
SRIOVVirtualFunctionMutex used to coordinate access for finding and claiming free virtual functions.
Functions ¶
func AttachInterface ¶
AttachInterface attaches an interface to a bridge.
func BridgeNetfilterEnabled ¶
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 host, as otherwise the packets from the bridge do have the SNAT netfilter rules applied.
func BridgeVLANDefaultPVID ¶
BridgeVLANDefaultPVID returns the VLAN default port VLAN ID (PVID).
func BridgeVLANFilterSetStatus ¶
BridgeVLANFilterSetStatus sets the status of VLAN filtering on a bridge interface.
func BridgeVLANFilteringStatus ¶
BridgeVLANFilteringStatus returns whether VLAN filtering is enabled on a bridge interface.
func BridgeVLANSetDefaultPVID ¶
BridgeVLANSetDefaultPVID sets the VLAN default port VLAN ID (PVID).
func DefaultGatewaySubnetV4 ¶
DefaultGatewaySubnetV4 returns subnet of default gateway interface.
func DetachInterface ¶
DetachInterface detaches an interface from a bridge.
func GetHostDevice ¶
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 ¶
GetLeaseAddresses returns the lease addresses for a network and hwaddr.
func GetNeighbourIPs ¶
GetNeighbourIPs returns the IP addresses in the neighbour cache for a particular interface and MAC.
func GetTXQueueLength ¶
GetTXQueueLength retrieves the current txqlen setting for a named network device.
func IPRangesOverlap ¶
IPRangesOverlap checks whether two ip ranges have ip addresses in common.
func InterfaceExists ¶
InterfaceExists returns true if network interface exists.
func InterfaceRemove ¶
InterfaceRemove removes a network interface by name.
func InterfaceStatus ¶
InterfaceStatus returns the global unicast IP addresses configured on an interface and whether it is up or not.
func IsAvailable ¶
IsAvailable checks if a network is available.
func IsNativeBridge ¶
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 'inc' and MAC without leading 2 digits.
func NICUsesNetwork ¶
NICUsesNetwork returns true if the nicDev's "network" or "parent" property matches one of the networks names.
func ParseIPCIDRToNet ¶
ParseIPCIDRToNet parses an IP in CIDR format into a net.IPNet (with the IP field set to the IP supplied).
func ParseIPToNet ¶
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 ¶
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 ¶
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) (string, string, string, int, 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 ¶
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 ¶
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 SRIOVGetVFDevicePCISlot ¶
SRIOVGetVFDevicePCISlot returns the PCI slot name for a network virtual function device.
func SRIOVSwitchdevEnabled ¶
SRIOVSwitchdevEnabled returns true if switchdev mode is enabled on the given device.
func SubnetContains ¶
SubnetContains returns true if outerSubnet contains innerSubnet.
func SubnetContainsIP ¶
SubnetContainsIP returns true if outsetSubnet contains IP address.
func SubnetIterate ¶
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 ¶
SubnetParseAppend parses one or more string CIDR subnets. Appends to the supplied slice. Returns subnets slice.
func UpdateDNSMasqStatic ¶
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.
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() []iprange.Range DHCPv6Ranges() []iprange.Range // 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) 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) 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 network.
type OVNInstanceNICSetupOpts ¶
type OVNInstanceNICSetupOpts struct { InstanceUUID string DeviceName string DeviceConfig deviceConfig.Device UplinkConfig map[string]string DNSName string LastStateIPs []net.IP }
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 ¶
ProjectNetwork is a composite type of project name and network name.