I have been studying BPF recently, but it is not proceeding because of a very basic problem.
I included linux/bpf.h as described in man bpf(2), but GCC can not find bpf function. This code is just for the test to make sure that GCC can find bpf function.
#include <linux/bpf.h>
int main()
{
bpf(0,(void *)0,0);
return 0;
}
GCC output is this.
$ gcc -o test bpf.c
bpf.c: In function ‘main’:
bpf.c:5:2: warning: implicit declaration of function ‘bpf’ [-Wimplicit-function-declaration]
bpf(0,(void *)0,0);
^~~
/usr/bin/ld: /tmp/cc4tjrUh.o: in function `main':
bpf.c:(.text+0x19): undefined reference to `bpf'
collect2: error: ld returned 1 exit status
I'm using Archlinux and linux kernel version is 4.20.11-arch1-1-ARCH. Please help me how to include bpf function.