bpf_helpers.h file not found in WSL (Windows Sub-system for Linux)

68 Views Asked by At

I have been trying to run some ebpf programs in WSL with ubuntu22.04. But I got the below error while running a XDP program.

root@hsekar-T14:/home/hsekar/pgms/ebpf# python3 4_xdp_demo.py
...
In file included from /virtual/main.c:1:
include/linux/bpf.h:211:35: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_timer'
                memset(dst + map->timer_off, 0, sizeof(struct bpf_timer));
                                                ^     ~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:211:49: note: forward declaration of 'struct bpf_timer'
                memset(dst + map->timer_off, 0, sizeof(struct bpf_timer));
                                                              ^
include/linux/bpf.h:225:10: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_timer'
                t_sz = sizeof(struct bpf_timer);
                       ^     ~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:225:24: note: forward declaration of 'struct bpf_timer'
                t_sz = sizeof(struct bpf_timer);
                                     ^
include/linux/bpf.h:539:26: error: use of undeclared identifier 'BPF_PSEUDO_FUNC'
               insn->src_reg == BPF_PSEUDO_FUNC;
                                ^
/virtual/main.c:2:10: fatal error: 'bpf/bpf_helpers.h' file not found
#include <bpf/bpf_helpers.h>
         ^~~~~~~~~~~~~~~~~~~
3 warnings and 4 errors generated.
Traceback (most recent call last):
  File "/home/hsekar/pgms/ebpf/4_xdp_demo.py", line 7, in <module>
    b = BPF(src_file="4_xdp_demo.c")
  File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 364, in __init__
    raise Exception("Failed to compile BPF module %s" % (src_file or "<text>"))
Exception: Failed to compile BPF module b'4_xdp_demo.c'
root@hsekar-T14:/home/hsekar/pgms/ebpf#

I found this stack-overflow link that states to install libbpf-dev package.

I did. But still seeing the same error.

root@hsekar-T14:/home/hsekar/pgms/ebpf# sudo apt-get install libbpf-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
libbpf-dev is already the newest version (1:0.5.0-1ubuntu22.04.1).
0 upgraded, 0 newly installed, 0 to remove and 19 not upgraded.
root@hsekar-T14:/home/hsekar/pgms/ebpf#
root@hsekar-T14:/home/hsekar/pgms/ebpf# sudo apt-file list libbpf-dev | grep bpf_helpers.h
libbpf-dev: /usr/include/bpf/bpf_helpers.h
root@hsekar-T14:/home/hsekar/pgms/ebpf#

WSL OS information

root@hsekar-T14:/home/hsekar/pgms/ebpf# uname -r
5.15.133.1-microsoft-standard-WSL2
root@hsekar-T14:/home/hsekar/pgms/ebpf# cat /etc/os-release
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=jammy
root@hsekar-T14:/home/hsekar/pgms/ebpf#
0

There are 0 best solutions below