ipam

package module
v0.0.0-...-41e40eb Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Provides tools and data structures for managing IP address pools

Provides tools and data structures for caching IP address pools and managing them

Provides tools for handling IP address ranges

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasIp

func HasIp(list *IpAlloc, ip net.IP) bool

Checks if the List has the given IP

func Range2Cidr

func Range2Cidr(start, end net.IP) (r []*net.IPNet)

Types

type IpAlloc

type IpAlloc struct {
	FreeList []IpRange
}

A IP pool containing a list of free IP address ranges. IP addresses can be either v4 or v6, but not both

func New

func New() *IpAlloc

Create a new IpAlloc

func NewFromRanges

func NewFromRanges(ranges []IpRange) *IpAlloc

Create a new IpAlloc from an existing freelist

func (*IpAlloc) AddAll

func (ipa *IpAlloc) AddAll(other *IpAlloc) error

Add all IP ranges from another IpAlloc object

func (*IpAlloc) AddIp

func (ipa *IpAlloc) AddIp(ip net.IP)

Add the ip address to the free list

func (*IpAlloc) AddRange

func (ipa *IpAlloc) AddRange(start net.IP, end net.IP)

Add the range of IP addresses provides to the free list example: start:10.2.1.1 and end 10.2.1.1 example: ipa.FreeList = [{10.2.1.2 10.2.1.129}] After the following function the ipa.Freelist = [{10.2.1.1 10.2.1.129}]

func (*IpAlloc) AddRanges

func (ipa *IpAlloc) AddRanges(ranges []IpRange) error

Add all IP ranges from a slice of ranges

func (*IpAlloc) AddSubnet

func (ipa *IpAlloc) AddSubnet(subnet *net.IPNet)

Add the given subnet to the free list. Note that this will include the network address ip|mask in the range.

func (*IpAlloc) Empty

func (ipa *IpAlloc) Empty() bool

Check whether there are no IPs available

func (*IpAlloc) GetIp

func (ipa *IpAlloc) GetIp() (net.IP, error)

Return a free IP address and remove it from the free list

func (*IpAlloc) GetIpChunk

func (ipa *IpAlloc) GetIpChunk(chunkSize int64) ([]IpRange, error)

Return a set of ranges containing at chunkSize IP addresses and remove them from the free list.

func (*IpAlloc) GetSize

func (ipa *IpAlloc) GetSize() int64

Get the number of IPs available in the free list

func (*IpAlloc) Intersect

func (ipa *IpAlloc) Intersect(other *IpAlloc) *IpAlloc

Create a new IpAlloc that is the intersection of the ranges in the ipa and other

func (*IpAlloc) RemoveAll

func (ipa *IpAlloc) RemoveAll(other *IpAlloc) error

Remove all IP ranges from another IpAlloc object

func (*IpAlloc) RemoveIp

func (ipa *IpAlloc) RemoveIp(ip net.IP) bool

Remove the given IP address from the free list

func (*IpAlloc) RemoveRange

func (ipa *IpAlloc) RemoveRange(start net.IP, end net.IP) bool

Remove all the IP addresses in the range from the free list

func (*IpAlloc) RemoveRanges

func (ipa *IpAlloc) RemoveRanges(ranges []IpRange) error

Remove all IP ranges from a slice of ranges

func (*IpAlloc) RemoveSubnet

func (ipa *IpAlloc) RemoveSubnet(subnet *net.IPNet) bool

Remove the given subnet from the free list

type IpCache

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

The data structure to cache the IpV4 and IpV6 lists

func NewIpCache

func NewIpCache() *IpCache

Create a new IpCache which will have 2 lists, the List-0 is for the available IPs and List-1 is for the used Ips.

func (*IpCache) AllocateIp

func (iplists *IpCache) AllocateIp(ipv4 bool) (net.IP, error)

allocates Ip from the pool and updates the Lists also removes the Ip from the available Ips list

func (*IpCache) CombineV4

func (iplists *IpCache) CombineV4() []IpRange

Combines the 2 V4 lists into 1 list

func (*IpCache) CombineV6

func (iplists *IpCache) CombineV6() []IpRange

Combines the 2 V6 lists into 1 list

func (*IpCache) DeallocateIp

func (iplists *IpCache) DeallocateIp(ip net.IP)

Adds the Ip to the used list of Ips

func (*IpCache) GetV4IpCache

func (iplists *IpCache) GetV4IpCache() []*IpAlloc

func (*IpCache) GetV6IpCache

func (iplists *IpCache) GetV6IpCache() []*IpAlloc

func (*IpCache) LoadRanges

func (iplists *IpCache) LoadRanges(ipranges []IpRange)

loads the Iplists from the given IpRange, this function is invoked at the init or the update

func (*IpCache) RemoveIp

func (iplists *IpCache) RemoveIp(ip net.IP) bool

Removes the IP from the respective IpCache Returns true if successful

type IpRange

type IpRange struct {
	Start net.IP `json:"start,omitempty"`
	End   net.IP `json:"end,omitempty"`
}

A range of IP addresses starting at Start and ending at End (inclusive)

Jump to

Keyboard shortcuts

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