From 9813c39f193279f22ccef59d7b3c65ee20b1aaae Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Fri, 1 Dec 2023 11:07:26 +0100 Subject: [PATCH] tests: Add queue ID matching to AF_XDP test --- test/integration-ebpf/src/redirect.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/test/integration-ebpf/src/redirect.rs b/test/integration-ebpf/src/redirect.rs index 41812cd0..d13fa143 100644 --- a/test/integration-ebpf/src/redirect.rs +++ b/test/integration-ebpf/src/redirect.rs @@ -25,8 +25,17 @@ static CPUS: CpuMap = CpuMap::with_max_entries(1, 0); static mut HITS: Array = Array::with_max_entries(2, 0); #[xdp] -pub fn redirect_sock(_ctx: XdpContext) -> u32 { - SOCKS.redirect(0, 0).unwrap_or(xdp_action::XDP_ABORTED) +pub fn redirect_sock(ctx: XdpContext) -> u32 { + // Retrieve queue ID of incoming packet. + let queue_id = unsafe { *ctx.ctx }.rx_queue_index; + // Check whether incoming packet's queue ID matches the queue ID of the socket in XSKMAP at index `queue_id`. + if SOCKS.get(queue_id) == Some(queue_id) { + // Queue ID matches, redirect to AF_XDP socket. + SOCKS.redirect(0, 0).unwrap_or(xdp_action::XDP_ABORTED) + } else { + // Queue ID did not match, pass packet to kernel network stack. + xdp_action::XDP_PASS + } } #[xdp]