Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | ================ |
| 2 | bpftool-cgroup |
| 3 | ================ |
| 4 | ------------------------------------------------------------------------------- |
| 5 | tool for inspection and simple manipulation of eBPF progs |
| 6 | ------------------------------------------------------------------------------- |
| 7 | |
| 8 | :Manual section: 8 |
| 9 | |
| 10 | SYNOPSIS |
| 11 | ======== |
| 12 | |
| 13 | **bpftool** [*OPTIONS*] **cgroup** *COMMAND* |
| 14 | |
| 15 | *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } |
| 16 | |
| 17 | *COMMANDS* := |
| 18 | { **show** | **list** | **tree** | **attach** | **detach** | **help** } |
| 19 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 20 | CGROUP COMMANDS |
| 21 | =============== |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 22 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 23 | | **bpftool** **cgroup { show | list }** *CGROUP* [**effective**] |
| 24 | | **bpftool** **cgroup tree** [*CGROUP_ROOT*] [**effective**] |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 25 | | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*] |
| 26 | | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG* |
| 27 | | **bpftool** **cgroup help** |
| 28 | | |
| 29 | | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } |
| 30 | | *ATTACH_TYPE* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** | |
| 31 | | **bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 32 | | **sendmsg4** | **sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** | |
| 33 | | **getsockopt** | **setsockopt** } |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 34 | | *ATTACH_FLAGS* := { **multi** | **override** } |
| 35 | |
| 36 | DESCRIPTION |
| 37 | =========== |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 38 | **bpftool cgroup { show | list }** *CGROUP* [**effective**] |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 39 | List all programs attached to the cgroup *CGROUP*. |
| 40 | |
| 41 | Output will start with program ID followed by attach type, |
| 42 | attach flags and program name. |
| 43 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 44 | If **effective** is specified retrieve effective programs that |
| 45 | will execute for events within a cgroup. This includes |
| 46 | inherited along with attached ones. |
| 47 | |
| 48 | **bpftool cgroup tree** [*CGROUP_ROOT*] [**effective**] |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 49 | Iterate over all cgroups in *CGROUP_ROOT* and list all |
| 50 | attached programs. If *CGROUP_ROOT* is not specified, |
| 51 | bpftool uses cgroup v2 mountpoint. |
| 52 | |
| 53 | The output is similar to the output of cgroup show/list |
| 54 | commands: it starts with absolute cgroup path, followed by |
| 55 | program ID, attach type, attach flags and program name. |
| 56 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 57 | If **effective** is specified retrieve effective programs that |
| 58 | will execute for events within a cgroup. This includes |
| 59 | inherited along with attached ones. |
| 60 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 61 | **bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*] |
| 62 | Attach program *PROG* to the cgroup *CGROUP* with attach type |
| 63 | *ATTACH_TYPE* and optional *ATTACH_FLAGS*. |
| 64 | |
| 65 | *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs |
| 66 | some bpf program, the program in this cgroup yields to sub-cgroup |
| 67 | program; **multi** if a sub-cgroup installs some bpf program, |
| 68 | that cgroup program gets run in addition to the program in this |
| 69 | cgroup. |
| 70 | |
| 71 | Only one program is allowed to be attached to a cgroup with |
| 72 | no attach flags or the **override** flag. Attaching another |
| 73 | program will release old program and attach the new one. |
| 74 | |
| 75 | Multiple programs are allowed to be attached to a cgroup with |
| 76 | **multi**. They are executed in FIFO order (those that were |
| 77 | attached first, run first). |
| 78 | |
| 79 | Non-default *ATTACH_FLAGS* are supported by kernel version 4.14 |
| 80 | and later. |
| 81 | |
| 82 | *ATTACH_TYPE* can be on of: |
| 83 | **ingress** ingress path of the inet socket (since 4.10); |
| 84 | **egress** egress path of the inet socket (since 4.10); |
| 85 | **sock_create** opening of an inet socket (since 4.10); |
| 86 | **sock_ops** various socket operations (since 4.12); |
| 87 | **device** device access (since 4.15); |
| 88 | **bind4** call to bind(2) for an inet4 socket (since 4.17); |
| 89 | **bind6** call to bind(2) for an inet6 socket (since 4.17); |
| 90 | **post_bind4** return from bind(2) for an inet4 socket (since 4.17); |
| 91 | **post_bind6** return from bind(2) for an inet6 socket (since 4.17); |
| 92 | **connect4** call to connect(2) for an inet4 socket (since 4.17); |
| 93 | **connect6** call to connect(2) for an inet6 socket (since 4.17); |
| 94 | **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an |
| 95 | unconnected udp4 socket (since 4.18); |
| 96 | **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 97 | unconnected udp6 socket (since 4.18); |
| 98 | **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for |
| 99 | an unconnected udp4 socket (since 5.2); |
| 100 | **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for |
| 101 | an unconnected udp6 socket (since 5.2); |
| 102 | **sysctl** sysctl access (since 5.2); |
| 103 | **getsockopt** call to getsockopt (since 5.3); |
| 104 | **setsockopt** call to setsockopt (since 5.3). |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 105 | |
| 106 | **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG* |
| 107 | Detach *PROG* from the cgroup *CGROUP* and attach type |
| 108 | *ATTACH_TYPE*. |
| 109 | |
| 110 | **bpftool prog help** |
| 111 | Print short help message. |
| 112 | |
| 113 | OPTIONS |
| 114 | ======= |
| 115 | -h, --help |
| 116 | Print short generic help message (similar to **bpftool help**). |
| 117 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 118 | -V, --version |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 119 | Print version number (similar to **bpftool version**). |
| 120 | |
| 121 | -j, --json |
| 122 | Generate JSON output. For commands that cannot produce JSON, this |
| 123 | option has no effect. |
| 124 | |
| 125 | -p, --pretty |
| 126 | Generate human-readable JSON output. Implies **-j**. |
| 127 | |
| 128 | -f, --bpffs |
| 129 | Show file names of pinned programs. |
| 130 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 131 | -d, --debug |
| 132 | Print all logs available from libbpf, including debug-level |
| 133 | information. |
| 134 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 135 | EXAMPLES |
| 136 | ======== |
| 137 | | |
| 138 | | **# mount -t bpf none /sys/fs/bpf/** |
| 139 | | **# mkdir /sys/fs/cgroup/test.slice** |
| 140 | | **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog** |
| 141 | | **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi** |
| 142 | |
| 143 | **# bpftool cgroup list /sys/fs/cgroup/test.slice/** |
| 144 | |
| 145 | :: |
| 146 | |
| 147 | ID AttachType AttachFlags Name |
| 148 | 1 device allow_multi bpf_prog1 |
| 149 | |
| 150 | | |
| 151 | | **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1** |
| 152 | | **# bpftool cgroup list /sys/fs/cgroup/test.slice/** |
| 153 | |
| 154 | :: |
| 155 | |
| 156 | ID AttachType AttachFlags Name |
| 157 | |
| 158 | SEE ALSO |
| 159 | ======== |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 160 | **bpf**\ (2), |
| 161 | **bpf-helpers**\ (7), |
| 162 | **bpftool**\ (8), |
| 163 | **bpftool-prog**\ (8), |
| 164 | **bpftool-map**\ (8), |
| 165 | **bpftool-feature**\ (8), |
| 166 | **bpftool-net**\ (8), |
| 167 | **bpftool-perf**\ (8), |
| 168 | **bpftool-btf**\ (8) |