bpftool-map.rst 5.9 KB
Newer Older
J
Jakub Kicinski 已提交
1 2 3 4 5 6 7 8 9 10 11 12
================
bpftool-map
================
-------------------------------------------------------------------------------
tool for inspection and simple manipulation of eBPF maps
-------------------------------------------------------------------------------

:Manual section: 8

SYNOPSIS
========

13 14
	**bpftool** [*OPTIONS*] **map** *COMMAND*

15
	*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
J
Jakub Kicinski 已提交
16 17

	*COMMANDS* :=
18 19
	{ **show** | **list** | **create** | **dump** | **update** | **lookup** | **getnext**
	| **delete** | **pin** | **help** }
J
Jakub Kicinski 已提交
20 21 22 23

MAP COMMANDS
=============

24
|	**bpftool** **map { show | list }**   [*MAP*]
25 26
|	**bpftool** **map create**     *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE* \
|		**entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
27 28 29 30 31 32 33
|	**bpftool** **map dump**       *MAP*
|	**bpftool** **map update**     *MAP*  **key** *DATA*   **value** *VALUE* [*UPDATE_FLAGS*]
|	**bpftool** **map lookup**     *MAP*  **key** *DATA*
|	**bpftool** **map getnext**    *MAP* [**key** *DATA*]
|	**bpftool** **map delete**     *MAP*  **key** *DATA*
|	**bpftool** **map pin**        *MAP*  *FILE*
|	**bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
34
|	**bpftool** **map help**
J
Jakub Kicinski 已提交
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 42 43 44 45
|	*TYPE* := { **hash** | **array** | **prog_array** | **perf_event_array** | **percpu_hash**
|		| **percpu_array** | **stack_trace** | **cgroup_array** | **lru_hash**
|		| **lru_percpu_hash** | **lpm_trie** | **array_of_maps** | **hash_of_maps**
|		| **devmap** | **sockmap** | **cpumap** | **xskmap** | **sockhash**
|		| **cgroup_storage** | **reuseport_sockarray** | **percpu_cgroup_storage** }
J
Jakub Kicinski 已提交
46 47 48

DESCRIPTION
===========
49
	**bpftool map { show | list }**   [*MAP*]
J
Jakub Kicinski 已提交
50 51 52 53 54 55 56
		  Show information about loaded maps.  If *MAP* is specified
		  show information only about given map, otherwise list all
		  maps currently loaded on the system.

		  Output will start with map ID followed by map type and
		  zero or more named attributes (depending on kernel version).

57 58 59 60
	**bpftool map create** *FILE* **type** *TYPE* **key** *KEY_SIZE* **value** *VALUE_SIZE*  **entries** *MAX_ENTRIES* **name** *NAME* [**flags** *FLAGS*] [**dev** *NAME*]
		  Create a new map with given parameters and pin it to *bpffs*
		  as *FILE*.

J
Jakub Kicinski 已提交
61 62 63
	**bpftool map dump**    *MAP*
		  Dump all entries in a given *MAP*.

64
	**bpftool map update**  *MAP*  **key** *DATA*   **value** *VALUE* [*UPDATE_FLAGS*]
J
Jakub Kicinski 已提交
65 66 67 68 69 70
		  Update map entry for a given *KEY*.

		  *UPDATE_FLAGS* can be one of: **any** update existing entry
		  or add if doesn't exit; **exist** update only if entry already
		  exists; **noexist** update only if entry doesn't exist.

71 72 73 74 75 76
		  If the **hex** keyword is provided in front of the bytes
		  sequence, the bytes are parsed as hexadeximal values, even if
		  no "0x" prefix is added. If the keyword is not provided, then
		  the bytes are parsed as decimal values, unless a "0x" prefix
		  (for hexadecimal) or a "0" prefix (for octal) is provided.

77
	**bpftool map lookup**  *MAP*  **key** *DATA*
J
Jakub Kicinski 已提交
78 79
		  Lookup **key** in the map.

80
	**bpftool map getnext** *MAP* [**key** *DATA*]
J
Jakub Kicinski 已提交
81 82
		  Get next key.  If *key* is not specified, get first key.

83
	**bpftool map delete**  *MAP*  **key** *DATA*
J
Jakub Kicinski 已提交
84 85 86 87 88
		  Remove entry from the map.

	**bpftool map pin**     *MAP*  *FILE*
		  Pin map *MAP* as *FILE*.

89 90 91
		  Note: *FILE* must be located in *bpffs* mount. It must not
		  contain a dot character ('.'), which is reserved for future
		  extensions of *bpffs*.
J
Jakub Kicinski 已提交
92

93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
	**bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
		  Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.

		  Install perf rings into a perf event array map and dump
		  output of any bpf_perf_event_output() call in the kernel.
		  By default read the number of CPUs on the system and
		  install perf ring for each CPU in the corresponding index
		  in the array.

		  If **cpu** and **index** are specified, install perf ring
		  for given **cpu** at **index** in the array (single ring).

		  Note that installing a perf ring into an array will silently
		  replace any existing ring.  Any other application will stop
		  receiving events if it installed its rings earlier.

J
Jakub Kicinski 已提交
109 110 111
	**bpftool map help**
		  Print short help message.

112 113 114 115 116 117 118 119
OPTIONS
=======
	-h, --help
		  Print short generic help message (similar to **bpftool help**).

	-v, --version
		  Print version number (similar to **bpftool version**).

120 121 122 123 124 125 126
	-j, --json
		  Generate JSON output. For commands that cannot produce JSON, this
		  option has no effect.

	-p, --pretty
		  Generate human-readable JSON output. Implies **-j**.

127 128 129
	-f, --bpffs
		  Show file names of pinned maps.

J
Jakub Kicinski 已提交
130 131 132 133 134 135 136 137
EXAMPLES
========
**# bpftool map show**
::

  10: hash  name some_map  flags 0x0
	key 4B  value 8B  max_entries 2048  memlock 167936B

138 139 140 141 142 143
The following three commands are equivalent:

|
| **# bpftool map update id 10 key hex   20   c4   b7   00 value hex   0f   ff   ff   ab   01   02   03   4c**
| **# bpftool map update id 10 key     0x20 0xc4 0xb7 0x00 value     0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
| **# bpftool map update id 10 key       32  196  183    0 value       15  255  255  171    1    2    3   76**
J
Jakub Kicinski 已提交
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173

**# bpftool map lookup id 10 key 0 1 2 3**

::

  key: 00 01 02 03 value: 00 01 02 03 04 05 06 07


**# bpftool map dump id 10**
::

  key: 00 01 02 03  value: 00 01 02 03 04 05 06 07
  key: 0d 00 07 00  value: 02 00 00 00 01 02 03 04
  Found 2 elements

**# bpftool map getnext id 10 key 0 1 2 3**
::

  key:
  00 01 02 03
  next key:
  0d 00 07 00

|
| **# mount -t bpf none /sys/fs/bpf/**
| **# bpftool map pin id 10 /sys/fs/bpf/map**
| **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**

SEE ALSO
========
174
	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)