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 help**
35|
36|	*MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
37|	*DATA* := { [**hex**] *BYTES* }
38|	*PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
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** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
45|		| **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage** }
46
47DESCRIPTION
48===========
49	**bpftool map { show | list }**   [*MAP*]
50		  Show information about loaded maps.  If *MAP* is specified
51		  show information only about given map, otherwise list all
52		  maps currently loaded on the system.
53
54		  Output will start with map ID followed by map type and
55		  zero or more named attributes (depending on kernel version).
56
57	**bpftool map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE*  **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
58		  Create a new map with given parameters and pin it to *bpffs*
59		  as *FILE*.
60
61	**bpftool map dump**    *MAP*
62		  Dump all entries in a given *MAP*.
63
64	**bpftool map update**  *MAP*  **key** *DATA*   **value** *VALUE* [*UPDATE_FLAGS*]
65		  Update map entry for a given *KEY*.
66
67		  *UPDATE_FLAGS* can be one of: **any** update existing entry
68		  or add if doesn't exit; **exist** update only if entry already
69		  exists; **noexist** update only if entry doesn't exist.
70
71		  If the **hex** keyword is provided in front of the bytes
72		  sequence, the bytes are parsed as hexadeximal values, even if
73		  no "0x" prefix is added. If the keyword is not provided, then
74		  the bytes are parsed as decimal values, unless a "0x" prefix
75		  (for hexadecimal) or a "0" prefix (for octal) is provided.
76
77	**bpftool map lookup**  *MAP*  **key** *DATA*
78		  Lookup **key** in the map.
79
80	**bpftool map getnext** *MAP* [**key** *DATA*]
81		  Get next key.  If *key* is not specified, get first key.
82
83	**bpftool map delete**  *MAP*  **key** *DATA*
84		  Remove entry from the map.
85
86	**bpftool map pin**     *MAP*  *FILE*
87		  Pin map *MAP* as *FILE*.
88
89		  Note: *FILE* must be located in *bpffs* mount. It must not
90		  contain a dot character ('.'), which is reserved for future
91		  extensions of *bpffs*.
92
93	**bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
94		  Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
95
96		  Install perf rings into a perf event array map and dump
97		  output of any bpf_perf_event_output() call in the kernel.
98		  By default read the number of CPUs on the system and
99		  install perf ring for each CPU in the corresponding index
100		  in the array.
101
102		  If **cpu** and **index** are specified, install perf ring
103		  for given **cpu** at **index** in the array (single ring).
104
105		  Note that installing a perf ring into an array will silently
106		  replace any existing ring.  Any other application will stop
107		  receiving events if it installed its rings earlier.
108
109	**bpftool map help**
110		  Print short help message.
111
112OPTIONS
113=======
114	-h, --help
115		  Print short generic help message (similar to **bpftool help**).
116
117	-v, --version
118		  Print version number (similar to **bpftool version**).
119
120	-j, --json
121		  Generate JSON output. For commands that cannot produce JSON, this
122		  option has no effect.
123
124	-p, --pretty
125		  Generate human-readable JSON output. Implies **-j**.
126
127	-f, --bpffs
128		  Show file names of pinned maps.
129
130EXAMPLES
131========
132**# bpftool map show**
133::
134
135  10: hash  name some_map  flags 0x0
136	key 4B  value 8B  max_entries 2048  memlock 167936B
137
138The following three commands are equivalent:
139
140|
141| **# bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c**
142| **# bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
143| **# bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76**
144
145**# bpftool map lookup id 10 key 0 1 2 3**
146
147::
148
149  key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
150
151
152**# bpftool map dump id 10**
153::
154
155  key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
156  key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
157  Found 2 elements
158
159**# bpftool map getnext id 10 key 0 1 2 3**
160::
161
162  key:
163  00 01 02 03
164  next key:
165  0d 00 07 00
166
167|
168| **# mount -t bpf none /sys/fs/bpf/**
169| **# bpftool map pin id 10 /sys/fs/bpf/map**
170| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
171
172SEE ALSO
173========
174	**bpf**\ (2),
175	**bpf-helpers**\ (7),
176	**bpftool**\ (8),
177	**bpftool-prog**\ (8),
178	**bpftool-cgroup**\ (8),
179	**bpftool-net**\ (8),
180	**bpftool-perf**\ (8)
181