Repository: aya-rs/aya (language: rust)

Issue:
bpf: LPMTrie needs to be created with flag BPF_F_NO_PREALLOC
Here: https://github.com/aya-rs/aya/blob/main/bpf/aya-bpf/src/maps/lpm_trie.rs#L40
And in any other constructor for this map, we should add `BPF_F_NOPREALLOC` if not already provided.

This is to avoid getting an `-EINVAL` on map creation.
See: https://github.com/torvalds/linux/blob/9e6b19a66d9b6b94395478fe79c5a3ccba181ad3/kernel/bpf/lpm_trie.c#L551


Discussion / hints:
I would like to work on this issue.

Fix patch:
diff --git a/bpf/aya-bpf/src/maps/lpm_trie.rs b/bpf/aya-bpf/src/maps/lpm_trie.rs
index e50282af1..d9314899e 100644
--- a/bpf/aya-bpf/src/maps/lpm_trie.rs
+++ b/bpf/aya-bpf/src/maps/lpm_trie.rs
@@ -1,5 +1,6 @@
 use core::{cell::UnsafeCell, marker::PhantomData, mem, ptr::NonNull};
 
+use aya_bpf_bindings::bindings::BPF_F_NO_PREALLOC;
 use aya_bpf_cty::{c_long, c_void};
 
 use crate::{
@@ -33,6 +34,7 @@ impl<K> Key<K> {
 
 impl<K, V> LpmTrie<K, V> {
     pub const fn with_max_entries(max_entries: u32, flags: u32) -> LpmTrie<K, V> {
+        let flags = flags | BPF_F_NO_PREALLOC;
         LpmTrie {
             def: UnsafeCell::new(build_def::<K, V>(
                 BPF_MAP_TYPE_LPM_TRIE,
@@ -46,6 +48,7 @@ impl<K, V> LpmTrie<K, V> {
     }
 
     pub const fn pinned(max_entries: u32, flags: u32) -> LpmTrie<K, V> {
+        let flags = flags | BPF_F_NO_PREALLOC;
         LpmTrie {
             def: UnsafeCell::new(build_def::<K, V>(
                 BPF_MAP_TYPE_LPM_TRIE,


Test patch: