mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-02 14:49:06 +08:00
libbpf: Add support for associating BPF program with struct_ops
Add low-level wrapper and libbpf API for BPF_PROG_ASSOC_STRUCT_OPS command in the bpf() syscall. Signed-off-by: Amery Hung <ameryhung@gmail.com> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20251203233748.668365-4-ameryhung@gmail.com
This commit is contained in:
committed by
Andrii Nakryiko
parent
1a41b12b4f
commit
5635185147
31
src/libbpf.c
31
src/libbpf.c
@@ -14133,6 +14133,37 @@ int bpf_program__set_attach_target(struct bpf_program *prog,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int bpf_program__assoc_struct_ops(struct bpf_program *prog, struct bpf_map *map,
|
||||
struct bpf_prog_assoc_struct_ops_opts *opts)
|
||||
{
|
||||
int prog_fd, map_fd;
|
||||
|
||||
prog_fd = bpf_program__fd(prog);
|
||||
if (prog_fd < 0) {
|
||||
pr_warn("prog '%s': can't associate BPF program without FD (was it loaded?)\n",
|
||||
prog->name);
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
if (prog->type == BPF_PROG_TYPE_STRUCT_OPS) {
|
||||
pr_warn("prog '%s': can't associate struct_ops program\n", prog->name);
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
map_fd = bpf_map__fd(map);
|
||||
if (map_fd < 0) {
|
||||
pr_warn("map '%s': can't associate BPF map without FD (was it created?)\n", map->name);
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
if (!bpf_map__is_struct_ops(map)) {
|
||||
pr_warn("map '%s': can't associate non-struct_ops map\n", map->name);
|
||||
return libbpf_err(-EINVAL);
|
||||
}
|
||||
|
||||
return bpf_prog_assoc_struct_ops(prog_fd, map_fd, opts);
|
||||
}
|
||||
|
||||
int parse_cpu_mask_str(const char *s, bool **mask, int *mask_sz)
|
||||
{
|
||||
int err = 0, n, len, start, end = -1;
|
||||
|
||||
Reference in New Issue
Block a user