libbpf: add BPF token support to bpf_map_create() API
authorAndrii Nakryiko <andrii@kernel.org>
Thu, 30 Nov 2023 18:52:25 +0000 (10:52 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 6 Dec 2023 18:03:00 +0000 (10:03 -0800)
Add ability to provide token_fd for BPF_MAP_CREATE command through
bpf_map_create() API.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20231130185229.2688956-14-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/lib/bpf/bpf.c
tools/lib/bpf/bpf.h

index d4019928a864654bab03755f90e61b8b2d70ef4e..1653b64b701581b8ed029f6e0ef064a2283bf3f1 100644 (file)
@@ -169,7 +169,7 @@ int bpf_map_create(enum bpf_map_type map_type,
                   __u32 max_entries,
                   const struct bpf_map_create_opts *opts)
 {
-       const size_t attr_sz = offsetofend(union bpf_attr, map_extra);
+       const size_t attr_sz = offsetofend(union bpf_attr, map_token_fd);
        union bpf_attr attr;
        int fd;
 
@@ -198,6 +198,8 @@ int bpf_map_create(enum bpf_map_type map_type,
        attr.numa_node = OPTS_GET(opts, numa_node, 0);
        attr.map_ifindex = OPTS_GET(opts, map_ifindex, 0);
 
+       attr.map_token_fd = OPTS_GET(opts, token_fd, 0);
+
        fd = sys_bpf_fd(BPF_MAP_CREATE, &attr, attr_sz);
        return libbpf_err_errno(fd);
 }
index e49254c9f68f48b25c83306a70fd5475bdac4521..ae2136f596b4af1d5dc601f86972ab36a08b2609 100644 (file)
@@ -51,8 +51,11 @@ struct bpf_map_create_opts {
 
        __u32 numa_node;
        __u32 map_ifindex;
+
+       __u32 token_fd;
+       size_t :0;
 };
-#define bpf_map_create_opts__last_field map_ifindex
+#define bpf_map_create_opts__last_field token_fd
 
 LIBBPF_API int bpf_map_create(enum bpf_map_type map_type,
                              const char *map_name,