2 * Copyright (c) 2015-2018 Dmitry V. Levin <ldv@altlinux.org>
5 * SPDX-License-Identifier: LGPL-2.1-or-later
8 #ifndef STRACE_BPF_ATTR_H
9 # define STRACE_BPF_ATTR_H
12 * The policy is that all fields of type uint64_t in this header file
13 * must have ATTRIBUTE_ALIGNED(8).
15 * This should not cause any contradictions with <linux/bpf.h>
16 * unless the latter is buggy.
18 * By word "buggy" I mean containing such changes as Linux kernel commit
19 * v4.16-rc1~123^2~109^2~5^2~4.
22 # ifndef BPF_OBJ_NAME_LEN
23 # define BPF_OBJ_NAME_LEN 16U
25 # if BPF_OBJ_NAME_LEN != 16U
26 # error "Unexpected value of BPF_OBJ_NAME_LEN"
31 # define BPF_TAG_SIZE 8
33 # if BPF_TAG_SIZE != 8
34 # error "Unexpected value of BPF_TAG_SIZE"
38 struct BPF_MAP_CREATE_struct {
44 uint32_t inner_map_fd;
46 char map_name[BPF_OBJ_NAME_LEN];
49 uint32_t btf_key_type_id;
50 uint32_t btf_value_type_id;
53 # define BPF_MAP_CREATE_struct_size \
54 sizeof(struct BPF_MAP_CREATE_struct)
55 # define expected_BPF_MAP_CREATE_struct_size 60
57 struct BPF_MAP_LOOKUP_ELEM_struct {
59 uint64_t ATTRIBUTE_ALIGNED(8) key;
60 uint64_t ATTRIBUTE_ALIGNED(8) value;
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
67 struct BPF_MAP_UPDATE_ELEM_struct {
69 uint64_t ATTRIBUTE_ALIGNED(8) key;
70 uint64_t ATTRIBUTE_ALIGNED(8) value;
71 uint64_t ATTRIBUTE_ALIGNED(8) flags;
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
78 struct BPF_MAP_DELETE_ELEM_struct {
80 uint64_t ATTRIBUTE_ALIGNED(8) key;
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
87 struct BPF_MAP_GET_NEXT_KEY_struct {
89 uint64_t ATTRIBUTE_ALIGNED(8) key;
90 uint64_t ATTRIBUTE_ALIGNED(8) next_key;
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
97 struct BPF_PROG_LOAD_struct {
100 uint64_t ATTRIBUTE_ALIGNED(8) insns;
101 uint64_t ATTRIBUTE_ALIGNED(8) license;
104 uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
105 uint32_t kern_version;
107 char prog_name[BPF_OBJ_NAME_LEN];
108 uint32_t prog_ifindex;
109 uint32_t expected_attach_type;
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
116 struct BPF_OBJ_PIN_struct {
117 uint64_t ATTRIBUTE_ALIGNED(8) pathname;
122 # define BPF_OBJ_PIN_struct_size \
123 sizeof(struct BPF_OBJ_PIN_struct)
124 # define expected_BPF_OBJ_PIN_struct_size 16
126 # define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
127 # define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
129 struct BPF_PROG_ATTACH_struct {
131 uint32_t attach_bpf_fd;
132 uint32_t attach_type;
133 uint32_t attach_flags;
136 # define BPF_PROG_ATTACH_struct_size \
137 sizeof(struct BPF_PROG_ATTACH_struct)
138 # define expected_BPF_PROG_ATTACH_struct_size 16
140 struct BPF_PROG_DETACH_struct {
143 uint32_t attach_type;
146 # define BPF_PROG_DETACH_struct_size \
147 sizeof(struct BPF_PROG_DETACH_struct)
148 # define expected_BPF_PROG_DETACH_struct_size 12
150 struct BPF_PROG_TEST_RUN_struct /* test */ {
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;
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
165 struct BPF_PROG_GET_NEXT_ID_struct {
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
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
178 struct BPF_PROG_GET_FD_BY_ID_struct {
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
188 struct BPF_MAP_GET_FD_BY_ID_struct {
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
198 struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
201 uint64_t ATTRIBUTE_ALIGNED(8) info;
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
208 struct BPF_PROG_QUERY_struct /* query */ {
210 uint32_t attach_type;
211 uint32_t query_flags;
212 uint32_t attach_flags;
213 uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
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
221 struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
222 uint64_t ATTRIBUTE_ALIGNED(8) name;
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
230 struct bpf_map_info_struct {
235 uint32_t max_entries;
237 char name[BPF_OBJ_NAME_LEN];
240 * The kernel UAPI is broken by Linux commit
241 * v4.16-rc1~123^2~109^2~5^2~4 .
243 uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
244 uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
246 uint32_t btf_key_type_id;
247 uint32_t btf_value_type_id;
250 # define bpf_map_info_struct_size \
251 offsetofend(struct bpf_map_info_struct, btf_value_type_id)
252 # define expected_bpf_map_info_struct_size 76
254 struct bpf_prog_info_struct {
257 uint8_t tag[BPF_TAG_SIZE];
258 uint32_t jited_prog_len;
259 uint32_t xlated_prog_len;
260 uint64_t ATTRIBUTE_ALIGNED(8) jited_prog_insns;
261 uint64_t ATTRIBUTE_ALIGNED(8) xlated_prog_insns;
262 uint64_t ATTRIBUTE_ALIGNED(8) load_time;
263 uint32_t created_by_uid;
265 uint64_t ATTRIBUTE_ALIGNED(8) map_ids;
266 char name[BPF_OBJ_NAME_LEN];
268 uint32_t gpl_compatible:1;
270 * The kernel UAPI is broken by Linux commit
271 * v4.16-rc1~123^2~227^2~5^2~2 .
273 uint64_t ATTRIBUTE_ALIGNED(8) netns_dev; /* skip check */
274 uint64_t ATTRIBUTE_ALIGNED(8) netns_ino; /* skip check */
277 # define bpf_prog_info_struct_size \
278 sizeof(struct bpf_prog_info_struct)
279 # define expected_bpf_prog_info_struct_size 104
281 #endif /* !STRACE_BPF_ATTR_H */