Struct ProgramArray

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

An array of eBPF program file descriptors used as a jump table.

eBPF programs can jump to other programs calling bpf_tail_call(ctx, prog_array, index). You can use ProgramArray to configure which programs correspond to which jump indexes.

§Minimum kernel version

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

§Examples

use aya::maps::ProgramArray;
use aya::programs::CgroupSkb;

let mut prog_array = ProgramArray::try_from(bpf.take_map("JUMP_TABLE").unwrap())?;
let prog_0: &CgroupSkb = bpf.program("example_prog_0").unwrap().try_into()?;
let prog_0_fd =  prog_0.fd().unwrap();
let prog_1: &CgroupSkb = bpf.program("example_prog_1").unwrap().try_into()?;
let prog_1_fd = prog_1.fd().unwrap();
let prog_2: &CgroupSkb = bpf.program("example_prog_2").unwrap().try_into()?;
let prog_2_fd = prog_2.fd().unwrap();
let flags = 0;

// bpf_tail_call(ctx, JUMP_TABLE, 0) will jump to prog_0
prog_array.set(0, &prog_0_fd, flags);

// bpf_tail_call(ctx, JUMP_TABLE, 1) will jump to prog_1
prog_array.set(1, &prog_1_fd, flags);

// bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2
prog_array.set(2, &prog_2_fd, flags);

Implementations§

Source§

impl<T: Borrow<MapData>> ProgramArray<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§

impl<T: BorrowMut<MapData>> ProgramArray<T>

Source

pub fn set( &mut self, index: u32, program: &ProgramFd, flags: u64, ) -> Result<(), MapError>

Sets the target program file descriptor for the given index in the jump table.

When an eBPF program calls bpf_tail_call(ctx, prog_array, index), control flow will jump to program.

Source

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

Clears the value at index in the jump table.

Calling bpf_tail_call(ctx, prog_array, index) on an index that has been cleared returns an error.

Source§

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

§

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

§

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

§

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

§

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

§

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