|
|
@ -1,14 +1,15 @@
|
|
|
|
use core::{cell::UnsafeCell, marker::PhantomData, mem, ptr::NonNull};
|
|
|
|
use core::{cell::UnsafeCell, marker::PhantomData, mem};
|
|
|
|
|
|
|
|
|
|
|
|
use aya_ebpf_bindings::bindings::bpf_map_type::{
|
|
|
|
use aya_ebpf_bindings::bindings::bpf_map_type::{
|
|
|
|
BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH,
|
|
|
|
BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH, BPF_MAP_TYPE_PERCPU_HASH,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
use aya_ebpf_cty::{c_long, c_void};
|
|
|
|
use aya_ebpf_cty::c_long;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::{
|
|
|
|
use crate::{
|
|
|
|
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_HASH},
|
|
|
|
bindings::{bpf_map_def, bpf_map_type::BPF_MAP_TYPE_HASH},
|
|
|
|
helpers::{bpf_map_delete_elem, bpf_map_lookup_elem, bpf_map_update_elem},
|
|
|
|
insert, lookup,
|
|
|
|
maps::PinningType,
|
|
|
|
maps::PinningType,
|
|
|
|
|
|
|
|
remove,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#[repr(transparent)]
|
|
|
|
#[repr(transparent)]
|
|
|
@ -321,11 +322,7 @@ const fn build_def<K, V>(ty: u32, max_entries: u32, flags: u32, pin: PinningType
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
|
fn get_ptr_mut<K, V>(def: *mut bpf_map_def, key: &K) -> Option<*mut V> {
|
|
|
|
fn get_ptr_mut<K, V>(def: *mut bpf_map_def, key: &K) -> Option<*mut V> {
|
|
|
|
unsafe {
|
|
|
|
lookup(def, key).map(|p| p.as_ptr())
|
|
|
|
let value = bpf_map_lookup_elem(def as *mut _, key as *const _ as *const c_void);
|
|
|
|
|
|
|
|
// FIXME: alignment
|
|
|
|
|
|
|
|
NonNull::new(value as *mut V).map(|p| p.as_ptr())
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
#[inline]
|
|
|
@ -337,22 +334,3 @@ fn get_ptr<K, V>(def: *mut bpf_map_def, key: &K) -> Option<*const V> {
|
|
|
|
unsafe fn get<'a, K, V>(def: *mut bpf_map_def, key: &K) -> Option<&'a V> {
|
|
|
|
unsafe fn get<'a, K, V>(def: *mut bpf_map_def, key: &K) -> Option<&'a V> {
|
|
|
|
get_ptr(def, key).map(|p| &*p)
|
|
|
|
get_ptr(def, key).map(|p| &*p)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
|
|
|
fn insert<K, V>(def: *mut bpf_map_def, key: &K, value: &V, flags: u64) -> Result<(), c_long> {
|
|
|
|
|
|
|
|
let ret = unsafe {
|
|
|
|
|
|
|
|
bpf_map_update_elem(
|
|
|
|
|
|
|
|
def as *mut _,
|
|
|
|
|
|
|
|
key as *const _ as *const _,
|
|
|
|
|
|
|
|
value as *const _ as *const _,
|
|
|
|
|
|
|
|
flags,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
(ret == 0).then_some(()).ok_or(ret)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
|
|
|
fn remove<K>(def: *mut bpf_map_def, key: &K) -> Result<(), c_long> {
|
|
|
|
|
|
|
|
let ret = unsafe { bpf_map_delete_elem(def as *mut _, key as *const _ as *const c_void) };
|
|
|
|
|
|
|
|
(ret == 0).then_some(()).ok_or(ret)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|