From 19af2497d79fdaa7dfe747e04934c0b0f5187b12 Mon Sep 17 00:00:00 2001 From: Dave Tucker Date: Tue, 19 Dec 2023 14:53:12 +0000 Subject: [PATCH] aya-bpf: Fix XDP Map documentation Signed-off-by: Dave Tucker --- bpf/aya-bpf/src/maps/xdp/cpu_map.rs | 4 ++-- bpf/aya-bpf/src/maps/xdp/dev_map.rs | 6 +++--- bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs | 6 +++--- bpf/aya-bpf/src/maps/xdp/xsk_map.rs | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/bpf/aya-bpf/src/maps/xdp/cpu_map.rs b/bpf/aya-bpf/src/maps/xdp/cpu_map.rs index 0ada7010..6a86351a 100644 --- a/bpf/aya-bpf/src/maps/xdp/cpu_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/cpu_map.rs @@ -25,9 +25,9 @@ use crate::{ /// static MAP: CpuMap = CpuMap::with_max_entries(8, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { +/// fn xdp(_ctx: XdpContext) -> u32 { /// // Redirect to CPU 7 or drop packet if no entry found. -/// MAP.redirect(7, xdp_action::XDP_DROP as u64) +/// MAP.redirect(7, xdp_action::XDP_DROP as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] diff --git a/bpf/aya-bpf/src/maps/xdp/dev_map.rs b/bpf/aya-bpf/src/maps/xdp/dev_map.rs index d7e62dd0..2d015b46 100644 --- a/bpf/aya-bpf/src/maps/xdp/dev_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/dev_map.rs @@ -27,8 +27,8 @@ use crate::{ /// static MAP: DevMap = DevMap::with_max_entries(1, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { -/// MAP.redirect(0, xdp_action::XDP_PASS as u64) +/// fn xdp(_ctx: XdpContext) -> u32 { +/// MAP.redirect(0, xdp_action::XDP_PASS as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] @@ -100,7 +100,7 @@ impl DevMap { /// #[map] /// static MAP: DevMap = DevMap::with_max_entries(1, 0); /// - /// let target_if_index = MAP.get(0).target_if_index; + /// let target_if_index = MAP.get(0).unwrap().if_index; /// /// // redirect to if_index /// ``` diff --git a/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs b/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs index 809215aa..d268bf5f 100644 --- a/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs +++ b/bpf/aya-bpf/src/maps/xdp/dev_map_hash.rs @@ -29,8 +29,8 @@ use crate::{ /// static MAP: DevMapHash = DevMapHash::with_max_entries(1, 0); /// /// #[xdp] -/// fn xdp(_ctx: XdpContext) -> i32 { -/// MAP.redirect(42, xdp_action::XDP_PASS as u64) +/// fn xdp(_ctx: XdpContext) -> u32 { +/// MAP.redirect(42, xdp_action::XDP_PASS as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[repr(transparent)] @@ -102,7 +102,7 @@ impl DevMapHash { /// #[map] /// static MAP: DevMapHash = DevMapHash::with_max_entries(1, 0); /// - /// let target_if_index = MAP.get(42).target_if_index; + /// let target_if_index = MAP.get(42).unwrap().if_index; /// /// // redirect to ifindex /// ``` diff --git a/bpf/aya-bpf/src/maps/xdp/xsk_map.rs b/bpf/aya-bpf/src/maps/xdp/xsk_map.rs index 934785c1..328c92b2 100644 --- a/bpf/aya-bpf/src/maps/xdp/xsk_map.rs +++ b/bpf/aya-bpf/src/maps/xdp/xsk_map.rs @@ -28,9 +28,9 @@ use crate::{ /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// /// #[xdp] -/// fn xdp(ctx, XdpContext) -> i32 { +/// fn xdp(ctx: XdpContext) -> u32 { /// let queue_id = unsafe { (*ctx.ctx).rx_queue_index }; -/// MAP.redirect(queue_id, xdp_action::XDP_DROP as u64) +/// SOCKS.redirect(queue_id, xdp_action::XDP_DROP as u64).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` /// @@ -68,7 +68,7 @@ impl XskMap { /// use aya_bpf::{macros::map, maps::XskMap}; /// /// #[map] - /// static SOCKS: XskMap::with_max_entries(8, 0); + /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// ``` pub const fn with_max_entries(max_entries: u32, flags: u32) -> XskMap { XskMap { @@ -93,7 +93,7 @@ impl XskMap { /// use aya_bpf::{macros::map, maps::XskMap}; /// /// #[map] - /// static SOCKS: XskMap::pinned(8, 0); + /// static SOCKS: XskMap = XskMap::pinned(8, 0); /// ``` pub const fn pinned(max_entries: u32, flags: u32) -> XskMap { XskMap { @@ -151,9 +151,9 @@ impl XskMap { /// static SOCKS: XskMap = XskMap::with_max_entries(8, 0); /// /// #[xdp] - /// fn xdp(ctx, XdpContext) -> u32 { + /// fn xdp(ctx: XdpContext) -> u32 { /// let queue_id = unsafe { (*ctx.ctx).rx_queue_index }; - /// MAP.redirect(queue_id, 0).unwrap_or(xdp_action::XDP_DROP) + /// SOCKS.redirect(queue_id, 0).unwrap_or(xdp_action::XDP_DROP) /// } /// ``` #[inline(always)]