Skip to content

Commit a57fdb8

Browse files
yarikkgopherbot
authored andcommitted
unix: add IoctlGetHwTstamp/IoctlGetHwTstamp on Linux
Add the ioctls to get/set the hardware timestamping configuration (SIOCSHWTSTAMP and SIOCGHWTSTAMP) along with relevant symbols. The usage is described in https://www.kernel.org/doc/Documentation/networking/timestamping.txt Change-Id: Ib7509feaf28218aeae497eff9ca6c0a532aa73c0 GitHub-Last-Rev: 47dc9df GitHub-Pull-Request: #224 Reviewed-on: https://go-review.googlesource.com/c/sys/+/620376 LUCI-TryBot-Result: Go LUCI <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 3932916 commit a57fdb8

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

unix/ioctl_linux.go

+26
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,32 @@ func IoctlGetEthtoolTsInfo(fd int, ifname string) (*EthtoolTsInfo, error) {
7373
return &value, err
7474
}
7575

76+
// IoctlGetHwTstamp retrieves the hardware timestamping configuration
77+
// for the network device specified by ifname.
78+
func IoctlGetHwTstamp(fd int, ifname string) (*HwTstampConfig, error) {
79+
ifr, err := NewIfreq(ifname)
80+
if err != nil {
81+
return nil, err
82+
}
83+
84+
value := HwTstampConfig{}
85+
ifrd := ifr.withData(unsafe.Pointer(&value))
86+
87+
err = ioctlIfreqData(fd, SIOCGHWTSTAMP, &ifrd)
88+
return &value, err
89+
}
90+
91+
// IoctlSetHwTstamp updates the hardware timestamping configuration for
92+
// the network device specified by ifname.
93+
func IoctlSetHwTstamp(fd int, ifname string, cfg *HwTstampConfig) error {
94+
ifr, err := NewIfreq(ifname)
95+
if err != nil {
96+
return err
97+
}
98+
ifrd := ifr.withData(unsafe.Pointer(cfg))
99+
return ioctlIfreqData(fd, SIOCSHWTSTAMP, &ifrd)
100+
}
101+
76102
// IoctlGetWatchdogInfo fetches information about a watchdog device from the
77103
// Linux watchdog API. For more information, see:
78104
// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html.

unix/linux/types.go

+19
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ struct termios2 {
144144
#include <linux/netfilter.h>
145145
#include <linux/netfilter_ipv4.h>
146146
#include <linux/netlink.h>
147+
#include <linux/net_tstamp.h>
147148
#include <linux/nexthop.h>
148149
#include <linux/nfc.h>
149150
#include <linux/nl80211.h>
@@ -4107,6 +4108,24 @@ type EthtoolDrvinfo C.struct_ethtool_drvinfo
41074108

41084109
type EthtoolTsInfo C.struct_ethtool_ts_info
41094110

4111+
type HwTstampConfig C.struct_hwtstamp_config
4112+
4113+
const (
4114+
HWTSTAMP_FILTER_NONE = C.HWTSTAMP_FILTER_NONE
4115+
HWTSTAMP_FILTER_ALL = C.HWTSTAMP_FILTER_ALL
4116+
HWTSTAMP_FILTER_SOME = C.HWTSTAMP_FILTER_SOME
4117+
HWTSTAMP_FILTER_PTP_V1_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V1_L4_EVENT
4118+
HWTSTAMP_FILTER_PTP_V2_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L4_EVENT
4119+
HWTSTAMP_FILTER_PTP_V2_L2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L2_EVENT
4120+
HWTSTAMP_FILTER_PTP_V2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_EVENT
4121+
)
4122+
4123+
const (
4124+
HWTSTAMP_TX_OFF = C.HWTSTAMP_TX_OFF
4125+
HWTSTAMP_TX_ON = C.HWTSTAMP_TX_ON
4126+
HWTSTAMP_TX_ONESTEP_SYNC = C.HWTSTAMP_TX_ONESTEP_SYNC
4127+
)
4128+
41104129
type (
41114130
HIDRawReportDescriptor C.struct_hidraw_report_descriptor
41124131
HIDRawDevInfo C.struct_hidraw_devinfo

unix/ztypes_linux.go

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)