Skip to content

Commit

Permalink
Update xdp to 0.1.0 (#1073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle authored Jan 22, 2025
1 parent b346e89 commit 588a4ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 58 deletions.
5 changes: 3 additions & 2 deletions Cargo.lock

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

34 changes: 10 additions & 24 deletions crates/test/tests/xdp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ async fn packet_manipulation() {
let mut server_packet = unsafe { umem.alloc().unwrap() };
etherparse::PacketBuilder::ethernet2([3, 3, 3, 3, 3, 3], [4, 4, 4, 4, 4, 4])
.ipv4(SERVER.ip().octets(), PROXY.ip().octets(), 64)
.udp(SERVER.port(), udp.source.port.host())
.udp(SERVER.port(), udp.src_port.host())
.write(&mut server_packet, &pdata)
.unwrap();

Expand Down Expand Up @@ -593,14 +593,10 @@ async fn many_sessions() {
let udp = nt::UdpPacket::parse_packet(packet).unwrap().unwrap();

let new = nt::UdpPacket {
source: nt::FullAddress {
mac: udp.destination.mac,
port: udp.destination.port,
},
destination: nt::FullAddress {
mac: udp.source.mac,
port: udp.source.port,
},
src_mac: udp.dst_mac,
src_port: udp.dst_port,
dst_mac: udp.src_mac,
dst_port: udp.src_port,
ips: match udp.ips {
nt::IpAddresses::V4 {
source,
Expand All @@ -618,7 +614,7 @@ async fn many_sessions() {
};

new.set_packet_headers(packet).unwrap();
xdp::packet::csum::recalc_udp(packet).unwrap();
packet.calc_udp_checksum().unwrap();
}

let mut rx_slab = xdp::HeapSlab::with_capacity(1);
Expand Down Expand Up @@ -652,20 +648,10 @@ async fn many_sessions() {
&client_packet[udp.data_offset..udp.data_offset + udp.data_length],
&data
);
assert_eq!(
udp.destination,
nt::FullAddress {
mac: nt::MacAddress([3, 3, 3, 3, 3, 3]),
port: (i as u16).into(),
}
);
assert_eq!(
udp.source,
nt::FullAddress {
mac: nt::MacAddress([4, 4, 4, 4, 4, 4]),
port: PROXY.port().into(),
}
);
assert_eq!(udp.dst_mac, nt::MacAddress([3, 3, 3, 3, 3, 3]));
assert_eq!(udp.dst_port, (i as u16).into());
assert_eq!(udp.src_mac, nt::MacAddress([4, 4, 4, 4, 4, 4]));
assert_eq!(udp.src_port.host(), PROXY.port());
assert_eq!(
udp.ips,
nt::IpAddresses::V4 {
Expand Down
4 changes: 2 additions & 2 deletions crates/xdp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ aya-log = "0.2.1"
libc.workspace = true
thiserror.workspace = true
tracing.workspace = true
xdp = { git = "https://github.com/Jake-Shadle/xdp", branch = "impl" }
#xdp = { path = "../../../xdp" }
xdp = "0.1.0"
#xdp = { git = "https://github.com/Jake-Shadle/xdp", branch = "main" }

[lints]
workspace = true
48 changes: 18 additions & 30 deletions src/net/xdp/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub use quilkin_xdp::xdp;
use quilkin_xdp::xdp::{
packet::{
csum,
net_types::{FullAddress, IpAddresses, NetworkU16, UdpPacket},
net_types::{IpAddresses, NetworkU16, UdpPacket},
Packet, PacketError,
},
HeapSlab, Umem,
Expand Down Expand Up @@ -371,7 +371,7 @@ pub fn process_packets(
unreachable!("we somehow got a non-UDP packet, this should be impossible with the eBPF program we use to route packets");
};

let is_client = udp.destination.port == state.external_port;
let is_client = udp.dst_port == state.external_port;
let direction = if is_client {
metrics::READ
} else {
Expand Down Expand Up @@ -427,7 +427,7 @@ fn process_client_packet(
state: &mut State,
tx_slab: &mut HeapSlab,
) -> Result<(), PipelineError> {
let source_addr = SocketAddr::from((packet.udp.ips.source(), packet.udp.source.port.host()));
let source_addr = SocketAddr::from((packet.udp.ips.source(), packet.udp.src_port.host()));
let mut ctx =
filters::ReadContext::new(cm, source_addr.into(), packet, &mut state.destinations);

Expand Down Expand Up @@ -462,14 +462,10 @@ fn process_client_packet(
let src_port = state.session(source_addr, dest_addr);

let mut headers = UdpPacket {
source: FullAddress {
mac: packet.udp.destination.mac,
port: src_port,
},
destination: FullAddress {
mac: packet.udp.source.mac,
port: dest_addr.port().into(),
},
src_mac: packet.udp.dst_mac,
src_port,
dst_mac: packet.udp.src_mac,
dst_port: dest_addr.port().into(),
ips: state.ips(dest_addr.ip()),
data_offset: packet.udp.data_offset,
data_length: packet.udp.data_length,
Expand Down Expand Up @@ -499,14 +495,10 @@ fn process_client_packet(
let src_port = state.session(source_addr, dest_addr);

let mut headers = UdpPacket {
source: FullAddress {
mac: packet.udp.destination.mac,
port: src_port,
},
destination: FullAddress {
mac: packet.udp.source.mac,
port: dest_addr.port().into(),
},
src_mac: packet.udp.dst_mac,
src_port,
dst_mac: packet.udp.src_mac,
dst_port: dest_addr.port().into(),
ips: state.ips(dest_addr.ip()),
data_offset: packet.udp.data_offset,
data_length: packet.udp.data_length,
Expand All @@ -532,9 +524,9 @@ fn process_server_packet(
state: &mut State,
tx_slab: &mut HeapSlab,
) -> Result<(), PipelineError> {
let server_addr = SocketAddr::new(packet.udp.ips.source(), packet.udp.source.port.host());
let server_addr = SocketAddr::new(packet.udp.ips.source(), packet.udp.src_port.host());

let Some(client_addr) = state.lookup_client(server_addr, packet.udp.destination.port) else {
let Some(client_addr) = state.lookup_client(server_addr, packet.udp.dst_port) else {
tracing::debug!(address = %server_addr, "received traffic from a server that has no downstream");
return Ok(());
};
Expand All @@ -548,14 +540,10 @@ fn process_server_packet(
} = ctx;

let headers = UdpPacket {
source: FullAddress {
mac: packet.udp.destination.mac,
port: state.external_port,
},
destination: FullAddress {
mac: packet.udp.source.mac,
port: client_addr.port().into(),
},
src_mac: packet.udp.dst_mac,
src_port: state.external_port,
dst_mac: packet.udp.src_mac,
dst_port: client_addr.port().into(),
ips: state.ips(client_addr.ip()),
data_offset: packet.udp.data_offset,
data_length: packet.udp.data_length,
Expand All @@ -566,7 +554,7 @@ fn process_server_packet(
push_packet(
metrics::Direction::Write,
modify_packet_headers(&packet.udp, &headers, &mut packet.inner).map(|_| {
let _ = csum::recalc_udp(&mut packet.inner);
let _ = packet.inner.calc_udp_checksum();
packet.inner
}),
tx_slab,
Expand Down

0 comments on commit 588a4ca

Please sign in to comment.