addrset

package
v0.0.0-...-e82d903 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package addrset implements a set of IP addresses.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotAvailable is returned when no more addresses are available to set
	ErrNotAvailable = errors.New("address not available")
	// ErrAllocated is returned when the specific address requested is already allocated
	ErrAllocated = errors.New("address already allocated")
)

Functions

This section is empty.

Types

type AddrSet

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

AddrSet is a set of IP addresses.

func New

func New(pool netip.Prefix) *AddrSet

New returns an AddrSet for the range of addresses in pool.

func (*AddrSet) Add

func (as *AddrSet) Add(addr netip.Addr) error

Add adds address addr to the set. If addr is already in the set, it returns a wrapped ErrAllocated. If addr is not in the set's address range, it returns an error.

func (*AddrSet) AddAny

func (as *AddrSet) AddAny(serial bool) (netip.Addr, error)

AddAny adds an arbitrary address to the set, and returns that address. Or, if no addresses are available, it returns a wrapped ErrNotAvailable.

If the address set's pool contains fewer than 1<<maxBitsPerBitmap addresses, AddAny will add any address from the entire set. If the pool is bigger than that, AddAny will only consider the first 1<<maxBitsPerBitmap addresses. If those are all allocated, it returns ErrNotAvailable.

When serial=true, the set is scanned starting from the address following the address most recently set by AddrSet.AddAny (or AddrSet.AddAnyInRange if the range is in the same 1<<maxBitsPerBitmap .

func (*AddrSet) AddAnyInRange

func (as *AddrSet) AddAnyInRange(ipr netip.Prefix, serial bool) (netip.Addr, error)

AddAnyInRange adds an arbitrary address from ipr to the set, and returns that address. Or, if no addresses are available, it returns a wrapped ErrNotAvailable. If ipr is not fully contained within the set's range, it returns an error.

When serial=true, the set is scanned starting from the address following the address most recently set by AddrSet.AddAny or AddrSet.AddAnyInRange.

func (*AddrSet) Remove

func (as *AddrSet) Remove(addr netip.Addr) error

Remove removes addr from the set or, if addr is not in the set's address range it returns an error. If addr is not in the set, it returns nil (removing an address that's not in the set is not an error).

func (*AddrSet) String

func (as *AddrSet) String() string

String returns a description of the address set.

Jump to

Keyboard shortcuts

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