[][src]Struct redbpf::Program

pub struct Program {
    pub kind: ProgramKind,
    pub name: String,
    // some fields omitted
}

You can load an eBPF module, and all the programs in it like so:

use redbpf::Module;

let mut module = Module::parse(&vec![]).unwrap();
for prog in module.programs.iter_mut() {
    prog.load(module.version, module.license.clone()).unwrap();
}

Note that during the parsing the ELF file all BPF maps are automatically initialised.

You can attach kprobes like very easily:

use redbpf::Module;
use redbpf::ProgramKind::*;

let code = std::fs::read("bpf.elf").unwrap();
let mut module = Module::parse(&code).unwrap();
for prog in module
    .programs
    .iter_mut()
    .filter(|p| p.kind == Kprobe || p.kind == Kretprobe)
{
    prog.attach_probe().unwrap();
}

XDP and socket filters additionally require an interface to attach to. Note that in case of XDP, the driver needs to support XDP probes, so, for example, network bridges may not work out of the box.

use redbpf::Module;
use redbpf::ProgramKind::*;

let code = std::fs::read("bpf.elf").unwrap();
let mut module = Module::parse(&code).unwrap();
for prog in module
    .programs
    .iter_mut()
    .filter(|p| p.kind == XDP)
{
    prog.attach_xdp("eth0").unwrap();
}

Fields

kind: ProgramKindname: String

Methods

impl Program[src]

pub fn new(kind: &str, name: &str, code: &[u8]) -> Result<Program>[src]

pub fn is_loaded(&self) -> bool[src]

pub fn is_attached(&self) -> bool[src]

pub fn load(&mut self, kernel_version: u32, license: String) -> Result<RawFd>[src]

pub fn attach_probe(&mut self) -> Result<RawFd>[src]

pub fn attach_probe_to_name(&mut self, name: &str) -> Result<RawFd>[src]

pub fn attach_tracepoint(&mut self, category: &str, name: &str) -> Result<RawFd>[src]

pub fn attach_xdp(&mut self, iface: &str) -> Result<()>[src]

pub fn attach_socketfilter(&mut self, iface: &str) -> Result<RawFd>[src]

Auto Trait Implementations

impl Send for Program

impl Sync for Program

impl Unpin for Program

impl UnwindSafe for Program

impl RefUnwindSafe for Program

Blanket Implementations

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]