diff options
author | 2018-07-27 07:18:45 +0200 | |
---|---|---|
committer | 2018-07-27 07:18:45 +0200 | |
commit | 54b757592fdf310c9b8b3a8ea6cc0ce7cf9af983 (patch) | |
tree | e3d7389a2f79db94f5b29fc36eb5a28b4c761e4e /tools | |
parent | Merge branch 'bpf-nfp-perf-event-improvements' (diff) | |
parent | samples: bpf: convert xdpsock_user.c to libbpf (diff) | |
download | wireguard-linux-54b757592fdf310c9b8b3a8ea6cc0ce7cf9af983.tar.xz wireguard-linux-54b757592fdf310c9b8b3a8ea6cc0ce7cf9af983.zip |
Merge branch 'bpf-convert-more-samples'
Jakub Kicinski says:
====================
This set converts xdpsock_user.c and xdp_fwd_user.c to use libbpf instead
of bpf_load.o. First two patches are minor improvements to libbpf to make
the conversion (and use of libbpf in general) nicer.
====================
Acked-by: Yonghong Song <yhs@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to '')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 15 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.h | 3 |
2 files changed, 18 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 955f8eafbf41..857d3d16968e 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -873,6 +873,18 @@ bpf_object__find_prog_by_idx(struct bpf_object *obj, int idx) return NULL; } +struct bpf_program * +bpf_object__find_program_by_title(struct bpf_object *obj, const char *title) +{ + struct bpf_program *pos; + + bpf_object__for_each_program(pos, obj) { + if (pos->section_name && !strcmp(pos->section_name, title)) + return pos; + } + return NULL; +} + static int bpf_program__collect_reloc(struct bpf_program *prog, GElf_Shdr *shdr, Elf_Data *data, struct bpf_object *obj) @@ -1991,6 +2003,9 @@ int bpf_program__nth_fd(struct bpf_program *prog, int n) { int fd; + if (!prog) + return -EINVAL; + if (n >= prog->instances.nr || n < 0) { pr_warning("Can't get the %dth fd from program %s: only %d instances\n", n, prog->section_name, prog->instances.nr); diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 1f8fc2060460..a295fe2f822b 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -86,6 +86,9 @@ const char *bpf_object__name(struct bpf_object *obj); unsigned int bpf_object__kversion(struct bpf_object *obj); int bpf_object__btf_fd(const struct bpf_object *obj); +struct bpf_program * +bpf_object__find_program_by_title(struct bpf_object *obj, const char *title); + struct bpf_object *bpf_object__next(struct bpf_object *prev); #define bpf_object__for_each_safe(pos, tmp) \ for ((pos) = bpf_object__next(NULL), \ |