]> granicus.if.org Git - strace/blob - bpf_attr.h
print_array: enhance printing of unfetchable object addresses
[strace] / bpf_attr.h
1 /*
2  * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. The name of the author may not be used to endorse or promote products
14  *    derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef STRACE_BPF_ATTR_H
29 #define STRACE_BPF_ATTR_H
30
31 #ifndef BPF_OBJ_NAME_LEN
32 # define BPF_OBJ_NAME_LEN 16U
33 #else
34 # if BPF_OBJ_NAME_LEN != 16U
35 #  error "Unexpected value of BPF_OBJ_NAME_LEN"
36 # endif
37 #endif
38
39 #ifndef BPF_TAG_SIZE
40 # define BPF_TAG_SIZE 8
41 #else
42 # if BPF_TAG_SIZE != 8
43 #  error "Unexpected value of BPF_TAG_SIZE"
44 # endif
45 #endif
46
47 struct BPF_MAP_CREATE_struct {
48         uint32_t map_type;
49         uint32_t key_size;
50         uint32_t value_size;
51         uint32_t max_entries;
52         uint32_t map_flags;
53         uint32_t inner_map_fd;
54         uint32_t numa_node;
55         char     map_name[BPF_OBJ_NAME_LEN];
56         uint32_t map_ifindex;
57 };
58
59 #define BPF_MAP_CREATE_struct_size \
60         sizeof(struct BPF_MAP_CREATE_struct)
61 #define expected_BPF_MAP_CREATE_struct_size 48
62
63 struct BPF_MAP_LOOKUP_ELEM_struct {
64         uint32_t map_fd;
65         uint64_t ATTRIBUTE_ALIGNED(8) key;
66         uint64_t ATTRIBUTE_ALIGNED(8) value;
67 };
68
69 #define BPF_MAP_LOOKUP_ELEM_struct_size \
70         sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
71 #define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
72
73 struct BPF_MAP_UPDATE_ELEM_struct {
74         uint32_t map_fd;
75         uint64_t ATTRIBUTE_ALIGNED(8) key;
76         uint64_t ATTRIBUTE_ALIGNED(8) value;
77         uint64_t flags;
78 };
79
80 #define BPF_MAP_UPDATE_ELEM_struct_size \
81         sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
82 #define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
83
84 struct BPF_MAP_DELETE_ELEM_struct {
85         uint32_t map_fd;
86         uint64_t ATTRIBUTE_ALIGNED(8) key;
87 };
88
89 #define BPF_MAP_DELETE_ELEM_struct_size \
90         sizeof(struct BPF_MAP_DELETE_ELEM_struct)
91 #define expected_BPF_MAP_DELETE_ELEM_struct_size 16
92
93 struct BPF_MAP_GET_NEXT_KEY_struct {
94         uint32_t map_fd;
95         uint64_t ATTRIBUTE_ALIGNED(8) key;
96         uint64_t ATTRIBUTE_ALIGNED(8) next_key;
97 };
98
99 #define BPF_MAP_GET_NEXT_KEY_struct_size \
100         sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
101 #define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
102
103 struct BPF_PROG_LOAD_struct {
104         uint32_t prog_type;
105         uint32_t insn_cnt;
106         uint64_t ATTRIBUTE_ALIGNED(8) insns;
107         uint64_t ATTRIBUTE_ALIGNED(8) license;
108         uint32_t log_level;
109         uint32_t log_size;
110         uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
111         uint32_t kern_version;
112         uint32_t prog_flags;
113         char     prog_name[BPF_OBJ_NAME_LEN];
114         uint32_t prog_ifindex;
115         uint32_t expected_attach_type;
116 };
117
118 #define BPF_PROG_LOAD_struct_size \
119         offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
120 #define expected_BPF_PROG_LOAD_struct_size 72
121
122 struct BPF_OBJ_PIN_struct {
123         uint64_t ATTRIBUTE_ALIGNED(8) pathname;
124         uint32_t bpf_fd;
125         uint32_t file_flags;
126 };
127
128 #define BPF_OBJ_PIN_struct_size \
129         sizeof(struct BPF_OBJ_PIN_struct)
130 #define expected_BPF_OBJ_PIN_struct_size 16
131
132 #define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
133 #define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
134
135 struct BPF_PROG_ATTACH_struct {
136         uint32_t target_fd;
137         uint32_t attach_bpf_fd;
138         uint32_t attach_type;
139         uint32_t attach_flags;
140 };
141
142 #define BPF_PROG_ATTACH_struct_size \
143         sizeof(struct BPF_PROG_ATTACH_struct)
144 #define expected_BPF_PROG_ATTACH_struct_size 16
145
146 struct BPF_PROG_DETACH_struct {
147         uint32_t target_fd;
148         uint32_t dummy;
149         uint32_t attach_type;
150 };
151
152 #define BPF_PROG_DETACH_struct_size \
153         sizeof(struct BPF_PROG_DETACH_struct)
154 #define expected_BPF_PROG_DETACH_struct_size 12
155
156 struct BPF_PROG_TEST_RUN_struct /* test */ {
157         uint32_t prog_fd;
158         uint32_t retval;
159         uint32_t data_size_in;
160         uint32_t data_size_out;
161         uint64_t ATTRIBUTE_ALIGNED(8) data_in;
162         uint64_t ATTRIBUTE_ALIGNED(8) data_out;
163         uint32_t repeat;
164         uint32_t duration;
165 };
166
167 #define BPF_PROG_TEST_RUN_struct_size \
168         sizeof(struct BPF_PROG_TEST_RUN_struct)
169 #define expected_BPF_PROG_TEST_RUN_struct_size 40
170
171 struct BPF_PROG_GET_NEXT_ID_struct {
172         uint32_t start_id;
173         uint32_t next_id;
174         uint32_t open_flags;
175 };
176
177 #define BPF_PROG_GET_NEXT_ID_struct_size \
178         sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
179 #define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
180
181 #define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
182 #define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
183
184 struct BPF_PROG_GET_FD_BY_ID_struct {
185         uint32_t prog_id;
186         uint32_t next_id;
187         uint32_t open_flags;
188 };
189
190 #define BPF_PROG_GET_FD_BY_ID_struct_size \
191         sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
192 #define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
193
194 struct BPF_MAP_GET_FD_BY_ID_struct {
195         uint32_t map_id;
196         uint32_t next_id;
197         uint32_t open_flags;
198 };
199
200 #define BPF_MAP_GET_FD_BY_ID_struct_size \
201         sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
202 #define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
203
204 struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
205         uint32_t bpf_fd;
206         uint32_t info_len;
207         uint64_t ATTRIBUTE_ALIGNED(8) info;
208 };
209
210 #define BPF_OBJ_GET_INFO_BY_FD_struct_size \
211         sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
212 #define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
213
214 struct BPF_PROG_QUERY_struct /* query */ {
215         uint32_t target_fd;
216         uint32_t attach_type;
217         uint32_t query_flags;
218         uint32_t attach_flags;
219         uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
220         uint32_t prog_cnt;
221 };
222
223 #define BPF_PROG_QUERY_struct_size \
224         offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
225 #define expected_BPF_PROG_QUERY_struct_size 28
226
227 struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
228         uint64_t ATTRIBUTE_ALIGNED(8) name;
229         uint32_t prog_fd;
230 };
231
232 #define BPF_RAW_TRACEPOINT_OPEN_struct_size \
233         offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
234 #define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
235
236 struct bpf_map_info_struct {
237         uint32_t type;
238         uint32_t id;
239         uint32_t key_size;
240         uint32_t value_size;
241         uint32_t max_entries;
242         uint32_t map_flags;
243         char     name[BPF_OBJ_NAME_LEN];
244         uint32_t ifindex;
245         uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* kernel UAPI is buggy, skip check */
246         uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* kernel UAPI is buggy, skip check */
247 };
248
249 #define bpf_map_info_struct_size \
250         sizeof(struct bpf_map_info_struct)
251 #define expected_bpf_map_info_struct_size 64
252
253 struct bpf_prog_info_struct {
254         uint32_t type;
255         uint32_t id;
256         uint8_t  tag[BPF_TAG_SIZE];
257         uint32_t jited_prog_len;
258         uint32_t xlated_prog_len;
259         uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
260         uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
261         uint64_t load_time;
262         uint32_t created_by_uid;
263         uint32_t nr_map_ids;
264         uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
265         char     name[BPF_OBJ_NAME_LEN];
266         uint32_t ifindex;
267         uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* kernel UAPI is buggy, skip check */
268         uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* kernel UAPI is buggy, skip check */
269 };
270
271 #define bpf_prog_info_struct_size \
272         sizeof(struct bpf_prog_info_struct)
273 #define expected_bpf_prog_info_struct_size 104
274
275 #endif /* !STRACE_BPF_ATTR_H */