]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
lib bpf: Add support for BPF_PROG_ATTACH and BPF_PROG_DETACH
authorDavid Ahern <dsa@cumulusnetworks.com>
Mon, 12 Dec 2016 00:53:08 +0000 (16:53 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Tue, 13 Dec 2016 18:20:15 +0000 (10:20 -0800)
Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Acked-by: Daniel Borkmann <daniel@iogearbox.net>
include/bpf_util.h
lib/bpf.c

index 05baeecda57f47f255088fc3bc7893be773ddb87..b038379684a8afb423dd6a0557467dad435428ec 100644 (file)
@@ -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,
index 43ef63db92fbf7acd95c2cd40f50d74c667eca7b..006db9a869bb94bd321b54fcc752a94bf366ba80 100644 (file)
--- 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;