bpftool-prog.rst 6.1 KB

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