network

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2026 License: MIT Imports: 7 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"`
	Provider     string     `json:"provider,omitempty"`      // "native", "aws", "azure", "gcp"; default "native"
	ExternalID   string     `json:"external_id,omitempty"`   // provider resource ID (e.g. subnet-xxxx)
	ConnectionID *uuid.UUID `json:"connection_id,omitempty"` // cloud connection used to sync
	DeletedAt    *time.Time `json:"deleted_at,omitempty"`    // set when soft-deleted (pending cloud delete on next sync)
}

Allocation represents an allocation of a network block. Provider/ExternalID/ConnectionID support cloud-synced allocations (e.g. AWS VPC subnets). DeletedAt is set when the allocation is soft-deleted (IPAM conflict); sync will delete it in the cloud then remove the row.

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
	Provider       string     `json:"provider,omitempty"`        // "native", "aws", "azure", "gcp"; default "native"
	ExternalID     string     `json:"external_id,omitempty"`     // provider resource ID (e.g. vpc-xxxx)
	ConnectionID   *uuid.UUID `json:"connection_id,omitempty"`   // cloud connection used to sync
	DeletedAt      *time.Time `json:"deleted_at,omitempty"`      // set when soft-deleted (pending cloud delete on next sync)
}

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. Provider/ExternalID/ConnectionID support cloud integrations (e.g. AWS allocation -> Block for a VPC). DeletedAt is set when the block is soft-deleted (IPAM conflict); sync will delete it in the cloud then remove the row.

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"`
	Provider       string     `json:"provider,omitempty"`       // "native", "aws", "azure", "gcp"; default "native"
	ExternalID     string     `json:"external_id,omitempty"`    // provider resource ID (e.g. ipam-pool-xxxx)
	ConnectionID   *uuid.UUID `json:"connection_id,omitempty"`  // cloud connection used to sync
	ParentPoolID   *uuid.UUID `json:"parent_pool_id,omitempty"` // for sub-pools (e.g. AWS IPAM nested pools)
	DeletedAt      *time.Time `json:"deleted_at,omitempty"`     // set when soft-deleted (pending cloud delete on next sync)
}

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 Provider/ExternalID/ConnectionID/ParentPoolID support cloud integrations (e.g. AWS IPAM sub-pools). DeletedAt is set when the pool is soft-deleted (IPAM conflict resolution); sync will delete it in the cloud then remove the row.

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