[][src]Crate redbpf

Rust API to load BPF programs.

Overview

The redbpf crate provides an idiomatic Rust API to load and interact with BPF programs. It is part of the larger redbpf project.

BPF programs used with redbpf are typically created and built with cargo-bpf, and use the redbpf-probes and redbpf-macros APIs.

For full featured examples on how to use redbpf see https://github.com/redsift/redbpf/tree/master/redbpf-tools.

Example

The following example loads all the kprobes defined in the file iotop.elf.

use redbpf::load::Loader;

let mut loader = Loader::load_file("iotop.elf").expect("error loading probe");

// attach all the kprobes defined in iotop.elf
for kprobe in loader.kprobes_mut() {
    kprobe
        .attach_kprobe(&kprobe.name(), 0)
        .expect(&format!("error attaching program {}", kprobe.name()));
}

Modules

cpus
sys
uname
xdp

Structs

BpfStackFrames
HashMap
KProbe

Type to work with kprobes or kretprobes.

LostSamples
Map
MapIter
Module
PerfMap
ProgramArray

Program array map.

Rel
Sample
SocketFilter

Type to work with socket filters.

StackTrace
TracePoint
UProbe

Type to work with uprobes or uretprobes.

XDP

Type to work with XDP programs.

Enums

Error
Event
Program

A BPF program defined in a Module.

Type Definitions

DataPtr
MutDataPtr
Result