Documentation
¶
Overview ¶
Package ipallocator deals with assigning CIDR blocks to environments, and subnets within those blocks for specific networks.
Index ¶
- Constants
- func AlignToBlockBoundary(addr netip.Addr, blockSize int) (netip.Addr, error)
- func FindNextAvailableBlock(allowedPrefix netip.Prefix, allocated []NetworkBlock, reserved []ReservedRange, ...) (netip.Addr, error)
- func GetFirstUsableIP(prefix netip.Prefix) netip.Addr
- func GetGatewayIP(prefix netip.Prefix) netip.Addr
- func GetLastUsableIP(prefix netip.Prefix) netip.Addr
- func GetNextIP(ip netip.Addr) netip.Addr
- func GetNextNIPs(startIP netip.Addr, n int) ([]netip.Addr, error)
- func GetSubnetSize(prefix netip.Prefix) int
- func GetUsableIPCount(prefix netip.Prefix) int
- func IPToUint32(ip netip.Addr) (uint32, error)
- func IsSubnetNameOf(subnetName, parentName string) bool
- func IsSubnetOf(subnet, parent netip.Prefix) bool
- func RangesOverlap(r1, r2 netipx.IPRange) bool
- func Uint32ToIP(n uint32) netip.Addr
- type AllocationParams
- type AllocatorState
- type IPAllocator
- func (i *IPAllocator) AllocateNetworkBlock(ctx restate.ObjectContext, params AllocationParams) (*NetworkBlock, error)
- func (i *IPAllocator) AllocateSubnetBlock(ctx restate.ObjectContext, params SubnetAllocationParams) (*NetworkBlock, error)
- func (i *IPAllocator) GetAllocatedBlocks(ctx restate.ObjectSharedContext) (allocatedBlocks, error)
- func (i *IPAllocator) GetAllocatorState(ctx restate.ObjectSharedContext) (*AllocatorState, error)
- func (i *IPAllocator) GetNetworkBlock(ctx restate.ObjectSharedContext, network string) (*NetworkBlock, error)
- func (i *IPAllocator) GetReservedRanges(ctx restate.ObjectSharedContext) ([]ReservedRange, error)
- func (i *IPAllocator) HasNetworkBlock(ctx restate.ObjectSharedContext, network string) (bool, error)
- func (i *IPAllocator) Initialize(ctx restate.ObjectContext, config IPAllocatorConfig) error
- func (i *IPAllocator) ReleaseNetworkBlock(ctx restate.ObjectContext, network string) error
- func (i *IPAllocator) ReleaseSubnetBlock(ctx restate.ObjectContext, params struct{ ... }) error
- func (i *IPAllocator) ResetAllocator(ctx restate.ObjectContext) error
- type IPAllocatorConfig
- type IPRangeInfo
- type NetworkBlock
- type ReservedRange
- type SubnetAllocationParams
Constants ¶
const ( MethodAllocateNetworkBlock = "AllocateNetworkBlock" MethodAllocateSubnetBlock = "AllocateSubnetBlock" MethodReleaseNetworkBlock = "ReleaseNetworkBlock" MethodReleaseSubnetBlock = "ReleaseSubnetBlock" MethodGetNetworkBlock = "GetNetworkBlock" MethodGetAllocatedNetworkBlocks = "GetAllocatedNetworkBlocks" MethodHasNetworkBlock = "HasNetworkBlock" MethodGetReservedRanges = "GetReservedRanges" MethodInitialize = "Initialize" )
Method names for the IPAllocator service
Variables ¶
This section is empty.
Functions ¶
func AlignToBlockBoundary ¶
AlignToBlockBoundary aligns an IP address to the block boundary for the given block size
func FindNextAvailableBlock ¶
func FindNextAvailableBlock(allowedPrefix netip.Prefix, allocated []NetworkBlock, reserved []ReservedRange, blockSize int) (netip.Addr, error)
FindNextAvailableBlock locates the next available IP block of the requested size
func GetFirstUsableIP ¶
GetFirstUsableIP returns the first usable IP in a subnet (excludes network address)
func GetGatewayIP ¶
GetGatewayIP typically returns the first usable IP as the gateway
func GetLastUsableIP ¶
GetLastUsableIP returns the last usable IP in a subnet (excludes broadcast address)
func GetNextNIPs ¶
GetNextNIPs returns the next n IP addresses after the given IP
func GetSubnetSize ¶
GetSubnetSize returns the total number of IPs in a subnet
func GetUsableIPCount ¶
GetUsableIPCount returns the number of usable IPs (excluding network and broadcast)
func IPToUint32 ¶
IPToUint32 converts an IPv4 address to a uint32 integer
func IsSubnetNameOf ¶
IsSubnetNameOf determines if a subnet name belongs to a parent network
func IsSubnetOf ¶
IsSubnetOf checks if subnet is contained within parent prefix
func RangesOverlap ¶
RangesOverlap checks if two IP ranges overlap
func Uint32ToIP ¶
Uint32ToIP converts a uint32 integer to an IPv4 address
Types ¶
type AllocationParams ¶
type AllocationParams struct {
Network string `json:"network"`
// BlockSize represents a CIDR block, eg 24 = 256.
BlockSize int `json:"blockSize"`
}
AllocationParams defines parameters for allocating a new network block
type AllocatorState ¶
type AllocatorState struct {
AllowedCIDR string `json:"allowedCIDR"`
DefaultBlockSize int `json:"defaultBlockSize"`
ReservedRanges []ReservedRange `json:"reservedRanges"`
AllocatedBlocks allocatedBlocks `json:"allocatedBlocks"`
}
AllocatorState provides a complete overview of the IP allocator configuration and current state
type IPAllocator ¶
type IPAllocator struct{}
IPAllocator manages IP address allocation for networks and their subnets
func (*IPAllocator) AllocateNetworkBlock ¶
func (i *IPAllocator) AllocateNetworkBlock(ctx restate.ObjectContext, params AllocationParams) (*NetworkBlock, error)
AllocateNetworkBlock allocates a new block within the main subnet for a specific network. If the network already has an allocation, returns the existing allocation.
func (*IPAllocator) AllocateSubnetBlock ¶
func (i *IPAllocator) AllocateSubnetBlock(ctx restate.ObjectContext, params SubnetAllocationParams) (*NetworkBlock, error)
AllocateSubnetBlock allocates a subnet within an existing network block The subnet will be named "parentNetwork-subnetName" and must have a larger prefix size than its parent network
func (*IPAllocator) GetAllocatedBlocks ¶
func (i *IPAllocator) GetAllocatedBlocks(ctx restate.ObjectSharedContext) (allocatedBlocks, error)
GetAllocatedBlocks returns all allocated network blocks
func (*IPAllocator) GetAllocatorState ¶
func (i *IPAllocator) GetAllocatorState(ctx restate.ObjectSharedContext) (*AllocatorState, error)
GetAllocatorState returns comprehensive information about the allocator configuration and current state
func (*IPAllocator) GetNetworkBlock ¶
func (i *IPAllocator) GetNetworkBlock(ctx restate.ObjectSharedContext, network string) (*NetworkBlock, error)
GetNetworkBlock returns a specific network's allocation
func (*IPAllocator) GetReservedRanges ¶
func (i *IPAllocator) GetReservedRanges(ctx restate.ObjectSharedContext) ([]ReservedRange, error)
GetReservedRanges returns the reserved ranges from configuration
func (*IPAllocator) HasNetworkBlock ¶
func (i *IPAllocator) HasNetworkBlock(ctx restate.ObjectSharedContext, network string) (bool, error)
HasNetworkBlock checks if a network has an IP allocation
func (*IPAllocator) Initialize ¶
func (i *IPAllocator) Initialize(ctx restate.ObjectContext, config IPAllocatorConfig) error
Initialize sets up the IP allocator with a given configuration, which defines the main subnet this allocator will provide blocks for.
func (*IPAllocator) ReleaseNetworkBlock ¶
func (i *IPAllocator) ReleaseNetworkBlock(ctx restate.ObjectContext, network string) error
ReleaseNetworkBlock removes a network block allocation and any of its subnets
func (*IPAllocator) ReleaseSubnetBlock ¶
func (i *IPAllocator) ReleaseSubnetBlock(ctx restate.ObjectContext, params struct { ParentNetwork string `json:"parentNetwork"` SubnetName string `json:"subnetName"` }, ) error
ReleaseSubnetBlock releases a specific subnet without affecting its parent network
func (*IPAllocator) ResetAllocator ¶
func (i *IPAllocator) ResetAllocator(ctx restate.ObjectContext) error
ResetAllocator clears all state and allows re-initialization
type IPAllocatorConfig ¶
type IPAllocatorConfig struct {
// The overall IP range to allocate from (e.g., "10.0.0.0/8")
AllowedCIDR string `json:"allowedCIDR"`
// Default size of allocated blocks (e.g., 24 for /24 blocks)
DefaultBlockSize int `json:"defaultBlockSize"`
// Ranges that should be excluded from allocation
ReservedRanges []ReservedRange `json:"reservedRanges"`
}
IPAllocatorConfig defines the global configuration for the IP allocator
type IPRangeInfo ¶
type IPRangeInfo struct {
Network string `json:"network"`
Netmask string `json:"netmask"`
Gateway string `json:"gateway"`
Broadcast string `json:"broadcast"`
FirstUsable string `json:"firstUsable"`
LastUsable string `json:"lastUsable"`
TotalIPs int `json:"totalIPs"`
UsableIPs int `json:"usableIPs"`
}
IPRangeInfo provides detailed information about an IP range
func GetIPRangeInfo ¶
func GetIPRangeInfo(cidr string) (*IPRangeInfo, error)
GetIPRangeInfo returns detailed information about an IP range
type NetworkBlock ¶
type NetworkBlock struct {
StartIP string `json:"startIP"`
CIDR string `json:"cidr"`
BlockSize int `json:"blockSize"`
}
NetworkBlock represents an allocated IP block for a network
type ReservedRange ¶
ReservedRange represents an IP range that is reserved and should not be allocated
type SubnetAllocationParams ¶
type SubnetAllocationParams struct {
ParentNetwork string `json:"parentNetwork"`
SubnetName string `json:"subnetName"`
BlockSize int `json:"blockSize"`
Offset int `json:"offset"`
}
SubnetAllocationParams defines parameters for allocating a subnet within a parent network