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