mirror of
https://github.com/golang/sys.git
synced 2026-02-09 04:06:04 +03:00
unix: add IoctlGetEthtoolTsInfo on Linux
The function fetches ethtool timestamping and PHC association for a
network interface. Its primary usage is to query the mapping between
the interface and its corresponding PTP clock number in /dev/ptp𝑛.
Change-Id: Id09466b3b43056c628593d4d2e05d77ec8d8082b
GitHub-Last-Rev: 3743a3a650
GitHub-Pull-Request: golang/sys#222
Reviewed-on: https://go-review.googlesource.com/c/sys/+/619335
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
This commit is contained in:
committed by
Gopher Robot
parent
fe162bad74
commit
e5eee7e480
@@ -68,6 +68,44 @@ func TestIoctlGetEthtoolDrvinfo(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIoctlGetEthtoolTsInfo(t *testing.T) {
|
||||
if runtime.GOOS == "android" {
|
||||
t.Skip("ethtool driver info is not available on android, skipping test")
|
||||
}
|
||||
|
||||
s, err := unix.Socket(unix.AF_INET, unix.SOCK_STREAM, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to open socket: %v", err)
|
||||
}
|
||||
defer unix.Close(s)
|
||||
|
||||
ifis, err := net.Interfaces()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to get network interfaces: %v", err)
|
||||
}
|
||||
|
||||
// Print the interface name and associated PHC information for each
|
||||
// network interface supported by ethtool.
|
||||
for _, ifi := range ifis {
|
||||
tsi, err := unix.IoctlGetEthtoolTsInfo(s, ifi.Name)
|
||||
if err != nil {
|
||||
if err == unix.EOPNOTSUPP {
|
||||
continue
|
||||
}
|
||||
|
||||
if err == unix.EBUSY {
|
||||
// See https://go.dev/issues/67350
|
||||
t.Logf("%s: ethtool driver busy, possible kernel bug", ifi.Name)
|
||||
continue
|
||||
}
|
||||
|
||||
t.Fatalf("failed to get ethtool PHC info for %q: %v", ifi.Name, err)
|
||||
}
|
||||
|
||||
t.Logf("%s: ptp%d", ifi.Name, tsi.Phc_index)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIoctlGetInt(t *testing.T) {
|
||||
f, err := os.Open("/dev/random")
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user