mirror of
https://github.com/vishvananda/netlink.git
synced 2025-09-26 20:01:13 +08:00
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:

committed by
Alessandro Boch

parent
efd156c058
commit
7af87bcf82
@@ -12,13 +12,24 @@ import (
|
|||||||
// Empty handle used by the netlink package methods
|
// Empty handle used by the netlink package methods
|
||||||
var pkgHandle = &Handle{}
|
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
|
// specific network namespace. All the requests on the
|
||||||
// same netlink family share the same netlink socket,
|
// same netlink family share the same netlink socket,
|
||||||
// which gets released when the handle is Close'd.
|
// which gets released when the handle is Close'd.
|
||||||
type Handle struct {
|
type Handle struct {
|
||||||
sockets map[int]*nl.SocketHandle
|
sockets map[int]*nl.SocketHandle
|
||||||
lookupByDump bool
|
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
|
// 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) {
|
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
|
fams := nl.SupportedNlFamilies
|
||||||
if len(nlFamilies) != 0 {
|
if len(nlFamilies) != 0 {
|
||||||
fams = nlFamilies
|
fams = nlFamilies
|
||||||
|
@@ -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
|
// filtering a dump of all link names. In this case, if the returned error is
|
||||||
// [ErrDumpInterrupted] the result may be missing or outdated.
|
// [ErrDumpInterrupted] the result may be missing or outdated.
|
||||||
func (h *Handle) LinkByName(name string) (Link, error) {
|
func (h *Handle) LinkByName(name string) (Link, error) {
|
||||||
if h.lookupByDump {
|
if h.options.lookupByDump {
|
||||||
return h.linkByNameDump(name)
|
return h.linkByNameDump(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1942,8 +1942,10 @@ func (h *Handle) LinkByName(name string) (Link, error) {
|
|||||||
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
||||||
req.AddData(msg)
|
req.AddData(msg)
|
||||||
|
|
||||||
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
|
if h.options.collectVFInfo {
|
||||||
req.AddData(attr)
|
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))
|
nameData := nl.NewRtAttr(unix.IFLA_IFNAME, nl.ZeroTerminated(name))
|
||||||
if len(name) > 15 {
|
if len(name) > 15 {
|
||||||
@@ -1955,7 +1957,7 @@ func (h *Handle) LinkByName(name string) (Link, error) {
|
|||||||
if err == unix.EINVAL {
|
if err == unix.EINVAL {
|
||||||
// older kernels don't support looking up via IFLA_IFNAME
|
// older kernels don't support looking up via IFLA_IFNAME
|
||||||
// so fall back to dumping all links
|
// so fall back to dumping all links
|
||||||
h.lookupByDump = true
|
h.options.lookupByDump = true
|
||||||
return h.linkByNameDump(name)
|
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
|
// filtering a dump of all link names. In this case, if the returned error is
|
||||||
// [ErrDumpInterrupted] the result may be missing or outdated.
|
// [ErrDumpInterrupted] the result may be missing or outdated.
|
||||||
func (h *Handle) LinkByAlias(alias string) (Link, error) {
|
func (h *Handle) LinkByAlias(alias string) (Link, error) {
|
||||||
if h.lookupByDump {
|
if h.options.lookupByDump {
|
||||||
return h.linkByAliasDump(alias)
|
return h.linkByAliasDump(alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1988,8 +1990,10 @@ func (h *Handle) LinkByAlias(alias string) (Link, error) {
|
|||||||
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
||||||
req.AddData(msg)
|
req.AddData(msg)
|
||||||
|
|
||||||
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
|
if h.options.collectVFInfo {
|
||||||
req.AddData(attr)
|
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))
|
nameData := nl.NewRtAttr(unix.IFLA_IFALIAS, nl.ZeroTerminated(alias))
|
||||||
req.AddData(nameData)
|
req.AddData(nameData)
|
||||||
@@ -1998,7 +2002,7 @@ func (h *Handle) LinkByAlias(alias string) (Link, error) {
|
|||||||
if err == unix.EINVAL {
|
if err == unix.EINVAL {
|
||||||
// older kernels don't support looking up via IFLA_IFALIAS
|
// older kernels don't support looking up via IFLA_IFALIAS
|
||||||
// so fall back to dumping all links
|
// so fall back to dumping all links
|
||||||
h.lookupByDump = true
|
h.options.lookupByDump = true
|
||||||
return h.linkByAliasDump(alias)
|
return h.linkByAliasDump(alias)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2017,8 +2021,10 @@ func (h *Handle) LinkByIndex(index int) (Link, error) {
|
|||||||
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
msg := nl.NewIfInfomsg(unix.AF_UNSPEC)
|
||||||
msg.Index = int32(index)
|
msg.Index = int32(index)
|
||||||
req.AddData(msg)
|
req.AddData(msg)
|
||||||
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
|
if h.options.collectVFInfo {
|
||||||
req.AddData(attr)
|
attr := nl.NewRtAttr(unix.IFLA_EXT_MASK, nl.Uint32Attr(nl.RTEXT_FILTER_VF))
|
||||||
|
req.AddData(attr)
|
||||||
|
}
|
||||||
|
|
||||||
return execGetLink(req)
|
return execGetLink(req)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user