bpftool: support cgroup sockopt
authorStanislav Fomichev <sdf@google.com>
Thu, 27 Jun 2019 20:38:55 +0000 (13:38 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Thu, 27 Jun 2019 22:25:17 +0000 (15:25 -0700)
Support sockopt prog type and cgroup hooks in the bpftool.

Cc: Andrii Nakryiko <andriin@fb.com>
Cc: Martin Lau <kafai@fb.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
tools/bpf/bpftool/Documentation/bpftool-cgroup.rst
tools/bpf/bpftool/Documentation/bpftool-prog.rst
tools/bpf/bpftool/bash-completion/bpftool
tools/bpf/bpftool/cgroup.c
tools/bpf/bpftool/main.h
tools/bpf/bpftool/prog.c

index d80fdde79c229ddd1bc2b04d70cbf967607710d4..585f270c2d25db90fceb0ab6d815e3fdf5c65585 100644 (file)
@@ -29,7 +29,8 @@ CGROUP COMMANDS
 |      *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
 |      *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** |
 |              **bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** |
-|              **sendmsg4** | **sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** }
+|              **sendmsg4** | **sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** |
+|              **getsockopt** | **setsockopt** }
 |      *ATTACH_FLAGS* := { **multi** | **override** }
 
 DESCRIPTION
@@ -90,7 +91,9 @@ DESCRIPTION
                   an unconnected udp4 socket (since 5.2);
                  **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
                   an unconnected udp6 socket (since 5.2);
-                 **sysctl** sysctl access (since 5.2).
+                 **sysctl** sysctl access (since 5.2);
+                 **getsockopt** call to getsockopt (since 5.3);
+                 **setsockopt** call to setsockopt (since 5.3).
 
        **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
                  Detach *PROG* from the cgroup *CGROUP* and attach type
index 55dd06517a3ba23b0690bc3cb5ab982b9845b89c..1df637f85f9436dbac1662274f691dd7fefd67cd 100644 (file)
@@ -40,7 +40,8 @@ PROG COMMANDS
 |              **lwt_seg6local** | **sockops** | **sk_skb** | **sk_msg** | **lirc_mode2** |
 |              **cgroup/bind4** | **cgroup/bind6** | **cgroup/post_bind4** | **cgroup/post_bind6** |
 |              **cgroup/connect4** | **cgroup/connect6** | **cgroup/sendmsg4** | **cgroup/sendmsg6** |
-|              **cgroup/recvmsg4** | **cgroup/recvmsg6** | **cgroup/sysctl**
+|              **cgroup/recvmsg4** | **cgroup/recvmsg6** | **cgroup/sysctl** |
+|              **cgroup/getsockopt** | **cgroup/setsockopt**
 |      }
 |       *ATTACH_TYPE* := {
 |              **msg_verdict** | **stream_verdict** | **stream_parser** | **flow_dissector**
index a17e84c67498aaa79fd3774c205566edf7f64b14..ba37095e1f62e64b2ebcb7d7c51c6ad8d48d22a2 100644 (file)
@@ -379,7 +379,8 @@ _bpftool()
                                 cgroup/sendmsg4 cgroup/sendmsg6 \
                                 cgroup/recvmsg4 cgroup/recvmsg6 \
                                 cgroup/post_bind4 cgroup/post_bind6 \
-                                cgroup/sysctl" -- \
+                                cgroup/sysctl cgroup/getsockopt \
+                                cgroup/setsockopt" -- \
                                                    "$cur" ) )
                             return 0
                             ;;
@@ -689,7 +690,8 @@ _bpftool()
                 attach|detach)
                     local ATTACH_TYPES='ingress egress sock_create sock_ops \
                         device bind4 bind6 post_bind4 post_bind6 connect4 \
-                        connect6 sendmsg4 sendmsg6 recvmsg4 recvmsg6 sysctl'
+                        connect6 sendmsg4 sendmsg6 recvmsg4 recvmsg6 sysctl \
+                        getsockopt setsockopt'
                     local ATTACH_FLAGS='multi override'
                     local PROG_TYPE='id pinned tag'
                     case $prev in
@@ -699,7 +701,8 @@ _bpftool()
                             ;;
                         ingress|egress|sock_create|sock_ops|device|bind4|bind6|\
                         post_bind4|post_bind6|connect4|connect6|sendmsg4|\
-                        sendmsg6|recvmsg4|recvmsg6|sysctl)
+                        sendmsg6|recvmsg4|recvmsg6|sysctl|getsockopt|\
+                        setsockopt)
                             COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
                                 "$cur" ) )
                             return 0
index 73ec8ea33fb43af8f4286e2dfd4361eb4672fd07..390b89a224f1d43542424196364ed5228a688c1f 100644 (file)
@@ -26,7 +26,8 @@
        "                        sock_ops | device | bind4 | bind6 |\n"        \
        "                        post_bind4 | post_bind6 | connect4 |\n"       \
        "                        connect6 | sendmsg4 | sendmsg6 |\n"           \
-       "                        recvmsg4 | recvmsg6 | sysctl }"
+       "                        recvmsg4 | recvmsg6 | sysctl |\n"             \
+       "                        getsockopt | setsockopt }"
 
 static const char * const attach_type_strings[] = {
        [BPF_CGROUP_INET_INGRESS] = "ingress",
@@ -45,6 +46,8 @@ static const char * const attach_type_strings[] = {
        [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,
 };
 
index 28a2a5857e141ec3fa5ceece0257d59b62e58a7f..9c5d9c80f71ed915590d72a8bdd86096622f590e 100644 (file)
@@ -74,6 +74,7 @@ static const char * const prog_type_name[] = {
        [BPF_PROG_TYPE_SK_REUSEPORT]            = "sk_reuseport",
        [BPF_PROG_TYPE_FLOW_DISSECTOR]          = "flow_dissector",
        [BPF_PROG_TYPE_CGROUP_SYSCTL]           = "cgroup_sysctl",
+       [BPF_PROG_TYPE_CGROUP_SOCKOPT]          = "cgroup_sockopt",
 };
 
 extern const char * const map_type_name[];
index f1a831f05010a381828649dd625e4728132984fc..9b0db5d14e31adbfdc98f680d60334bd25b2292e 100644 (file)
@@ -1071,7 +1071,8 @@ static int do_help(int argc, char **argv)
                "                 cgroup/bind4 | cgroup/bind6 | cgroup/post_bind4 |\n"
                "                 cgroup/post_bind6 | cgroup/connect4 | cgroup/connect6 |\n"
                "                 cgroup/sendmsg4 | cgroup/sendmsg6 | cgroup/recvmsg4 |\n"
-               "                 cgroup/recvmsg6 }\n"
+               "                 cgroup/recvmsg6 | cgroup/getsockopt |\n"
+               "                 cgroup/setsockopt }\n"
                "       ATTACH_TYPE := { msg_verdict | stream_verdict | stream_parser |\n"
                "                        flow_dissector }\n"
                "       " HELP_SPEC_OPTIONS "\n"