Documentation ¶
Overview ¶
Package ipam is a very simple IPAM it administers a single CIDR range, e.g "1000::/124".
The functions are NOT thread safe.
Example ¶
package main import ( "fmt" "github.com/Nordix/simple-ipam/pkg/ipam" ) func main() { cidr := "1100::/120" ipam, _ := ipam.New(cidr) fmt.Printf("Unallocated addresses in %s; %d\n", cidr, ipam.Unallocated()) a, _ := ipam.Allocate() fmt.Printf("Allocated; %s\n", a) ipam.Free(a) }
Output: Unallocated addresses in 1100::/120; 256 Allocated; 1100::
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IPAM ¶
type IPAM struct { // The original CIDR range CIDR net.IPNet // contains filtered or unexported fields }
IPAM holds the ipam state
func (*IPAM) Allocate ¶
Allocate allocates a new address. An error is returned if there is no addresses left.
func (*IPAM) Reserve ¶
Reserve reserves an address. Error if the address is outside the CIDR or if the address is allocated already.
func (*IPAM) ReserveFirstAndLast ¶
func (i *IPAM) ReserveFirstAndLast()
ReserveFirstAndLast reserves the first and last address. These are valid addresses but some programs may refuse to use them. Note that the number of Unallocated addresses may become zero.
func (*IPAM) Unallocated ¶
Unallocated returns the number of unallocated addresses. If the CIDR host-bits are >=64 math.MaxUint64 is always returned.