10

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.

dippynark
  • 2,743
  • 20
  • 58
  • 2
    Had you consider looking within linux-source Ubuntu' package, i.e. your target OS kernel source package? – agg3l Mar 30 '19 at 23:40

2 Answers2

9

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.

pchaigno
  • 11,313
  • 2
  • 29
  • 54
  • How could you tell that it is not distributed with the kernel headers? Your link just shows the file is in the particular location. – user2984297 Jan 29 '22 at 06:50
  • If it was distributed with the kernel headers, it would be in https://github.com/torvalds/linux/tree/master/include/uapi/linux, like `bpf.h`, `bpf_common.h` and `btf.h`. – pchaigno Jan 29 '22 at 10:32
  • 1
    After installation, you can include the bpf_helpers header file, for example, with `#include ` for C – Annemie Mar 17 '23 at 06:42
2

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
user2233706
  • 6,148
  • 5
  • 44
  • 86