aya: ProgramArray: tweak docs

pull/1/head
Alessandro Decina 3 years ago
parent 2cda5dbbe7
commit 4bde0c54bd

@ -16,30 +16,31 @@ use crate::{
/// An array of eBPF program file descriptors used as a jump table. /// An array of eBPF program file descriptors used as a jump table.
/// ///
/// eBPF programs can jump to other programs calling `bpf_tail_call(prog_array, index)`. You can /// eBPF programs can jump to other programs calling `bpf_tail_call(ctx,
/// use [`ProgramArray`] to configure which programs correspond to which jump indexes. /// prog_array, index)`. You can use [`ProgramArray`] to configure which
/// programs correspond to which jump indexes.
/// ///
/// # Example /// # Example
/// ```no_run /// ```no_run
/// # let bpf = aya::Bpf::load(&[], None)?; /// # let bpf = aya::Bpf::load(&[], None)?;
/// use aya::maps::ProgramArray; /// use aya::maps::ProgramArray;
/// use aya::programs::KProbe; /// use aya::programs::CgroupSkb;
/// use std::convert::{TryFrom, TryInto}; /// use std::convert::{TryFrom, TryInto};
/// ///
/// let mut prog_array = ProgramArray::try_from(bpf.map_mut("JUMP_TABLE")?)?; /// let mut prog_array = ProgramArray::try_from(bpf.map_mut("JUMP_TABLE")?)?;
/// let prog_0: &KProbe = bpf.program("example_prog_0")?.try_into()?; /// let prog_0: &CgroupSkb = bpf.program("example_prog_0")?.try_into()?;
/// let prog_1: &KProbe = bpf.program("example_prog_1")?.try_into()?; /// let prog_1: &CgroupSkb = bpf.program("example_prog_1")?.try_into()?;
/// let prog_2: &KProbe = bpf.program("example_prog_2")?.try_into()?; /// let prog_2: &CgroupSkb = bpf.program("example_prog_2")?.try_into()?;
/// ///
/// let flags = 0; /// let flags = 0;
/// ///
/// // bpf_tail_call(JUMP_TABLE, 0) will jump to prog_0 /// // bpf_tail_call(ctx, JUMP_TABLE, 0) will jump to prog_0
/// prog_array.set(0, prog_0, flags); /// prog_array.set(0, prog_0, flags);
/// ///
/// // bpf_tail_call(JUMP_TABLE, 1) will jump to prog_1 /// // bpf_tail_call(ctx, JUMP_TABLE, 1) will jump to prog_1
/// prog_array.set(1, prog_1, flags); /// prog_array.set(1, prog_1, flags);
/// ///
/// // bpf_tail_call(JUMP_TABLE, 2) will jump to prog_2 /// // bpf_tail_call(ctx, JUMP_TABLE, 2) will jump to prog_2
/// prog_array.set(2, prog_2, flags); /// prog_array.set(2, prog_2, flags);
/// # Ok::<(), aya::BpfError>(()) /// # Ok::<(), aya::BpfError>(())
/// ``` /// ```

Loading…
Cancel
Save