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

NAME

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

SYNOPSIS

10          bpftool [OPTIONS] prog COMMAND
11
12          OPTIONS := { { -j | --json } [{ -p | --pretty }] | { -f | --bpffs  }
13          }
14
15          COMMANDS  := { show | list | dump xlated | dump jited | pin | load |
16          loadall | help }
17

PROG COMMANDS

19       bpftool prog { show | list } [PROG]
20       bpftool prog dump xlated PROG [{file FILE | opcodes | visual | linum}]
21       bpftool prog dump jited  PROG [{file FILE | opcodes | linum}]
22       bpftool prog pin PROG FILE
23       bpftool prog { load | loadall } OBJ PATH [type TYPE] [map {idx IDX | name NAME} MAP] [dev NAME] [pinmaps MAP_DIR]
24       bpftool prog attach PROG ATTACH_TYPE [MAP]
25       bpftool prog detach PROG ATTACH_TYPE [MAP]
26       bpftool prog tracelog
27       bpftool prog run PROG data_in FILE [data_out FILE [data_size_out L]] [ctx_in FILE [ctx_out FILE [ctx_size_out M]]] [repeat N]
28       bpftool prog help
29
30       MAP := { id MAP_ID | pinned FILE }
31       PROG := { id PROG_ID | pinned FILE | tag PROG_TAG }
32       TYPE := {
33         socket | kprobe | kretprobe | classifier | action |
34         tracepoint | raw_tracepoint | xdp | perf_event | cgroup/skb |
35         cgroup/sock | cgroup/dev | lwt_in | lwt_out | lwt_xmit |
36         lwt_seg6local | sockops | sk_skb | sk_msg | lirc_mode2 |
37         cgroup/bind4 | cgroup/bind6 | cgroup/post_bind4 | cgroup/post_bind6 |
38         cgroup/connect4 | cgroup/connect6 | cgroup/sendmsg4 | cgroup/sendmsg6 |
39         cgroup/recvmsg4 | cgroup/recvmsg6 | cgroup/sysctl |
40         cgroup/getsockopt | cgroup/setsockopt
41       }
42       ATTACH_TYPE := {
43         msg_verdict | stream_verdict | stream_parser | flow_dissector
44       }
45
46

DESCRIPTION

48          bpftool prog { show | list } [PROG]
49                 Show information about loaded programs.  If PROG is specified
50                 show information only about given program, otherwise list all
51                 programs currently loaded on the system.
52
53                 Output will start with program ID followed  by  program  type
54                 and  zero  or more named attributes (depending on kernel ver‐
55                 sion).
56
57                 Since Linux 5.1 the kernel can collect statistics on BPF pro‐
58                 grams  (such as the total time spent running the program, and
59                 the number of times it was run). If available, bpftool  shows
60                 such statistics. However, the kernel does not collect them by
61                 defaults, as it slightly impacts performance on each  program
62                 run.  Activation  or deactivation of the feature is performed
63                 via the kernel.bpf_stats_enabled sysctl knob.
64
65          bpftool prog dump xlated PROG [{ file FILE  |  opcodes  |  visual  |
66          linum }]
67                 Dump  eBPF  instructions  of  the program from the kernel. By
68                 default, eBPF will be disassembled and  printed  to  standard
69                 output  in  human-readable format. In this case, opcodes con‐
70                 trols if raw opcodes should be printed as well.
71
72                 If file is specified, the binary image will instead be  writ‐
73                 ten to FILE.
74
75                 If  visual  is  specified,  control  flow graph (CFG) will be
76                 built instead, and eBPF instructions will be  presented  with
77                 CFG in DOT format, on standard output.
78
79                 If  the prog has line_info available, the source line will be
80                 displayed by default.  If linum is specified,  the  filename,
81                 line  number and line column will also be displayed on top of
82                 the source line.
83
84          bpftool prog dump jited PROG [{ file FILE | opcodes | linum }]
85                 Dump jited image (host machine code) of the program.  If FILE
86                 is  specified  image  will be written to a file, otherwise it
87                 will be disassembled and printed to stdout.
88
89                 opcodes controls if raw opcodes will be printed.
90
91                 If the prog has line_info available, the source line will  be
92                 displayed  by  default.  If linum is specified, the filename,
93                 line number and line column will also be displayed on top  of
94                 the source line.
95
96          bpftool prog pin PROG FILE
97                 Pin program PROG as FILE.
98
99                 Note:  FILE  must be located in bpffs mount. It must not con‐
100                 tain a dot character ('.'),  which  is  reserved  for  future
101                 extensions of bpffs.
102
103          bpftool prog { load | loadall } OBJ PATH [type TYPE] [map {idx IDX |
104          name NAME} MAP] [dev NAME] [pinmaps MAP_DIR]
105                 Load bpf program(s) from binary OBJ and pin as PATH.  bpftool
106                 prog  load  pins only the first program from the OBJ as PATH.
107                 bpftool prog loadall pins all programs  from  the  OBJ  under
108                 PATH  directory.   type is optional, if not specified program
109                 type will be inferred from section names.  By default bpftool
110                 will  create  new  maps  as  declared in the ELF object being
111                 loaded.  map parameter allows for the reuse of existing maps.
112                 It can be specified multiple times, each time for a different
113                 map.  IDX refers to index of the map to be  replaced  in  the
114                 ELF  file counting from 0, while NAME allows to replace a map
115                 by name.  MAP specifies the map to use, referring to it by id
116                 or  through  a pinned file.  If dev NAME is specified program
117                 will  be  loaded  onto  given  networking  device  (offload).
118                 Optional  pinmaps  argument  can  be provided to pin all maps
119                 under MAP_DIR directory.
120
121                 Note: PATH must be located in bpffs mount. It must  not  con‐
122                 tain  a  dot  character  ('.'),  which is reserved for future
123                 extensions of bpffs.
124
125          bpftool prog attach PROG ATTACH_TYPE [MAP]
126                 Attach bpf program PROG (with type specified by ATTACH_TYPE).
127                 Most ATTACH_TYPEs require a MAP parameter, with the exception
128                 of flow_dissector which is  attached  to  current  networking
129                 name space.
130
131          bpftool prog detach PROG ATTACH_TYPE [MAP]
132                 Detach bpf program PROG (with type specified by ATTACH_TYPE).
133                 Most ATTACH_TYPEs require a MAP parameter, with the exception
134                 of flow_dissector which is detached from the current network‐
135                 ing name space.
136
137          bpftool prog tracelog
138                 Dump the trace pipe of the system to  the  console  (stdout).
139                 Hit <Ctrl+C> to stop printing. BPF programs can write to this
140                 trace pipe at runtime  with  the  bpf_trace_printk()  helper.
141                 This  should be used only for debugging purposes. For stream‐
142                 ing data from BPF programs to user space, one  can  use  perf
143                 events (see also bpftool-map(8)).
144
145          bpftool prog run PROG data_in FILE [data_out FILE [data_size_out L]]
146          [ctx_in FILE [ctx_out FILE [ctx_size_out M]]] [repeat N]
147                 Run BPF program PROG in the kernel testing infrastructure for
148                 BPF,  meaning  that the program works on the data and context
149                 provided by the user, and not on actual packets or  monitored
150                 functions etc. Return value and duration for the test run are
151                 printed out to the console.
152
153                 Input data is read from the FILE  passed  with  data_in.   If
154                 this  FILE  is  "-",  input data is read from standard input.
155                 Input context, if any, is read from FILE passed with  ctx_in.
156                 Again,  "-" can be used to read from standard input, but only
157                 if standard input is not already in use for input data. If  a
158                 FILE  is passed with data_out, output data is written to that
159                 file. Similarly, output context is written to the FILE passed
160                 with ctx_out. For both output flows, "-" can be used to print
161                 to the standard output (as plain text, or  JSON  if  relevant
162                 option  was  passed).  If output keywords are omitted, output
163                 data and context are discarded.  Keywords  data_size_out  and
164                 ctx_size_out  are  used  to  pass the size (in bytes) for the
165                 output buffers to the kernel, although the default of  32  kB
166                 should be more than enough for most cases.
167
168                 Keyword  repeat is used to indicate the number of consecutive
169                 runs to perform. Note that output data and context printed to
170                 files  correspond  to  the  last  of those runs. The duration
171                 printed out at the end of the runs is  an  average  over  all
172                 runs performed by the command.
173
174                 Not all program types support test run. Among those which do,
175                 not all  of  them  can  take  the  ctx_in/ctx_out  arguments.
176                 bpftool does not perform checks on program types.
177
178          bpftool prog help
179                 Print short help message.
180

OPTIONS

182          -h, --help
183                 Print short generic help message (similar to bpftool help).
184
185          -V, --version
186                 Print version number (similar to bpftool version).
187
188          -j, --json
189                 Generate  JSON output. For commands that cannot produce JSON,
190                 this option has no effect.
191
192          -p, --pretty
193                 Generate human-readable JSON output. Implies -j.
194
195          -f, --bpffs
196                 When showing BPF programs, show file  names  of  pinned  pro‐
197                 grams.
198
199          -m, --mapcompat
200                 Allow loading maps with unknown map definitions.
201
202          -n, --nomount
203                 Do not automatically attempt to mount any virtual file system
204                 (such as tracefs or BPF virtual file system) when necessary.
205
206          -d, --debug
207                 Print all logs available, even debug-level information.  This
208                 includes  logs from libbpf as well as from the verifier, when
209                 attempting to load programs.
210

EXAMPLES

212       # bpftool prog show
213
214          10: xdp  name some_prog  tag 005a3d2123620c8b  gpl run_time_ns 81632 run_cnt 10
215                  loaded_at 2017-09-29T20:11:00+0000  uid 0
216                  xlated 528B  jited 370B  memlock 4096B  map_ids 10
217
218       # bpftool --json --pretty prog show
219
220          [{
221                  "id": 10,
222                  "type": "xdp",
223                  "tag": "005a3d2123620c8b",
224                  "gpl_compatible": true,
225                  "run_time_ns": 81632,
226                  "run_cnt": 10,
227                  "loaded_at": 1506715860,
228                  "uid": 0,
229                  "bytes_xlated": 528,
230                  "jited": true,
231                  "bytes_jited": 370,
232                  "bytes_memlock": 4096,
233                  "map_ids": [10
234                  ]
235              }
236          ]
237
238       # bpftool prog dump xlated id 10 file /tmp/t
239       # ls -l /tmp/t
240
241
242          -rw------- 1 root root 560 Jul 22 01:42 /tmp/t
243
244       # bpftool prog dump jited tag 005a3d2123620c8b
245
246          0:   push   %rbp
247          1:   mov    %rsp,%rbp
248          2:   sub    $0x228,%rsp
249          3:   sub    $0x28,%rbp
250          4:   mov    %rbx,0x0(%rbp)
251
252       # mount -t bpf none /sys/fs/bpf/
253       # bpftool prog pin id 10 /sys/fs/bpf/prog
254       # bpftool prog load ./my_prog.o /sys/fs/bpf/prog2
255       # ls -l /sys/fs/bpf/
256
257
258          -rw------- 1 root root 0 Jul 22 01:43 prog
259          -rw------- 1 root root 0 Jul 22 01:44 prog2
260
261       # bpftool prog dump jited pinned /sys/fs/bpf/prog opcodes
262
263          0:   push   %rbp
264               55
265          1:   mov    %rsp,%rbp
266               48 89 e5
267          4:   sub    $0x228,%rsp
268               48 81 ec 28 02 00 00
269          b:   sub    $0x28,%rbp
270               48 83 ed 28
271          f:   mov    %rbx,0x0(%rbp)
272               48 89 5d 00
273
274       # bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7
275       # bpftool prog show pinned /sys/fs/bpf/xdp1
276
277
278          9: xdp  name xdp_prog1  tag 539ec6ce11b52f98  gpl
279                  loaded_at 2018-06-25T16:17:31-0700  uid 0
280                  xlated 488B  jited 336B  memlock 4096B  map_ids 7
281
282       # rm /sys/fs/bpf/xdp1
283

SEE ALSO

285          bpf(2),      bpf-helpers(7),       bpftool(8),       bpftool-map(8),
286          bpftool-cgroup(8),        bpftool-feature(8),        bpftool-net(8),
287          bpftool-perf(8), bpftool-btf(8)
288
289
290
291
292                                                               BPFTOOL-PROG(8)
Impressum