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 := { ingress | egress | sock_create | sock_ops | device |
26         bind4 | bind6 | post_bind4 | post_bind6 | connect4 | connect6 |
27         getpeername4 | getpeername6 | getsockname4 | getsockname6 | sendmsg4 |
28         sendmsg6 | recvmsg4 | recvmsg6 | sysctl | getsockopt | setsockopt |
29         sock_release }
30       ATTACH_FLAGS := { multi | override }
31
32

DESCRIPTION

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

OPTIONS

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

EXAMPLES

151       # mount -t bpf none /sys/fs/bpf/
152       # mkdir /sys/fs/cgroup/test.slice
153       # bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog
154       # bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi
155
156
157       # bpftool cgroup list /sys/fs/cgroup/test.slice/
158
159          ID       AttachType      AttachFlags     Name
160          1        device          allow_multi     bpf_prog1
161
162       # bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1
163       # bpftool cgroup list /sys/fs/cgroup/test.slice/
164
165
166          ID       AttachType      AttachFlags     Name
167

SEE ALSO

169          bpf(2),  bpf-helpers(7),  bpftool(8),  bpftool-btf(8),  bpftool-fea‐
170          ture(8),     bpftool-gen(8),    bpftool-iter(8),    bpftool-link(8),
171          bpftool-map(8),  bpftool-net(8),  bpftool-perf(8),  bpftool-prog(8),
172          bpftool-struct_ops(8)
173
174
175
176
177                                                             BPFTOOL-CGROUP(8)
Impressum