bpftool-prog.rst 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. ================
  2. bpftool-prog
  3. ================
  4. -------------------------------------------------------------------------------
  5. tool for inspection and simple manipulation of eBPF progs
  6. -------------------------------------------------------------------------------
  7. :Manual section: 8
  8. SYNOPSIS
  9. ========
  10. **bpftool** [*OPTIONS*] **prog** *COMMAND*
  11. *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } }
  12. *COMMANDS* :=
  13. { **show** | **list** | **dump xlated** | **dump jited** | **pin** | **load** | **help** }
  14. MAP COMMANDS
  15. =============
  16. | **bpftool** **prog { show | list }** [*PROG*]
  17. | **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes** | **visual**}]
  18. | **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}]
  19. | **bpftool** **prog pin** *PROG* *FILE*
  20. | **bpftool** **prog load** *OBJ* *FILE* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*]
  21. | **bpftool** **prog attach** *PROG* *ATTACH_TYPE* *MAP*
  22. | **bpftool** **prog detach** *PROG* *ATTACH_TYPE* *MAP*
  23. | **bpftool** **prog help**
  24. |
  25. | *MAP* := { **id** *MAP_ID* | **pinned** *FILE* }
  26. | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
  27. | *TYPE* := {
  28. | **socket** | **kprobe** | **kretprobe** | **classifier** | **action** |
  29. | **tracepoint** | **raw_tracepoint** | **xdp** | **perf_event** | **cgroup/skb** |
  30. | **cgroup/sock** | **cgroup/dev** | **lwt_in** | **lwt_out** | **lwt_xmit** |
  31. | **lwt_seg6local** | **sockops** | **sk_skb** | **sk_msg** | **lirc_mode2** |
  32. | **cgroup/bind4** | **cgroup/bind6** | **cgroup/post_bind4** | **cgroup/post_bind6** |
  33. | **cgroup/connect4** | **cgroup/connect6** | **cgroup/sendmsg4** | **cgroup/sendmsg6**
  34. | }
  35. | *ATTACH_TYPE* := { **msg_verdict** | **skb_verdict** | **skb_parse** }
  36. DESCRIPTION
  37. ===========
  38. **bpftool prog { show | list }** [*PROG*]
  39. Show information about loaded programs. If *PROG* is
  40. specified show information only about given program, otherwise
  41. list all programs currently loaded on the system.
  42. Output will start with program ID followed by program type and
  43. zero or more named attributes (depending on kernel version).
  44. **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** }]
  45. Dump eBPF instructions of the program from the kernel. By
  46. default, eBPF will be disassembled and printed to standard
  47. output in human-readable format. In this case, **opcodes**
  48. controls if raw opcodes should be printed as well.
  49. If **file** is specified, the binary image will instead be
  50. written to *FILE*.
  51. If **visual** is specified, control flow graph (CFG) will be
  52. built instead, and eBPF instructions will be presented with
  53. CFG in DOT format, on standard output.
  54. **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }]
  55. Dump jited image (host machine code) of the program.
  56. If *FILE* is specified image will be written to a file,
  57. otherwise it will be disassembled and printed to stdout.
  58. **opcodes** controls if raw opcodes will be printed.
  59. **bpftool prog pin** *PROG* *FILE*
  60. Pin program *PROG* as *FILE*.
  61. Note: *FILE* must be located in *bpffs* mount. It must not
  62. contain a dot character ('.'), which is reserved for future
  63. extensions of *bpffs*.
  64. **bpftool prog load** *OBJ* *FILE* [**type** *TYPE*] [**map** {**idx** *IDX* | **name** *NAME*} *MAP*] [**dev** *NAME*]
  65. Load bpf program from binary *OBJ* and pin as *FILE*.
  66. **type** is optional, if not specified program type will be
  67. inferred from section names.
  68. By default bpftool will create new maps as declared in the ELF
  69. object being loaded. **map** parameter allows for the reuse
  70. of existing maps. It can be specified multiple times, each
  71. time for a different map. *IDX* refers to index of the map
  72. to be replaced in the ELF file counting from 0, while *NAME*
  73. allows to replace a map by name. *MAP* specifies the map to
  74. use, referring to it by **id** or through a **pinned** file.
  75. If **dev** *NAME* is specified program will be loaded onto
  76. given networking device (offload).
  77. Note: *FILE* must be located in *bpffs* mount. It must not
  78. contain a dot character ('.'), which is reserved for future
  79. extensions of *bpffs*.
  80. **bpftool prog attach** *PROG* *ATTACH_TYPE* *MAP*
  81. Attach bpf program *PROG* (with type specified by *ATTACH_TYPE*)
  82. to the map *MAP*.
  83. **bpftool prog detach** *PROG* *ATTACH_TYPE* *MAP*
  84. Detach bpf program *PROG* (with type specified by *ATTACH_TYPE*)
  85. from the map *MAP*.
  86. **bpftool prog help**
  87. Print short help message.
  88. OPTIONS
  89. =======
  90. -h, --help
  91. Print short generic help message (similar to **bpftool help**).
  92. -v, --version
  93. Print version number (similar to **bpftool version**).
  94. -j, --json
  95. Generate JSON output. For commands that cannot produce JSON, this
  96. option has no effect.
  97. -p, --pretty
  98. Generate human-readable JSON output. Implies **-j**.
  99. -f, --bpffs
  100. Show file names of pinned programs.
  101. EXAMPLES
  102. ========
  103. **# bpftool prog show**
  104. ::
  105. 10: xdp name some_prog tag 005a3d2123620c8b gpl
  106. loaded_at Sep 29/20:11 uid 0
  107. xlated 528B jited 370B memlock 4096B map_ids 10
  108. **# bpftool --json --pretty prog show**
  109. ::
  110. {
  111. "programs": [{
  112. "id": 10,
  113. "type": "xdp",
  114. "tag": "005a3d2123620c8b",
  115. "gpl_compatible": true,
  116. "loaded_at": "Sep 29/20:11",
  117. "uid": 0,
  118. "bytes_xlated": 528,
  119. "jited": true,
  120. "bytes_jited": 370,
  121. "bytes_memlock": 4096,
  122. "map_ids": [10
  123. ]
  124. }
  125. ]
  126. }
  127. |
  128. | **# bpftool prog dump xlated id 10 file /tmp/t**
  129. | **# ls -l /tmp/t**
  130. | -rw------- 1 root root 560 Jul 22 01:42 /tmp/t
  131. **# bpftool prog dum jited tag 005a3d2123620c8b**
  132. ::
  133. push %rbp
  134. mov %rsp,%rbp
  135. sub $0x228,%rsp
  136. sub $0x28,%rbp
  137. mov %rbx,0x0(%rbp)
  138. |
  139. | **# mount -t bpf none /sys/fs/bpf/**
  140. | **# bpftool prog pin id 10 /sys/fs/bpf/prog**
  141. | **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2**
  142. | **# ls -l /sys/fs/bpf/**
  143. | -rw------- 1 root root 0 Jul 22 01:43 prog
  144. | -rw------- 1 root root 0 Jul 22 01:44 prog2
  145. **# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes**
  146. ::
  147. push %rbp
  148. 55
  149. mov %rsp,%rbp
  150. 48 89 e5
  151. sub $0x228,%rsp
  152. 48 81 ec 28 02 00 00
  153. sub $0x28,%rbp
  154. 48 83 ed 28
  155. mov %rbx,0x0(%rbp)
  156. 48 89 5d 00
  157. |
  158. | **# bpftool prog load xdp1_kern.o /sys/fs/bpf/xdp1 type xdp map name rxcnt id 7**
  159. | **# bpftool prog show pinned /sys/fs/bpf/xdp1**
  160. | 9: xdp name xdp_prog1 tag 539ec6ce11b52f98 gpl
  161. | loaded_at 2018-06-25T16:17:31-0700 uid 0
  162. | xlated 488B jited 336B memlock 4096B map_ids 7
  163. | **# rm /sys/fs/bpf/xdp1**
  164. |
  165. SEE ALSO
  166. ========
  167. **bpftool**\ (8), **bpftool-map**\ (8), **bpftool-cgroup**\ (8)