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