networking

package
v1.33.4 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2024 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package networking provides IP address management functionality. Mostly a copy/paste from https://github.com/giantswarm/ipam without proprietary service/error handling

Index

Constants

View Source
const (

	// ManagementSwitchBrandAruba for Aruba Management switches
	ManagementSwitchBrandAruba ManagementSwitchBrand = "Aruba"

	// ManagementSwitchBrandDell for Dell Management switches
	ManagementSwitchBrandDell ManagementSwitchBrand = "Dell"

	// ManagementSwitchBrandMellanox for Mellanox Management switches
	ManagementSwitchBrandMellanox ManagementSwitchBrand = "Mellanox"

	// ManagementSwitchBrandArista for Arista Edge switches
	ManagementSwitchBrandArista ManagementSwitchBrand = "Arista"

	// ManagementSwitchBrandCisco for Cisco Edge switches
	ManagementSwitchBrandCisco ManagementSwitchBrand = "Cisco"

	// ManagementSwitchBrandJuniper for Juniper Edge switches
	ManagementSwitchBrandJuniper ManagementSwitchBrand = "Juniper"

	// ManagementSwitchTypeCDU is the type for CDU Management switches
	ManagementSwitchTypeCDU ManagementSwitchType = "CDU"

	// ManagementSwitchTypeLeafBMC is the type for Leaf Management switches
	ManagementSwitchTypeLeafBMC ManagementSwitchType = "LeafBMC"

	// ManagementSwitchTypeSpine is the type for Spine Management switches
	ManagementSwitchTypeSpine ManagementSwitchType = "Spine"

	// ManagementSwitchTypeLeaf is the type for Leaf Management switches
	ManagementSwitchTypeLeaf ManagementSwitchType = "Leaf"

	// ManagementSwitchTypeEdge is the type for Edge Management switches
	ManagementSwitchTypeEdge ManagementSwitchType = "Edge"
)
View Source
const SubrolePlaceHolder = "~fixme~"

SubrolePlaceHolder is the placeholder used to indicate that a prefix has no subrole mapping in ApplicationNodeConfig.

Variables

View Source
var DefaultApplicationNodePrefixes = []string{
	"uan",
	"gn",
	"ln",
}

DefaultApplicationNodePrefixes is the list of default Application node prefixes, for source column in the hmn_connections.json

View Source
var DefaultApplicationNodeSubroles = map[string]string{
	"uan": "UAN",
	"ln":  "UAN",
	"gn":  "Gateway",
}

DefaultApplicationNodeSubroles is the default prefix<->subrole mapping for application node subroles, these can be overridden via ApplicationNodeConfig

View Source
var DefaultUAISubnetReservations = map[string][]string{
	"uai_nmn_blackhole": {"uai-nmn-blackhole"},
	"slurmctld_service": {
		"slurmctld-service",
		"slurmctld-service-nmn",
	},
	"slurmdbd_service": {
		"slurmdbd-service",
		"slurmdbd-service-nmn",
	},
	"pbs_service": {
		"pbs-service",
		"pbs-service-nmn",
	},
	"pbs_comm_service": {
		"pbs-comm-service",
		"pbs-comm-service-nmn",
	},
}

DefaultUAISubnetReservations is the map of dns names and aliases

View Source
var Networks = [...]string{
	"cmn",
	"hmn",
	"mtl",
	"nmn",
}

Networks - The networks that need IPAM.

View Source
var PinnedMetalLBReservations = map[string]PinnedReservation{
	"istio-ingressgateway": {
		71,
		strings.Split(
			"api-gw-service api-gw-service-nmn.local packages registry spire.local api_gw_service registry.local packages packages.local spire",
			" ",
		),
	},
	"istio-ingressgateway-local": {
		81,
		[]string{"api-gw-service.local"},
	},
	"rsyslog-aggregator": {
		72,
		[]string{"rsyslog-agg-service"},
	},
	"cray-tftp": {
		60,
		[]string{"tftp-service"},
	},
	"unbound": {
		225,
		[]string{"unbound"},
	},
	"docker-registry": {
		73,
		[]string{"docker_registry_service"},
	},
}

PinnedMetalLBReservations is the map of dns names and aliases with the required final octet of th ip address *** This structure is only necessary to pin ip addresses as we shift from 1.3 to 1.4 *** *** *** *** To anyone editing this code in the future, PLEASE DON'T MAKE IT BETTER *** *** *** *** *** *** This code is written to be thrown away with a fully dynamic ip addressing scheme *** *** ***

View Source
var ValidNetNames = []string{
	"BICAN",
	"CAN",
	"CHN",
	"CMN",
	"HMN",
	"HMN_MTN",
	"HMN_RVR",
	"MTL",
	"NMN",
	"NMN_MTN",
	"NMN_RVR",
}

ValidNetNames is the list of strings that enumerate valid main network names

Functions

func Add

func Add(
	ip net.IP, number int,
) net.IP

Add increments the given IP by the number. e.g: add(10.0.4.0, 1) -> 10.0.4.1. Negative values are allowed for decrementing.

func Broadcast

func Broadcast(network net.IPNet) net.IP

Broadcast takes a net.IPNet and returns the broadcast address as net.IP

func CalculateSubnetMask

func CalculateSubnetMask(
	networkMask net.IPMask, n uint,
) (
	net.IPMask, error,
)

CalculateSubnetMask calculates new subnet mask to accommodate n subnets.

func CanonicalizeSubnets

func CanonicalizeSubnets(
	networkRange net.IPNet, subnets []net.IPNet,
) []net.IPNet

CanonicalizeSubnets iterates over subnets and returns deduplicated list of networks that belong to networkRange. Subnets that overlap each other but aren't exactly the same are not removed. Subnets are returned in the same order as they appear in input.

Example:

networkRange: 192.168.2.0/24
subnets: [172.168.2.0/25, 192.168.2.0/25, 192.168.3.128/25, 192.168.2.0/25, 192.168.2.128/25]
returned: [192.168.2.0/25, 192.168.2.128/25]

Example 2:

networkRange: 10.0.0.0/8
subnets: [10.1.0.0/16, 10.1.0.0/24, 10.1.1.0/24]
returned: [10.1.0.0/16, 10.1.0.0/24, 10.1.1.0/24]

func Contains

func Contains(network, subnet net.IPNet) bool

Contains returns true when the subnet is a part of the network, false otherwise.

func Free

func Free(
	network net.IPNet, mask net.IPMask, subnets []net.IPNet,
) (
	net.IPNet, error,
)

Free takes a network, a mask, and a list of subnets. An available network, within the first network, is returned.

func Half

func Half(network net.IPNet) (
	first, second net.IPNet, err error,
)

Half takes a network and returns two subnets which split the network in half.

func IPLessThan

func IPLessThan(a, b net.IP) bool

IPLessThan compare two ip addresses by section left-most is most significant

func IPNetfromCIDRString

func IPNetfromCIDRString(mynet string) *net.IPNet

IPNetfromCIDRString converts from a string to an net.IPNet struct

func IsManagementSwitchTypeValid

func IsManagementSwitchTypeValid(mst ManagementSwitchType) bool

IsManagementSwitchTypeValid validates the given ManagementSwitchType

func NetIPInSlice

func NetIPInSlice(
	a net.IP, list []net.IP,
) int

NetIPInSlice makes it easy to assess if an IP address is present in a list of ips

func Split

func Split(
	network net.IPNet, n uint,
) (
	[]net.IPNet, error,
)

Split returns n subnets from network.

func SubnetWithin

func SubnetWithin(
	network net.IPNet, hostNumber int,
) (
	net.IPNet, error,
)

SubnetWithin returns the smallest subnet than can contain (size) hosts

Types

type BootstrapSwitchMetadata

type BootstrapSwitchMetadata struct {
	Xname string `json:"xname" csv:"Switch Xname"`
	Type  string `json:"type" csv:"Type"`
}

BootstrapSwitchMetadata is a type that matches the switch_metadata.csv file as Switch Xname, Type The type can be CDU, Spine, Leaf, or LeafBMC

type IPNets

type IPNets []net.IPNet

IPNets is a helper type for sorting net.IPNets.

func (IPNets) Len

func (s IPNets) Len() int

func (IPNets) Less

func (s IPNets) Less(i, j int) bool

func (IPNets) Swap

func (s IPNets) Swap(i, j int)

type IPRange

type IPRange struct {
	// contains filtered or unexported fields
}

IPRange defines a pair of IPs, over a range.

func NewIPRange

func NewIPRange(network net.IPNet) IPRange

NewIPRange takes an IPNet, and returns the ipRange of the network.

type IPReservation

type IPReservation struct {
	IPAddress net.IP   `yaml:"ip_address"`
	Name      string   `yaml:"name"`
	Comment   string   `yaml:"comment"`
	Aliases   []string `yaml:"aliases"`
}

IPReservation is a type for managing IP Reservations

func (*IPReservation) AddReservationAlias

func (iReserv *IPReservation) AddReservationAlias(alias string)

AddReservationAlias adds an alias to a reservation if it doesn't already exist

type IPV4Network

type IPV4Network struct {
	FullName           string                `yaml:"full_name"`
	CIDR               string                `yaml:"cidr"`
	Subnets            []*IPV4Subnet         `yaml:"subnets"`
	Name               string                `yaml:"name"`
	VlanRange          []int16               `yaml:"vlan_range"`
	MTU                int16                 `yaml:"mtu"`
	NetType            slsCommon.NetworkType `yaml:"type"`
	Comment            string                `yaml:"comment"`
	PeerASN            int                   `yaml:"peer-asn"`
	MyASN              int                   `yaml:"my-asn"`
	SystemDefaultRoute string                `yaml:"system_default_route"`
}

IPV4Network is a type for managing IPv4 Networks

func (*IPV4Network) AddBiggestSubnet

func (iNet *IPV4Network) AddBiggestSubnet(
	mask net.IPMask, name string, vlanID int16,
) (
	*IPV4Subnet, error,
)

AddBiggestSubnet allocates the largest subnet possible within the requested network and mask

func (*IPV4Network) AddSubnet

func (iNet *IPV4Network) AddSubnet(
	mask net.IPMask, name string, vlanID int16,
) (
	*IPV4Subnet, error,
)

AddSubnet allocates a new subnet

func (*IPV4Network) AddSubnetbyCIDR

func (iNet *IPV4Network) AddSubnetbyCIDR(
	desiredNet net.IPNet, name string, vlanID int16,
) (
	*IPV4Subnet, error,
)

AddSubnetbyCIDR allocates a new subnet

func (IPV4Network) AllocatedSubnets

func (iNet IPV4Network) AllocatedSubnets() []net.IPNet

AllocatedSubnets returns a list of the allocated subnets

func (IPV4Network) AllocatedVlans

func (iNet IPV4Network) AllocatedVlans() []int16

AllocatedVlans returns a list of all allocated vlan ids

func (*IPV4Network) ApplySupernetHack

func (iNet *IPV4Network) ApplySupernetHack()

ApplySupernetHack applys a dirty hack.

func (*IPV4Network) GenSubnets

func (iNet *IPV4Network) GenSubnets(
	cabinetDetails []sls.CabinetGroupDetail, mask net.IPMask, cabinetFilter sls.CabinetFilterFunc,
) error

GenSubnets subdivides a network into a set of subnets

func (*IPV4Network) LookUpSubnet

func (iNet *IPV4Network) LookUpSubnet(name string) (
	*IPV4Subnet, error,
)

LookUpSubnet returns a subnet by name

func (IPV4Network) SubnetbyName

func (iNet IPV4Network) SubnetbyName(name string) IPV4Subnet

SubnetbyName Return a copy of the subnet by name or a blank subnet if it doesn't exists

type IPV4Subnet

type IPV4Subnet struct {
	FullName         string          `yaml:"full_name" form:"full_name" mapstructure:"full_name"`
	CIDR             net.IPNet       `yaml:"cidr"`
	IPReservations   []IPReservation `yaml:"ip_reservations"`
	Name             string          `yaml:"name" form:"name" mapstructure:"name"`
	NetName          string          `yaml:"net-name"`
	VlanID           int16           `yaml:"vlan_id" form:"vlan_id" mapstructure:"vlan_id"`
	Comment          string          `yaml:"comment"`
	Gateway          net.IP          `yaml:"gateway"`
	PITServer        net.IP          `yaml:"_"`
	DNSServer        net.IP          `yaml:"dns_server"`
	DHCPStart        net.IP          `yaml:"iprange-start"`
	DHCPEnd          net.IP          `yaml:"iprange-end"`
	ReservationStart net.IP          `yaml:"reservation-start"`
	ReservationEnd   net.IP          `yaml:"reservation-end"`
	MetalLBPoolName  string          `yaml:"metallb-pool-name"`
}

IPV4Subnet is a type for managing IPv4 Subnets

func (*IPV4Subnet) AddReservation

func (iSubnet *IPV4Subnet) AddReservation(name, comment string) *IPReservation

AddReservation adds a new IP reservation to the subnet

func (*IPV4Subnet) AddReservationWithIP

func (iSubnet *IPV4Subnet) AddReservationWithIP(name, addr, comment string) (
	*IPReservation, error,
)

AddReservationWithIP adds a reservation with a specific ip address

func (*IPV4Subnet) AddReservationWithPin

func (iSubnet *IPV4Subnet) AddReservationWithPin(
	name, comment string, pin uint8,
) *IPReservation

AddReservationWithPin adds a new IPv4 reservation to the subnet with the last octet pinned

func (*IPV4Subnet) LookupReservation

func (iSubnet *IPV4Subnet) LookupReservation(resName string) IPReservation

LookupReservation searches the subnet for an IPReservation that matches the name provided

func (*IPV4Subnet) ReservationsByName

func (iSubnet *IPV4Subnet) ReservationsByName() map[string]IPReservation

ReservationsByName presents the IPReservations in a map by name

func (*IPV4Subnet) ReserveEdgeSwitchIPs

func (iSubnet *IPV4Subnet) ReserveEdgeSwitchIPs(edges []string)

ReserveEdgeSwitchIPs reserves (n) IP addresses for edge switches

func (*IPV4Subnet) ReserveNetMgmtIPs

func (iSubnet *IPV4Subnet) ReserveNetMgmtIPs(
	spines []string, leafs []string, leafbmcs []string, cdus []string,
)

ReserveNetMgmtIPs reserves (n) IP addresses for management networking equipment

func (*IPV4Subnet) ReservedIPs

func (iSubnet *IPV4Subnet) ReservedIPs() []net.IP

ReservedIPs returns a list of IPs already reserved within the subnet

func (*IPV4Subnet) TotalIPAddresses

func (iSubnet *IPV4Subnet) TotalIPAddresses() int

TotalIPAddresses returns the number of ip addresses in a subnet see UsableHostAddresses

func (*IPV4Subnet) UpdateDHCPRange

func (iSubnet *IPV4Subnet) UpdateDHCPRange(applySupernetHack bool)

UpdateDHCPRange resets the DHCPStart to exclude all IPReservations

func (*IPV4Subnet) UsableHostAddresses

func (iSubnet *IPV4Subnet) UsableHostAddresses() int

UsableHostAddresses returns the number of usable ip addresses in a subnet

type ManagementSwitch

type ManagementSwitch struct {
	Xname               string                `json:"xname" mapstructure:"xname" csv:"Switch Xname"` // Required for SLS
	Name                string                `json:"name" mapstructure:"name" csv:"-"`              // Required for SLS to update DNS
	Brand               ManagementSwitchBrand `json:"brand" mapstructure:"brand" csv:"Brand"`
	Model               string                `json:"model" mapstructure:"model" csv:"Model"`
	Os                  string                `json:"operating-system" mapstructure:"operating-system" csv:"-"`
	Firmware            string                `json:"firmware" mapstructure:"firmware" csv:"-"`
	SwitchType          ManagementSwitchType  `json:"type" mapstructure:"type" csv:"Type"` // "CDU/LeafBMC/Spine/Leaf/Edge"
	ManagementInterface net.IP                `json:"ip" mapstructure:"ip" csv:"-"`        // SNMP/REST interface IP (not a distinct BMC)  // Required for SLS
}

ManagementSwitch is a type for managing Management switches

func ReadSwitchCSV

func ReadSwitchCSV(filename string) ([]*ManagementSwitch, error)

ReadSwitchCSV parses a CSV file into a list of ManagementSwitch structs

func (*ManagementSwitch) Normalize

func (mySwitch *ManagementSwitch) Normalize() error

Normalize the values of a Management switch

func (*ManagementSwitch) Validate

func (mySwitch *ManagementSwitch) Validate() error

Validate ManagementSwitch contents

type ManagementSwitchBrand

type ManagementSwitchBrand string

ManagementSwitchBrand known list of Management switch brands

func (ManagementSwitchBrand) String

func (msb ManagementSwitchBrand) String() string

type ManagementSwitchType

type ManagementSwitchType string

ManagementSwitchType the type of management switch CDU/LeafBMC/Spine/Leaf/Edge

func (ManagementSwitchType) String

func (mst ManagementSwitchType) String() string

type PinnedReservation

type PinnedReservation struct {
	IPByte  uint8
	Aliases []string
}

PinnedReservation is a simple struct to work with our abomination of a PinnedMetalLBReservations

Jump to

Keyboard shortcuts

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