]> granicus.if.org Git - strace/blob - bpf_attr.h
bpf: add support for BPF_RAW_TRACEPOINT_OPEN command decoding
[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 struct BPF_MAP_CREATE_struct {
40         uint32_t map_type;
41         uint32_t key_size;
42         uint32_t value_size;
43         uint32_t max_entries;
44         uint32_t map_flags;
45         uint32_t inner_map_fd;
46         uint32_t numa_node;
47         char     map_name[BPF_OBJ_NAME_LEN];
48         uint32_t map_ifindex;
49 };
50
51 #define BPF_MAP_CREATE_struct_size \
52         sizeof(struct BPF_MAP_CREATE_struct)
53 #define expected_BPF_MAP_CREATE_struct_size 48
54
55 struct BPF_MAP_LOOKUP_ELEM_struct {
56         uint32_t map_fd;
57         uint64_t ATTRIBUTE_ALIGNED(8) key;
58         uint64_t ATTRIBUTE_ALIGNED(8) value;
59 };
60
61 #define BPF_MAP_LOOKUP_ELEM_struct_size \
62         sizeof(struct BPF_MAP_LOOKUP_ELEM_struct)
63 #define expected_BPF_MAP_LOOKUP_ELEM_struct_size 24
64
65 struct BPF_MAP_UPDATE_ELEM_struct {
66         uint32_t map_fd;
67         uint64_t ATTRIBUTE_ALIGNED(8) key;
68         uint64_t ATTRIBUTE_ALIGNED(8) value;
69         uint64_t flags;
70 };
71
72 #define BPF_MAP_UPDATE_ELEM_struct_size \
73         sizeof(struct BPF_MAP_UPDATE_ELEM_struct)
74 #define expected_BPF_MAP_UPDATE_ELEM_struct_size 32
75
76 struct BPF_MAP_DELETE_ELEM_struct {
77         uint32_t map_fd;
78         uint64_t ATTRIBUTE_ALIGNED(8) key;
79 };
80
81 #define BPF_MAP_DELETE_ELEM_struct_size \
82         sizeof(struct BPF_MAP_DELETE_ELEM_struct)
83 #define expected_BPF_MAP_DELETE_ELEM_struct_size 16
84
85 struct BPF_MAP_GET_NEXT_KEY_struct {
86         uint32_t map_fd;
87         uint64_t ATTRIBUTE_ALIGNED(8) key;
88         uint64_t ATTRIBUTE_ALIGNED(8) next_key;
89 };
90
91 #define BPF_MAP_GET_NEXT_KEY_struct_size \
92         sizeof(struct BPF_MAP_GET_NEXT_KEY_struct)
93 #define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24
94
95 struct BPF_PROG_LOAD_struct {
96         uint32_t prog_type;
97         uint32_t insn_cnt;
98         uint64_t ATTRIBUTE_ALIGNED(8) insns;
99         uint64_t ATTRIBUTE_ALIGNED(8) license;
100         uint32_t log_level;
101         uint32_t log_size;
102         uint64_t ATTRIBUTE_ALIGNED(8) log_buf;
103         uint32_t kern_version;
104         uint32_t prog_flags;
105         char     prog_name[BPF_OBJ_NAME_LEN];
106         uint32_t prog_ifindex;
107         uint32_t expected_attach_type;
108 };
109
110 #define BPF_PROG_LOAD_struct_size \
111         offsetofend(struct BPF_PROG_LOAD_struct, expected_attach_type)
112 #define expected_BPF_PROG_LOAD_struct_size 72
113
114 struct BPF_OBJ_PIN_struct {
115         uint64_t ATTRIBUTE_ALIGNED(8) pathname;
116         uint32_t bpf_fd;
117         uint32_t file_flags;
118 };
119
120 #define BPF_OBJ_PIN_struct_size \
121         sizeof(struct BPF_OBJ_PIN_struct)
122 #define expected_BPF_OBJ_PIN_struct_size 16
123
124 #define BPF_OBJ_GET_struct BPF_OBJ_PIN_struct
125 #define BPF_OBJ_GET_struct_size BPF_OBJ_PIN_struct_size
126
127 struct BPF_PROG_ATTACH_struct {
128         uint32_t target_fd;
129         uint32_t attach_bpf_fd;
130         uint32_t attach_type;
131         uint32_t attach_flags;
132 };
133
134 #define BPF_PROG_ATTACH_struct_size \
135         sizeof(struct BPF_PROG_ATTACH_struct)
136 #define expected_BPF_PROG_ATTACH_struct_size 16
137
138 struct BPF_PROG_DETACH_struct {
139         uint32_t target_fd;
140         uint32_t dummy;
141         uint32_t attach_type;
142 };
143
144 #define BPF_PROG_DETACH_struct_size \
145         sizeof(struct BPF_PROG_DETACH_struct)
146 #define expected_BPF_PROG_DETACH_struct_size 12
147
148 struct BPF_PROG_TEST_RUN_struct /* test */ {
149         uint32_t prog_fd;
150         uint32_t retval;
151         uint32_t data_size_in;
152         uint32_t data_size_out;
153         uint64_t ATTRIBUTE_ALIGNED(8) data_in;
154         uint64_t ATTRIBUTE_ALIGNED(8) data_out;
155         uint32_t repeat;
156         uint32_t duration;
157 };
158
159 #define BPF_PROG_TEST_RUN_struct_size \
160         sizeof(struct BPF_PROG_TEST_RUN_struct)
161 #define expected_BPF_PROG_TEST_RUN_struct_size 40
162
163 struct BPF_PROG_GET_NEXT_ID_struct {
164         uint32_t start_id;
165         uint32_t next_id;
166         uint32_t open_flags;
167 };
168
169 #define BPF_PROG_GET_NEXT_ID_struct_size \
170         sizeof(struct BPF_PROG_GET_NEXT_ID_struct)
171 #define expected_BPF_PROG_GET_NEXT_ID_struct_size 12
172
173 #define BPF_MAP_GET_NEXT_ID_struct BPF_PROG_GET_NEXT_ID_struct
174 #define BPF_MAP_GET_NEXT_ID_struct_size BPF_PROG_GET_NEXT_ID_struct_size
175
176 struct BPF_PROG_GET_FD_BY_ID_struct {
177         uint32_t prog_id;
178         uint32_t next_id;
179         uint32_t open_flags;
180 };
181
182 #define BPF_PROG_GET_FD_BY_ID_struct_size \
183         sizeof(struct BPF_PROG_GET_FD_BY_ID_struct)
184 #define expected_BPF_PROG_GET_FD_BY_ID_struct_size 12
185
186 struct BPF_MAP_GET_FD_BY_ID_struct {
187         uint32_t map_id;
188         uint32_t next_id;
189         uint32_t open_flags;
190 };
191
192 #define BPF_MAP_GET_FD_BY_ID_struct_size \
193         sizeof(struct BPF_MAP_GET_FD_BY_ID_struct)
194 #define expected_BPF_MAP_GET_FD_BY_ID_struct_size 12
195
196 struct BPF_OBJ_GET_INFO_BY_FD_struct /* info */ {
197         uint32_t bpf_fd;
198         uint32_t info_len;
199         uint64_t ATTRIBUTE_ALIGNED(8) info;
200 };
201
202 #define BPF_OBJ_GET_INFO_BY_FD_struct_size \
203         sizeof(struct BPF_OBJ_GET_INFO_BY_FD_struct)
204 #define expected_BPF_OBJ_GET_INFO_BY_FD_struct_size 16
205
206 struct BPF_PROG_QUERY_struct /* query */ {
207         uint32_t target_fd;
208         uint32_t attach_type;
209         uint32_t query_flags;
210         uint32_t attach_flags;
211         uint64_t ATTRIBUTE_ALIGNED(8) prog_ids;
212         uint32_t prog_cnt;
213 };
214
215 #define BPF_PROG_QUERY_struct_size \
216         offsetofend(struct BPF_PROG_QUERY_struct, prog_cnt)
217 #define expected_BPF_PROG_QUERY_struct_size 28
218
219 struct BPF_RAW_TRACEPOINT_OPEN_struct /* raw_tracepoint */ {
220         uint64_t ATTRIBUTE_ALIGNED(8) name;
221         uint32_t prog_fd;
222 };
223
224 #define BPF_RAW_TRACEPOINT_OPEN_struct_size \
225         offsetofend(struct BPF_RAW_TRACEPOINT_OPEN_struct, prog_fd)
226 #define expected_BPF_RAW_TRACEPOINT_OPEN_struct_size 12
227
228 #endif /* !STRACE_BPF_ATTR_H */