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* := { **ingress** | **egress** | **sock_create** | **sock_ops** | **device** |
35|		**bind4** | **bind6** | **post_bind4** | **post_bind6** | **connect4** | **connect6** |
36|		**getpeername4** | **getpeername6** | **getsockname4** | **getsockname6** | **sendmsg4** |
37|		**sendmsg6** | **recvmsg4** | **recvmsg6** | **sysctl** | **getsockopt** | **setsockopt** |
38|		**sock_release** }
39|	*ATTACH_FLAGS* := { **multi** | **override** }
40
41DESCRIPTION
42===========
43	**bpftool cgroup { show | list }** *CGROUP* [**effective**]
44		  List all programs attached to the cgroup *CGROUP*.
45
46		  Output will start with program ID followed by attach type,
47		  attach flags and program name.
48
49		  If **effective** is specified retrieve effective programs that
50		  will execute for events within a cgroup. This includes
51		  inherited along with attached ones.
52
53	**bpftool cgroup tree** [*CGROUP_ROOT*] [**effective**]
54		  Iterate over all cgroups in *CGROUP_ROOT* and list all
55		  attached programs. If *CGROUP_ROOT* is not specified,
56		  bpftool uses cgroup v2 mountpoint.
57
58		  The output is similar to the output of cgroup show/list
59		  commands: it starts with absolute cgroup path, followed by
60		  program ID, attach type, attach flags and program name.
61
62		  If **effective** is specified retrieve effective programs that
63		  will execute for events within a cgroup. This includes
64		  inherited along with attached ones.
65
66	**bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
67		  Attach program *PROG* to the cgroup *CGROUP* with attach type
68		  *ATTACH_TYPE* and optional *ATTACH_FLAGS*.
69
70		  *ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
71		  some bpf program, the program in this cgroup yields to sub-cgroup
72		  program; **multi** if a sub-cgroup installs some bpf program,
73		  that cgroup program gets run in addition to the program in this
74		  cgroup.
75
76		  Only one program is allowed to be attached to a cgroup with
77		  no attach flags or the **override** flag. Attaching another
78		  program will release old program and attach the new one.
79
80		  Multiple programs are allowed to be attached to a cgroup with
81		  **multi**. They are executed in FIFO order (those that were
82		  attached first, run first).
83
84		  Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
85		  and later.
86
87		  *ATTACH_TYPE* can be on of:
88		  **ingress** ingress path of the inet socket (since 4.10);
89		  **egress** egress path of the inet socket (since 4.10);
90		  **sock_create** opening of an inet socket (since 4.10);
91		  **sock_ops** various socket operations (since 4.12);
92		  **device** device access (since 4.15);
93		  **bind4** call to bind(2) for an inet4 socket (since 4.17);
94		  **bind6** call to bind(2) for an inet6 socket (since 4.17);
95		  **post_bind4** return from bind(2) for an inet4 socket (since 4.17);
96		  **post_bind6** return from bind(2) for an inet6 socket (since 4.17);
97		  **connect4** call to connect(2) for an inet4 socket (since 4.17);
98		  **connect6** call to connect(2) for an inet6 socket (since 4.17);
99		  **sendmsg4** call to sendto(2), sendmsg(2), sendmmsg(2) for an
100		  unconnected udp4 socket (since 4.18);
101		  **sendmsg6** call to sendto(2), sendmsg(2), sendmmsg(2) for an
102		  unconnected udp6 socket (since 4.18);
103		  **recvmsg4** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
104		  an unconnected udp4 socket (since 5.2);
105		  **recvmsg6** call to recvfrom(2), recvmsg(2), recvmmsg(2) for
106		  an unconnected udp6 socket (since 5.2);
107		  **sysctl** sysctl access (since 5.2);
108		  **getsockopt** call to getsockopt (since 5.3);
109		  **setsockopt** call to setsockopt (since 5.3);
110		  **getpeername4** call to getpeername(2) for an inet4 socket (since 5.8);
111		  **getpeername6** call to getpeername(2) for an inet6 socket (since 5.8);
112		  **getsockname4** call to getsockname(2) for an inet4 socket (since 5.8);
113		  **getsockname6** call to getsockname(2) for an inet6 socket (since 5.8).
114		  **sock_release** closing an userspace inet socket (since 5.9).
115
116	**bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
117		  Detach *PROG* from the cgroup *CGROUP* and attach type
118		  *ATTACH_TYPE*.
119
120	**bpftool prog help**
121		  Print short help message.
122
123OPTIONS
124=======
125	.. include:: common_options.rst
126
127	-f, --bpffs
128		  Show file names of pinned programs.
129
130EXAMPLES
131========
132|
133| **# mount -t bpf none /sys/fs/bpf/**
134| **# mkdir /sys/fs/cgroup/test.slice**
135| **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
136| **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
137
138**# bpftool cgroup list /sys/fs/cgroup/test.slice/**
139
140::
141
142    ID       AttachType      AttachFlags     Name
143    1        device          allow_multi     bpf_prog1
144
145|
146| **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
147| **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
148
149::
150
151    ID       AttachType      AttachFlags     Name
152