]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
bpftool: Support sysctl hook
authorAndrey Ignatov <rdna@fb.com>
Tue, 16 Apr 2019 20:13:47 +0000 (13:13 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 17 Apr 2019 02:45:47 +0000 (19:45 -0700)
Add support for recently added BPF_PROG_TYPE_CGROUP_SYSCTL program type
and BPF_CGROUP_SYSCTL attach type.

Example of bpftool output with sysctl program from selftests:

  # bpftool p load ./test_sysctl_prog.o /mnt/bpf/sysctl_prog type cgroup/sysctl
  # bpftool p l
  9: cgroup_sysctl  name sysctl_tcp_mem  tag 0dd05f81a8d0d52e  gpl
          loaded_at 2019-04-16T12:57:27-0700  uid 0
          xlated 1008B  jited 623B  memlock 4096B
  # bpftool c a /mnt/cgroup2/bla sysctl id 9
  # bpftool c t
  CgroupPath
  ID       AttachType      AttachFlags     Name
  /mnt/cgroup2/bla
      9        sysctl                          sysctl_tcp_mem
  # bpftool c d /mnt/cgroup2/bla sysctl id 9
  # bpftool c t
  CgroupPath
  ID       AttachType      AttachFlags     Name

Signed-off-by: Andrey Ignatov <rdna@fb.com>
Acked-by: Song Liu <songliubraving@fb.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.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 5e3b7d9d75997c2e703db16b230fffda32ff15b0..89b6b10e21835f1a52b4708b2b88073b8a91bd2e 100644 (file)
@@ -29,7 +29,7 @@ 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** }
+|              **sendmsg4** | **sendmsg6** | **sysctl** }
 |      *ATTACH_FLAGS* := { **multi** | **override** }
 
 DESCRIPTION
@@ -85,7 +85,8 @@ DESCRIPTION
                  **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
                  unconnected udp4 socket (since 4.18);
                  **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
-                 unconnected udp6 socket (since 4.18).
+                 unconnected udp6 socket (since 4.18);
+                 **sysctl** sysctl access (since 5.2).
 
        **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
                  Detach *PROG* from the cgroup *CGROUP* and attach type
index bb9bb00c0c2c3dfa6b6544a4e90b2da65bd83b14..2f183ffd8351ed412209642ed65db158de5be840 100644 (file)
@@ -39,7 +39,8 @@ PROG COMMANDS
 |              **cgroup/sock** | **cgroup/dev** | **lwt_in** | **lwt_out** | **lwt_xmit** |
 |              **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/connect4** | **cgroup/connect6** | **cgroup/sendmsg4** | **cgroup/sendmsg6** |
+|              **cgroup/sysctl**
 |      }
 |       *ATTACH_TYPE* := {
 |              **msg_verdict** | **stream_verdict** | **stream_parser** | **flow_dissector**
index b803827d01e8843941d40de02e819a3af8eee079..9f3ffe1e26ab6480ac74f62ca2cd748fa328f5d4 100644 (file)
@@ -370,7 +370,8 @@ _bpftool()
                                 lirc_mode2 cgroup/bind4 cgroup/bind6 \
                                 cgroup/connect4 cgroup/connect6 \
                                 cgroup/sendmsg4 cgroup/sendmsg6 \
-                                cgroup/post_bind4 cgroup/post_bind6" -- \
+                                cgroup/post_bind4 cgroup/post_bind6 \
+                                cgroup/sysctl" -- \
                                                    "$cur" ) )
                             return 0
                             ;;
@@ -619,7 +620,7 @@ _bpftool()
                 attach|detach)
                     local ATTACH_TYPES='ingress egress sock_create sock_ops \
                         device bind4 bind6 post_bind4 post_bind6 connect4 \
-                        connect6 sendmsg4 sendmsg6'
+                        connect6 sendmsg4 sendmsg6 sysctl'
                     local ATTACH_FLAGS='multi override'
                     local PROG_TYPE='id pinned tag'
                     case $prev in
@@ -629,7 +630,7 @@ _bpftool()
                             ;;
                         ingress|egress|sock_create|sock_ops|device|bind4|bind6|\
                         post_bind4|post_bind6|connect4|connect6|sendmsg4|\
-                        sendmsg6)
+                        sendmsg6|sysctl)
                             COMPREPLY=( $( compgen -W "$PROG_TYPE" -- \
                                 "$cur" ) )
                             return 0
index a81b34343eb8d357aac6c4dfcb553e785973dcb9..7e22f115c8c1af352984961a3a6c0dc336d4b864 100644 (file)
@@ -25,7 +25,7 @@
        "       ATTACH_TYPE := { ingress | egress | sock_create |\n"           \
        "                        sock_ops | device | bind4 | bind6 |\n"        \
        "                        post_bind4 | post_bind6 | connect4 |\n"       \
-       "                        connect6 | sendmsg4 | sendmsg6 }"
+       "                        connect6 | sendmsg4 | sendmsg6 | sysctl }"
 
 static const char * const attach_type_strings[] = {
        [BPF_CGROUP_INET_INGRESS] = "ingress",
@@ -41,6 +41,7 @@ static const char * const attach_type_strings[] = {
        [BPF_CGROUP_INET6_POST_BIND] = "post_bind6",
        [BPF_CGROUP_UDP4_SENDMSG] = "sendmsg4",
        [BPF_CGROUP_UDP6_SENDMSG] = "sendmsg6",
+       [BPF_CGROUP_SYSCTL] = "sysctl",
        [__MAX_BPF_ATTACH_TYPE] = NULL,
 };
 
index d7dd84d3c660eb62b60f2d762fb0e74a5524ff42..1ccc46169a1957627694469c035d0cf78a723c89 100644 (file)
@@ -73,6 +73,7 @@ static const char * const prog_type_name[] = {
        [BPF_PROG_TYPE_LIRC_MODE2]              = "lirc_mode2",
        [BPF_PROG_TYPE_SK_REUSEPORT]            = "sk_reuseport",
        [BPF_PROG_TYPE_FLOW_DISSECTOR]          = "flow_dissector",
+       [BPF_PROG_TYPE_CGROUP_SYSCTL]           = "cgroup_sysctl",
 };
 
 extern const char * const map_type_name[];
index 4b7a307b9fc9bbeea4ecb0971395b78516766ff8..fc495b27f0fcb98cd852f08c7cc6523bd54a9925 100644 (file)
@@ -1060,7 +1060,7 @@ static int do_help(int argc, char **argv)
                "                 tracepoint | raw_tracepoint | xdp | perf_event | cgroup/skb |\n"
                "                 cgroup/sock | cgroup/dev | lwt_in | lwt_out | lwt_xmit |\n"
                "                 lwt_seg6local | sockops | sk_skb | sk_msg | lirc_mode2 |\n"
-               "                 sk_reuseport | flow_dissector |\n"
+               "                 sk_reuseport | flow_dissector | cgroup/sysctl |\n"
                "                 cgroup/bind4 | cgroup/bind6 | cgroup/post_bind4 |\n"
                "                 cgroup/post_bind6 | cgroup/connect4 | cgroup/connect6 |\n"
                "                 cgroup/sendmsg4 | cgroup/sendmsg6 }\n"