bpftool-prog.rst 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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*
  21. | **bpftool** **prog help**
  22. |
  23. | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* }
  24. DESCRIPTION
  25. ===========
  26. **bpftool prog { show | list }** [*PROG*]
  27. Show information about loaded programs. If *PROG* is
  28. specified show information only about given program, otherwise
  29. list all programs currently loaded on the system.
  30. Output will start with program ID followed by program type and
  31. zero or more named attributes (depending on kernel version).
  32. **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** | **visual** }]
  33. Dump eBPF instructions of the program from the kernel. By
  34. default, eBPF will be disassembled and printed to standard
  35. output in human-readable format. In this case, **opcodes**
  36. controls if raw opcodes should be printed as well.
  37. If **file** is specified, the binary image will instead be
  38. written to *FILE*.
  39. If **visual** is specified, control flow graph (CFG) will be
  40. built instead, and eBPF instructions will be presented with
  41. CFG in DOT format, on standard output.
  42. **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }]
  43. Dump jited image (host machine code) of the program.
  44. If *FILE* is specified image will be written to a file,
  45. otherwise it will be disassembled and printed to stdout.
  46. **opcodes** controls if raw opcodes will be printed.
  47. **bpftool prog pin** *PROG* *FILE*
  48. Pin program *PROG* as *FILE*.
  49. Note: *FILE* must be located in *bpffs* mount.
  50. **bpftool prog load** *OBJ* *FILE*
  51. Load bpf program from binary *OBJ* and pin as *FILE*.
  52. Note: *FILE* must be located in *bpffs* mount.
  53. **bpftool prog help**
  54. Print short help message.
  55. OPTIONS
  56. =======
  57. -h, --help
  58. Print short generic help message (similar to **bpftool help**).
  59. -v, --version
  60. Print version number (similar to **bpftool version**).
  61. -j, --json
  62. Generate JSON output. For commands that cannot produce JSON, this
  63. option has no effect.
  64. -p, --pretty
  65. Generate human-readable JSON output. Implies **-j**.
  66. -f, --bpffs
  67. Show file names of pinned programs.
  68. EXAMPLES
  69. ========
  70. **# bpftool prog show**
  71. ::
  72. 10: xdp name some_prog tag 005a3d2123620c8b gpl
  73. loaded_at Sep 29/20:11 uid 0
  74. xlated 528B jited 370B memlock 4096B map_ids 10
  75. **# bpftool --json --pretty prog show**
  76. ::
  77. {
  78. "programs": [{
  79. "id": 10,
  80. "type": "xdp",
  81. "tag": "005a3d2123620c8b",
  82. "gpl_compatible": true,
  83. "loaded_at": "Sep 29/20:11",
  84. "uid": 0,
  85. "bytes_xlated": 528,
  86. "jited": true,
  87. "bytes_jited": 370,
  88. "bytes_memlock": 4096,
  89. "map_ids": [10
  90. ]
  91. }
  92. ]
  93. }
  94. |
  95. | **# bpftool prog dump xlated id 10 file /tmp/t**
  96. | **# ls -l /tmp/t**
  97. | -rw------- 1 root root 560 Jul 22 01:42 /tmp/t
  98. **# bpftool prog dum jited tag 005a3d2123620c8b**
  99. ::
  100. push %rbp
  101. mov %rsp,%rbp
  102. sub $0x228,%rsp
  103. sub $0x28,%rbp
  104. mov %rbx,0x0(%rbp)
  105. |
  106. | **# mount -t bpf none /sys/fs/bpf/**
  107. | **# bpftool prog pin id 10 /sys/fs/bpf/prog**
  108. | **# bpftool prog load ./my_prog.o /sys/fs/bpf/prog2**
  109. | **# ls -l /sys/fs/bpf/**
  110. | -rw------- 1 root root 0 Jul 22 01:43 prog
  111. | -rw------- 1 root root 0 Jul 22 01:44 prog2
  112. **# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes**
  113. ::
  114. push %rbp
  115. 55
  116. mov %rsp,%rbp
  117. 48 89 e5
  118. sub $0x228,%rsp
  119. 48 81 ec 28 02 00 00
  120. sub $0x28,%rbp
  121. 48 83 ed 28
  122. mov %rbx,0x0(%rbp)
  123. 48 89 5d 00
  124. SEE ALSO
  125. ========
  126. **bpftool**\ (8), **bpftool-map**\ (8), **bpftool-cgroup**\ (8)