Skip to content

Commit 2dc31a7

Browse files
committed
Auto merge of rust-lang#3155 - folkertdev:hardware-timestamping, r=JohnTitor
definitions for linux hardware timestamping Definitions can be found here https://elixir.bootlin.com/linux/latest/source/include/uapi/linux/net_tstamp.h#L76 These definitions are relevant for (PTP and NTP) hardware timestamping
2 parents c64bfc5 + 4949998 commit 2dc31a7

File tree

3 files changed

+82
-1
lines changed

3 files changed

+82
-1
lines changed

libc-test/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -3394,7 +3394,7 @@ fn test_linux(target: &str) {
33943394
}
33953395
// FIXME(https://github.com/rust-lang/libc/issues/1558): passing by
33963396
// value corrupts the value for reasons not understood.
3397-
if (gnu && sparc64) && ty == "ip_mreqn" {
3397+
if (gnu && sparc64) && (ty == "ip_mreqn" || ty == "hwtstamp_config") {
33983398
return true;
33993399
}
34003400
match ty {
@@ -3724,6 +3724,9 @@ fn test_linux(target: &str) {
37243724
=> true,
37253725
"SCTP_FUTURE_ASSOC" | "SCTP_CURRENT_ASSOC" | "SCTP_ALL_ASSOC" | "SCTP_PEER_ADDR_THLDS_V2" => true, // linux 5.5+
37263726

3727+
// FIXME: Requires more recent kernel headers
3728+
"HWTSTAMP_TX_ONESTEP_P2P" if sparc64 || musl => true, // linux v5.6+
3729+
37273730
_ => false,
37283731
}
37293732
});

libc-test/semver/linux.txt

+23
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,26 @@ GLOB_NOSPACE
818818
GRND_NONBLOCK
819819
GRND_RANDOM
820820
GRND_INSECURE
821+
HWTSTAMP_TX_OFF
822+
HWTSTAMP_TX_ON
823+
HWTSTAMP_TX_ONESTEP_SYNC
824+
HWTSTAMP_TX_ONESTEP_P2P
825+
HWTSTAMP_FILTER_NONE
826+
HWTSTAMP_FILTER_ALL
827+
HWTSTAMP_FILTER_SOME
828+
HWTSTAMP_FILTER_PTP_V1_L4_EVENT
829+
HWTSTAMP_FILTER_PTP_V1_L4_SYNC
830+
HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
831+
HWTSTAMP_FILTER_PTP_V2_L4_EVENT
832+
HWTSTAMP_FILTER_PTP_V2_L4_SYNC
833+
HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
834+
HWTSTAMP_FILTER_PTP_V2_L2_EVENT
835+
HWTSTAMP_FILTER_PTP_V2_L2_SYNC
836+
HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
837+
HWTSTAMP_FILTER_PTP_V2_EVENT
838+
HWTSTAMP_FILTER_PTP_V2_SYNC
839+
HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
840+
HWTSTAMP_FILTER_NTP_ALL
821841
IBSHIFT
822842
IFA_ADDRESS
823843
IFA_ANYCAST
@@ -2316,6 +2336,7 @@ SIOCDIFADDR
23162336
SIOCDRARP
23172337
SIOCETHTOOL
23182338
SIOCGARP
2339+
SIOCGHWTSTAMP
23192340
SIOCGIFADDR
23202341
SIOCGIFBR
23212342
SIOCGIFBRDADDR
@@ -2341,6 +2362,7 @@ SIOGIFINDEX
23412362
SIOCGMIIPHY
23422363
SIOCGMIIREG
23432364
SIOCSARP
2365+
SIOCSHWTSTAMP
23442366
SIOCSIFADDR
23452367
SIOCSIFBR
23462368
SIOCSIFBRDADDR
@@ -3128,6 +3150,7 @@ getspnam_r
31283150
gettid
31293151
getxattr
31303152
hasmntopt
3153+
hwtstamp_config
31313154
iconv
31323155
iconv_close
31333156
iconv_open

src/unix/linux_like/linux/mod.rs

+55
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,12 @@ s_no_extra_traits! {
798798
#[cfg(not(libc_union))]
799799
pub ifr_ifru: ::sockaddr,
800800
}
801+
802+
pub struct hwtstamp_config {
803+
pub flags: ::c_int,
804+
pub tx_type: ::c_int,
805+
pub rx_filter: ::c_int,
806+
}
801807
}
802808

803809
s_no_extra_traits! {
@@ -1221,6 +1227,31 @@ cfg_if! {
12211227
.finish()
12221228
}
12231229
}
1230+
1231+
impl ::fmt::Debug for hwtstamp_config {
1232+
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
1233+
f.debug_struct("hwtstamp_config")
1234+
.field("flags", &self.flags)
1235+
.field("tx_type", &self.tx_type)
1236+
.field("rx_filter", &self.rx_filter)
1237+
.finish()
1238+
}
1239+
}
1240+
impl PartialEq for hwtstamp_config {
1241+
fn eq(&self, other: &hwtstamp_config) -> bool {
1242+
self.flags == other.flags &&
1243+
self.tx_type == other.tx_type &&
1244+
self.rx_filter == other.rx_filter
1245+
}
1246+
}
1247+
impl Eq for hwtstamp_config {}
1248+
impl ::hash::Hash for hwtstamp_config {
1249+
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
1250+
self.flags.hash(state);
1251+
self.tx_type.hash(state);
1252+
self.rx_filter.hash(state);
1253+
}
1254+
}
12241255
}
12251256
}
12261257

@@ -2771,6 +2802,8 @@ pub const SIOCGRARP: ::c_ulong = 0x00008961;
27712802
pub const SIOCSRARP: ::c_ulong = 0x00008962;
27722803
pub const SIOCGIFMAP: ::c_ulong = 0x00008970;
27732804
pub const SIOCSIFMAP: ::c_ulong = 0x00008971;
2805+
pub const SIOCSHWTSTAMP: ::c_ulong = 0x000089b0;
2806+
pub const SIOCGHWTSTAMP: ::c_ulong = 0x000089b1;
27742807

27752808
pub const IPTOS_TOS_MASK: u8 = 0x1E;
27762809
pub const IPTOS_PREC_MASK: u8 = 0xE0;
@@ -3129,6 +3162,28 @@ pub const SOF_TIMESTAMPING_OPT_TX_SWHW: ::c_uint = 1 << 14;
31293162
pub const SOF_TXTIME_DEADLINE_MODE: u32 = 1 << 0;
31303163
pub const SOF_TXTIME_REPORT_ERRORS: u32 = 1 << 1;
31313164

3165+
pub const HWTSTAMP_TX_OFF: ::c_uint = 0;
3166+
pub const HWTSTAMP_TX_ON: ::c_uint = 1;
3167+
pub const HWTSTAMP_TX_ONESTEP_SYNC: ::c_uint = 2;
3168+
pub const HWTSTAMP_TX_ONESTEP_P2P: ::c_uint = 3;
3169+
3170+
pub const HWTSTAMP_FILTER_NONE: ::c_uint = 0;
3171+
pub const HWTSTAMP_FILTER_ALL: ::c_uint = 1;
3172+
pub const HWTSTAMP_FILTER_SOME: ::c_uint = 2;
3173+
pub const HWTSTAMP_FILTER_PTP_V1_L4_EVENT: ::c_uint = 3;
3174+
pub const HWTSTAMP_FILTER_PTP_V1_L4_SYNC: ::c_uint = 4;
3175+
pub const HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: ::c_uint = 5;
3176+
pub const HWTSTAMP_FILTER_PTP_V2_L4_EVENT: ::c_uint = 6;
3177+
pub const HWTSTAMP_FILTER_PTP_V2_L4_SYNC: ::c_uint = 7;
3178+
pub const HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: ::c_uint = 8;
3179+
pub const HWTSTAMP_FILTER_PTP_V2_L2_EVENT: ::c_uint = 9;
3180+
pub const HWTSTAMP_FILTER_PTP_V2_L2_SYNC: ::c_uint = 10;
3181+
pub const HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: ::c_uint = 11;
3182+
pub const HWTSTAMP_FILTER_PTP_V2_EVENT: ::c_uint = 12;
3183+
pub const HWTSTAMP_FILTER_PTP_V2_SYNC: ::c_uint = 13;
3184+
pub const HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ::c_uint = 14;
3185+
pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15;
3186+
31323187
// linux/if_alg.h
31333188
pub const ALG_SET_KEY: ::c_int = 1;
31343189
pub const ALG_SET_IV: ::c_int = 2;

0 commit comments

Comments
 (0)