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

NAME

6       bpftool-map - tool for inspection and simple manipulation of eBPF maps
7

SYNOPSIS

9          bpftool [OPTIONS] map COMMAND
10
11          OPTIONS  := { { -j | --json } [{ -p | --pretty }] | { -d | --debug }
12          | { -f | --bpffs } | { -n | --nomount } }
13
14          COMMANDS := { show | list | create | dump | update | lookup  |  get‐
15          next | delete | pin | help }
16

MAP COMMANDS

18       bpftool map { show | list }   [MAP]
19       bpftool map create     FILE type TYPE key KEY_SIZE value VALUE_SIZE
20         entries MAX_ENTRIES name NAME [flags FLAGS] [inner_map MAP]
21         [offload_dev NAME]
22       bpftool map dump       MAP
23       bpftool map update     MAP [key DATA] [value VALUE] [UPDATE_FLAGS]
24       bpftool map lookup     MAP [key DATA]
25       bpftool map getnext    MAP [key DATA]
26       bpftool map delete     MAP  key DATA
27       bpftool map pin        MAP  FILE
28       bpftool map event_pipe MAP [cpu N index M]
29       bpftool map peek       MAP
30       bpftool map push       MAP value VALUE
31       bpftool map pop        MAP
32       bpftool map enqueue    MAP value VALUE
33       bpftool map dequeue    MAP
34       bpftool map freeze     MAP
35       bpftool map help
36
37       MAP := { id MAP_ID | pinned FILE | name MAP_NAME }
38       DATA := { [hex] BYTES }
39       PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name PROG_NAME }
40       VALUE := { DATA | MAP | PROG }
41       UPDATE_FLAGS := { any | exist | noexist }
42       TYPE := { hash | array | prog_array | perf_event_array | percpu_hash
43         | percpu_array | stack_trace | cgroup_array | lru_hash
44         | lru_percpu_hash | lpm_trie | array_of_maps | hash_of_maps
45         | devmap | devmap_hash | sockmap | cpumap | xskmap | sockhash
46         | cgroup_storage | reuseport_sockarray | percpu_cgroup_storage
47         | queue | stack | sk_storage | struct_ops | ringbuf | inode_storage
48         | task_storage | bloom_filter | user_ringbuf | cgrp_storage }
49
50

DESCRIPTION

52          bpftool map { show | list } [MAP]
53                 Show information about loaded maps.  If MAP is specified show
54                 information only about given maps, otherwise  list  all  maps
55                 currently  loaded  on  the  system.  In case of name, MAP may
56                 match several maps which will all be shown.
57
58                 Output will start with map ID followed by map type  and  zero
59                 or more named attributes (depending on kernel version).
60
61                 Since Linux 5.8 bpftool is able to discover information about
62                 processes that hold open file descriptors (FDs)  against  BPF
63                 maps.  On  such  kernels bpftool will automatically emit this
64                 information as well.
65
66          bpftool map create FILE type TYPE key KEY_SIZE value VALUE_SIZE  en‐
67          tries  MAX_ENTRIES  name  NAME  [flags  FLAGS] [inner_map MAP] [off‐
68          load_dev NAME]
69                 Create a new map with given parameters and pin it to bpffs as
70                 FILE.
71
72                 FLAGS  should  be  an integer which is the combination of de‐
73                 sired flags, e.g. 1024 for  BPF_F_MMAPABLE  (see  bpf.h  UAPI
74                 header for existing flags).
75
76                 To create maps of type array-of-maps or hash-of-maps, the in‐
77                 ner_map keyword must be used to pass an inner map. The kernel
78                 needs  it  to collect metadata related to the inner maps that
79                 the new map will work with.
80
81                 Keyword offload_dev expects a network interface name, and  is
82                 used to request hardware offload for the map.
83
84          bpftool map dump MAP
85                 Dump  all  entries  in a given MAP.  In case of name, MAP may
86                 match several maps which will all be dumped.
87
88          bpftool map update MAP [key DATA] [value VALUE] [UPDATE_FLAGS]
89                 Update map entry for a given KEY.
90
91                 UPDATE_FLAGS can be one of: any update existing entry or  add
92                 if  doesn't  exit; exist update only if entry already exists;
93                 noexist update only if entry doesn't exist.
94
95                 If the hex keyword is provided in  front  of  the  bytes  se‐
96                 quence,  the  bytes are parsed as hexadecimal values, even if
97                 no "0x" prefix is added. If the keyword is not provided, then
98                 the  bytes are parsed as decimal values, unless a "0x" prefix
99                 (for hexadecimal) or a "0" prefix (for octal) is provided.
100
101          bpftool map lookup MAP [key DATA]
102                 Lookup key in the map.
103
104          bpftool map getnext MAP [key DATA]
105                 Get next key.  If key is not specified, get first key.
106
107          bpftool map delete MAP key DATA
108                 Remove entry from the map.
109
110          bpftool map pin MAP FILE
111                 Pin map MAP as FILE.
112
113                 Note: FILE must be located in bpffs mount. It must  not  con‐
114                 tain  a dot character ('.'), which is reserved for future ex‐
115                 tensions of bpffs.
116
117          bpftool map event_pipe MAP [cpu N index M]
118                 Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
119
120                 Install perf rings into a perf event array map and dump  out‐
121                 put  of  any  bpf_perf_event_output() call in the kernel.  By
122                 default read the number of CPUs on  the  system  and  install
123                 perf  ring for each CPU in the corresponding index in the ar‐
124                 ray.
125
126                 If cpu and index are specified, install perf ring  for  given
127                 cpu at index in the array (single ring).
128
129                 Note  that installing a perf ring into an array will silently
130                 replace any existing ring.  Any other application  will  stop
131                 receiving events if it installed its rings earlier.
132
133          bpftool map peek MAP
134                 Peek next value in the queue or stack.
135
136          bpftool map push MAP value VALUE
137                 Push VALUE onto the stack.
138
139          bpftool map pop MAP
140                 Pop and print value from the stack.
141
142          bpftool map enqueue MAP value VALUE
143                 Enqueue VALUE into the queue.
144
145          bpftool map dequeue MAP
146                 Dequeue and print value from the queue.
147
148          bpftool map freeze MAP
149                 Freeze  the  map as read-only from user space. Entries from a
150                 frozen map can not longer be  updated  or  deleted  with  the
151                 bpf()  system call. This operation is not reversible, and the
152                 map remains immutable from user space until its  destruction.
153                 However,  read  and write permissions for BPF programs to the
154                 map remain unchanged.
155
156          bpftool map help
157                 Print short help message.
158

OPTIONS

160          -h, --help
161                 Print short help message (similar to bpftool help).
162
163          -V, --version
164                 Print bpftool's version number (similar to bpftool  version),
165                 the  number  of  the libbpf version in use, and optional fea‐
166                 tures that were included when bpftool was compiled.  Optional
167                 features  include  linking  against LLVM or libbfd to provide
168                 the disassembler for  JIT-ted  programs  (bpftool  prog  dump
169                 jited) and usage of BPF skeletons (some features like bpftool
170                 prog profile or showing pids associated to  BPF  objects  may
171                 rely on it).
172
173          -j, --json
174                 Generate  JSON output. For commands that cannot produce JSON,
175                 this option has no effect.
176
177          -p, --pretty
178                 Generate human-readable JSON output. Implies -j.
179
180          -d, --debug
181                 Print all logs available, even debug-level information.  This
182                 includes  logs from libbpf as well as from the verifier, when
183                 attempting to load programs.
184
185          -f, --bpffs
186                 Show file names of pinned maps.
187
188          -n, --nomount
189                 Do not automatically attempt to mount any virtual file system
190                 (such as tracefs or BPF virtual file system) when necessary.
191

EXAMPLES

193       # bpftool map show
194
195          10: hash  name some_map  flags 0x0
196                key 4B  value 8B  max_entries 2048  memlock 167936B
197                pids systemd(1)
198
199       The following three commands are equivalent:
200
201       # bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c
202       # bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c
203       # bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76
204
205
206       # bpftool map lookup id 10 key 0 1 2 3
207
208          key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
209
210       # bpftool map dump id 10
211
212          key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
213          key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
214          Found 2 elements
215
216       # bpftool map getnext id 10 key 0 1 2 3
217
218          key:
219          00 01 02 03
220          next key:
221          0d 00 07 00
222
223       # mount -t bpf none /sys/fs/bpf/
224       # bpftool map pin id 10 /sys/fs/bpf/map
225       # bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00
226
227
228       Note  that  map  update can also be used in order to change the program
229       references hold by a program array map. This can be used, for  example,
230       to  change  the  programs  used for tail-call jumps at runtime, without
231       having to reload the entry-point program. Below is an example for  this
232       use  case: we load a program defining a prog array map, and with a main
233       function that contains a tail call to other programs that can  be  used
234       either  to  "process"  packets  or to "debug" processing. Note that the
235       prog array map MUST be pinned into the BPF virtual file system for  the
236       map update to work successfully, as kernel flushes prog array maps when
237       they have no more references from user space (and the update  would  be
238       lost as soon as bpftool exits).
239
240       # bpftool prog loadall tail_calls.o /sys/fs/bpf/foo type xdp
241       # bpftool prog --bpffs
242
243
244          545: xdp  name main_func  tag 674b4b5597193dc3  gpl
245                  loaded_at 2018-12-12T15:02:58+0000  uid 0
246                  xlated 240B  jited 257B  memlock 4096B  map_ids 294
247                  pinned /sys/fs/bpf/foo/xdp
248          546: xdp  name bpf_func_process  tag e369a529024751fc  gpl
249                  loaded_at 2018-12-12T15:02:58+0000  uid 0
250                  xlated 200B  jited 164B  memlock 4096B
251                  pinned /sys/fs/bpf/foo/process
252          547: xdp  name bpf_func_debug  tag 0b597868bc7f0976  gpl
253                  loaded_at 2018-12-12T15:02:58+0000  uid 0
254                  xlated 200B  jited 164B  memlock 4096B
255                  pinned /sys/fs/bpf/foo/debug
256
257       # bpftool map
258
259          294: prog_array  name jmp_table  flags 0x0
260                  key 4B  value 4B  max_entries 1  memlock 4096B
261                  owner_prog_type xdp  owner jited
262
263       # bpftool map pin id 294 /sys/fs/bpf/bar
264       # bpftool map dump pinned /sys/fs/bpf/bar
265
266
267          Found 0 elements
268
269       # bpftool map update pinned /sys/fs/bpf/bar key 0 0 0 0 value pinned /sys/fs/bpf/foo/debug
270       # bpftool map dump pinned /sys/fs/bpf/bar
271
272
273          key: 00 00 00 00  value: 22 02 00 00
274          Found 1 element
275

SEE ALSO

277          bpf(2),       bpf-helpers(7),       bpftool(8),      bpftool-btf(8),
278          bpftool-cgroup(8),        bpftool-feature(8),        bpftool-gen(8),
279          bpftool-iter(8),  bpftool-link(8),  bpftool-net(8), bpftool-perf(8),
280          bpftool-prog(8), bpftool-struct_ops(8)
281
282
283
284
285                                                                BPFTOOL-MAP(8)
Impressum