Skip to content

Commit

Permalink
tests: Add queue ID matching to AF_XDP test
Browse files Browse the repository at this point in the history
  • Loading branch information
arctic-alpaca committed Dec 1, 2023
1 parent ef92841 commit c8ebd90
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions test/integration-ebpf/src/redirect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,17 @@ static CPUS: CpuMap = CpuMap::with_max_entries(1, 0);
static mut HITS: Array<u32> = 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 queue ID of socket in XSKMAP.
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]
Expand Down

0 comments on commit c8ebd90

Please sign in to comment.