Skip to content

Commit 5ccda64

Browse files
rgushchinborkmann
authored andcommitted
bpftool: implement cgroup bpf operations
This patch adds basic cgroup bpf operations to bpftool: cgroup list, attach and detach commands. Usage is described in the corresponding man pages, and examples are provided. Syntax: $ bpftool cgroup list CGROUP $ bpftool cgroup attach CGROUP ATTACH_TYPE PROG [ATTACH_FLAGS] $ bpftool cgroup detach CGROUP ATTACH_TYPE PROG Signed-off-by: Roman Gushchin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Daniel Borkmann <[email protected]> Cc: Jakub Kicinski <[email protected]> Cc: Martin KaFai Lau <[email protected]> Cc: Quentin Monnet <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Jakub Kicinski <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 49a086c commit 5ccda64

File tree

7 files changed

+434
-5
lines changed

7 files changed

+434
-5
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
================
2+
bpftool-cgroup
3+
================
4+
-------------------------------------------------------------------------------
5+
tool for inspection and simple manipulation of eBPF progs
6+
-------------------------------------------------------------------------------
7+
8+
:Manual section: 8
9+
10+
SYNOPSIS
11+
========
12+
13+
**bpftool** [*OPTIONS*] **cgroup** *COMMAND*
14+
15+
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16+
17+
*COMMANDS* :=
18+
{ **list** | **attach** | **detach** | **help** }
19+
20+
MAP COMMANDS
21+
=============
22+
23+
| **bpftool** **cgroup list** *CGROUP*
24+
| **bpftool** **cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
25+
| **bpftool** **cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
26+
| **bpftool** **cgroup help**
27+
|
28+
| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
29+
| *ATTACH_TYPE* := { *ingress* | *egress* | *sock_create* | *sock_ops* | *device* }
30+
| *ATTACH_FLAGS* := { *multi* | *override* }
31+
32+
DESCRIPTION
33+
===========
34+
**bpftool cgroup list** *CGROUP*
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+
**bpftool cgroup attach** *CGROUP* *ATTACH_TYPE* *PROG* [*ATTACH_FLAGS*]
41+
Attach program *PROG* to the cgroup *CGROUP* with attach type
42+
*ATTACH_TYPE* and optional *ATTACH_FLAGS*.
43+
44+
*ATTACH_FLAGS* can be one of: **override** if a sub-cgroup installs
45+
some bpf program, the program in this cgroup yields to sub-cgroup
46+
program; **multi** if a sub-cgroup installs some bpf program,
47+
that cgroup program gets run in addition to the program in this
48+
cgroup.
49+
50+
Only one program is allowed to be attached to a cgroup with
51+
no attach flags or the **override** flag. Attaching another
52+
program will release old program and attach the new one.
53+
54+
Multiple programs are allowed to be attached to a cgroup with
55+
**multi**. They are executed in FIFO order (those that were
56+
attached first, run first).
57+
58+
Non-default *ATTACH_FLAGS* are supported by kernel version 4.14
59+
and later.
60+
61+
*ATTACH_TYPE* can be on of:
62+
**ingress** ingress path of the inet socket (since 4.10);
63+
**egress** egress path of the inet socket (since 4.10);
64+
**sock_create** opening of an inet socket (since 4.10);
65+
**sock_ops** various socket operations (since 4.12);
66+
**device** device access (since 4.15).
67+
68+
**bpftool cgroup detach** *CGROUP* *ATTACH_TYPE* *PROG*
69+
Detach *PROG* from the cgroup *CGROUP* and attach type
70+
*ATTACH_TYPE*.
71+
72+
**bpftool prog help**
73+
Print short help message.
74+
75+
OPTIONS
76+
=======
77+
-h, --help
78+
Print short generic help message (similar to **bpftool help**).
79+
80+
-v, --version
81+
Print version number (similar to **bpftool version**).
82+
83+
-j, --json
84+
Generate JSON output. For commands that cannot produce JSON, this
85+
option has no effect.
86+
87+
-p, --pretty
88+
Generate human-readable JSON output. Implies **-j**.
89+
90+
-f, --bpffs
91+
Show file names of pinned programs.
92+
93+
EXAMPLES
94+
========
95+
|
96+
| **# mount -t bpf none /sys/fs/bpf/**
97+
| **# mkdir /sys/fs/cgroup/test.slice**
98+
| **# bpftool prog load ./device_cgroup.o /sys/fs/bpf/prog**
99+
| **# bpftool cgroup attach /sys/fs/cgroup/test.slice/ device id 1 allow_multi**
100+
101+
**# bpftool cgroup list /sys/fs/cgroup/test.slice/**
102+
103+
::
104+
105+
ID AttachType AttachFlags Name
106+
1 device allow_multi bpf_prog1
107+
108+
|
109+
| **# bpftool cgroup detach /sys/fs/cgroup/test.slice/ device id 1**
110+
| **# bpftool cgroup list /sys/fs/cgroup/test.slice/**
111+
112+
::
113+
114+
ID AttachType AttachFlags Name
115+
116+
SEE ALSO
117+
========
118+
**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-map**\ (8)

tools/bpf/bpftool/Documentation/bpftool-map.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,4 @@ EXAMPLES
128128
129129
SEE ALSO
130130
========
131-
**bpftool**\ (8), **bpftool-prog**\ (8)
131+
**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)

tools/bpf/bpftool/Documentation/bpftool-prog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,4 @@ EXAMPLES
155155

156156
SEE ALSO
157157
========
158-
**bpftool**\ (8), **bpftool-map**\ (8)
158+
**bpftool**\ (8), **bpftool-map**\ (8), **bpftool-cgroup**\ (8)

tools/bpf/bpftool/Documentation/bpftool.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SYNOPSIS
1616

1717
**bpftool** **version**
1818

19-
*OBJECT* := { **map** | **program** }
19+
*OBJECT* := { **map** | **program** | **cgroup** }
2020

2121
*OPTIONS* := { { **-V** | **--version** } | { **-h** | **--help** }
2222
| { **-j** | **--json** } [{ **-p** | **--pretty** }] }
@@ -28,6 +28,8 @@ SYNOPSIS
2828
*PROG-COMMANDS* := { **show** | **dump jited** | **dump xlated** | **pin**
2929
| **load** | **help** }
3030
31+
*CGROUP-COMMANDS* := { **list** | **attach** | **detach** | **help** }
32+
3133
DESCRIPTION
3234
===========
3335
*bpftool* allows for inspection and simple modification of BPF objects
@@ -53,4 +55,4 @@ OPTIONS
5355

5456
SEE ALSO
5557
========
56-
**bpftool-map**\ (8), **bpftool-prog**\ (8)
58+
**bpftool-map**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)

0 commit comments

Comments
 (0)