Skip to content

Commit

Permalink
First pass implementation of XDP I/O loop (#1066)
Browse files Browse the repository at this point in the history
This PR is the real meat of the XDP implementation, the I/O loop.

The setup of the memory, sockets, and rings is done in the root xdp module, along with the spawning of one (named) thread per NIC queue, the actual packet processing code is in the xdp/process module. This split of code allows much easier testing, since we can just have a Umem (memory map) and don't need to do any actual I/O.

For the sake of simplicity in this initial pass I decided not to share any code at all with the current sessionpool, instead opting for a more minimal approach to pairing client <-> server sessions by having a single TTL map for all servers, where each unique client gets its own port in the range of valid ephemeral ports that Linux itself doesn't assign, which gives 4535 unique clients per server, so the TTL applies to the server instead of each individual client. Other than that difference, the only thing different about XDP versus the other implementations is that packets need to parsed manually when received to pull out the source information, and, unless being routed to multiple servers, the packet is then modified inline and queued for sending with the new source and destination information as determined by the filters.
  • Loading branch information
Jake-Shadle authored Jan 20, 2025
1 parent a4b302a commit 0dcfd9b
Show file tree
Hide file tree
Showing 15 changed files with 2,233 additions and 108 deletions.
94 changes: 62 additions & 32 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ features = ["client", "client-legacy"]

[target.'cfg(target_os = "linux")'.dependencies]
io-uring = { version = "0.7", default-features = false }
libc = "0.2"
libc.workspace = true
pprof = { version = "0.13.0", features = ["prost", "prost-codec"], package = "pprof2" }
quilkin-xdp = { version = "0.1.0", path = "crates/xdp" }
slab = "0.4"
sys-info = "0.9.1"
pprof = { version = "0.13.0", features = ["prost", "prost-codec"], package = "pprof2" }

[dev-dependencies]
divan = "0.1.15"
Expand Down Expand Up @@ -218,6 +219,7 @@ kube-core = { version = "0.97", default-features = false, features = [
"schema",
] }
k8s-openapi = { version = "0.23", features = ["v1_29", "schemars"] }
libc = "0.2"
once_cell = "1.20.2"
prometheus = { version = "0.13.4", default-features = false }
prost = "0.13"
Expand Down
3 changes: 3 additions & 0 deletions crates/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ publish = false
workspace = true

[dependencies]
# Packet creation/parsing to validate the packet processing for XDP
etherparse = "0.17"
insta = { version = "1.42", features = ["json"] }
once_cell.workspace = true
quilkin.workspace = true
rand.workspace = true
Expand Down
93 changes: 93 additions & 0 deletions crates/test/tests/snapshots/xdp__changes_ip_version-2.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
source: crates/test/tests/xdp.rs
expression: "&packet_headers"
---
PacketHeaders {
link: Some(
Ethernet2(
Ethernet2Header {
source: [
4,
4,
4,
4,
4,
4,
],
destination: [
3,
3,
3,
3,
3,
3,
],
ether_type: 0x0800 (Internet Protocol version 4 (IPv4)),
},
),
),
vlan: None,
net: Some(
Ipv4(
Ipv4Header {
dscp: Ipv4Dscp(
0,
),
ecn: Ipv4Ecn(
0,
),
total_len: 39,
identification: 0,
dont_fragment: false,
more_fragments: false,
fragment_offset: IpFragOffset(
0,
),
time_to_live: 63,
protocol: 17 (UDP - User Datagram),
header_checksum: 0,
source: [
2,
2,
2,
2,
],
destination: [
5,
5,
5,
5,
],
options: [],
},
Ipv4Extensions {
auth: None,
},
),
),
transport: Some(
Udp(
UdpHeader {
source_port: 7777,
destination_port: 8888,
length: 19,
checksum: 1511,
},
),
),
payload: Udp(
[
241,
241,
241,
241,
241,
241,
241,
241,
241,
241,
241,
],
),
}
Loading

0 comments on commit 0dcfd9b

Please sign in to comment.