Skip to main content

DevMapHash

Struct DevMapHash 

Source
pub struct DevMapHash<T> { /* private fields */ }
Expand description

An hashmap of network devices.

XDP programs can use this map to redirect to other network devices.

§Minimum kernel version

The minimum kernel version required to use this feature is 5.4.

§Examples

use aya::maps::xdp::DevMapHash;

let mut devmap = DevMapHash::try_from(bpf.map_mut("IFACES").unwrap())?;
// Lookups with key 2 will redirect packets to interface with index 3 (e.g. eth1)
devmap.insert(2, 3, None, 0);

§See also

Kernel documentation: https://docs.kernel.org/next/bpf/map_devmap.html

Implementations§

Source§

impl<T: Borrow<MapData>> DevMapHash<T>

Source

pub fn get(&self, key: u32, flags: u64) -> Result<DevMapValue, MapError>

Returns the target interface index and optional program for a given key.

§Errors

Returns MapError::SyscallError if bpf_map_lookup_elem fails.

Source

pub fn iter(&self) -> MapIter<'_, u32, DevMapValue, Self>

An iterator over the elements of the devmap in arbitrary order.

Source

pub fn keys(&self) -> MapKeys<'_, u32>

An iterator visiting all keys in arbitrary order.

Source§

impl<T: BorrowMut<MapData>> DevMapHash<T>

Source

pub fn insert( &mut self, key: u32, target_if_index: u32, program: Option<&ProgramFd>, flags: u64, ) -> Result<(), XdpMapError>

Inserts an ifindex and optionally a chained program in the map.

When redirecting using key, packets will be transmitted by the interface with ifindex.

Starting from Linux kernel 5.8, another XDP program can be passed in that will be run before actual transmission. It can be used to modify the packet before transmission with NIC specific data (MAC address update, checksum computations, etc) or other purposes.

The chained program must be loaded with the BPF_XDP_DEVMAP attach type. When using aya-ebpf, that means XDP programs that specify the map = "devmap" argument. See the kernel-space aya_ebpf::xdp for more information.

§Errors

Returns MapError::SyscallError if bpf_map_update_elem fails, MapError::ProgIdNotSupported if the kernel does not support chained programs and one is provided.

Source

pub fn remove(&mut self, key: u32) -> Result<(), MapError>

Removes a value from the map.

§Errors

Returns MapError::SyscallError if bpf_map_delete_elem fails.

Source§

impl<T: Borrow<MapData>> DevMapHash<T>

Source

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

Pins the map to a BPF filesystem.

When a map is pinned it will remain loaded until the corresponding file is deleted. All parent directories in the given path must already exist.

Trait Implementations§

Source§

impl<'a, T: Borrow<MapData>> IntoIterator for &'a DevMapHash<T>

Source§

type Item = Result<(u32, DevMapValue), MapError>

The type of the elements being iterated over.
Source§

type IntoIter = MapIter<'a, u32, DevMapValue, DevMapHash<T>>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a> TryFrom<&'a Map> for DevMapHash<&'a MapData>

Source§

type Error = MapError

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

fn try_from(map: &'a Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<'a> TryFrom<&'a mut Map> for DevMapHash<&'a mut MapData>

Source§

type Error = MapError

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

fn try_from(map: &'a mut Map) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<Map> for DevMapHash<MapData>

Source§

type Error = MapError

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

fn try_from(map: Map) -> Result<Self, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T> Freeze for DevMapHash<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for DevMapHash<T>
where T: RefUnwindSafe,

§

impl<T> Send for DevMapHash<T>
where T: Send,

§

impl<T> Sync for DevMapHash<T>
where T: Sync,

§

impl<T> Unpin for DevMapHash<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for DevMapHash<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for DevMapHash<T>
where T: UnwindSafe,

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.
Source§

impl<T> FromMapData for T
where T: FromMapData,

Source§

impl<T> InnerMap for T
where T: InnerMap,