Skip to content

Commit 52ccb98

Browse files
authoredNov 20, 2024
Merge pull request #3956 from arctic-alpaca/af_xdp
Linux: update and add missing AF_XDP API
2 parents b3d958a + 88aa42a commit 52ccb98

File tree

5 files changed

+73
-2
lines changed

5 files changed

+73
-2
lines changed
 

‎libc-test/build.rs

+34-2
Original file line numberDiff line numberDiff line change
@@ -3817,12 +3817,25 @@ fn test_linux(target: &str) {
38173817

38183818
// FIXME: Requires >= 5.4 kernel headers.
38193819
// Everything that uses install-musl.sh has 4.19 kernel headers.
3820-
"xdp_umem_reg" | "xdp_ring_offset" | "xdp_mmap_offsets" if musl => true,
3820+
"xdp_ring_offset" | "xdp_mmap_offsets" if musl => true,
3821+
3822+
// FIXME: Requires >= 6.8 kernel headers.
3823+
// A field was added in 6.8.
3824+
// https://github.com/torvalds/linux/commit/341ac980eab90ac1f6c22ee9f9da83ed9604d899
3825+
// The previous version of the struct was removed in 6.11 due to a bug.
3826+
// https://github.com/torvalds/linux/commit/32654bbd6313b4cfc82297e6634fa9725c3c900f
3827+
"xdp_umem_reg" => true,
38213828

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

3833+
// FIXME: Requires >= 6.8 kernel headers.
3834+
"xsk_tx_metadata"
3835+
| "__c_anonymous_xsk_tx_metadata_union"
3836+
| "xsk_tx_metadata_request"
3837+
| "xsk_tx_metadata_completion" => true,
3838+
38263839
// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
38273840
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
38283841
"xdp_ring_offset_v1" | "xdp_mmap_offsets_v1" => true,
@@ -4267,6 +4280,23 @@ fn test_linux(target: &str) {
42674280
true
42684281
}
42694282

4283+
// FIXME: Requires >= 6.8 kernel headers.
4284+
"XDP_UMEM_TX_SW_CSUM"
4285+
| "XDP_TXMD_FLAGS_TIMESTAMP"
4286+
| "XDP_TXMD_FLAGS_CHECKSUM"
4287+
| "XDP_TX_METADATA"
4288+
=>
4289+
{
4290+
true
4291+
}
4292+
4293+
// FIXME: Requires >= 6.11 kernel headers.
4294+
"XDP_UMEM_TX_METADATA_LEN"
4295+
=>
4296+
{
4297+
true
4298+
}
4299+
42704300
// FIXME: Requires >= 6.6 kernel headers.
42714301
"SYS_fchmodat2" => true,
42724302

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

45304562
cfg.skip_roundtrip(move |s| match s {

‎libc-test/semver/linux.txt

+5
Original file line numberDiff line numberDiff line change
@@ -3387,6 +3387,11 @@ W_EXITCODE
33873387
W_STOPCODE
33883388
XATTR_CREATE
33893389
XATTR_REPLACE
3390+
XDP_TXMD_FLAGS_CHECKSUM
3391+
XDP_TXMD_FLAGS_TIMESTAMP
3392+
XDP_TX_METADATA
3393+
XDP_UMEM_TX_METADATA_LEN
3394+
XDP_UMEM_TX_SW_CSUM
33903395
XTABS
33913396
YESEXPR
33923397
YESSTR

‎src/unix/linux_like/linux/gnu/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ s! {
401401
pub chunk_size: ::__u32,
402402
pub headroom: ::__u32,
403403
pub flags: ::__u32,
404+
pub tx_metadata_len: ::__u32,
404405
}
405406

406407
pub struct xdp_umem_reg_v1 {

‎src/unix/linux_like/linux/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1194,6 +1194,16 @@ s! {
11941194
pub chan: ::c_uint,
11951195
pub rsv: [::c_uint; 5],
11961196
}
1197+
1198+
// linux/if_xdp.h
1199+
pub struct xsk_tx_metadata_completion {
1200+
pub tx_timestamp: ::__u64,
1201+
}
1202+
1203+
pub struct xsk_tx_metadata_request {
1204+
pub csum_start: ::__u16,
1205+
pub csum_offset: ::__u16,
1206+
}
11971207
}
11981208

11991209
cfg_if! {
@@ -1648,6 +1658,19 @@ s_no_extra_traits! {
16481658
pub flags: ::c_uint,
16491659
pub anonymous_2: __c_anonymous_ptp_perout_request_2,
16501660
}
1661+
1662+
// linux/if_xdp.h
1663+
#[allow(missing_debug_implementations)]
1664+
pub struct xsk_tx_metadata {
1665+
pub flags: ::__u64,
1666+
pub xsk_tx_metadata_union: __c_anonymous_xsk_tx_metadata_union,
1667+
}
1668+
1669+
#[allow(missing_debug_implementations)]
1670+
pub union __c_anonymous_xsk_tx_metadata_union {
1671+
pub request: xsk_tx_metadata_request,
1672+
pub completion: xsk_tx_metadata_completion,
1673+
}
16511674
}
16521675

16531676
cfg_if! {
@@ -5592,6 +5615,15 @@ pub const SCHED_FLAG_KEEP_PARAMS: ::c_int = 0x10;
55925615
pub const SCHED_FLAG_UTIL_CLAMP_MIN: ::c_int = 0x20;
55935616
pub const SCHED_FLAG_UTIL_CLAMP_MAX: ::c_int = 0x40;
55945617

5618+
// linux/if_xdp.h
5619+
pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1;
5620+
pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2;
5621+
5622+
pub const XDP_TXMD_FLAGS_TIMESTAMP: ::__u32 = 1 << 0;
5623+
pub const XDP_TXMD_FLAGS_CHECKSUM: ::__u32 = 1 << 1;
5624+
5625+
pub const XDP_TX_METADATA: ::__u32 = 1 << 1;
5626+
55955627
// elf.h
55965628
pub const NT_PRSTATUS: ::c_int = 1;
55975629
pub const NT_PRFPREG: ::c_int = 2;

‎src/unix/linux_like/linux/musl/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ s! {
311311
pub chunk_size: ::__u32,
312312
pub headroom: ::__u32,
313313
pub flags: ::__u32,
314+
pub tx_metadata_len: ::__u32,
314315
}
315316

316317
pub struct xdp_umem_reg_v1 {

0 commit comments

Comments
 (0)