Skip to main content

CgroupArray

Struct CgroupArray 

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

An array of cgroups.

eBPF programs can test whether a packet or the current task belongs to a cgroup by calling bpf_skb_under_cgroup or bpf_current_task_under_cgroup against this map. You populate it from userspace with the file descriptors of cgroup directories.

§Minimum kernel version

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

§Examples

use aya::maps::CgroupArray;

let mut array = CgroupArray::try_from(bpf.map_mut("CGROUPS").unwrap())?;
// cgroup_fd is the RawFd of an open cgroup directory.
array.set(0, cgroup_fd, 0);

Implementations§

Source§

impl<T: Borrow<MapData>> CgroupArray<T>

Source

pub fn len(&self) -> u32

Returns the number of elements in the array.

This corresponds to the value of bpf_map_def::max_entries on the eBPF side.

Source§

impl<T: BorrowMut<MapData>> CgroupArray<T>

Source

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

Stores a cgroup file descriptor at the given index.

§Errors

Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError if bpf_map_update_elem fails.

Source

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

Un-sets the cgroup at the given index.

§Errors

Returns MapError::OutOfBounds if index is out of bounds, MapError::SyscallError if bpf_map_delete_elem fails.

Source§

impl<T: Borrow<MapData>> CgroupArray<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 CgroupArray<&'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 CgroupArray<&'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 CgroupArray<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 CgroupArray<T>
where T: Freeze,

§

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

§

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

§

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

§

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

§

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

§

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