pub struct ProgramArray<T: Deref<Target = Map>> { /* 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, ProgramFd};
use std::convert::{TryFrom, TryInto};

let mut prog_array = ProgramArray::try_from(bpf.map_mut("JUMP_TABLE")?)?;
let prog_0: &CgroupSkb = bpf.program("example_prog_0").unwrap().try_into()?;
let prog_1: &CgroupSkb = bpf.program("example_prog_1").unwrap().try_into()?;
let prog_2: &CgroupSkb = bpf.program("example_prog_2").unwrap().try_into()?;

let flags = 0;

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

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

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

Implementations

An iterator over the indices of the array that point to a program. The iterator item type is Result<u32, 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.

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.

Trait Implementations

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.