Skip to content

Commit 485e125

Browse files
committed
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/
1 parent 214fe3c commit 485e125

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

ebpf/aya-ebpf/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ mod intrinsics {
113113
#[cfg(target_arch = "bpf")]
114114
pub use intrinsics::*;
115115

116+
// A reimplementation of the BPF_F_ADJ_ROOM_ENCAP_L2(len) macro of the kernel, to use to construct
117+
// flags to pass to bpf_skb_adjust_room.
118+
// https://elixir.bootlin.com/linux/v6.16.4/source/include/uapi/linux/bpf.h#L6149
119+
#[inline(always)]
120+
#[allow(non_snake_case)]
121+
pub fn BPF_F_ADJ_ROOM_ENCAP_L2(len: u64) -> u64 {
122+
(len & u64::from(bindings::BPF_ADJ_ROOM_ENCAP_L2_MASK))
123+
<< u64::from(bindings::BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
124+
}
125+
116126
/// Check if a value is within a range, using conditional forms compatible with
117127
/// the verifier.
118128
#[inline(always)]

0 commit comments

Comments
 (0)