network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CIDRAddressCount

func CIDRAddressCount(cidr string) (*big.Int, error)

CIDRAddressCount returns the number of addresses in the CIDR (2^(bits-prefix)) for both IPv4 and IPv6. Caller can use the result for display or comparison.

func CIDRAddressCountFitsInt64

func CIDRAddressCountFitsInt64(cidr string) bool

CIDRAddressCountFitsInt64 reports whether the CIDR's address count fits in int64.

func CIDRAddressCountInt64

func CIDRAddressCountInt64(cidr string) int64

CIDRAddressCountInt64 returns the address count as int64 when it fits; otherwise 0. Used for backward-compat storage (total_ips) when value fits in BIGINT.

func CIDRAddressCountString

func CIDRAddressCountString(cidr string) string

CIDRAddressCountString returns the address count as a decimal string for API/display. Returns "0" on parse error so callers can still display something safe.

func Contains

func Contains(supernet string, cidr string) (bool, error)

Contains checks if the supernet contains the specified CIDR block.

func IsCIDRAvailable

func IsCIDRAvailable(supernet string, cidr string) (bool, error)

IsCIDRAvailable checks if the specified CIDR block is available within the given supernet.

func NextAvailableCIDR

func NextAvailableCIDR(supernet string, prefixLength int) (string, error)

NextAvailableCIDR finds the next available CIDR block within the given supernet. It attempts best-effort bin-packing to minimize fragmentation of the supernet.

func NextAvailableCIDRWithAllocations

func NextAvailableCIDRWithAllocations(supernet string, prefixLength int, allocatedCIDRs []string) (string, error)

NextAvailableCIDRWithAllocations returns a suggested CIDR of the given prefix length within the supernet, considering existing allocations (IPv4 only). It bin-packs: first tries to fill a gap between allocations; if no gap fits, returns the next available CIDR after the last allocation. If allocatedCIDRs is empty, delegates to NextAvailableCIDR.

func Overlaps

func Overlaps(cidr1 string, cidr2 string) (bool, error)

Overlaps checks if two CIDR blocks overlap.

func ValidateCIDR

func ValidateCIDR(cidr string) bool

ValidateCIDR checks if the provided CIDR block is valid.

Types

type Allocation

type Allocation struct {
	Id    uuid.UUID `json:"id"`
	Name  string    `json:"name"`
	Block Block     `json:"block"`
}

Allocation represents an allocation of a network block.

type Block

type Block struct {
	ID             uuid.UUID  `json:"id"`
	Name           string     `json:"name"`
	CIDR           string     `json:"cidr"`
	Usage          Usage      `json:"usage"`
	Children       []Block    `json:"children,omitempty"`
	EnvironmentID  uuid.UUID  `json:"environment_id,omitempty"`
	OrganizationID uuid.UUID  `json:"organization_id,omitempty"` // for orphan blocks; blocks in envs get org via environment
	PoolID         *uuid.UUID `json:"pool_id,omitempty"`         // optional; block CIDR must be contained in pool's CIDR
}

Block represents a network block with a CIDR notation. When EnvironmentID is nil (orphan block), OrganizationID scopes the block to that organization. PoolID optionally links the block to an environment pool; the block's CIDR must be contained in the pool's CIDR.

type Environment

type Environment struct {
	Id             uuid.UUID `json:"id"`
	Name           string    `json:"name"`
	OrganizationID uuid.UUID `json:"organization_id"`
	Block          []Block   `json:"block"`
}

Environment represents a network environment. It containers a supernet block.

type Pool

type Pool struct {
	ID             uuid.UUID `json:"id"`
	OrganizationID uuid.UUID `json:"organization_id"`
	EnvironmentID  uuid.UUID `json:"environment_id"`
	Name           string    `json:"name"`
	CIDR           string    `json:"cidr"`
}

Pool is a range of CIDRs that network blocks in an environment can draw from. Pools are scoped to an organization (via environment). Hierarchy: Organization -> Environment -> Pool(s) -> Network blocks -> Allocations

type Usage

type Usage struct {
	TotalIPs     int `json:"total_ips"`
	UsedIPs      int `json:"used_ips"`
	AvailableIPs int `json:"available_ips"`
}

Jump to

Keyboard shortcuts

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