From eefeba6be22f4d31103cbad177ee5c78b9eb1daa 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 | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ebpf/aya-ebpf/src/lib.rs b/ebpf/aya-ebpf/src/lib.rs index d842abaf..9da648a2 100644 --- a/ebpf/aya-ebpf/src/lib.rs +++ b/ebpf/aya-ebpf/src/lib.rs @@ -113,6 +113,16 @@ 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 & bindings::BPF_ADJ_ROOM_ENCAP_L2_MASK as u64) + << bindings::BPF_ADJ_ROOM_ENCAP_L2_SHIFT as u64 +} + /// Check if a value is within a range, using conditional forms compatible with /// the verifier. #[inline(always)]