From cd76d8a4696045e1b229b3a756aaf201b424fdd3 Mon Sep 17 00:00:00 2001 From: Michal R Date: Mon, 29 Sep 2025 08:25:04 +0200 Subject: [PATCH] aya-ebpf: Add BTF map definitions for hash maps Introduce BTF map definitions for hash maps, with custom structs indicating the metadata of the map, which end up in the `.maps` section. --- .../src/btf_maps/docs/hash_map_examples.md | 42 +++ .../btf_maps/docs/lru_hash_map_examples.md | 43 +++ .../docs/lru_per_cpu_hash_map_examples.md | 43 +++ .../docs/per_cpu_hash_map_examples.md | 42 +++ ebpf/aya-ebpf/src/btf_maps/hash_map.rs | 123 +++++++ ebpf/aya-ebpf/src/btf_maps/mod.rs | 2 + test/integration-common/src/lib.rs | 4 + test/integration-ebpf/Cargo.toml | 4 + test/integration-ebpf/src/hash_map.rs | 135 +++++++ test/integration-test/Cargo.toml | 1 + test/integration-test/src/lib.rs | 1 + test/integration-test/src/tests.rs | 1 + test/integration-test/src/tests/hash_map.rs | 234 ++++++++++++ xtask/public-api/aya-ebpf.txt | 341 ++++++++++++++++++ 14 files changed, 1016 insertions(+) create mode 100644 ebpf/aya-ebpf/src/btf_maps/docs/hash_map_examples.md create mode 100644 ebpf/aya-ebpf/src/btf_maps/docs/lru_hash_map_examples.md create mode 100644 ebpf/aya-ebpf/src/btf_maps/docs/lru_per_cpu_hash_map_examples.md create mode 100644 ebpf/aya-ebpf/src/btf_maps/docs/per_cpu_hash_map_examples.md create mode 100644 ebpf/aya-ebpf/src/btf_maps/hash_map.rs create mode 100644 test/integration-ebpf/src/hash_map.rs create mode 100644 test/integration-test/src/tests/hash_map.rs diff --git a/ebpf/aya-ebpf/src/btf_maps/docs/hash_map_examples.md b/ebpf/aya-ebpf/src/btf_maps/docs/hash_map_examples.md new file mode 100644 index 00000000..030de0c7 --- /dev/null +++ b/ebpf/aya-ebpf/src/btf_maps/docs/hash_map_examples.md @@ -0,0 +1,42 @@ +# Examples + +```rust,no_run +use aya_ebpf::{ + btf_maps::HashMap, + macros::{btf_map, tracepoint}, + programs::TracePointContext, + EbpfContext as _, +}; + +/// A hash map that counts syscalls issued by different processes. +#[btf_map] +static COUNTER: HashMap< + // PID. + u32, + // Count of syscalls issued by the given process. + u32, + // Maximum number of elements. Reaching this capacity triggers an error. + 10, + // Optional flags. + 0 +> = HashMap::new(); + +/// A simple program attached to the `sys_enter` tracepoint that counts +/// syscalls. +#[tracepoint] +fn sys_enter(ctx: TracePointContext) { + let pid = ctx.pid(); + + if let Some(mut count) = COUNTER.get_ptr_mut(pid) { + unsafe { *count += 1 }; + } else { + COUNTER.insert( + pid, + // New value. + 1, + // Optional flags. + 0 + ); + } +} +``` diff --git a/ebpf/aya-ebpf/src/btf_maps/docs/lru_hash_map_examples.md b/ebpf/aya-ebpf/src/btf_maps/docs/lru_hash_map_examples.md new file mode 100644 index 00000000..57c57650 --- /dev/null +++ b/ebpf/aya-ebpf/src/btf_maps/docs/lru_hash_map_examples.md @@ -0,0 +1,43 @@ +# Examples + +```rust,no_run +use aya_ebpf::{ + btf_maps::LruHashMap, + macros::{btf_map, tracepoint}, + programs::TracePointContext, + EbpfContext as _, +}; + +/// A hash map that counts syscalls issued by different processes. +#[btf_map] +static COUNTER: LruHashMap< + // PID. + u32, + // Count of syscalls issued by the given process. + u32, + // Maximum number of elements. Reaching this capacity triggers eviction of + // the least used elements. + 10, + // Optional flags. + 0 +> = LruHashMap::new(); + +/// A simple program attached to the `sys_enter` tracepoint that counts +/// syscalls. +#[tracepoint] +fn sys_enter(ctx: TracePointContext) { + let pid = ctx.pid(); + + if let Some(mut count) = COUNTER.get_ptr_mut(pid) { + unsafe { *count += 1 }; + } else { + COUNTER.insert( + pid, + // New value. + 1, + // Optional flags. + 0 + ); + } +} +``` diff --git a/ebpf/aya-ebpf/src/btf_maps/docs/lru_per_cpu_hash_map_examples.md b/ebpf/aya-ebpf/src/btf_maps/docs/lru_per_cpu_hash_map_examples.md new file mode 100644 index 00000000..ccb85cab --- /dev/null +++ b/ebpf/aya-ebpf/src/btf_maps/docs/lru_per_cpu_hash_map_examples.md @@ -0,0 +1,43 @@ +# Examples + +```rust,no_run +use aya_ebpf::{ + btf_maps::LruPerCpuHashMap, + macros::{btf_map, tracepoint}, + programs::TracePointContext, + EbpfContext as _, +}; + +/// A hash map that counts syscalls issued by different processes. +#[btf_map] +static COUNTER: LruPerCpuHashMap< + // PID. + u32, + // Count of syscalls issued by the given process. + u32, + // Maximum number of elements. Reaching this capacity triggers eviction of + // the least used elements. + 10, + // Optional flags. + 0 +> = LruPerCpuHashMap::new(); + +/// A simple program attached to the `sys_enter` tracepoint that counts +/// syscalls. +#[tracepoint] +fn sys_enter(ctx: TracePointContext) { + let pid = ctx.pid(); + + if let Some(mut count) = COUNTER.get_ptr_mut(pid) { + unsafe { *count += 1 }; + } else { + COUNTER.insert( + pid, + // New value. + 1, + // Optional flags. + 0 + ); + } +} +``` diff --git a/ebpf/aya-ebpf/src/btf_maps/docs/per_cpu_hash_map_examples.md b/ebpf/aya-ebpf/src/btf_maps/docs/per_cpu_hash_map_examples.md new file mode 100644 index 00000000..fb476fb2 --- /dev/null +++ b/ebpf/aya-ebpf/src/btf_maps/docs/per_cpu_hash_map_examples.md @@ -0,0 +1,42 @@ +# Examples + +```rust,no_run +use aya_ebpf::{ + btf_maps::PerCpuHashMap, + macros::{btf_map, tracepoint}, + programs::TracePointContext, + EbpfContext as _, +}; + +/// A hash map that counts syscalls issued by different processes. +#[btf_map] +static COUNTER: PerCpuHashMap< + // PID. + u32, + // Count of syscalls issued by the given process. + u32, + // Maximum number of elements. Reaching this capacity triggers an error. + 10, + // Optional flags. + 0 +> = PerCpuHashMap::new(); + +/// A simple program attached to the `sys_enter` tracepoint that counts +/// syscalls. +#[tracepoint] +fn sys_enter(ctx: TracePointContext) { + let pid = ctx.pid(); + + if let Some(mut count) = COUNTER.get_ptr_mut(pid) { + unsafe { *count += 1 }; + } else { + COUNTER.insert( + pid, + // New value. + 1, + // Optional flags. + 0 + ); + } +} +``` diff --git a/ebpf/aya-ebpf/src/btf_maps/hash_map.rs b/ebpf/aya-ebpf/src/btf_maps/hash_map.rs new file mode 100644 index 00000000..8f5d9896 --- /dev/null +++ b/ebpf/aya-ebpf/src/btf_maps/hash_map.rs @@ -0,0 +1,123 @@ +use core::{borrow::Borrow, cell::UnsafeCell}; + +use crate::{ + bindings::bpf_map_type::{ + BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH, + BPF_MAP_TYPE_PERCPU_HASH, + }, + btf_map_def, + cty::{c_long, c_void}, + insert, lookup, remove, +}; + +/// Generates a hash map definition with common methods. +macro_rules! hash_map { + ( + $map_doc:literal, + $map_doc_examples:literal, + $name:ident, + $def:ident + $(,)? + ) => { + #[doc = include_str!($map_doc)] + #[doc = include_str!($map_doc_examples)] + #[repr(transparent)] + pub struct $name(UnsafeCell<$def>); + + unsafe impl Sync for $name {} + + impl $name { + #[expect( + clippy::new_without_default, + reason = "BPF maps are always used as static variables, therefore this method has to be `const`. `Default::default` is not `const`." + )] + pub const fn new() -> Self { + Self(UnsafeCell::new($def::new())) + } + + #[doc = "Retrieves the value associated with `key` from the map."] + #[doc = include_str!("../maps/map_safety.md")] + #[inline] + pub unsafe fn get(&self, key: impl Borrow) -> Option<&V> { + unsafe { get(self.0.get().cast(), key.borrow()) } + } + + #[doc = "Retrieves the pointer associated with `key` from the map."] + #[doc = include_str!("../maps/map_safety.md")] + #[inline] + pub fn get_ptr(&self, key: impl Borrow) -> Option<*const V> { + get_ptr(self.0.get().cast(), key.borrow()) + } + + #[doc = "Retrieves the mutable pointer associated with `key` from the map."] + #[doc = include_str!("../maps/map_safety.md")] + #[inline] + pub fn get_ptr_mut(&self, key: impl Borrow) -> Option<*mut V> { + get_ptr_mut(self.0.get().cast(), key.borrow()) + } + + #[inline] + pub fn insert( + &self, + key: impl Borrow, + value: impl Borrow, + flags: u64, + ) -> Result<(), c_long> { + insert(self.0.get().cast(), key.borrow(), value.borrow(), flags) + } + + #[inline] + pub fn remove(&self, key: impl Borrow) -> Result<(), c_long> { + remove(self.0.get().cast(), key.borrow()) + } + } + }; +} + +btf_map_def!(HashMapDef, BPF_MAP_TYPE_HASH); +btf_map_def!(LruHashMapDef, BPF_MAP_TYPE_LRU_HASH); +btf_map_def!(PerCpuHashMapDef, BPF_MAP_TYPE_PERCPU_HASH); +btf_map_def!(LruPerCpuHashMapDef, BPF_MAP_TYPE_LRU_PERCPU_HASH); + +hash_map!( + "../maps/docs/hash_map.md", + "docs/hash_map_examples.md", + HashMap, + HashMapDef, +); + +hash_map!( + "../maps/docs/lru_hash_map.md", + "docs/lru_hash_map_examples.md", + LruHashMap, + LruHashMapDef, +); + +hash_map!( + "../maps/docs/per_cpu_hash_map.md", + "docs/per_cpu_hash_map_examples.md", + PerCpuHashMap, + PerCpuHashMapDef, +); + +hash_map!( + "../maps/docs/lru_per_cpu_hash_map.md", + "docs/lru_per_cpu_hash_map_examples.md", + LruPerCpuHashMap, + LruPerCpuHashMapDef, +); + +#[inline] +unsafe fn get<'a, K, V>(def: *mut c_void, key: &K) -> Option<&'a V> { + get_ptr(def, key).map(|p| unsafe { &*p }) +} + +#[inline] +fn get_ptr_mut(def: *mut c_void, key: &K) -> Option<*mut V> { + lookup(def, key).map(|p| p.as_ptr()) +} + +#[inline] +fn get_ptr(def: *mut c_void, key: &K) -> Option<*const V> { + lookup::<_, V>(def.cast(), key).map(|p| p.as_ptr().cast_const()) +} diff --git a/ebpf/aya-ebpf/src/btf_maps/mod.rs b/ebpf/aya-ebpf/src/btf_maps/mod.rs index a65a4a7e..5e68ef61 100644 --- a/ebpf/aya-ebpf/src/btf_maps/mod.rs +++ b/ebpf/aya-ebpf/src/btf_maps/mod.rs @@ -1,9 +1,11 @@ use core::marker::PhantomData; pub mod array; +pub mod hash_map; pub mod sk_storage; pub use array::Array; +pub use hash_map::{HashMap, LruHashMap, LruPerCpuHashMap, PerCpuHashMap}; pub use sk_storage::SkStorage; /// A marker used to remove names of annotated types in LLVM debug info and diff --git a/test/integration-common/src/lib.rs b/test/integration-common/src/lib.rs index 89179841..c18a271c 100644 --- a/test/integration-common/src/lib.rs +++ b/test/integration-common/src/lib.rs @@ -20,6 +20,10 @@ pub mod bpf_probe_read { unsafe impl aya::Pod for TestResult {} } +pub mod hash_map { + pub const GET_INDEX: u32 = 0; +} + pub mod log { pub const BUF_LEN: usize = 1024; diff --git a/test/integration-ebpf/Cargo.toml b/test/integration-ebpf/Cargo.toml index cb52e728..7112fd6a 100644 --- a/test/integration-ebpf/Cargo.toml +++ b/test/integration-ebpf/Cargo.toml @@ -32,6 +32,10 @@ path = "src/array.rs" name = "bpf_probe_read" path = "src/bpf_probe_read.rs" +[[bin]] +name = "hash_map" +path = "src/hash_map.rs" + [[bin]] name = "linear_data_structures" path = "src/linear_data_structures.rs" diff --git a/test/integration-ebpf/src/hash_map.rs b/test/integration-ebpf/src/hash_map.rs new file mode 100644 index 00000000..3965b57e --- /dev/null +++ b/test/integration-ebpf/src/hash_map.rs @@ -0,0 +1,135 @@ +#![no_std] +#![no_main] +#![expect(unused_crate_dependencies, reason = "used in other bins")] + +#[cfg(not(test))] +extern crate ebpf_panic; + +use aya_ebpf::{ + btf_maps::{Array, HashMap, LruHashMap, LruPerCpuHashMap, PerCpuHashMap}, + cty::c_long, + macros::{btf_map, map, uprobe}, + maps::{ + Array as LegacyArray, HashMap as LegacyHashMap, LruHashMap as LegacyLruHashMap, + LruPerCpuHashMap as LegacyLruPerCpuHashMap, PerCpuHashMap as LegacyPerCpuHashMap, + }, + programs::ProbeContext, +}; +use integration_common::hash_map::GET_INDEX; + +#[btf_map] +static RESULT: Array = Array::new(); +#[btf_map] +static HASH_MAP: HashMap = HashMap::new(); +#[btf_map] +static LRU_HASH_MAP: LruHashMap = LruHashMap::new(); +#[btf_map] +static PER_CPU_HASH_MAP: PerCpuHashMap = PerCpuHashMap::new(); +#[btf_map] +static LRU_PER_CPU_HASH_MAP: LruPerCpuHashMap = + LruPerCpuHashMap::new(); + +#[map] +static RESULT_LEGACY: LegacyArray = LegacyArray::with_max_entries(3, 0); +#[map] +static HASH_MAP_LEGACY: LegacyHashMap = LegacyHashMap::with_max_entries(10, 0); +#[map] +static LRU_HASH_MAP_LEGACY: LegacyLruHashMap = LegacyLruHashMap::with_max_entries(10, 0); +#[map] +static PER_CPU_HASH_MAP_LEGACY: LegacyPerCpuHashMap = + LegacyPerCpuHashMap::with_max_entries(10, 0); +#[map] +static LRU_PER_CPU_HASH_MAP_LEGACY: LegacyLruPerCpuHashMap = + LegacyLruPerCpuHashMap::with_max_entries(10, 0); + +macro_rules! define_result_set { + ( + $result_map:ident, + $result_set_fn:ident + ) => { + #[inline(always)] + fn $result_set_fn(index: u32, value: u32) -> Result<(), c_long> { + let ptr = $result_map.get_ptr_mut(index).ok_or(-1)?; + let dst = unsafe { ptr.as_mut() }; + let dst_res = dst.ok_or(-1)?; + *dst_res = value; + Ok(()) + } + }; +} + +define_result_set!(RESULT, result_set); +define_result_set!(RESULT_LEGACY, result_set_legacy); + +macro_rules! define_hash_map_test { + ( + $hash_map:ident, + $result_set_fn:ident, + $insert_prog:ident, + $get_prog:ident + $(,)? + ) => { + #[uprobe] + fn $insert_prog(ctx: ProbeContext) -> Result<(), c_long> { + let key = ctx.arg(0).ok_or(-1)?; + let value = ctx.arg(1).ok_or(-1)?; + $hash_map.insert(&key, &value, 0)?; + Ok(()) + } + + #[uprobe] + fn $get_prog(ctx: ProbeContext) -> Result<(), c_long> { + let key = ctx.arg(0).ok_or(-1)?; + let value = unsafe { $hash_map.get(&key).ok_or(-1)? }; + $result_set_fn(GET_INDEX, *value)?; + Ok(()) + } + }; +} + +define_hash_map_test!(HASH_MAP, result_set, hash_map_insert, hash_map_get); +define_hash_map_test!( + HASH_MAP_LEGACY, + result_set_legacy, + hash_map_insert_legacy, + hash_map_get_legacy, +); + +define_hash_map_test!( + LRU_HASH_MAP, + result_set, + lru_hash_map_insert, + lru_hash_map_get +); +define_hash_map_test!( + LRU_HASH_MAP_LEGACY, + result_set_legacy, + lru_hash_map_insert_legacy, + lru_hash_map_get_legacy, +); + +define_hash_map_test!( + PER_CPU_HASH_MAP, + result_set, + per_cpu_hash_map_insert, + per_cpu_hash_map_get, +); +define_hash_map_test!( + PER_CPU_HASH_MAP_LEGACY, + result_set_legacy, + per_cpu_hash_map_insert_legacy, + per_cpu_hash_map_get_legacy, +); + +define_hash_map_test!( + LRU_PER_CPU_HASH_MAP, + result_set, + lru_per_cpu_hash_map_insert, + lru_per_cpu_hash_map_get, +); +define_hash_map_test!( + LRU_PER_CPU_HASH_MAP_LEGACY, + result_set_legacy, + lru_per_cpu_hash_map_insert_legacy, + lru_per_cpu_hash_map_get_legacy, +); diff --git a/test/integration-test/Cargo.toml b/test/integration-test/Cargo.toml index 916db163..2a304f90 100644 --- a/test/integration-test/Cargo.toml +++ b/test/integration-test/Cargo.toml @@ -27,6 +27,7 @@ integration-common = { path = "../integration-common", features = ["user"] } libc = { workspace = true } log = { workspace = true } netns-rs = { workspace = true } +nix = { workspace = true, features = ["process", "sched"] } object = { workspace = true, features = ["elf", "read_core", "std"] } procfs = { workspace = true, features = ["flate2"] } rand = { workspace = true, features = ["thread_rng"] } diff --git a/test/integration-test/src/lib.rs b/test/integration-test/src/lib.rs index 64f37d18..4bb78354 100644 --- a/test/integration-test/src/lib.rs +++ b/test/integration-test/src/lib.rs @@ -40,6 +40,7 @@ bpf_file!( ARRAY => "array", BPF_PROBE_READ => "bpf_probe_read", + HASH_MAP => "hash_map", LINEAR_DATA_STRUCTURES => "linear_data_structures", LOG => "log", MAP_TEST => "map_test", diff --git a/test/integration-test/src/tests.rs b/test/integration-test/src/tests.rs index b7d4d492..2b8f2caf 100644 --- a/test/integration-test/src/tests.rs +++ b/test/integration-test/src/tests.rs @@ -3,6 +3,7 @@ mod bpf_probe_read; mod btf_relocations; mod elf; mod feature_probe; +mod hash_map; mod info; mod iter; mod linear_data_structures; diff --git a/test/integration-test/src/tests/hash_map.rs b/test/integration-test/src/tests/hash_map.rs new file mode 100644 index 00000000..623570e2 --- /dev/null +++ b/test/integration-test/src/tests/hash_map.rs @@ -0,0 +1,234 @@ +use std::thread; + +use aya::{ + Ebpf, EbpfLoader, + maps::{Array, HashMap, MapData, MapError, PerCpuHashMap}, + programs::UProbe, +}; +use integration_common::hash_map::GET_INDEX; + +/// Triggers the eBPF program that inserts the given `key` and `value` pair +/// into the hash map. +#[unsafe(no_mangle)] +#[inline(never)] +extern "C" fn hash_map_insert(key: u32, value: u32) { + std::hint::black_box((key, value)); +} + +/// Triggers the eBPF program that retrieves the value associated with the +/// `key` and inserts it into the array. +#[unsafe(no_mangle)] +#[inline(never)] +extern "C" fn hash_map_get(key: u32) { + std::hint::black_box(key); +} + +/// Loads the uprobe program and attaches it to the given `symbol`. +fn load_program(ebpf: &mut Ebpf, prog_name: &str, symbol: &str) { + let prog: &mut UProbe = ebpf.program_mut(prog_name).unwrap().try_into().unwrap(); + prog.load().unwrap(); + prog.attach(symbol, "/proc/self/exe", None, None).unwrap(); +} + +/// Loads the pair of programs: +/// +/// * `insert_prog` that inserts key and value pairs into the `hash_map`. +/// * `get_prog` that retrieves values from the `hash_map` and inserts them +/// into `result_map`. +/// +/// Returns the result array and the hash map. +fn load_programs_with_maps<'a>( + ebpf: &'a mut Ebpf, + result_array: &'a str, + hash_map: &'a str, + insert_prog: &'a str, + get_prog: &'a str, +) -> (Array<&'a MapData, u32>, HashMap<&'a MapData, u32, u32>) { + load_program(ebpf, insert_prog, "hash_map_insert"); + load_program(ebpf, get_prog, "hash_map_get"); + + let result_array = ebpf.map(result_array).unwrap(); + let result_array = Array::<_, u32>::try_from(result_array).unwrap(); + + let hash_map = ebpf.map(hash_map).unwrap(); + let hash_map = HashMap::<_, u32, u32>::try_from(hash_map).unwrap(); + + (result_array, hash_map) +} + +/// Loads the `insert_prog` program that inserts elements into the +/// `per_cpu_hash_map`. Returns the map. +fn load_program_with_per_cpu_map<'a>( + ebpf: &'a mut Ebpf, + per_cpu_hash_map: &'a str, + insert_prog: &'a str, +) -> PerCpuHashMap<&'a MapData, u32, u32> { + load_program(ebpf, insert_prog, "hash_map_insert"); + + let hash_map = ebpf.map(per_cpu_hash_map).unwrap(); + PerCpuHashMap::<_, u32, u32>::try_from(hash_map).unwrap() +} + +#[test_log::test] +fn test_hash_map() { + let mut ebpf = EbpfLoader::new().load(crate::HASH_MAP).unwrap(); + for (result_map_name, hash_map_name, insert_prog_name, get_prog_name) in [ + // BTF map definitions. + ("RESULT", "HASH_MAP", "hash_map_insert", "hash_map_get"), + // Legacy map definitions. + ( + "RESULT_LEGACY", + "HASH_MAP_LEGACY", + "hash_map_insert_legacy", + "hash_map_get_legacy", + ), + ] { + let (result_array, hash_map) = load_programs_with_maps( + &mut ebpf, + result_map_name, + hash_map_name, + insert_prog_name, + get_prog_name, + ); + + let seq = 0_u32..9; + for i in seq.clone() { + hash_map_insert(i.pow(2), i); + } + for i in seq.clone() { + // Assert the value returned by user-space API. + let key = i.pow(2); + let value = hash_map.get(&key, 0).unwrap(); + assert_eq!(value, i); + // Assert the value returned by eBPF in-kernel API. + hash_map_get(key); + let result = result_array.get(&GET_INDEX, 0).unwrap(); + assert_eq!(result, i); + } + } +} + +#[test_log::test] +fn test_lru_hash_map() { + let mut ebpf = EbpfLoader::new().load(crate::HASH_MAP).unwrap(); + for (result_map_name, hash_map_name, insert_prog_name, get_prog_name) in [ + // BTF map definitions. + ( + "RESULT", + "LRU_HASH_MAP", + "lru_hash_map_insert", + "lru_hash_map_get", + ), + // Legacy map definitions. + ( + "RESULT_LEGACY", + "LRU_HASH_MAP_LEGACY", + "lru_hash_map_insert_legacy", + "lru_hash_map_get_legacy", + ), + ] { + let (result_array, hash_map) = load_programs_with_maps( + &mut ebpf, + result_map_name, + hash_map_name, + insert_prog_name, + get_prog_name, + ); + + // Insert elements over capacity. + let seq = 0_u32..15; + for i in seq.clone() { + hash_map_insert(i.pow(2), i); + } + // Check whether elements 0..5 got evicted. + for i in 0_u32..5 { + let key = i.pow(2); + assert!(matches!(hash_map.get(&key, 0), Err(MapError::KeyNotFound))); + } + // Check whether the newest 10 elements can be retrieved. + for i in 5_u32..15 { + // Assert the value returned by user-space API. + let key = i.pow(2); + let value = hash_map.get(&key, 0).unwrap(); + assert_eq!(value, i); + // Assert the value returned by eBPF in-kernel API. + hash_map_get(key); + let result = result_array.get(&GET_INDEX, 0).unwrap(); + assert_eq!(result, i); + } + } +} + +#[test_log::test] +fn test_per_cpu_hash_map() { + let mut ebpf = EbpfLoader::new().load(crate::HASH_MAP).unwrap(); + for (hash_map_name, insert_prog_name) in [ + // BTF map definitions. + ("PER_CPU_HASH_MAP", "per_cpu_hash_map_insert"), + // Legacy map definitions. + ("PER_CPU_HASH_MAP_LEGACY", "per_cpu_hash_map_insert_legacy"), + ] { + let hash_map = load_program_with_per_cpu_map(&mut ebpf, hash_map_name, insert_prog_name); + + let seq = 0_u32..9; + thread::scope(|s| { + let seq = seq.clone(); + s.spawn(move || { + let mut cpu_set = nix::sched::CpuSet::new(); + cpu_set.set(0).unwrap(); + nix::sched::sched_setaffinity(nix::unistd::Pid::from_raw(0), &cpu_set).unwrap(); + + for i in seq { + hash_map_insert(i.pow(2), i); + } + }); + }); + for i in seq.clone() { + let key = i.pow(2); + let values = hash_map.get(&key, 0).unwrap(); + assert_eq!(values.first().unwrap(), &i); + } + } +} + +#[test_log::test] +fn test_lru_per_cpu_hash_map() { + let mut ebpf = EbpfLoader::new().load(crate::HASH_MAP).unwrap(); + for (hash_map_name, insert_prog_name) in [ + // BTF map definitions. + ("LRU_PER_CPU_HASH_MAP", "lru_per_cpu_hash_map_insert"), + // Legacy map definitions. + ( + "LRU_PER_CPU_HASH_MAP_LEGACY", + "lru_per_cpu_hash_map_insert_legacy", + ), + ] { + let hash_map = load_program_with_per_cpu_map(&mut ebpf, hash_map_name, insert_prog_name); + + // Insert elements over capacity. + let seq = 0_u32..15; + thread::scope(|s| { + let seq = seq.clone(); + s.spawn(move || { + let mut cpu_set = nix::sched::CpuSet::new(); + cpu_set.set(0).unwrap(); + nix::sched::sched_setaffinity(nix::unistd::Pid::from_raw(0), &cpu_set).unwrap(); + + for i in seq { + hash_map_insert(i.pow(2), i); + } + }); + }); + // Check whether elements 0..5 got evicted. + for i in 0_u32..5 { + let key = i.pow(2); + assert!(matches!(hash_map.get(&key, 0), Err(MapError::KeyNotFound))); + } + // Check whether the newest 10 elements can be retrieved. + for i in 5_u32..15 { + let key = i.pow(2); + let values = hash_map.get(&key, 0).unwrap(); + assert_eq!(values.first().unwrap(), &i); + } + } +} diff --git a/xtask/public-api/aya-ebpf.txt b/xtask/public-api/aya-ebpf.txt index 74317218..91856482 100644 --- a/xtask/public-api/aya-ebpf.txt +++ b/xtask/public-api/aya-ebpf.txt @@ -58,6 +58,227 @@ impl core::borrow::BorrowMut for aya_ebpf::btf_maps::array::ArrayDef::borrow_mut(&mut self) -> &mut T impl core::convert::From for aya_ebpf::btf_maps::array::ArrayDef pub fn aya_ebpf::btf_maps::array::ArrayDef::from(t: T) -> T +pub mod aya_ebpf::btf_maps::hash_map +#[repr(transparent)] pub struct aya_ebpf::btf_maps::hash_map::HashMap(_) +impl aya_ebpf::btf_maps::hash_map::HashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::HashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::HashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::HashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::HashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::HashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::HashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::HashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::HashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::HashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::HashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::HashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::HashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::HashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::HashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::HashMap +pub fn aya_ebpf::btf_maps::hash_map::HashMap::from(t: T) -> T +pub struct aya_ebpf::btf_maps::hash_map::HashMapDef +impl aya_ebpf::btf_maps::hash_map::HashMapDef +pub const fn aya_ebpf::btf_maps::hash_map::HashMapDef::new() -> aya_ebpf::btf_maps::hash_map::HashMapDef +impl core::marker::Freeze for aya_ebpf::btf_maps::hash_map::HashMapDef +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::HashMapDef +impl !core::marker::Sync for aya_ebpf::btf_maps::hash_map::HashMapDef +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::HashMapDef +impl core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::HashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::HashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::HashMapDef where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::HashMapDef where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::HashMapDef::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::HashMapDef where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::HashMapDef::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::HashMapDef where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::HashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::HashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::HashMapDef +pub fn aya_ebpf::btf_maps::hash_map::HashMapDef::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::hash_map::LruHashMap(_) +impl aya_ebpf::btf_maps::hash_map::LruHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::LruHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::LruHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruHashMap +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::from(t: T) -> T +pub struct aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl aya_ebpf::btf_maps::hash_map::LruHashMapDef +pub const fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::new() -> aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl !core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruHashMapDef +impl core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruHashMapDef where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruHashMapDef where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruHashMapDef::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruHashMapDef where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruHashMapDef::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruHashMapDef where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruHashMapDef +pub fn aya_ebpf::btf_maps::hash_map::LruHashMapDef::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap(_) +impl aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::from(t: T) -> T +pub struct aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +pub const fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::new() -> aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl !core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +impl core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMapDef::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::hash_map::PerCpuHashMap(_) +impl aya_ebpf::btf_maps::hash_map::PerCpuHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::from(t: T) -> T +pub struct aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +pub const fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::new() -> aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl core::marker::Freeze for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl !core::marker::Sync for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +impl core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMapDef::from(t: T) -> T pub mod aya_ebpf::btf_maps::sk_storage #[repr(transparent)] pub struct aya_ebpf::btf_maps::sk_storage::SkStorage(_) impl aya_ebpf::btf_maps::sk_storage::SkStorage @@ -141,6 +362,126 @@ impl core::borrow::BorrowMut for aya_ebpf::btf_maps::array::Array pub fn aya_ebpf::btf_maps::array::Array::borrow_mut(&mut self) -> &mut T impl core::convert::From for aya_ebpf::btf_maps::array::Array pub fn aya_ebpf::btf_maps::array::Array::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::HashMap(_) +impl aya_ebpf::btf_maps::hash_map::HashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::HashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::HashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::HashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::HashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::HashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::HashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::HashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::HashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::HashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::HashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::HashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::HashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::HashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::HashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::HashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::HashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::HashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::HashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::HashMap +pub fn aya_ebpf::btf_maps::hash_map::HashMap::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::LruHashMap(_) +impl aya_ebpf::btf_maps::hash_map::LruHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::LruHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::LruHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruHashMap +pub fn aya_ebpf::btf_maps::hash_map::LruHashMap::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::LruPerCpuHashMap(_) +impl aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap +pub fn aya_ebpf::btf_maps::hash_map::LruPerCpuHashMap::from(t: T) -> T +#[repr(transparent)] pub struct aya_ebpf::btf_maps::PerCpuHashMap(_) +impl aya_ebpf::btf_maps::hash_map::PerCpuHashMap +pub unsafe fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get(&self, key: impl core::borrow::Borrow) -> core::option::Option<&V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get_ptr(&self, key: impl core::borrow::Borrow) -> core::option::Option<*const V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::get_ptr_mut(&self, key: impl core::borrow::Borrow) -> core::option::Option<*mut V> +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::insert(&self, key: impl core::borrow::Borrow, value: impl core::borrow::Borrow, flags: u64) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +pub const fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::new() -> Self +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::remove(&self, key: impl core::borrow::Borrow) -> core::result::Result<(), aya_ebpf_cty::od::c_long> +impl core::marker::Sync for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::marker::Freeze for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::marker::Send for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl core::marker::Unpin for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl !core::panic::unwind_safe::RefUnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +impl core::panic::unwind_safe::UnwindSafe for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where K: core::panic::unwind_safe::RefUnwindSafe, V: core::panic::unwind_safe::RefUnwindSafe +impl core::convert::Into for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::From +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::into(self) -> U +impl core::convert::TryFrom for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::Into +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMap::Error = core::convert::Infallible +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::try_from(value: U) -> core::result::Result>::Error> +impl core::convert::TryInto for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where U: core::convert::TryFrom +pub type aya_ebpf::btf_maps::hash_map::PerCpuHashMap::Error = >::Error +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::try_into(self) -> core::result::Result>::Error> +impl core::any::Any for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: 'static + ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::type_id(&self) -> core::any::TypeId +impl core::borrow::Borrow for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::borrow(&self) -> &T +impl core::borrow::BorrowMut for aya_ebpf::btf_maps::hash_map::PerCpuHashMap where T: ?core::marker::Sized +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::borrow_mut(&mut self) -> &mut T +impl core::convert::From for aya_ebpf::btf_maps::hash_map::PerCpuHashMap +pub fn aya_ebpf::btf_maps::hash_map::PerCpuHashMap::from(t: T) -> T #[repr(transparent)] pub struct aya_ebpf::btf_maps::SkStorage(_) impl aya_ebpf::btf_maps::sk_storage::SkStorage pub unsafe fn aya_ebpf::btf_maps::sk_storage::SkStorage::delete(&self, sk: *mut aya_ebpf_bindings::x86_64::bindings::bpf_sock) -> core::result::Result<(), aya_ebpf_cty::od::c_long>