Documentation
¶
Index ¶
- Constants
- func BondModeToString(mode uint8) string
- func CollectKernelArgs() []string
- func DefaultRoute() (iface, gw string, err error)
- func GenerateBondCmdline(info *NetworkInfo, bond *LinkInfo, bondName string) string
- func GenerateIPCmdline(ip, gateway, netmask, hostname, device string) string
- func GenerateVLANCmdline(info *NetworkInfo, vlan *LinkInfo, vlanName string) string
- func GetHostname() string
- func HashPolicyToString(policy uint8) string
- func IfaceAddr(name string) (ip, mask string, err error)
- func LACPRateToString(rate uint8) string
- func PrettyName(name string) string
- type BondMasterSpec
- type LinkInfo
- type NetworkInfo
- func (n *NetworkInfo) GetBondSlaves(masterIndex uint32) []*LinkInfo
- func (n *NetworkInfo) GetBridgePorts(masterIndex uint32) []*LinkInfo
- func (n *NetworkInfo) GetLinkByIndex(index uint32) *LinkInfo
- func (n *NetworkInfo) GetLinkByName(name string) *LinkInfo
- func (n *NetworkInfo) GetVLANChain(link *LinkInfo) []*LinkInfo
- type VLANSpec
Constants ¶
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.
const ( LACPRateSlow uint8 = 0 LACPRateFast uint8 = 1 )
LACP rate constants.
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 ¶
BondModeToString converts bond mode constant to kernel string.
func CollectKernelArgs ¶
func CollectKernelArgs() []string
CollectKernelArgs collects kernel arguments for network configuration.
func DefaultRoute ¶
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 ¶
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 HashPolicyToString ¶
HashPolicyToString converts hash policy constant to kernel string.
func LACPRateToString ¶
LACPRateToString converts LACP rate to kernel string.
func PrettyName ¶
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) IsBondSlave ¶
IsBondSlave returns true if the link is a bond slave.
func (*LinkInfo) IsBridgeSlave ¶
IsBridgeSlave returns true if the link is a bridge port.
func (*LinkInfo) IsPhysical ¶
IsPhysical returns true if the link is a physical ethernet 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).