]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - tools/bpf/bpftool/Documentation/bpftool-prog.rst
tools: libbpf: allow map reuse
[thirdparty/kernel/stable.git] / tools / bpf / bpftool / Documentation / bpftool-prog.rst
CommitLineData
ff69c21a
JK
1================
2bpftool-prog
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF progs
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
0641c3c8
QM
13 **bpftool** [*OPTIONS*] **prog** *COMMAND*
14
c541b734 15 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
0641c3c8
QM
16
17 *COMMANDS* :=
6ebe6dbd 18 { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** | **help** }
0641c3c8
QM
19
20MAP COMMANDS
21=============
22
6ebe6dbd 23| **bpftool** **prog { show | list }** [*PROG*]
b6c1cedb 24| **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual**}]
47ff7ac6
QM
25| **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
26| **bpftool** **prog pin** *PROG* *FILE*
49f2cba3 27| **bpftool** **prog load** *OBJ* *FILE* [**type** *TYPE*] [**dev** *NAME*]
47ff7ac6 28| **bpftool** **prog help**
ff69c21a 29|
47ff7ac6 30| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
49f2cba3
JK
31| *TYPE* := {
32| **socket** | **kprobe** | **kretprobe** | **classifier** | **action** |
33| **tracepoint** | **raw_tracepoint** | **xdp** | **perf_event** | **cgroup/skb** |
34| **cgroup/sock** | **cgroup/dev** | **lwt_in** | **lwt_out** | **lwt_xmit** |
35| **lwt_seg6local** | **sockops** | **sk_skb** | **sk_msg** | **lirc_mode2** |
36| **cgroup/bind4** | **cgroup/bind6** | **cgroup/post_bind4** | **cgroup/post_bind6** |
37| **cgroup/connect4** | **cgroup/connect6** | **cgroup/sendmsg4** | **cgroup/sendmsg6**
38| }
39
ff69c21a
JK
40
41DESCRIPTION
42===========
6ebe6dbd 43 **bpftool prog { show | list }** [*PROG*]
ff69c21a
JK
44 Show information about loaded programs. If *PROG* is
45 specified show information only about given program, otherwise
46 list all programs currently loaded on the system.
47
48 Output will start with program ID followed by program type and
49 zero or more named attributes (depending on kernel version).
50
b6c1cedb
JW
51 **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** }]
52 Dump eBPF instructions of the program from the kernel. By
53 default, eBPF will be disassembled and printed to standard
54 output in human-readable format. In this case, **opcodes**
55 controls if raw opcodes should be printed as well.
c9c35995 56
b6c1cedb
JW
57 If **file** is specified, the binary image will instead be
58 written to *FILE*.
59
60 If **visual** is specified, control flow graph (CFG) will be
61 built instead, and eBPF instructions will be presented with
62 CFG in DOT format, on standard output.
ff69c21a 63
8dfbc6d1 64 **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }]
ff69c21a
JK
65 Dump jited image (host machine code) of the program.
66 If *FILE* is specified image will be written to a file,
67 otherwise it will be disassembled and printed to stdout.
68
69 **opcodes** controls if raw opcodes will be printed.
70
71 **bpftool prog pin** *PROG* *FILE*
72 Pin program *PROG* as *FILE*.
73
74 Note: *FILE* must be located in *bpffs* mount.
75
49f2cba3 76 **bpftool prog load** *OBJ* *FILE* [**type** *TYPE*] [**dev** *NAME*]
49a086c2 77 Load bpf program from binary *OBJ* and pin as *FILE*.
49f2cba3
JK
78 **type** is optional, if not specified program type will be
79 inferred from section names.
ba6dd679
JK
80 If **dev** *NAME* is specified program will be loaded onto
81 given networking device (offload).
49a086c2
RG
82
83 Note: *FILE* must be located in *bpffs* mount.
84
ff69c21a
JK
85 **bpftool prog help**
86 Print short help message.
87
a2bc2e5c
QM
88OPTIONS
89=======
90 -h, --help
91 Print short generic help message (similar to **bpftool help**).
92
93 -v, --version
94 Print version number (similar to **bpftool version**).
95
0641c3c8
QM
96 -j, --json
97 Generate JSON output. For commands that cannot produce JSON, this
98 option has no effect.
99
100 -p, --pretty
101 Generate human-readable JSON output. Implies **-j**.
102
c541b734
PB
103 -f, --bpffs
104 Show file names of pinned programs.
105
ff69c21a
JK
106EXAMPLES
107========
108**# bpftool prog show**
109::
110
9b984a20 111 10: xdp name some_prog tag 005a3d2123620c8b gpl
ff69c21a
JK
112 loaded_at Sep 29/20:11 uid 0
113 xlated 528B jited 370B memlock 4096B map_ids 10
114
0641c3c8
QM
115**# bpftool --json --pretty prog show**
116
117::
118
119 {
120 "programs": [{
121 "id": 10,
122 "type": "xdp",
123 "tag": "005a3d2123620c8b",
9b984a20 124 "gpl_compatible": true,
0641c3c8
QM
125 "loaded_at": "Sep 29/20:11",
126 "uid": 0,
127 "bytes_xlated": 528,
128 "jited": true,
129 "bytes_jited": 370,
130 "bytes_memlock": 4096,
131 "map_ids": [10
132 ]
133 }
134 ]
135 }
136
ff69c21a
JK
137|
138| **# bpftool prog dump xlated id 10 file /tmp/t**
139| **# ls -l /tmp/t**
140| -rw------- 1 root root 560 Jul 22 01:42 /tmp/t
141
0641c3c8 142**# bpftool prog dum jited tag 005a3d2123620c8b**
ff69c21a
JK
143
144::
145
146 push %rbp
147 mov %rsp,%rbp
148 sub $0x228,%rsp
149 sub $0x28,%rbp
150 mov %rbx,0x0(%rbp)
151
0641c3c8
QM
152|
153| **# mount -t bpf none /sys/fs/bpf/**
154| **# bpftool prog pin id 10 /sys/fs/bpf/prog**
49a086c2 155| **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2**
0641c3c8
QM
156| **# ls -l /sys/fs/bpf/**
157| -rw------- 1 root root 0 Jul 22 01:43 prog
49a086c2 158| -rw------- 1 root root 0 Jul 22 01:44 prog2
0641c3c8
QM
159
160**# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes**
161
162::
163
164 push %rbp
165 55
166 mov %rsp,%rbp
167 48 89 e5
168 sub $0x228,%rsp
169 48 81 ec 28 02 00 00
170 sub $0x28,%rbp
171 48 83 ed 28
172 mov %rbx,0x0(%rbp)
173 48 89 5d 00
ff69c21a
JK
174
175
176SEE ALSO
177========
5ccda64d 178 **bpftool**\ (8), **bpftool-map**\ (8), **bpftool-cgroup**\ (8)