OSDN Git Service

Merge branch 'bpf-bpftool-improved-prog-load'
authorDaniel Borkmann <daniel@iogearbox.net>
Wed, 11 Jul 2018 20:13:35 +0000 (22:13 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 11 Jul 2018 20:13:35 +0000 (22:13 +0200)
commit671dffa7de7b6dcc37c028e33899ef69f939969d
tree227ec4a474eaa03236f5ce8df1df25d890846ee4
parentd90c936fb3181695d63a1edb155d26fc576b17b4
parent3ff5a4dc5d890963e669fc99cc62ee07d1da24e8
Merge branch 'bpf-bpftool-improved-prog-load'

Jakub Kicinski says:

====================
This series starts with two minor clean ups to test_offload.py
selftest script.

The next 11 patches extend the abilities of bpftool prog load
beyond the simple cgroup use cases.  Three new parameters are
added:

 - type - allows specifying program type, independent of how
   code sections are named;
 - map  - allows reusing existing maps, instead of creating a new
   map on every program load;
 - dev  - offload/binding to a device.

A number of changes to libbpf is required to accomplish the task.
The section - program type logic mapping is exposed.  We should
probably aim to use the libbpf program section naming everywhere.
For reuse of maps we need to allow users to set FD for bpf map
object in libbpf.

Examples

Load program my_xdp.o and pin it as /sys/fs/bpf/my_xdp, for xdp
program type:

$ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
  type xdp

As above but for offload:

$ bpftool prog load my_xdp.o /sys/fs/bpf/my_xdp \
  type xdp \
  dev netdevsim0

Load program my_maps.o, but for the first map reuse map id 17,
and for the map called "other_map" reuse pinned map /sys/fs/bpf/map0:

$ bpftool prog load my_maps.o /sys/fs/bpf/prog \
  map idx 0 id 17 \
  map name other_map pinned /sys/fs/bpf/map0

v3:
 - fix return codes in patch 5;
 - rename libbpf_prog_type_by_string() -> libbpf_prog_type_by_name();
 - fold file path into xattr in patch 8;
 - add patch 10;
 - use dup3() in patch 12;
 - depend on fd value in patch 12;
 - close old fd in patch 12.
v2:
 - add compat for reallocarray().
====================

Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>