libbpf_rs

Struct MapHandle

Source
pub struct MapHandle { /* private fields */ }
Expand description

A handle to a map. Handles can be duplicated and dropped.

While possible to created directly, in many cases it is useful to create such a handle from an existing Map:

let map: &Map = get_map();
let map_handle = MapHandle::try_from(map).unwrap();

Some methods require working with raw bytes. You may find libraries such as plain helpful.

Implementations§

Source§

impl MapHandle

Source

pub fn create<T: AsRef<OsStr>>( map_type: MapType, name: Option<T>, key_size: u32, value_size: u32, max_entries: u32, opts: &bpf_map_create_opts, ) -> Result<Self>

Create a bpf map whose data is not managed by libbpf.

Source

pub fn from_pinned_path<P: AsRef<Path>>(path: P) -> Result<Self>

Open a previously pinned map from its path.

§Panics

If the path contains null bytes.

Source

pub fn from_map_id(id: u32) -> Result<Self>

Open a loaded map from its map id.

Source

pub fn freeze(&self) -> Result<()>

Freeze the map as read-only from user space.

Entries from a frozen map can no longer be updated or deleted with the bpf() system call. This operation is not reversible, and the map remains immutable from user space until its destruction. However, read and write permissions for BPF programs to the map remain unchanged.

Source

pub fn pin<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Pin this map to bpffs.

Source

pub fn unpin<P: AsRef<Path>>(&mut self, path: P) -> Result<()>

Unpin this map from bpffs.

Trait Implementations§

Source§

impl AsFd for MapHandle

Source§

fn as_fd(&self) -> BorrowedFd<'_>

Borrows the file descriptor. Read more
Source§

impl Debug for MapHandle

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl MapCore for MapHandle

Source§

fn name(&self) -> &OsStr

Retrieve the map’s name.
Source§

fn map_type(&self) -> MapType

Retrieve type of the map.
Source§

fn key_size(&self) -> u32

Retrieve the size of the map’s keys.
Source§

fn value_size(&self) -> u32

Retrieve the size of the map’s values.
Source§

fn info(&self) -> Result<MapInfo>

Fetch extra map information
Source§

fn keys(&self) -> MapKeyIter<'_>

Returns an iterator over keys in this map Read more
Source§

fn lookup(&self, key: &[u8], flags: MapFlags) -> Result<Option<Vec<u8>>>

Returns map value as Vec of u8. Read more
Source§

fn lookup_bloom_filter(&self, value: &[u8]) -> Result<bool>

Returns if the given value is likely present in bloom_filter as bool. Read more
Source§

fn lookup_percpu( &self, key: &[u8], flags: MapFlags, ) -> Result<Option<Vec<Vec<u8>>>>

Returns one value per cpu as Vec of Vec of u8 for per per-cpu maps. Read more
Source§

fn delete(&self, key: &[u8]) -> Result<()>

Deletes an element from the map. Read more
Source§

fn delete_batch( &self, keys: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()>

Deletes many elements in batch mode from the map. Read more
Source§

fn lookup_and_delete(&self, key: &[u8]) -> Result<Option<Vec<u8>>>

Same as Self::lookup() except this also deletes the key from the map. Read more
Source§

fn update(&self, key: &[u8], value: &[u8], flags: MapFlags) -> Result<()>

Update an element. Read more
Source§

fn update_batch( &self, keys: &[u8], values: &[u8], count: u32, elem_flags: MapFlags, flags: MapFlags, ) -> Result<()>

Updates many elements in batch mode in the map Read more
Source§

fn update_percpu( &self, key: &[u8], values: &[Vec<u8>], flags: MapFlags, ) -> Result<()>

Update an element in an per-cpu map with one value per cpu. Read more
Source§

impl TryFrom<&MapHandle> for MapHandle

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(other: &MapHandle) -> Result<Self>

Performs the conversion.
Source§

impl<T> TryFrom<&MapImpl<'_, T>> for MapHandle
where T: Debug,

Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(other: &MapImpl<'_, T>) -> Result<Self>

Performs the conversion.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.