diff options
author | Andrii Nakryiko | 2019-07-02 01:58:56 +0200 |
---|---|---|
committer | Daniel Borkmann | 2019-07-05 22:37:30 +0200 |
commit | 1c2e9efc26f389effc86e9b4d41f85d101f17629 (patch) | |
tree | 2b04dd901d8ec783e1c140de208573cba1527cec /tools/lib/bpf/libbpf.c | |
parent | libbpf: make libbpf_strerror_r agnostic to sign of error (diff) | |
download | kernel-qcow2-linux-1c2e9efc26f389effc86e9b4d41f85d101f17629.tar.gz kernel-qcow2-linux-1c2e9efc26f389effc86e9b4d41f85d101f17629.tar.xz kernel-qcow2-linux-1c2e9efc26f389effc86e9b4d41f85d101f17629.zip |
libbpf: introduce concept of bpf_link
bpf_link is an abstraction of an association of a BPF program and one of
many possible BPF attachment points (hooks). This allows to have uniform
interface for detaching BPF programs regardless of the nature of link
and how it was created. Details of creation and setting up of a specific
bpf_link is handled by corresponding attachment methods
(bpf_program__attach_xxx) added in subsequent commits. Once successfully
created, bpf_link has to be eventually destroyed with
bpf_link__destroy(), at which point BPF program is disassociated from
a hook and all the relevant resources are freed.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Reviewed-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf/libbpf.c')
-rw-r--r-- | tools/lib/bpf/libbpf.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 4907997289e9..f308690abd50 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -3941,6 +3941,23 @@ int bpf_prog_load_xattr(const struct bpf_prog_load_attr *attr, return 0; } +struct bpf_link { + int (*destroy)(struct bpf_link *link); +}; + +int bpf_link__destroy(struct bpf_link *link) +{ + int err; + + if (!link) + return 0; + + err = link->destroy(link); + free(link); + + return err; +} + enum bpf_perf_event_ret bpf_perf_event_read_simple(void *mmap_mem, size_t mmap_size, size_t page_size, void **copy_mem, size_t *copy_size, |