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
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2021-06-16 21:53:21 +03:00
|
|
|
#include "../external/ebpf-verifier/src/ebpf_base.h"
|
2021-06-09 18:44:24 +03:00
|
|
|
|
2021-08-04 03:25:50 +03:00
|
|
|
typedef enum bpf_map_type
|
2021-06-09 18:44:24 +03:00
|
|
|
{
|
2021-08-04 03:25:50 +03:00
|
|
|
BPF_MAP_TYPE_UNSPECIFIED = 0, ///< Unspecified map type.
|
|
|
|
BPF_MAP_TYPE_HASH = 1, ///< Hash table.
|
2021-08-06 23:18:47 +03:00
|
|
|
BPF_MAP_TYPE_ARRAY = 2, ///< Array, where the map key is the array index.
|
|
|
|
BPF_MAP_TYPE_PROG_ARRAY =
|
|
|
|
3, ///< Array of program fds usable with bpf_tail_call, where the map key is the array index.
|
2021-08-12 01:39:54 +03:00
|
|
|
BPF_MAP_TYPE_PERCPU_HASH = 4,
|
|
|
|
BPF_MAP_TYPE_PERCPU_ARRAY = 5,
|
2021-08-24 04:46:24 +03:00
|
|
|
BPF_MAP_TYPE_HASH_OF_MAPS = 6,
|
|
|
|
BPF_MAP_TYPE_ARRAY_OF_MAPS = 7,
|
2021-06-09 18:44:24 +03:00
|
|
|
} ebpf_map_type_t;
|
|
|
|
|
2021-08-24 00:49:50 +03:00
|
|
|
typedef enum ebpf_map_option
|
|
|
|
{
|
|
|
|
// Create a new element or update an existing element.
|
|
|
|
EBPF_ANY,
|
|
|
|
// Create a new element only when it does not exist.
|
|
|
|
EBPF_NOEXIST,
|
|
|
|
// Update an existing element.
|
|
|
|
EBPF_EXIST
|
|
|
|
} ebpf_map_option_t;
|
|
|
|
|
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
|
|
|
uint32_t size; ///< Size in bytes of the ebpf_map_definition_t structure.
|
|
|
|
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.
|
|
|
|
uint32_t inner_map_id;
|
|
|
|
} 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
|
|
|
|
{
|
|
|
|
uint32_t size; ///< Size in bytes of the ebpf_map_definition_t structure.
|
|
|
|
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-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
|
|
|
|
{
|
|
|
|
BPF_FUNC_map_lookup_elem = 1,
|
|
|
|
BPF_FUNC_map_update_elem = 2,
|
|
|
|
BPF_FUNC_map_delete_elem = 3,
|
|
|
|
BPF_FUNC_tail_call = 4,
|
|
|
|
BPF_FUNC_get_prandom_u32 = 5,
|
|
|
|
BPF_FUNC_ktime_get_boot_ns = 6,
|
|
|
|
BPF_FUNC_get_smp_processor_id = 7,
|
|
|
|
} ebpf_helper_id_t;
|