tests: add queue ID matching to AF_XDP test

pull/1187/merge
arctic-alpaca 1 year ago committed by Tamir Duberstein
parent 4d2a56ed46
commit e1cb4237bd

@ -21,12 +21,6 @@ impl XdpContext {
unsafe { (*self.ctx).data_end as usize }
}
/// Return the interface of the index as determined by the OS.
#[inline]
pub fn ingress_ifindex(&self) -> usize {
unsafe { (*self.ctx).ingress_ifindex as usize }
}
/// Return the raw address of the XdpContext metadata.
#[inline(always)]
pub fn metadata(&self) -> usize {
@ -38,6 +32,18 @@ impl XdpContext {
pub fn metadata_end(&self) -> usize {
self.data()
}
/// Return the index of the ingress interface.
#[inline]
pub fn ingress_ifindex(&self) -> usize {
unsafe { (*self.ctx).ingress_ifindex as usize }
}
/// Return the index of the receive queue.
#[inline]
pub fn rx_queue_index(&self) -> u32 {
unsafe { (*self.ctx).rx_queue_index }
}
}
impl EbpfContext for XdpContext {

@ -25,8 +25,15 @@ static CPUS: CpuMap = CpuMap::with_max_entries(1, 0);
static 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 {
let queue_id = ctx.rx_queue_index();
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]

@ -2024,6 +2024,7 @@ pub fn aya_ebpf::programs::xdp::XdpContext::ingress_ifindex(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata_end(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::new(ctx: *mut aya_ebpf_bindings::x86_64::bindings::xdp_md) -> aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::rx_queue_index(&self) -> u32
impl aya_ebpf::EbpfContext for aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::as_ptr(&self) -> *mut core::ffi::c_void
impl core::marker::Freeze for aya_ebpf::programs::xdp::XdpContext
@ -2638,6 +2639,7 @@ pub fn aya_ebpf::programs::xdp::XdpContext::ingress_ifindex(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::metadata_end(&self) -> usize
pub fn aya_ebpf::programs::xdp::XdpContext::new(ctx: *mut aya_ebpf_bindings::x86_64::bindings::xdp_md) -> aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::rx_queue_index(&self) -> u32
impl aya_ebpf::EbpfContext for aya_ebpf::programs::xdp::XdpContext
pub fn aya_ebpf::programs::xdp::XdpContext::as_ptr(&self) -> *mut core::ffi::c_void
impl core::marker::Freeze for aya_ebpf::programs::xdp::XdpContext

Loading…
Cancel
Save