feat: option to disable VF polling

Introduces a configuration flag to disable Virtual Function polling,
providing users with control over polling behavior for performance
optimization scenarios.

Fixes: #1097

Signed-off-by: pasteley <ceasebeing@gmail.com>
This commit is contained in:
pasteley
2025-05-06 16:56:56 +02:00
committed by Alessandro Boch
parent efd156c058
commit 7af87bcf82
2 changed files with 34 additions and 14 deletions

View File

@@ -12,13 +12,24 @@ import (
// Empty handle used by the netlink package methods
var pkgHandle = &Handle{}
// Handle is an handle for the netlink requests on a
type HandleOptions struct {
lookupByDump bool
collectVFInfo bool
}
// Handle is a handle for the netlink requests on a
// specific network namespace. All the requests on the
// same netlink family share the same netlink socket,
// which gets released when the handle is Close'd.
type Handle struct {
sockets map[int]*nl.SocketHandle
lookupByDump bool
sockets map[int]*nl.SocketHandle
options HandleOptions
}
// DisableVFInfoCollection configures the handle to skip VF information fetching
func (h *Handle) DisableVFInfoCollection() *Handle {
h.options.collectVFInfo = false
return h
}
// SetSocketTimeout configures timeout for default netlink sockets
@@ -136,7 +147,10 @@ func NewHandleAtFrom(newNs, curNs netns.NsHandle) (*Handle, error) {
}
func newHandle(newNs, curNs netns.NsHandle, nlFamilies ...int) (*Handle, error) {
h := &Handle{sockets: map[int]*nl.SocketHandle{}}
h := &Handle{
sockets: map[int]*nl.SocketHandle{},
options: HandleOptions{collectVFInfo: true},
}
fams := nl.SupportedNlFamilies
if len(nlFamilies) != 0 {
fams = nlFamilies

View File

@@ -1933,7 +1933,7 @@ func LinkByName(name string) (Link, error) {
// filtering a dump of all link names. In this case, if the returned error is
// [ErrDumpInterrupted] the result may be missing or outdated.
func (h *Handle) LinkByName(name string) (Link, error) {
if h.lookupByDump {
if h.options.lookupByDump {
return h.linkByNameDump(name)
}
@@ -1942,8 +1942,10 @@ func (h *Handle) LinkByName(name string) (Link, error) {
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
if h.options.collectVFInfo {
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
}
nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name))
if len(name) > 15 {
@@ -1955,7 +1957,7 @@ func (h *Handle) LinkByName(name string) (Link, error) {
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFNAME
// so fall back to dumping all links
h.lookupByDump = true
h.options.lookupByDump = true
return h.linkByNameDump(name)
}
@@ -1979,7 +1981,7 @@ func LinkByAlias(alias string) (Link, error) {
// filtering a dump of all link names. In this case, if the returned error is
// [ErrDumpInterrupted] the result may be missing or outdated.
func (h *Handle) LinkByAlias(alias string) (Link, error) {
if h.lookupByDump {
if h.options.lookupByDump {
return h.linkByAliasDump(alias)
}
@@ -1988,8 +1990,10 @@ func (h *Handle) LinkByAlias(alias string) (Link, error) {
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
if h.options.collectVFInfo {
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
}
nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias))
req.AddData(nameData)
@@ -1998,7 +2002,7 @@ func (h *Handle) LinkByAlias(alias string) (Link, error) {
if err == unix.EINVAL {
// older kernels don't support looking up via IFLA_IFALIAS
// so fall back to dumping all links
h.lookupByDump = true
h.options.lookupByDump = true
return h.linkByAliasDump(alias)
}
@@ -2017,8 +2021,10 @@ func (h *Handle) LinkByIndex(index int) (Link, error) {
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
msg.Index = int32(index)
req.AddData(msg)
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
if h.options.collectVFInfo {
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
req.AddData(attr)
}
return execGetLink(req)
}