diff --git a/go.mod b/go.mod index 02d8cda..6374300 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/jaypipes/ghw v0.13.0 github.com/linuxkit/virtsock v0.0.0-20220523201153-1a23e78aa7a2 github.com/pkg/errors v0.9.1 - github.com/safchain/ethtool v0.4.1 + github.com/safchain/ethtool v0.5.10 github.com/shirou/gopsutil/v3 v3.24.5 github.com/sirupsen/logrus v1.9.3 github.com/spf13/viper v1.19.0 diff --git a/go.sum b/go.sum index 187f433..e6779d7 100644 --- a/go.sum +++ b/go.sum @@ -78,8 +78,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= -github.com/safchain/ethtool v0.4.1 h1:S6mEleTADqgynileXoiapt/nKnatyR6bmIHoF+h2ADo= -github.com/safchain/ethtool v0.4.1/go.mod h1:XLLnZmy4OCRTkksP/UiMjij96YmIsBfmBQcs7H6tA48= +github.com/safchain/ethtool v0.5.10 h1:Im294gZtuf4pSGJRAOGKaASNi3wMeFaGaWuSaomedpc= +github.com/safchain/ethtool v0.5.10/go.mod h1:w9jh2Lx7YBR4UwzLkzCmWl85UY0W2uZdd7/DckVE5+c= github.com/sagikazarmark/locafero v0.4.0 h1:HApY1R9zGo4DBgr7dqsTH/JJxLTTsOt7u6keLGt6kNQ= github.com/sagikazarmark/locafero v0.4.0/go.mod h1:Pe1W6UlPYUk/+wc/6KFhbORCfqzgYEpgQ3O5fPuL3H4= github.com/sagikazarmark/slog-shim v0.1.0 h1:diDBnUNK9N/354PgrxMywXnAwEr1QZcOr6gto+ugjYE= @@ -150,7 +150,7 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc= golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM= diff --git a/vendor/github.com/safchain/ethtool/.golangci.yml b/vendor/github.com/safchain/ethtool/.golangci.yml index 77ccf92..65552c9 100644 --- a/vendor/github.com/safchain/ethtool/.golangci.yml +++ b/vendor/github.com/safchain/ethtool/.golangci.yml @@ -1,11 +1,15 @@ linters: - disable: - - gosimple - - unused enable: + - gosimple - gci - gofmt - misspell + - goimports + - staticcheck + - errcheck + - govet + - misspell + - gocritic linters-settings: gci: sections: diff --git a/vendor/github.com/safchain/ethtool/LICENSE b/vendor/github.com/safchain/ethtool/LICENSE index 8f71f43..3c83e6b 100644 --- a/vendor/github.com/safchain/ethtool/LICENSE +++ b/vendor/github.com/safchain/ethtool/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright {yyyy} {name of copyright owner} + Copyright (c) 2015 The Ethtool Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/vendor/github.com/safchain/ethtool/ethtool.go b/vendor/github.com/safchain/ethtool/ethtool.go index f309c50..62df2c1 100644 --- a/vendor/github.com/safchain/ethtool/ethtool.go +++ b/vendor/github.com/safchain/ethtool/ethtool.go @@ -55,12 +55,14 @@ const ( // CMD supported ETHTOOL_GSET = 0x00000001 /* Get settings. */ ETHTOOL_SSET = 0x00000002 /* Set settings. */ + ETHTOOL_GWOL = 0x00000005 /* Get wake-on-lan options. */ + ETHTOOL_SWOL = 0x00000006 /* Set wake-on-lan options. */ ETHTOOL_GDRVINFO = 0x00000003 /* Get driver info. */ ETHTOOL_GMSGLVL = 0x00000007 /* Get driver message level */ ETHTOOL_SMSGLVL = 0x00000008 /* Set driver msg level. */ - /* Get link status for host, i.e. whether the interface *and* the - * physical port (if there is one) are up (ethtool_value). */ + // Get link status for host, i.e. whether the interface *and* the + // physical port (if there is one) are up (ethtool_value). ETHTOOL_GLINK = 0x0000000a ETHTOOL_GCOALESCE = 0x0000000e /* Get coalesce config */ ETHTOOL_SCOALESCE = 0x0000000f /* Set coalesce config */ @@ -207,23 +209,55 @@ type Coalesce struct { RateSampleInterval uint32 } +// WoL options const ( - SOF_TIMESTAMPING_TX_HARDWARE = (1 << 0) - SOF_TIMESTAMPING_TX_SOFTWARE = (1 << 1) - SOF_TIMESTAMPING_RX_HARDWARE = (1 << 2) - SOF_TIMESTAMPING_RX_SOFTWARE = (1 << 3) - SOF_TIMESTAMPING_SOFTWARE = (1 << 4) - SOF_TIMESTAMPING_SYS_HARDWARE = (1 << 5) - SOF_TIMESTAMPING_RAW_HARDWARE = (1 << 6) - SOF_TIMESTAMPING_OPT_ID = (1 << 7) - SOF_TIMESTAMPING_TX_SCHED = (1 << 8) - SOF_TIMESTAMPING_TX_ACK = (1 << 9) - SOF_TIMESTAMPING_OPT_CMSG = (1 << 10) - SOF_TIMESTAMPING_OPT_TSONLY = (1 << 11) - SOF_TIMESTAMPING_OPT_STATS = (1 << 12) - SOF_TIMESTAMPING_OPT_PKTINFO = (1 << 13) - SOF_TIMESTAMPING_OPT_TX_SWHW = (1 << 14) - SOF_TIMESTAMPING_BIND_PHC = (1 << 15) + WAKE_PHY = 1 << 0 + WAKE_UCAST = 1 << 1 + WAKE_MCAST = 1 << 2 + WAKE_BCAST = 1 << 3 + WAKE_ARP = 1 << 4 + WAKE_MAGIC = 1 << 5 + WAKE_MAGICSECURE = 1 << 6 // only meaningful if WAKE_MAGIC +) + +var WoLMap = map[uint32]string{ + WAKE_PHY: "p", // Wake on PHY activity + WAKE_UCAST: "u", // Wake on unicast messages + WAKE_MCAST: "m", // Wake on multicast messages + WAKE_BCAST: "b", // Wake on broadcast messages + WAKE_ARP: "a", // Wake on ARP + WAKE_MAGIC: "g", // Wake on MagicPacket™ + WAKE_MAGICSECURE: "s", // Enable SecureOn™ password for MagicPacket™ + // f Wake on filter(s) + // d Disable (wake on nothing). This option clears all previous options. +} + +// WakeOnLan contains WoL config for an interface +type WakeOnLan struct { + Cmd uint32 // ETHTOOL_GWOL or ETHTOOL_SWOL + Supported uint32 // r/o bitmask of WAKE_* flags for supported WoL modes + Opts uint32 // Bitmask of WAKE_* flags for enabled WoL modes +} + +// Timestamping options +// see: https://www.kernel.org/doc/Documentation/networking/timestamping.txt +const ( + SOF_TIMESTAMPING_TX_HARDWARE = (1 << 0) /* Request tx timestamps generated by the network adapter. */ + SOF_TIMESTAMPING_TX_SOFTWARE = (1 << 1) /* Request tx timestamps when data leaves the kernel. */ + SOF_TIMESTAMPING_RX_HARDWARE = (1 << 2) /* Request rx timestamps generated by the network adapter. */ + SOF_TIMESTAMPING_RX_SOFTWARE = (1 << 3) /* Request rx timestamps when data enters the kernel. */ + SOF_TIMESTAMPING_SOFTWARE = (1 << 4) /* Report any software timestamps when available. */ + SOF_TIMESTAMPING_SYS_HARDWARE = (1 << 5) /* This option is deprecated and ignored. */ + SOF_TIMESTAMPING_RAW_HARDWARE = (1 << 6) /* Report hardware timestamps. */ + SOF_TIMESTAMPING_OPT_ID = (1 << 7) /* Generate a unique identifier along with each packet. */ + SOF_TIMESTAMPING_TX_SCHED = (1 << 8) /* Request tx timestamps prior to entering the packet scheduler. */ + SOF_TIMESTAMPING_TX_ACK = (1 << 9) /* Request tx timestamps when all data in the send buffer has been acknowledged. */ + SOF_TIMESTAMPING_OPT_CMSG = (1 << 10) /* Support recv() cmsg for all timestamped packets. */ + SOF_TIMESTAMPING_OPT_TSONLY = (1 << 11) /* Applies to transmit timestamps only. */ + SOF_TIMESTAMPING_OPT_STATS = (1 << 12) /* Optional stats that are obtained along with the transmit timestamps. */ + SOF_TIMESTAMPING_OPT_PKTINFO = (1 << 13) /* Enable the SCM_TIMESTAMPING_PKTINFO control message for incoming packets with hardware timestamps. */ + SOF_TIMESTAMPING_OPT_TX_SWHW = (1 << 14) /* Request both hardware and software timestamps for outgoing packets when SOF_TIMESTAMPING_TX_HARDWARE and SOF_TIMESTAMPING_TX_SOFTWARE are enabled at the same time. */ + SOF_TIMESTAMPING_BIND_PHC = (1 << 15) /* Bind the socket to a specific PTP Hardware Clock. */ ) const ( @@ -279,6 +313,7 @@ const ( HWTSTAMP_FILTER_NTP_ALL /* NTP, UDP, all versions and packet modes */ ) +// TimestampingInformation contains PTP timetstapming information type TimestampingInformation struct { Cmd uint32 SoTimestamping uint32 /* SOF_TIMESTAMPING_* bitmask */ @@ -349,6 +384,7 @@ type Pause struct { TxPause uint32 } +// Ethtool is a struct that contains the file descriptor for the ethtool type Ethtool struct { fd int } @@ -357,7 +393,7 @@ type Ethtool struct { func goString(s []byte) string { strEnd := bytes.IndexByte(s, 0) if strEnd == -1 { - return string(s[:]) + return string(s) } return string(s[:strEnd]) } @@ -496,6 +532,31 @@ func (e *Ethtool) PermAddr(intf string) (string, error) { ), nil } +// GetWakeOnLan returns the WoL config for the given interface name. +func (e *Ethtool) GetWakeOnLan(intf string) (WakeOnLan, error) { + wol := WakeOnLan{ + Cmd: ETHTOOL_GWOL, + } + + if err := e.ioctl(intf, uintptr(unsafe.Pointer(&wol))); err != nil { + return WakeOnLan{}, err + } + + return wol, nil +} + +// SetWakeOnLan sets the WoL config for the given interface name and +// returns the new WoL config. +func (e *Ethtool) SetWakeOnLan(intf string, wol WakeOnLan) (WakeOnLan, error) { + wol.Cmd = ETHTOOL_SWOL + + if err := e.ioctl(intf, uintptr(unsafe.Pointer(&wol))); err != nil { + return WakeOnLan{}, err + } + + return wol, nil +} + func (e *Ethtool) ioctl(intf string, data uintptr) error { var name [IFNAMSIZ]byte copy(name[:], []byte(intf)) @@ -672,6 +733,7 @@ func isFeatureBitSet(blocks [MAX_FEATURE_BLOCKS]ethtoolGetFeaturesBlock, index u return (blocks)[index/32].active&(1<<(index%32)) != 0 } +// FeatureState contains the state of a feature. type FeatureState struct { Available bool Requested bool @@ -893,7 +955,7 @@ func (e *Ethtool) UpdatePrivFlags(intf string, config map[string]bool) error { return e.ioctl(intf, uintptr(unsafe.Pointer(&update))) } -// Get state of a link. +// LinkState get the state of a link. func (e *Ethtool) LinkState(intf string) (uint32, error) { x := ethtoolLink{ cmd: ETHTOOL_GLINK, @@ -964,7 +1026,7 @@ func (e *Ethtool) Close() { // NewEthtool returns a new ethtool handler func NewEthtool() (*Ethtool, error) { - fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM, unix.IPPROTO_IP) + fd, err := unix.Socket(unix.AF_INET, unix.SOCK_DGRAM|unix.SOCK_CLOEXEC, unix.IPPROTO_IP) if err != nil { return nil, err } diff --git a/vendor/github.com/safchain/ethtool/ethtool_cmd.go b/vendor/github.com/safchain/ethtool/ethtool_cmd.go index e94d6dd..09499fe 100644 --- a/vendor/github.com/safchain/ethtool/ethtool_cmd.go +++ b/vendor/github.com/safchain/ethtool/ethtool_cmd.go @@ -33,7 +33,9 @@ import ( "golang.org/x/sys/unix" ) -type EthtoolCmd struct { /* ethtool.c: struct ethtool_cmd */ +// EthtoolCmd is the Go version of the Linux kerne ethtool_cmd struct +// see ethtool.c +type EthtoolCmd struct { Cmd uint32 Supported uint32 Advertising uint32 @@ -102,10 +104,6 @@ func (f *EthtoolCmd) reflect(retv *map[string]uint64) { default: (*retv)[typeField.Name+"_unknown_type"] = 0 } - - // tag := typeField.Tag - // fmt.Printf("Field Name: %s,\t Field Value: %v,\t Tag Value: %s\n", - // typeField.Name, valueField.Interface(), tag.Get("tag_name")) } } @@ -198,6 +196,7 @@ func (e *Ethtool) CmdGetMapped(intf string) (map[string]uint64, error) { return result, nil } +// CmdGetMapped returns the interface settings in a map func CmdGetMapped(intf string) (map[string]uint64, error) { e, err := NewEthtool() if err != nil { diff --git a/vendor/modules.txt b/vendor/modules.txt index 43a629d..ab7986a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -133,7 +133,7 @@ github.com/power-devops/perfstat # github.com/russross/blackfriday/v2 v2.1.0 ## explicit github.com/russross/blackfriday/v2 -# github.com/safchain/ethtool v0.4.1 +# github.com/safchain/ethtool v0.5.10 ## explicit; go 1.16 github.com/safchain/ethtool # github.com/sagikazarmark/locafero v0.4.0