Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
[sfrench/cifs-2.6.git] / tools / bpf / bpftool / cgroup.c
index 62c6a1d7cd18b66261f17d9d8b14571f85bcd8e1..1693c802bb20705be434a8fc3ab073e654511c6e 100644 (file)
 
 static unsigned int query_flags;
 
-static const char * const attach_type_strings[] = {
-       [BPF_CGROUP_INET_INGRESS] = "ingress",
-       [BPF_CGROUP_INET_EGRESS] = "egress",
-       [BPF_CGROUP_INET_SOCK_CREATE] = "sock_create",
-       [BPF_CGROUP_SOCK_OPS] = "sock_ops",
-       [BPF_CGROUP_DEVICE] = "device",
-       [BPF_CGROUP_INET4_BIND] = "bind4",
-       [BPF_CGROUP_INET6_BIND] = "bind6",
-       [BPF_CGROUP_INET4_CONNECT] = "connect4",
-       [BPF_CGROUP_INET6_CONNECT] = "connect6",
-       [BPF_CGROUP_INET4_POST_BIND] = "post_bind4",
-       [BPF_CGROUP_INET6_POST_BIND] = "post_bind6",
-       [BPF_CGROUP_UDP4_SENDMSG] = "sendmsg4",
-       [BPF_CGROUP_UDP6_SENDMSG] = "sendmsg6",
-       [BPF_CGROUP_SYSCTL] = "sysctl",
-       [BPF_CGROUP_UDP4_RECVMSG] = "recvmsg4",
-       [BPF_CGROUP_UDP6_RECVMSG] = "recvmsg6",
-       [BPF_CGROUP_GETSOCKOPT] = "getsockopt",
-       [BPF_CGROUP_SETSOCKOPT] = "setsockopt",
-       [__MAX_BPF_ATTACH_TYPE] = NULL,
-};
-
 static enum bpf_attach_type parse_attach_type(const char *str)
 {
        enum bpf_attach_type type;
 
        for (type = 0; type < __MAX_BPF_ATTACH_TYPE; type++) {
-               if (attach_type_strings[type] &&
-                   is_prefix(str, attach_type_strings[type]))
+               if (attach_type_name[type] &&
+                   is_prefix(str, attach_type_name[type]))
                        return type;
        }
 
        return __MAX_BPF_ATTACH_TYPE;
 }
 
-static int show_bpf_prog(int id, const char *attach_type_str,
+static int show_bpf_prog(int id, enum bpf_attach_type attach_type,
                         const char *attach_flags_str,
                         int level)
 {
@@ -86,18 +64,22 @@ static int show_bpf_prog(int id, const char *attach_type_str,
        if (json_output) {
                jsonw_start_object(json_wtr);
                jsonw_uint_field(json_wtr, "id", info.id);
-               jsonw_string_field(json_wtr, "attach_type",
-                                  attach_type_str);
+               if (attach_type < ARRAY_SIZE(attach_type_name))
+                       jsonw_string_field(json_wtr, "attach_type",
+                                          attach_type_name[attach_type]);
+               else
+                       jsonw_uint_field(json_wtr, "attach_type", attach_type);
                jsonw_string_field(json_wtr, "attach_flags",
                                   attach_flags_str);
                jsonw_string_field(json_wtr, "name", info.name);
                jsonw_end_object(json_wtr);
        } else {
-               printf("%s%-8u %-15s %-15s %-15s\n", level ? "    " : "",
-                      info.id,
-                      attach_type_str,
-                      attach_flags_str,
-                      info.name);
+               printf("%s%-8u ", level ? "    " : "", info.id);
+               if (attach_type < ARRAY_SIZE(attach_type_name))
+                       printf("%-15s", attach_type_name[attach_type]);
+               else
+                       printf("type %-10u", attach_type);
+               printf(" %-15s %-15s\n", attach_flags_str, info.name);
        }
 
        close(prog_fd);
@@ -171,7 +153,7 @@ static int show_attached_bpf_progs(int cgroup_fd, enum bpf_attach_type type,
        }
 
        for (iter = 0; iter < prog_cnt; iter++)
-               show_bpf_prog(prog_ids[iter], attach_type_strings[type],
+               show_bpf_prog(prog_ids[iter], type,
                              attach_flags_str, level);
 
        return 0;