network

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BondModeBalanceRR    uint8 = 0 // balance-rr
	BondModeActiveBackup uint8 = 1 // active-backup
	BondModeBalanceXOR   uint8 = 2 // balance-xor
	BondModeBroadcast    uint8 = 3 // broadcast
	BondMode8023AD       uint8 = 4 // 802.3ad (LACP)
	BondModeBalanceTLB   uint8 = 5 // balance-tlb
	BondModeBalanceALB   uint8 = 6 // balance-alb
)

Bond mode constants.

View Source
const (
	LACPRateSlow uint8 = 0
	LACPRateFast uint8 = 1
)

LACP rate constants.

View Source
const (
	BondXmitHashPolicyLayer2     uint8 = 0
	BondXmitHashPolicyLayer34    uint8 = 1
	BondXmitHashPolicyLayer23    uint8 = 2
	BondXmitHashPolicyEncap23    uint8 = 3
	BondXmitHashPolicyEncap34    uint8 = 4
	BondXmitHashPolicyVlanSrcMAC uint8 = 5
)

Hash policy constants.

Variables

This section is empty.

Functions

func BondModeToString

func BondModeToString(mode uint8) string

BondModeToString converts bond mode constant to kernel string.

func CollectKernelArgs

func CollectKernelArgs() []string

CollectKernelArgs collects kernel arguments for network configuration.

func DefaultRoute

func DefaultRoute() (iface, gw string, err error)

DefaultRoute returns the default route interface and gateway.

func GenerateBondCmdline

func GenerateBondCmdline(info *NetworkInfo, bond *LinkInfo, bondName string) string

GenerateBondCmdline generates kernel cmdline for bond configuration. Format: bond=<bondname>:<slaves>:<options>

func GenerateIPCmdline

func GenerateIPCmdline(ip, gateway, netmask, hostname, device string) string

GenerateIPCmdline generates kernel cmdline for IP configuration. Format: ip=<client-ip>:<server-ip>:<gw-ip>:<netmask>:<hostname>:<device>:<autoconf>

func GenerateVLANCmdline

func GenerateVLANCmdline(info *NetworkInfo, vlan *LinkInfo, vlanName string) string

GenerateVLANCmdline generates kernel cmdline for VLAN configuration. Format: vlan=<vlandev>:<parent>

func GetHostname

func GetHostname() string

GetHostname returns the current system hostname.

func HashPolicyToString

func HashPolicyToString(policy uint8) string

HashPolicyToString converts hash policy constant to kernel string.

func IfaceAddr

func IfaceAddr(name string) (ip, mask string, err error)

IfaceAddr returns the IPv4 address and netmask of the named interface.

func LACPRateToString

func LACPRateToString(rate uint8) string

LACPRateToString converts LACP rate to kernel string.

func PrettyName

func PrettyName(name string) string

PrettyName returns the predictable network interface name based on permanent MAC address. Format: enx<mac> where mac is the permanent hardware MAC address without colons. This ensures the interface name remains consistent across reboots even if the user has modified the active MAC address.

Types

type BondMasterSpec

type BondMasterSpec struct {
	Mode         uint8
	HashPolicy   uint8
	LACPRate     uint8
	MIIMon       uint32
	UpDelay      uint32
	DownDelay    uint32
	ARPInterval  uint32
	ARPIPTargets []netip.Addr
	PrimaryIndex *uint32
	UseCarrier   bool
}

BondMasterSpec represents bond master configuration.

type LinkInfo

type LinkInfo struct {
	Name             string
	Index            uint32
	Type             uint16
	LinkIndex        uint32 // Parent interface index (for VLAN, etc.)
	Flags            uint32
	HardwareAddr     net.HardwareAddr
	MTU              uint32
	MasterIndex      uint32
	OperationalState rtnetlink.OperationalState
	Kind             string
	SlaveKind        string
	BondMaster       *BondMasterSpec
	VLAN             *VLANSpec
}

LinkInfo represents network interface information.

func ResolveNetworkDevice

func ResolveNetworkDevice(info *NetworkInfo, link *LinkInfo) *LinkInfo

ResolveNetworkDevice finds the actual device to use for network configuration. If the device is a bridge, it finds the underlying physical interface or bond. If the device is a bond, it returns the bond itself. If the device is a VLAN, it recursively resolves the parent interface.

func (*LinkInfo) IsBond

func (l *LinkInfo) IsBond() bool

IsBond returns true if the link is a bond interface.

func (*LinkInfo) IsBondSlave

func (l *LinkInfo) IsBondSlave() bool

IsBondSlave returns true if the link is a bond slave.

func (*LinkInfo) IsBridge

func (l *LinkInfo) IsBridge() bool

IsBridge returns true if the link is a bridge interface.

func (*LinkInfo) IsBridgeSlave

func (l *LinkInfo) IsBridgeSlave() bool

IsBridgeSlave returns true if the link is a bridge port.

func (*LinkInfo) IsPhysical

func (l *LinkInfo) IsPhysical() bool

IsPhysical returns true if the link is a physical ethernet interface.

func (*LinkInfo) IsVLAN

func (l *LinkInfo) IsVLAN() bool

IsVLAN returns true if the link is a VLAN interface.

type NetworkInfo

type NetworkInfo struct {
	Links []LinkInfo
	// contains filtered or unexported fields
}

NetworkInfo contains all collected network information.

func CollectNetworkInfo

func CollectNetworkInfo() (*NetworkInfo, error)

CollectNetworkInfo gathers all network interface information via netlink.

func (*NetworkInfo) GetBondSlaves

func (n *NetworkInfo) GetBondSlaves(masterIndex uint32) []*LinkInfo

GetBondSlaves returns slave interfaces for a bond.

func (*NetworkInfo) GetBridgePorts

func (n *NetworkInfo) GetBridgePorts(masterIndex uint32) []*LinkInfo

GetBridgePorts returns port interfaces for a bridge.

func (*NetworkInfo) GetLinkByIndex

func (n *NetworkInfo) GetLinkByIndex(index uint32) *LinkInfo

GetLinkByIndex returns link by index.

func (*NetworkInfo) GetLinkByName

func (n *NetworkInfo) GetLinkByName(name string) *LinkInfo

GetLinkByName returns link by name.

func (*NetworkInfo) GetVLANChain

func (n *NetworkInfo) GetVLANChain(link *LinkInfo) []*LinkInfo

GetVLANChain returns all VLAN interfaces in the path from link to physical/bond. Returns VLANs in order from topmost to lowest (closest to physical).

type VLANSpec

type VLANSpec struct {
	VID      uint16 // VLAN ID (1-4094)
	Protocol uint16 // VLAN protocol (0x8100 for 802.1Q, 0x88a8 for 802.1ad)
}

VLANSpec represents VLAN configuration.

Jump to

Keyboard shortcuts

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