ipam

package
v1.32.7 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

This section is empty.

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 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 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.

Jump to

Keyboard shortcuts

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