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 missing AF_* definitions and AF_XDP header and structs to v0.4.11 #98

Merged
merged 2 commits into from
Nov 30, 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ net = []
netlink = []
prctl = []
system = []
xdp = []
default = ["std", "general", "errno"]
std = []
no_std = []
Expand Down
11 changes: 10 additions & 1 deletion gen/modules/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,16 @@ typedef __UINT32_TYPE__ socklen_t;
#define AF_ISDN 34
#define AF_PHONET 35
#define AF_IEEE802154 36
#define AF_MAX 37
#define AF_CAIF 37
#define AF_ALG 38
#define AF_NFC 39
#define AF_VSOCK 40
#define AF_KCM 41
#define AF_QIPCRTR 42
#define AF_SMC 43
#define AF_XDP 44
#define AF_MCTP 45
#define AF_MAX 46

#define MSG_OOB 0x1
#define MSG_PEEK 0x2
Expand Down
54 changes: 54 additions & 0 deletions gen/modules/xdp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file includes selected Linux header files, and supplementary
// definitions, needed for AF_XDP code.

#include "support.h"

// Selected Linux headers.

#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
#include <linux/if_xdp.h>

// v1 versions of xdp structs. They are defined in linux/net/xdp/xsk.c and
// don't appear in header files, so they are defined here for backwards compatibility.

// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.h#L14-L18
struct xdp_ring_offset_v1 {
__u64 producer;
__u64 consumer;
__u64 desc;
};

// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.h#L20-L25
struct xdp_mmap_offsets_v1 {
struct xdp_ring_offset_v1 rx;
struct xdp_ring_offset_v1 tx;
struct xdp_ring_offset_v1 fr;
struct xdp_ring_offset_v1 cr;
};

// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.c#L1251-L1256
struct xdp_umem_reg_v1 {
__u64 addr;
__u64 len;
__u32 chunk_size;
__u32 headroom;
};

// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.c#L1367-L1371
struct xdp_statistics_v1 {
__u64 rx_dropped;
__u64 rx_invalid_descs;
__u64 tx_invalid_descs;
};

// The following two definitions were added in kernel version 6.6 and can be removed
// when the crate is updated to kernel version 6.6.

// https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_xdp.h#L33
#define XDP_USE_SG (1 << 4)

// https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_xdp.h#L122
#define XDP_PKT_CONTD (1 << 0)

#endif

11 changes: 10 additions & 1 deletion src/aarch64/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,16 @@ pub const AF_RXRPC: u32 = 33;
pub const AF_ISDN: u32 = 34;
pub const AF_PHONET: u32 = 35;
pub const AF_IEEE802154: u32 = 36;
pub const AF_MAX: u32 = 37;
pub const AF_CAIF: u32 = 37;
pub const AF_ALG: u32 = 38;
pub const AF_NFC: u32 = 39;
pub const AF_VSOCK: u32 = 40;
pub const AF_KCM: u32 = 41;
pub const AF_QIPCRTR: u32 = 42;
pub const AF_SMC: u32 = 43;
pub const AF_XDP: u32 = 44;
pub const AF_MCTP: u32 = 45;
pub const AF_MAX: u32 = 46;
pub const MSG_OOB: u32 = 1;
pub const MSG_PEEK: u32 = 2;
pub const MSG_DONTROUTE: u32 = 4;
Expand Down
159 changes: 159 additions & 0 deletions src/aarch64/xdp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
/* automatically generated by rust-bindgen 0.66.1 */

pub type __s8 = crate::ctypes::c_schar;
pub type __u8 = crate::ctypes::c_uchar;
pub type __s16 = crate::ctypes::c_short;
pub type __u16 = crate::ctypes::c_ushort;
pub type __s32 = crate::ctypes::c_int;
pub type __u32 = crate::ctypes::c_uint;
pub type __s64 = crate::ctypes::c_longlong;
pub type __u64 = crate::ctypes::c_ulonglong;
pub type __kernel_key_t = crate::ctypes::c_int;
pub type __kernel_mqd_t = crate::ctypes::c_int;
pub type __kernel_old_uid_t = crate::ctypes::c_ushort;
pub type __kernel_old_gid_t = crate::ctypes::c_ushort;
pub type __kernel_long_t = crate::ctypes::c_long;
pub type __kernel_ulong_t = crate::ctypes::c_ulong;
pub type __kernel_ino_t = __kernel_ulong_t;
pub type __kernel_mode_t = crate::ctypes::c_uint;
pub type __kernel_pid_t = crate::ctypes::c_int;
pub type __kernel_ipc_pid_t = crate::ctypes::c_int;
pub type __kernel_uid_t = crate::ctypes::c_uint;
pub type __kernel_gid_t = crate::ctypes::c_uint;
pub type __kernel_suseconds_t = __kernel_long_t;
pub type __kernel_daddr_t = crate::ctypes::c_int;
pub type __kernel_uid32_t = crate::ctypes::c_uint;
pub type __kernel_gid32_t = crate::ctypes::c_uint;
pub type __kernel_old_dev_t = crate::ctypes::c_uint;
pub type __kernel_size_t = __kernel_ulong_t;
pub type __kernel_ssize_t = __kernel_long_t;
pub type __kernel_ptrdiff_t = __kernel_long_t;
pub type __kernel_off_t = __kernel_long_t;
pub type __kernel_loff_t = crate::ctypes::c_longlong;
pub type __kernel_old_time_t = __kernel_long_t;
pub type __kernel_time_t = __kernel_long_t;
pub type __kernel_time64_t = crate::ctypes::c_longlong;
pub type __kernel_clock_t = __kernel_long_t;
pub type __kernel_timer_t = crate::ctypes::c_int;
pub type __kernel_clockid_t = crate::ctypes::c_int;
pub type __kernel_caddr_t = *mut crate::ctypes::c_char;
pub type __kernel_uid16_t = crate::ctypes::c_ushort;
pub type __kernel_gid16_t = crate::ctypes::c_ushort;
pub type __le16 = __u16;
pub type __be16 = __u16;
pub type __le32 = __u32;
pub type __be32 = __u32;
pub type __le64 = __u64;
pub type __be64 = __u64;
pub type __sum16 = __u16;
pub type __wsum = __u32;
pub type __poll_t = crate::ctypes::c_uint;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
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,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_ring_offset {
pub producer: __u64,
pub consumer: __u64,
pub desc: __u64,
pub flags: __u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
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,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_umem_reg {
pub addr: __u64,
pub len: __u64,
pub chunk_size: __u32,
pub headroom: __u32,
pub flags: __u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
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,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_options {
pub flags: __u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_desc {
pub addr: __u64,
pub len: __u32,
pub options: __u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_ring_offset_v1 {
pub producer: __u64,
pub consumer: __u64,
pub desc: __u64,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
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,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_umem_reg_v1 {
pub addr: __u64,
pub len: __u64,
pub chunk_size: __u32,
pub headroom: __u32,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct xdp_statistics_v1 {
pub rx_dropped: __u64,
pub rx_invalid_descs: __u64,
pub tx_invalid_descs: __u64,
}
pub const XDP_SHARED_UMEM: u32 = 1;
pub const XDP_COPY: u32 = 2;
pub const XDP_ZEROCOPY: u32 = 4;
pub const XDP_USE_NEED_WAKEUP: u32 = 8;
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: u32 = 1;
pub const XDP_RING_NEED_WAKEUP: u32 = 1;
pub const XDP_MMAP_OFFSETS: u32 = 1;
pub const XDP_RX_RING: u32 = 2;
pub const XDP_TX_RING: u32 = 3;
pub const XDP_UMEM_REG: u32 = 4;
pub const XDP_UMEM_FILL_RING: u32 = 5;
pub const XDP_UMEM_COMPLETION_RING: u32 = 6;
pub const XDP_STATISTICS: u32 = 7;
pub const XDP_OPTIONS: u32 = 8;
pub const XDP_OPTIONS_ZEROCOPY: u32 = 1;
pub const XDP_PGOFF_RX_RING: u32 = 0;
pub const XDP_PGOFF_TX_RING: u32 = 2147483648;
pub const XDP_UMEM_PGOFF_FILL_RING: u64 = 4294967296;
pub const XDP_UMEM_PGOFF_COMPLETION_RING: u64 = 6442450944;
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: u32 = 48;
pub const XSK_UNALIGNED_BUF_ADDR_MASK: u64 = 281474976710655;
pub const XDP_USE_SG: u32 = 16;
pub const XDP_PKT_CONTD: u32 = 1;
11 changes: 10 additions & 1 deletion src/arm/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1359,7 +1359,16 @@ pub const AF_RXRPC: u32 = 33;
pub const AF_ISDN: u32 = 34;
pub const AF_PHONET: u32 = 35;
pub const AF_IEEE802154: u32 = 36;
pub const AF_MAX: u32 = 37;
pub const AF_CAIF: u32 = 37;
pub const AF_ALG: u32 = 38;
pub const AF_NFC: u32 = 39;
pub const AF_VSOCK: u32 = 40;
pub const AF_KCM: u32 = 41;
pub const AF_QIPCRTR: u32 = 42;
pub const AF_SMC: u32 = 43;
pub const AF_XDP: u32 = 44;
pub const AF_MCTP: u32 = 45;
pub const AF_MAX: u32 = 46;
pub const MSG_OOB: u32 = 1;
pub const MSG_PEEK: u32 = 2;
pub const MSG_DONTROUTE: u32 = 4;
Expand Down
Loading