2017-10-05 11:10:05 +08:00
|
|
|
================
|
|
|
|
bpftool-map
|
|
|
|
================
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
tool for inspection and simple manipulation of eBPF maps
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
:Manual section: 8
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
========
|
|
|
|
|
2017-10-24 00:24:16 +08:00
|
|
|
**bpftool** [*OPTIONS*] **map** *COMMAND*
|
|
|
|
|
2017-11-08 12:55:49 +08:00
|
|
|
*OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
*COMMANDS* :=
|
2018-01-03 06:48:36 +08:00
|
|
|
{ **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
|
2017-10-24 00:24:15 +08:00
|
|
|
| **pin** | **help** }
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
MAP COMMANDS
|
|
|
|
=============
|
|
|
|
|
2018-01-03 06:48:36 +08:00
|
|
|
| **bpftool** **map { show | list }** [*MAP*]
|
2017-10-24 00:24:15 +08:00
|
|
|
| **bpftool** **map dump** *MAP*
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
| **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*
|
2017-10-24 00:24:15 +08:00
|
|
|
| **bpftool** **map pin** *MAP* *FILE*
|
|
|
|
| **bpftool** **map help**
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
2017-10-24 00:24:15 +08:00
|
|
|
| *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
|
2018-02-08 12:27:15 +08:00
|
|
|
| *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
|
|
|
|
| *VALUE* := { *BYTES* | *MAP* | *PROG* }
|
2017-10-24 00:24:15 +08:00
|
|
|
| *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
===========
|
2018-01-03 06:48:36 +08:00
|
|
|
**bpftool map { show | list }** [*MAP*]
|
2017-10-05 11:10:05 +08:00
|
|
|
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*.
|
|
|
|
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
**bpftool map update** *MAP* **key** [**hex**] *BYTES* **value** [**hex**] *VALUE* [*UPDATE_FLAGS*]
|
2017-10-05 11:10:05 +08:00
|
|
|
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.
|
|
|
|
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
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*
|
2017-10-05 11:10:05 +08:00
|
|
|
Lookup **key** in the map.
|
|
|
|
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
**bpftool map getnext** *MAP* [**key** [**hex**] *BYTES*]
|
2017-10-05 11:10:05 +08:00
|
|
|
Get next key. If *key* is not specified, get first key.
|
|
|
|
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
**bpftool map delete** *MAP* **key** [**hex**] *BYTES*
|
2017-10-05 11:10:05 +08:00
|
|
|
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.
|
|
|
|
|
2017-10-24 00:24:06 +08:00
|
|
|
OPTIONS
|
|
|
|
=======
|
|
|
|
-h, --help
|
|
|
|
Print short generic help message (similar to **bpftool help**).
|
|
|
|
|
|
|
|
-v, --version
|
|
|
|
Print version number (similar to **bpftool version**).
|
|
|
|
|
2017-10-24 00:24:16 +08:00
|
|
|
-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**.
|
|
|
|
|
2017-11-08 12:55:49 +08:00
|
|
|
-f, --bpffs
|
|
|
|
Show file names of pinned maps.
|
|
|
|
|
2017-10-05 11:10:05 +08:00
|
|
|
EXAMPLES
|
|
|
|
========
|
|
|
|
**# bpftool map show**
|
|
|
|
::
|
|
|
|
|
|
|
|
10: hash name some_map flags 0x0
|
|
|
|
key 4B value 8B max_entries 2048 memlock 167936B
|
|
|
|
|
tools: bpftool: make it easier to feed hex bytes to bpftool
bpftool uses hexadecimal values when it dumps map contents:
# bpftool map dump id 1337
key: ff 13 37 ff value: a1 b2 c3 d4 ff ff ff ff
Found 1 element
In order to lookup or update values with bpftool, the natural reflex is
then to copy and paste the values to the command line, and to try to run
something like:
# bpftool map update id 1337 key ff 13 37 ff \
value 00 00 00 00 00 00 1a 2b
Error: error parsing byte: ff
bpftool complains, because it uses strtoul() with a 0 base to parse the
bytes, and that without a "0x" prefix, the bytes are considered as
decimal values (or even octal if they start with "0").
To feed hexadecimal values instead, one needs to add "0x" prefixes
everywhere necessary:
# bpftool map update id 1337 key 0xff 0x13 0x37 0xff \
value 0 0 0 0 0 0 0x1a 0x2b
To make it easier to use hexadecimal values, add an optional "hex"
keyword to put after "key" or "value" to tell bpftool to consider the
digits as hexadecimal. We can now do:
# bpftool map update id 1337 key hex ff 13 37 ff \
value hex 0 0 0 0 0 0 1a 2b
Without the "hex" keyword, the bytes are still parsed according to
normal integer notation (decimal if no prefix, or hexadecimal or octal
if "0x" or "0" prefix is used, respectively).
The patch also add related documentation and bash completion for the
"hex" keyword.
Suggested-by: Daniel Borkmann <daniel@iogearbox.net>
Suggested-by: David Beckett <david.beckett@netronome.com>
Signed-off-by: Quentin Monnet <quentin.monnet@netronome.com>
Acked-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
2018-04-18 10:46:34 +08:00
|
|
|
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**
|
2017-10-05 11:10:05 +08:00
|
|
|
|
|
|
|
**# 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
|
|
|
|
========
|
2017-12-13 23:18:54 +08:00
|
|
|
**bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)
|