ipstore

package
v0.0.0-...-f26629f Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 2

Documentation

Index

Constants

View Source
const (
	// Mask size beyond 30 won't be accepted since the .0 and .255 are reserved
	MaxMask = 30
	// MaxMaskIPv6 is the maximum prefix length for IPv6 subnets (/126 minimum for 4 addresses)
	MaxMaskIPv6 = 126
	// This assumes all the ip start with 1 for now before we address
	// the issue: https://github.com/aws/amazon-ecs-cni-plugins/issues/37
	IPPrefix = "1"
	// IPPrefixV6 is the prefix for IPv6 addresses in the database
	IPPrefixV6 = "6"
	// LastKnownIPv6Key is the key used to store the last allocated IPv6 address in the database
	LastKnownIPv6Key = "lastKnownIPv6"
)

Variables

This section is empty.

Functions

func NextIP

func NextIP(ip net.IP, subnet net.IPNet) (net.IP, error)

NextIP returns the next ip in the subnet

func NextIPv6

func NextIPv6(ip net.IP, subnet net.IPNet) (net.IP, error)

NextIPv6 returns the next IP in an IPv6 subnet It handles 128-bit arithmetic using math/big and skips the network address (IPv6 has no broadcast address to skip)

Types

type Config

type Config struct {
	DB                string
	PersistConnection bool
	Bucket            string
	ConnectionTimeout time.Duration
}

Config represents the configuration for boltdb opermation where the ip address are stored

type IPAllocator

type IPAllocator interface {
	GetAvailableIP(string) (string, error)
	GetAvailableIPv6(string) (string, error)
	Get(string) (string, error)
	Assign(string, string) error
	Update(string, string) error
	Release(string) error
	ReleaseByID(string) (ipv4Released, ipv6Released string, err error)
	Exists(string) (bool, error)
	SetLastKnownIP(net.IP)
	SetLastKnownIPv6(net.IP)
	Close()
}

IPAllocator defines the operation for an ip allocator

func NewIPAllocator

func NewIPAllocator(options *Config, subnet net.IPNet) (IPAllocator, error)

NewIPAllocator creates an ip manager from the IPAM and db configuration

func NewIPAllocatorDualStack

func NewIPAllocatorDualStack(options *Config, subnetV4, subnetV6 *net.IPNet) (IPAllocator, error)

NewIPAllocatorDualStack creates an IP manager supporting both IPv4 and IPv6 subnetV4 and subnetV6 can be nil if that stack is not configured

type IPManager

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

IPManager is responsible for managing the ip addresses using boltdb

func (*IPManager) Assign

func (manager *IPManager) Assign(ip string, id string) error

Assign marks the ip as used or return an error if the ip has already been used

func (*IPManager) Close

func (manager *IPManager) Close()

Close will close the connection to the db

func (*IPManager) Exists

func (manager *IPManager) Exists(ip string) (bool, error)

Exists checks whether the ip is used or not

func (*IPManager) Get

func (manager *IPManager) Get(ip string) (string, error)

Get returns the id by which the ip was used and return empty if the key not exists

func (*IPManager) GetAvailableIP

func (manager *IPManager) GetAvailableIP(id string) (string, error)

GetAvailableIP returns the next available ip address

func (*IPManager) GetAvailableIPv6

func (manager *IPManager) GetAvailableIPv6(id string) (string, error)

GetAvailableIPv6 returns the next available IPv6 address from the configured subnet

func (*IPManager) Release

func (manager *IPManager) Release(ip string) error

Release marks the ip as available or return an error if the ip is avaialble already

func (*IPManager) ReleaseByID

func (manager *IPManager) ReleaseByID(id string) (ipv4Released, ipv6Released string, err error)

ReleaseByID releases all IPs (v4 and v6) associated with an ID It searches both IPv4 and IPv6 prefixes in the database and returns both released IPs

func (*IPManager) SetLastKnownIP

func (manager *IPManager) SetLastKnownIP(ip net.IP)

SetLastKnownIP updates the record of last visited ip address

func (*IPManager) SetLastKnownIPv6

func (manager *IPManager) SetLastKnownIPv6(ip net.IP)

SetLastKnownIPv6 updates the record of last visited IPv6 address

func (*IPManager) UniqueID

func (manager *IPManager) UniqueID(id string) (bool, error)

UniqueID checks whether the id has already existed in the ipam

func (*IPManager) UniqueIDDualStack

func (manager *IPManager) UniqueIDDualStack(id string) (bool, error)

UniqueIDDualStack checks whether the id has already existed in the ipam for both IPv4 and IPv6

func (*IPManager) UniqueIDv6

func (manager *IPManager) UniqueIDv6(id string) (bool, error)

UniqueIDv6 checks whether the id has already existed in the IPv6 addresses only

func (*IPManager) Update

func (manager *IPManager) Update(key string, value string) error

Update updates the value of existed key in the db

Directories

Path Synopsis
Package mock_ipstore is a generated GoMock package.
Package mock_ipstore is a generated GoMock package.

Jump to

Keyboard shortcuts

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