bpftool-map.rst 4.3 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
	{ **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
19
	| **pin** | **help** }
J
Jakub Kicinski 已提交
20 21 22 23

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

24
|	**bpftool** **map { show | list }**   [*MAP*]
25
|	**bpftool** **map dump**    *MAP*
26 27 28 29
|	**bpftool** **map update**  *MAP*  **key** [**hex**] *BYTES*   **value** [**hex**] *VALUE* [*UPDATE_FLAGS*]
|	**bpftool** **map lookup**  *MAP*  **key** [**hex**] *BYTES*
|	**bpftool** **map getnext** *MAP* [**key** [**hex**] *BYTES*]
|	**bpftool** **map delete**  *MAP*  **key** [**hex**] *BYTES*
30 31
|	**bpftool** **map pin**     *MAP*  *FILE*
|	**bpftool** **map help**
J
Jakub Kicinski 已提交
32
|
33
|	*MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
34 35
|	*PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
|	*VALUE* := { *BYTES* | *MAP* | *PROG* }
36
|	*UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
J
Jakub Kicinski 已提交
37 38 39

DESCRIPTION
===========
40
	**bpftool map { show | list }**   [*MAP*]
J
Jakub Kicinski 已提交
41 42 43 44 45 46 47 48 49 50
		  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).

	**bpftool map dump**    *MAP*
		  Dump all entries in a given *MAP*.

51
	**bpftool map update**  *MAP*  **key** [**hex**] *BYTES*   **value** [**hex**] *VALUE* [*UPDATE_FLAGS*]
J
Jakub Kicinski 已提交
52 53 54 55 56 57
		  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.

58 59 60 61 62 63 64
		  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.

	**bpftool map lookup**  *MAP*  **key** [**hex**] *BYTES*
J
Jakub Kicinski 已提交
65 66
		  Lookup **key** in the map.

67
	**bpftool map getnext** *MAP* [**key** [**hex**] *BYTES*]
J
Jakub Kicinski 已提交
68 69
		  Get next key.  If *key* is not specified, get first key.

70
	**bpftool map delete**  *MAP*  **key** [**hex**] *BYTES*
J
Jakub Kicinski 已提交
71 72 73 74 75 76 77 78 79 80
		  Remove entry from the map.

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

		  Note: *FILE* must be located in *bpffs* mount.

	**bpftool map help**
		  Print short help message.

81 82 83 84 85 86 87 88
OPTIONS
=======
	-h, --help
		  Print short generic help message (similar to **bpftool help**).

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

89 90 91 92 93 94 95
	-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**.

96 97 98
	-f, --bpffs
		  Show file names of pinned maps.

J
Jakub Kicinski 已提交
99 100 101 102 103 104 105 106
EXAMPLES
========
**# bpftool map show**
::

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

107 108 109 110 111 112
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 已提交
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142

**# 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
========
143
	**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)