4 -------------------------------------------------------------------------------
5 tool for inspection and simple manipulation of eBPF progs
6 -------------------------------------------------------------------------------
13 **bpftool** [*OPTIONS*] **cgroup** *COMMAND*
15 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
18 { **show** | **list** | **tree** | **attach** | **detach** | **help** }
23 | **bpftool** **cgroup { show | list }** *CGROUP*
24 | **bpftool** **cgroup tree** [*CGROUP_ROOT*]
25 | **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
26 | **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
27 | **bpftool** **cgroup help**
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** |
32 | **sendmsg4** | **sendmsg6** }
33 | *ATTACH_FLAGS* := { **multi** | **override** }
37 **bpftool cgroup { show | list }** *CGROUP*
38 List all programs attached to the cgroup *CGROUP*.
40 Output will start with program ID followed by attach type,
41 attach flags and program name.
43 **bpftool cgroup tree** [*CGROUP_ROOT*]
44 Iterate over all cgroups in *CGROUP_ROOT* and list all
45 attached programs. If *CGROUP_ROOT* is not specified,
46 bpftool uses cgroup v2 mountpoint.
48 The output is similar to the output of cgroup show/list
49 commands: it starts with absolute cgroup path, followed by
50 program ID, attach type, attach flags and program name.
52 **bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
53 Attach program *PROG* to the cgroup *CGROUP* with attach type
54 *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
56 *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
57 some bpf program, the program in this cgroup yields to sub-cgroup
58 program; **multi** if a sub-cgroup installs some bpf program,
59 that cgroup program gets run in addition to the program in this
62 Only one program is allowed to be attached to a cgroup with
63 no attach flags or the **override** flag. Attaching another
64 program will release old program and attach the new one.
66 Multiple programs are allowed to be attached to a cgroup with
67 **multi**. They are executed in FIFO order (those that were
68 attached first, run first).
70 Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
73 *ATTACH_TYPE* can be on of:
74 **ingress** ingress path of the inet socket (since 4.10);
75 **egress** egress path of the inet socket (since 4.10);
76 **sock_create** opening of an inet socket (since 4.10);
77 **sock_ops** various socket operations (since 4.12);
78 **device** device access (since 4.15);
79 **bind4** call to bind(2) for an inet4 socket (since 4.17);
80 **bind6** call to bind(2) for an inet6 socket (since 4.17);
81 **post_bind4** return from bind(2) for an inet4 socket (since 4.17);
82 **post_bind6** return from bind(2) for an inet6 socket (since 4.17);
83 **connect4** call to connect(2) for an inet4 socket (since 4.17);
84 **connect6** call to connect(2) for an inet6 socket (since 4.17);
85 **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
86 unconnected udp4 socket (since 4.18);
87 **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
88 unconnected udp6 socket (since 4.18).
90 **bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
91 Detach *PROG* from the cgroup *CGROUP* and attach type
95 Print short help message.
100 Print short generic help message (similar to **bpftool help**).
103 Print version number (similar to **bpftool version**).
106 Generate JSON output. For commands that cannot produce JSON, this
107 option has no effect.
110 Generate human-readable JSON output. Implies **-j**.
113 Show file names of pinned programs.
118 | **# mount -t bpf none /sys/fs/bpf/**
119 | **# mkdir /sys/fs/cgroup/test.slice**
120 | **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
121 | **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
123 **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
127 ID AttachType AttachFlags Name
128 1 device allow_multi bpf_prog1
131 | **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
132 | **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
136 ID AttachType AttachFlags Name
140 **bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)