diff options
author | Maciej Fijalkowski <maciejromanfijalkowski@gmail.com> | 2019-02-01 22:42:23 +0100 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-02-01 23:37:50 +0100 |
commit | f3cea32d56e96c510af454616104e3979f7626dd (patch) | |
tree | c533d2064965a7f1071d14b53105e591cbb24867 /tools/lib/bpf/libbpf.c | |
parent | 6f20c71d8505d6ad0ddbfdb44838402aba9b7c4e (diff) | |
download | lwn-f3cea32d56e96c510af454616104e3979f7626dd.tar.gz lwn-f3cea32d56e96c510af454616104e3979f7626dd.zip |
libbpf: Add a helper for retrieving a map fd for a given name
XDP samples are mostly cooperating with eBPF maps through their file
descriptors. In case of a eBPF program that contains multiple maps it
might be tiresome to iterate through them and call bpf_map__fd for each
one. Add a helper mostly based on bpf_object__find_map_by_name, but
instead of returning the struct bpf_map pointer, return map fd.
Suggested-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 2ccde17957e6..03bc01ca2577 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -2884,6 +2884,12 @@ bpf_object__find_map_by_name(struct bpf_object *obj, const char *name) return NULL; } +int +bpf_object__find_map_fd_by_name(struct bpf_object *obj, const char *name) +{ + return bpf_map__fd(bpf_object__find_map_by_name(obj, name)); +} + struct bpf_map * bpf_object__find_map_by_offset(struct bpf_object *obj, size_t offset) { |