diff --git a/go.mod b/go.mod index 60de0cb82..eef23b7ae 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/networkplumbing/go-nft v0.2.0 github.com/onsi/ginkgo v1.16.5 github.com/onsi/gomega v1.24.2 - github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1 + github.com/safchain/ethtool v0.2.0 github.com/vishvananda/netlink v1.2.1-beta.2 golang.org/x/sys v0.4.0 ) diff --git a/go.sum b/go.sum index 5e88994f6..3ac5efd32 100644 --- a/go.sum +++ b/go.sum @@ -596,8 +596,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/safchain/ethtool v0.0.0-20190326074333-42ed695e3de8/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= -github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1 h1:ZFfeKAhIQiiOrQaI3/znw0gOmYpO28Tcu1YaqMa/jtQ= -github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1/go.mod h1:Z0q5wiBQGYcxhMZ6gUqHn6pYNLypFAvaL3UvgZLR0U4= +github.com/safchain/ethtool v0.2.0 h1:dILxMBqDnQfX192cCAPjZr9v2IgVXeElHPy435Z/IdE= +github.com/safchain/ethtool v0.2.0/go.mod h1:WkKB1DnNtvsMlDmQ50sgwowDJV/hGbJSOvJoEXs1AJQ= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sclevine/spec v1.2.0/go.mod h1:W4J29eT/Kzv7/b9IWLB055Z+qvVC9vt0Arko24q7p+U= github.com/seccomp/libseccomp-golang v0.9.1/go.mod h1:GbW5+tmTXfcxTToHLXlScSlAvWlF4P2Ca7zGrPiEpWo= @@ -880,6 +880,7 @@ golang.org/x/sys v0.0.0-20210426230700-d19ff857e887/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= diff --git a/vendor/github.com/safchain/ethtool/ethtool.go b/vendor/github.com/safchain/ethtool/ethtool.go index d1cd4d31f..240911678 100644 --- a/vendor/github.com/safchain/ethtool/ethtool.go +++ b/vendor/github.com/safchain/ethtool/ethtool.go @@ -234,13 +234,22 @@ type Ethtool struct { fd int } +// Convert zero-terminated array of chars (string in C) to a Go string. +func goString(s []byte) string { + strEnd := bytes.IndexByte(s, 0) + if strEnd == -1 { + return string(s[:]) + } + return string(s[:strEnd]) +} + // DriverName returns the driver name of the given interface name. func (e *Ethtool) DriverName(intf string) (string, error) { info, err := e.getDriverInfo(intf) if err != nil { return "", err } - return string(bytes.Trim(info.driver[:], "\x00")), nil + return goString(info.driver[:]), nil } // BusInfo returns the bus information of the given interface name. @@ -249,7 +258,7 @@ func (e *Ethtool) BusInfo(intf string) (string, error) { if err != nil { return "", err } - return string(bytes.Trim(info.bus_info[:], "\x00")), nil + return goString(info.bus_info[:]), nil } // ModuleEeprom returns Eeprom information of the given interface name. @@ -281,12 +290,12 @@ func (e *Ethtool) DriverInfo(intf string) (DrvInfo, error) { drvInfo := DrvInfo{ Cmd: i.cmd, - Driver: string(bytes.Trim(i.driver[:], "\x00")), - Version: string(bytes.Trim(i.version[:], "\x00")), - FwVersion: string(bytes.Trim(i.fw_version[:], "\x00")), - BusInfo: string(bytes.Trim(i.bus_info[:], "\x00")), - EromVersion: string(bytes.Trim(i.erom_version[:], "\x00")), - Reserved2: string(bytes.Trim(i.reserved2[:], "\x00")), + Driver: goString(i.driver[:]), + Version: goString(i.version[:]), + FwVersion: goString(i.fw_version[:]), + BusInfo: goString(i.bus_info[:]), + EromVersion: goString(i.erom_version[:]), + Reserved2: goString(i.reserved2[:]), NPrivFlags: i.n_priv_flags, NStats: i.n_stats, TestInfoLen: i.testinfo_len, @@ -500,7 +509,7 @@ func (e *Ethtool) FeatureNames(intf string) (map[string]uint, error) { var result = make(map[string]uint) for i := 0; i != int(length); i++ { b := gstrings.data[i*ETH_GSTRING_LEN : i*ETH_GSTRING_LEN+ETH_GSTRING_LEN] - key := string(bytes.Trim(b, "\x00")) + key := goString(b) if key != "" { result[key] = uint(i) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 800bd5b76..679b97cdc 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -148,8 +148,8 @@ github.com/onsi/gomega/types # github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors -# github.com/safchain/ethtool v0.0.0-20210803160452-9aa261dae9b1 -## explicit +# github.com/safchain/ethtool v0.2.0 +## explicit; go 1.16 github.com/safchain/ethtool # github.com/sirupsen/logrus v1.8.1 ## explicit; go 1.13