1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
//! AF_XDP source backend (design stub).
//!
//! AF_XDP is a Linux socket family that enables high-performance packet
//! processing entirely in userspace. It works in conjunction with XDP/eBPF:
//! a small eBPF program running in the kernel redirects packets from the NIC
//! receive path directly into a userspace memory region called **UMEM**.
//!
//! ## How AF_XDP works
//!
//! ```text
//! NIC receives packet
//! ↓
//! XDP/eBPF program runs (in kernel, on the driver receive path)
//! ↓
//! program calls bpf_redirect_map() → AF_XDP socket
//! ↓
//! kernel DMA's packet into UMEM frame (zero-copy) or copies it (copy mode)
//! ↓
//! kernel writes descriptor to RX ring
//! ↓
//! FlyBy userspace reads RX ring → decodes packet → routes to sink
//! ```
//!
//! ## Rings
//!
//! AF_XDP uses four rings (FlyBy v0.1 uses only the first two):
//!
//! | Ring | Direction | Purpose |
//! |------|-----------|---------|
//! | RX ring | kernel → userspace | Received packet descriptors |
//! | Fill ring | userspace → kernel | Free UMEM frame addresses |
//! | TX ring | userspace → kernel | Transmit descriptors (deferred) |
//! | Completion ring | kernel → userspace | Transmitted frame confirmations (deferred) |
//!
//! ## UMEM vs FlyBy shared-memory sink
//!
//! These are **different memory domains**:
//!
//! - **UMEM**: shared between the kernel and the AF_XDP socket. Contains
//! raw packet frames. Managed by `mmap` + `setsockopt(XDP_UMEM_REG)`.
//! - **FlyBy shared-memory sink**: the typed message ring from Part III.
//! Contains decoded, structured messages. Managed by `flyby::memory`.
//!
//! A packet flows from UMEM → decode → FlyBy ring. The copy happens at
//! the decode boundary. True end-to-end zero-copy into the FlyBy sink is
//! a separate and harder problem; it must not be claimed without measurement.
//!
//! ## Copy mode vs zero-copy
//!
//! | Mode | NIC requirement | Kernel requirement | Status |
//! |------|----------------|-------------------|--------|
//! | Copy | any driver | ≥ 5.4 | v0.2 target |
//! | Zero-copy | AF_XDP-capable driver | ≥ 5.10 | v0.3 target |
//!
//! Always start with copy mode. Benchmark both before claiming any
//! latency advantage.
//!
//! ## Operational requirements
//!
//! - Linux host (macOS and Docker Desktop are **not** supported).
//! - Kernel ≥ 5.4 recommended (≥ 5.10 for production zero-copy).
//! - `CAP_SYS_ADMIN` or (`CAP_BPF` + `CAP_NET_ADMIN`) to load the XDP program.
//! - NIC driver with AF_XDP support (check with `ethtool --show-features`).
//! ## Status
//!
//! This is a **design stub**. The implementation requires a Linux host with
//! the capabilities listed above. The concrete binding — UMEM allocation,
//! ring mmap, XDP program load, and packet polling loop — is a subsequent
//! deliverable. All unsafe code will be isolated in clearly-marked modules
//! with a safety comment per block.
use crate;
use crateRawBatch;
use crateAfXdpConfig;
use crate;
/// AF_XDP source: receives packets from a Linux NIC queue via an XSK socket.
///
/// See the module documentation for the full design description and
/// operational requirements.
///
/// # Current status
///
/// Stub. Returns [`ErrorKind::NotImplemented`] until the binding is
/// implemented. Enable the `af_xdp` feature flag to compile this type.