Skip to content

Commit

Permalink
unix: add IoctlGetHwTstamp/IoctlGetHwTstamp on Linux
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
yarikk authored and gopherbot committed Oct 16, 2024
1 parent 3932916 commit a57fdb8
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
26 changes: 26 additions & 0 deletions unix/ioctl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,32 @@ func IoctlGetEthtoolTsInfo(fd int, ifname string) (*EthtoolTsInfo, error) {
return &value, err
}

// IoctlGetHwTstamp retrieves the hardware timestamping configuration
// for the network device specified by ifname.
func IoctlGetHwTstamp(fd int, ifname string) (*HwTstampConfig, error) {
ifr, err := NewIfreq(ifname)
if err != nil {
return nil, err
}

value := HwTstampConfig{}
ifrd := ifr.withData(unsafe.Pointer(&value))

err = ioctlIfreqData(fd, SIOCGHWTSTAMP, &ifrd)
return &value, err
}

// IoctlSetHwTstamp updates the hardware timestamping configuration for
// the network device specified by ifname.
func IoctlSetHwTstamp(fd int, ifname string, cfg *HwTstampConfig) error {
ifr, err := NewIfreq(ifname)
if err != nil {
return err
}
ifrd := ifr.withData(unsafe.Pointer(cfg))
return ioctlIfreqData(fd, SIOCSHWTSTAMP, &ifrd)
}

// IoctlGetWatchdogInfo fetches information about a watchdog device from the
// Linux watchdog API. For more information, see:
// https://www.kernel.org/doc/html/latest/watchdog/watchdog-api.html.
Expand Down
19 changes: 19 additions & 0 deletions unix/linux/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ struct termios2 {
#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/netlink.h>
#include <linux/net_tstamp.h>
#include <linux/nexthop.h>
#include <linux/nfc.h>
#include <linux/nl80211.h>
Expand Down Expand Up @@ -4107,6 +4108,24 @@ type EthtoolDrvinfo C.struct_ethtool_drvinfo

type EthtoolTsInfo C.struct_ethtool_ts_info

type HwTstampConfig C.struct_hwtstamp_config

const (
HWTSTAMP_FILTER_NONE = C.HWTSTAMP_FILTER_NONE
HWTSTAMP_FILTER_ALL = C.HWTSTAMP_FILTER_ALL
HWTSTAMP_FILTER_SOME = C.HWTSTAMP_FILTER_SOME
HWTSTAMP_FILTER_PTP_V1_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V1_L4_EVENT
HWTSTAMP_FILTER_PTP_V2_L4_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L4_EVENT
HWTSTAMP_FILTER_PTP_V2_L2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_L2_EVENT
HWTSTAMP_FILTER_PTP_V2_EVENT = C.HWTSTAMP_FILTER_PTP_V2_EVENT
)

const (
HWTSTAMP_TX_OFF = C.HWTSTAMP_TX_OFF
HWTSTAMP_TX_ON = C.HWTSTAMP_TX_ON
HWTSTAMP_TX_ONESTEP_SYNC = C.HWTSTAMP_TX_ONESTEP_SYNC
)

type (
HIDRawReportDescriptor C.struct_hidraw_report_descriptor
HIDRawDevInfo C.struct_hidraw_devinfo
Expand Down
22 changes: 22 additions & 0 deletions unix/ztypes_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a57fdb8

Please sign in to comment.