vfmac

package
v0.1.0-latest-stable Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

README

vfmac

A Go package for managing persistent MAC addresses for Mellanox Virtual Functions (VFs).

Purpose

  • Assigns and persists MAC addresses for all VFs on Mellanox SmartNIC ECPFs.
  • Stores MAC assignments in a TOML config file for persistence across reboots.
  • Ensures each VF gets a unique, stable MAC address.

Configuration

You can override defaults using environment variables:

Variable Default Value Description
VFMAC_CONFIG_DIR /etc/mellanox Directory for config file
VFMAC_CONFIG_FILE dpf-vf-mac-mapping.toml Config file name

Usage Example

import (
  "os"
  "path/to/pkg/vfmac"
)

func main() {
  if err := vfmac.ProcessVFs(); err != nil {
      os.Exit(1)
  }
}

Testing

  • The package abstracts file/OS operations for testability.
  • You can inject a mock FileSystem for unit tests.

Example Config File

[p0]
  [p0.vf0]
    mac = "fa:b0:b2:04:9f:b1"
  ...
[p1]
  [p1.vf0]
    mac = "da:f2:ea:53:cf:40"
  ...
[enp1s0np0]
  [enp1s0np0.vf0]
    mac = "ab:22:ea:7f:fe:12" 
  ...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ECPFConfig

type ECPFConfig map[string]VFConfig

ECPFConfig holds VFConfig for VFs and PF of a specific ECPF keyed by VF+index/PF e.g "vf0", "vf1", "pf".

type FileSystem

type FileSystem interface {
	Stat(name string) (os.FileInfo, error)
	ReadFile(name string) ([]byte, error)
	WriteFile(name string, data []byte, perm os.FileMode) error
	Open(name string) (*os.File, error)
	MkdirAll(path string, perm os.FileMode) error
	ReadDir(name string) ([]os.DirEntry, error)
}

FileSystem abstracts file and OS operations for testability.

type OSFileSystem

type OSFileSystem struct{}

OSFileSystem is the default implementation of FileSystem using the os package.

func (OSFileSystem) MkdirAll

func (OSFileSystem) MkdirAll(path string, perm os.FileMode) error

func (OSFileSystem) Open

func (OSFileSystem) Open(name string) (*os.File, error)

func (OSFileSystem) ReadDir

func (OSFileSystem) ReadDir(name string) ([]os.DirEntry, error)

func (OSFileSystem) ReadFile

func (OSFileSystem) ReadFile(name string) ([]byte, error)

func (OSFileSystem) Stat

func (OSFileSystem) Stat(name string) (os.FileInfo, error)

func (OSFileSystem) WriteFile

func (OSFileSystem) WriteFile(name string, data []byte, perm os.FileMode) error

type VFConfig

type VFConfig struct {
	MAC string `toml:"mac"`
}

VFConfig holds the MAC address for a VF.

type VFMAC

type VFMAC struct {
	// contains filtered or unexported fields
}

VFMAC manages virtual function (VF) MAC addresses.

func NewVFMAC

func NewVFMAC(fs FileSystem, networkhelper networkhelper.NetworkHelper, log logr.Logger, configDir, configFile string, allowedPCIAddresses []string) (*VFMAC, error)

NewVFMAC creates a new VFMAC instance with the given configuration. allowedPCIAddresses restricts discovery to physical devlink ports owned by those PCI devices. An empty allow-list allows all ports.

func (*VFMAC) LoadIfaceMACAddressMapping

func (v *VFMAC) LoadIfaceMACAddressMapping() (VFMapping, error)

LoadIfaceMACAddressMapping walks sysfs to build a ECPF/VF → MAC mapping.

func (*VFMAC) ProcessVFs

func (v *VFMAC) ProcessVFs() error

ProcessVFs processes all virtual functions (VFs) for configured physical interfaces.

type VFMapping

type VFMapping map[string]ECPFConfig

VFMapping holds ECPFConfigs keyed by ECPF netdev name.

func (VFMapping) GetPFMacAddress

func (vfMapping VFMapping) GetPFMacAddress(ecpfName string) (string, error)

GetPFMacAddress retrieves the MAC address from an ECPF (specified by its netdev name) of a PF interface from the VF MAC mapping.

func (VFMapping) GetVFMacAddress

func (vfMapping VFMapping) GetVFMacAddress(ecpfName string, vfID int) (string, error)

GetVFMacAddress retrieves the MAC address from an ECPF (specified by its netdev name) of a VF interface from the VF MAC mapping.

Jump to

Keyboard shortcuts

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