bpftool-map.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. ================
  2. bpftool-map
  3. ================
  4. -------------------------------------------------------------------------------
  5. tool for inspection and simple manipulation of eBPF maps
  6. -------------------------------------------------------------------------------
  7. :Manual section: 8
  8. SYNOPSIS
  9. ========
  10. **bpftool** [*OPTIONS*] **map** *COMMAND*
  11. *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
  12. *COMMANDS* :=
  13. { **show** | **list** | **dump** | **update** | **lookup** | **getnext** | **delete**
  14. | **pin** | **help** }
  15. MAP COMMANDS
  16. =============
  17. | **bpftool** **map { show | list }** [*MAP*]
  18. | **bpftool** **map dump** *MAP*
  19. | **bpftool** **map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*]
  20. | **bpftool** **map lookup** *MAP* **key** *DATA*
  21. | **bpftool** **map getnext** *MAP* [**key** *DATA*]
  22. | **bpftool** **map delete** *MAP* **key** *DATA*
  23. | **bpftool** **map pin** *MAP* *FILE*
  24. | **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
  25. | **bpftool** **map help**
  26. |
  27. | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
  28. | *DATA* := { [**hex**] *BYTES* }
  29. | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
  30. | *VALUE* := { *DATA* | *MAP* | *PROG* }
  31. | *UPDATE_FLAGS* := { **any** | **exist** | **noexist** }
  32. DESCRIPTION
  33. ===========
  34. **bpftool map { show | list }** [*MAP*]
  35. Show information about loaded maps. If *MAP* is specified
  36. show information only about given map, otherwise list all
  37. maps currently loaded on the system.
  38. Output will start with map ID followed by map type and
  39. zero or more named attributes (depending on kernel version).
  40. **bpftool map dump** *MAP*
  41. Dump all entries in a given *MAP*.
  42. **bpftool map update** *MAP* **key** *DATA* **value** *VALUE* [*UPDATE_FLAGS*]
  43. Update map entry for a given *KEY*.
  44. *UPDATE_FLAGS* can be one of: **any** update existing entry
  45. or add if doesn't exit; **exist** update only if entry already
  46. exists; **noexist** update only if entry doesn't exist.
  47. If the **hex** keyword is provided in front of the bytes
  48. sequence, the bytes are parsed as hexadeximal values, even if
  49. no "0x" prefix is added. If the keyword is not provided, then
  50. the bytes are parsed as decimal values, unless a "0x" prefix
  51. (for hexadecimal) or a "0" prefix (for octal) is provided.
  52. **bpftool map lookup** *MAP* **key** *DATA*
  53. Lookup **key** in the map.
  54. **bpftool map getnext** *MAP* [**key** *DATA*]
  55. Get next key. If *key* is not specified, get first key.
  56. **bpftool map delete** *MAP* **key** *DATA*
  57. Remove entry from the map.
  58. **bpftool map pin** *MAP* *FILE*
  59. Pin map *MAP* as *FILE*.
  60. Note: *FILE* must be located in *bpffs* mount.
  61. **bpftool** **map event_pipe** *MAP* [**cpu** *N* **index** *M*]
  62. Read events from a BPF_MAP_TYPE_PERF_EVENT_ARRAY map.
  63. Install perf rings into a perf event array map and dump
  64. output of any bpf_perf_event_output() call in the kernel.
  65. By default read the number of CPUs on the system and
  66. install perf ring for each CPU in the corresponding index
  67. in the array.
  68. If **cpu** and **index** are specified, install perf ring
  69. for given **cpu** at **index** in the array (single ring).
  70. Note that installing a perf ring into an array will silently
  71. replace any existing ring. Any other application will stop
  72. receiving events if it installed its rings earlier.
  73. **bpftool map help**
  74. Print short help message.
  75. OPTIONS
  76. =======
  77. -h, --help
  78. Print short generic help message (similar to **bpftool help**).
  79. -v, --version
  80. Print version number (similar to **bpftool version**).
  81. -j, --json
  82. Generate JSON output. For commands that cannot produce JSON, this
  83. option has no effect.
  84. -p, --pretty
  85. Generate human-readable JSON output. Implies **-j**.
  86. -f, --bpffs
  87. Show file names of pinned maps.
  88. EXAMPLES
  89. ========
  90. **# bpftool map show**
  91. ::
  92. 10: hash name some_map flags 0x0
  93. key 4B value 8B max_entries 2048 memlock 167936B
  94. The following three commands are equivalent:
  95. |
  96. | **# bpftool map update id 10 key hex 20 c4 b7 00 value hex 0f ff ff ab 01 02 03 4c**
  97. | **# bpftool map update id 10 key 0x20 0xc4 0xb7 0x00 value 0x0f 0xff 0xff 0xab 0x01 0x02 0x03 0x4c**
  98. | **# bpftool map update id 10 key 32 196 183 0 value 15 255 255 171 1 2 3 76**
  99. **# bpftool map lookup id 10 key 0 1 2 3**
  100. ::
  101. key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
  102. **# bpftool map dump id 10**
  103. ::
  104. key: 00 01 02 03 value: 00 01 02 03 04 05 06 07
  105. key: 0d 00 07 00 value: 02 00 00 00 01 02 03 04
  106. Found 2 elements
  107. **# bpftool map getnext id 10 key 0 1 2 3**
  108. ::
  109. key:
  110. 00 01 02 03
  111. next key:
  112. 0d 00 07 00
  113. |
  114. | **# mount -t bpf none /sys/fs/bpf/**
  115. | **# bpftool map pin id 10 /sys/fs/bpf/map**
  116. | **# bpftool map del pinned /sys/fs/bpf/map key 13 00 07 00**
  117. SEE ALSO
  118. ========
  119. **bpftool**\ (8), **bpftool-prog**\ (8), **bpftool-cgroup**\ (8)