diff --git a/libc-test/build.rs b/libc-test/build.rs index d8f97d253a667..cb28758ad507f 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -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", @@ -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, } }); @@ -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, } }); diff --git a/libc-test/semver/linux-gnu.txt b/libc-test/semver/linux-gnu.txt index ad971de731bad..4d95520d3e9de 100644 --- a/libc-test/semver/linux-gnu.txt +++ b/libc-test/semver/linux-gnu.txt @@ -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 diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index 09c461350f9a5..09a63c7294a76 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -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 diff --git a/src/unix/linux_like/linux/gnu/mod.rs b/src/unix/linux_like/linux/gnu/mod.rs index 377b9f122f150..e7284fd46f096 100644 --- a/src/unix/linux_like/linux/gnu/mod.rs +++ b/src/unix/linux_like/linux/gnu/mod.rs @@ -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 { @@ -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; diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index b67d55e99bb53..97429a7f3a21a 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -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! { @@ -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;