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 }] | { -f | --bpffs }
12          }
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] [dev NAME]
21       bpftool map dump       MAP
22       bpftool map update     MAP [key DATA] [value VALUE] [UPDATE_FLAGS]
23       bpftool map lookup     MAP [key DATA]
24       bpftool map getnext    MAP [key DATA]
25       bpftool map delete     MAP  key DATA
26       bpftool map pin        MAP  FILE
27       bpftool map event_pipe MAP [cpu N index M]
28       bpftool map peek       MAP
29       bpftool map push       MAP value VALUE
30       bpftool map pop        MAP
31       bpftool map enqueue    MAP value VALUE
32       bpftool map dequeue    MAP
33       bpftool map freeze     MAP
34       bpftool map help
35
36       MAP := { id MAP_ID | pinned FILE | name MAP_NAME }
37       DATA := { [hex] BYTES }
38       PROG := { id PROG_ID | pinned FILE | tag PROG_TAG | name PROG_NAME }
39       VALUE := { DATA | MAP | PROG }
40       UPDATE_FLAGS := { any | exist | noexist }
41       TYPE := { hash | array | prog_array | perf_event_array | percpu_hash
42         | percpu_array | stack_trace | cgroup_array | lru_hash
43         | lru_percpu_hash | lpm_trie | array_of_maps | hash_of_maps
44         | devmap | devmap_hash | sockmap | cpumap | xskmap | sockhash
45         | cgroup_storage | reuseport_sockarray | percpu_cgroup_storage
46         | queue | stack }
47
48

DESCRIPTION

50          bpftool map { show | list } [MAP]
51                 Show information about loaded maps.  If MAP is specified show
52                 information only about given maps, otherwise  list  all  maps
53                 currently  loaded  on  the  system.  In case of name, MAP may
54                 match several maps which will all be shown.
55
56                 Output will start with map ID followed by map type  and  zero
57                 or more named attributes (depending on kernel version).
58
59          bpftool  map  create  FILE  type  TYPE key KEY_SIZE value VALUE_SIZE
60          entries MAX_ENTRIES name NAME [flags FLAGS] [dev NAME]
61                 Create a new map with given parameters and pin it to bpffs as
62                 FILE.
63
64          bpftool map dump MAP
65                 Dump  all  entries  in a given MAP.  In case of name, MAP may
66                 match several maps which will all be dumped.
67
68          bpftool map update MAP [key DATA] [value VALUE] [UPDATE_FLAGS]
69                 Update map entry for a given KEY.
70
71                 UPDATE_FLAGS can be one of: any update existing entry or  add
72                 if  doesn't  exit; exist update only if entry already exists;
73                 noexist update only if entry doesn't exist.
74
75                 If the  hex  keyword  is  provided  in  front  of  the  bytes
76                 sequence, the bytes are parsed as hexadeximal values, even if
77                 no "0x" prefix is added. If the keyword is not provided, then
78                 the  bytes are parsed as decimal values, unless a "0x" prefix
79                 (for hexadecimal) or a "0" prefix (for octal) is provided.
80
81          bpftool map lookup MAP [key DATA]
82                 Lookup key in the map.
83
84          bpftool map getnext MAP [key DATA]
85                 Get next key.  If key is not specified, get first key.
86
87          bpftool map delete MAP key DATA
88                 Remove entry from the map.
89
90          bpftool map pin MAP FILE
91                 Pin map MAP as FILE.
92
93                 Note: FILE must be located in bpffs mount. It must  not  con‐
94                 tain  a  dot  character  ('.'),  which is reserved for future
95                 extensions of bpffs.
96
97          bpftool map event_pipe MAP [cpu N index M]
98                 Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
99
100                 Install perf rings into a perf event array map and dump  out‐
101                 put  of  any  bpf_perf_event_output() call in the kernel.  By
102                 default read the number of CPUs on  the  system  and  install
103                 perf  ring  for  each  CPU  in the corresponding index in the
104                 array.
105
106                 If cpu and index are specified, install perf ring  for  given
107                 cpu at index in the array (single ring).
108
109                 Note  that installing a perf ring into an array will silently
110                 replace any existing ring.  Any other application  will  stop
111                 receiving events if it installed its rings earlier.
112
113          bpftool map peek MAP
114                 Peek next value in the queue or stack.
115
116          bpftool map push MAP value VALUE
117                 Push value onto the stack.
118
119          bpftool map pop MAP
120                 Pop and print value from the stack.
121
122          bpftool map enqueue MAP value VALUE
123                 Enqueue value into the queue.
124
125          bpftool map dequeue MAP
126                 Dequeue and print value from the queue.
127
128          bpftool map freeze MAP
129                 Freeze  the  map as read-only from user space. Entries from a
130                 frozen map can not longer be  updated  or  deleted  with  the
131                 bpf()  system call. This operation is not reversible, and the
132                 map remains immutable from user space until its  destruction.
133                 However,  read  and write permissions for BPF programs to the
134                 map remain unchanged.
135
136          bpftool map help
137                 Print short help message.
138

OPTIONS

140          -h, --help
141                 Print short generic help message (similar to bpftool help).
142
143          -V, --version
144                 Print version number (similar to bpftool version).
145
146          -j, --json
147                 Generate JSON output. For commands that cannot produce  JSON,
148                 this option has no effect.
149
150          -p, --pretty
151                 Generate human-readable JSON output. Implies -j.
152
153          -f, --bpffs
154                 Show file names of pinned maps.
155
156          -n, --nomount
157                 Do not automatically attempt to mount any virtual file system
158                 (such as tracefs or BPF virtual file system) when necessary.
159
160          -d, --debug
161                 Print all logs available from libbpf,  including  debug-level
162                 information.
163

EXAMPLES

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

SEE ALSO

248          bpf(2),       bpf-helpers(7),      bpftool(8),      bpftool-prog(8),
249          bpftool-cgroup(8),        bpftool-feature(8),        bpftool-net(8),
250          bpftool-perf(8), bpftool-btf(8)
251
252
253
254
255                                                                BPFTOOL-MAP(8)
Impressum