2021-06-30 19:22:40 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// SPDX-License-Identifier: MIT
|
2021-06-09 18:44:24 +03:00
|
|
|
|
|
|
|
// This file contains eBPF definitions common to eBPF programs, core execution engine
|
|
|
|
// as well as eBPF API library.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-02-24 21:18:28 +03:00
|
|
|
#if !defined(NO_CRT)
|
2022-04-15 01:09:54 +03:00
|
|
|
#include <stdbool.h>
|
2021-06-09 18:44:24 +03:00
|
|
|
#include <stdint.h>
|
2022-02-24 21:18:28 +03:00
|
|
|
#endif
|
2021-09-15 22:08:18 +03:00
|
|
|
#include "ebpf_windows.h"
|
2021-06-09 18:44:24 +03:00
|
|
|
|
2022-05-07 00:39:57 +03:00
|
|
|
#define BPF_ENUM_TO_STRING(X) #X
|
|
|
|
|
2021-08-04 03:25:50 +03:00
|
|
|
typedef enum bpf_map_type
|
2021-06-09 18:44:24 +03:00
|
|
|
{
|
2021-09-24 05:32:09 +03:00
|
|
|
BPF_MAP_TYPE_UNSPEC = 0, ///< Unspecified map type.
|
|
|
|
BPF_MAP_TYPE_HASH = 1, ///< Hash table.
|
|
|
|
BPF_MAP_TYPE_ARRAY = 2, ///< Array, where the map key is the array index.
|
2021-08-06 23:18:47 +03:00
|
|
|
BPF_MAP_TYPE_PROG_ARRAY =
|
|
|
|
3, ///< Array of program fds usable with bpf_tail_call, where the map key is the array index.
|
2021-11-29 22:47:58 +03:00
|
|
|
BPF_MAP_TYPE_PERCPU_HASH = 4, ///< Per-CPU hash table.
|
|
|
|
BPF_MAP_TYPE_PERCPU_ARRAY = 5, ///< Per-CPU array.
|
|
|
|
BPF_MAP_TYPE_HASH_OF_MAPS = 6, ///< Hash table, where the map value is another map.
|
|
|
|
BPF_MAP_TYPE_ARRAY_OF_MAPS = 7, ///< Array, where the map value is another map.
|
|
|
|
BPF_MAP_TYPE_LRU_HASH = 8, ///< Least-recently-used hash table.
|
|
|
|
BPF_MAP_TYPE_LPM_TRIE = 9, ///< Longest prefix match trie.
|
|
|
|
BPF_MAP_TYPE_QUEUE = 10, ///< Queue.
|
|
|
|
BPF_MAP_TYPE_LRU_PERCPU_HASH = 11, ///< Per-CPU least-recently-used hash table.
|
|
|
|
BPF_MAP_TYPE_STACK = 12, ///< Stack.
|
2021-12-04 00:19:21 +03:00
|
|
|
BPF_MAP_TYPE_RINGBUF = 13 ///< Ring buffer.
|
2021-06-09 18:44:24 +03:00
|
|
|
} ebpf_map_type_t;
|
|
|
|
|
2022-09-30 20:24:50 +03:00
|
|
|
#define BPF_MAP_TYPE_PER_CPU(X) \
|
|
|
|
((X) == BPF_MAP_TYPE_PERCPU_HASH || (X) == BPF_MAP_TYPE_PERCPU_ARRAY || (X) == BPF_MAP_TYPE_LRU_PERCPU_HASH)
|
|
|
|
|
2022-05-07 00:39:57 +03:00
|
|
|
static const char* const _ebpf_map_type_names[] = {
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_UNSPEC),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_HASH),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_ARRAY),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_PROG_ARRAY),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_PERCPU_HASH),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_PERCPU_ARRAY),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_HASH_OF_MAPS),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_ARRAY_OF_MAPS),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_LRU_HASH),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_LPM_TRIE),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_QUEUE),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_LRU_PERCPU_HASH),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_STACK),
|
|
|
|
BPF_ENUM_TO_STRING(BPF_MAP_TYPE_RINGBUF),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char* const _ebpf_map_display_names[] = {
|
2022-07-29 21:57:30 +03:00
|
|
|
"unspec",
|
|
|
|
"hash",
|
|
|
|
"array",
|
|
|
|
"prog_array",
|
|
|
|
"percpu_hash",
|
|
|
|
"percpu_array",
|
|
|
|
"hash_of_maps",
|
|
|
|
"array_of_maps",
|
|
|
|
"lru_hash",
|
|
|
|
"lpm_trie",
|
|
|
|
"queue",
|
|
|
|
"lru_percpu_hash",
|
|
|
|
"stack",
|
|
|
|
"ringbuf",
|
2022-05-07 00:39:57 +03:00
|
|
|
};
|
|
|
|
|
2021-08-24 00:49:50 +03:00
|
|
|
typedef enum ebpf_map_option
|
|
|
|
{
|
2021-11-29 22:47:58 +03:00
|
|
|
EBPF_ANY, ///< Create a new element or update an existing element.
|
|
|
|
EBPF_NOEXIST, ///< Create a new element only when it does not exist.
|
|
|
|
EBPF_EXIST ///< Update an existing element.
|
2021-08-24 00:49:50 +03:00
|
|
|
} ebpf_map_option_t;
|
|
|
|
|
2021-10-01 18:01:39 +03:00
|
|
|
typedef enum ebpf_pin_type
|
|
|
|
{
|
2022-04-12 05:51:02 +03:00
|
|
|
PIN_NONE, ///< Object is not pinned.
|
|
|
|
PIN_OBJECT_NS, ///< Pinning that is local to an object.
|
|
|
|
PIN_GLOBAL_NS, ///< Pinning with a global namespace.
|
|
|
|
PIN_CUSTOM_NS ///< Pinning with a custom path given as section parameter.
|
2021-10-01 18:01:39 +03:00
|
|
|
} ebpf_pin_type_t;
|
|
|
|
|
2022-05-07 00:39:57 +03:00
|
|
|
static const char* const _ebpf_pin_type_names[] = {
|
|
|
|
BPF_ENUM_TO_STRING(PIN_NONE),
|
|
|
|
BPF_ENUM_TO_STRING(PIN_OBJECT_NS),
|
|
|
|
BPF_ENUM_TO_STRING(PIN_GLOBAL_NS),
|
|
|
|
BPF_ENUM_TO_STRING(PIN_CUSTOM_NS),
|
|
|
|
};
|
|
|
|
|
2021-09-07 19:54:08 +03:00
|
|
|
typedef uint32_t ebpf_id_t;
|
|
|
|
#define EBPF_ID_NONE UINT32_MAX
|
|
|
|
|
2021-06-09 18:44:24 +03:00
|
|
|
/**
|
2021-08-31 05:14:08 +03:00
|
|
|
* @brief eBPF Map Definition as it is stored in memory.
|
2021-06-09 18:44:24 +03:00
|
|
|
*/
|
2021-08-31 05:14:08 +03:00
|
|
|
typedef struct _ebpf_map_definition_in_memory
|
2021-06-09 18:44:24 +03:00
|
|
|
{
|
2021-08-31 05:14:08 +03:00
|
|
|
ebpf_map_type_t type; ///< Type of map.
|
|
|
|
uint32_t key_size; ///< Size in bytes of a map key.
|
|
|
|
uint32_t value_size; ///< Size in bytes of a map value.
|
|
|
|
uint32_t max_entries; ///< Maximum number of entries allowed in the map.
|
2021-09-07 19:54:08 +03:00
|
|
|
ebpf_id_t inner_map_id;
|
2021-10-01 18:01:39 +03:00
|
|
|
ebpf_pin_type_t pinning;
|
2021-08-31 05:14:08 +03:00
|
|
|
} ebpf_map_definition_in_memory_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief eBPF Map Definition as it appears in the maps section of an ELF file.
|
|
|
|
*/
|
|
|
|
typedef struct _ebpf_map_definition_in_file
|
|
|
|
{
|
|
|
|
ebpf_map_type_t type; ///< Type of map.
|
|
|
|
uint32_t key_size; ///< Size in bytes of a map key.
|
|
|
|
uint32_t value_size; ///< Size in bytes of a map value.
|
|
|
|
uint32_t max_entries; ///< Maximum number of entries allowed in the map.
|
|
|
|
|
|
|
|
/** When a map definition is hard coded in an eBPF program, inner_map_idx
|
|
|
|
* indicates the 0-based index of which map in the maps section of the ELF
|
|
|
|
* file is the inner map template.
|
|
|
|
*/
|
2021-08-24 04:46:24 +03:00
|
|
|
uint32_t inner_map_idx;
|
2021-10-01 18:01:39 +03:00
|
|
|
ebpf_pin_type_t pinning;
|
2021-10-01 01:14:26 +03:00
|
|
|
|
|
|
|
/** id is the identifier for a map template.
|
|
|
|
*/
|
|
|
|
uint32_t id;
|
|
|
|
/** For a map of map, inner_id is the id of the inner map template.
|
|
|
|
*/
|
|
|
|
uint32_t inner_id;
|
2021-08-31 05:14:08 +03:00
|
|
|
} ebpf_map_definition_in_file_t;
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2022-04-12 05:51:02 +03:00
|
|
|
BPF_FUNC_map_lookup_elem = 1, ///< \ref bpf_map_lookup_elem
|
|
|
|
BPF_FUNC_map_update_elem = 2, ///< \ref bpf_map_update_elem
|
|
|
|
BPF_FUNC_map_delete_elem = 3, ///< \ref bpf_map_delete_elem
|
|
|
|
BPF_FUNC_map_lookup_and_delete_elem = 4, ///< \ref bpf_map_lookup_and_delete_elem
|
|
|
|
BPF_FUNC_tail_call = 5, ///< \ref bpf_tail_call
|
|
|
|
BPF_FUNC_get_prandom_u32 = 6, ///< \ref bpf_get_prandom_u32
|
|
|
|
BPF_FUNC_ktime_get_boot_ns = 7, ///< \ref bpf_ktime_get_boot_ns
|
|
|
|
BPF_FUNC_get_smp_processor_id = 8, ///< \ref bpf_get_smp_processor_id
|
|
|
|
BPF_FUNC_ktime_get_ns = 9, ///< \ref bpf_ktime_get_ns
|
|
|
|
BPF_FUNC_csum_diff = 10, ///< \ref bpf_csum_diff
|
|
|
|
BPF_FUNC_ringbuf_output = 11, ///< \ref bpf_ringbuf_output
|
|
|
|
BPF_FUNC_trace_printk2 = 12, ///< \ref bpf_trace_printk2 (but use \ref bpf_printk instead)
|
|
|
|
BPF_FUNC_trace_printk3 = 13, ///< \ref bpf_trace_printk3 (but use \ref bpf_printk instead)
|
|
|
|
BPF_FUNC_trace_printk4 = 14, ///< \ref bpf_trace_printk4 (but use \ref bpf_printk instead)
|
|
|
|
BPF_FUNC_trace_printk5 = 15, ///< \ref bpf_trace_printk5 (but use \ref bpf_printk instead)
|
|
|
|
BPF_FUNC_map_push_elem = 16, ///< \ref bpf_map_push_elem
|
|
|
|
BPF_FUNC_map_pop_elem = 17, ///< \ref bpf_map_pop_elem
|
|
|
|
BPF_FUNC_map_peek_elem = 18, ///< \ref bpf_map_peek_elem
|
2022-05-19 05:12:31 +03:00
|
|
|
BPF_FUNC_get_current_pid_tgid = 19, ///< \ref bpf_get_current_pid_tgid
|
Rename ebpf_helpers.h to bpf_helpers.h for cross-plat compat (#472)
Libbpf has bpf_helpers.h which is mostly platform-agnostic, and
bpf_helper_defs.h which is platform-specific but is included
by bpf_helpers.h. Until libbpf is made more platform-agnostic
(issue #351), the workaround is to have a separate pair of files.
Our bpf_helpers.h and our own bpf_helper_defs.h, both of which
would ideally be merged into libbpf's in the future.
Platform-specific defines are in ebpf_struct.h, though that
name may need to change later on. Linux uses "linux/bpf.h"
(e.g., as used in the https://docs.cilium.io/en/v1.8/bpf/ and
https://developers.redhat.com/blog/2021/04/01/get-started-with-xdp
articles) or "vmlinux.h" (e.g., as used in the
https://ruderich.org/simon/notes/xdp-minimal-example article),
and these filenames are hard coded in eBPF programs. In the future,
we should probably settle on a cross-platform name and use include
paths to distinguish them, as opposed to requiring ifdefs in eBPF
programs. However, all of that is part of issue 351 and not this
issue.
Also removed obsolete/unused "repro.c" from tests/samples
Fixes #426
Signed-off-by: Dave Thaler <dthaler@microsoft.com>
Co-authored-by: Alan Jowett <alanjo@microsoft.com>
2021-09-02 02:30:33 +03:00
|
|
|
} ebpf_helper_id_t;
|
2021-09-11 07:54:07 +03:00
|
|
|
|
2021-09-15 22:08:18 +03:00
|
|
|
// Cross-platform BPF program types.
|
|
|
|
enum bpf_prog_type
|
|
|
|
{
|
2022-04-12 05:51:02 +03:00
|
|
|
BPF_PROG_TYPE_UNSPEC, ///< Unspecified program type.
|
|
|
|
|
|
|
|
/** @brief Program type for handling incoming packets as early as possible.
|
|
|
|
*
|
|
|
|
* **eBPF program prototype:** \ref xdp_hook_t
|
|
|
|
*
|
2022-04-14 17:31:26 +03:00
|
|
|
* **Attach type(s):** \ref BPF_XDP
|
2022-04-12 05:51:02 +03:00
|
|
|
*
|
|
|
|
* **Helpers available:** all helpers defined in bpf_helpers.h
|
|
|
|
*/
|
2021-09-15 22:08:18 +03:00
|
|
|
BPF_PROG_TYPE_XDP,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Program type for handling socket bind() requests.
|
|
|
|
*
|
|
|
|
* **eBPF program prototype:** \ref bind_hook_t
|
|
|
|
*
|
|
|
|
* **Attach type(s):** \ref BPF_ATTACH_TYPE_BIND
|
|
|
|
*
|
|
|
|
* **Helpers available:** all helpers defined in bpf_helpers.h
|
|
|
|
*/
|
2021-09-15 22:08:18 +03:00
|
|
|
BPF_PROG_TYPE_BIND, // TODO(#333): replace with cross-platform program type
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Program type for handling various socket operations such as connect(), accept() etc.
|
|
|
|
*
|
|
|
|
* **eBPF program prototype:** \ref sock_addr_hook_t
|
|
|
|
*
|
|
|
|
* **Attach type(s):**
|
|
|
|
* \ref BPF_CGROUP_INET4_CONNECT
|
|
|
|
* \ref BPF_CGROUP_INET6_CONNECT
|
|
|
|
* \ref BPF_CGROUP_INET4_RECV_ACCEPT
|
|
|
|
* \ref BPF_CGROUP_INET6_RECV_ACCEPT
|
|
|
|
*
|
|
|
|
* **Helpers available:** all helpers defined in bpf_helpers.h
|
|
|
|
*/
|
2022-04-08 04:18:53 +03:00
|
|
|
BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
2022-04-15 01:09:54 +03:00
|
|
|
/** @brief Program type for handling various socket event notifications such as connection established etc.
|
|
|
|
*
|
|
|
|
* **eBPF program prototype:** \ref sock_ops_hook_t
|
|
|
|
*
|
|
|
|
* **Attach type(s):**
|
|
|
|
* \ref BPF_CGROUP_SOCK_OPS
|
|
|
|
*
|
|
|
|
* **Helpers available:** all helpers defined in bpf_helpers.h
|
|
|
|
*/
|
|
|
|
BPF_PROG_TYPE_SOCK_OPS,
|
|
|
|
|
2022-04-12 05:51:02 +03:00
|
|
|
/** @brief Program type for handling calls from the eBPF sample extension. Used for
|
|
|
|
* testing.
|
|
|
|
*
|
|
|
|
* **eBPF program prototype:** see the eBPF sample extension.
|
|
|
|
*
|
|
|
|
* **Attach type(s):** \ref BPF_ATTACH_TYPE_SAMPLE
|
|
|
|
*/
|
2022-03-15 01:16:11 +03:00
|
|
|
BPF_PROG_TYPE_SAMPLE = 999
|
2021-09-15 22:08:18 +03:00
|
|
|
};
|
|
|
|
|
2022-03-15 01:16:11 +03:00
|
|
|
typedef enum bpf_prog_type bpf_prog_type_t;
|
|
|
|
|
2022-02-15 03:40:56 +03:00
|
|
|
#define XDP_FLAGS_REPLACE 0x01
|
|
|
|
|
2021-09-24 05:32:09 +03:00
|
|
|
// The link type is used to tell which union member is present
|
|
|
|
// in the bpf_link_info struct. There is exactly one non-zero value
|
|
|
|
// per union member.
|
|
|
|
enum bpf_link_type
|
|
|
|
{
|
2022-04-12 05:51:02 +03:00
|
|
|
BPF_LINK_TYPE_UNSPEC, ///< Unspecified link type.
|
2022-08-08 03:21:23 +03:00
|
|
|
BPF_LINK_TYPE_PLAIN, ///< No union members are used in bpf_link_info.
|
|
|
|
BPF_LINK_TYPE_CGROUP, ///< cgroup struct is present in bpf_link_info.
|
|
|
|
BPF_LINK_TYPE_XDP, ///< xdp struct is present in bpf_link_info.
|
2021-09-24 05:32:09 +03:00
|
|
|
};
|
|
|
|
|
2022-07-29 21:57:30 +03:00
|
|
|
static const char* const _ebpf_link_display_names[] = {
|
|
|
|
"unspec",
|
|
|
|
"plain",
|
|
|
|
};
|
|
|
|
|
2021-09-24 05:32:09 +03:00
|
|
|
enum bpf_attach_type
|
|
|
|
{
|
2022-04-12 05:51:02 +03:00
|
|
|
BPF_ATTACH_TYPE_UNSPEC, ///< Unspecified attach type.
|
|
|
|
|
|
|
|
/** @brief Attach type for handling incoming packets as early as possible.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_XDP
|
|
|
|
*/
|
2022-04-14 17:31:26 +03:00
|
|
|
BPF_XDP,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Attach type for handling socket bind() requests.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_BIND
|
|
|
|
*/
|
|
|
|
BPF_ATTACH_TYPE_BIND,
|
|
|
|
|
|
|
|
/** @brief Attach type for handling IPv4 TCP connect() or UDP send
|
|
|
|
* to a unique remote address/port tuple.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_CGROUP_SOCK_ADDR
|
|
|
|
*/
|
2022-04-08 04:18:53 +03:00
|
|
|
BPF_CGROUP_INET4_CONNECT,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Attach type for handling IPv6 TCP connect() or UDP send
|
|
|
|
* to a unique remote address/port tuple.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_CGROUP_SOCK_ADDR
|
|
|
|
*/
|
2022-04-08 04:18:53 +03:00
|
|
|
BPF_CGROUP_INET6_CONNECT,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Attach type for handling IPv4 TCP accept() or on receiving
|
|
|
|
* the first unicast UDP packet from a unique remote address/port tuple.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_CGROUP_SOCK_ADDR
|
|
|
|
*/
|
2022-04-08 04:18:53 +03:00
|
|
|
BPF_CGROUP_INET4_RECV_ACCEPT,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
|
|
|
/** @brief Attach type for handling IPv6 TCP accept() or on receiving
|
|
|
|
* the first unicast UDP packet from a unique remote address/port tuple.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_CGROUP_SOCK_ADDR
|
|
|
|
*/
|
2022-04-08 04:18:53 +03:00
|
|
|
BPF_CGROUP_INET6_RECV_ACCEPT,
|
2022-04-12 05:51:02 +03:00
|
|
|
|
2022-04-15 01:09:54 +03:00
|
|
|
/** @brief Attach type for handling various socket event notifications.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_SOCK_OPS
|
|
|
|
*/
|
|
|
|
BPF_CGROUP_SOCK_OPS,
|
|
|
|
|
2022-04-12 05:51:02 +03:00
|
|
|
/** @brief Attach type implemented by eBPF Sample Extension driver, used for testing.
|
|
|
|
*
|
|
|
|
* **Program type:** \ref BPF_PROG_TYPE_SAMPLE
|
|
|
|
*/
|
|
|
|
BPF_ATTACH_TYPE_SAMPLE,
|
|
|
|
|
2021-09-24 05:32:09 +03:00
|
|
|
__MAX_BPF_ATTACH_TYPE,
|
|
|
|
};
|
|
|
|
|
2022-06-15 18:59:39 +03:00
|
|
|
typedef enum bpf_attach_type bpf_attach_type_t;
|
|
|
|
|
2021-09-11 07:54:07 +03:00
|
|
|
// Libbpf itself requires the following structs to be defined, but doesn't
|
|
|
|
// care what fields they have. Applications such as bpftool on the other
|
|
|
|
// hand depend on fields of specific names and types.
|
|
|
|
|
2022-04-11 23:26:49 +03:00
|
|
|
#ifdef _MSC_VER
|
2021-09-24 05:32:09 +03:00
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable : 4201) /* nameless struct/union */
|
2022-04-11 23:26:49 +03:00
|
|
|
#endif
|
2022-04-12 05:51:02 +03:00
|
|
|
/**
|
|
|
|
* @brief eBPF link information. This structure can be retrieved by calling
|
|
|
|
* \ref bpf_obj_get_info_by_fd on a link fd.
|
|
|
|
*/
|
2021-09-11 07:54:07 +03:00
|
|
|
struct bpf_link_info
|
|
|
|
{
|
2022-02-15 03:40:56 +03:00
|
|
|
ebpf_id_t id; ///< Link ID.
|
|
|
|
ebpf_id_t prog_id; ///< Program ID.
|
|
|
|
enum bpf_link_type type; ///< Link type.
|
2022-07-29 21:57:30 +03:00
|
|
|
enum bpf_attach_type attach_type; ///< Attach type.
|
2022-02-15 03:40:56 +03:00
|
|
|
ebpf_attach_type_t attach_type_uuid; ///< Attach type UUID.
|
|
|
|
ebpf_program_type_t program_type_uuid; ///< Program type UUID.
|
2021-09-24 05:32:09 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
struct
|
|
|
|
{
|
2022-02-15 03:40:56 +03:00
|
|
|
uint32_t ifindex;
|
|
|
|
} xdp;
|
2022-08-08 03:21:23 +03:00
|
|
|
struct
|
|
|
|
{
|
|
|
|
uint64_t cgroup_id;
|
|
|
|
} cgroup;
|
|
|
|
uint8_t attach_data;
|
2021-09-24 05:32:09 +03:00
|
|
|
};
|
2021-09-11 07:54:07 +03:00
|
|
|
};
|
2022-04-11 23:26:49 +03:00
|
|
|
#ifdef _MSC_VER
|
2021-09-24 05:32:09 +03:00
|
|
|
#pragma warning(pop)
|
2022-04-11 23:26:49 +03:00
|
|
|
#endif
|
2021-09-11 07:54:07 +03:00
|
|
|
|
|
|
|
#define BPF_OBJ_NAME_LEN 64
|
|
|
|
|
2022-04-12 05:51:02 +03:00
|
|
|
/**
|
|
|
|
* @brief eBPF map information. This structure can be retrieved by calling
|
|
|
|
* \ref bpf_obj_get_info_by_fd on a map fd.
|
|
|
|
*/
|
2021-09-11 07:54:07 +03:00
|
|
|
struct bpf_map_info
|
|
|
|
{
|
2021-09-18 04:52:47 +03:00
|
|
|
// Cross-platform fields.
|
2021-09-11 07:54:07 +03:00
|
|
|
ebpf_id_t id; ///< Map ID.
|
|
|
|
ebpf_map_type_t type; ///< Type of map.
|
|
|
|
uint32_t key_size; ///< Size in bytes of a map key.
|
|
|
|
uint32_t value_size; ///< Size in bytes of a map value.
|
|
|
|
uint32_t max_entries; ///< Maximum number of entries allowed in the map.
|
|
|
|
char name[BPF_OBJ_NAME_LEN]; ///< Null-terminated map name.
|
2021-09-24 05:32:09 +03:00
|
|
|
uint32_t map_flags; ///< Map flags.
|
2021-09-18 04:52:47 +03:00
|
|
|
|
|
|
|
// Windows-specific fields.
|
2021-09-21 19:34:13 +03:00
|
|
|
ebpf_id_t inner_map_id; ///< ID of inner map template.
|
|
|
|
uint32_t pinned_path_count; ///< Number of pinned paths.
|
2021-09-11 07:54:07 +03:00
|
|
|
};
|
|
|
|
|
2021-09-24 05:32:09 +03:00
|
|
|
#define BPF_ANY 0x0
|
|
|
|
#define BPF_NOEXIST 0x1
|
|
|
|
#define BPF_EXIST 0x2
|
|
|
|
|
2022-04-12 05:51:02 +03:00
|
|
|
/**
|
|
|
|
* @brief eBPF program information. This structure can be retrieved by calling
|
|
|
|
* \ref bpf_obj_get_info_by_fd on a program fd.
|
|
|
|
*/
|
2021-09-11 07:54:07 +03:00
|
|
|
struct bpf_prog_info
|
|
|
|
{
|
2021-09-15 22:08:18 +03:00
|
|
|
// Cross-platform fields.
|
2021-09-11 07:54:07 +03:00
|
|
|
ebpf_id_t id; ///< Program ID.
|
2021-09-18 02:41:43 +03:00
|
|
|
enum bpf_prog_type type; ///< Program type, if a cross-platform type.
|
2021-09-11 07:54:07 +03:00
|
|
|
uint32_t nr_map_ids; ///< Number of maps associated with this program.
|
|
|
|
char name[BPF_OBJ_NAME_LEN]; ///< Null-terminated program name.
|
2021-09-15 22:08:18 +03:00
|
|
|
|
|
|
|
// Windows-specific fields.
|
2022-04-01 22:52:04 +03:00
|
|
|
ebpf_program_type_t type_uuid; ///< Program type UUID.
|
|
|
|
ebpf_attach_type_t attach_type_uuid; ///< Attach type UUID.
|
|
|
|
uint32_t pinned_path_count; ///< Number of pinned paths.
|
|
|
|
uint32_t link_count; ///< Number of attached links.
|
|
|
|
};
|