tomwassing / xdp-test-example

Example of testing a eBPF/XDP program in pure C
MIT License
4 stars 1 forks source link

bpftool not found for kernel 6.5.0-26 #1

Open lneto opened 5 months ago

lneto commented 5 months ago

Firstly, thank you very much for this example! I'm opening this issue because it might be useful for others. I tried to run it on Ubuntu 22.04 with kernel 6.5 and I needed to update linux-tools as described below:

$ uname -a
Linux ubuntu 6.5.0-26-generic #26~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Tue Mar 12 19:16:50 UTC 2 aarch64 aarch64 aarch64 GNU/Linux
$ make
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
WARNING: bpftool not found for kernel 6.5.0-26

  You may need to install the following packages for this specific kernel:
    linux-tools-6.5.0-26-generic
    linux-cloud-tools-6.5.0-26-generic

  You may also want to install one of the following packages to keep up to date:
    linux-tools-generic
    linux-cloud-tools-generic
make: *** [Makefile:4: vmlinux] Error 2
$ sudo apt-get install linux-tools-6.5.0-26-generic
$ make
bpftool btf dump file /sys/kernel/btf/vmlinux format c > vmlinux.h
clang -target bpf -Wall -O2 -c example.bpf.c
bpftool gen skeleton example.bpf.o > example.skel.h
gcc -Wall -o test test.c -lbpf
$ sudo ./test
[success] drop ICMP packets
[success] pass non-ICMP packets
pvvm commented 3 months ago

Would you know the version of bpftool that this command installs? Because I'm currently facing an error where bpf_prog_test_run_opts always returns error 524 and I also have kernel 6.5.0. So, I wonder if it might be related. The current version of bpftool I have installed is 7.2

lneto commented 3 months ago

it will depend on the kernel version..

ubuntu@ubuntu:~/lunatik$ dpkg-query -L linux-tools-$(uname -r)
/.
/usr
/usr/lib
/usr/lib/linux-tools
/usr/lib/linux-tools/6.5.0-41-generic
/usr/share
/usr/share/doc
/usr/share/doc/linux-tools-6.5.0-41-generic
/usr/share/doc/linux-tools-6.5.0-41-generic/copyright
/usr/lib/linux-tools/6.5.0-41-generic/bpftool
/usr/lib/linux-tools/6.5.0-41-generic/cpupower
/usr/lib/linux-tools/6.5.0-41-generic/libperf-jvmti.so
/usr/lib/linux-tools/6.5.0-41-generic/perf
/usr/lib/linux-tools/6.5.0-41-generic/usbip
/usr/lib/linux-tools/6.5.0-41-generic/usbipd
/usr/share/doc/linux-tools-6.5.0-41-generic/changelog.Debian.gz
ubuntu@ubuntu:~/lunatik$ /usr/lib/linux-tools/6.5.0-41-generic/bpftool version
bpftool v7.3.0
using libbpf v1.3
features:

try sudo apt install linux-tools-$(uname -r); I've created a PR for this.

you might be also interested in this small article I wrote ;-).

pvvm commented 3 months ago

I guess bpftool version isn't what is causing my problem. But thanks for the help anyway!

pvvm commented 3 months ago

Actually, could you please also tell me the version of clang and llc you are using? Because I've just tested executing a similar program on Kernel 5.11.0 and with clang-11, and it is working well. While in the other machine I have 6.5.0 and clang-16.

lneto commented 2 months ago
ubuntu@ubuntu:~/lunatik$ clang --version
Ubuntu clang version 14.0.0-1ubuntu1.1
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
ubuntu@ubuntu:~/lunatik$ llc --version
Ubuntu LLVM version 14.0.0

  Optimized build.
  Default target: aarch64-unknown-linux-gnu
  Host CPU: (unknown)
lneto commented 2 months ago

@pvvm did you check your libebpf version? I would recommend you to get it from github, as I pointed in this article:

$ git clone -b v1.4.2 --depth 1 --recurse-submodules https://github.com/xdp-project/xdp-tools.git
$ cd xdp-tools/lib/libbpf/src
$ make
$ sudo DESTDIR=/ make install
$ cd ../../../
$ make libxdp
$ cd xdp-loader
$ make
$ sudo make install
$ cd ../../
pvvm commented 2 months ago

Thank you very much for your help! And the article looks pretty good! But I sorted out a way to solve my problem in this post I made

lneto commented 2 months ago

btw, even that it doesn't see related.. just for the records.. I've had a trouble with SEC("xdp_drop_icmp") and needed to change it to SEC("xdp") to make it work..