Skip to content

Commit

Permalink
Add structures for interface bonding information
Browse files Browse the repository at this point in the history
Update net_class.go with new structures to handle bonding driver
information

References:
torvalds/linux/drivers/net/bonding/bond_sysfs.c
torvalds/linux/drivers/net/bonding/bond_sysfs_slave.c
torvalds/linux/include/net/bonding.h
torvalds/linux/include/net/bond_options.h
torvalds/linux/include/net/bond_3ad.h

Signed-off-by: Brandon Ewing <[email protected]>
  • Loading branch information
bewing committed Mar 21, 2022
1 parent 5f46783 commit 23a31a1
Showing 1 changed file with 84 additions and 27 deletions.
111 changes: 84 additions & 27 deletions sysfs/net_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build linux
// +build linux

package sysfs

import (
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"

Expand All @@ -26,36 +28,91 @@ import (

const netclassPath = "class/net"

// NetClassBondAttrs contains info from files in /sys/class/net/<iface>/bonding
// for a bonding controller interface (iface)
type NetClassBondAttrs struct {
ActiveDevice string // /sys/class/net/<iface>/bonding/active_slave
AdActorKey uint16 // /sys/class/net/<iface>/bonding/ad_actor_key (Requires CAP_NET_ADMIN)
AdActorSysPriority uint16 // /sys/class/net/<iface>/bonding/ad_actor_sys_prio (Requires CAP_NET_ADMIN)
AdActorSystem net.HardwareAddr // /sys/class/net/<iface>/bonding/ad_actor_system (Requires CAP_NET_ADMIN)
AdAggregator uint16 // /sys/class/net/<iface>/bonding/ad_aggregator
AdNumPorts uint16 // /sys/class/net/<iface>/bonding/ad_num_ports
AdPartnerKey uint16 // /sys/class/net/<iface>/bonding/ad_partner_key (Requires CAP_NET_ADMIN)
AdPartnerMac net.HardwareAddr // /sys/class/net/<iface>/bonding/ad_partner_mac (Requires CAP_NET_ADMIN)
AdSelect string // /sys/class/net/<iface>/bonding/ad_select
AdUserPortKey uint16 // /sys/class/net/<iface>/bonding/ad_user_port_key (Requires CAP_NET_ADMIN)
AllDevicesActive bool // /sys/class/net/<iface>/bonding/all_slaves_active
ARPAllTargets string // /sys/class/net/<iface>/bonding/arp_all_targets
ARPInterval int64 // /sys/class/net/<iface>/bonding/arp_interval
ARPIPTarget net.IP // /sys/class/net/<iface>/bonding/arp_ip_target
ARPValidate string // /sys/class/net/<iface>/bonding/arp_validate
DownDelay int64 // /sys/class/net/<iface>/bonding/downdelay
FailoverMac string // /sys/class/net/<iface>/bonding/failover_mac
LACPRate string // /sys/class/net/<iface>/bonding/lacp_rate
LPInterval int64 // /sys/class/net/<iface>/bonding/lp_interval
MIIMon int64 // /sys/class/net/<iface>/bonding/miimon
MIIStatus bool // /sys/class/net/<iface>/bonding/mii_status
MinLinks uint64 // /sys/class/net/<iface>/bonding/min_links
Mode string // /sys/class/net/<iface>/bonding/mode
NumberGratuitousArp uint8 // /sys/class/net/<iface>/bonding/num_grat_arp
NumberUnsolicitedNeighborAdvertisement uint8 // /sys/class/net/<iface>/bonding/num_unsol_na
PacketsPerDevice int64 // /sys/class/net/<iface>/bonding/packets_per_slave
PrimaryDevice string // /sys/class/net/<iface>/bonding/primary
PrimaryReselect string // /sys/class/net/<iface>/bonding/primary_reselect
DeviceQueueIDs map[string]uint16 // /sys/class/net/<iface>/bonding/queue_id
ResendIgmp int64 // /sys/class/net/<iface>/bonding/resend_igmp
Devices string // /sys/class/net/<iface>/bonding/slaves
TLBDynamicLB int64 // /sys/class/net/<iface>/bonding/tlb_dynamic_lb
UpDelay int64 // /sys/class/net/<iface>/bonding/updelay
UseCarrier int64 // /sys/class/net/<iface>/bonding/use_carrier
TransmitHashPolicy string // /sys/class/net/<iface>/bonding/xmit_hash_policy
}

// NetClassBondSlaveAttrs contains info from files in /sys/class/net/<iface>/bonding_slave
// for a bonding device interface (iface)
type NetClassBondDeviceAttrs struct {
AdActorOperationalPortState uint8 // /sys/class/net/<iface>/bonding_slave/ad_actor_oper_port_state
AdAggregatorId uint16 // /sys/class/net/<iface>/bonding_slave/ad_aggregator_id
AdPartnerOperationalPortState uint16 // /sys/class/net/<iface>/bonding_slave/ad_partner_oper_port_state
LinkFailureCount uint32 // /sys/class/net/<iface>/bonding_slave/link_failure_count
MiiStatus bool // /sys/class/net/<iface>/bonding_slave/mii_status
PermamentHWAddress net.HardwareAddr // /sys/class/net/<iface>/bonding_slave/perm_hwaddr
QueueID uint16 // /sys/class/net/<iface>/bonding_slave/queue_id
State uint8 // /sys/class/net/<iface>/bonding_slave/state
}

// NetClassIface contains info from files in /sys/class/net/<iface>
// for single interface (iface).
type NetClassIface struct {
Name string // Interface name
AddrAssignType *int64 // /sys/class/net/<iface>/addr_assign_type
AddrLen *int64 // /sys/class/net/<iface>/addr_len
Address string // /sys/class/net/<iface>/address
Broadcast string // /sys/class/net/<iface>/broadcast
Carrier *int64 // /sys/class/net/<iface>/carrier
CarrierChanges *int64 // /sys/class/net/<iface>/carrier_changes
CarrierUpCount *int64 // /sys/class/net/<iface>/carrier_up_count
CarrierDownCount *int64 // /sys/class/net/<iface>/carrier_down_count
DevID *int64 // /sys/class/net/<iface>/dev_id
Dormant *int64 // /sys/class/net/<iface>/dormant
Duplex string // /sys/class/net/<iface>/duplex
Flags *int64 // /sys/class/net/<iface>/flags
IfAlias string // /sys/class/net/<iface>/ifalias
IfIndex *int64 // /sys/class/net/<iface>/ifindex
IfLink *int64 // /sys/class/net/<iface>/iflink
LinkMode *int64 // /sys/class/net/<iface>/link_mode
MTU *int64 // /sys/class/net/<iface>/mtu
NameAssignType *int64 // /sys/class/net/<iface>/name_assign_type
NetDevGroup *int64 // /sys/class/net/<iface>/netdev_group
OperState string // /sys/class/net/<iface>/operstate
PhysPortID string // /sys/class/net/<iface>/phys_port_id
PhysPortName string // /sys/class/net/<iface>/phys_port_name
PhysSwitchID string // /sys/class/net/<iface>/phys_switch_id
Speed *int64 // /sys/class/net/<iface>/speed
TxQueueLen *int64 // /sys/class/net/<iface>/tx_queue_len
Type *int64 // /sys/class/net/<iface>/type
Name string // Interface name
AddrAssignType *int64 // /sys/class/net/<iface>/addr_assign_type
AddrLen *int64 // /sys/class/net/<iface>/addr_len
Address string // /sys/class/net/<iface>/address
Broadcast string // /sys/class/net/<iface>/broadcast
BondAttrs NetClassBondAttrs // /sys/class/net/<iface>/bonding
BondDeviceAttrs NetClassBondDeviceAttrs // /sys/class/net/<iface>/bonding_slave
Carrier *int64 // /sys/class/net/<iface>/carrier
CarrierChanges *int64 // /sys/class/net/<iface>/carrier_changes
CarrierUpCount *int64 // /sys/class/net/<iface>/carrier_up_count
CarrierDownCount *int64 // /sys/class/net/<iface>/carrier_down_count
DevID *int64 // /sys/class/net/<iface>/dev_id
Dormant *int64 // /sys/class/net/<iface>/dormant
Duplex string // /sys/class/net/<iface>/duplex
Flags *int64 // /sys/class/net/<iface>/flags
IfAlias string // /sys/class/net/<iface>/ifalias
IfIndex *int64 // /sys/class/net/<iface>/ifindex
IfLink *int64 // /sys/class/net/<iface>/iflink
LinkMode *int64 // /sys/class/net/<iface>/link_mode
MTU *int64 // /sys/class/net/<iface>/mtu
NameAssignType *int64 // /sys/class/net/<iface>/name_assign_type
NetDevGroup *int64 // /sys/class/net/<iface>/netdev_group
OperState string // /sys/class/net/<iface>/operstate
PhysPortID string // /sys/class/net/<iface>/phys_port_id
PhysPortName string // /sys/class/net/<iface>/phys_port_name
PhysSwitchID string // /sys/class/net/<iface>/phys_switch_id
Speed *int64 // /sys/class/net/<iface>/speed
TxQueueLen *int64 // /sys/class/net/<iface>/tx_queue_len
Type *int64 // /sys/class/net/<iface>/type
}

// NetClass is collection of info for every interface (iface) in /sys/class/net. The map keys
Expand Down

0 comments on commit 23a31a1

Please sign in to comment.