Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 1 | ================ |
| 2 | bpftool-map |
| 3 | ================ |
| 4 | ------------------------------------------------------------------------------- |
| 5 | tool for inspection and simple manipulation of eBPF maps |
| 6 | ------------------------------------------------------------------------------- |
| 7 | |
| 8 | :Manual section: 8 |
| 9 | |
| 10 | SYNOPSIS |
| 11 | ======== |
| 12 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 13 | **bpftool** [*OPTIONS*] **map** *COMMAND* |
| 14 | |
Prashant Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame] | 15 | *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 16 | |
| 17 | *COMMANDS* := |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 18 | { **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete** |
Quentin Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 19 | | **pin** | **help** } |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 20 | |
| 21 | MAP COMMANDS |
| 22 | ============= |
| 23 | |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 24 | | **bpftool** **map { show | list }** [*MAP*] |
Jakub Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 25 | | **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 Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 32 | | **bpftool** **map help** |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 33 | | |
Quentin Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 34 | | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* } |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 35 | | *DATA* := { [**hex**] *BYTES* } |
Quentin Monnet | 2148481 | 2018-02-07 20:27:15 -0800 | [diff] [blame] | 36 | | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 37 | | *VALUE* := { *DATA* | *MAP* | *PROG* } |
Quentin Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 38 | | *UPDATE_FLAGS* := { **any** | **exist** | **noexist** } |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 39 | |
| 40 | DESCRIPTION |
| 41 | =========== |
Jakub Kicinski | 6ebe6db | 2018-01-02 14:48:36 -0800 | [diff] [blame] | 42 | **bpftool map { show | list }** [*MAP*] |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 43 | 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 Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 53 | **bpftool map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*] |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 54 | 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 Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 60 | 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 Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 66 | **bpftool map lookup** *MAP* **key** *DATA* |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 67 | Lookup **key** in the map. |
| 68 | |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 69 | **bpftool map getnext** *MAP* [**key** *DATA*] |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 70 | Get next key. If *key* is not specified, get first key. |
| 71 | |
Jakub Kicinski | c642ea2 | 2018-05-03 18:37:14 -0700 | [diff] [blame] | 72 | **bpftool map delete** *MAP* **key** *DATA* |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 73 | 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 Kicinski | f412eed | 2018-05-03 18:37:16 -0700 | [diff] [blame] | 80 | **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 Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 96 | **bpftool map help** |
| 97 | Print short help message. |
| 98 | |
Quentin Monnet | a2bc2e5 | 2017-10-23 09:24:06 -0700 | [diff] [blame] | 99 | OPTIONS |
| 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 Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 107 | -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 Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame] | 114 | -f, --bpffs |
| 115 | Show file names of pinned maps. |
| 116 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 117 | EXAMPLES |
| 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 Monnet | 0c90f22 | 2018-04-17 19:46:34 -0700 | [diff] [blame] | 125 | The 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 Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 131 | |
| 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 | |
| 159 | SEE ALSO |
| 160 | ======== |
Roman Gushchin | 5ccda64 | 2017-12-13 15:18:54 +0000 | [diff] [blame] | 161 | **bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8) |