You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aya/aya/src/maps/hash_map/mod.rs

43 lines
938 B
Rust

//! Hash map types.
use crate::{
maps::MapError,
sys::{bpf_map_delete_elem, bpf_map_update_elem},
Pod,
};
#[allow(clippy::module_inception)]
mod hash_map;
mod per_cpu_hash_map;
pub use hash_map::*;
pub use per_cpu_hash_map::*;
use super::MapData;
pub(crate) fn insert<K: Pod, V: Pod>(
map: &mut MapData,
key: &K,
value: &V,
flags: u64,
) -> Result<(), MapError> {
let fd = map.fd_or_err()?;
bpf_map_update_elem(fd, Some(key), value, flags).map_err(|(_, io_error)| {
MapError::SyscallError {
call: "bpf_map_update_elem",
io_error,
}
})?;
Ok(())
}
pub(crate) fn remove<K: Pod>(map: &mut MapData, key: &K) -> Result<(), MapError> {
let fd = map.fd_or_err()?;
bpf_map_delete_elem(fd, key)
.map(|_| ())
.map_err(|(_, io_error)| MapError::SyscallError {
call: "bpf_map_delete_elem",
io_error,
})
}