From: David Ahern Date: Mon, 12 Dec 2016 00:53:08 +0000 (-0800) Subject: lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH X-Git-Tag: v4.10.0~70 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc4ccce038942f42485bcbf7b49e90b8d24f3438;p=thirdparty%2Fiproute2.git lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH Signed-off-by: David Ahern Acked-by: Daniel Borkmann --- diff --git a/include/bpf_util.h b/include/bpf_util.h index 05baeecda..b03837968 100644 --- a/include/bpf_util.h +++ b/include/bpf_util.h @@ -75,6 +75,9 @@ int bpf_trace_pipe(void); void bpf_print_ops(FILE *f, struct rtattr *bpf_ops, __u16 len); +int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type); +int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type); + #ifdef HAVE_ELF int bpf_send_map_fds(const char *path, const char *obj); int bpf_recv_map_fds(const char *path, int *fds, struct bpf_map_aux *aux, diff --git a/lib/bpf.c b/lib/bpf.c index 43ef63db9..006db9a86 100644 --- a/lib/bpf.c +++ b/lib/bpf.c @@ -868,6 +868,27 @@ out_prog: return ret; } +int bpf_prog_attach_fd(int prog_fd, int target_fd, enum bpf_attach_type type) +{ + union bpf_attr attr = {}; + + attr.target_fd = target_fd; + attr.attach_bpf_fd = prog_fd; + attr.attach_type = type; + + return bpf(BPF_PROG_ATTACH, &attr, sizeof(attr)); +} + +int bpf_prog_detach_fd(int target_fd, enum bpf_attach_type type) +{ + union bpf_attr attr = {}; + + attr.target_fd = target_fd; + attr.attach_type = type; + + return bpf(BPF_PROG_DETACH, &attr, sizeof(attr)); +} + #ifdef HAVE_ELF struct bpf_elf_prog { enum bpf_prog_type type;