/
ebpf_helpers.h
46 lines (36 loc) · 1.36 KB
/
ebpf_helpers.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright (c) Microsoft Corporation
// SPDX-License-Identifier: MIT
#pragma once
#include <stdint.h>
// This file contains APIs for global helpers that are
// exposed for use by all eBPF programs.
typedef struct _ebpf_map_definition
{
uint32_t size;
uint32_t type;
uint32_t key_size;
uint32_t value_size;
uint32_t max_entries;
} ebpf_map_definition_t;
typedef enum _ebpf_map_type
{
EBPF_MAP_TYPE_UNSPECIFIED = 0,
EBPF_MAP_TYPE_HASH = 1,
EBPF_MAP_TYPE_ARRAY = 2,
} ebpf_map_type_t;
typedef void* (*ebpf_map_lookup_element_t)(ebpf_map_definition_t* map, void* key);
#define ebpf_map_lookup_element ((ebpf_map_lookup_element_t)1)
typedef int64_t (*ebpf_map_update_element_t)(ebpf_map_definition_t* map, void* key, void* data, uint64_t flags);
#define ebpf_map_update_element ((ebpf_map_update_element_t)2)
typedef int64_t (*ebpf_map_delete_element_t)(ebpf_map_definition_t* map, void* key);
#define ebpf_map_delete_element ((ebpf_map_delete_element_t)3)
//
// Defines for cross-platform compatibility.
//
#define bpf_map _ebpf_map_definition
#define bpf_map_lookup_elem ebpf_map_lookup_element
#define bpf_map_update_elem ebpf_map_update_element
#define bpf_map_delete_elem ebpf_map_delete_element
#define BPF_MAP_TYPE_UNSPECIFIED EBPF_MAP_TYPE_UNSPECIFIED
#define BPF_MAP_TYPE_HASH EBPF_MAP_TYPE_HASH
#define BPF_MAP_TYPE_ARRAY EBPF_MAP_TYPE_ARRAY