From 0c2cc1f85b8ae06ac1fb40d0d76a8426d31f57de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20DEROIDE?= Date: Mon, 15 Sep 2025 16:56:04 +0200 Subject: [PATCH] aya-ebpf: Add BPF_F_ADJ_ROOM_ENCAP_L2 macro This macro is needed to properly add a L2 header when using bpf_skb_adjust_room [1]. As it is originally a C macro, it isn't automatically generated in the `bindings` crate [1]: https://docs.ebpf.io/linux/helper-function/bpf_skb_adjust_room/ --- ebpf/aya-ebpf/src/lib.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ebpf/aya-ebpf/src/lib.rs b/ebpf/aya-ebpf/src/lib.rs index d842abaf..1e850138 100644 --- a/ebpf/aya-ebpf/src/lib.rs +++ b/ebpf/aya-ebpf/src/lib.rs @@ -113,6 +113,15 @@ mod intrinsics { #[cfg(target_arch = "bpf")] pub use intrinsics::*; +// A reimplementation of the BPF_F_ADJ_ROOM_ENCAP_L2(len) macro of the kernel, to use to construct +// flags to pass to bpf_skb_adjust_room. +// https://elixir.bootlin.com/linux/v6.16.4/source/include/uapi/linux/bpf.h#L6149 +#[inline(always)] +#[allow(non_snake_case)] +pub fn BPF_F_ADJ_ROOM_ENCAP_L2(len: u64) -> u64 { + (len & u64::from(bindings::BPF_ADJ_ROOM_ENCAP_L2_MASK)) << bindings::BPF_ADJ_ROOM_ENCAP_L2_SHIFT +} + /// Check if a value is within a range, using conditional forms compatible with /// the verifier. #[inline(always)]