Commit ea02a946 authored by Ihor Solodrai's avatar Ihor Solodrai Committed by Andrii Nakryiko
Browse files

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: default avatarAndrii Nakryiko <andrii@kernel.org>
Signed-off-by: default avatarIhor Solodrai <ihor.solodrai@pm.me>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20240913001858.3345583-1-ihor.solodrai@pm.me
parent 6182e0b8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -9059,6 +9059,11 @@ unsigned int bpf_object__kversion(const struct bpf_object *obj)
	return obj ? obj->kern_version : 0;
}

int bpf_object__token_fd(const struct bpf_object *obj)
{
	return obj->token_fd ?: -1;
}

struct btf *bpf_object__btf(const struct bpf_object *obj)
{
	return obj ? obj->btf : NULL;
+8 −0
Original line number Diff line number Diff line
@@ -294,6 +294,14 @@ LIBBPF_API const char *bpf_object__name(const struct bpf_object *obj);
LIBBPF_API unsigned int bpf_object__kversion(const struct bpf_object *obj);
LIBBPF_API int bpf_object__set_kversion(struct bpf_object *obj, __u32 kern_version);

/**
 * @brief **bpf_object__token_fd** is an accessor for BPF token FD associated
 * with BPF object.
 * @param obj Pointer to a valid BPF object
 * @return BPF token FD or -1, if it wasn't set
 */
LIBBPF_API int bpf_object__token_fd(const struct bpf_object *obj);

struct btf;
LIBBPF_API struct btf *bpf_object__btf(const struct bpf_object *obj);
LIBBPF_API int bpf_object__btf_fd(const struct bpf_object *obj);
+1 −0
Original line number Diff line number Diff line
@@ -423,6 +423,7 @@ LIBBPF_1.5.0 {
		btf__relocate;
		bpf_map__autoattach;
		bpf_map__set_autoattach;
		bpf_object__token_fd;
		bpf_program__attach_sockmap;
		ring__consume_n;
		ring_buffer__consume_n;