eBPF for Windows
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bpf.h
Go to the documentation of this file.
1// Copyright (c) eBPF for Windows contributors
2// SPDX-License-Identifier: MIT
3#pragma once
4
8
9#include "ebpf_structs.h"
10
11#include <stdint.h>
12
13#ifdef _MSC_VER
14// This file is being included by a user-mode Windows application.
15#include "ebpf_api.h"
16#include "ebpf_program_types.h"
17#define LIBBPF_API
18#include "libbpf/src/libbpf_common.h"
19#undef LIBBPF_DEPRECATED
20#define LIBBPF_DEPRECATED(x)
21#else
22// This file is being included by an eBPF program.
23typedef int32_t s32;
24typedef uint8_t u8;
25typedef uint32_t u32;
26typedef uint64_t u64;
27#endif
28
29#define __SIZEOF_SIZE_T__ 8 /* only x64 is supported */
30#define __SIZEOF_LONG_LONG__ 8 /* only x64 is supported */
31
32typedef int32_t __s32;
33
34typedef uint8_t __u8;
35typedef uint32_t __u32;
36typedef uint64_t __u64;
37typedef uint32_t pid_t;
38
43
48
49// All types below must be ABI compatible with the Linux bpf() syscalls. This means
50// that the order, size and alignment of the types must match uapi/linux/bpf.h in
51// a tagged release of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/.
52// Constants must also match.
53//
54// Names do not have to match, but try to keep them the same as much as possible.
55// In case of conflicts prefix them with "sys_" or "SYS_".
56
57#define SYS_BPF_OBJ_NAME_LEN 16U
58
84
85#ifdef _MSC_VER
86#pragma warning(push)
87#pragma warning(default : 4820) // reject implicit padding
88#endif
89
91typedef struct
92{
94 uint32_t key_size;
95 uint32_t value_size;
96 uint32_t max_entries;
97 uint32_t map_flags;
98 uint32_t inner_map_fd;
99 uint32_t numa_node;
100 char map_name[SYS_BPF_OBJ_NAME_LEN];
101 uint32_t map_ifindex;
103
104typedef struct
105{
106 uint32_t map_fd;
107 uint32_t _pad0;
108 uint64_t key;
109 uint64_t value;
110 uint64_t flags;
112
113typedef struct
114{
115 uint32_t map_fd;
116 uint32_t _pad0;
117 uint64_t key;
119
120typedef struct
121{
122 uint32_t map_fd;
123 uint32_t _pad0;
124 uint64_t key;
125 uint64_t next_key;
127
128typedef struct
129{
130 uint32_t start_id;
131 uint32_t next_id;
133
134typedef struct
135{
137 uint32_t insn_cnt;
138 uint64_t insns;
139 uint64_t license;
140 uint32_t log_level;
141 uint32_t log_size;
142 uint64_t log_buf;
143 uint32_t kern_version;
144 uint32_t prog_flags;
145 char prog_name[SYS_BPF_OBJ_NAME_LEN];
146 uint32_t prog_ifindex;
148 uint32_t prog_btf_fd;
150 uint64_t func_info;
151 uint32_t func_info_cnt;
153 uint64_t line_info;
154 uint32_t line_info_cnt;
155 uint32_t attach_btf_id;
156 union
157 {
162 };
163 uint32_t core_relo_cnt;
164 uint64_t fd_array;
165 uint64_t core_relos;
167 uint32_t log_true_size;
169
177
178typedef struct
179{
180 uint32_t prog_fd;
181 uint32_t retval;
182 uint32_t data_size_in;
183 uint32_t data_size_out;
184 uint64_t data_in;
185 uint64_t data_out;
186 uint32_t repeat;
187 uint32_t duration;
188 uint32_t ctx_size_in;
189 uint32_t ctx_size_out;
190 uint64_t ctx_in;
191 uint64_t ctx_out;
192 uint32_t flags;
193 uint32_t cpu;
194 uint32_t batch_size;
195 uint32_t _pad0;
197
198typedef struct
199{
200 uint64_t pathname;
201 uint32_t bpf_fd;
202 uint32_t flags;
204
206typedef struct
207{
208 uint32_t bpf_fd;
213 uint32_t info_len;
214 uint64_t info;
216
227
228typedef struct
229{
232 char tag[8];
233 uint32_t jited_prog_len;
237 uint64_t load_time;
238 uint32_t created_by_uid;
239 uint32_t nr_map_ids;
240 uint64_t map_ids;
243
250
252typedef struct
253{
254 uint32_t link_fd;
256
258typedef struct
259{
260 uint32_t prog_fd;
261 uint32_t map_fd;
262 uint32_t flags;
264
267{
268 // BPF_MAP_CREATE
270
271 // BPF_MAP_LOOKUP_ELEM
272 // BPF_MAP_UPDATE_ELEM
275
276 // BPF_MAP_GET_NEXT_KEY
278
279 // BPF_MAP_DELETE_ELEM
281
282 // BPF_PROG_LOAD
284
285 // BPF_PROG_ATTACH
286 // BPF_PROG_DETACH
288
289 // BPF_OBJ_PIN
290 // BPF_OBJ_GET
292
293 // BPF_PROG_GET_NEXT_ID
294 // BPF_MAP_GET_NEXT_ID
295 // BPF_LINK_GET_NEXT_ID
298
299 // BPF_MAP_GET_FD_BY_ID
300 uint32_t map_id;
301
302 // BPF_PROG_GET_FD_BY_ID
303 uint32_t prog_id;
304
305 // BPF_LINK_GET_FD_BY_ID
306 uint32_t link_id;
307
308 // BPF_OBJ_GET_INFO_BY_FD
310
311 // BPF_LINK_DETACH
313
314 // BPF_PROG_BIND_MAP
316
317 // BPF_PROG_TEST_RUN
319};
320
321#ifdef _MSC_VER
322#pragma warning(pop)
323#endif
324
325int
326bpf(int cmd, union bpf_attr* attr, unsigned int size);
This file contains eBPF definitions common to eBPF programs, core execution engine as well as eBPF AP...
bpf_prog_type
Definition ebpf_structs.h:178
bpf_link_type
Definition ebpf_structs.h:278
enum bpf_map_type ebpf_map_type_t
uint32_t ebpf_id_t
Definition ebpf_structs.h:99
bpf_attach_type
Definition ebpf_structs.h:289
bpf_map_type
Definition ebpf_structs.h:18
int32_t __s32
Definition bpf.h:32
uint32_t __u32
Definition bpf.h:35
uint64_t u64
Definition bpf.h:26
bpf_func_id
Definition bpf.h:40
@ BPF_FUNC_ID_UNKNOWN
Definition bpf.h:41
uint8_t __u8
Definition bpf.h:34
uint32_t pid_t
Definition bpf.h:37
uint8_t u8
Definition bpf.h:24
bpf_cmd_id
Definition bpf.h:60
@ BPF_MAP_LOOKUP_AND_DELETE_ELEM
Definition bpf.h:77
@ BPF_PROG_RUN
Definition bpf.h:82
@ BPF_MAP_CREATE
Definition bpf.h:61
@ BPF_OBJ_GET
Definition bpf.h:68
@ BPF_PROG_LOAD
Definition bpf.h:66
@ BPF_PROG_DETACH
Definition bpf.h:70
@ BPF_PROG_GET_NEXT_ID
Definition bpf.h:72
@ BPF_PROG_ATTACH
Definition bpf.h:69
@ BPF_OBJ_PIN
Definition bpf.h:67
@ BPF_MAP_GET_FD_BY_ID
Definition bpf.h:75
@ BPF_LINK_GET_NEXT_ID
Definition bpf.h:79
@ BPF_LINK_DETACH
Definition bpf.h:80
@ BPF_PROG_TEST_RUN
Definition bpf.h:71
@ BPF_PROG_BIND_MAP
Definition bpf.h:81
@ BPF_MAP_GET_NEXT_KEY
Definition bpf.h:65
@ BPF_LINK_GET_FD_BY_ID
Definition bpf.h:78
@ BPF_PROG_GET_FD_BY_ID
Definition bpf.h:74
@ BPF_OBJ_GET_INFO_BY_FD
Definition bpf.h:76
@ BPF_MAP_GET_NEXT_ID
Definition bpf.h:73
@ BPF_MAP_UPDATE_ELEM
Definition bpf.h:63
@ BPF_MAP_LOOKUP_ELEM
Definition bpf.h:62
@ BPF_MAP_DELETE_ELEM
Definition bpf.h:64
#define SYS_BPF_OBJ_NAME_LEN
Definition bpf.h:57
uint64_t __u64
Definition bpf.h:36
int bpf(int cmd, union bpf_attr *attr, unsigned int size)
int32_t s32
Definition bpf.h:23
bpf_stats_type
Definition bpf.h:45
@ BPF_STATS_TYPE_UNKNOWN
Definition bpf.h:46
uint32_t u32
Definition bpf.h:25
Attributes used by BPF_MAP_CREATE.
Definition bpf.h:92
uint32_t value_size
Size in bytes of values.
Definition bpf.h:95
uint32_t max_entries
Maximum number of entries in the map.
Definition bpf.h:96
uint32_t map_ifindex
Not supported, must be zero.
Definition bpf.h:101
uint32_t numa_node
Not supported, must be zero.
Definition bpf.h:99
uint32_t key_size
Size in bytes of keys.
Definition bpf.h:94
uint32_t map_flags
Not supported, must be zero.
Definition bpf.h:97
uint32_t inner_map_fd
File descriptor of inner map.
Definition bpf.h:98
enum bpf_map_type map_type
Type of map to create.
Definition bpf.h:93
Definition bpf.h:114
uint32_t map_fd
File descriptor of map.
Definition bpf.h:115
uint64_t key
Pointer to key to delete.
Definition bpf.h:117
uint32_t _pad0
Definition bpf.h:116
Definition bpf.h:218
ebpf_id_t id
Map ID.
Definition bpf.h:220
uint32_t map_flags
Map flags.
Definition bpf.h:224
uint32_t max_entries
Maximum number of entries allowed in the map.
Definition bpf.h:223
uint32_t value_size
Size in bytes of a map value.
Definition bpf.h:222
ebpf_map_type_t type
Type of map.
Definition bpf.h:219
uint32_t key_size
Size in bytes of a map key.
Definition bpf.h:221
Definition bpf.h:105
uint32_t map_fd
File descriptor of map.
Definition bpf.h:106
uint64_t key
Pointer to key to look up.
Definition bpf.h:108
uint64_t flags
Not supported, must be zero.
Definition bpf.h:110
uint32_t _pad0
Definition bpf.h:107
uint64_t value
Pointer to value.
Definition bpf.h:109
Definition bpf.h:129
uint32_t start_id
ID to look for an ID after. The start_id need not exist.
Definition bpf.h:130
uint32_t next_id
On return, contains the next ID.
Definition bpf.h:131
Definition bpf.h:121
uint64_t key
Pointer to key to look up.
Definition bpf.h:124
uint32_t _pad0
Definition bpf.h:123
uint32_t map_fd
File descriptor of map.
Definition bpf.h:122
uint64_t next_key
Pointer to next key.
Definition bpf.h:125
Attributes used by BPF_OBJ_GET_INFO_BY_FD.
Definition bpf.h:207
uint32_t info_len
On input, contains the maximum number of bytes to write into the info. On output, contains the actual...
Definition bpf.h:213
uint32_t bpf_fd
File descriptor referring to an eBPF object.
Definition bpf.h:208
uint64_t info
Pointer to memory in which to write the info obtained.
Definition bpf.h:214
Definition bpf.h:199
uint32_t flags
Not supported, must be zero.
Definition bpf.h:202
uint32_t bpf_fd
File descriptor referring to the program or map.
Definition bpf.h:201
uint64_t pathname
Path name for pinning.
Definition bpf.h:200
Definition bpf.h:171
uint32_t attach_flags
Flags affecting the attach operation.
Definition bpf.h:175
enum bpf_attach_type attach_type
Type of program to attach/detach to/from.
Definition bpf.h:174
uint32_t target_fd
eBPF target to attach/detach to/from.
Definition bpf.h:172
uint32_t attach_bpf_fd
File descriptor of program to attach to.
Definition bpf.h:173
Attributes used by BPF_PROG_BIND_MAP.
Definition bpf.h:259
uint32_t map_fd
File descriptor of map to bind.
Definition bpf.h:261
uint32_t flags
Flags affecting the bind operation.
Definition bpf.h:262
uint32_t prog_fd
File descriptor of program to bind map to.
Definition bpf.h:260
Definition bpf.h:229
enum bpf_prog_type type
Program type.
Definition bpf.h:230
uint64_t jited_prog_insns
Not supported.
Definition bpf.h:235
uint32_t jited_prog_len
Not supported.
Definition bpf.h:233
uint32_t nr_map_ids
Number of maps associated with this program.
Definition bpf.h:239
uint32_t created_by_uid
Not supported.
Definition bpf.h:238
uint64_t map_ids
Pointer to caller-allocated array to fill map IDs into.
Definition bpf.h:240
uint64_t xlated_prog_insns
Not supported.
Definition bpf.h:236
ebpf_id_t id
Program ID.
Definition bpf.h:231
uint32_t xlated_prog_len
Not supported.
Definition bpf.h:234
uint64_t load_time
Not supported.
Definition bpf.h:237
Definition bpf.h:135
uint32_t insn_cnt
Number of instructions in the array.
Definition bpf.h:137
uint32_t line_info_rec_size
Not supported, must be zero.
Definition bpf.h:152
uint32_t attach_prog_fd
< Not supported, must be zero.
Definition bpf.h:159
uint64_t log_buf
Pointer to a buffer in which log info can be written.
Definition bpf.h:142
uint64_t fd_array
Not supported, must be zero.
Definition bpf.h:164
uint32_t prog_ifindex
Not supported, must be zero.
Definition bpf.h:146
uint32_t expected_attach_type
Not supported, must be zero.
Definition bpf.h:147
uint64_t func_info
Not supported, must be zero.
Definition bpf.h:150
uint64_t license
Optional pointer to a string specifying the license (currently ignored on Windows).
Definition bpf.h:139
uint32_t prog_btf_fd
Not supported, must be zero.
Definition bpf.h:148
uint32_t log_level
Logging level (currently ignored on Windows).
Definition bpf.h:140
uint32_t kern_version
Kernel version (currently ignored on Windows).
Definition bpf.h:143
uint32_t line_info_cnt
Not supported, must be zero.
Definition bpf.h:154
uint32_t attach_btf_obj_fd
Definition bpf.h:161
uint32_t func_info_cnt
Not supported, must be zero.
Definition bpf.h:151
uint32_t core_relo_cnt
Not supported, must be zero.
Definition bpf.h:163
uint32_t attach_btf_id
Not supported, must be zero.
Definition bpf.h:155
enum bpf_prog_type prog_type
Program type to use for loading the program.
Definition bpf.h:136
uint64_t core_relos
Not supported, must be zero.
Definition bpf.h:165
uint64_t line_info
Not supported, must be zero.
Definition bpf.h:153
uint32_t log_size
Size in bytes of the log buffer.
Definition bpf.h:141
uint32_t func_info_rec_size
Not supported, must be zero.
Definition bpf.h:149
uint32_t prog_flags
Not supported, must be zero.
Definition bpf.h:144
uint64_t insns
Array of instructions.
Definition bpf.h:138
uint32_t core_relo_rec_size
Not supported, must be zero.
Definition bpf.h:166
uint32_t log_true_size
Total size of the log output. May be larger than log_size.
Definition bpf.h:167
Definition bpf.h:179
uint32_t repeat
Number of times to repeat the program.
Definition bpf.h:186
uint64_t ctx_in
Pointer to input context.
Definition bpf.h:190
uint32_t data_size_in
Size in bytes of input data.
Definition bpf.h:182
uint64_t ctx_out
Pointer to output context.
Definition bpf.h:191
uint32_t flags
Flags (currently 0).
Definition bpf.h:192
uint32_t duration
Duration in milliseconds to run the program.
Definition bpf.h:187
uint32_t retval
On return, contains the return value of the program.
Definition bpf.h:181
uint32_t ctx_size_in
Size in bytes of input context.
Definition bpf.h:188
uint64_t data_in
Pointer to input data.
Definition bpf.h:184
uint32_t batch_size
Number of times to run the program in a batch.
Definition bpf.h:194
uint64_t data_out
Pointer to output data.
Definition bpf.h:185
uint32_t prog_fd
File descriptor of program to run.
Definition bpf.h:180
uint32_t ctx_size_out
Size in bytes of output context.
Definition bpf.h:189
uint32_t _pad0
Definition bpf.h:195
uint32_t data_size_out
Size in bytes of output data.
Definition bpf.h:183
uint32_t cpu
CPU to run the program on.
Definition bpf.h:193
Parameters used by the bpf() API.
Definition bpf.h:267
sys_bpf_prog_load_attr_t prog_load
Attributes used by BPF_PROG_LOAD.
Definition bpf.h:283
uint32_t map_id
ID of map for BPF_MAP_GET_FD_BY_ID to find.
Definition bpf.h:300
sys_bpf_obj_pin_attr_t obj_pin
Definition bpf.h:291
sys_bpf_map_lookup_attr_t map_update
Attributes used by BPF_MAP_LOOKUP_ELEM, BPF_MAP_UPDATE_ELEM and.
Definition bpf.h:274
sys_bpf_obj_pin_attr_t obj_get
Attributes used by BPF_OBJ_PIN and BPF_OBJ_GET.
Definition bpf.h:291
uint32_t prog_id
ID of program for BPF_PROG_GET_FD_BY_ID to find.
Definition bpf.h:303
sys_bpf_map_next_id_attr_t prog_get_next_id
Definition bpf.h:296
sys_bpf_prog_bind_map_attr_t prog_bind_map
Attributes used by BPF_PROG_BIND_MAP.
Definition bpf.h:315
sys_bpf_obj_info_attr_t info
Attributes used by BPF_OBJ_GET_INFO_BY_FD.
Definition bpf.h:309
uint32_t link_id
ID of link for BPF_LINK_GET_FD_BY_ID to find.
Definition bpf.h:306
sys_bpf_map_lookup_attr_t map_lookup
Definition bpf.h:273
sys_bpf_map_next_id_attr_t map_get_next_id
Definition bpf.h:296
sys_bpf_map_next_id_attr_t link_get_next_id
Attributes used by BPF_PROG_GET_NEXT_ID, BPF_MAP_GET_NEXT_ID, and BPF_LINK_GET_NEXT_ID.
Definition bpf.h:297
sys_bpf_map_delete_attr_t map_delete
Attributes used by BPF_MAP_DELETE_ELEM.
Definition bpf.h:280
sys_bpf_prog_attach_attr_t prog_attach
Definition bpf.h:287
sys_bpf_link_detach_attr_t link_detach
Attributes used by BPF_LINK_DETACH.
Definition bpf.h:312
sys_bpf_prog_attach_attr_t prog_detach
Attributes used by BPF_PROG_ATTACH/DETACH.
Definition bpf.h:287
sys_bpf_map_next_key_attr_t map_get_next_key
Attributes used by BPF_MAP_GET_NEXT_KEY.
Definition bpf.h:277
sys_bpf_map_create_attr_t map_create
Attributes used by BPF_MAP_CREATE.
Definition bpf.h:269
sys_bpf_prog_run_attr_t test
Attributes used by BPF_PROG_TEST_RUN.
Definition bpf.h:318