Skip to content

Commit

Permalink
update/add missing AF_XDP structs & constants
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-alpaca committed Nov 20, 2024
1 parent 93b49b1 commit 6bc41c9
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 2 deletions.
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-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -489,12 +489,17 @@ XDP_RING_NEED_WAKEUP
XDP_RX_RING
XDP_SHARED_UMEM
XDP_STATISTICS
XDP_TXMD_FLAGS_CHECKSUM
XDP_TXMD_FLAGS_TIMESTAMP
XDP_TX_METADATA
XDP_TX_RING
XDP_UMEM_COMPLETION_RING
XDP_UMEM_FILL_RING
XDP_UMEM_PGOFF_COMPLETION_RING
XDP_UMEM_PGOFF_FILL_RING
XDP_UMEM_REG
XDP_UMEM_TX_METADATA_LEN
XDP_UMEM_TX_SW_CSUM
XDP_UMEM_UNALIGNED_CHUNK_FLAG
XDP_USE_NEED_WAKEUP
XDP_USE_SG
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/linux-musl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ XDP_RING_NEED_WAKEUP
XDP_RX_RING
XDP_SHARED_UMEM
XDP_STATISTICS
XDP_TXMD_FLAGS_CHECKSUM
XDP_TXMD_FLAGS_TIMESTAMP
XDP_TX_METADATA
XDP_TX_RING
XDP_UMEM_COMPLETION_RING
XDP_UMEM_FILL_RING
XDP_UMEM_PGOFF_COMPLETION_RING
XDP_UMEM_PGOFF_FILL_RING
XDP_UMEM_REG
XDP_UMEM_TX_METADATA_LEN
XDP_UMEM_TX_SW_CSUM
XDP_UMEM_UNALIGNED_CHUNK_FLAG
XDP_USE_NEED_WAKEUP
XDP_USE_SG
Expand Down
28 changes: 28 additions & 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 Expand Up @@ -435,6 +436,15 @@ s! {
pub options: ::__u32,
}

pub struct xsk_tx_metadata_completion {
pub tx_timestamp: ::__u64,
}

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

pub struct iocb {
pub aio_data: ::__u64,
#[cfg(target_endian = "little")]
Expand Down Expand Up @@ -656,6 +666,18 @@ s_no_extra_traits! {
pub ut_addr_v6: [i32; 4],
__glibc_reserved: [::c_char; 20],
}

#[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 @@ -1087,6 +1109,8 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3;
pub const XDP_USE_SG: ::__u16 = 1 << 4;

pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0;
pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1;
pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2;

pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0;

Expand All @@ -1109,7 +1133,11 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000;
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48;
pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;

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

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

pub const ELFOSABI_ARM_AEABI: u8 = 64;

Expand Down
28 changes: 28 additions & 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 Expand Up @@ -345,6 +346,15 @@ s! {
pub options: ::__u32,
}

pub struct xsk_tx_metadata_completion {
pub tx_timestamp: ::__u64,
}

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

// netinet/tcp.h

pub struct tcp_info {
Expand Down Expand Up @@ -482,6 +492,18 @@ s_no_extra_traits! {
pub ut_addr_v6: [::c_uint; 4],
__unused: [::c_char; 20],
}

#[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 @@ -887,6 +909,8 @@ pub const XDP_USE_NEED_WAKEUP: ::__u16 = 1 << 3;
pub const XDP_USE_SG: ::__u16 = 1 << 4;

pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: ::__u32 = 1 << 0;
pub const XDP_UMEM_TX_SW_CSUM: ::__u32 = 1 << 1;
pub const XDP_UMEM_TX_METADATA_LEN: ::__u32 = 1 << 2;

pub const XDP_RING_NEED_WAKEUP: ::__u32 = 1 << 0;

Expand All @@ -909,7 +933,11 @@ pub const XDP_UMEM_PGOFF_COMPLETION_RING: ::c_ulonglong = 0x180000000;
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: ::c_int = 48;
pub const XSK_UNALIGNED_BUF_ADDR_MASK: ::c_ulonglong = (1 << XSK_UNALIGNED_BUF_OFFSET_SHIFT) - 1;

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

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

pub const _CS_V6_ENV: ::c_int = 1148;
pub const _CS_V7_ENV: ::c_int = 1149;
Expand Down

0 comments on commit 6bc41c9

Please sign in to comment.