Skip to content

Commit

Permalink
definitions for linux hardware timestamping
Browse files Browse the repository at this point in the history
  • Loading branch information
Folkert authored and folkertdev committed Apr 3, 2023
1 parent e0d66cd commit 4949998
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3394,7 +3394,7 @@ fn test_linux(target: &str) {
}
// FIXME(https://github.com/rust-lang/libc/issues/1558): passing by
// value corrupts the value for reasons not understood.
if (gnu && sparc64) && ty == "ip_mreqn" {
if (gnu && sparc64) && (ty == "ip_mreqn" || ty == "hwtstamp_config") {
return true;
}
match ty {
Expand Down Expand Up @@ -3724,6 +3724,9 @@ fn test_linux(target: &str) {
=> true,
"SCTP_FUTURE_ASSOC" | "SCTP_CURRENT_ASSOC" | "SCTP_ALL_ASSOC" | "SCTP_PEER_ADDR_THLDS_V2" => true, // linux 5.5+

// FIXME: Requires more recent kernel headers
"HWTSTAMP_TX_ONESTEP_P2P" if sparc64 || musl => true, // linux v5.6+

_ => false,
}
});
Expand Down
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,26 @@ GLOB_NOSPACE
GRND_NONBLOCK
GRND_RANDOM
GRND_INSECURE
HWTSTAMP_TX_OFF
HWTSTAMP_TX_ON
HWTSTAMP_TX_ONESTEP_SYNC
HWTSTAMP_TX_ONESTEP_P2P
HWTSTAMP_FILTER_NONE
HWTSTAMP_FILTER_ALL
HWTSTAMP_FILTER_SOME
HWTSTAMP_FILTER_PTP_V1_L4_EVENT
HWTSTAMP_FILTER_PTP_V1_L4_SYNC
HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ
HWTSTAMP_FILTER_PTP_V2_L4_EVENT
HWTSTAMP_FILTER_PTP_V2_L4_SYNC
HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ
HWTSTAMP_FILTER_PTP_V2_L2_EVENT
HWTSTAMP_FILTER_PTP_V2_L2_SYNC
HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ
HWTSTAMP_FILTER_PTP_V2_EVENT
HWTSTAMP_FILTER_PTP_V2_SYNC
HWTSTAMP_FILTER_PTP_V2_DELAY_REQ
HWTSTAMP_FILTER_NTP_ALL
IBSHIFT
IFA_ADDRESS
IFA_ANYCAST
Expand Down Expand Up @@ -2316,6 +2336,7 @@ SIOCDIFADDR
SIOCDRARP
SIOCETHTOOL
SIOCGARP
SIOCGHWTSTAMP
SIOCGIFADDR
SIOCGIFBR
SIOCGIFBRDADDR
Expand All @@ -2341,6 +2362,7 @@ SIOGIFINDEX
SIOCGMIIPHY
SIOCGMIIREG
SIOCSARP
SIOCSHWTSTAMP
SIOCSIFADDR
SIOCSIFBR
SIOCSIFBRDADDR
Expand Down Expand Up @@ -3128,6 +3150,7 @@ getspnam_r
gettid
getxattr
hasmntopt
hwtstamp_config
iconv
iconv_close
iconv_open
Expand Down
55 changes: 55 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -798,6 +798,12 @@ s_no_extra_traits! {
#[cfg(not(libc_union))]
pub ifr_ifru: ::sockaddr,
}

pub struct hwtstamp_config {
pub flags: ::c_int,
pub tx_type: ::c_int,
pub rx_filter: ::c_int,
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -1221,6 +1227,31 @@ cfg_if! {
.finish()
}
}

impl ::fmt::Debug for hwtstamp_config {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("hwtstamp_config")
.field("flags", &self.flags)
.field("tx_type", &self.tx_type)
.field("rx_filter", &self.rx_filter)
.finish()
}
}
impl PartialEq for hwtstamp_config {
fn eq(&self, other: &hwtstamp_config) -> bool {
self.flags == other.flags &&
self.tx_type == other.tx_type &&
self.rx_filter == other.rx_filter
}
}
impl Eq for hwtstamp_config {}
impl ::hash::Hash for hwtstamp_config {
fn hash<H: ::hash::Hasher>(&self, state: &mut H) {
self.flags.hash(state);
self.tx_type.hash(state);
self.rx_filter.hash(state);
}
}
}
}

Expand Down Expand Up @@ -2771,6 +2802,8 @@ pub const SIOCGRARP: ::c_ulong = 0x00008961;
pub const SIOCSRARP: ::c_ulong = 0x00008962;
pub const SIOCGIFMAP: ::c_ulong = 0x00008970;
pub const SIOCSIFMAP: ::c_ulong = 0x00008971;
pub const SIOCSHWTSTAMP: ::c_ulong = 0x000089b0;
pub const SIOCGHWTSTAMP: ::c_ulong = 0x000089b1;

pub const IPTOS_TOS_MASK: u8 = 0x1E;
pub const IPTOS_PREC_MASK: u8 = 0xE0;
Expand Down Expand Up @@ -3129,6 +3162,28 @@ pub const SOF_TIMESTAMPING_OPT_TX_SWHW: ::c_uint = 1 << 14;
pub const SOF_TXTIME_DEADLINE_MODE: u32 = 1 << 0;
pub const SOF_TXTIME_REPORT_ERRORS: u32 = 1 << 1;

pub const HWTSTAMP_TX_OFF: ::c_uint = 0;
pub const HWTSTAMP_TX_ON: ::c_uint = 1;
pub const HWTSTAMP_TX_ONESTEP_SYNC: ::c_uint = 2;
pub const HWTSTAMP_TX_ONESTEP_P2P: ::c_uint = 3;

pub const HWTSTAMP_FILTER_NONE: ::c_uint = 0;
pub const HWTSTAMP_FILTER_ALL: ::c_uint = 1;
pub const HWTSTAMP_FILTER_SOME: ::c_uint = 2;
pub const HWTSTAMP_FILTER_PTP_V1_L4_EVENT: ::c_uint = 3;
pub const HWTSTAMP_FILTER_PTP_V1_L4_SYNC: ::c_uint = 4;
pub const HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: ::c_uint = 5;
pub const HWTSTAMP_FILTER_PTP_V2_L4_EVENT: ::c_uint = 6;
pub const HWTSTAMP_FILTER_PTP_V2_L4_SYNC: ::c_uint = 7;
pub const HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: ::c_uint = 8;
pub const HWTSTAMP_FILTER_PTP_V2_L2_EVENT: ::c_uint = 9;
pub const HWTSTAMP_FILTER_PTP_V2_L2_SYNC: ::c_uint = 10;
pub const HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: ::c_uint = 11;
pub const HWTSTAMP_FILTER_PTP_V2_EVENT: ::c_uint = 12;
pub const HWTSTAMP_FILTER_PTP_V2_SYNC: ::c_uint = 13;
pub const HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: ::c_uint = 14;
pub const HWTSTAMP_FILTER_NTP_ALL: ::c_uint = 15;

// linux/if_alg.h
pub const ALG_SET_KEY: ::c_int = 1;
pub const ALG_SET_IV: ::c_int = 2;
Expand Down

0 comments on commit 4949998

Please sign in to comment.