blob: a6258bc8ec4f57d0cf1d5b35a95030fd66cbe881 [file] [log] [blame]
Jakub Kicinskiff69c212017-10-04 20:10:05 -07001================
2bpftool-map
3================
4-------------------------------------------------------------------------------
5tool for inspection and simple manipulation of eBPF maps
6-------------------------------------------------------------------------------
7
8:Manual section: 8
9
10SYNOPSIS
11========
12
Quentin Monnet0641c3c2017-10-23 09:24:16 -070013 **bpftool** [*OPTIONS*] **map** *COMMAND*
14
Prashant Bholec541b732017-11-08 13:55:49 +090015 *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
Jakub Kicinskiff69c212017-10-04 20:10:05 -070016
17 *COMMANDS* :=
Jakub Kicinski6ebe6db2018-01-02 14:48:36 -080018 { **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
Quentin Monnet47ff7ac2017-10-23 09:24:15 -070019 | **pin** | **help** }
Jakub Kicinskiff69c212017-10-04 20:10:05 -070020
21MAP COMMANDS
22=============
23
Jakub Kicinski6ebe6db2018-01-02 14:48:36 -080024| **bpftool** **map { show | list }** [*MAP*]
Jakub Kicinskif412eed2018-05-03 18:37:16 -070025| **bpftool** **map dump** *MAP*
26| **bpftool** **map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*]
27| **bpftool** **map lookup** *MAP* **key** *DATA*
28| **bpftool** **map getnext** *MAP* [**key** *DATA*]
29| **bpftool** **map delete** *MAP* **key** *DATA*
30| **bpftool** **map pin** *MAP* *FILE*
31| **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
Quentin Monnet47ff7ac2017-10-23 09:24:15 -070032| **bpftool** **map help**
Jakub Kicinskiff69c212017-10-04 20:10:05 -070033|
Quentin Monnet47ff7ac2017-10-23 09:24:15 -070034| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
Jakub Kicinskic642ea22018-05-03 18:37:14 -070035| *DATA* := { [**hex**] *BYTES* }
Quentin Monnet21484812018-02-07 20:27:15 -080036| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
Jakub Kicinskic642ea22018-05-03 18:37:14 -070037| *VALUE* := { *DATA* | *MAP* | *PROG* }
Quentin Monnet47ff7ac2017-10-23 09:24:15 -070038| *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
Jakub Kicinskiff69c212017-10-04 20:10:05 -070039
40DESCRIPTION
41===========
Jakub Kicinski6ebe6db2018-01-02 14:48:36 -080042 **bpftool map { show | list }** [*MAP*]
Jakub Kicinskiff69c212017-10-04 20:10:05 -070043 Show information about loaded maps. If *MAP* is specified
44 show information only about given map, otherwise list all
45 maps currently loaded on the system.
46
47 Output will start with map ID followed by map type and
48 zero or more named attributes (depending on kernel version).
49
50 **bpftool map dump** *MAP*
51 Dump all entries in a given *MAP*.
52
Jakub Kicinskic642ea22018-05-03 18:37:14 -070053 **bpftool map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*]
Jakub Kicinskiff69c212017-10-04 20:10:05 -070054 Update map entry for a given *KEY*.
55
56 *UPDATE_FLAGS* can be one of: **any** update existing entry
57 or add if doesn't exit; **exist** update only if entry already
58 exists; **noexist** update only if entry doesn't exist.
59
Quentin Monnet0c90f222018-04-17 19:46:34 -070060 If the **hex** keyword is provided in front of the bytes
61 sequence, the bytes are parsed as hexadeximal values, even if
62 no "0x" prefix is added. If the keyword is not provided, then
63 the bytes are parsed as decimal values, unless a "0x" prefix
64 (for hexadecimal) or a "0" prefix (for octal) is provided.
65
Jakub Kicinskic642ea22018-05-03 18:37:14 -070066 **bpftool map lookup** *MAP* **key** *DATA*
Jakub Kicinskiff69c212017-10-04 20:10:05 -070067 Lookup **key** in the map.
68
Jakub Kicinskic642ea22018-05-03 18:37:14 -070069 **bpftool map getnext** *MAP* [**key** *DATA*]
Jakub Kicinskiff69c212017-10-04 20:10:05 -070070 Get next key. If *key* is not specified, get first key.
71
Jakub Kicinskic642ea22018-05-03 18:37:14 -070072 **bpftool map delete** *MAP* **key** *DATA*
Jakub Kicinskiff69c212017-10-04 20:10:05 -070073 Remove entry from the map.
74
75 **bpftool map pin** *MAP* *FILE*
76 Pin map *MAP* as *FILE*.
77
78 Note: *FILE* must be located in *bpffs* mount.
79
Jakub Kicinskif412eed2018-05-03 18:37:16 -070080 **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
81 Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
82
83 Install perf rings into a perf event array map and dump
84 output of any bpf_perf_event_output() call in the kernel.
85 By default read the number of CPUs on the system and
86 install perf ring for each CPU in the corresponding index
87 in the array.
88
89 If **cpu** and **index** are specified, install perf ring
90 for given **cpu** at **index** in the array (single ring).
91
92 Note that installing a perf ring into an array will silently
93 replace any existing ring. Any other application will stop
94 receiving events if it installed its rings earlier.
95
Jakub Kicinskiff69c212017-10-04 20:10:05 -070096 **bpftool map help**
97 Print short help message.
98
Quentin Monneta2bc2e52017-10-23 09:24:06 -070099OPTIONS
100=======
101 -h, --help
102 Print short generic help message (similar to **bpftool help**).
103
104 -v, --version
105 Print version number (similar to **bpftool version**).
106
Quentin Monnet0641c3c2017-10-23 09:24:16 -0700107 -j, --json
108 Generate JSON output. For commands that cannot produce JSON, this
109 option has no effect.
110
111 -p, --pretty
112 Generate human-readable JSON output. Implies **-j**.
113
Prashant Bholec541b732017-11-08 13:55:49 +0900114 -f, --bpffs
115 Show file names of pinned maps.
116
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700117EXAMPLES
118========
119**# bpftool map show**
120::
121
122 10: hash name some_map flags 0x0
123 key 4B value 8B max_entries 2048 memlock 167936B
124
Quentin Monnet0c90f222018-04-17 19:46:34 -0700125The following three commands are equivalent:
126
127|
128| **# bpftool map update id 10 key hex 20 c4 b7 00 value hex 0f ff ff ab 01 02 03 4c**
129| **# bpftool map update id 10 key 0x20 0xc4 0xb7 0x00 value 0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
130| **# bpftool map update id 10 key 32 196 183 0 value 15 255 255 171 1 2 3 76**
Jakub Kicinskiff69c212017-10-04 20:10:05 -0700131
132**# bpftool map lookup id 10 key 0 1 2 3**
133
134::
135
136 key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
137
138
139**# bpftool map dump id 10**
140::
141
142 key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
143 key: 0d 00 07 00 value: 02 00 00 00 01 02 03 04
144 Found 2 elements
145
146**# bpftool map getnext id 10 key 0 1 2 3**
147::
148
149 key:
150 00 01 02 03
151 next key:
152 0d 00 07 00
153
154|
155| **# mount -t bpf none /sys/fs/bpf/**
156| **# bpftool map pin id 10 /sys/fs/bpf/map**
157| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
158
159SEE ALSO
160========
Roman Gushchin5ccda642017-12-13 15:18:54 +0000161 **bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)