libbpf: add bpf_btf_get_next_id() to cycle through BTF objects
authorQuentin Monnet <quentin.monnet@netronome.com>
Tue, 20 Aug 2019 09:31:53 +0000 (10:31 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 20 Aug 2019 16:51:06 +0000 (09:51 -0700)
Add an API function taking a BTF object id and providing the id of the
next BTF object in the kernel. This can be used to list all BTF objects
loaded on the system.

v2:
- Rebase on top of Andrii's changes regarding libbpf versioning.

Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.h
tools/lib/bpf/libbpf.map

index 1439e99c9be53d5c417dc6ccd7ad9ffafb8ae251..cbb933532981f0923b2d37ac3acacf1d5e428b46 100644 (file)
@@ -593,6 +593,11 @@ int bpf_map_get_next_id(__u32 start_id, __u32 *next_id)
        return bpf_obj_get_next_id(start_id, next_id, BPF_MAP_GET_NEXT_ID);
 }
 
+int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id)
+{
+       return bpf_obj_get_next_id(start_id, next_id, BPF_BTF_GET_NEXT_ID);
+}
+
 int bpf_prog_get_fd_by_id(__u32 id)
 {
        union bpf_attr attr;
index ff42ca043dc8fc1e0e94eaf1334367ec4585b543..0db01334740f8d1961a54bb28d8cb7f11d8ea9f6 100644 (file)
@@ -156,6 +156,7 @@ LIBBPF_API int bpf_prog_test_run(int prog_fd, int repeat, void *data,
                                 __u32 *retval, __u32 *duration);
 LIBBPF_API int bpf_prog_get_next_id(__u32 start_id, __u32 *next_id);
 LIBBPF_API int bpf_map_get_next_id(__u32 start_id, __u32 *next_id);
+LIBBPF_API int bpf_btf_get_next_id(__u32 start_id, __u32 *next_id);
 LIBBPF_API int bpf_prog_get_fd_by_id(__u32 id);
 LIBBPF_API int bpf_map_get_fd_by_id(__u32 id);
 LIBBPF_API int bpf_btf_get_fd_by_id(__u32 id);
index 4e72df8e98ba38fa03fd8bc50de7d5f9eeebf722..664ce8e7a60e79e4f875c6c976001b3a62d68b52 100644 (file)
@@ -186,4 +186,6 @@ LIBBPF_0.0.4 {
 } LIBBPF_0.0.3;
 
 LIBBPF_0.0.5 {
+       global:
+               bpf_btf_get_next_id;
 } LIBBPF_0.0.4;