diff options
author | Joe Stringer <joe@ovn.org> | 2016-12-14 17:05:26 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2016-12-20 10:00:39 -0500 |
commit | 5dc880de6e7c8566fbc8bc5dfc3a922d2d1c5ee3 (patch) | |
tree | b2d6edd5122a4da1c87e5760adbeea14d2323e0d /tools/lib/bpf/bpf.c | |
parent | 43371c83f382bd495a2294e91a32f30763cfdbef (diff) |
tools lib bpf: Add bpf_prog_{attach,detach}
Commit d8c5b17f2bc0 ("samples: bpf: add userspace example for attaching
eBPF programs to cgroups") added these functions to samples/libbpf, but
during this merge all of the samples libbpf functionality is shifting to
tools/lib/bpf. Shift these functions there.
Committer notes:
Use bzero + attr.FIELD = value instead of 'attr = { .FIELD = value, just
like the other wrapper calls to sys_bpf with bpf_attr to make this build
in older toolchais, such as the ones in CentOS 5 and 6.
Signed-off-by: Joe Stringer <joe@ovn.org>
Cc: Alexei Starovoitov <ast@fb.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Wang Nan <wangnan0@huawei.com>
Link: http://lkml.kernel.org/n/tip-au2zvtsh55vqeo3v3uw7jr4c@git.kernel.org
Link: https://github.com/joestringer/linux/commit/353e6f298c3d0a92fa8bfa61ff898c5050261a12.patch
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/lib/bpf/bpf.c')
-rw-r--r-- | tools/lib/bpf/bpf.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tools/lib/bpf/bpf.c b/tools/lib/bpf/bpf.c index d0afb26c2e0f..3ddb58a36d3c 100644 --- a/tools/lib/bpf/bpf.c +++ b/tools/lib/bpf/bpf.c | |||
@@ -167,3 +167,26 @@ int bpf_obj_get(const char *pathname) | |||
167 | 167 | ||
168 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); | 168 | return sys_bpf(BPF_OBJ_GET, &attr, sizeof(attr)); |
169 | } | 169 | } |
170 | |||
171 | int bpf_prog_attach(int prog_fd, int target_fd, enum bpf_attach_type type) | ||
172 | { | ||
173 | union bpf_attr attr; | ||
174 | |||
175 | bzero(&attr, sizeof(attr)); | ||
176 | attr.target_fd = target_fd; | ||
177 | attr.attach_bpf_fd = prog_fd; | ||
178 | attr.attach_type = type; | ||
179 | |||
180 | return sys_bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); | ||
181 | } | ||
182 | |||
183 | int bpf_prog_detach(int target_fd, enum bpf_attach_type type) | ||
184 | { | ||
185 | union bpf_attr attr; | ||
186 | |||
187 | bzero(&attr, sizeof(attr)); | ||
188 | attr.target_fd = target_fd; | ||
189 | attr.attach_type = type; | ||
190 | |||
191 | return sys_bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); | ||
192 | } | ||