1ff69c21aSJakub Kicinski================
2ff69c21aSJakub Kicinskibpftool-map
3ff69c21aSJakub Kicinski================
4ff69c21aSJakub Kicinski-------------------------------------------------------------------------------
5ff69c21aSJakub Kicinskitool for inspection and simple manipulation of eBPF maps
6ff69c21aSJakub Kicinski-------------------------------------------------------------------------------
7ff69c21aSJakub Kicinski
8ff69c21aSJakub Kicinski:Manual section: 8
9ff69c21aSJakub Kicinski
10ff69c21aSJakub KicinskiSYNOPSIS
11ff69c21aSJakub Kicinski========
12ff69c21aSJakub Kicinski
130641c3c8SQuentin Monnet	**bpftool** [*OPTIONS*] **map** *COMMAND*
140641c3c8SQuentin Monnet
15c541b734SPrashant Bhole	*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
16ff69c21aSJakub Kicinski
17ff69c21aSJakub Kicinski	*COMMANDS* :=
186ebe6dbdSJakub Kicinski	{ **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
1947ff7ac6SQuentin Monnet	| **pin** | **help** }
20ff69c21aSJakub Kicinski
21ff69c21aSJakub KicinskiMAP COMMANDS
22ff69c21aSJakub Kicinski=============
23ff69c21aSJakub Kicinski
246ebe6dbdSJakub Kicinski|	**bpftool** **map { show | list }**   [*MAP*]
2547ff7ac6SQuentin Monnet|	**bpftool** **map dump**    *MAP*
260c90f224SQuentin Monnet|	**bpftool** **map update**  *MAP*  **key** [**hex**] *BYTES*   **value** [**hex**] *VALUE* [*UPDATE_FLAGS*]
270c90f224SQuentin Monnet|	**bpftool** **map lookup**  *MAP*  **key** [**hex**] *BYTES*
280c90f224SQuentin Monnet|	**bpftool** **map getnext** *MAP* [**key** [**hex**] *BYTES*]
290c90f224SQuentin Monnet|	**bpftool** **map delete**  *MAP*  **key** [**hex**] *BYTES*
3047ff7ac6SQuentin Monnet|	**bpftool** **map pin**     *MAP*  *FILE*
3147ff7ac6SQuentin Monnet|	**bpftool** **map help**
32ff69c21aSJakub Kicinski|
3347ff7ac6SQuentin Monnet|	*MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
342148481dSQuentin Monnet|	*PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
352148481dSQuentin Monnet|	*VALUE* := { *BYTES* | *MAP* | *PROG* }
3647ff7ac6SQuentin Monnet|	*UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
37ff69c21aSJakub Kicinski
38ff69c21aSJakub KicinskiDESCRIPTION
39ff69c21aSJakub Kicinski===========
406ebe6dbdSJakub Kicinski	**bpftool map { show | list }**   [*MAP*]
41ff69c21aSJakub Kicinski		  Show information about loaded maps.  If *MAP* is specified
42ff69c21aSJakub Kicinski		  show information only about given map, otherwise list all
43ff69c21aSJakub Kicinski		  maps currently loaded on the system.
44ff69c21aSJakub Kicinski
45ff69c21aSJakub Kicinski		  Output will start with map ID followed by map type and
46ff69c21aSJakub Kicinski		  zero or more named attributes (depending on kernel version).
47ff69c21aSJakub Kicinski
48ff69c21aSJakub Kicinski	**bpftool map dump**    *MAP*
49ff69c21aSJakub Kicinski		  Dump all entries in a given *MAP*.
50ff69c21aSJakub Kicinski
510c90f224SQuentin Monnet	**bpftool map update**  *MAP*  **key** [**hex**] *BYTES*   **value** [**hex**] *VALUE* [*UPDATE_FLAGS*]
52ff69c21aSJakub Kicinski		  Update map entry for a given *KEY*.
53ff69c21aSJakub Kicinski
54ff69c21aSJakub Kicinski		  *UPDATE_FLAGS* can be one of: **any** update existing entry
55ff69c21aSJakub Kicinski		  or add if doesn't exit; **exist** update only if entry already
56ff69c21aSJakub Kicinski		  exists; **noexist** update only if entry doesn't exist.
57ff69c21aSJakub Kicinski
580c90f224SQuentin Monnet		  If the **hex** keyword is provided in front of the bytes
590c90f224SQuentin Monnet		  sequence, the bytes are parsed as hexadeximal values, even if
600c90f224SQuentin Monnet		  no "0x" prefix is added. If the keyword is not provided, then
610c90f224SQuentin Monnet		  the bytes are parsed as decimal values, unless a "0x" prefix
620c90f224SQuentin Monnet		  (for hexadecimal) or a "0" prefix (for octal) is provided.
630c90f224SQuentin Monnet
640c90f224SQuentin Monnet	**bpftool map lookup**  *MAP*  **key** [**hex**] *BYTES*
65ff69c21aSJakub Kicinski		  Lookup **key** in the map.
66ff69c21aSJakub Kicinski
670c90f224SQuentin Monnet	**bpftool map getnext** *MAP* [**key** [**hex**] *BYTES*]
68ff69c21aSJakub Kicinski		  Get next key.  If *key* is not specified, get first key.
69ff69c21aSJakub Kicinski
700c90f224SQuentin Monnet	**bpftool map delete**  *MAP*  **key** [**hex**] *BYTES*
71ff69c21aSJakub Kicinski		  Remove entry from the map.
72ff69c21aSJakub Kicinski
73ff69c21aSJakub Kicinski	**bpftool map pin**     *MAP*  *FILE*
74ff69c21aSJakub Kicinski		  Pin map *MAP* as *FILE*.
75ff69c21aSJakub Kicinski
76ff69c21aSJakub Kicinski		  Note: *FILE* must be located in *bpffs* mount.
77ff69c21aSJakub Kicinski
78ff69c21aSJakub Kicinski	**bpftool map help**
79ff69c21aSJakub Kicinski		  Print short help message.
80ff69c21aSJakub Kicinski
81a2bc2e5cSQuentin MonnetOPTIONS
82a2bc2e5cSQuentin Monnet=======
83a2bc2e5cSQuentin Monnet	-h, --help
84a2bc2e5cSQuentin Monnet		  Print short generic help message (similar to **bpftool help**).
85a2bc2e5cSQuentin Monnet
86a2bc2e5cSQuentin Monnet	-v, --version
87a2bc2e5cSQuentin Monnet		  Print version number (similar to **bpftool version**).
88a2bc2e5cSQuentin Monnet
890641c3c8SQuentin Monnet	-j, --json
900641c3c8SQuentin Monnet		  Generate JSON output. For commands that cannot produce JSON, this
910641c3c8SQuentin Monnet		  option has no effect.
920641c3c8SQuentin Monnet
930641c3c8SQuentin Monnet	-p, --pretty
940641c3c8SQuentin Monnet		  Generate human-readable JSON output. Implies **-j**.
950641c3c8SQuentin Monnet
96c541b734SPrashant Bhole	-f, --bpffs
97c541b734SPrashant Bhole		  Show file names of pinned maps.
98c541b734SPrashant Bhole
99ff69c21aSJakub KicinskiEXAMPLES
100ff69c21aSJakub Kicinski========
101ff69c21aSJakub Kicinski**# bpftool map show**
102ff69c21aSJakub Kicinski::
103ff69c21aSJakub Kicinski
104ff69c21aSJakub Kicinski  10: hash  name some_map  flags 0x0
105ff69c21aSJakub Kicinski	key 4B  value 8B  max_entries 2048  memlock 167936B
106ff69c21aSJakub Kicinski
1070c90f224SQuentin MonnetThe following three commands are equivalent:
1080c90f224SQuentin Monnet
1090c90f224SQuentin Monnet|
1100c90f224SQuentin Monnet| **# bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c**
1110c90f224SQuentin Monnet| **# bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
1120c90f224SQuentin Monnet| **# bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76**
113ff69c21aSJakub Kicinski
114ff69c21aSJakub Kicinski**# bpftool map lookup id 10 key 0 1 2 3**
115ff69c21aSJakub Kicinski
116ff69c21aSJakub Kicinski::
117ff69c21aSJakub Kicinski
118ff69c21aSJakub Kicinski  key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
119ff69c21aSJakub Kicinski
120ff69c21aSJakub Kicinski
121ff69c21aSJakub Kicinski**# bpftool map dump id 10**
122ff69c21aSJakub Kicinski::
123ff69c21aSJakub Kicinski
124ff69c21aSJakub Kicinski  key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
125ff69c21aSJakub Kicinski  key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
126ff69c21aSJakub Kicinski  Found 2 elements
127ff69c21aSJakub Kicinski
128ff69c21aSJakub Kicinski**# bpftool map getnext id 10 key 0 1 2 3**
129ff69c21aSJakub Kicinski::
130ff69c21aSJakub Kicinski
131ff69c21aSJakub Kicinski  key:
132ff69c21aSJakub Kicinski  00 01 02 03
133ff69c21aSJakub Kicinski  next key:
134ff69c21aSJakub Kicinski  0d 00 07 00
135ff69c21aSJakub Kicinski
136ff69c21aSJakub Kicinski|
137ff69c21aSJakub Kicinski| **# mount -t bpf none /sys/fs/bpf/**
138ff69c21aSJakub Kicinski| **# bpftool map pin id 10 /sys/fs/bpf/map**
139ff69c21aSJakub Kicinski| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
140ff69c21aSJakub Kicinski
141ff69c21aSJakub KicinskiSEE ALSO
142ff69c21aSJakub Kicinski========
1435ccda64dSRoman Gushchin	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)
144