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

Add if_xdp.h structs and constants and add SOL_XDP to musl #3453

Merged
merged 2 commits into from
Dec 10, 2023
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
53 changes: 53 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3408,6 +3408,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 @@ -3642,6 +3643,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 @@ -3994,6 +4019,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
23 changes: 23 additions & 0 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,29 @@ UDF_SUPER_MAGIC
UNAME26
USBDEVICE_SUPER_MAGIC
USER_PROCESS
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
XENFS_SUPER_MAGIC
XFS_SUPER_MAGIC
_SC_2_C_VERSION
Expand Down
24 changes: 24 additions & 0 deletions libc-test/semver/linux-musl.txt
Original file line number Diff line number Diff line change
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
109 changes: 109 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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