diff --git a/pkg/host/network.go b/pkg/host/network.go index 959275be1..ab8273c96 100644 --- a/pkg/host/network.go +++ b/pkg/host/network.go @@ -9,6 +9,7 @@ import ( "time" "github.com/cenkalti/backoff" + "github.com/vishvananda/netlink" "sigs.k8s.io/controller-runtime/pkg/log" dputils "github.com/k8snetworkplumbingwg/sriov-network-device-plugin/pkg/utils" @@ -231,12 +232,14 @@ func (n *network) GetNetDevLinkSpeed(ifaceName string) string { func (n *network) GetNetDevLinkStatus(ifaceName string) string { log.Log.V(2).Info("GetNetDevLinkStatus(): get LinkStatus", "device", ifaceName) - statusFilePath := filepath.Join(vars.FilesystemRoot, consts.SysClassNet, ifaceName, "operstate") - data, err := os.ReadFile(statusFilePath) - if err != nil { - log.Log.Error(err, "GetNetDevLinkStatus(): fail to read Link Status file", "path", statusFilePath) - return "" + if len(ifaceName) > 0 { + link, err := netlink.LinkByName(ifaceName) + if err != nil { + log.Log.Error(err, "GetNetDevLinkStatus(): failed to get link", "device", ifaceName) + return "" + } + linkStatus := link.Attrs().OperState + return linkStatus.String() } - - return strings.TrimSpace(string(data)) + return "" }