netutil

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignFirstHostIP

func AssignFirstHostIP(ifaceName, cidr string) error

AssignFirstHostIP assigns the first host IP of cidr to the named interface. e.g. cidr="10.9.5.0/24" → assigns 10.9.5.1/24 to ifaceName.

func AssignFirstHostIPToLink(link netlink.Link, cidr string) error

AssignFirstHostIPToLink assigns the first host IP of cidr to an already-resolved link. Use when the caller already holds a netlink.Link (avoids a second LinkByName lookup).

func AssignIfaceIP

func AssignIfaceIP(ifaceName, cidr string) error

AssignIfaceIP assigns cidr (e.g. "10.8.0.1/24") to the named interface and brings it up. Idempotent — EEXIST is not an error.

func FirstHostCIDR

func FirstHostCIDR(subnet *net.IPNet) string

FirstHostCIDR returns the first host address of subnet as "ip/prefix" (e.g. 10.8.0.0/24 → 10.8.0.1/24).

func NextIP

func NextIP(ip net.IP) net.IP

NextIP returns ip+1 (e.g. 10.9.5.0 → 10.9.5.1).

func RemoveFirstHostIP added in v1.1.0

func RemoveFirstHostIP(ifaceName, cidr string)

RemoveFirstHostIP removes only the address installed for this lab binding.

func SubnetCount added in v1.10.0

func SubnetCount(baseCIDR string, childBits int) (uint, error)

SubnetCount is the number of child subnets of childBits that SubnetForIndex can give from baseCIDR (numbers 0 .. count-1). It counts from the literal host address of the base, like SubnetForIndex: "10.8.0.0/10" has the subnets from 10.8.0.0 to the end of its /10.

func SubnetForIndex

func SubnetForIndex(baseCIDR string, childBits int, n uint) (string, error)

SubnetForIndex computes a child subnet by adding n * 2^(32-childBits) to the literal host address in baseCIDR (NOT the masked network address). This lets you write "10.8.0.0/10" to mean "start from 10.8.0.0 within the /10 space". Example: SubnetForIndex("10.8.0.0/10", 24, 5) → "10.8.5.0/24"

func SubnetIndex added in v1.10.0

func SubnetIndex(baseCIDR string, childBits int, cidr string) (uint, error)

SubnetIndex is the number of cidr among the child subnets of baseCIDR: the inverse of SubnetForIndex. The cidr must be a canonical subnet of childBits inside the base.

Types

This section is empty.

Jump to

Keyboard shortcuts

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