14

I am developing an eBPF program on an Ubuntu machine:

$ uname -a
Linux ubuntu-bionic 4.18.0-16-generic #17~18.04.1-Ubuntu SMP Tue Feb 12 13:35:51 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

To do this I need both bpf.h for a number of definitions as well bpf_helpers.h for helper function definitions. I installed a new kernel with the headers:

apt-get update -y
apt-get install -y linux-image-4.18.0-16-generic linux-headers-4.18.0-16-generic

The headers include bpf.h:

$ find /usr/src/linux-headers-4.18.0-16 -name bpf.h
/usr/src/linux-headers-4.18.0-16/include/uapi/linux/bpf.h
/usr/src/linux-headers-4.18.0-16/include/linux/bpf.h

but not bpf_helpers.h:

$ find /usr/src/linux-headers-4.18.0-16 -name bpf_helpers.h

How can I get this file for my kernel and why is it not included with the distribution headers?

I could checkout a particular version of the Linux kernel or get the file from master but the distribution could have potentially made changes to upstream which makes me uncomfortable doing this.

1
  • 2
    Had you consider looking within linux-source Ubuntu' package, i.e. your target OS kernel source package? Commented Mar 30, 2019 at 23:40

2 Answers 2

18

bpf_helpers.h is not distributed with the kernel headers, but with libbpf.

You can install libbpf on Ubuntu with:

apt install libbpf-dev

Or you can install it from the sources at https://github.com/libbpf/libbpf.

Sign up to request clarification or add additional context in comments.

3 Comments

How could you tell that it is not distributed with the kernel headers? Your link just shows the file is in the particular location.
If it was distributed with the kernel headers, it would be in github.com/torvalds/linux/tree/master/include/uapi/linux, like bpf.h, bpf_common.h and btf.h.
After installation, you can include the bpf_helpers header file, for example, with #include <bpf/bpf_helpers.h> for C
4

On Ubuntu I installed libbpf-dev to get that header:

sudo apt-get install libbpf-dev
$ apt-file list libbpf-dev | grep bpf_helpers.h
libbpf-dev: /usr/include/bpf/bpf_helpers.h

2 Comments

This basically just duplicates the accepted answer.
Look at the history of the accepted answer. I came up with this answer first. That answer originally just had "bpf_helpers.h is not distributed with the kernel headers..." The accepted answer just copied my answer afterwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.