diff --git a/devlink_linux.go b/devlink_linux.go index 7d57080..ef20a1f 100644 --- a/devlink_linux.go +++ b/devlink_linux.go @@ -1,11 +1,11 @@ package netlink import ( - "syscall" - "fmt" "github.com/vishvananda/netlink/nl" "golang.org/x/sys/unix" + "net" + "syscall" ) // DevlinkDevEswitchAttr represents device's eswitch attributes @@ -27,6 +27,13 @@ type DevlinkDevice struct { Attrs DevlinkDevAttrs } +// DevlinkPortFn represents port function and its attributes +type DevlinkPortFn struct { + HwAddr net.HardwareAddr + State uint8 + OpState uint8 +} + // DevlinkPort represents port and its attributes type DevlinkPort struct { BusName string @@ -37,6 +44,7 @@ type DevlinkPort struct { NetdevIfIndex uint32 RdmaDeviceName string PortFlavour uint16 + Fn *DevlinkPortFn } func parseDevLinkDeviceList(msgs [][]byte) ([]*DevlinkDevice, error) { @@ -302,6 +310,18 @@ func (port *DevlinkPort) parseAttributes(attrs []syscall.NetlinkRouteAttr) error port.RdmaDeviceName = string(a.Value) case nl.DEVLINK_ATTR_PORT_FLAVOUR: port.PortFlavour = native.Uint16(a.Value) + case nl.DEVLINK_ATTR_PORT_FUNCTION: + port.Fn = &DevlinkPortFn{} + for nested := range nl.ParseAttributes(a.Value) { + switch nested.Type { + case nl.DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR: + port.Fn.HwAddr = nested.Value[:] + case nl.DEVLINK_PORT_FN_ATTR_STATE: + port.Fn.State = uint8(nested.Value[0]) + case nl.DEVLINK_PORT_FN_ATTR_OPSTATE: + port.Fn.OpState = uint8(nested.Value[0]) + } + } } } return nil diff --git a/devlink_test.go b/devlink_test.go index 6014e56..47e845d 100644 --- a/devlink_test.go +++ b/devlink_test.go @@ -66,5 +66,8 @@ func TestDevLinkGetPortByIndex(t *testing.T) { t.Fatal(err) } t.Log(*p) + if p.Fn != nil { + t.Log("function attributes = " , *p.Fn) + } } } diff --git a/nl/devlink_linux.go b/nl/devlink_linux.go index aa6155e..f98ee69 100644 --- a/nl/devlink_linux.go +++ b/nl/devlink_linux.go @@ -27,6 +27,7 @@ const ( DEVLINK_ATTR_ESWITCH_INLINE_MODE = 26 DEVLINK_ATTR_ESWITCH_ENCAP_MODE = 62 DEVLINK_ATTR_PORT_FLAVOUR = 77 + DEVLINK_ATTR_PORT_FUNCTION = 145 ) const ( @@ -53,6 +54,8 @@ const ( DEVLINK_PORT_FLAVOUR_PCI_PF = 3 DEVLINK_PORT_FLAVOUR_PCI_VF = 4 DEVLINK_PORT_FLAVOUR_VIRTUAL = 5 + DEVLINK_PORT_FLAVOUR_UNUSED = 6 + DEVLINK_PORT_FLAVOUR_PCI_SF = 7 ) const ( @@ -61,3 +64,19 @@ const ( DEVLINK_PORT_TYPE_ETH = 2 DEVLINK_PORT_TYPE_IB = 3 ) + +const ( + DEVLINK_PORT_FUNCTION_ATTR_HW_ADDR = 1 + DEVLINK_PORT_FN_ATTR_STATE = 2 + DEVLINK_PORT_FN_ATTR_OPSTATE = 3 +) + +const ( + DEVLINK_PORT_FN_STATE_INACTIVE = 0 + DEVLINK_PORT_FN_STATE_ACTIVE = 1 +) + +const ( + DEVLINK_PORT_FN_OPSTATE_DETACHED = 0 + DEVLINK_PORT_FN_OPSTATE_ATTACHED = 1 +)