From 4c06589e832da36852111b7b7b96b04094ce43cb Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Fri, 12 May 2023 11:26:17 +0200 Subject: [PATCH 1/4] Add linux canxl constants and canxl frame struct --- libc-test/semver/linux.txt | 14 ++++++++++++++ src/unix/linux_like/linux/align.rs | 11 +++++++++++ src/unix/linux_like/linux/mod.rs | 18 ++++++++++++++++++ 3 files changed, 43 insertions(+) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 5d86647f08c46..5b6ac0ee232fe 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -237,6 +237,19 @@ CAN_RAW_LOOPBACK CAN_RAW_RECV_OWN_MSGS CAN_RAW_FD_FRAMES CAN_RAW_JOIN_FILTERS +CANXL_HDR_SIZE +CANXL_MAX_DLC +CANXL_MAX_DLC_MASK +CANXL_MAX_DLEN +CANXL_MAX_MTU +CANXL_MIN_DLC +CANXL_MIN_DLEN +CANXL_MIN_MTU +CANXL_MTU +CANXL_PRIO_BITS +CANXL_PRIO_MASK +CANXL_SEC +CANXL_XLF CBAUD CBAUDEX CLD_CONTINUED @@ -3056,6 +3069,7 @@ can_err_mask_t can_filter can_frame canfd_frame +canxl_frame canid_t chroot clearenv diff --git a/src/unix/linux_like/linux/align.rs b/src/unix/linux_like/linux/align.rs index cd4bbc7213957..97f811dac18ee 100644 --- a/src/unix/linux_like/linux/align.rs +++ b/src/unix/linux_like/linux/align.rs @@ -176,6 +176,17 @@ macro_rules! expand_align { __res1: u8, pub data: [u8; CANFD_MAX_DLEN], } + + #[repr(align(8))] + #[allow(missing_debug_implementations)] + pub struct canxl_frame { + pub prio: canid_t, + pub flags: u8, + pub sdt: u8, + pub len: u16, + pub af: u32, + pub data: [u8; CANXL_MAX_DLEN], + } } }; } diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 45a383b405029..4b58361a26711 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3723,9 +3723,11 @@ pub const CAN_ERR_FLAG: canid_t = 0x20000000; pub const CAN_SFF_MASK: canid_t = 0x000007FF; pub const CAN_EFF_MASK: canid_t = 0x1FFFFFFF; pub const CAN_ERR_MASK: canid_t = 0x1FFFFFFF; +pub const CANXL_PRIO_MASK: ::canid_t = CAN_SFF_MASK; pub const CAN_SFF_ID_BITS: ::c_int = 11; pub const CAN_EFF_ID_BITS: ::c_int = 29; +pub const CANXL_PRIO_BITS: ::c_int = CAN_SFF_ID_BITS; pub const CAN_MAX_DLC: ::c_int = 8; pub const CAN_MAX_DLEN: usize = 8; @@ -3735,10 +3737,26 @@ pub const CANFD_MAX_DLEN: usize = 64; pub const CANFD_BRS: ::c_int = 0x01; pub const CANFD_ESI: ::c_int = 0x02; +pub const CANXL_MIN_DLC: ::c_int = 0; +pub const CANXL_MAX_DLC: ::c_int = 2047; +pub const CANXL_MAX_DLC_MASK: ::c_int = 0x07FF; +pub const CANXL_MIN_DLEN: usize = 1; +pub const CANXL_MAX_DLEN: usize = 2048; + +pub const CANXL_XLF: ::c_int = 0x80; +pub const CANXL_SEC: ::c_int = 0x01; + cfg_if! { if #[cfg(libc_align)] { pub const CAN_MTU: usize = ::mem::size_of::(); pub const CANFD_MTU: usize = ::mem::size_of::(); + pub const CANXL_MTU: usize = ::mem::size_of::(); + // FIXME: use `core::mem::offset_of!` once that is available + // https://github.com/rust-lang/rfcs/pull/3308 + // pub const CANXL_HDR_SIZE: usize = core::mem::offset_of!(canxl_frame, data); + pub const CANXL_HDR_SIZE: usize = 12; + pub const CANXL_MIN_MTU: usize = CANXL_HDR_SIZE + 64; + pub const CANXL_MAX_MTU: usize = CANXL_MTU; } } From 7914da1dd296b65fbe9742fbaa6c79d1cba72374 Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Fri, 12 May 2023 15:01:58 +0200 Subject: [PATCH 2/4] Add CAN_RAW_XL_FRAMES socket option --- libc-test/semver/linux.txt | 1 + src/unix/linux_like/linux/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 5b6ac0ee232fe..1b8700f02b16a 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -237,6 +237,7 @@ CAN_RAW_LOOPBACK CAN_RAW_RECV_OWN_MSGS CAN_RAW_FD_FRAMES CAN_RAW_JOIN_FILTERS +CAN_RAW_XL_FRAMES CANXL_HDR_SIZE CANXL_MAX_DLC CANXL_MAX_DLC_MASK diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 4b58361a26711..f9cdac0cef356 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3782,6 +3782,7 @@ pub const CAN_RAW_LOOPBACK: ::c_int = 3; pub const CAN_RAW_RECV_OWN_MSGS: ::c_int = 4; pub const CAN_RAW_FD_FRAMES: ::c_int = 5; pub const CAN_RAW_JOIN_FILTERS: ::c_int = 6; +pub const CAN_RAW_XL_FRAMES: ::c_int = 7; // linux/can/j1939.h pub const SOL_CAN_J1939: ::c_int = SOL_CAN_BASE + CAN_J1939; From af4b0a479184ad903a9d1fae50415375a1813ec2 Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Sun, 14 May 2023 10:15:12 +0200 Subject: [PATCH 3/4] Skip canxl constants --- libc-test/build.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 2f993486ef311..d64e9a38c2646 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3651,7 +3651,22 @@ fn test_linux(target: &str) { "FUTEX_LOCK_PI2" => true, // Added in linux 6.1 - "STATX_DIOALIGN" => true, + "STATX_DIOALIGN" + | "CAN_RAW_XL_FRAMES" + | "CANXL_HDR_SIZE" + | "CANXL_MAX_DLC" + | "CANXL_MAX_DLC_MASK" + | "CANXL_MAX_DLEN" + | "CANXL_MAX_MTU" + | "CANXL_MIN_DLC" + | "CANXL_MIN_DLEN" + | "CANXL_MIN_MTU" + | "CANXL_MTU" + | "CANXL_PRIO_BITS" + | "CANXL_PRIO_MASK" + | "CANXL_SEC" + | "CANXL_XLF" + => true, // FIXME: Parts of netfilter/nfnetlink*.h require more recent kernel headers: | "RTNLGRP_MCTP_IFADDR" // linux v5.17+ From ca85ccb53ed79212ba7e170d00e555801aae8304 Mon Sep 17 00:00:00 2001 From: marcelbuesing Date: Sun, 14 May 2023 10:17:16 +0200 Subject: [PATCH 4/4] Skip canxl_frame struct --- libc-test/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index d64e9a38c2646..f86dfbcbe6feb 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -3469,6 +3469,8 @@ fn test_linux(target: &str) { "sctp_initmsg" | "sctp_sndrcvinfo" | "sctp_sndinfo" | "sctp_rcvinfo" | "sctp_nxtinfo" | "sctp_prinfo" | "sctp_authinfo" => true, + // FIXME: requires >= 6.1 kernel headers + "canxl_frame" => true, _ => false, } });