1BPFTOOL-CGROUP(8)                                            BPFTOOL-CGROUP(8)
2
3
4

NAME

6       bpftool-cgroup  -  tool  for inspection and simple manipulation of eBPF
7       progs
8

SYNOPSIS

10          bpftool [OPTIONS] cgroup COMMAND
11
12          OPTIONS := { { -j | --json } [{ -p | --pretty }] | { -d | --debug  }
13          | { -l | --legacy } | { -f | --bpffs } }
14
15          COMMANDS := { show | list | tree | attach | detach | help }
16

CGROUP COMMANDS

18       bpftool cgroup { show | list } CGROUP [effective]
19       bpftool cgroup tree [CGROUP_ROOT] [effective]
20       bpftool cgroup attach CGROUP ATTACH_TYPE PROG [ATTACH_FLAGS]
21       bpftool cgroup detach CGROUP ATTACH_TYPE PROG
22       bpftool cgroup help
23
24       PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }
25       ATTACH_TYPE := { cgroup_inet_ingress | cgroup_inet_egress |
26         cgroup_inet_sock_create | cgroup_sock_ops |
27         cgroup_device | cgroup_inet4_bind | cgroup_inet6_bind |
28         cgroup_inet4_post_bind | cgroup_inet6_post_bind |
29         cgroup_inet4_connect | cgroup_inet6_connect |
30         cgroup_inet4_getpeername | cgroup_inet6_getpeername |
31         cgroup_inet4_getsockname | cgroup_inet6_getsockname |
32         cgroup_udp4_sendmsg | cgroup_udp6_sendmsg |
33         cgroup_udp4_recvmsg | cgroup_udp6_recvmsg |
34         cgroup_sysctl | cgroup_getsockopt | cgroup_setsockopt |
35         cgroup_inet_sock_release }
36       ATTACH_FLAGS := { multi | override }
37
38

DESCRIPTION

40          bpftool cgroup { show | list } CGROUP [effective]
41                 List all programs attached to the cgroup CGROUP.
42
43                 Output  will  start  with program ID followed by attach type,
44                 attach flags and program name.
45
46                 If effective is specified retrieve  effective  programs  that
47                 will execute for events within a cgroup. This includes inher‐
48                 ited along with attached ones.
49
50          bpftool cgroup tree [CGROUP_ROOT] [effective]
51                 Iterate over all cgroups in CGROUP_ROOT and list all attached
52                 programs.  If  CGROUP_ROOT  is  not  specified,  bpftool uses
53                 cgroup v2 mountpoint.
54
55                 The output is similar to the output of cgroup show/list  com‐
56                 mands:  it starts with absolute cgroup path, followed by pro‐
57                 gram ID, attach type, attach flags and program name.
58
59                 If effective is specified retrieve  effective  programs  that
60                 will execute for events within a cgroup. This includes inher‐
61                 ited along with attached ones.
62
63          bpftool cgroup attach CGROUP ATTACH_TYPE PROG [ATTACH_FLAGS]
64                 Attach program PROG to the cgroup CGROUP with attach type AT‐
65                 TACH_TYPE and optional ATTACH_FLAGS.
66
67                 ATTACH_FLAGS can be one of: override if a sub-cgroup installs
68                 some bpf program,  the  program  in  this  cgroup  yields  to
69                 sub-cgroup  program;  multi if a sub-cgroup installs some bpf
70                 program, that cgroup program gets run in addition to the pro‐
71                 gram in this cgroup.
72
73                 Only  one  program is allowed to be attached to a cgroup with
74                 no attach flags or the override flag. Attaching another  pro‐
75                 gram will release old program and attach the new one.
76
77                 Multiple programs are allowed to be attached to a cgroup with
78                 multi. They are executed in FIFO order (those that  were  at‐
79                 tached first, run first).
80
81                 Non-default ATTACH_FLAGS are supported by kernel version 4.14
82                 and later.
83
84                 ATTACH_TYPE can be on of: ingress ingress path  of  the  inet
85                 socket  (since  4.10);  egress egress path of the inet socket
86                 (since 4.10); sock_create opening of an  inet  socket  (since
87                 4.10);  sock_ops  various socket operations (since 4.12); de‐
88                 vice device access (since 4.15); bind4 call to bind(2) for an
89                 inet4 socket (since 4.17); bind6 call to bind(2) for an inet6
90                 socket (since 4.17); post_bind4 return from  bind(2)  for  an
91                 inet4 socket (since 4.17); post_bind6 return from bind(2) for
92                 an inet6 socket (since 4.17); connect4 call to connect(2) for
93                 an inet4 socket (since 4.17); connect6 call to connect(2) for
94                 an inet6 socket (since 4.17);  sendmsg4  call  to  sendto(2),
95                 sendmsg(2), sendmmsg(2) for an unconnected udp4 socket (since
96                 4.18); sendmsg6 call to  sendto(2),  sendmsg(2),  sendmmsg(2)
97                 for an unconnected udp6 socket (since 4.18); recvmsg4 call to
98                 recvfrom(2), recvmsg(2), recvmmsg(2) for an unconnected  udp4
99                 socket (since 5.2); recvmsg6 call to recvfrom(2), recvmsg(2),
100                 recvmmsg(2) for  an  unconnected  udp6  socket  (since  5.2);
101                 sysctl sysctl access (since 5.2); getsockopt call to getsock‐
102                 opt (since 5.3); setsockopt call to setsockopt  (since  5.3);
103                 getpeername4  call  to  getpeername(2)  for  an  inet4 socket
104                 (since 5.8); getpeername6 call to getpeername(2) for an inet6
105                 socket  (since  5.8); getsockname4 call to getsockname(2) for
106                 an inet4 socket (since 5.8); getsockname6  call  to  getsock‐
107                 name(2)  for an inet6 socket (since 5.8).  sock_release clos‐
108                 ing an userspace inet socket (since 5.9).
109
110          bpftool cgroup detach CGROUP ATTACH_TYPE PROG
111                 Detach PROG from  the  cgroup  CGROUP  and  attach  type  AT‐
112                 TACH_TYPE.
113
114          bpftool prog help
115                 Print short help message.
116

OPTIONS

118          -h, --help
119                 Print short help message (similar to bpftool help).
120
121          -V, --version
122                 Print  bpftool's version number (similar to bpftool version),
123                 the number of the libbpf version in use,  and  optional  fea‐
124                 tures  that were included when bpftool was compiled. Optional
125                 features include linking against libbfd to provide the disas‐
126                 sembler  for  JIT-ted  programs (bpftool prog dump jited) and
127                 usage of BPF skeletons (some features like bpftool prog  pro‐
128                 file  or  showing  pids associated to BPF objects may rely on
129                 it).
130
131          -j, --json
132                 Generate JSON output. For commands that cannot produce  JSON,
133                 this option has no effect.
134
135          -p, --pretty
136                 Generate human-readable JSON output. Implies -j.
137
138          -d, --debug
139                 Print  all logs available, even debug-level information. This
140                 includes logs from libbpf as well as from the verifier,  when
141                 attempting to load programs.
142
143          -l, --legacy
144                 Use legacy libbpf mode which has more relaxed BPF program re‐
145                 quirements. By default, bpftool has more strict  requirements
146                 about  section  names, changes pinning logic and doesn't sup‐
147                 port some of the older non-BTF map declarations.
148
149                 See
150                 https://github.com/libbpf/libbpf/wiki/Libbpf:-the-road-to-v1.0
151                 for details.
152
153          -f, --bpffs
154                 Show file names of pinned programs.
155

EXAMPLES

157       # mount -t bpf none /sys/fs/bpf/
158       # mkdir /sys/fs/cgroup/test.slice
159       # bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog
160       # bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi
161
162
163       # bpftool cgroup list /sys/fs/cgroup/test.slice/
164
165          ID       AttachType      AttachFlags     Name
166          1        device          allow_multi     bpf_prog1
167
168       # bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1
169       # bpftool cgroup list /sys/fs/cgroup/test.slice/
170
171
172          ID       AttachType      AttachFlags     Name
173

SEE ALSO

175          bpf(2),  bpf-helpers(7),  bpftool(8),  bpftool-btf(8),  bpftool-fea‐
176          ture(8),     bpftool-gen(8),    bpftool-iter(8),    bpftool-link(8),
177          bpftool-map(8),  bpftool-net(8),  bpftool-perf(8),  bpftool-prog(8),
178          bpftool-struct_ops(8)
179
180
181
182
183                                                             BPFTOOL-CGROUP(8)
Impressum