19 releases (5 stable)

1.3.0 Dec 7, 2020
1.2.0 Oct 28, 2020
1.1.0 Aug 22, 2020
1.0.0 Apr 1, 2020
0.9.6 Nov 9, 2019

#23 in Unix APIs

Download history 70/week @ 2021-01-16 178/week @ 2021-01-23 163/week @ 2021-01-30 420/week @ 2021-02-06 80/week @ 2021-02-13 44/week @ 2021-02-20 25/week @ 2021-02-27 17/week @ 2021-03-06 41/week @ 2021-03-13 103/week @ 2021-03-20 56/week @ 2021-03-27 96/week @ 2021-04-03 75/week @ 2021-04-10 83/week @ 2021-04-17 52/week @ 2021-04-24 44/week @ 2021-05-01

799 downloads per month
Used in redbpf-macros

MIT/Apache

57KB
1K SLoC

RedBPF

LICENSE CircleCI element

A Rust eBPF toolchain.

Overview

The redbpf project is a collection of tools and libraries to build eBPF programs using Rust. It includes:

  • redbpf - a user space library that can be used to load eBPF programs

  • redbpf-probes - an idiomatic Rust API to write eBPF programs that can be loaded by the linux kernel

  • redbpf-macros - companion crate to redbpf-probes which provides convenient procedural macros useful when writing eBPF programs

  • cargo-bpf - a cargo subcommand for creating, building and debugging eBPF programs

Requirements

In order to use redbpf you need LLVM 11 and the headers for the kernel you want to target.

Linux kernel

The minimum kernel version supported is 4.19. Kernel headers are discovered automatically, or you can use the KERNEL_SOURCE environment variable to point to a specific location. Building against a linux source tree is supported as long as you run make prepare first.

Installing dependencies on Debian based distributions

On Debian, Ubuntu and derivatives you can install the dependencies running:

sudo apt-get -y install build-essential zlib1g-dev \
		llvm-11-dev libclang-11-dev linux-headers-$(uname -r)

If your distribution doesn't have LLVM 11, you can add the official LLVM APT repository to your sources.list.

Installing dependencies on RPM based distributions

First ensure that your distro includes LLVM 11:

yum info llvm-devel | grep Version
Version      : 11.0.0

If you don't have vesion 11, you can get it from the Fedora 33 repository.

Then install the dependencies running:

yum install clang llvm-devel zlib-devel kernel-devel

Getting started

The easiest way to get started is using cargo-bpf, see the documentation for more info.

redbpf-tools is a cargo-bpf generated crate that includes simple examples you can use to understand how to structure your programs.

Finally the ingraind project includes more concrete examples of redbpf programs.

Building from source

After cloning the repository run:

git submodule sync
git submodule update --init

Install the dependencies as documented above, then run cargo build as usual.

License

This repository contains code from other software in the following directories, licensed under their own particular licenses:

  • bpf-sys/libelf/*: GPL2 + LGPL3
  • bpf-sys/bcc/*: Apache2, public domain
  • include/bpf_helpers.h LGPL2 + BSD-2
  • include/bpf_helper_defs.h: LGPL2 + BSD-2
  • bpf-sys/libbpf: LGPL2 + BSD-2

Where '+' means they are dual licensed.

RedBPF and its components, unless otherwise stated, are licensed under either of

at your option.

Contribution

This project is for everyone. We ask that our users and contributors take a few minutes to review our code of conduct.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

For further advice on getting started, please consult the Contributor's Guide. Please note that all contributions MUST contain a Developer Certificate of Origin sign-off line.

Dependencies

~0.5–2.6MB
~56K SLoC