sriovutils

package
v0.0.0-...-530b9ac Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// NetDirectory sysfs net directory
	NetDirectory = "/sys/class/net"
	// SysBusPci is sysfs pci device directory
	SysBusPci = "/sys/bus/pci/devices"
	// SysV4ArpNotify is the sysfs IPv4 ARP Notify directory
	SysV4ArpNotify = "/proc/sys/net/ipv4/conf/"
	// SysV6NdiscNotify is the sysfs IPv6 Neighbor Discovery Notify directory
	SysV6NdiscNotify = "/proc/sys/net/ipv6/conf/"
	// UserspaceDrivers is a list of driver names that don't have netlink representation for their devices
	UserspaceDrivers = []string{"vfio-pci", "uio_pci_generic", "igb_uio"}
)

Functions

func AnnounceIPs

func AnnounceIPs(ifName string, ipConfigs []*current.IPConfig) error

AnnounceIPs sends either a GARP or Unsolicited NA depending on the IP address type (IPv4 vs. IPv6 respectively) configured on the interface.

func CleanCachedNetConf

func CleanCachedNetConf(cRefPath string) error

CleanCachedNetConf removed cached NetConf from disk

func EnableArpAndNdiscNotify

func EnableArpAndNdiscNotify(ifName string) error

EnableArpAndNdiscNotify enables IPv4 arp_notify and IPv6 ndisc_notify for netdev

func GetPciAddress

func GetPciAddress(ifName string, vf int) (string, error)

GetPciAddress takes in a interface(ifName) and VF id and returns its pci addr as string

func GetPfName

func GetPfName(vf string) (string, error)

GetPfName returns PF net device name of a given VF pci address

func GetSharedPF

func GetSharedPF(ifName string) (string, error)

GetSharedPF takes in VF name(ifName) as string and returns the other VF name that shares same PCI address as string

func GetSriovNumVfs

func GetSriovNumVfs(ifName string) (int, error)

GetSriovNumVfs takes in a PF name(ifName) as string and returns number of VF configured as int

func GetVFLinkName

func GetVFLinkName(pciAddr string) (string, error)

GetVFLinkName returns VF's network interface name given it's PCI addr

func GetVFLinkNamesFromVFID

func GetVFLinkNamesFromVFID(pfName string, vfID int) ([]string, error)

GetVFLinkNamesFromVFID returns VF's network interface name given it's PF name as string and VF id as int

func GetVfid

func GetVfid(addr string, pfName string) (int, error)

GetVfid takes in VF's PCI address(addr) and pfName as string and returns VF's ID as int

func HasDpdkDriver

func HasDpdkDriver(pciAddr string) (bool, error)

HasDpdkDriver checks if a device is attached to dpdk supported driver

func IsIPv4

func IsIPv4(ip net.IP) bool

IsIPv4 checks if a net.IP is an IPv4 address.

func IsIPv6

func IsIPv6(ip net.IP) bool

IsIPv6 checks if a net.IP is an IPv6 address.

func IsValidMACAddress

func IsValidMACAddress(addr net.HardwareAddr) bool

IsValidMACAddress checks if net.HardwareAddr is a valid MAC address.

func ReadScratchNetConf

func ReadScratchNetConf(cRefPath string) ([]byte, error)

ReadScratchNetConf takes in container ID, Pod interface name and data dir as string and returns a pointer to Conf

func Retry

func Retry(retries int, sleep time.Duration, f func() error) error

Retry retries a given function until no return error; times out after retries*sleep

func SaveNetConf

func SaveNetConf(cid, dataDir, podIfName string, conf interface{}) error

SaveNetConf takes in container ID, data dir and Pod interface name as string and a json encoded struct Conf and save this Conf in data dir

func SendGratuitousArp

func SendGratuitousArp(srcIP net.IP, linkObj netlink.Link) error

SendGratuitousArp sends a gratuitous ARP packet with the provided source IP over the provided interface.

func SendUnsolicitedNeighborAdvertisement

func SendUnsolicitedNeighborAdvertisement(srcIP net.IP, linkObj netlink.Link) error

SendUnsolicitedNeighborAdvertisement sends an unsolicited neighbor advertisement packet with the provided source IP over the provided interface.

func SetVFEffectiveMAC

func SetVFEffectiveMAC(netLinkManager NetlinkManager, netDeviceName string, macAddress string) error

SetVFEffectiveMAC will try to set the mac address on a specific VF interface

the function will also validate that the mac address was configured as expect it will return an error if it didn't manage to configure the vf mac address or the mac is not equal to the expect one retries 20 times and wait 100 milliseconds

Some NIC drivers (i.e. i40e/iavf) set VF MAC address asynchronously via PF. This means that while the PF could already show the VF with the desired MAC address, the netdev VF may still have the original one. If in this window we issue a netdev VF MAC address set, the driver will return an error and the pod will fail to create. Other NICs (Mellanox) require explicit netdev VF MAC address so we cannot skip this part. Retry up to 5 times; wait 200 milliseconds between retries

func SetVFHardwareMAC

func SetVFHardwareMAC(netLinkManager NetlinkManager, pfDevice string, vfID int, macAddress string) error

the function will also validate that the mac address was configured as expect it will return an error if it didn't manage to configure the vf mac address or the mac is not equal to the expect one retries 20 times and wait 100 milliseconds

Types

type MyNetlink struct {
	NetlinkManager
}

MyNetlink NetlinkManager

func (*MyNetlink) LinkByName

func (n *MyNetlink) LinkByName(name string) (netlink.Link, error)

LinkByName implements NetlinkManager

func (*MyNetlink) LinkSetDown

func (n *MyNetlink) LinkSetDown(link netlink.Link) error

LinkSetDown using NetlinkManager

func (*MyNetlink) LinkSetHardwareAddr

func (n *MyNetlink) LinkSetHardwareAddr(link netlink.Link, hwaddr net.HardwareAddr) error

LinkSetHardwareAddr using NetlinkManager

func (*MyNetlink) LinkSetName

func (n *MyNetlink) LinkSetName(link netlink.Link, name string) error

LinkSetName using NetlinkManager

func (*MyNetlink) LinkSetNsFd

func (n *MyNetlink) LinkSetNsFd(link netlink.Link, fd int) error

LinkSetNsFd using NetlinkManager

func (*MyNetlink) LinkSetUp

func (n *MyNetlink) LinkSetUp(link netlink.Link) error

LinkSetUp using NetlinkManager

func (*MyNetlink) LinkSetVfHardwareAddr

func (n *MyNetlink) LinkSetVfHardwareAddr(link netlink.Link, vf int, hwaddr net.HardwareAddr) error

LinkSetVfHardwareAddr using NetlinkManager

func (*MyNetlink) LinkSetVfRate

func (n *MyNetlink) LinkSetVfRate(link netlink.Link, vf int, minRate int, maxRate int) error

LinkSetVfRate using NetlinkManager

func (*MyNetlink) LinkSetVfSpoofchk

func (n *MyNetlink) LinkSetVfSpoofchk(link netlink.Link, vf int, check bool) error

LinkSetVfSpoofchk using NetlinkManager

func (*MyNetlink) LinkSetVfState

func (n *MyNetlink) LinkSetVfState(link netlink.Link, vf int, state uint32) error

LinkSetVfState using NetlinkManager

func (*MyNetlink) LinkSetVfTrust

func (n *MyNetlink) LinkSetVfTrust(link netlink.Link, vf int, state bool) error

LinkSetVfTrust using NetlinkManager

func (*MyNetlink) LinkSetVfVlanQosProto

func (n *MyNetlink) LinkSetVfVlanQosProto(link netlink.Link, vf, vlan, qos, proto int) error

LinkSetVfVlanQosProto sets VLAN ID, QoS and Proto field for given VF using NetlinkManager

type NetlinkManager

type NetlinkManager interface {
	LinkByName(string) (netlink.Link, error)
	LinkSetVfVlanQosProto(netlink.Link, int, int, int, int) error
	LinkSetVfHardwareAddr(netlink.Link, int, net.HardwareAddr) error
	LinkSetHardwareAddr(netlink.Link, net.HardwareAddr) error
	LinkSetUp(netlink.Link) error
	LinkSetDown(netlink.Link) error
	LinkSetNsFd(netlink.Link, int) error
	LinkSetName(netlink.Link, string) error
	LinkSetVfRate(netlink.Link, int, int, int) error
	LinkSetVfSpoofchk(netlink.Link, int, bool) error
	LinkSetVfTrust(netlink.Link, int, bool) error
	LinkSetVfState(netlink.Link, int, uint32) error
}

NetlinkManager is an interface to mock nelink library

type PCIAllocation

type PCIAllocation interface {
	SaveAllocatedPCI(string, string) error
	DeleteAllocatedPCI(string) error
	IsAllocated(string) error
}

type PCIAllocator

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

func NewPCIAllocator

func NewPCIAllocator(dataDir string) *PCIAllocator

NewPCIAllocator returns a new PCI allocator it will use the <dataDir>/pci folder to store the information about allocated PCI addresses

func (*PCIAllocator) DeleteAllocatedPCI

func (p *PCIAllocator) DeleteAllocatedPCI(pciAddress string) error

DeleteAllocatedPCI Remove the allocated PCI file return error if the file doesn't exist

func (*PCIAllocator) IsAllocated

func (p *PCIAllocator) IsAllocated(pciAddress string) (bool, error)

IsAllocated checks if the PCI address file exist if it exists we also check the network namespace still exist if not we delete the allocation The function will return an error if the pci is still allocated to a running pod

func (*PCIAllocator) SaveAllocatedPCI

func (p *PCIAllocator) SaveAllocatedPCI(pciAddress, ns string) error

SaveAllocatedPCI creates a file with the pci address as a name and the network namespace as the content return error if the file was not created

Jump to

Keyboard shortcuts

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