2 * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #ifndef STRACE_BPF_ATTR_H
29 #define STRACE_BPF_ATTR_H
32 * The policy is that all fields of type uint64_t in this header file
33 * must have ATTRIBUTE_ALIGNED(8).
35 * This should not cause any contradictions with <linux/bpf.h>
36 * unless the latter is buggy.
38 * By word "buggy" I mean containing such changes as Linux kernel commit
39 * v4.16-rc1~123^2~109^2~5^2~4.
42 #ifndef BPF_OBJ_NAME_LEN
43 # define BPF_OBJ_NAME_LEN 16U
45 # if BPF_OBJ_NAME_LEN != 16U
46 # error "Unexpected value of BPF_OBJ_NAME_LEN"
51 # define BPF_TAG_SIZE 8
53 # if BPF_TAG_SIZE != 8
54 # error "Unexpected value of BPF_TAG_SIZE"
58 struct BPF_MAP_CREATE_struct {
64 uint32_t inner_map_fd;
66 char map_name[BPF_OBJ_NAME_LEN];
70 #define BPF_MAP_CREATE_struct_size \
71 sizeof(struct BPF_MAP_CREATE_struct)
72 #define expected_BPF_MAP_CREATE_struct_size 48
74 struct BPF_MAP_LOOKUP_ELEM_struct {
76 uint64_t ATTRIBUTE_ALIGNED(8) key;
77 uint64_t ATTRIBUTE_ALIGNED(8) value;
80 #define BPF_MAP_LOOKUP_ELEM_struct_size \
81 sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
82 #define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
84 struct BPF_MAP_UPDATE_ELEM_struct {
86 uint64_t ATTRIBUTE_ALIGNED(8) key;
87 uint64_t ATTRIBUTE_ALIGNED(8) value;
88 uint64_t ATTRIBUTE_ALIGNED(8) flags;
91 #define BPF_MAP_UPDATE_ELEM_struct_size \
92 sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
93 #define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
95 struct BPF_MAP_DELETE_ELEM_struct {
97 uint64_t ATTRIBUTE_ALIGNED(8) key;
100 #define BPF_MAP_DELETE_ELEM_struct_size \
101 sizeof(struct BPF_MAP_DELETE_ELEM_struct)
102 #define expected_BPF_MAP_DELETE_ELEM_struct_size 16
104 struct BPF_MAP_GET_NEXT_KEY_struct {
106 uint64_t ATTRIBUTE_ALIGNED(8) key;
107 uint64_t ATTRIBUTE_ALIGNED(8) next_key;
110 #define BPF_MAP_GET_NEXT_KEY_struct_size \
111 sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
112 #define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
114 struct BPF_PROG_LOAD_struct {
117 uint64_t ATTRIBUTE_ALIGNED(8) insns;
118 uint64_t ATTRIBUTE_ALIGNED(8) license;
121 uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
122 uint32_t kern_version;
124 char prog_name[BPF_OBJ_NAME_LEN];
125 uint32_t prog_ifindex;
126 uint32_t expected_attach_type;
129 #define BPF_PROG_LOAD_struct_size \
130 offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
131 #define expected_BPF_PROG_LOAD_struct_size 72
133 struct BPF_OBJ_PIN_struct {
134 uint64_t ATTRIBUTE_ALIGNED(8) pathname;
139 #define BPF_OBJ_PIN_struct_size \
140 sizeof(struct BPF_OBJ_PIN_struct)
141 #define expected_BPF_OBJ_PIN_struct_size 16
143 #define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
144 #define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
146 struct BPF_PROG_ATTACH_struct {
148 uint32_t attach_bpf_fd;
149 uint32_t attach_type;
150 uint32_t attach_flags;
153 #define BPF_PROG_ATTACH_struct_size \
154 sizeof(struct BPF_PROG_ATTACH_struct)
155 #define expected_BPF_PROG_ATTACH_struct_size 16
157 struct BPF_PROG_DETACH_struct {
160 uint32_t attach_type;
163 #define BPF_PROG_DETACH_struct_size \
164 sizeof(struct BPF_PROG_DETACH_struct)
165 #define expected_BPF_PROG_DETACH_struct_size 12
167 struct BPF_PROG_TEST_RUN_struct /* test */ {
170 uint32_t data_size_in;
171 uint32_t data_size_out;
172 uint64_t ATTRIBUTE_ALIGNED(8) data_in;
173 uint64_t ATTRIBUTE_ALIGNED(8) data_out;
178 #define BPF_PROG_TEST_RUN_struct_size \
179 sizeof(struct BPF_PROG_TEST_RUN_struct)
180 #define expected_BPF_PROG_TEST_RUN_struct_size 40
182 struct BPF_PROG_GET_NEXT_ID_struct {
188 #define BPF_PROG_GET_NEXT_ID_struct_size \
189 sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
190 #define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
192 #define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
193 #define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
195 struct BPF_PROG_GET_FD_BY_ID_struct {
201 #define BPF_PROG_GET_FD_BY_ID_struct_size \
202 sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
203 #define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
205 struct BPF_MAP_GET_FD_BY_ID_struct {
211 #define BPF_MAP_GET_FD_BY_ID_struct_size \
212 sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
213 #define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
215 struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
218 uint64_t ATTRIBUTE_ALIGNED(8) info;
221 #define BPF_OBJ_GET_INFO_BY_FD_struct_size \
222 sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
223 #define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
225 struct BPF_PROG_QUERY_struct /* query */ {
227 uint32_t attach_type;
228 uint32_t query_flags;
229 uint32_t attach_flags;
230 uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
234 #define BPF_PROG_QUERY_struct_size \
235 offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
236 #define expected_BPF_PROG_QUERY_struct_size 28
238 struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
239 uint64_t ATTRIBUTE_ALIGNED(8) name;
243 #define BPF_RAW_TRACEPOINT_OPEN_struct_size \
244 offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
245 #define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
247 struct bpf_map_info_struct {
252 uint32_t max_entries;
254 char name[BPF_OBJ_NAME_LEN];
257 * The kernel UAPI is broken by Linux commit
258 * v4.16-rc1~123^2~109^2~5^2~4 .
260 uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
261 uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
264 #define bpf_map_info_struct_size \
265 sizeof(struct bpf_map_info_struct)
266 #define expected_bpf_map_info_struct_size 64
268 struct bpf_prog_info_struct {
271 uint8_t tag[BPF_TAG_SIZE];
272 uint32_t jited_prog_len;
273 uint32_t xlated_prog_len;
274 uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
275 uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
276 uint64_t ATTRIBUTE_ALIGNED(8) load_time;
277 uint32_t created_by_uid;
279 uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
280 char name[BPF_OBJ_NAME_LEN];
283 * The kernel UAPI is broken by Linux commit
284 * v4.16-rc1~123^2~227^2~5^2~2 .
286 uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
287 uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
290 #define bpf_prog_info_struct_size \
291 sizeof(struct bpf_prog_info_struct)
292 #define expected_bpf_prog_info_struct_size 104
294 #endif /* !STRACE_BPF_ATTR_H */