#bpf #libbpf #async

libbpf-async

library for writing BPF programs in Async Rust, complementary for libbpf-rs

2 unstable releases

0.2.0 Jan 30, 2024
0.1.0 Nov 5, 2021

#765 in Unix APIs

Download history 1/week @ 2023-11-06 1/week @ 2023-11-13 2/week @ 2023-11-20 6/week @ 2023-11-27 1/week @ 2023-12-04 1/week @ 2023-12-11 2/week @ 2023-12-25 1/week @ 2024-01-15 2/week @ 2024-01-22 32/week @ 2024-01-29 3/week @ 2024-02-05 18/week @ 2024-02-12 58/week @ 2024-02-19

111 downloads per month

LGPL-2.1 OR BSD-2-Clause

8KB
126 lines

libbpf-async

A library for writing BPF programs in Async Rust, complementary for libbpf-rs, Rust wrapper for libbpf.

Currently, this provides Async-friendly APIs for BPF ring buffer.

To use in your project, add into your Cargo.toml:

[dependencies]
libbpf-async = "0.1"

Example

#[tokio::main]
async fn main() {
    let mut builder = TracerSkelBuilder::default();
    let mut skel = builder.open().unwrap().load().unwrap();

    let mut rb = libbpf_async::RingBuffer::new(skel.obj.map_mut("ringbuf").unwrap());
    loop {
        let mut buf = [0; 128];
        let n = rb.read(&mut buf).await.unwrap();
        // do something useful with the buffer
    }
}

A working example code can be found here.

License

This work is dual-licensed under BSD 2-clause license and GNU LGPL v2.1 license. You can choose between one of them if you use this work.

Dependencies

~14–22MB
~317K SLoC