diff --git a/devlink_linux.go b/devlink_linux.go index 19a0ca7e4..7fa1a392b 100644 --- a/devlink_linux.go +++ b/devlink_linux.go @@ -3,7 +3,6 @@ package netlink import ( "errors" "fmt" - "net" "strings" "syscall" @@ -11,104 +10,6 @@ import ( "golang.org/x/sys/unix" ) -// DevlinkDevEswitchAttr represents device's eswitch attributes -type DevlinkDevEswitchAttr struct { - Mode string - InlineMode string - EncapMode string -} - -// DevlinkDevAttrs represents device attributes -type DevlinkDevAttrs struct { - Eswitch DevlinkDevEswitchAttr -} - -// DevlinkDevice represents device and its attributes -type DevlinkDevice struct { - BusName string - DeviceName string - Attrs DevlinkDevAttrs -} - -// DevlinkPortFn represents port function and its attributes -type DevlinkPortFn struct { - HwAddr net.HardwareAddr - State uint8 - OpState uint8 -} - -// DevlinkPortFnSetAttrs represents attributes to set -type DevlinkPortFnSetAttrs struct { - FnAttrs DevlinkPortFn - HwAddrValid bool - StateValid bool -} - -// DevlinkPort represents port and its attributes -type DevlinkPort struct { - BusName string - DeviceName string - PortIndex uint32 - PortType uint16 - NetdeviceName string - NetdevIfIndex uint32 - RdmaDeviceName string - PortFlavour uint16 - Fn *DevlinkPortFn - PortNumber *uint32 - PfNumber *uint16 - VfNumber *uint16 - SfNumber *uint32 - ControllerNumber *uint32 - External *bool -} - -type DevLinkPortAddAttrs struct { - Controller uint32 - SfNumber uint32 - PortIndex uint32 - PfNumber uint16 - SfNumberValid bool - PortIndexValid bool - ControllerValid bool -} - -// DevlinkDeviceInfo represents devlink info -type DevlinkDeviceInfo struct { - Driver string - SerialNumber string - BoardID string - FwApp string - FwAppBoundleID string - FwAppName string - FwBoundleID string - FwMgmt string - FwMgmtAPI string - FwMgmtBuild string - FwNetlist string - FwNetlistBuild string - FwPsidAPI string - FwUndi string -} - -// DevlinkResource represents a device resource -type DevlinkResource struct { - Name string - ID uint64 - Size uint64 - SizeNew uint64 - SizeMin uint64 - SizeMax uint64 - SizeGranularity uint64 - PendingChange bool - Unit uint8 - SizeValid bool - OCCValid bool - OCCSize uint64 - Parent *DevlinkResource - Children []DevlinkResource -} - // parseAttributes parses provided Netlink Attributes and populates DevlinkResource, returns error if occured func (dlr *DevlinkResource) parseAttributes(attrs map[uint16]syscall.NetlinkRouteAttr) error { var attr syscall.NetlinkRouteAttr @@ -201,13 +102,6 @@ func (dlr *DevlinkResource) parseAttributes(attrs map[uint16]syscall.NetlinkRout return nil } -// DevlinkResources represents all devlink resources of a devlink device -type DevlinkResources struct { - Bus string - Device string - Resources []DevlinkResource -} - // parseAttributes parses provided Netlink Attributes and populates DevlinkResources, returns error if occured func (dlrs *DevlinkResources) parseAttributes(attrs map[uint16]syscall.NetlinkRouteAttr) error { var attr syscall.NetlinkRouteAttr @@ -254,22 +148,6 @@ func (dlrs *DevlinkResources) parseAttributes(attrs map[uint16]syscall.NetlinkRo return nil } -// DevlinkParam represents parameter of the device -type DevlinkParam struct { - Name string - IsGeneric bool - Type uint8 // possible values are in nl.DEVLINK_PARAM_TYPE_* constants - Values []DevlinkParamValue -} - -// DevlinkParamValue contains values of the parameter -// Data field contains specific type which can be casted by unsing info from the DevlinkParam.Type field -type DevlinkParamValue struct { - rawData []byte - Data interface{} - CMODE uint8 // possible values are in nl.DEVLINK_PARAM_CMODE_* constants -} - // parseAttributes parses provided Netlink Attributes and populates DevlinkParam, returns error if occured func (dlp *DevlinkParam) parseAttributes(attrs []syscall.NetlinkRouteAttr) error { var valuesList [][]syscall.NetlinkRouteAttr @@ -857,8 +735,10 @@ func (h *Handle) DevlinkSplitPort(port *DevlinkPort, count uint32) error { return err } +// DevlinkSplitPort splits the specified devlink port into count logical ports. +// It returns an error if the operation fails. func DevlinkSplitPort(port *DevlinkPort, count uint32) error { - return pkgHandle.DevlinkSplitPort(port, count); + return pkgHandle.DevlinkSplitPort(port, count) } // DevlinkUnsplitPort: unsplit devlink port @@ -875,8 +755,11 @@ func (h *Handle) DevlinkUnsplitPort(port *DevlinkPort) error { return err } +// DevlinkUnsplitPort unsplits a previously split devlink port represented by p. +// It reverses a prior split operation for the provided port and returns an error +// if the operation fails. func DevlinkUnsplitPort(port *DevlinkPort) error { - return pkgHandle.DevlinkUnsplitPort(port); + return pkgHandle.DevlinkUnsplitPort(port) } // DevlinkSetDeviceParam set specific parameter for devlink device @@ -1233,4 +1116,4 @@ func parseInfoData(data map[string]string) *DevlinkDeviceInfo { func parseInfoValue(value []byte) string { v := strings.ReplaceAll(string(value), "\x00", "") return strings.TrimSpace(v) -} +} \ No newline at end of file diff --git a/devlink_unspecified.go b/devlink_unspecified.go new file mode 100644 index 000000000..c2ad608b9 --- /dev/null +++ b/devlink_unspecified.go @@ -0,0 +1,107 @@ +//go:build !linux +// +build !linux + +package netlink + +// DevLinkGetDeviceList retrieves the list of devlink devices available on the system. +// On non-Linux builds this function is not implemented and returns nil, ErrNotImplemented. +func DevLinkGetDeviceList() ([]*DevlinkDevice, error) { + return nil, ErrNotImplemented +} + +// DevLinkGetDeviceByName looks up the Devlink device identified by the bus and device names. +// On non-Linux builds this always returns nil and ErrNotImplemented. +func DevLinkGetDeviceByName(Bus string, Device string) (*DevlinkDevice, error) { + return nil, ErrNotImplemented +} + +// DevLinkSetEswitchMode sets the eswitch mode of the specified DevlinkDevice to NewMode. +// On platforms where Devlink is not implemented this returns ErrNotImplemented. +func DevLinkSetEswitchMode(Dev *DevlinkDevice, NewMode string) error { + return ErrNotImplemented +} + +// DevLinkGetAllPortList retrieves the list of all devlink ports available on the system. +// On platforms where devlink functionality is unavailable this returns nil and ErrNotImplemented. +func DevLinkGetAllPortList() ([]*DevlinkPort, error) { + return nil, ErrNotImplemented +} + +// DevlinkGetDeviceResources retrieves the resource information for the devlink device specified by bus and device. +// On non-Linux builds this function is unimplemented and returns ErrNotImplemented. +func DevlinkGetDeviceResources(bus string, device string) (*DevlinkResources, error) { + return nil, ErrNotImplemented +} + +// DevlinkGetDeviceParams retrieves the devlink parameters for the device specified by bus and device. +// On non-Linux builds this function is not implemented and returns ErrNotImplemented. +func DevlinkGetDeviceParams(bus string, device string) ([]*DevlinkParam, error) { + return nil, ErrNotImplemented +} + +// DevlinkGetDeviceParamByName retrieves the devlink parameter with the given name for the specified bus and device. +// It returns a pointer to the matching DevlinkParam, or nil and an error if the parameter cannot be obtained. +func DevlinkGetDeviceParamByName(bus string, device string, param string) (*DevlinkParam, error) { + return nil, ErrNotImplemented +} + +// DevlinkSplitPort splits the specified devlink port into the given number of logical ports. +// The function returns ErrNotImplemented on platforms where devlink operations are unavailable. +func DevlinkSplitPort(port *DevlinkPort, count uint32) error { + return ErrNotImplemented +} + +// DevlinkUnsplitPort attempts to unsplit the specified DevlinkPort. +// It always returns ErrNotImplemented on non-Linux platforms. +func DevlinkUnsplitPort(port *DevlinkPort) error { + return ErrNotImplemented +} + +// DevlinkSetDeviceParam sets the named parameter for a devlink device identified by bus and device, +// using cmode to indicate the change mode and value as the new parameter value. +// It returns an error if the parameter could not be set. +func DevlinkSetDeviceParam(bus string, device string, param string, cmode uint8, value interface{}) error { + return ErrNotImplemented +} + +// DevLinkGetPortByIndex retrieves the devlink port identified by the bus, device, and port index. +// On non-Linux builds this function returns nil and ErrNotImplemented. +func DevLinkGetPortByIndex(Bus string, Device string, PortIndex uint32) (*DevlinkPort, error) { + return nil, ErrNotImplemented +} + +// DevLinkPortAdd adds a new devlink port to the specified device. + // + // Bus and Device identify the target device. Flavour selects the port flavour to create; + // Attrs contains creation attributes for the new port. + // + // On success returns the created *DevlinkPort. On unsupported platforms returns nil and ErrNotImplemented. +func DevLinkPortAdd(Bus string, Device string, Flavour uint16, Attrs DevLinkPortAddAttrs) (*DevlinkPort, error) { + return nil, ErrNotImplemented +} + +// DevLinkPortDel deletes the devlink port identified by bus, device, and port index. +// On non-Linux builds this always returns ErrNotImplemented. +func DevLinkPortDel(Bus string, Device string, PortIndex uint32) error { + return ErrNotImplemented +} + +// DevlinkPortFnSet sets function-specific attributes for the devlink port identified +// by the given PCI `Bus` and `Device` strings and `PortIndex`. +// The `FnAttrs` parameter specifies the attributes to apply. +// On non-Linux builds this function is not implemented and returns ErrNotImplemented. +func DevlinkPortFnSet(Bus string, Device string, PortIndex uint32, FnAttrs DevlinkPortFnSetAttrs) error { + return ErrNotImplemented +} + +// DevlinkGetDeviceInfoByName retrieves the DevlinkDeviceInfo for a devlink device identified by its bus and device names. +// On non-Linux builds this function is not implemented and returns ErrNotImplemented. +func DevlinkGetDeviceInfoByName(Bus string, Device string) (*DevlinkDeviceInfo, error) { + return nil, ErrNotImplemented +} + +// DevlinkGetDeviceInfoByNameAsMap returns a map of device information keyed by attribute name for the device identified by bus and device. +// On non-Linux platforms this function returns ErrNotImplemented. +func DevlinkGetDeviceInfoByNameAsMap(Bus string, Device string) (map[string]string, error) { + return nil, ErrNotImplemented +} \ No newline at end of file