@@ -1331,3 +1331,20 @@ int bpf_token_create(int bpffs_fd, struct bpf_token_create_opts *opts)
fd = sys_bpf_fd(BPF_TOKEN_CREATE, &attr, attr_sz);
return libbpf_err_errno(fd);
}
+
+int bpf_static_key_update(int map_fd, struct bpf_static_key_update_opts *opts)
+{
+ const size_t attr_sz = offsetofend(union bpf_attr, static_key);
+ union bpf_attr attr;
+ int ret;
+
+ if (!OPTS_VALID(opts, bpf_static_key_update_opts))
+ return libbpf_err(-EINVAL);
+
+ memset(&attr, 0, attr_sz);
+ attr.static_key.map_fd = map_fd;
+ attr.static_key.on = OPTS_GET(opts, on, 0);
+
+ ret = sys_bpf(BPF_STATIC_KEY_UPDATE, &attr, attr_sz);
+ return libbpf_err_errno(ret);
+}
@@ -704,6 +704,25 @@ struct bpf_token_create_opts {
LIBBPF_API int bpf_token_create(int bpffs_fd,
struct bpf_token_create_opts *opts);
+struct bpf_static_key_update_opts {
+ size_t sz; /* size of this struct for forward/backward compatibility */
+ __u32 on;
+ size_t :0;
+};
+#define bpf_static_key_update_opts__last_field on
+
+/**
+ * @brief **bpf_static_key_update()** updates the value of a static key
+ *
+ * @param map_fd FD for the static key.
+ * @param opts optional BPF token creation options, can be NULL
+ *
+ * @return 0 on success; negative error code, otherwise (errno
+ * is also set to the error code)
+ */
+LIBBPF_API int bpf_static_key_update(int map_fd,
+ struct bpf_static_key_update_opts *opts);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
@@ -439,4 +439,5 @@ LIBBPF_1.6.0 {
bpf_object__prepare;
btf__add_decl_attr;
btf__add_type_attr;
+ bpf_static_key_update;
} LIBBPF_1.5.0;
Add low-level wrapper API for BPF_STATIC_KEY_UPDATE command in bpf() syscall. Signed-off-by: Anton Protopopov <aspsk@isovalent.com> --- tools/lib/bpf/bpf.c | 17 +++++++++++++++++ tools/lib/bpf/bpf.h | 19 +++++++++++++++++++ tools/lib/bpf/libbpf.map | 1 + 3 files changed, 37 insertions(+)