diff --git a/unix/ioctl_linux.go b/unix/ioctl_linux.go index e605abd1c..7fbec37a5 100644 --- a/unix/ioctl_linux.go +++ b/unix/ioctl_linux.go @@ -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. diff --git a/unix/linux/types.go b/unix/linux/types.go index 80342dd4d..705d20a25 100644 --- a/unix/linux/types.go +++ b/unix/linux/types.go @@ -144,6 +144,7 @@ struct termios2 { #include #include #include +#include #include #include #include @@ -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 diff --git a/unix/ztypes_linux.go b/unix/ztypes_linux.go index 232c3798d..40d149dad 100644 --- a/unix/ztypes_linux.go +++ b/unix/ztypes_linux.go @@ -4120,6 +4120,28 @@ type EthtoolTsInfo struct { Rx_reserved [3]uint32 } +type HwTstampConfig struct { + Flags int32 + Tx_type int32 + Rx_filter int32 +} + +const ( + HWTSTAMP_FILTER_NONE = 0x0 + HWTSTAMP_FILTER_ALL = 0x1 + HWTSTAMP_FILTER_SOME = 0x2 + HWTSTAMP_FILTER_PTP_V1_L4_EVENT = 0x3 + HWTSTAMP_FILTER_PTP_V2_L4_EVENT = 0x6 + HWTSTAMP_FILTER_PTP_V2_L2_EVENT = 0x9 + HWTSTAMP_FILTER_PTP_V2_EVENT = 0xc +) + +const ( + HWTSTAMP_TX_OFF = 0x0 + HWTSTAMP_TX_ON = 0x1 + HWTSTAMP_TX_ONESTEP_SYNC = 0x2 +) + type ( HIDRawReportDescriptor struct { Size uint32