eBPF for Windows
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
ebpf_structs.h
Go to the documentation of this file.
1// Copyright (c) eBPF for Windows contributors
2// SPDX-License-Identifier: MIT
3#pragma once
4
11#include "ebpf_windows.h"
12
13#define MAX_TAIL_CALL_CNT 33
14
15#define BPF_ENUM_TO_STRING(X) #X
16
36
37#define BPF_MAP_TYPE_PER_CPU(X) \
38 ((X) == BPF_MAP_TYPE_PERCPU_HASH || (X) == BPF_MAP_TYPE_PERCPU_ARRAY || (X) == BPF_MAP_TYPE_LRU_PERCPU_HASH || \
39 (X) == BPF_MAP_TYPE_PERF_EVENT_ARRAY)
40
41static const char* const _ebpf_map_type_names[] = {
57};
58
59static const char* const _ebpf_map_display_names[] = {
60 "unspec",
61 "hash",
62 "array",
63 "prog_array",
64 "percpu_hash",
65 "percpu_array",
66 "hash_of_maps",
67 "array_of_maps",
68 "lru_hash",
69 "lpm_trie",
70 "queue",
71 "lru_percpu_hash",
72 "stack",
73 "ringbuf",
74 "perf_event_array",
75};
76
83
93
94static const char* const _ebpf_pin_type_names[] = {
97};
98
99typedef uint32_t ebpf_id_t;
100#define EBPF_ID_NONE 0
101
114
139
175
176// Cross-platform BPF program types.
269
271
272#define XDP_FLAGS_REPLACE 0x01
273
274// The link type is used to tell which union member is present
275// in the bpf_link_info struct. There is exactly one non-zero value
276// per union member.
285
286static const char* const _ebpf_link_display_names[] = {
287 "unspec",
288 "plain",
289};
290
367
369
370// Libbpf itself requires the following structs to be defined, but doesn't
371// care what fields they have. Applications such as bpftool on the other
372// hand depend on fields of specific names and types.
373
374#ifdef _MSC_VER
375#pragma warning(push)
376#pragma warning(disable : 4201) /* nameless struct/union */
377#endif
403#ifdef _MSC_VER
404#pragma warning(pop)
405#endif
406
407#define BPF_OBJ_NAME_LEN 64
408
414{
415 // Cross-platform fields.
418 uint32_t key_size;
419 uint32_t value_size;
420 uint32_t max_entries;
422 uint32_t map_flags;
423
424 // Windows-specific fields.
427};
428
429#define BPF_ANY 0x0
430#define BPF_NOEXIST 0x1
431#define BPF_EXIST 0x2
432
438{
439 // Cross-platform fields.
442 uint32_t nr_map_ids;
443 uintptr_t map_ids;
445
446 // Windows-specific fields.
450 uint32_t link_count;
451};
452
453/* BPF_FUNC_perf_event_output flags. */
454#define EBPF_MAP_FLAG_INDEX_MASK 0xffffffffULL
455#define EBPF_MAP_FLAG_INDEX_SHIFT 0
456#define EBPF_MAP_FLAG_CURRENT_CPU EBPF_MAP_FLAG_INDEX_MASK
457/* BPF_FUNC_perf_event_output flags for program types with data pointer in context. */
458#define EBPF_MAP_FLAG_CTX_LENGTH_SHIFT 32
459#define EBPF_MAP_FLAG_CTX_LENGTH_MAX (0xfffffULL)
460#define EBPF_MAP_FLAG_CTX_LENGTH_MASK (EBPF_MAP_FLAG_CTX_LENGTH_MAX << EBPF_MAP_FLAG_CTX_LENGTH_SHIFT)
461
bpf_prog_type
Definition ebpf_structs.h:178
@ BPF_PROG_TYPE_PROCESS
Program type for handling process creation/deletion events. The github microsoft/ntosebpfext repo has...
Definition ebpf_structs.h:248
@ BPF_PROG_TYPE_XDP
Program type for handling incoming packets as early as possible.
Definition ebpf_structs.h:189
@ BPF_PROG_TYPE_BIND
Program type for handling socket bind() requests.
Definition ebpf_structs.h:199
@ BPF_PROG_TYPE_CGROUP_SOCK_ADDR
Program type for handling various socket operations such as connect(), accept() etc.
Definition ebpf_structs.h:213
@ BPF_PROG_TYPE_UNSPEC
Unspecified program type.
Definition ebpf_structs.h:179
@ BPF_PROG_TYPE_XDP_TEST
Program type for handling incoming packets as early as possible.
Definition ebpf_structs.h:258
@ BPF_PROG_TYPE_SOCK_OPS
Program type for handling various socket event notifications such as connection established etc.
Definition ebpf_structs.h:224
@ BPF_PROG_TYPE_NETEVENT
Program type for handling netevents. The github microsoft/ntosebpfext repo has the implementation for...
Definition ebpf_structs.h:236
@ BPF_PROG_TYPE_SAMPLE
Program type for handling calls from the eBPF sample extension. Used for testing.
Definition ebpf_structs.h:267
enum ebpf_map_option ebpf_map_option_t
bpf_link_type
Definition ebpf_structs.h:278
@ BPF_LINK_TYPE_UNSPEC
Unspecified link type.
Definition ebpf_structs.h:279
@ BPF_LINK_TYPE_PLAIN
No union members are used in bpf_link_info.
Definition ebpf_structs.h:280
@ BPF_LINK_TYPE_CGROUP
cgroup struct is present in bpf_link_info.
Definition ebpf_structs.h:281
@ BPF_LINK_TYPE_XDP
xdp struct is present in bpf_link_info.
Definition ebpf_structs.h:282
@ BPF_LINK_TYPE_MAX
Definition ebpf_structs.h:283
enum bpf_prog_type bpf_prog_type_t
Definition ebpf_structs.h:270
enum bpf_map_type ebpf_map_type_t
#define BPF_ENUM_TO_STRING(X)
Definition ebpf_structs.h:15
struct _ebpf_map_definition_in_memory ebpf_map_definition_in_memory_t
eBPF Map Definition as it is stored in memory.
enum ebpf_pin_type ebpf_pin_type_t
Pinning type for eBPF objects. The values should match the LIBBPF_PIN_* pin types defined in libbpf.
ebpf_pin_type
Pinning type for eBPF objects. The values should match the LIBBPF_PIN_* pin types defined in libbpf.
Definition ebpf_structs.h:89
@ LIBBPF_PIN_NONE
Object is not pinned.
Definition ebpf_structs.h:90
@ LIBBPF_PIN_BY_NAME
Pinning with a global namespace.
Definition ebpf_structs.h:91
uint32_t ebpf_id_t
Definition ebpf_structs.h:99
ebpf_helper_id_t
Definition ebpf_structs.h:141
@ BPF_FUNC_trace_printk2
bpf_trace_printk2 (but use bpf_printk instead)
Definition ebpf_structs.h:153
@ BPF_FUNC_tail_call
bpf_tail_call
Definition ebpf_structs.h:146
@ BPF_FUNC_ktime_get_ns
bpf_ktime_get_ns
Definition ebpf_structs.h:150
@ BPF_FUNC_memset
bpf_memset
Definition ebpf_structs.h:165
@ BPF_FUNC_get_smp_processor_id
bpf_get_smp_processor_id
Definition ebpf_structs.h:149
@ BPF_FUNC_get_prandom_u32
bpf_get_prandom_u32
Definition ebpf_structs.h:147
@ BPF_FUNC_get_socket_cookie
bpf_get_socket_cookie
Definition ebpf_structs.h:167
@ BPF_FUNC_trace_printk3
bpf_trace_printk3 (but use bpf_printk instead)
Definition ebpf_structs.h:154
@ BPF_FUNC_map_lookup_and_delete_elem
bpf_map_lookup_and_delete_elem
Definition ebpf_structs.h:145
@ BPF_FUNC_ringbuf_output
bpf_ringbuf_output
Definition ebpf_structs.h:152
@ BPF_FUNC_memcmp
bpf_memcmp
Definition ebpf_structs.h:164
@ BPF_FUNC_ktime_get_ms
bpf_ktime_get_ms
Definition ebpf_structs.h:172
@ BPF_FUNC_memmove
bpf_memmove
Definition ebpf_structs.h:166
@ BPF_FUNC_trace_printk5
bpf_trace_printk5 (but use bpf_printk instead)
Definition ebpf_structs.h:156
@ BPF_FUNC_perf_event_output
bpf_perf_event_output
Definition ebpf_structs.h:173
@ BPF_FUNC_is_current_admin
bpf_is_current_admin
Definition ebpf_structs.h:162
@ BPF_FUNC_map_pop_elem
bpf_map_pop_elem
Definition ebpf_structs.h:158
@ BPF_FUNC_map_update_elem
bpf_map_update_elem
Definition ebpf_structs.h:143
@ BPF_FUNC_strnlen_s
bpf_strnlen_s
Definition ebpf_structs.h:170
@ BPF_FUNC_csum_diff
bpf_csum_diff
Definition ebpf_structs.h:151
@ BPF_FUNC_map_delete_elem
bpf_map_delete_elem
Definition ebpf_structs.h:144
@ BPF_FUNC_map_lookup_elem
bpf_map_lookup_elem
Definition ebpf_structs.h:142
@ BPF_FUNC_trace_printk4
bpf_trace_printk4 (but use bpf_printk instead)
Definition ebpf_structs.h:155
@ BPF_FUNC_map_peek_elem
bpf_map_peek_elem
Definition ebpf_structs.h:159
@ BPF_FUNC_strncpy_s
bpf_strncpy_s
Definition ebpf_structs.h:168
@ BPF_FUNC_strncat_s
bpf_strncat_s
Definition ebpf_structs.h:169
@ BPF_FUNC_ktime_get_boot_ns
bpf_ktime_get_boot_ns
Definition ebpf_structs.h:148
@ BPF_FUNC_ktime_get_boot_ms
bpf_ktime_get_boot_ms
Definition ebpf_structs.h:171
@ BPF_FUNC_get_current_logon_id
bpf_get_current_logon_id
Definition ebpf_structs.h:161
@ BPF_FUNC_memcpy
bpf_memcpy
Definition ebpf_structs.h:163
@ BPF_FUNC_map_push_elem
bpf_map_push_elem
Definition ebpf_structs.h:157
@ BPF_FUNC_get_current_pid_tgid
bpf_get_current_pid_tgid
Definition ebpf_structs.h:160
bpf_attach_type
Definition ebpf_structs.h:292
@ BPF_XDP
Attach type for handling incoming packets as early as possible.
Definition ebpf_structs.h:299
@ BPF_CGROUP_INET6_CONNECT
Attach type for handling IPv6 TCP connect() or UDP send to a unique remote address/port tuple.
Definition ebpf_structs.h:319
@ BPF_ATTACH_TYPE_UNSPEC
Unspecified attach type.
Definition ebpf_structs.h:293
@ BPF_ATTACH_TYPE_PROCESS
Attach type for handling process creation/deletion events.
Definition ebpf_structs.h:363
@ __MAX_BPF_ATTACH_TYPE
Definition ebpf_structs.h:365
@ BPF_ATTACH_TYPE_BIND
Attach type for handling socket bind() requests.
Definition ebpf_structs.h:305
@ BPF_XDP_TEST
Attach type for handling incoming packets as early as possible.
Definition ebpf_structs.h:351
@ BPF_CGROUP_INET6_RECV_ACCEPT
Attach type for handling IPv6 TCP accept() or on receiving the first unicast UDP packet from a unique...
Definition ebpf_structs.h:333
@ BPF_ATTACH_TYPE_SAMPLE
Attach type implemented by eBPF Sample Extension driver, used for testing.
Definition ebpf_structs.h:345
@ BPF_CGROUP_SOCK_OPS
Attach type for handling various socket event notifications.
Definition ebpf_structs.h:339
@ BPF_CGROUP_INET4_RECV_ACCEPT
Attach type for handling IPv4 TCP accept() or on receiving the first unicast UDP packet from a unique...
Definition ebpf_structs.h:326
@ BPF_CGROUP_INET4_CONNECT
Attach type for handling IPv4 TCP connect() or UDP send to a unique remote address/port tuple.
Definition ebpf_structs.h:312
@ BPF_ATTACH_TYPE_NETEVENT
Attach type for handling netevents.
Definition ebpf_structs.h:357
ebpf_extension_header_t ebpf_native_module_header_t
Header of an eBPF native module data structure. Every eBPF native module data structure must start wi...
Definition ebpf_structs.h:472
struct _ebpf_map_definition_in_file ebpf_map_definition_in_file_t
eBPF Map Definition as it appears in the maps section of an ELF file.
#define BPF_OBJ_NAME_LEN
Definition ebpf_structs.h:407
enum bpf_attach_type bpf_attach_type_t
Definition ebpf_structs.h:368
ebpf_map_option
Definition ebpf_structs.h:78
@ EBPF_ANY
Create a new element or update an existing element.
Definition ebpf_structs.h:79
@ EBPF_EXIST
Update an existing element.
Definition ebpf_structs.h:81
@ EBPF_NOEXIST
Create a new element only when it does not exist.
Definition ebpf_structs.h:80
bpf_map_type
Definition ebpf_structs.h:18
@ BPF_MAP_TYPE_PERF_EVENT_ARRAY
Perf event array.
Definition ebpf_structs.h:34
@ BPF_MAP_TYPE_STACK
Stack.
Definition ebpf_structs.h:32
@ BPF_MAP_TYPE_RINGBUF
Ring buffer.
Definition ebpf_structs.h:33
@ BPF_MAP_TYPE_PERCPU_ARRAY
Per-CPU array.
Definition ebpf_structs.h:25
@ BPF_MAP_TYPE_QUEUE
Queue.
Definition ebpf_structs.h:30
@ BPF_MAP_TYPE_LRU_PERCPU_HASH
Per-CPU least-recently-used hash table.
Definition ebpf_structs.h:31
@ BPF_MAP_TYPE_LPM_TRIE
Longest prefix match trie.
Definition ebpf_structs.h:29
@ BPF_MAP_TYPE_HASH_OF_MAPS
Hash table, where the map value is another map.
Definition ebpf_structs.h:26
@ BPF_MAP_TYPE_LRU_HASH
Least-recently-used hash table.
Definition ebpf_structs.h:28
@ BPF_MAP_TYPE_PERCPU_HASH
Per-CPU hash table.
Definition ebpf_structs.h:24
@ BPF_MAP_TYPE_ARRAY_OF_MAPS
Array, where the map value is another map.
Definition ebpf_structs.h:27
@ BPF_MAP_TYPE_UNSPEC
Unspecified map type.
Definition ebpf_structs.h:19
@ BPF_MAP_TYPE_ARRAY
Array, where the map key is the array index.
Definition ebpf_structs.h:21
@ BPF_MAP_TYPE_PROG_ARRAY
Array of program fds usable with bpf_tail_call, where the map key is the array index.
Definition ebpf_structs.h:22
@ BPF_MAP_TYPE_HASH
Hash table.
Definition ebpf_structs.h:20
GUID ebpf_attach_type_t
Definition ebpf_windows.h:62
GUID ebpf_program_type_t
Definition ebpf_windows.h:61
Header of an eBPF extension data structure. Every eBPF extension data structure must start with this ...
Definition ebpf_windows.h:153
eBPF Map Definition as it appears in the maps section of an ELF file.
Definition ebpf_structs.h:119
uint32_t inner_id
Definition ebpf_structs.h:137
uint32_t key_size
Size in bytes of a map key.
Definition ebpf_structs.h:121
uint32_t max_entries
Maximum number of entries allowed in the map.
Definition ebpf_structs.h:123
uint32_t inner_map_idx
Definition ebpf_structs.h:129
ebpf_map_type_t type
Type of map.
Definition ebpf_structs.h:120
uint32_t value_size
Size in bytes of a map value.
Definition ebpf_structs.h:122
ebpf_pin_type_t pinning
Definition ebpf_structs.h:130
uint32_t id
Definition ebpf_structs.h:134
eBPF Map Definition as it is stored in memory.
Definition ebpf_structs.h:106
ebpf_map_type_t type
Type of map.
Definition ebpf_structs.h:107
uint32_t key_size
Size in bytes of a map key.
Definition ebpf_structs.h:108
ebpf_id_t inner_map_id
Definition ebpf_structs.h:111
uint32_t max_entries
Maximum number of entries allowed in the map.
Definition ebpf_structs.h:110
ebpf_pin_type_t pinning
Definition ebpf_structs.h:112
uint32_t value_size
Size in bytes of a map value.
Definition ebpf_structs.h:109
eBPF map information. This structure can be retrieved by calling bpf_obj_get_info_by_fd on a map fd.
Definition ebpf_structs.h:414
uint32_t max_entries
Maximum number of entries allowed in the map.
Definition ebpf_structs.h:420
char name[BPF_OBJ_NAME_LEN]
Null-terminated map name.
Definition ebpf_structs.h:421
ebpf_map_type_t type
Type of map.
Definition ebpf_structs.h:417
uint32_t key_size
Size in bytes of a map key.
Definition ebpf_structs.h:418
ebpf_id_t id
Map ID.
Definition ebpf_structs.h:416
uint32_t map_flags
Map flags.
Definition ebpf_structs.h:422
uint32_t pinned_path_count
Number of pinned paths.
Definition ebpf_structs.h:426
uint32_t value_size
Size in bytes of a map value.
Definition ebpf_structs.h:419
ebpf_id_t inner_map_id
ID of inner map template.
Definition ebpf_structs.h:425
eBPF program information. This structure can be retrieved by calling bpf_obj_get_info_by_fd on a prog...
Definition ebpf_structs.h:438
ebpf_attach_type_t attach_type_uuid
Attach type UUID.
Definition ebpf_structs.h:448
uint32_t pinned_path_count
Number of pinned paths.
Definition ebpf_structs.h:449
uint32_t link_count
Number of attached links.
Definition ebpf_structs.h:450
enum bpf_prog_type type
Program type, if a cross-platform type.
Definition ebpf_structs.h:441
char name[BPF_OBJ_NAME_LEN]
Null-terminated program name.
Definition ebpf_structs.h:444
uintptr_t map_ids
Pointer to caller-allocated array to fill map IDs into.
Definition ebpf_structs.h:443
uint32_t nr_map_ids
Number of maps associated with this program.
Definition ebpf_structs.h:442
ebpf_id_t id
Program ID.
Definition ebpf_structs.h:440
ebpf_program_type_t type_uuid
Program type UUID.
Definition ebpf_structs.h:447