From d46fc8991bc3fb8368f5ec27c9f74926132715e5 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 da969290..f6356f9e 100644 --- a/ebpf/aya-ebpf/src/lib.rs +++ b/ebpf/aya-ebpf/src/lib.rs @@ -114,6 +114,15 @@ mod 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)]