eBPF for Windows
Loading...
Searching...
No Matches
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];
147
155
156typedef struct
157{
158 uint32_t prog_fd;
159 uint32_t retval;
160 uint32_t data_size_in;
161 uint32_t data_size_out;
162 uint64_t data_in;
163 uint64_t data_out;
164 uint32_t repeat;
165 uint32_t duration;
166 uint32_t ctx_size_in;
167 uint32_t ctx_size_out;
168 uint64_t ctx_in;
169 uint64_t ctx_out;
170 uint32_t flags;
171 uint32_t cpu;
172 uint32_t batch_size;
173 uint32_t _pad0;
175
176typedef struct
177{
178 uint64_t pathname;
179 uint32_t bpf_fd;
180 uint32_t flags;
182
184typedef struct
185{
186 uint32_t bpf_fd;
191 uint32_t info_len;
192 uint64_t info;
194
205
206typedef struct
207{
210 char tag[8];
211 uint32_t jited_prog_len;
215 uint64_t load_time;
216 uint32_t created_by_uid;
217 uint32_t nr_map_ids;
218 uint64_t map_ids;
221
228
230typedef struct
231{
232 uint32_t link_fd;
234
236typedef struct
237{
238 uint32_t prog_fd;
239 uint32_t map_fd;
240 uint32_t flags;
242
245{
246 // BPF_MAP_CREATE
248
249 // BPF_MAP_LOOKUP_ELEM
250 // BPF_MAP_UPDATE_ELEM
253
254 // BPF_MAP_GET_NEXT_KEY
256
257 // BPF_MAP_DELETE_ELEM
259
260 // BPF_PROG_LOAD
262
263 // BPF_PROG_ATTACH
264 // BPF_PROG_DETACH
266
267 // BPF_OBJ_PIN
268 // BPF_OBJ_GET
270
271 // BPF_PROG_GET_NEXT_ID
272 // BPF_MAP_GET_NEXT_ID
273 // BPF_LINK_GET_NEXT_ID
276
277 // BPF_MAP_GET_FD_BY_ID
278 uint32_t map_id;
279
280 // BPF_PROG_GET_FD_BY_ID
281 uint32_t prog_id;
282
283 // BPF_LINK_GET_FD_BY_ID
284 uint32_t link_id;
285
286 // BPF_OBJ_GET_INFO_BY_FD
288
289 // BPF_LINK_DETACH
291
292 // BPF_PROG_BIND_MAP
294
295 // BPF_PROG_TEST_RUN
297};
298
299#ifdef _MSC_VER
300#pragma warning(pop)
301#endif
302
303int
304bpf(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:173
bpf_link_type
Definition ebpf_structs.h:249
enum bpf_map_type ebpf_map_type_t
uint32_t ebpf_id_t
Definition ebpf_structs.h:95
bpf_attach_type
Definition ebpf_structs.h:263
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:196
ebpf_id_t id
Map ID.
Definition bpf.h:198
uint32_t map_flags
Map flags.
Definition bpf.h:202
uint32_t max_entries
Maximum number of entries allowed in the map.
Definition bpf.h:201
uint32_t value_size
Size in bytes of a map value.
Definition bpf.h:200
ebpf_map_type_t type
Type of map.
Definition bpf.h:197
uint32_t key_size
Size in bytes of a map key.
Definition bpf.h:199
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:185
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:191
uint32_t bpf_fd
File descriptor referring to an eBPF object.
Definition bpf.h:186
uint64_t info
Pointer to memory in which to write the info obtained.
Definition bpf.h:192
Definition bpf.h:177
uint32_t flags
Not supported, must be zero.
Definition bpf.h:180
uint32_t bpf_fd
File descriptor referring to the program or map.
Definition bpf.h:179
uint64_t pathname
Path name for pinning.
Definition bpf.h:178
Definition bpf.h:149
uint32_t attach_flags
Flags affecting the attach operation.
Definition bpf.h:153
enum bpf_attach_type attach_type
Type of program to attach/detach to/from.
Definition bpf.h:152
uint32_t target_fd
eBPF target to attach/detach to/from.
Definition bpf.h:150
uint32_t attach_bpf_fd
File descriptor of program to attach to.
Definition bpf.h:151
Attributes used by BPF_PROG_BIND_MAP.
Definition bpf.h:237
uint32_t map_fd
File descriptor of map to bind.
Definition bpf.h:239
uint32_t flags
Flags affecting the bind operation.
Definition bpf.h:240
uint32_t prog_fd
File descriptor of program to bind map to.
Definition bpf.h:238
Definition bpf.h:207
enum bpf_prog_type type
Program type.
Definition bpf.h:208
uint64_t jited_prog_insns
Not supported.
Definition bpf.h:213
uint32_t jited_prog_len
Not supported.
Definition bpf.h:211
uint32_t nr_map_ids
Number of maps associated with this program.
Definition bpf.h:217
uint32_t created_by_uid
Not supported.
Definition bpf.h:216
uint64_t map_ids
Pointer to caller-allocated array to fill map IDs into.
Definition bpf.h:218
uint64_t xlated_prog_insns
Not supported.
Definition bpf.h:214
ebpf_id_t id
Program ID.
Definition bpf.h:209
uint32_t xlated_prog_len
Not supported.
Definition bpf.h:212
uint64_t load_time
Not supported.
Definition bpf.h:215
Definition bpf.h:135
uint32_t insn_cnt
Number of instructions in the array.
Definition bpf.h:137
uint64_t log_buf
Pointer to a buffer in which log info can be written.
Definition bpf.h:142
uint64_t license
Optional pointer to a string specifying the license (currently ignored on Windows).
Definition bpf.h:139
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
enum bpf_prog_type prog_type
Program type to use for loading the program.
Definition bpf.h:136
uint32_t log_size
Size in bytes of the log buffer.
Definition bpf.h:141
uint32_t prog_flags
Not supported, must be zero.
Definition bpf.h:144
uint64_t insns
Array of instructions.
Definition bpf.h:138
Definition bpf.h:157
uint32_t repeat
Number of times to repeat the program.
Definition bpf.h:164
uint64_t ctx_in
Pointer to input context.
Definition bpf.h:168
uint32_t data_size_in
Size in bytes of input data.
Definition bpf.h:160
uint64_t ctx_out
Pointer to output context.
Definition bpf.h:169
uint32_t flags
Flags (currently 0).
Definition bpf.h:170
uint32_t duration
Duration in milliseconds to run the program.
Definition bpf.h:165
uint32_t retval
On return, contains the return value of the program.
Definition bpf.h:159
uint32_t ctx_size_in
Size in bytes of input context.
Definition bpf.h:166
uint64_t data_in
Pointer to input data.
Definition bpf.h:162
uint32_t batch_size
Number of times to run the program in a batch.
Definition bpf.h:172
uint64_t data_out
Pointer to output data.
Definition bpf.h:163
uint32_t prog_fd
File descriptor of program to run.
Definition bpf.h:158
uint32_t ctx_size_out
Size in bytes of output context.
Definition bpf.h:167
uint32_t _pad0
Definition bpf.h:173
uint32_t data_size_out
Size in bytes of output data.
Definition bpf.h:161
uint32_t cpu
CPU to run the program on.
Definition bpf.h:171
Parameters used by the bpf() API.
Definition bpf.h:245
sys_bpf_prog_load_attr_t prog_load
Attributes used by BPF_PROG_LOAD.
Definition bpf.h:261
uint32_t map_id
ID of map for BPF_MAP_GET_FD_BY_ID to find.
Definition bpf.h:278
sys_bpf_obj_pin_attr_t obj_pin
Definition bpf.h:269
sys_bpf_map_lookup_attr_t map_update
Attributes used by BPF_MAP_LOOKUP_ELEM, BPF_MAP_UPDATE_ELEM and.
Definition bpf.h:252
sys_bpf_obj_pin_attr_t obj_get
Attributes used by BPF_OBJ_PIN and BPF_OBJ_GET.
Definition bpf.h:269
uint32_t prog_id
ID of program for BPF_PROG_GET_FD_BY_ID to find.
Definition bpf.h:281
sys_bpf_map_next_id_attr_t prog_get_next_id
Definition bpf.h:274
sys_bpf_prog_bind_map_attr_t prog_bind_map
Attributes used by BPF_PROG_BIND_MAP.
Definition bpf.h:293
sys_bpf_obj_info_attr_t info
Attributes used by BPF_OBJ_GET_INFO_BY_FD.
Definition bpf.h:287
uint32_t link_id
ID of link for BPF_LINK_GET_FD_BY_ID to find.
Definition bpf.h:284
sys_bpf_map_lookup_attr_t map_lookup
Definition bpf.h:251
sys_bpf_map_next_id_attr_t map_get_next_id
Definition bpf.h:274
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:275
sys_bpf_map_delete_attr_t map_delete
Attributes used by BPF_MAP_DELETE_ELEM.
Definition bpf.h:258
sys_bpf_prog_attach_attr_t prog_attach
Definition bpf.h:265
sys_bpf_link_detach_attr_t link_detach
Attributes used by BPF_LINK_DETACH.
Definition bpf.h:290
sys_bpf_prog_attach_attr_t prog_detach
Attributes used by BPF_PROG_ATTACH/DETACH.
Definition bpf.h:265
sys_bpf_map_next_key_attr_t map_get_next_key
Attributes used by BPF_MAP_GET_NEXT_KEY.
Definition bpf.h:255
sys_bpf_map_create_attr_t map_create
Attributes used by BPF_MAP_CREATE.
Definition bpf.h:247
sys_bpf_prog_run_attr_t test
Attributes used by BPF_PROG_TEST_RUN.
Definition bpf.h:296