]> git.ipfire.org Git - thirdparty/iproute2.git/commit
lib: add libbpf support
authorHangbin Liu <haliu@redhat.com>
Mon, 23 Nov 2020 13:11:59 +0000 (21:11 +0800)
committerDavid Ahern <dsahern@gmail.com>
Wed, 25 Nov 2020 05:14:05 +0000 (22:14 -0700)
commit6d61a2b55799b4706f1f43cc23eea4ba708b502f
treeb97a692cc969e9661f2c4ac35483be5d49ad621e
parentdc800a4ed4f3112d932dbb6266c664de4766fa6e
lib: add libbpf support

This patch converts iproute2 to use libbpf for loading and attaching
BPF programs when it is available, which is started by Toke's
implementation[1]. With libbpf iproute2 could correctly process BTF
information and support the new-style BTF-defined maps, while keeping
compatibility with the old internal map definition syntax.

The old iproute2 bpf code is kept and will be used if no suitable libbpf
is available. When using libbpf, wrapper code in bpf_legacy.c ensures that
iproute2 will still understand the old map definition format, including
populating map-in-map and tail call maps before load.

In bpf_libbpf.c, we init iproute2 ctx and elf info first to check the
legacy bytes. When handling the legacy maps, for map-in-maps, we create
them manually and re-use the fd as they are associated with id/inner_id.
For pin maps, we only set the pin path and let libbp load to handle it.
For tail calls, we find it first and update the element after prog load.

Other maps/progs will be loaded by libbpf directly.

[1] https://lore.kernel.org/bpf/20190820114706.18546-1-toke@redhat.com/

Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Hangbin Liu <haliu@redhat.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
include/bpf_util.h
lib/Makefile
lib/bpf_legacy.c
lib/bpf_libbpf.c [new file with mode: 0644]