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