Skip to content

Commit c4b12eb

Browse files
committed
Auto merge of #3453 - arctic-alpaca:main, r=JohnTitor
Add `if_xdp.h` structs and constants and add `SOL_XDP` to musl Hi, this PR adds constants and structs from `if_xdp.h` for use with [`AF_XDP`](https://www.kernel.org/doc/html/latest/networking/af_xdp.html). It also adds `SOL_XDP` to musl which was missing before. I'm not sure whether the location I added the code is correct, I just edited the files where the `AF_XDP` constant was defined. Some of the structs were changed between their initial release in the kernel and the current version. For those, `_v1` structs have been added for backwards compatibility.
2 parents 1e755f9 + 771b179 commit c4b12eb

File tree

5 files changed

+320
-0
lines changed

5 files changed

+320
-0
lines changed

libc-test/build.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3418,6 +3418,7 @@ fn test_linux(target: &str) {
34183418
"linux/if_alg.h",
34193419
"linux/if_ether.h",
34203420
"linux/if_tun.h",
3421+
"linux/if_xdp.h",
34213422
"linux/input.h",
34223423
"linux/ipv6.h",
34233424
"linux/kexec.h",
@@ -3652,6 +3653,30 @@ fn test_linux(target: &str) {
36523653
true
36533654
}
36543655

3656+
// FIXME: Requires >= 5.3 kernel headers.
3657+
// Everything that uses install-musl.sh has 4.19 kernel headers.
3658+
"xdp_options" if musl => true,
3659+
3660+
// FIXME: Requires >= 5.4 kernel headers.
3661+
// Everything that uses install-musl.sh has 4.19 kernel headers.
3662+
"xdp_umem_reg" | "xdp_ring_offset" | "xdp_mmap_offsets" if musl => true,
3663+
3664+
// FIXME: Requires >= 5.9 kernel headers.
3665+
// Everything that uses install-musl.sh has 4.19 kernel headers.
3666+
"xdp_statistics" if musl => true,
3667+
3668+
// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
3669+
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
3670+
"xdp_ring_offset_v1" | "xdp_mmap_offsets_v1" => true,
3671+
3672+
// Multiple new fields were added in kernel 5.9, this is the old version for backwards compatibility.
3673+
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
3674+
"xdp_statistics_v1" => true,
3675+
3676+
// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
3677+
// https://github.com/torvalds/linux/commit/c05cd3645814724bdeb32a2b4d953b12bdea5f8c
3678+
"xdp_umem_reg_v1" => true,
3679+
36553680
_ => false,
36563681
}
36573682
});
@@ -4004,6 +4029,34 @@ fn test_linux(target: &str) {
40044029
true
40054030
}
40064031

4032+
// FIXME: Requires >= 5.3 kernel headers.
4033+
// Everything that uses install-musl.sh has 4.19 kernel headers.
4034+
"XDP_OPTIONS_ZEROCOPY" | "XDP_OPTIONS"
4035+
if musl =>
4036+
{
4037+
true
4038+
}
4039+
4040+
// FIXME: Requires >= 5.4 kernel headers.
4041+
// Everything that uses install-musl.sh has 4.19 kernel headers.
4042+
"XSK_UNALIGNED_BUF_OFFSET_SHIFT"
4043+
| "XSK_UNALIGNED_BUF_ADDR_MASK"
4044+
| "XDP_UMEM_UNALIGNED_CHUNK_FLAG"
4045+
| "XDP_RING_NEED_WAKEUP"
4046+
| "XDP_USE_NEED_WAKEUP"
4047+
if musl =>
4048+
{
4049+
true
4050+
}
4051+
4052+
// FIXME: Requires >= 6.6 kernel headers.
4053+
"XDP_USE_SG"
4054+
| "XDP_PKT_CONTD"
4055+
=>
4056+
{
4057+
true
4058+
}
4059+
40074060
_ => false,
40084061
}
40094062
});

libc-test/semver/linux-musl.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ PF_XDP
2323
PIDFD_NONBLOCK
2424
PR_SET_VMA
2525
PR_SET_VMA_ANON_NAME
26+
SOL_XDP
27+
XDP_SHARED_UMEM
28+
XDP_COPY
29+
XDP_ZEROCOPY
30+
XDP_USE_NEED_WAKEUP
31+
XDP_USE_SG
32+
XDP_UMEM_UNALIGNED_CHUNK_FLAG
33+
XDP_RING_NEED_WAKEUP
34+
XDP_MMAP_OFFSETS
35+
XDP_RX_RING
36+
XDP_TX_RING
37+
XDP_UMEM_REG
38+
XDP_UMEM_FILL_RING
39+
XDP_UMEM_COMPLETION_RING
40+
XDP_STATISTICS
41+
XDP_OPTIONS
42+
XDP_OPTIONS_ZEROCOPY
43+
XDP_PGOFF_RX_RING
44+
XDP_PGOFF_TX_RING
45+
XDP_UMEM_PGOFF_FILL_RING
46+
XDP_UMEM_PGOFF_COMPLETION_RING
47+
XSK_UNALIGNED_BUF_OFFSET_SHIFT
48+
XSK_UNALIGNED_BUF_ADDR_MASK
49+
XDP_PKT_CONTD
2650
adjtimex
2751
aio_cancel
2852
aio_error

libc-test/semver/linux.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3218,6 +3218,29 @@ W_EXITCODE
32183218
W_STOPCODE
32193219
XATTR_CREATE
32203220
XATTR_REPLACE
3221+
XDP_SHARED_UMEM
3222+
XDP_COPY
3223+
XDP_ZEROCOPY
3224+
XDP_USE_NEED_WAKEUP
3225+
XDP_USE_SG
3226+
XDP_UMEM_UNALIGNED_CHUNK_FLAG
3227+
XDP_RING_NEED_WAKEUP
3228+
XDP_MMAP_OFFSETS
3229+
XDP_RX_RING
3230+
XDP_TX_RING
3231+
XDP_UMEM_REG
3232+
XDP_UMEM_FILL_RING
3233+
XDP_UMEM_COMPLETION_RING
3234+
XDP_STATISTICS
3235+
XDP_OPTIONS
3236+
XDP_OPTIONS_ZEROCOPY
3237+
XDP_PGOFF_RX_RING
3238+
XDP_PGOFF_TX_RING
3239+
XDP_UMEM_PGOFF_FILL_RING
3240+
XDP_UMEM_PGOFF_COMPLETION_RING
3241+
XSK_UNALIGNED_BUF_OFFSET_SHIFT
3242+
XSK_UNALIGNED_BUF_ADDR_MASK
3243+
XDP_PKT_CONTD
32213244
XTABS
32223245
YESEXPR
32233246
YESSTR

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

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,83 @@ s! {
355355
#[cfg(libc_union)]
356356
pub u: __c_anonymous_ptrace_syscall_info_data,
357357
}
358+
359+
// linux/if_xdp.h
360+
361+
pub struct sockaddr_xdp {
362+
pub sxdp_family: ::__u16,
363+
pub sxdp_flags: ::__u16,
364+
pub sxdp_ifindex: ::__u32,
365+
pub sxdp_queue_id: ::__u32,
366+
pub sxdp_shared_umem_fd: ::__u32,
367+
}
368+
369+
pub struct xdp_ring_offset {
370+
pub producer: ::__u64,
371+
pub consumer: ::__u64,
372+
pub desc: ::__u64,
373+
pub flags: ::__u64,
374+
}
375+
376+
pub struct xdp_mmap_offsets {
377+
pub rx: xdp_ring_offset,
378+
pub tx: xdp_ring_offset,
379+
pub fr: xdp_ring_offset,
380+
pub cr: xdp_ring_offset,
381+
}
382+
383+
pub struct xdp_ring_offset_v1 {
384+
pub producer: ::__u64,
385+
pub consumer: ::__u64,
386+
pub desc: ::__u64,
387+
}
388+
389+
pub struct xdp_mmap_offsets_v1 {
390+
pub rx: xdp_ring_offset_v1,
391+
pub tx: xdp_ring_offset_v1,
392+
pub fr: xdp_ring_offset_v1,
393+
pub cr: xdp_ring_offset_v1,
394+
}
395+
396+
pub struct xdp_umem_reg {
397+
pub addr: ::__u64,
398+
pub len: ::__u64,
399+
pub chunk_size: ::__u32,
400+
pub headroom: ::__u32,
401+
pub flags: ::__u32,
402+
}
403+
404+
pub struct xdp_umem_reg_v1 {
405+
pub addr: ::__u64,
406+
pub len: ::__u64,
407+
pub chunk_size: ::__u32,
408+
pub headroom: ::__u32,
409+
}
410+
411+
pub struct xdp_statistics {
412+
pub rx_dropped: ::__u64,
413+
pub rx_invalid_descs: ::__u64,
414+
pub tx_invalid_descs: ::__u64,
415+
pub rx_ring_full: ::__u64,
416+
pub rx_fill_ring_empty_descs: ::__u64,
417+
pub tx_ring_empty_descs: ::__u64,
418+
}
419+
420+
pub struct xdp_statistics_v1 {
421+
pub rx_dropped: ::__u64,
422+
pub rx_invalid_descs: ::__u64,
423+
pub tx_invalid_descs: ::__u64,
424+
}
425+
426+
pub struct xdp_options {
427+
pub flags: ::__u32,
428+
}
429+
430+
pub struct xdp_desc {
431+
pub addr: ::__u64,
432+
pub len: ::__u32,
433+
pub options: ::__u32,
434+
}
358435
}
359436

360437
impl siginfo_t {
@@ -920,6 +997,38 @@ pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
920997
pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
921998
pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;
922999

1000+
// linux/if_xdp.h
1001+
pub const XDP_SHARED_UMEM: ::__u16 = 1 << 0;
1002+
pub const XDP_COPY: ::__u16 = 1 << 1;
1003+
pub const XDP_ZEROCOPY: ::__u16 = 1 << 2;
1004+
pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3;
1005+
pub const XDP_USE_SG: ::__u16 = 1 << 4;
1006+
1007+
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0;
1008+
1009+
pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0;
1010+
1011+
pub const XDP_MMAP_OFFSETS: ::c_int = 1;
1012+
pub const XDP_RX_RING: ::c_int = 2;
1013+
pub const XDP_TX_RING: ::c_int = 3;
1014+
pub const XDP_UMEM_REG: ::c_int = 4;
1015+
pub const XDP_UMEM_FILL_RING: ::c_int = 5;
1016+
pub const XDP_UMEM_COMPLETION_RING: ::c_int = 6;
1017+
pub const XDP_STATISTICS: ::c_int = 7;
1018+
pub const XDP_OPTIONS: ::c_int = 8;
1019+
1020+
pub const XDP_OPTIONS_ZEROCOPY: ::__u32 = 1 << 0;
1021+
1022+
pub const XDP_PGOFF_RX_RING: ::off_t = 0;
1023+
pub const XDP_PGOFF_TX_RING: ::off_t = 0x80000000;
1024+
pub const XDP_UMEM_PGOFF_FILL_RING: ::c_ulonglong = 0x100000000;
1025+
pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000;
1026+
1027+
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48;
1028+
pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
1029+
1030+
pub const XDP_PKT_CONTD: ::__u32 = 1 << 0;
1031+
9231032
// elf.h
9241033
pub const NT_PRSTATUS: ::c_int = 1;
9251034
pub const NT_PRFPREG: ::c_int = 2;

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

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,83 @@ s! {
271271
pub maxerror: ::c_long,
272272
pub esterror: ::c_long,
273273
}
274+
275+
// linux/if_xdp.h
276+
277+
pub struct sockaddr_xdp {
278+
pub sxdp_family: ::__u16,
279+
pub sxdp_flags: ::__u16,
280+
pub sxdp_ifindex: ::__u32,
281+
pub sxdp_queue_id: ::__u32,
282+
pub sxdp_shared_umem_fd: ::__u32,
283+
}
284+
285+
pub struct xdp_ring_offset {
286+
pub producer: ::__u64,
287+
pub consumer: ::__u64,
288+
pub desc: ::__u64,
289+
pub flags: ::__u64,
290+
}
291+
292+
pub struct xdp_mmap_offsets {
293+
pub rx: xdp_ring_offset,
294+
pub tx: xdp_ring_offset,
295+
pub fr: xdp_ring_offset,
296+
pub cr: xdp_ring_offset,
297+
}
298+
299+
pub struct xdp_ring_offset_v1 {
300+
pub producer: ::__u64,
301+
pub consumer: ::__u64,
302+
pub desc: ::__u64,
303+
}
304+
305+
pub struct xdp_mmap_offsets_v1 {
306+
pub rx: xdp_ring_offset_v1,
307+
pub tx: xdp_ring_offset_v1,
308+
pub fr: xdp_ring_offset_v1,
309+
pub cr: xdp_ring_offset_v1,
310+
}
311+
312+
pub struct xdp_umem_reg {
313+
pub addr: ::__u64,
314+
pub len: ::__u64,
315+
pub chunk_size: ::__u32,
316+
pub headroom: ::__u32,
317+
pub flags: ::__u32,
318+
}
319+
320+
pub struct xdp_umem_reg_v1 {
321+
pub addr: ::__u64,
322+
pub len: ::__u64,
323+
pub chunk_size: ::__u32,
324+
pub headroom: ::__u32,
325+
}
326+
327+
pub struct xdp_statistics {
328+
pub rx_dropped: ::__u64,
329+
pub rx_invalid_descs: ::__u64,
330+
pub tx_invalid_descs: ::__u64,
331+
pub rx_ring_full: ::__u64,
332+
pub rx_fill_ring_empty_descs: ::__u64,
333+
pub tx_ring_empty_descs: ::__u64,
334+
}
335+
336+
pub struct xdp_statistics_v1 {
337+
pub rx_dropped: ::__u64,
338+
pub rx_invalid_descs: ::__u64,
339+
pub tx_invalid_descs: ::__u64,
340+
}
341+
342+
pub struct xdp_options {
343+
pub flags: ::__u32,
344+
}
345+
346+
pub struct xdp_desc {
347+
pub addr: ::__u64,
348+
pub len: ::__u32,
349+
pub options: ::__u32,
350+
}
274351
}
275352

276353
s_no_extra_traits! {
@@ -703,6 +780,40 @@ pub const TIME_ERROR: ::c_int = 5;
703780
pub const TIME_BAD: ::c_int = TIME_ERROR;
704781
pub const MAXTC: ::c_long = 6;
705782

783+
pub const SOL_XDP: ::c_int = 283;
784+
785+
// linux/if_xdp.h
786+
pub const XDP_SHARED_UMEM: ::__u16 = 1 << 0;
787+
pub const XDP_COPY: ::__u16 = 1 << 1;
788+
pub const XDP_ZEROCOPY: ::__u16 = 1 << 2;
789+
pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3;
790+
pub const XDP_USE_SG: ::__u16 = 1 << 4;
791+
792+
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0;
793+
794+
pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0;
795+
796+
pub const XDP_MMAP_OFFSETS: ::c_int = 1;
797+
pub const XDP_RX_RING: ::c_int = 2;
798+
pub const XDP_TX_RING: ::c_int = 3;
799+
pub const XDP_UMEM_REG: ::c_int = 4;
800+
pub const XDP_UMEM_FILL_RING: ::c_int = 5;
801+
pub const XDP_UMEM_COMPLETION_RING: ::c_int = 6;
802+
pub const XDP_STATISTICS: ::c_int = 7;
803+
pub const XDP_OPTIONS: ::c_int = 8;
804+
805+
pub const XDP_OPTIONS_ZEROCOPY: ::__u32 = 1 << 0;
806+
807+
pub const XDP_PGOFF_RX_RING: ::off_t = 0;
808+
pub const XDP_PGOFF_TX_RING: ::off_t = 0x80000000;
809+
pub const XDP_UMEM_PGOFF_FILL_RING: ::c_ulonglong = 0x100000000;
810+
pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000;
811+
812+
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48;
813+
pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;
814+
815+
pub const XDP_PKT_CONTD: ::__u32 = 1 << 0;
816+
706817
cfg_if! {
707818
if #[cfg(target_arch = "s390x")] {
708819
pub const POSIX_FADV_DONTNEED: ::c_int = 6;

0 commit comments

Comments
 (0)