]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - samples/bpf/bpf_load.c
bpf: BPF support for sock_ops
[linux.git] / samples / bpf / bpf_load.c
index a91c57dd8571e01f93ad95986a8c80103a0a406e..a4be7cfa65190b2bab1a1d654dea931ece8501dc 100644 (file)
@@ -64,6 +64,7 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
        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;
+       bool is_sockops = strncmp(event, "sockops", 7) == 0;
        size_t insns_cnt = size / sizeof(struct bpf_insn);
        enum bpf_prog_type prog_type;
        char buf[256];
@@ -89,6 +90,8 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
                prog_type = BPF_PROG_TYPE_CGROUP_SKB;
        } else if (is_cgroup_sk) {
                prog_type = BPF_PROG_TYPE_CGROUP_SOCK;
+       } else if (is_sockops) {
+               prog_type = BPF_PROG_TYPE_SOCK_OPS;
        } else {
                printf("Unknown event '%s'\n", event);
                return -1;
@@ -106,8 +109,11 @@ static int load_and_attach(const char *event, struct bpf_insn *prog, int size)
        if (is_xdp || is_perf_event || is_cgroup_skb || is_cgroup_sk)
                return 0;
 
-       if (is_socket) {
-               event += 6;
+       if (is_socket || is_sockops) {
+               if (is_socket)
+                       event += 6;
+               else
+                       event += 7;
                if (*event != '/')
                        return 0;
                event++;
@@ -560,7 +566,8 @@ static int do_load_bpf_file(const char *path, fixup_map_cb fixup_map)
                    memcmp(shname, "xdp", 3) == 0 ||
                    memcmp(shname, "perf_event", 10) == 0 ||
                    memcmp(shname, "socket", 6) == 0 ||
-                   memcmp(shname, "cgroup/", 7) == 0)
+                   memcmp(shname, "cgroup/", 7) == 0 ||
+                   memcmp(shname, "sockops", 7) == 0)
                        load_and_attach(shname, data->d_buf, data->d_size);
        }