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>
impl<T: Borrow<MapData>> DevMapHash<T>
Sourcepub fn get(&self, key: u32, flags: u64) -> Result<DevMapValue, MapError>
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§impl<T: BorrowMut<MapData>> DevMapHash<T>
impl<T: BorrowMut<MapData>> DevMapHash<T>
Sourcepub fn insert(
&mut self,
key: u32,
target_if_index: u32,
program: Option<&ProgramFd>,
flags: u64,
) -> Result<(), XdpMapError>
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.