tools: libbpf: add bpf_object__find_program_by_title()
authorJakub Kicinski <jakub.kicinski@netronome.com>
Thu, 26 Jul 2018 21:32:19 +0000 (14:32 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Fri, 27 Jul 2018 05:18:44 +0000 (07:18 +0200)
Allow users to find programs by section names.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/lib/bpf/libbpf.c
tools/lib/bpf/libbpf.h

index afa9860db755d904a12cd8a4f7ff640c834691b9..857d3d16968ebc6687c536b873f275f97c6fddb9 100644 (file)
@@ -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)
index 1f8fc20604605d512f5fa12517bbeed4b9979dac..a295fe2f822b5bd80790b835453be9ef17aafb4a 100644 (file)
@@ -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),            \