SockMap

Struct SockMap 

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

An array of TCP or UDP sockets.

A SockMap is used to store TCP or UDP sockets. eBPF programs can then be attached to the map to inspect, filter or redirect network buffers on those sockets.

A SockMap can also be used to redirect packets to sockets contained by the map using bpf_redirect_map(), bpf_sk_redirect_map() etc.

§Minimum kernel version

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

§Examples

use aya::maps::SockMap;
use aya::programs::SkSkb;

let intercept_ingress = SockMap::try_from(bpf.map("INTERCEPT_INGRESS").unwrap())?;
let map_fd = intercept_ingress.fd().try_clone()?;

let prog: &mut SkSkb = bpf.program_mut("intercept_ingress_packet").unwrap().try_into()?;
prog.load()?;
prog.attach(&map_fd)?;

Implementations§

Source§

impl<T: Borrow<MapData>> SockMap<T>

Source

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

An iterator over the indices of the array that point to a program. The iterator item type is Result<u32, MapError>.

Source

pub fn fd(&self) -> &SockMapFd

Returns the map’s file descriptor.

The returned file descriptor can be used to attach programs that work with socket maps, like SkMsg and SkSkb.

Source§

impl<T: BorrowMut<MapData>> SockMap<T>

Source

pub fn set<I: AsRawFd>( &mut self, index: u32, socket: &I, flags: u64, ) -> Result<(), MapError>

Stores a socket into the map.

Source

pub fn clear_index(&mut self, index: &u32) -> Result<(), MapError>

Removes the socket stored at index from the map.

Source§

impl<T: Borrow<MapData>> SockMap<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> TryFrom<&'a Map> for SockMap<&'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 SockMap<&'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 SockMap<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 SockMap<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for SockMap<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.