1.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2
3================
4bpftool-cgroup
5================
6-------------------------------------------------------------------------------
7tool for inspection and simple manipulation of eBPF progs
8-------------------------------------------------------------------------------
9
10:Manual section: 8
11
12.. include:: substitutions.rst
13
14SYNOPSIS
15========
16
17	**bpftool** [*OPTIONS*] **cgroup** *COMMAND*
18
19	*OPTIONS* := { |COMMON_OPTIONS| | { **-f** | **--bpffs** } }
20
21	*COMMANDS* :=
22	{ **show** | **list** | **tree** | **attach** | **detach** | **help** }
23
24CGROUP COMMANDS
25===============
26
27|	**bpftool** **cgroup** { **show** | **list** } *CGROUP* [**effective**]
28|	**bpftool** **cgroup tree** [*CGROUP_ROOT*] [**effective**]
29|	**bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
30|	**bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
31|	**bpftool** **cgroup help**
32|
33|	*PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
34|	*ATTACH_TYPE* := { **cgroup_inet_ingress** | **cgroup_inet_egress** |
35|		**cgroup_inet_sock_create** | **cgroup_sock_ops** |
36|		**cgroup_device** | **cgroup_inet4_bind** | **cgroup_inet6_bind** |
37|		**cgroup_inet4_post_bind** | **cgroup_inet6_post_bind** |
38|		**cgroup_inet4_connect** | **cgroup_inet6_connect** |
39|		**cgroup_inet4_getpeername** | **cgroup_inet6_getpeername** |
40|		**cgroup_inet4_getsockname** | **cgroup_inet6_getsockname** |
41|		**cgroup_udp4_sendmsg** | **cgroup_udp6_sendmsg** |
42|		**cgroup_udp4_recvmsg** | **cgroup_udp6_recvmsg** |
43|		**cgroup_sysctl** | **cgroup_getsockopt** | **cgroup_setsockopt** |
44|		**cgroup_inet_sock_release** }
45|	*ATTACH_FLAGS* := { **multi** | **override** }
46
47DESCRIPTION
48===========
49	**bpftool cgroup { show | list }** *CGROUP* [**effective**]
50		  List all programs attached to the cgroup *CGROUP*.
51
52		  Output will start with program ID followed by attach type,
53		  attach flags and program name.
54
55		  If **effective** is specified retrieve effective programs that
56		  will execute for events within a cgroup. This includes
57		  inherited along with attached ones.
58
59	**bpftool cgroup tree** [*CGROUP_ROOT*] [**effective**]
60		  Iterate over all cgroups in *CGROUP_ROOT* and list all
61		  attached programs. If *CGROUP_ROOT* is not specified,
62		  bpftool uses cgroup v2 mountpoint.
63
64		  The output is similar to the output of cgroup show/list
65		  commands: it starts with absolute cgroup path, followed by
66		  program ID, attach type, attach flags and program name.
67
68		  If **effective** is specified retrieve effective programs that
69		  will execute for events within a cgroup. This includes
70		  inherited along with attached ones.
71
72	**bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
73		  Attach program *PROG* to the cgroup *CGROUP* with attach type
74		  *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
75
76		  *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
77		  some bpf program, the program in this cgroup yields to sub-cgroup
78		  program; **multi** if a sub-cgroup installs some bpf program,
79		  that cgroup program gets run in addition to the program in this
80		  cgroup.
81
82		  Only one program is allowed to be attached to a cgroup with
83		  no attach flags or the **override** flag. Attaching another
84		  program will release old program and attach the new one.
85
86		  Multiple programs are allowed to be attached to a cgroup with
87		  **multi**. They are executed in FIFO order (those that were
88		  attached first, run first).
89
90		  Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
91		  and later.
92
93		  *ATTACH_TYPE* can be on of:
94		  **ingress** ingress path of the inet socket (since 4.10);
95		  **egress** egress path of the inet socket (since 4.10);
96		  **sock_create** opening of an inet socket (since 4.10);
97		  **sock_ops** various socket operations (since 4.12);
98		  **device** device access (since 4.15);
99		  **bind4** call to bind(2) for an inet4 socket (since 4.17);
100		  **bind6** call to bind(2) for an inet6 socket (since 4.17);
101		  **post_bind4** return from bind(2) for an inet4 socket (since 4.17);
102		  **post_bind6** return from bind(2) for an inet6 socket (since 4.17);
103		  **connect4** call to connect(2) for an inet4 socket (since 4.17);
104		  **connect6** call to connect(2) for an inet6 socket (since 4.17);
105		  **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
106		  unconnected udp4 socket (since 4.18);
107		  **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
108		  unconnected udp6 socket (since 4.18);
109		  **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
110		  an unconnected udp4 socket (since 5.2);
111		  **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
112		  an unconnected udp6 socket (since 5.2);
113		  **sysctl** sysctl access (since 5.2);
114		  **getsockopt** call to getsockopt (since 5.3);
115		  **setsockopt** call to setsockopt (since 5.3);
116		  **getpeername4** call to getpeername(2) for an inet4 socket (since 5.8);
117		  **getpeername6** call to getpeername(2) for an inet6 socket (since 5.8);
118		  **getsockname4** call to getsockname(2) for an inet4 socket (since 5.8);
119		  **getsockname6** call to getsockname(2) for an inet6 socket (since 5.8).
120		  **sock_release** closing an userspace inet socket (since 5.9).
121
122	**bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
123		  Detach *PROG* from the cgroup *CGROUP* and attach type
124		  *ATTACH_TYPE*.
125
126	**bpftool prog help**
127		  Print short help message.
128
129OPTIONS
130=======
131	.. include:: common_options.rst
132
133	-f, --bpffs
134		  Show file names of pinned programs.
135
136EXAMPLES
137========
138|
139| **# mount -t bpf none /sys/fs/bpf/**
140| **# mkdir /sys/fs/cgroup/test.slice**
141| **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
142| **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
143
144**# bpftool cgroup list /sys/fs/cgroup/test.slice/**
145
146::
147
148    ID       AttachType      AttachFlags     Name
149    1        device          allow_multi     bpf_prog1
150
151|
152| **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
153| **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
154
155::
156
157    ID       AttachType      AttachFlags     Name
158