Skip to content

Commit

Permalink
Add `if_xdp.h" structs and constants
Browse files Browse the repository at this point in the history
Also adds  _v1 versions for backwards compatibility
  • Loading branch information
arctic-alpaca committed Dec 9, 2023
1 parent 3195caf commit 9368878
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 0 deletions.
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
23 changes: 23 additions & 0 deletions libc-test/semver/linux-musl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,29 @@ PF_XDP
PIDFD_NONBLOCK
PR_SET_VMA
PR_SET_VMA_ANON_NAME
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
109 changes: 109 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,38 @@ pub const TIME_ERROR: ::c_int = 5;
pub const TIME_BAD: ::c_int = TIME_ERROR;
pub const MAXTC: ::c_long = 6;

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

Please sign in to comment.