]> granicus.if.org Git - strace/blob - bpf_attr.h
bpf: implement decoding of BPF_BTF_LOAD command
[strace] / bpf_attr.h
1 /*
2  * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * SPDX-License-Identifier: LGPL-2.1-or-later
6  */
7
8 #ifndef STRACE_BPF_ATTR_H
9 # define STRACE_BPF_ATTR_H
10
11 /*
12  * The policy is that all fields of type uint64_t in this header file
13  * must have ATTRIBUTE_ALIGNED(8).
14  *
15  * This should not cause any contradictions with <linux/bpf.h>
16  * unless the latter is buggy.
17  *
18  * By word "buggy" I mean containing such changes as Linux kernel commit
19  * v4.16-rc1~123^2~109^2~5^2~4.
20  */
21
22 # ifndef BPF_OBJ_NAME_LEN
23 #  define BPF_OBJ_NAME_LEN 16U
24 # else
25 #  if BPF_OBJ_NAME_LEN != 16U
26 #   error "Unexpected value of BPF_OBJ_NAME_LEN"
27 #  endif
28 # endif
29
30 # ifndef BPF_TAG_SIZE
31 #  define BPF_TAG_SIZE 8
32 # else
33 #  if BPF_TAG_SIZE != 8
34 #   error "Unexpected value of BPF_TAG_SIZE"
35 #  endif
36 # endif
37
38 struct BPF_MAP_CREATE_struct {
39         uint32_t map_type;
40         uint32_t key_size;
41         uint32_t value_size;
42         uint32_t max_entries;
43         uint32_t map_flags;
44         uint32_t inner_map_fd;
45         uint32_t numa_node;
46         char     map_name[BPF_OBJ_NAME_LEN];
47         uint32_t map_ifindex;
48         uint32_t btf_fd;
49         uint32_t btf_key_type_id;
50         uint32_t btf_value_type_id;
51 };
52
53 # define BPF_MAP_CREATE_struct_size \
54         sizeof(struct BPF_MAP_CREATE_struct)
55 # define expected_BPF_MAP_CREATE_struct_size 60
56
57 struct BPF_MAP_LOOKUP_ELEM_struct {
58         uint32_t map_fd;
59         uint64_t ATTRIBUTE_ALIGNED(8) key;
60         uint64_t ATTRIBUTE_ALIGNED(8) value;
61 };
62
63 # define BPF_MAP_LOOKUP_ELEM_struct_size \
64         sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
65 # define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
66
67 struct BPF_MAP_UPDATE_ELEM_struct {
68         uint32_t map_fd;
69         uint64_t ATTRIBUTE_ALIGNED(8) key;
70         uint64_t ATTRIBUTE_ALIGNED(8) value;
71         uint64_t ATTRIBUTE_ALIGNED(8) flags;
72 };
73
74 # define BPF_MAP_UPDATE_ELEM_struct_size \
75         sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
76 # define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
77
78 struct BPF_MAP_DELETE_ELEM_struct {
79         uint32_t map_fd;
80         uint64_t ATTRIBUTE_ALIGNED(8) key;
81 };
82
83 # define BPF_MAP_DELETE_ELEM_struct_size \
84         sizeof(struct BPF_MAP_DELETE_ELEM_struct)
85 # define expected_BPF_MAP_DELETE_ELEM_struct_size 16
86
87 struct BPF_MAP_GET_NEXT_KEY_struct {
88         uint32_t map_fd;
89         uint64_t ATTRIBUTE_ALIGNED(8) key;
90         uint64_t ATTRIBUTE_ALIGNED(8) next_key;
91 };
92
93 # define BPF_MAP_GET_NEXT_KEY_struct_size \
94         sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
95 # define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
96
97 struct BPF_PROG_LOAD_struct {
98         uint32_t prog_type;
99         uint32_t insn_cnt;
100         uint64_t ATTRIBUTE_ALIGNED(8) insns;
101         uint64_t ATTRIBUTE_ALIGNED(8) license;
102         uint32_t log_level;
103         uint32_t log_size;
104         uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
105         uint32_t kern_version;
106         uint32_t prog_flags;
107         char     prog_name[BPF_OBJ_NAME_LEN];
108         uint32_t prog_ifindex;
109         uint32_t expected_attach_type;
110 };
111
112 # define BPF_PROG_LOAD_struct_size \
113         offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
114 # define expected_BPF_PROG_LOAD_struct_size 72
115
116 struct BPF_OBJ_PIN_struct {
117         uint64_t ATTRIBUTE_ALIGNED(8) pathname;
118         uint32_t bpf_fd;
119         uint32_t file_flags;
120 };
121
122 # define BPF_OBJ_PIN_struct_size \
123         sizeof(struct BPF_OBJ_PIN_struct)
124 # define expected_BPF_OBJ_PIN_struct_size 16
125
126 # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
127 # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
128
129 struct BPF_PROG_ATTACH_struct {
130         uint32_t target_fd;
131         uint32_t attach_bpf_fd;
132         uint32_t attach_type;
133         uint32_t attach_flags;
134 };
135
136 # define BPF_PROG_ATTACH_struct_size \
137         sizeof(struct BPF_PROG_ATTACH_struct)
138 # define expected_BPF_PROG_ATTACH_struct_size 16
139
140 struct BPF_PROG_DETACH_struct {
141         uint32_t target_fd;
142         uint32_t dummy;
143         uint32_t attach_type;
144 };
145
146 # define BPF_PROG_DETACH_struct_size \
147         sizeof(struct BPF_PROG_DETACH_struct)
148 # define expected_BPF_PROG_DETACH_struct_size 12
149
150 struct BPF_PROG_TEST_RUN_struct /* test */ {
151         uint32_t prog_fd;
152         uint32_t retval;
153         uint32_t data_size_in;
154         uint32_t data_size_out;
155         uint64_t ATTRIBUTE_ALIGNED(8) data_in;
156         uint64_t ATTRIBUTE_ALIGNED(8) data_out;
157         uint32_t repeat;
158         uint32_t duration;
159 };
160
161 # define BPF_PROG_TEST_RUN_struct_size \
162         sizeof(struct BPF_PROG_TEST_RUN_struct)
163 # define expected_BPF_PROG_TEST_RUN_struct_size 40
164
165 struct BPF_PROG_GET_NEXT_ID_struct {
166         uint32_t start_id;
167         uint32_t next_id;
168         uint32_t open_flags;
169 };
170
171 # define BPF_PROG_GET_NEXT_ID_struct_size \
172         sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
173 # define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
174
175 # define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
176 # define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
177
178 struct BPF_PROG_GET_FD_BY_ID_struct {
179         uint32_t prog_id;
180         uint32_t next_id;
181         uint32_t open_flags;
182 };
183
184 # define BPF_PROG_GET_FD_BY_ID_struct_size \
185         sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
186 # define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
187
188 struct BPF_MAP_GET_FD_BY_ID_struct {
189         uint32_t map_id;
190         uint32_t next_id;
191         uint32_t open_flags;
192 };
193
194 # define BPF_MAP_GET_FD_BY_ID_struct_size \
195         sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
196 # define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
197
198 struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
199         uint32_t bpf_fd;
200         uint32_t info_len;
201         uint64_t ATTRIBUTE_ALIGNED(8) info;
202 };
203
204 # define BPF_OBJ_GET_INFO_BY_FD_struct_size \
205         sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
206 # define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
207
208 struct BPF_PROG_QUERY_struct /* query */ {
209         uint32_t target_fd;
210         uint32_t attach_type;
211         uint32_t query_flags;
212         uint32_t attach_flags;
213         uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
214         uint32_t prog_cnt;
215 };
216
217 # define BPF_PROG_QUERY_struct_size \
218         offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
219 # define expected_BPF_PROG_QUERY_struct_size 28
220
221 struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
222         uint64_t ATTRIBUTE_ALIGNED(8) name;
223         uint32_t prog_fd;
224 };
225
226 # define BPF_RAW_TRACEPOINT_OPEN_struct_size \
227         offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
228 # define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
229
230 struct BPF_BTF_LOAD_struct {
231         uint64_t ATTRIBUTE_ALIGNED(8) btf;
232         uint64_t ATTRIBUTE_ALIGNED(8) btf_log_buf;
233         uint32_t btf_size;
234         uint32_t btf_log_size;
235         uint32_t btf_log_level;
236 };
237
238 # define BPF_BTF_LOAD_struct_size \
239         offsetofend(struct BPF_BTF_LOAD_struct, btf_log_level)
240 # define expected_BPF_BTF_LOAD_struct_size 28
241
242 struct bpf_map_info_struct {
243         uint32_t type;
244         uint32_t id;
245         uint32_t key_size;
246         uint32_t value_size;
247         uint32_t max_entries;
248         uint32_t map_flags;
249         char     name[BPF_OBJ_NAME_LEN];
250         uint32_t ifindex;
251         /*
252          * The kernel UAPI is broken by Linux commit
253          * v4.16-rc1~123^2~109^2~5^2~4 .
254          */
255         uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
256         uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
257         uint32_t btf_id;
258         uint32_t btf_key_type_id;
259         uint32_t btf_value_type_id;
260 };
261
262 # define bpf_map_info_struct_size \
263         offsetofend(struct bpf_map_info_struct, btf_value_type_id)
264 # define expected_bpf_map_info_struct_size 76
265
266 struct bpf_prog_info_struct {
267         uint32_t type;
268         uint32_t id;
269         uint8_t  tag[BPF_TAG_SIZE];
270         uint32_t jited_prog_len;
271         uint32_t xlated_prog_len;
272         uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
273         uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
274         uint64_t ATTRIBUTE_ALIGNED(8) load_time;
275         uint32_t created_by_uid;
276         uint32_t nr_map_ids;
277         uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
278         char     name[BPF_OBJ_NAME_LEN];
279         uint32_t ifindex;
280         uint32_t gpl_compatible:1;
281         /*
282          * The kernel UAPI is broken by Linux commit
283          * v4.16-rc1~123^2~227^2~5^2~2 .
284          */
285         uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
286         uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
287         uint32_t nr_jited_ksyms;
288         uint32_t nr_jited_func_lens;
289         uint64_t ATTRIBUTE_ALIGNED(8) jited_ksyms;
290         uint64_t ATTRIBUTE_ALIGNED(8) jited_func_lens;
291         uint32_t btf_id;
292         uint32_t func_info_rec_size;
293         uint64_t ATTRIBUTE_ALIGNED(8) func_info;
294         uint32_t nr_func_info;
295         uint32_t nr_line_info;
296         uint64_t ATTRIBUTE_ALIGNED(8) line_info;
297         uint64_t ATTRIBUTE_ALIGNED(8) jited_line_info;
298         uint32_t nr_jited_line_info;
299         uint32_t line_info_rec_size;
300         uint32_t jited_line_info_rec_size;
301         uint32_t nr_prog_tags;
302         uint64_t ATTRIBUTE_ALIGNED(8) prog_tags;
303 };
304
305 # define bpf_prog_info_struct_size \
306         sizeof(struct bpf_prog_info_struct)
307 # define expected_bpf_prog_info_struct_size 192
308
309 #endif /* !STRACE_BPF_ATTR_H */