Skip to content

Setup and Building bpfd

This section describes how to build bpfd. If this is the first time building bpfd, jump to the Development Environment Setup section for help installing the tooling.

There is also an option to run images from a given release as opposed to building locally. Jump to the Run bpfd From Release Image section for installing from a fixed release.

Kernel Versions

eBPF is still a relatively new technology and being actively developed. To take advantage of this constantly evolving technology, it is best to use the newest kernel version possible. If bpfd needs to be run on an older kernel, this section describes some of the kernel features bpfd relies on to work and which kernel the feature was first introduced.

Major kernel features leveraged by bpfd:

  • Program Extensions: Program Extensions allows bpfd to load multiple XDP or TC eBPF programs on an interface, which is not natively supported in the kernel. A dispatcher program is loaded as the one program on a given interface, and the user's XDP or TC programs are loaded as extensions to the dispatcher program. Introduced in Kernel 5.6.
  • Pinning: Pinning allows the eBPF program to remain loaded when the loading process (bpfd) is stopped or restarted. Introduced in Kernel 4.11.
  • BPF Perf Link: Support BPF perf link for tracing programs (Tracepoint, Uprobe and Kprobe) which enables pinning for these program types. Introduced in Kernel 5.15.

Tested kernel versions:

  • Fedora 34: Kernel 5.17.6-100.fc34.x86_64
    • XDP, TC, Tracepoint, Uprobe and Kprobe programs all loaded with bpfd running on localhost and running as systemd service.
  • Fedora 33: Kernel 5.14.18-100.fc33.x86_64
    • XDP and TC programs loaded with bpfd running on localhost and running as systemd service once SELinux was disabled (see https://github.com/fedora-selinux/selinux-policy/pull/806).
    • Tracepoint, Uprobe and Kprobe programs failed to load because they require the BPF Perf Link support.
  • Fedora 32: Kernel 5.11.22-100.fc32.x86_64
    • XDP and TC programs loaded with bpfd running on localhost once SELinux was disabled (see https://github.com/fedora-selinux/selinux-policy/pull/806).
    • bpfd fails to run as a systemd service because of some capabilities issues in the bpfd.service file.
    • Tracepoint, Uprobe and Kprobe programs failed to load because they require the BPF Perf Link support.
  • Fedora 31: Kernel 5.8.18-100.fc31.x86_64
    • bpfd was able to start on localhost, but XDP and TC programs wouldn't load because BPF_LINK_CREATE call was updated in newer kernels.
    • bpfd fails to run as a systemd service because of some capabilities issues in the bpfd.service file.

Clone the bpfd Repo

You can build and run bpfd from anywhere. However, if you plan to make changes to the bpfd operator, it will need to be under your GOPATH because Kubernetes Code-generator does not work outside of GOPATH issue 86753. Assuming your GOPATH is set to the typical $HOME/go, your repo should live in $HOME/go/src/github.com/bpfd-dev/bpfd

mkdir -p $HOME/go/src/github.com/bpfd-dev
cd $HOME/go/src/github.com/bpfd-dev
git clone git@github.com:bpfd-dev/bpfd.git

Building bpfd

To just test with the latest bpfd, containerized image are stored in quay.io/bpfd (see bpfd Container Images). To build with local changes, use the following commands.

If you are building bpfd for the first time OR the eBPF code has changed:

cargo xtask build-ebpf --libbpf-dir /path/to/libbpf

If protobuf files have changed:

cargo xtask build-proto

To build bpfd and bpfctl:

cargo build

Development Environment Setup

To build bpfd, the following packages must be installed.

Install Rust Toolchain

For further detailed instructions, see Rust Stable & Rust Nightly.

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
export PATH="$HOME/.cargo/bin:$PATH"
rustup toolchain install nightly -c rustfmt,clippy,rust-src

Install LLVM

LLVM 11 or later must be installed. Linux package managers should provide a recent enough release.

dnf based OS:

sudo dnf install llvm-devel clang-devel elfutils-libelf-devel

apt based OS:

sudo apt install clang lldb lld libelf-dev gcc-multilib

Install Protobuf Compiler

For further detailed instructions, see protoc.

dnf based OS:

sudo dnf install protobuf-compiler

apt based OS:

sudo apt install protobuf-compiler

Install GO protobuf Compiler Extensions

See Quick Start Guide for gRPC in Go for installation instructions.

Local libbpf

Checkout a local copy of libbpf.

git clone https://github.com/libbpf/libbpf --branch v0.8.0

Install perl

Install perl:

dnf based OS:

sudo dnf install perl

apt based OS:

sudo apt install perl

Install Yaml Formatter

As part of CI, the Yaml files are validated with a Yaml formatter. Optionally, to verify locally, install the YAML Language Support by Red Hat VsCode Extension, or to format in bulk, installprettier.

To install prettier:

npm install -g prettier

Then to flag which files are violating the formatting guide, run:

prettier -l "*.yaml"

And to write changes in place, run:

 prettier -f "*.yaml"