Skip to content

Commit ea02a94

Browse files
theihoranakryiko
authored andcommitted
libbpf: Add bpf_object__token_fd accessor
Add a LIBBPF_API function to retrieve the token_fd from a bpf_object. Without this accessor, if user needs a token FD they have to get it manually via bpf_token_create, even though a token might have been already created by bpf_object__load. Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Ihor Solodrai <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 6182e0b commit ea02a94

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

tools/lib/bpf/libbpf.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9059,6 +9059,11 @@ unsigned int bpf_object__kversion(const struct bpf_object *obj)
90599059
return obj ? obj->kern_version : 0;
90609060
}
90619061

9062+
int bpf_object__token_fd(const struct bpf_object *obj)
9063+
{
9064+
return obj->token_fd ?: -1;
9065+
}
9066+
90629067
struct btf *bpf_object__btf(const struct bpf_object *obj)
90639068
{
90649069
return obj ? obj->btf : NULL;

tools/lib/bpf/libbpf.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
294294
LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
295295
LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version);
296296

297+
/**
298+
* @brief **bpf_object__token_fd** is an accessor for BPF token FD associated
299+
* with BPF object.
300+
* @param obj Pointer to a valid BPF object
301+
* @return BPF token FD or -1, if it wasn't set
302+
*/
303+
LIBBPF_API int bpf_object__token_fd(const struct bpf_object *obj);
304+
297305
struct btf;
298306
LIBBPF_API struct btf *bpf_object__btf(const struct bpf_object *obj);
299307
LIBBPF_API int bpf_object__btf_fd(const struct bpf_object *obj);

tools/lib/bpf/libbpf.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ LIBBPF_1.5.0 {
423423
btf__relocate;
424424
bpf_map__autoattach;
425425
bpf_map__set_autoattach;
426+
bpf_object__token_fd;
426427
bpf_program__attach_sockmap;
427428
ring__consume_n;
428429
ring_buffer__consume_n;

0 commit comments

Comments
 (0)