dippynark
dippynark

Reputation: 3003

How can I get the bpf_helpers.h header file for my Linux kernel?

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.

Upvotes: 14

Views: 15274

Answers (2)

pchaigno
pchaigno

Reputation: 13113

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.

Upvotes: 15

user2233706
user2233706

Reputation: 7207

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

Upvotes: 3

Related Questions