Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 1 | ================ |
| 2 | bpftool-prog |
| 3 | ================ |
| 4 | ------------------------------------------------------------------------------- |
| 5 | tool for inspection and simple manipulation of eBPF progs |
| 6 | ------------------------------------------------------------------------------- |
| 7 | |
| 8 | :Manual section: 8 |
| 9 | |
| 10 | SYNOPSIS |
| 11 | ======== |
| 12 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 13 | **bpftool** [*OPTIONS*] **prog** *COMMAND* |
| 14 | |
Prashant Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame^] | 15 | *OPTIONS* := { { **-j** | **--json** } [{ **-p** | **--pretty** }] | { **-f** | **--bpffs** } } |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 16 | |
| 17 | *COMMANDS* := |
| 18 | { **show** | **dump xlated** | **dump jited** | **pin** | **help** } |
| 19 | |
| 20 | MAP COMMANDS |
| 21 | ============= |
| 22 | |
Quentin Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 23 | | **bpftool** **prog show** [*PROG*] |
| 24 | | **bpftool** **prog dump xlated** *PROG* [{**file** *FILE* | **opcodes**}] |
| 25 | | **bpftool** **prog dump jited** *PROG* [{**file** *FILE* | **opcodes**}] |
| 26 | | **bpftool** **prog pin** *PROG* *FILE* |
| 27 | | **bpftool** **prog help** |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 28 | | |
Quentin Monnet | 47ff7ac | 2017-10-23 09:24:15 -0700 | [diff] [blame] | 29 | | *PROG* := { **id** *PROG_ID* | **pinned** *FILE* | **tag** *PROG_TAG* } |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 30 | |
| 31 | DESCRIPTION |
| 32 | =========== |
| 33 | **bpftool prog show** [*PROG*] |
| 34 | Show information about loaded programs. If *PROG* is |
| 35 | specified show information only about given program, otherwise |
| 36 | list all programs currently loaded on the system. |
| 37 | |
| 38 | Output will start with program ID followed by program type and |
| 39 | zero or more named attributes (depending on kernel version). |
| 40 | |
Quentin Monnet | 8dfbc6d | 2017-10-19 15:46:25 -0700 | [diff] [blame] | 41 | **bpftool prog dump xlated** *PROG* [{ **file** *FILE* | **opcodes** }] |
Jakub Kicinski | c9c3599 | 2017-10-09 10:30:13 -0700 | [diff] [blame] | 42 | Dump eBPF instructions of the program from the kernel. |
| 43 | If *FILE* is specified image will be written to a file, |
| 44 | otherwise it will be disassembled and printed to stdout. |
| 45 | |
| 46 | **opcodes** controls if raw opcodes will be printed. |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 47 | |
Quentin Monnet | 8dfbc6d | 2017-10-19 15:46:25 -0700 | [diff] [blame] | 48 | **bpftool prog dump jited** *PROG* [{ **file** *FILE* | **opcodes** }] |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 49 | Dump jited image (host machine code) of the program. |
| 50 | If *FILE* is specified image will be written to a file, |
| 51 | otherwise it will be disassembled and printed to stdout. |
| 52 | |
| 53 | **opcodes** controls if raw opcodes will be printed. |
| 54 | |
| 55 | **bpftool prog pin** *PROG* *FILE* |
| 56 | Pin program *PROG* as *FILE*. |
| 57 | |
| 58 | Note: *FILE* must be located in *bpffs* mount. |
| 59 | |
| 60 | **bpftool prog help** |
| 61 | Print short help message. |
| 62 | |
Quentin Monnet | a2bc2e5 | 2017-10-23 09:24:06 -0700 | [diff] [blame] | 63 | OPTIONS |
| 64 | ======= |
| 65 | -h, --help |
| 66 | Print short generic help message (similar to **bpftool help**). |
| 67 | |
| 68 | -v, --version |
| 69 | Print version number (similar to **bpftool version**). |
| 70 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 71 | -j, --json |
| 72 | Generate JSON output. For commands that cannot produce JSON, this |
| 73 | option has no effect. |
| 74 | |
| 75 | -p, --pretty |
| 76 | Generate human-readable JSON output. Implies **-j**. |
| 77 | |
Prashant Bhole | c541b73 | 2017-11-08 13:55:49 +0900 | [diff] [blame^] | 78 | -f, --bpffs |
| 79 | Show file names of pinned programs. |
| 80 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 81 | EXAMPLES |
| 82 | ======== |
| 83 | **# bpftool prog show** |
| 84 | :: |
| 85 | |
Jakub Kicinski | 2dc7c1f | 2017-10-16 10:12:54 -0700 | [diff] [blame] | 86 | 10: xdp name some_prog tag 005a3d2123620c8b |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 87 | loaded_at Sep 29/20:11 uid 0 |
| 88 | xlated 528B jited 370B memlock 4096B map_ids 10 |
| 89 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 90 | **# bpftool --json --pretty prog show** |
| 91 | |
| 92 | :: |
| 93 | |
| 94 | { |
| 95 | "programs": [{ |
| 96 | "id": 10, |
| 97 | "type": "xdp", |
| 98 | "tag": "005a3d2123620c8b", |
| 99 | "loaded_at": "Sep 29/20:11", |
| 100 | "uid": 0, |
| 101 | "bytes_xlated": 528, |
| 102 | "jited": true, |
| 103 | "bytes_jited": 370, |
| 104 | "bytes_memlock": 4096, |
| 105 | "map_ids": [10 |
| 106 | ] |
| 107 | } |
| 108 | ] |
| 109 | } |
| 110 | |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 111 | | |
| 112 | | **# bpftool prog dump xlated id 10 file /tmp/t** |
| 113 | | **# ls -l /tmp/t** |
| 114 | | -rw------- 1 root root 560 Jul 22 01:42 /tmp/t |
| 115 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 116 | **# bpftool prog dum jited tag 005a3d2123620c8b** |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 117 | |
| 118 | :: |
| 119 | |
| 120 | push %rbp |
| 121 | mov %rsp,%rbp |
| 122 | sub $0x228,%rsp |
| 123 | sub $0x28,%rbp |
| 124 | mov %rbx,0x0(%rbp) |
| 125 | |
Quentin Monnet | 0641c3c | 2017-10-23 09:24:16 -0700 | [diff] [blame] | 126 | | |
| 127 | | **# mount -t bpf none /sys/fs/bpf/** |
| 128 | | **# bpftool prog pin id 10 /sys/fs/bpf/prog** |
| 129 | | **# ls -l /sys/fs/bpf/** |
| 130 | | -rw------- 1 root root 0 Jul 22 01:43 prog |
| 131 | |
| 132 | **# bpftool prog dum jited pinned /sys/fs/bpf/prog opcodes** |
| 133 | |
| 134 | :: |
| 135 | |
| 136 | push %rbp |
| 137 | 55 |
| 138 | mov %rsp,%rbp |
| 139 | 48 89 e5 |
| 140 | sub $0x228,%rsp |
| 141 | 48 81 ec 28 02 00 00 |
| 142 | sub $0x28,%rbp |
| 143 | 48 83 ed 28 |
| 144 | mov %rbx,0x0(%rbp) |
| 145 | 48 89 5d 00 |
Jakub Kicinski | ff69c21 | 2017-10-04 20:10:05 -0700 | [diff] [blame] | 146 | |
| 147 | |
| 148 | SEE ALSO |
| 149 | ======== |
| 150 | **bpftool**\ (8), **bpftool-map**\ (8) |