diff options
| author | Joe Burton <[email protected]> | 2022-07-29 20:27:27 +0000 |
|---|---|---|
| committer | Andrii Nakryiko <[email protected]> | 2022-07-29 22:30:06 +0000 |
| commit | 395fc4fa33e98944384d0d6c8b3ecd9fb4b50d00 (patch) | |
| tree | ca8f08c202735460a66276f9f461a3352689a1ae /tools/lib/bpf/bpf.c | |
| parent | netdevsim: Avoid allocation warnings triggered from user space (diff) | |
| download | kernel-395fc4fa33e98944384d0d6c8b3ecd9fb4b50d00.tar.gz kernel-395fc4fa33e98944384d0d6c8b3ecd9fb4b50d00.zip | |
libbpf: Add bpf_obj_get_opts()
Add an extensible variant of bpf_obj_get() capable of setting the
`file_flags` parameter.
This parameter is needed to enable unprivileged access to BPF maps.
Without a method like this, users must manually make the syscall.
Signed-off-by: Joe Burton <[email protected]>
Signed-off-by: Andrii Nakryiko <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Diffstat (limited to 'tools/lib/bpf/bpf.c')
| -rw-r--r-- | tools/lib/bpf/bpf.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index 5eb0df90eb2b..efcc06dafbd9 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c @@ -579,11 +579,20 @@ int bpf_obj_pin(int fd, const char *pathname) int bpf_obj_get(const char *pathname) { + return bpf_obj_get_opts(pathname, NULL); +} + +int bpf_obj_get_opts(const char *pathname, const struct bpf_obj_get_opts *opts) +{ union bpf_attr attr; int fd; + if (!OPTS_VALID(opts, bpf_obj_get_opts)) + return libbpf_err(-EINVAL); + memset(&attr, 0, sizeof(attr)); attr.pathname = ptr_to_u64((void *)pathname); + attr.file_flags = OPTS_GET(opts, file_flags, 0); fd = sys_bpf_fd(BPF_OBJ_GET, &attr, sizeof(attr)); return libbpf_err_errno(fd); |
