aboutsummaryrefslogtreecommitdiffstats
path: root/tools/bpf/bpftool/main.h
diff options
context:
space:
mode:
authorQuentin Monnet <quentin@isovalent.com>2021-10-23 21:51:53 +0100
committerAndrii Nakryiko <andrii@kernel.org>2021-10-25 17:31:39 -0700
commit2828d0d75b738c9cd98080c530b7b7ea90b279dd (patch)
treee8c565cc5d3daebca3f065a1e82e5ce4f4568f20 /tools/bpf/bpftool/main.h
parentbpftool: Switch to libbpf's hashmap for pinned paths of BPF objects (diff)
downloadlinux-2828d0d75b738c9cd98080c530b7b7ea90b279dd.tar.xz
linux-2828d0d75b738c9cd98080c530b7b7ea90b279dd.zip
bpftool: Switch to libbpf's hashmap for programs/maps in BTF listing
In order to show BPF programs and maps using BTF objects when the latter are being listed, bpftool creates hash maps to store all relevant items. This commit is part of a set that transitions from the kernel's hash map implementation to the one coming with libbpf. The motivation is to make bpftool less dependent of kernel headers, to ease the path to a potential out-of-tree mirror, like libbpf has. This commit focuses on the two hash maps used by bpftool when listing BTF objects to store references to programs and maps, and convert them to the libbpf's implementation. Signed-off-by: Quentin Monnet <quentin@isovalent.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20211023205154.6710-5-quentin@isovalent.com
Diffstat (limited to 'tools/bpf/bpftool/main.h')
-rw-r--r--tools/bpf/bpftool/main.h5
1 files changed, 5 insertions, 0 deletions
diff --git a/tools/bpf/bpftool/main.h b/tools/bpf/bpftool/main.h
index 0d64e39573f2..f6f2f951b193 100644
--- a/tools/bpf/bpftool/main.h
+++ b/tools/bpf/bpftool/main.h
@@ -256,6 +256,11 @@ static inline void *u32_as_hash_field(__u32 x)
return (void *)(uintptr_t)x;
}
+static inline __u32 hash_field_as_u32(const void *x)
+{
+ return (__u32)(uintptr_t)x;
+}
+
static inline bool hashmap__empty(struct hashmap *map)
{
return map ? hashmap__size(map) == 0 : true;