bpftool: Support new prog types and attach types
authorAndrey Ignatov <rdna@fb.com>
Tue, 17 Apr 2018 17:28:44 +0000 (10:28 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 18 Apr 2018 12:39:24 +0000 (14:39 +0200)
Add recently added prog types to `bpftool prog` and attach types to
`bpftool cgroup`.

Update bpftool documentation and bash completion appropriately.

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/cgroup.c
tools/bpf/bpftool/prog.c

index 0e4e923..d004f63 100644 (file)
@@ -26,7 +26,8 @@ MAP COMMANDS
 |      **bpftool** **cgroup help**
 |
 |      *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
-|      *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** }
+|      *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** |
+|              **bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** }
 |      *ATTACH_FLAGS* := { **multi** | **override** }
 
 DESCRIPTION
@@ -63,7 +64,13 @@ DESCRIPTION
                  **egress** egress path of the inet socket (since 4.10);
                  **sock_create** opening of an inet socket (since 4.10);
                  **sock_ops** various socket operations (since 4.12);
-                 **device** device access (since 4.15).
+                 **device** device access (since 4.15);
+                 **bind4** call to bind(2) for an inet4 socket (since 4.17);
+                 **bind6** call to bind(2) for an inet6 socket (since 4.17);
+                 **post_bind4** return from bind(2) for an inet4 socket (since 4.17);
+                 **post_bind6** return from bind(2) for an inet6 socket (since 4.17);
+                 **connect4** call to connect(2) for an inet4 socket (since 4.17);
+                 **connect6** call to connect(2) for an inet6 socket (since 4.17).
 
        **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
                  Detach *PROG* from the cgroup *CGROUP* and attach type
index 490811b..c01b2de 100644 (file)
@@ -372,7 +372,8 @@ _bpftool()
                     ;;
                 attach|detach)
                     local ATTACH_TYPES='ingress egress sock_create sock_ops \
-                        device'
+                        device bind4 bind6 post_bind4 post_bind6 connect4 \
+                        connect6'
                     local ATTACH_FLAGS='multi override'
                     local PROG_TYPE='id pinned tag'
                     case $prev in
@@ -380,7 +381,8 @@ _bpftool()
                             _filedir
                             return 0
                             ;;
-                        ingress|egress|sock_create|sock_ops|device)
+                        ingress|egress|sock_create|sock_ops|device|bind4|bind6|\
+                        post_bind4|post_bind6|connect4|connect6)
                             COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
                                 "$cur" ) )
                             return 0
index cae32a6..1351bd6 100644 (file)
 #define HELP_SPEC_ATTACH_FLAGS                                         \
        "ATTACH_FLAGS := { multi | override }"
 
-#define HELP_SPEC_ATTACH_TYPES                                         \
-       "ATTACH_TYPE := { ingress | egress | sock_create | sock_ops | device }"
+#define HELP_SPEC_ATTACH_TYPES                                                \
+       "       ATTACH_TYPE := { ingress | egress | sock_create |\n"           \
+       "                        sock_ops | device | bind4 | bind6 |\n"        \
+       "                        post_bind4 | post_bind6 | connect4 |\n"       \
+       "                        connect6 }"
 
 static const char * const attach_type_strings[] = {
        [BPF_CGROUP_INET_INGRESS] = "ingress",
@@ -25,6 +28,12 @@ static const char * const attach_type_strings[] = {
        [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",
        [__MAX_BPF_ATTACH_TYPE] = NULL,
 };
 
@@ -282,7 +291,7 @@ static int do_help(int argc, char **argv)
                "       %s %s detach CGROUP ATTACH_TYPE PROG\n"
                "       %s %s help\n"
                "\n"
-               "       " HELP_SPEC_ATTACH_TYPES "\n"
+               HELP_SPEC_ATTACH_TYPES "\n"
                "       " HELP_SPEC_ATTACH_FLAGS "\n"
                "       " HELP_SPEC_PROGRAM "\n"
                "       " HELP_SPEC_OPTIONS "\n"
index f7a8108..548adb9 100644 (file)
@@ -68,6 +68,9 @@ static const char * const prog_type_name[] = {
        [BPF_PROG_TYPE_SOCK_OPS]        = "sock_ops",
        [BPF_PROG_TYPE_SK_SKB]          = "sk_skb",
        [BPF_PROG_TYPE_CGROUP_DEVICE]   = "cgroup_device",
+       [BPF_PROG_TYPE_SK_MSG]          = "sk_msg",
+       [BPF_PROG_TYPE_RAW_TRACEPOINT]  = "raw_tracepoint",
+       [BPF_PROG_TYPE_CGROUP_SOCK_ADDR] = "cgroup_sock_addr",
 };
 
 static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)