8000
We read every piece of feedback, and take your input very seriously.
1 parent fe162ba commit e5eee7eCopy full SHA for e5eee7e
unix/ioctl_linux.go
@@ -58,6 +58,21 @@ func IoctlGetEthtoolDrvinfo(fd int, ifname string) (*EthtoolDrvinfo, error) {
58
return &value, err
59
}
60
61
+// IoctlGetEthtoolTsInfo fetches ethtool timestamping and PHC
62
+// association for the network device specified by ifname.
63
+func IoctlGetEthtoolTsInfo(fd int, ifname string) (*EthtoolTsInfo, error) {
64
+ ifr, err := NewIfreq(ifname)
65
+ if err != nil {
66
+ return nil, err
67
+ }
68
+
69
+ value := EthtoolTsInfo{Cmd: ETHTOOL_GET_TS_INFO}
70
+ ifrd := ifr.withData(unsafe.Pointer(&value))
71
72
+ err = ioctlIfreqData(fd, SIOCETHTOOL, &ifrd)
73
+ return &value, err
74
+}
75
76
// IoctlGetWatchdogInfo fetches information about a watchdog device from the
77
// Linux watchdog API. For more information, see:
78
// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html.
unix/linux/types.go
@@ -4090,6 +4090,8 @@ const SPEED_UNKNOWN = C.SPEED_UNKNOWN
4090
4091
type EthtoolDrvinfo C.struct_ethtool_drvinfo
4092
4093
+type EthtoolTsInfo C.struct_ethtool_ts_info
4094
4095
type (
4096
HIDRawReportDescriptor C.struct_hidraw_report_descriptor
4097
HIDRawDevInfo C.struct_hidraw_devinfo
unix/syscall_linux_test.go
@@ -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)
+ t.Fatalf("failed to open socket: %v", err)
79
80
+ defer unix.Close(s)
81
82
+ ifis, err := net.Interfaces()
83
84
+ t.Fatalf("failed to get network interfaces: %v", err)
85
86
87
+ // Print the interface name and associated PHC information for each
88
+ // network interface supported by ethtool.
89
+ for _, ifi := range ifis {
90
+ tsi, err := unix.IoctlGetEthtoolTsInfo(s, ifi.Name)
91
92
+ if err == unix.EOPNOTSUPP {
93
+ continue
94
95
96
+ if err == unix.EBUSY {
97
+ // See https://go.dev/issues/67350
98
+ t.Logf("%s: ethtool driver busy, possible kernel bug", ifi.Name)
99
100
101
102
+ t.Fatalf("failed to get ethtool PHC info for %q: %v", ifi.Name, err)
103
104
105
+ t.Logf("%s: ptp%d", ifi.Name, tsi.Phc_index)
106
107
108
109
func TestIoctlGetInt(t *testing.T) {
110
f, err := os.Open("/dev/random")
111
if err != nil {
unix/ztypes_linux.go