samples, bpf: Refactor tail call user progs with libbpf
authorDaniel T. Lee <danieltimlee@gmail.com>
Sat, 16 May 2020 04:06:06 +0000 (13:06 +0900)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 19 May 2020 15:12:56 +0000 (17:12 +0200)
commitbc1a85977b950407d67cd1e5b74f261a4bee3284
treee4c5283ae3815b08fe2a09a34576a7ebf7931ecf
parent63841bc0833623ecd4f758ec055b543cf1bc56ba
samples, bpf: Refactor tail call user progs with libbpf

BPF tail call uses the BPF_MAP_TYPE_PROG_ARRAY type map for calling
into other BPF programs and this PROG_ARRAY should be filled prior to
use. Currently, samples with the PROG_ARRAY type MAP fill this program
array with bpf_load. For bpf_load to fill this map, kernel BPF program
must specify the section with specific format of <prog_type>/<array_idx>
(e.g. SEC("socket/0"))

But by using libbpf instead of bpf_load, user program can specify which
programs should be added to PROG_ARRAY. The advantage of this approach
is that you can selectively add only the programs you want, rather than
adding all of them to PROG_ARRAY, and it's much more intuitive than the
traditional approach.

This commit refactors user programs with the PROG_ARRAY type MAP with
libbpf instead of using bpf_load.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Yonghong Song <yhs@fb.com>
Link: https://lore.kernel.org/bpf/20200516040608.1377876-4-danieltimlee@gmail.com
samples/bpf/Makefile
samples/bpf/sockex3_user.c
samples/bpf/tracex5_user.c