Skip to content

Commit

Permalink
Auto merge of #3453 - arctic-alpaca:main, r=JohnTitor
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bors committed Dec 9, 2023
2 parents 1e755f9 + 771b179 commit c4b12eb
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 0 deletions.
53 changes: 53 additions & 0 deletions libc-test/build.rs
Expand Up @@ -3418,6 +3418,7 @@ fn test_linux(target: &str) {
"linux/if_alg.h",
"linux/if_ether.h",
"linux/if_tun.h",
"linux/if_xdp.h",
"linux/input.h",
"linux/ipv6.h",
"linux/kexec.h",
Expand Down Expand Up @@ -3652,6 +3653,30 @@ fn test_linux(target: &str) {
true
}

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

// 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,

// FIXME: Requires >= 5.9 kernel headers.
// Everything that uses install-musl.sh has 4.19 kernel headers.
"xdp_statistics" if musl => 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,

// Multiple new fields were added in kernel 5.9, this is the old version for backwards compatibility.
// https://github.com/torvalds/linux/commit/77cd0d7b3f257fd0e3096b4fdcff1a7d38e99e10
"xdp_statistics_v1" => true,

// A new field was added in kernel 5.4, this is the old version for backwards compatibility.
// https://github.com/torvalds/linux/commit/c05cd3645814724bdeb32a2b4d953b12bdea5f8c
"xdp_umem_reg_v1" => true,

_ => false,
}
});
Expand Down Expand Up @@ -4004,6 +4029,34 @@ fn test_linux(target: &str) {
true
}

// FIXME: Requires >= 5.3 kernel headers.
// Everything that uses install-musl.sh has 4.19 kernel headers.
"XDP_OPTIONS_ZEROCOPY" | "XDP_OPTIONS"
if musl =>
{
true
}

// FIXME: Requires >= 5.4 kernel headers.
// Everything that uses install-musl.sh has 4.19 kernel headers.
"XSK_UNALIGNED_BUF_OFFSET_SHIFT"
| "XSK_UNALIGNED_BUF_ADDR_MASK"
| "XDP_UMEM_UNALIGNED_CHUNK_FLAG"
| "XDP_RING_NEED_WAKEUP"
| "XDP_USE_NEED_WAKEUP"
if musl =>
{
true
}

// FIXME: Requires >= 6.6 kernel headers.
"XDP_USE_SG"
| "XDP_PKT_CONTD"
=>
{
true
}

_ => false,
}
});
Expand Down
24 changes: 24 additions & 0 deletions libc-test/semver/linux-musl.txt
Expand Up @@ -23,6 +23,30 @@ PF_XDP
PIDFD_NONBLOCK
PR_SET_VMA
PR_SET_VMA_ANON_NAME
SOL_XDP
XDP_SHARED_UMEM
XDP_COPY
XDP_ZEROCOPY
XDP_USE_NEED_WAKEUP
XDP_USE_SG
XDP_UMEM_UNALIGNED_CHUNK_FLAG
XDP_RING_NEED_WAKEUP
XDP_MMAP_OFFSETS
XDP_RX_RING
XDP_TX_RING
XDP_UMEM_REG
XDP_UMEM_FILL_RING
XDP_UMEM_COMPLETION_RING
XDP_STATISTICS
XDP_OPTIONS
XDP_OPTIONS_ZEROCOPY
XDP_PGOFF_RX_RING
XDP_PGOFF_TX_RING
XDP_UMEM_PGOFF_FILL_RING
XDP_UMEM_PGOFF_COMPLETION_RING
XSK_UNALIGNED_BUF_OFFSET_SHIFT
XSK_UNALIGNED_BUF_ADDR_MASK
XDP_PKT_CONTD
adjtimex
aio_cancel
aio_error
Expand Down
23 changes: 23 additions & 0 deletions libc-test/semver/linux.txt
Expand Up @@ -3218,6 +3218,29 @@ W_EXITCODE
W_STOPCODE
XATTR_CREATE
XATTR_REPLACE
XDP_SHARED_UMEM
XDP_COPY
XDP_ZEROCOPY
XDP_USE_NEED_WAKEUP
XDP_USE_SG
XDP_UMEM_UNALIGNED_CHUNK_FLAG
XDP_RING_NEED_WAKEUP
XDP_MMAP_OFFSETS
XDP_RX_RING
XDP_TX_RING
XDP_UMEM_REG
XDP_UMEM_FILL_RING
XDP_UMEM_COMPLETION_RING
XDP_STATISTICS
XDP_OPTIONS
XDP_OPTIONS_ZEROCOPY
XDP_PGOFF_RX_RING
XDP_PGOFF_TX_RING
XDP_UMEM_PGOFF_FILL_RING
XDP_UMEM_PGOFF_COMPLETION_RING
XSK_UNALIGNED_BUF_OFFSET_SHIFT
XSK_UNALIGNED_BUF_ADDR_MASK
XDP_PKT_CONTD
XTABS
YESEXPR
YESSTR
Expand Down
109 changes: 109 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Expand Up @@ -355,6 +355,83 @@ s! {
#[cfg(libc_union)]
pub u: __c_anonymous_ptrace_syscall_info_data,
}

// linux/if_xdp.h

pub struct sockaddr_xdp {
pub sxdp_family: ::__u16,
pub sxdp_flags: ::__u16,
pub sxdp_ifindex: ::__u32,
pub sxdp_queue_id: ::__u32,
pub sxdp_shared_umem_fd: ::__u32,
}

pub struct xdp_ring_offset {
pub producer: ::__u64,
pub consumer: ::__u64,
pub desc: ::__u64,
pub flags: ::__u64,
}

pub struct xdp_mmap_offsets {
pub rx: xdp_ring_offset,
pub tx: xdp_ring_offset,
pub fr: xdp_ring_offset,
pub cr: xdp_ring_offset,
}

pub struct xdp_ring_offset_v1 {
pub producer: ::__u64,
pub consumer: ::__u64,
pub desc: ::__u64,
}

pub struct xdp_mmap_offsets_v1 {
pub rx: xdp_ring_offset_v1,
pub tx: xdp_ring_offset_v1,
pub fr: xdp_ring_offset_v1,
pub cr: xdp_ring_offset_v1,
}

pub struct xdp_umem_reg {
pub addr: ::__u64,
pub len: ::__u64,
pub chunk_size: ::__u32,
pub headroom: ::__u32,
pub flags: ::__u32,
}

pub struct xdp_umem_reg_v1 {
pub addr: ::__u64,
pub len: ::__u64,
pub chunk_size: ::__u32,
pub headroom: ::__u32,
}

pub struct xdp_statistics {
pub rx_dropped: ::__u64,
pub rx_invalid_descs: ::__u64,
pub tx_invalid_descs: ::__u64,
pub rx_ring_full: ::__u64,
pub rx_fill_ring_empty_descs: ::__u64,
pub tx_ring_empty_descs: ::__u64,
}

pub struct xdp_statistics_v1 {
pub rx_dropped: ::__u64,
pub rx_invalid_descs: ::__u64,
pub tx_invalid_descs: ::__u64,
}

pub struct xdp_options {
pub flags: ::__u32,
}

pub struct xdp_desc {
pub addr: ::__u64,
pub len: ::__u32,
pub options: ::__u32,
}
}

impl siginfo_t {
Expand Down Expand Up @@ -920,6 +997,38 @@ pub const GENL_UNS_ADMIN_PERM: ::c_int = 0x10;
pub const GENL_ID_VFS_DQUOT: ::c_int = ::NLMSG_MIN_TYPE + 1;
pub const GENL_ID_PMCRAID: ::c_int = ::NLMSG_MIN_TYPE + 2;

// linux/if_xdp.h
pub const XDP_SHARED_UMEM: ::__u16 = 1 << 0;
pub const XDP_COPY: ::__u16 = 1 << 1;
pub const XDP_ZEROCOPY: ::__u16 = 1 << 2;
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_RING_NEED_WAKEUP: ::__u32 = 1 << 0;

pub const XDP_MMAP_OFFSETS: ::c_int = 1;
pub const XDP_RX_RING: ::c_int = 2;
pub const XDP_TX_RING: ::c_int = 3;
pub const XDP_UMEM_REG: ::c_int = 4;
pub const XDP_UMEM_FILL_RING: ::c_int = 5;
pub const XDP_UMEM_COMPLETION_RING: ::c_int = 6;
pub const XDP_STATISTICS: ::c_int = 7;
pub const XDP_OPTIONS: ::c_int = 8;

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

pub const XDP_PGOFF_RX_RING: ::off_t = 0;
pub const XDP_PGOFF_TX_RING: ::off_t = 0x80000000;
pub const XDP_UMEM_PGOFF_FILL_RING: ::c_ulonglong = 0x100000000;
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_PKT_CONTD: ::__u32 = 1 << 0;

// elf.h
pub const NT_PRSTATUS: ::c_int = 1;
pub const NT_PRFPREG: ::c_int = 2;
Expand Down
111 changes: 111 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Expand Up @@ -271,6 +271,83 @@ s! {
pub maxerror: ::c_long,
pub esterror: ::c_long,
}

// linux/if_xdp.h

pub struct sockaddr_xdp {
pub sxdp_family: ::__u16,
pub sxdp_flags: ::__u16,
pub sxdp_ifindex: ::__u32,
pub sxdp_queue_id: ::__u32,
pub sxdp_shared_umem_fd: ::__u32,
}

pub struct xdp_ring_offset {
pub producer: ::__u64,
pub consumer: ::__u64,
pub desc: ::__u64,
pub flags: ::__u64,
}

pub struct xdp_mmap_offsets {
pub rx: xdp_ring_offset,
pub tx: xdp_ring_offset,
pub fr: xdp_ring_offset,
pub cr: xdp_ring_offset,
}

pub struct xdp_ring_offset_v1 {
pub producer: ::__u64,
pub consumer: ::__u64,
pub desc: ::__u64,
}

pub struct xdp_mmap_offsets_v1 {
pub rx: xdp_ring_offset_v1,
pub tx: xdp_ring_offset_v1,
pub fr: xdp_ring_offset_v1,
pub cr: xdp_ring_offset_v1,
}

pub struct xdp_umem_reg {
pub addr: ::__u64,
pub len: ::__u64,
pub chunk_size: ::__u32,
pub headroom: ::__u32,
pub flags: ::__u32,
}

pub struct xdp_umem_reg_v1 {
pub addr: ::__u64,
pub len: ::__u64,
pub chunk_size: ::__u32,
pub headroom: ::__u32,
}

pub struct xdp_statistics {
pub rx_dropped: ::__u64,
pub rx_invalid_descs: ::__u64,
pub tx_invalid_descs: ::__u64,
pub rx_ring_full: ::__u64,
pub rx_fill_ring_empty_descs: ::__u64,
pub tx_ring_empty_descs: ::__u64,
}

pub struct xdp_statistics_v1 {
pub rx_dropped: ::__u64,
pub rx_invalid_descs: ::__u64,
pub tx_invalid_descs: ::__u64,
}

pub struct xdp_options {
pub flags: ::__u32,
}

pub struct xdp_desc {
pub addr: ::__u64,
pub len: ::__u32,
pub options: ::__u32,
}
}

s_no_extra_traits! {
Expand Down Expand Up @@ -703,6 +780,40 @@ pub const TIME_ERROR: ::c_int = 5;
pub const TIME_BAD: ::c_int = TIME_ERROR;
pub const MAXTC: ::c_long = 6;

pub const SOL_XDP: ::c_int = 283;

// linux/if_xdp.h
pub const XDP_SHARED_UMEM: ::__u16 = 1 << 0;
pub const XDP_COPY: ::__u16 = 1 << 1;
pub const XDP_ZEROCOPY: ::__u16 = 1 << 2;
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_RING_NEED_WAKEUP: ::__u32 = 1 << 0;

pub const XDP_MMAP_OFFSETS: ::c_int = 1;
pub const XDP_RX_RING: ::c_int = 2;
pub const XDP_TX_RING: ::c_int = 3;
pub const XDP_UMEM_REG: ::c_int = 4;
pub const XDP_UMEM_FILL_RING: ::c_int = 5;
pub const XDP_UMEM_COMPLETION_RING: ::c_int = 6;
pub const XDP_STATISTICS: ::c_int = 7;
pub const XDP_OPTIONS: ::c_int = 8;

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

pub const XDP_PGOFF_RX_RING: ::off_t = 0;
pub const XDP_PGOFF_TX_RING: ::off_t = 0x80000000;
pub const XDP_UMEM_PGOFF_FILL_RING: ::c_ulonglong = 0x100000000;
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_PKT_CONTD: ::__u32 = 1 << 0;

cfg_if! {
if #[cfg(target_arch = "s390x")] {
pub const POSIX_FADV_DONTNEED: ::c_int = 6;
Expand Down

0 comments on commit c4b12eb

Please sign in to comment.