]> git.karo-electronics.de Git - linux-beck.git/commitdiff
samples/bpf: Update bpf loader for cgroup section names
authorDavid Ahern <dsa@cumulusnetworks.com>
Thu, 1 Dec 2016 16:48:07 +0000 (08:48 -0800)
committerDavid S. Miller <davem@davemloft.net>
Fri, 2 Dec 2016 18:46:09 +0000 (13:46 -0500)
Add support for section names starting with cgroup/skb and cgroup/sock.

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/bpf_load.c
samples/bpf/bpf_load.h

index 62f54d6eb8bf5c3381662ac76891c2aba3c64e83..49b45ccbe1530a7839ceb008c5e6008655ba734b 100644 (file)
@@ -52,6 +52,8 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
        bool is_tracepoint = strncmp(event, "tracepoint/", 11) == 0;
        bool is_xdp = strncmp(event, "xdp", 3) == 0;
        bool is_perf_event = strncmp(event, "perf_event", 10) == 0;
+       bool is_cgroup_skb = strncmp(event, "cgroup/skb", 10) == 0;
+       bool is_cgroup_sk = strncmp(event, "cgroup/sock", 11) == 0;
        enum bpf_prog_type prog_type;
        char buf[256];
        int fd, efd, err, id;
@@ -72,6 +74,10 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
                prog_type = BPF_PROG_TYPE_XDP;
        } else if (is_perf_event) {
                prog_type = BPF_PROG_TYPE_PERF_EVENT;
+       } else if (is_cgroup_skb) {
+               prog_type = BPF_PROG_TYPE_CGROUP_SKB;
+       } else if (is_cgroup_sk) {
+               prog_type = BPF_PROG_TYPE_CGROUP_SOCK;
        } else {
                printf("Unknown event '%s'\n", event);
                return -1;
@@ -85,7 +91,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
 
        prog_fd[prog_cnt++] = fd;
 
-       if (is_xdp || is_perf_event)
+       if (is_xdp || is_perf_event || is_cgroup_skb || is_cgroup_sk)
                return 0;
 
        if (is_socket) {
@@ -334,7 +340,8 @@ int load_bpf_file(char *path)
                            memcmp(shname_prog, "tracepoint/", 11) == 0 ||
                            memcmp(shname_prog, "xdp", 3) == 0 ||
                            memcmp(shname_prog, "perf_event", 10) == 0 ||
-                           memcmp(shname_prog, "socket", 6) == 0)
+                           memcmp(shname_prog, "socket", 6) == 0 ||
+                           memcmp(shname_prog, "cgroup/", 7) == 0)
                                load_and_attach(shname_prog, insns, data_prog->d_size);
                }
        }
@@ -353,7 +360,8 @@ int load_bpf_file(char *path)
                    memcmp(shname, "tracepoint/", 11) == 0 ||
                    memcmp(shname, "xdp", 3) == 0 ||
                    memcmp(shname, "perf_event", 10) == 0 ||
-                   memcmp(shname, "socket", 6) == 0)
+                   memcmp(shname, "socket", 6) == 0 ||
+                   memcmp(shname, "cgroup/", 7) == 0)
                        load_and_attach(shname, data->d_buf, data->d_size);
        }
 
index dfa57fe65c8e0f2eb67ae251705b631b1403fc55..4adeeef53ad6ea9f4c269cf8dd0aa52ff9ccf110 100644 (file)
@@ -7,6 +7,7 @@
 extern int map_fd[MAX_MAPS];
 extern int prog_fd[MAX_PROGS];
 extern int event_fd[MAX_PROGS];
+extern int prog_cnt;
 
 /* parses elf file compiled by llvm .c->.o
  * . parses 'maps' section and creates maps via BPF syscall