1================
2bpftool-map
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF maps
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
13	**bpftool** [*OPTIONS*] **map** *COMMAND*
14
15	*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16
17	*COMMANDS* :=
18	{ **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext**
19	| **delete** | **pin** | **help** }
20
21MAP COMMANDS
22=============
23
24|	**bpftool** **map** { **show** | **list** }   [*MAP*]
25|	**bpftool** **map create**     *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE* \
26|		**entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
27|	**bpftool** **map dump**       *MAP*
28|	**bpftool** **map update**     *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*]
29|	**bpftool** **map lookup**     *MAP* [**key** *DATA*]
30|	**bpftool** **map getnext**    *MAP* [**key** *DATA*]
31|	**bpftool** **map delete**     *MAP*  **key** *DATA*
32|	**bpftool** **map pin**        *MAP*  *FILE*
33|	**bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
34|	**bpftool** **map peek**       *MAP*
35|	**bpftool** **map push**       *MAP* **value** *VALUE*
36|	**bpftool** **map pop**        *MAP*
37|	**bpftool** **map enqueue**    *MAP* **value** *VALUE*
38|	**bpftool** **map dequeue**    *MAP*
39|	**bpftool** **map freeze**     *MAP*
40|	**bpftool** **map help**
41|
42|	*MAP* := { **id** *MAP_ID* | **pinned** *FILE* | **name** *MAP_NAME* }
43|	*DATA* := { [**hex**] *BYTES* }
44|	*PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* | **name** *PROG_NAME* }
45|	*VALUE* := { *DATA* | *MAP* | *PROG* }
46|	*UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
47|	*TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
48|		| **percpu_array** | **stack_trace** | **cgroup_array** | **lru_hash**
49|		| **lru_percpu_hash** | **lpm_trie** | **array_of_maps** | **hash_of_maps**
50|		| **devmap** | **devmap_hash** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
51|		| **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage**
52|		| **queue** | **stack** | **sk_storage** | **struct_ops** }
53
54DESCRIPTION
55===========
56	**bpftool map { show | list }**   [*MAP*]
57		  Show information about loaded maps.  If *MAP* is specified
58		  show information only about given maps, otherwise list all
59		  maps currently loaded on the system.  In case of **name**,
60		  *MAP* may match several maps which will all be shown.
61
62		  Output will start with map ID followed by map type and
63		  zero or more named attributes (depending on kernel version).
64
65	**bpftool map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE*  **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
66		  Create a new map with given parameters and pin it to *bpffs*
67		  as *FILE*.
68
69		  *FLAGS* should be an integer which is the combination of
70		  desired flags, e.g. 1024 for **BPF_F_MMAPABLE** (see bpf.h
71		  UAPI header for existing flags).
72
73		  Keyword **dev** expects a network interface name, and is used
74		  to request hardware offload for the map.
75
76	**bpftool map dump**    *MAP*
77		  Dump all entries in a given *MAP*.  In case of **name**,
78		  *MAP* may match several maps which will all be dumped.
79
80	**bpftool map update**  *MAP* [**key** *DATA*] [**value** *VALUE*] [*UPDATE_FLAGS*]
81		  Update map entry for a given *KEY*.
82
83		  *UPDATE_FLAGS* can be one of: **any** update existing entry
84		  or add if doesn't exit; **exist** update only if entry already
85		  exists; **noexist** update only if entry doesn't exist.
86
87		  If the **hex** keyword is provided in front of the bytes
88		  sequence, the bytes are parsed as hexadecimal values, even if
89		  no "0x" prefix is added. If the keyword is not provided, then
90		  the bytes are parsed as decimal values, unless a "0x" prefix
91		  (for hexadecimal) or a "0" prefix (for octal) is provided.
92
93	**bpftool map lookup**  *MAP* [**key** *DATA*]
94		  Lookup **key** in the map.
95
96	**bpftool map getnext** *MAP* [**key** *DATA*]
97		  Get next key.  If *key* is not specified, get first key.
98
99	**bpftool map delete**  *MAP*  **key** *DATA*
100		  Remove entry from the map.
101
102	**bpftool map pin**     *MAP*  *FILE*
103		  Pin map *MAP* as *FILE*.
104
105		  Note: *FILE* must be located in *bpffs* mount. It must not
106		  contain a dot character ('.'), which is reserved for future
107		  extensions of *bpffs*.
108
109	**bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
110		  Read events from a **BPF_MAP_TYPE_PERF_EVENT_ARRAY** map.
111
112		  Install perf rings into a perf event array map and dump
113		  output of any **bpf_perf_event_output**\ () call in the kernel.
114		  By default read the number of CPUs on the system and
115		  install perf ring for each CPU in the corresponding index
116		  in the array.
117
118		  If **cpu** and **index** are specified, install perf ring
119		  for given **cpu** at **index** in the array (single ring).
120
121		  Note that installing a perf ring into an array will silently
122		  replace any existing ring.  Any other application will stop
123		  receiving events if it installed its rings earlier.
124
125	**bpftool map peek**  *MAP*
126		  Peek next value in the queue or stack.
127
128	**bpftool map push**  *MAP* **value** *VALUE*
129		  Push *VALUE* onto the stack.
130
131	**bpftool map pop**  *MAP*
132		  Pop and print value from the stack.
133
134	**bpftool map enqueue**  *MAP* **value** *VALUE*
135		  Enqueue *VALUE* into the queue.
136
137	**bpftool map dequeue**  *MAP*
138		  Dequeue and print value from the queue.
139
140	**bpftool map freeze**  *MAP*
141		  Freeze the map as read-only from user space. Entries from a
142		  frozen map can not longer be updated or deleted with the
143		  **bpf**\ () system call. This operation is not reversible,
144		  and the map remains immutable from user space until its
145		  destruction. However, read and write permissions for BPF
146		  programs to the map remain unchanged.
147
148	**bpftool map help**
149		  Print short help message.
150
151OPTIONS
152=======
153	-h, --help
154		  Print short generic help message (similar to **bpftool help**).
155
156	-V, --version
157		  Print version number (similar to **bpftool version**).
158
159	-j, --json
160		  Generate JSON output. For commands that cannot produce JSON, this
161		  option has no effect.
162
163	-p, --pretty
164		  Generate human-readable JSON output. Implies **-j**.
165
166	-f, --bpffs
167		  Show file names of pinned maps.
168
169	-n, --nomount
170		  Do not automatically attempt to mount any virtual file system
171		  (such as tracefs or BPF virtual file system) when necessary.
172
173	-d, --debug
174		  Print all logs available from libbpf, including debug-level
175		  information.
176
177EXAMPLES
178========
179**# bpftool map show**
180::
181
182  10: hash  name some_map  flags 0x0
183	key 4B  value 8B  max_entries 2048  memlock 167936B
184
185The following three commands are equivalent:
186
187|
188| **# bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c**
189| **# bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
190| **# bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76**
191
192**# bpftool map lookup id 10 key 0 1 2 3**
193
194::
195
196  key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
197
198
199**# bpftool map dump id 10**
200::
201
202  key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
203  key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
204  Found 2 elements
205
206**# bpftool map getnext id 10 key 0 1 2 3**
207::
208
209  key:
210  00 01 02 03
211  next key:
212  0d 00 07 00
213
214|
215| **# mount -t bpf none /sys/fs/bpf/**
216| **# bpftool map pin id 10 /sys/fs/bpf/map**
217| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
218
219Note that map update can also be used in order to change the program references
220hold by a program array map. This can be used, for example, to change the
221programs used for tail-call jumps at runtime, without having to reload the
222entry-point program. Below is an example for this use case: we load a program
223defining a prog array map, and with a main function that contains a tail call
224to other programs that can be used either to "process" packets or to "debug"
225processing. Note that the prog array map MUST be pinned into the BPF virtual
226file system for the map update to work successfully, as kernel flushes prog
227array maps when they have no more references from user space (and the update
228would be lost as soon as bpftool exits).
229
230|
231| **# bpftool prog loadall tail_calls.o /sys/fs/bpf/foo type xdp**
232| **# bpftool prog --bpffs**
233
234::
235
236  545: xdp  name main_func  tag 674b4b5597193dc3  gpl
237          loaded_at 2018-12-12T15:02:58+0000  uid 0
238          xlated 240B  jited 257B  memlock 4096B  map_ids 294
239          pinned /sys/fs/bpf/foo/xdp
240  546: xdp  name bpf_func_process  tag e369a529024751fc  gpl
241          loaded_at 2018-12-12T15:02:58+0000  uid 0
242          xlated 200B  jited 164B  memlock 4096B
243          pinned /sys/fs/bpf/foo/process
244  547: xdp  name bpf_func_debug  tag 0b597868bc7f0976  gpl
245          loaded_at 2018-12-12T15:02:58+0000  uid 0
246          xlated 200B  jited 164B  memlock 4096B
247          pinned /sys/fs/bpf/foo/debug
248
249**# bpftool map**
250
251::
252
253  294: prog_array  name jmp_table  flags 0x0
254          key 4B  value 4B  max_entries 1  memlock 4096B
255          owner_prog_type xdp  owner jited
256
257|
258| **# bpftool map pin id 294 /sys/fs/bpf/bar**
259| **# bpftool map dump pinned /sys/fs/bpf/bar**
260
261::
262
263  Found 0 elements
264
265|
266| **# bpftool map update pinned /sys/fs/bpf/bar key 0 0 0 0 value pinned /sys/fs/bpf/foo/debug**
267| **# bpftool map dump pinned /sys/fs/bpf/bar**
268
269::
270
271  key: 00 00 00 00  value: 22 02 00 00
272  Found 1 element
273
274SEE ALSO
275========
276	**bpf**\ (2),
277	**bpf-helpers**\ (7),
278	**bpftool**\ (8),
279	**bpftool-btf**\ (8),
280	**bpftool-cgroup**\ (8),
281	**bpftool-feature**\ (8),
282	**bpftool-gen**\ (8),
283	**bpftool-iter**\ (8),
284	**bpftool-link**\ (8),
285	**bpftool-net**\ (8),
286	**bpftool-perf**\ (8),
287	**bpftool-prog**\ (8),
288	**bpftool-struct_ops**\ (8)
289