Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux: update and add missing AF_XDP API #3956

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3817,12 +3817,25 @@ fn test_linux(target: &str) {

// FIXME: Requires >= 5.4 kernel headers.
// Everything that uses install-musl.sh has 4.19 kernel headers.
"xdp_umem_reg" | "xdp_ring_offset" | "xdp_mmap_offsets" if musl => true,
"xdp_ring_offset" | "xdp_mmap_offsets" if musl => true,

// FIXME: Requires >= 6.8 kernel headers.
// A field was added in 6.8.
// https://github.com/torvalds/linux/commit/341ac980eab90ac1f6c22ee9f9da83ed9604d899
// The previous version of the struct was removed in 6.11 due to a bug.
// https://github.com/torvalds/linux/commit/32654bbd6313b4cfc82297e6634fa9725c3c900f
"xdp_umem_reg" => true,

// FIXME: Requires >= 5.9 kernel headers.
// Everything that uses install-musl.sh has 4.19 kernel headers.
"xdp_statistics" if musl => true,

// FIXME: Requires >= 6.8 kernel headers.
"xsk_tx_metadata"
| "__c_anonymous_xsk_tx_metadata_union"
| "xsk_tx_metadata_request"
| "xsk_tx_metadata_completion" => true,

// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
"xdp_ring_offset_v1" | "xdp_mmap_offsets_v1" => true,
Expand Down Expand Up @@ -4267,6 +4280,23 @@ fn test_linux(target: &str) {
true
}

// FIXME: Requires >= 6.8 kernel headers.
"XDP_UMEM_TX_SW_CSUM"
| "XDP_TXMD_FLAGS_TIMESTAMP"
| "XDP_TXMD_FLAGS_CHECKSUM"
| "XDP_TX_METADATA"
=>
{
true
}

// FIXME: Requires >= 6.11 kernel headers.
"XDP_UMEM_TX_METADATA_LEN"
=>
{
true
}

// FIXME: Requires >= 6.6 kernel headers.
"SYS_fchmodat2" => true,

Expand Down Expand Up @@ -4524,7 +4554,9 @@ fn test_linux(target: &str) {
(musl && struct_ == "mcontext_t" && field == "__extcontext" && loongarch64) ||
// FIXME(#4121): a new field was added from `f_spare`
(struct_ == "statvfs" && field == "__f_spare") ||
(struct_ == "statvfs64" && field == "__f_spare")
(struct_ == "statvfs64" && field == "__f_spare") ||
// the `xsk_tx_metadata_union` field is an anonymous union
(struct_ == "xsk_tx_metadata" && field == "xsk_tx_metadata_union")
});

cfg.skip_roundtrip(move |s| match s {
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3387,6 +3387,11 @@ W_EXITCODE
W_STOPCODE
XATTR_CREATE
XATTR_REPLACE
XDP_TXMD_FLAGS_CHECKSUM
XDP_TXMD_FLAGS_TIMESTAMP
XDP_TX_METADATA
XDP_UMEM_TX_METADATA_LEN
XDP_UMEM_TX_SW_CSUM
XTABS
YESEXPR
YESSTR
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ s! {
pub chunk_size: ::__u32,
pub headroom: ::__u32,
pub flags: ::__u32,
pub tx_metadata_len: ::__u32,
}

pub struct xdp_umem_reg_v1 {
Expand Down
32 changes: 32 additions & 0 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,16 @@ s! {
pub chan: ::c_uint,
pub rsv: [::c_uint; 5],
}

// linux/if_xdp.h
pub struct xsk_tx_metadata_completion {
pub tx_timestamp: ::__u64,
}

pub struct xsk_tx_metadata_request {
pub csum_start: ::__u16,
pub csum_offset: ::__u16,
}
}

cfg_if! {
Expand Down Expand Up @@ -1648,6 +1658,19 @@ s_no_extra_traits! {
pub flags: ::c_uint,
pub anonymous_2: __c_anonymous_ptp_perout_request_2,
}

// linux/if_xdp.h
#[allow(missing_debug_implementations)]
pub struct xsk_tx_metadata {
pub flags: ::__u64,
pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union,
}

#[allow(missing_debug_implementations)]
pub union __c_anonymous_xsk_tx_metadata_union {
pub request: xsk_tx_metadata_request,
pub completion: xsk_tx_metadata_completion,
}
}

cfg_if! {
Expand Down Expand Up @@ -5592,6 +5615,15 @@ pub const SCHED_FLAG_KEEP_PARAMS: ::c_int = 0x10;
pub const SCHED_FLAG_UTIL_CLAMP_MIN: ::c_int = 0x20;
pub const SCHED_FLAG_UTIL_CLAMP_MAX: ::c_int = 0x40;

// linux/if_xdp.h
pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1;
pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2;

pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0;
pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1;

pub const XDP_TX_METADATA: ::__u32 = 1 << 1;

// elf.h
pub const NT_PRSTATUS: ::c_int = 1;
pub const NT_PRFPREG: ::c_int = 2;
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ s! {
pub chunk_size: ::__u32,
pub headroom: ::__u32,
pub flags: ::__u32,
pub tx_metadata_len: ::__u32,
}

pub struct xdp_umem_reg_v1 {
Expand Down