ipam

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPool

func AddPool(db *gorm.DB, nsID uint, raw string) (*models.IpamNamespacePrefix, error)

func Allocate

func Allocate(db *gorm.DB, nsID, vrfID uint, raw, description string, dhcp PrefixDHCP) (*models.IpamPrefix, error)

func ContainingPrefix added in v1.1.0

func ContainingPrefix(prefixes []models.IpamPrefix, vrfs map[uint]models.IpamVRF, host netip.Prefix, vrfName string) *models.IpamPrefix

ContainingPrefix picks the most-specific allocated prefix that contains host. When vrfName is non-empty, only prefixes in a VRF of that name (case-insensitive) are considered.

func CreateVRF

func CreateVRF(db *gorm.DB, nsID uint, w VRFWrite) (*models.IpamVRF, error)

func DefaultGateway added in v1.0.6

func DefaultGateway(prefix netip.Prefix) netip.Addr

DefaultGateway is the first usable address: network + 1 for prefixes with a network/broadcast pair, otherwise the prefix address itself.

func DeleteNamespace

func DeleteNamespace(db *gorm.DB, id uint) error

func DeletePool

func DeletePool(db *gorm.DB, nsID, poolID uint) error

func DeletePrefix

func DeletePrefix(db *gorm.DB, nsID, prefixID uint) error

func DeleteVRF

func DeleteVRF(db *gorm.DB, nsID, vrfID uint) error

func DhcpEnabled added in v1.0.6

func DhcpEnabled(db *gorm.DB) bool

DhcpEnabled reports Settings.DhcpEnabled (nil/false = off). Disabling the flag only hides per-prefix DHCP UI and the DNS MAC column — it does not touch rows.

func Enabled

func Enabled(db *gorm.DB) bool

Enabled reports Settings.IpamEnabled (nil/false = off). Disabling the flag only hides the UI and 404s /api/ipam/* — it does not touch rows.

func EnsureEmptyNamespace added in v1.1.1

func EnsureEmptyNamespace(db *gorm.DB) (*models.IpamNamespace, error)

EnsureEmptyNamespace returns the unnamed namespace, creating it (and its default VRF) if needed. Prefixes and extra VRFs stored here are shown at the forest root.

func ListDhcpPrefixes added in v1.0.6

func ListDhcpPrefixes(db *gorm.DB) ([]models.IpamPrefix, error)

ListDhcpPrefixes returns every allocated prefix with DHCP enabled, across namespaces. Used by factum2-dns to build the dnsmgr2 prefix include.

func ListPools

func ListPools(db *gorm.DB, nsID uint) ([]models.IpamNamespacePrefix, error)

func ListPrefixes

func ListPrefixes(db *gorm.DB, nsID uint) ([]models.IpamPrefix, error)

func ListVRFs

func ListVRFs(db *gorm.DB, nsID uint) ([]models.IpamVRF, error)

func ParseNodeKey

func ParseNodeKey(s string) (string, uint, error)

ParseNodeKey splits "ns:3" into ("ns", 3).

func ParsePrefix

func ParsePrefix(s string) (netip.Prefix, error)

ParsePrefix accepts a CIDR or a bare address that means "the whole family": 0.0.0.0 and 0.0.0.0/0 are IPv4-any; :: and ::/0 are IPv6-any. The result is always masked (10.1.2.3/24 → 10.1.2.0/24).

func ResolveAddressPrefix added in v1.1.0

func ResolveAddressPrefix(db *gorm.DB, addr *models.Address, host netip.Prefix, vrfName string, preferredID *uint) error

ResolveAddressPrefix sets addr.PrefixID to the covering allocated prefix. preferredID, when non-nil, must contain the address. vrfName disambiguates overlapping namespaces. Returns a 400 StatusError when no covering prefix exists (or the preferred id is invalid).

func SplitLines added in v1.0.6

func SplitLines(s string) []string

SplitLines trims a newline-separated list, dropping empty lines.

func UpdatePrefix

func UpdatePrefix(db *gorm.DB, nsID, prefixID uint, description string, dhcp PrefixDHCP) (*models.IpamPrefix, error)

func UpdateVRF

func UpdateVRF(db *gorm.DB, nsID, vrfID uint, w VRFWrite) (*models.IpamVRF, error)

Types

type HostCell added in v1.1.0

type HostCell struct {
	Address   string `json:"address"`
	CIDR      string `json:"cidr"`
	Allocated bool   `json:"allocated"`
}

HostCell is one address in a prefix occupancy page.

type HostPage added in v1.1.0

type HostPage struct {
	PrefixID   uint       `json:"prefix_id"`
	Prefix     string     `json:"prefix"`
	VRFID      uint       `json:"vrf_id"`
	VRFName    string     `json:"vrf_name"`
	Family     int        `json:"family"`
	Bits       int        `json:"bits"`
	Page       int        `json:"page"`
	PageCount  int        `json:"page_count"`
	PagePrefix string     `json:"page_prefix"`
	PageSize   int        `json:"page_size"`
	Hosts      []HostCell `json:"hosts"`
}

HostPage is one page of hosts inside an allocated prefix. IPv4 prefixes longer than /24 (more than 256 addresses) are paged as successive /24s. IPv6 prefixes with more than 256 hosts are paged in 256-address chunks.

func PrefixHosts added in v1.1.0

func PrefixHosts(db *gorm.DB, prefixID uint, page int) (*HostPage, error)

type NamespaceView

type NamespaceView struct {
	models.IpamNamespace
	Pools       []models.IpamNamespacePrefix `json:"pools"`
	VRFs        []models.IpamVRF             `json:"vrfs"`
	PrefixCount int64                        `json:"prefix_count"`
	PoolCount   int                          `json:"pool_count"`
	VRFCount    int                          `json:"vrf_count"`
}

NamespaceView is a namespace plus the bits the list/detail pages need without extra round-trips.

func CreateNamespace

func CreateNamespace(db *gorm.DB, name, description string) (*NamespaceView, error)

func GetNamespace

func GetNamespace(db *gorm.DB, id uint) (*NamespaceView, error)

func ListNamespaces

func ListNamespaces(db *gorm.DB) ([]NamespaceView, error)

func UpdateNamespace

func UpdateNamespace(db *gorm.DB, id uint, name, description string) (*NamespaceView, error)

type PrefixDHCP added in v1.0.6

type PrefixDHCP struct {
	Enabled    bool
	RangeStart string
	RangeEnd   string
	Gateway    string
	DnsServers string
}

PrefixDHCP is the DHCP server config stored on an allocated prefix.

type StatusError

type StatusError struct {
	Status  int
	Message string
}

StatusError is an application-level failure with an HTTP-ish status so handlers don't have to string-match error text.

func (*StatusError) Error

func (e *StatusError) Error() string

type TreeNode

type TreeNode struct {
	Key      string       `json:"key"`
	Title    string       `json:"title"`
	Lazy     bool         `json:"lazy"`
	Expanded bool         `json:"expanded,omitempty"`
	Type     string       `json:"type"`
	Data     TreeNodeData `json:"data"`
	Children []TreeNode   `json:"children,omitempty"`
}

TreeNode is one row of the prefix tree, shaped for Wunderbaum (key, title, lazy, data). Parent/children are computed from CIDR containment.

func Children

func Children(db *gorm.DB, parentKey string) ([]TreeNode, error)

Children returns the next tree level under parentKey (ns:1, vrf:2, …).

func Roots

func Roots(db *gorm.DB) ([]TreeNode, error)

Roots returns the forest. Named namespaces are top-level nodes (with first-level children already loaded). The empty namespace is not shown; its prefixes and extra VRFs sit at the root instead.

func Tree

func Tree(db *gorm.DB, nsID uint, parentRaw string) ([]TreeNode, error)

type TreeNodeData

type TreeNodeData struct {
	Kind           string  `json:"kind"` // namespace | pool | vrf | allocated
	ID             uint    `json:"id"`
	NamespaceID    uint    `json:"namespace_id,omitempty"`
	PoolID         uint    `json:"pool_id,omitempty"`
	PrefixID       uint    `json:"prefix_id,omitempty"`
	VRFID          uint    `json:"vrf_id,omitempty"`
	VRFName        string  `json:"vrf_name,omitempty"`
	IsDefault      bool    `json:"is_default,omitempty"`
	Family         int     `json:"family"`
	Description    string  `json:"description,omitempty"`
	Used           string  `json:"used"`
	UsedFrac       float64 `json:"used_frac"`
	ChildCount     int     `json:"child_count"`
	DhcpEnabled    bool    `json:"dhcp_enabled,omitempty"`
	DhcpRangeStart string  `json:"dhcp_range_start,omitempty"`
	DhcpRangeEnd   string  `json:"dhcp_range_end,omitempty"`
	DhcpGateway    string  `json:"dhcp_gateway,omitempty"`
	DhcpDnsServers string  `json:"dhcp_dns_servers,omitempty"`
	RD             string  `json:"rd,omitempty"`
	ImportRT       string  `json:"import_rt,omitempty"`
	ExportRT       string  `json:"export_rt,omitempty"`
	Source         string  `json:"source,omitempty"`
	NetboxID       uint    `json:"netbox_id,omitempty"`
}

type VRFListItem added in v1.1.0

type VRFListItem struct {
	ID            uint   `json:"id"`
	NamespaceID   uint   `json:"namespace_id"`
	NamespaceName string `json:"namespace_name"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	IsDefault     bool   `json:"is_default"`
	RD            string `json:"rd"`
	ImportRT      string `json:"import_rt"`
	ExportRT      string `json:"export_rt"`
	Source        string `json:"source"`
	PrefixCount   int64  `json:"prefix_count"`
}

VRFListItem is a VRF plus its namespace name for the address picker.

func ListAllVRFs added in v1.1.0

func ListAllVRFs(db *gorm.DB) ([]VRFListItem, error)

type VRFWrite added in v1.1.1

type VRFWrite struct {
	Name        string
	Description string
	RD          string
	ImportRT    string
	ExportRT    string
}

VRFWrite is the operator-editable subset of a VRF. Source/NetboxID are sync-managed and never accepted from the API.

Jump to

Keyboard shortcuts

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