bpf-script

Crates.iobpf-script
lib.rsbpf-script
version0.5.4
sourcesrc
created_at2022-10-25 00:48:21.845942
updated_at2022-11-05 00:33:22.772455
descriptionA small scripting language and compiler for creating eBPF programs at runtime.
homepagehttps://github.com/arcjustin/bpf-script
repositoryhttps://github.com/arcjustin/bpf-script
max_upload_size
id696383
size111,613
(arcjustin)

documentation

README

bpf-script

Build Status crates.io mio Lines of Code

A small scripting language and compiler for creating eBPF programs at runtime without bcc or llvm.

The intent behind building this crate was to primarily learn more about BPF internals and, secondly, to provide a dependency-free way of writing BPF programs, using a higher-level language, that could be compiled at run-time without the need to shell out to a compiler and load/patch BPF from an ELF file.

The syntax for the language resembles Rust with a lot of features stripped out. For example, a simple u/k probe program that calls a helper and returns the value looks like so:

fn(regs: &bpf_user_pt_regs_t)
    a = get_current_uid_gid()
    map_push_elem(queue, &a, 0)
    return a

This crate is made to work together with the following crates but they are not required:

  • btf A BTF parsing library.
  • bpf-script-derive Allows you to seamlessly share types between Rust and this compiler.
  • bpf-api Creating programs, probes, maps, etc.

Usage

For usage examples, see code located in examples/ :

Examples Description
print-instructions Compiles a short program and prints the generated instructions

TODO

  • Add control flow.
  • Write more thorough tests.

License

Commit count: 58

cargo fmt