Skip to content

Commit eb456fc

Browse files
arctic-alpacasunfishcode
authored andcommitted
Add missing AF_* definitions and AF_XDP header and structs to v0.4.11 (#98)
* Add missing `AF_*` definitions * Add AF_XDP header and structs
1 parent 571cb37 commit eb456fc

40 files changed

Lines changed: 3257 additions & 19 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ net = []
3636
netlink = []
3737
prctl = []
3838
system = []
39+
xdp = []
3940
default = ["std", "general", "errno"]
4041
std = []
4142
no_std = []

gen/modules/net.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,16 @@ typedef __UINT32_TYPE__ socklen_t;
9292
#define AF_ISDN 34
9393
#define AF_PHONET 35
9494
#define AF_IEEE802154 36
95-
#define AF_MAX 37
95+
#define AF_CAIF 37
96+
#define AF_ALG 38
97+
#define AF_NFC 39
98+
#define AF_VSOCK 40
99+
#define AF_KCM 41
100+
#define AF_QIPCRTR 42
101+
#define AF_SMC 43
102+
#define AF_XDP 44
103+
#define AF_MCTP 45
104+
#define AF_MAX 46
96105

97106
#define MSG_OOB 0x1
98107
#define MSG_PEEK 0x2

gen/modules/xdp.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file includes selected Linux header files, and supplementary
2+
// definitions, needed for AF_XDP code.
3+
4+
#include "support.h"
5+
6+
// Selected Linux headers.
7+
8+
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,18,0)
9+
#include <linux/if_xdp.h>
10+
11+
// v1 versions of xdp structs. They are defined in linux/net/xdp/xsk.c and
12+
// don't appear in header files, so they are defined here for backwards compatibility.
13+
14+
// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.h#L14-L18
15+
struct xdp_ring_offset_v1 {
16+
__u64 producer;
17+
__u64 consumer;
18+
__u64 desc;
19+
};
20+
21+
// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.h#L20-L25
22+
struct xdp_mmap_offsets_v1 {
23+
struct xdp_ring_offset_v1 rx;
24+
struct xdp_ring_offset_v1 tx;
25+
struct xdp_ring_offset_v1 fr;
26+
struct xdp_ring_offset_v1 cr;
27+
};
28+
29+
// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.c#L1251-L1256
30+
struct xdp_umem_reg_v1 {
31+
__u64 addr;
32+
__u64 len;
33+
__u32 chunk_size;
34+
__u32 headroom;
35+
};
36+
37+
// https://github.com/torvalds/linux/blob/v6.6/net/xdp/xsk.c#L1367-L1371
38+
struct xdp_statistics_v1 {
39+
__u64 rx_dropped;
40+
__u64 rx_invalid_descs;
41+
__u64 tx_invalid_descs;
42+
};
43+
44+
// The following two definitions were added in kernel version 6.6 and can be removed
45+
// when the crate is updated to kernel version 6.6.
46+
47+
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_xdp.h#L33
48+
#define XDP_USE_SG (1 << 4)
49+
50+
// https://github.com/torvalds/linux/blob/master/include/uapi/linux/if_xdp.h#L122
51+
#define XDP_PKT_CONTD (1 << 0)
52+
53+
#endif
54+

src/aarch64/net.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,16 @@ pub const AF_RXRPC: u32 = 33;
13721372
pub const AF_ISDN: u32 = 34;
13731373
pub const AF_PHONET: u32 = 35;
13741374
pub const AF_IEEE802154: u32 = 36;
1375-
pub const AF_MAX: u32 = 37;
1375+
pub const AF_CAIF: u32 = 37;
1376+
pub const AF_ALG: u32 = 38;
1377+
pub const AF_NFC: u32 = 39;
1378+
pub const AF_VSOCK: u32 = 40;
1379+
pub const AF_KCM: u32 = 41;
1380+
pub const AF_QIPCRTR: u32 = 42;
1381+
pub const AF_SMC: u32 = 43;
1382+
pub const AF_XDP: u32 = 44;
1383+
pub const AF_MCTP: u32 = 45;
1384+
pub const AF_MAX: u32 = 46;
13761385
pub const MSG_OOB: u32 = 1;
13771386
pub const MSG_PEEK: u32 = 2;
13781387
pub const MSG_DONTROUTE: u32 = 4;

src/aarch64/xdp.rs

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/* automatically generated by rust-bindgen 0.66.1 */
2+
3+
pub type __s8 = crate::ctypes::c_schar;
4+
pub type __u8 = crate::ctypes::c_uchar;
5+
pub type __s16 = crate::ctypes::c_short;
6+
pub type __u16 = crate::ctypes::c_ushort;
7+
pub type __s32 = crate::ctypes::c_int;
8+
pub type __u32 = crate::ctypes::c_uint;
9+
pub type __s64 = crate::ctypes::c_longlong;
10+
pub type __u64 = crate::ctypes::c_ulonglong;
11+
pub type __kernel_key_t = crate::ctypes::c_int;
12+
pub type __kernel_mqd_t = crate::ctypes::c_int;
13+
pub type __kernel_old_uid_t = crate::ctypes::c_ushort;
14+
pub type __kernel_old_gid_t = crate::ctypes::c_ushort;
15+
pub type __kernel_long_t = crate::ctypes::c_long;
16+
pub type __kernel_ulong_t = crate::ctypes::c_ulong;
17+
pub type __kernel_ino_t = __kernel_ulong_t;
18+
pub type __kernel_mode_t = crate::ctypes::c_uint;
19+
pub type __kernel_pid_t = crate::ctypes::c_int;
20+
pub type __kernel_ipc_pid_t = crate::ctypes::c_int;
21+
pub type __kernel_uid_t = crate::ctypes::c_uint;
22+
pub type __kernel_gid_t = crate::ctypes::c_uint;
23+
pub type __kernel_suseconds_t = __kernel_long_t;
24+
pub type __kernel_daddr_t = crate::ctypes::c_int;
25+
pub type __kernel_uid32_t = crate::ctypes::c_uint;
26+
pub type __kernel_gid32_t = crate::ctypes::c_uint;
27+
pub type __kernel_old_dev_t = crate::ctypes::c_uint;
28+
pub type __kernel_size_t = __kernel_ulong_t;
29+
pub type __kernel_ssize_t = __kernel_long_t;
30+
pub type __kernel_ptrdiff_t = __kernel_long_t;
31+
pub type __kernel_off_t = __kernel_long_t;
32+
pub type __kernel_loff_t = crate::ctypes::c_longlong;
33+
pub type __kernel_old_time_t = __kernel_long_t;
34+
pub type __kernel_time_t = __kernel_long_t;
35+
pub type __kernel_time64_t = crate::ctypes::c_longlong;
36+
pub type __kernel_clock_t = __kernel_long_t;
37+
pub type __kernel_timer_t = crate::ctypes::c_int;
38+
pub type __kernel_clockid_t = crate::ctypes::c_int;
39+
pub type __kernel_caddr_t = *mut crate::ctypes::c_char;
40+
pub type __kernel_uid16_t = crate::ctypes::c_ushort;
41+
pub type __kernel_gid16_t = crate::ctypes::c_ushort;
42+
pub type __le16 = __u16;
43+
pub type __be16 = __u16;
44+
pub type __le32 = __u32;
45+
pub type __be32 = __u32;
46+
pub type __le64 = __u64;
47+
pub type __be64 = __u64;
48+
pub type __sum16 = __u16;
49+
pub type __wsum = __u32;
50+
pub type __poll_t = crate::ctypes::c_uint;
51+
#[repr(C)]
52+
#[derive(Debug, Copy, Clone)]
53+
pub struct sockaddr_xdp {
54+
pub sxdp_family: __u16,
55+
pub sxdp_flags: __u16,
56+
pub sxdp_ifindex: __u32,
57+
pub sxdp_queue_id: __u32,
58+
pub sxdp_shared_umem_fd: __u32,
59+
}
60+
#[repr(C)]
61+
#[derive(Debug, Copy, Clone)]
62+
pub struct xdp_ring_offset {
63+
pub producer: __u64,
64+
pub consumer: __u64,
65+
pub desc: __u64,
66+
pub flags: __u64,
67+
}
68+
#[repr(C)]
69+
#[derive(Debug, Copy, Clone)]
70+
pub struct xdp_mmap_offsets {
71+
pub rx: xdp_ring_offset,
72+
pub tx: xdp_ring_offset,
73+
pub fr: xdp_ring_offset,
74+
pub cr: xdp_ring_offset,
75+
}
76+
#[repr(C)]
77+
#[derive(Debug, Copy, Clone)]
78+
pub struct xdp_umem_reg {
79+
pub addr: __u64,
80+
pub len: __u64,
81+
pub chunk_size: __u32,
82+
pub headroom: __u32,
83+
pub flags: __u32,
84+
}
85+
#[repr(C)]
86+
#[derive(Debug, Copy, Clone)]
87+
pub struct xdp_statistics {
88+
pub rx_dropped: __u64,
89+
pub rx_invalid_descs: __u64,
90+
pub tx_invalid_descs: __u64,
91+
pub rx_ring_full: __u64,
92+
pub rx_fill_ring_empty_descs: __u64,
93+
pub tx_ring_empty_descs: __u64,
94+
}
95+
#[repr(C)]
96+
#[derive(Debug, Copy, Clone)]
97+
pub struct xdp_options {
98+
pub flags: __u32,
99+
}
100+
#[repr(C)]
101+
#[derive(Debug, Copy, Clone)]
102+
pub struct xdp_desc {
103+
pub addr: __u64,
104+
pub len: __u32,
105+
pub options: __u32,
106+
}
107+
#[repr(C)]
108+
#[derive(Debug, Copy, Clone)]
109+
pub struct xdp_ring_offset_v1 {
110+
pub producer: __u64,
111+
pub consumer: __u64,
112+
pub desc: __u64,
113+
}
114+
#[repr(C)]
115+
#[derive(Debug, Copy, Clone)]
116+
pub struct xdp_mmap_offsets_v1 {
117+
pub rx: xdp_ring_offset_v1,
118+
pub tx: xdp_ring_offset_v1,
119+
pub fr: xdp_ring_offset_v1,
120+
pub cr: xdp_ring_offset_v1,
121+
}
122+
#[repr(C)]
123+
#[derive(Debug, Copy, Clone)]
124+
pub struct xdp_umem_reg_v1 {
125+
pub addr: __u64,
126+
pub len: __u64,
127+
pub chunk_size: __u32,
128+
pub headroom: __u32,
129+
}
130+
#[repr(C)]
131+
#[derive(Debug, Copy, Clone)]
132+
pub struct xdp_statistics_v1 {
133+
pub rx_dropped: __u64,
134+
pub rx_invalid_descs: __u64,
135+
pub tx_invalid_descs: __u64,
136+
}
137+
pub const XDP_SHARED_UMEM: u32 = 1;
138+
pub const XDP_COPY: u32 = 2;
139+
pub const XDP_ZEROCOPY: u32 = 4;
140+
pub const XDP_USE_NEED_WAKEUP: u32 = 8;
141+
pub const XDP_UMEM_UNALIGNED_CHUNK_FLAG: u32 = 1;
142+
pub const XDP_RING_NEED_WAKEUP: u32 = 1;
143+
pub const XDP_MMAP_OFFSETS: u32 = 1;
144+
pub const XDP_RX_RING: u32 = 2;
145+
pub const XDP_TX_RING: u32 = 3;
146+
pub const XDP_UMEM_REG: u32 = 4;
147+
pub const XDP_UMEM_FILL_RING: u32 = 5;
148+
pub const XDP_UMEM_COMPLETION_RING: u32 = 6;
149+
pub const XDP_STATISTICS: u32 = 7;
150+
pub const XDP_OPTIONS: u32 = 8;
151+
pub const XDP_OPTIONS_ZEROCOPY: u32 = 1;
152+
pub const XDP_PGOFF_RX_RING: u32 = 0;
153+
pub const XDP_PGOFF_TX_RING: u32 = 2147483648;
154+
pub const XDP_UMEM_PGOFF_FILL_RING: u64 = 4294967296;
155+
pub const XDP_UMEM_PGOFF_COMPLETION_RING: u64 = 6442450944;
156+
pub const XSK_UNALIGNED_BUF_OFFSET_SHIFT: u32 = 48;
157+
pub const XSK_UNALIGNED_BUF_ADDR_MASK: u64 = 281474976710655;
158+
pub const XDP_USE_SG: u32 = 16;
159+
pub const XDP_PKT_CONTD: u32 = 1;

src/arm/net.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1362,7 +1362,16 @@ pub const AF_RXRPC: u32 = 33;
13621362
pub const AF_ISDN: u32 = 34;
13631363
pub const AF_PHONET: u32 = 35;
13641364
pub const AF_IEEE802154: u32 = 36;
1365-
pub const AF_MAX: u32 = 37;
1365+
pub const AF_CAIF: u32 = 37;
1366+
pub const AF_ALG: u32 = 38;
1367+
pub const AF_NFC: u32 = 39;
1368+
pub const AF_VSOCK: u32 = 40;
1369+
pub const AF_KCM: u32 = 41;
1370+
pub const AF_QIPCRTR: u32 = 42;
1371+
pub const AF_SMC: u32 = 43;
1372+
pub const AF_XDP: u32 = 44;
1373+
pub const AF_MCTP: u32 = 45;
1374+
pub const AF_MAX: u32 = 46;
13661375
pub const MSG_OOB: u32 = 1;
13671376
pub const MSG_PEEK: u32 = 2;
13681377
pub const MSG_DONTROUTE: u32 = 4;

0 commit comments

Comments
 (0)