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