Remove duplicate public APIs where standard libbpf APIs exist (#356)
* Remove duplicate public APIs where standard libbpf APIs exist Signed-off-by: Dave Thaler <dthaler@microsoft.com>
This commit is contained in:
Родитель
2fe891abf7
Коммит
2617349903
|
@ -59,11 +59,4 @@ EXPORTS
|
|||
ebpf_api_get_pinned_map_info
|
||||
ebpf_api_map_info_free
|
||||
ebpf_free_string
|
||||
ebpf_map_get_fd
|
||||
ebpf_map_next
|
||||
ebpf_map_previous
|
||||
ebpf_object_close
|
||||
ebpf_program_get_fd
|
||||
ebpf_program_load
|
||||
ebpf_program_next
|
||||
ebpf_program_previous
|
||||
|
|
|
@ -70,9 +70,9 @@ extern "C"
|
|||
const ebpf_handle_t ebpf_handle_invalid = (ebpf_handle_t)-1;
|
||||
typedef struct _tlv_type_length_value tlv_type_length_value_t;
|
||||
|
||||
struct _ebpf_object;
|
||||
struct _ebpf_program;
|
||||
struct _ebpf_map;
|
||||
struct bpf_object;
|
||||
struct bpf_program;
|
||||
struct bpf_map;
|
||||
|
||||
/**
|
||||
* @brief Initialize the eBPF user mode library.
|
||||
|
@ -442,77 +442,10 @@ extern "C"
|
|||
_In_opt_ const ebpf_program_type_t* program_type,
|
||||
_In_opt_ const ebpf_attach_type_t* attach_type,
|
||||
_In_ ebpf_execution_type_t execution_type,
|
||||
_Outptr_ struct _ebpf_object** object,
|
||||
_Outptr_ struct bpf_object** object,
|
||||
_Out_ fd_t* program_fd,
|
||||
_Outptr_result_maybenull_z_ const char** log_buffer);
|
||||
|
||||
/**
|
||||
* @brief Get next program in ebpf_object object.
|
||||
*
|
||||
* @param[in] previous Pointer to previous eBPF program, or NULL to get the first one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the next program, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct _ebpf_program*
|
||||
ebpf_program_next(_In_opt_ const struct _ebpf_program* previous, _In_ const struct _ebpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get previous program in ebpf_object object.
|
||||
*
|
||||
* @param[in] next Pointer to next eBPF program, or NULL to get the last one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the previous program, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct _ebpf_program*
|
||||
ebpf_program_previous(_In_opt_ const struct _ebpf_program* next, _In_ const struct _ebpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get next map in ebpf_object object.
|
||||
*
|
||||
* @param[in] previous Pointer to previous eBPF map, or NULL to get the first one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the next map, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct _ebpf_map*
|
||||
ebpf_map_next(_In_opt_ const struct _ebpf_map* previous, _In_ const struct _ebpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get previous map in ebpf_object object.
|
||||
*
|
||||
* @param[in] next Pointer to next eBPF map, or NULL to get the last one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the previous map, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct _ebpf_map*
|
||||
ebpf_map_previous(_In_opt_ const struct _ebpf_map* next, _In_ const struct _ebpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Fetch fd for a program object.
|
||||
*
|
||||
* @param[in] program Pointer to eBPF program.
|
||||
* @return fd for the program on success, ebpf_fd_invalid on failure.
|
||||
*/
|
||||
fd_t
|
||||
ebpf_program_get_fd(_In_ const struct _ebpf_program* program);
|
||||
|
||||
/**
|
||||
* @brief Fetch fd for a map object.
|
||||
*
|
||||
* @param[in] map Pointer to eBPF map.
|
||||
* @return fd for the map on success, ebpf_fd_invalid on failure.
|
||||
*/
|
||||
fd_t
|
||||
ebpf_map_get_fd(_In_ const struct _ebpf_map* map);
|
||||
|
||||
/**
|
||||
* @brief Clean up ebpf_object. Also delete all the sub objects
|
||||
* (maps, programs) and close the related file descriptors.
|
||||
*
|
||||
* @param[in] object Pointer to ebpf_object.
|
||||
*/
|
||||
void
|
||||
ebpf_object_close(_In_ _Post_invalid_ struct _ebpf_object* object);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
|
||||
#include "ebpf_structs.h"
|
||||
|
||||
// In an execution context, struct bpf_map means struct _ebpf_map_definition,
|
||||
// as opposed to for user mode apps, so define the alias here where the execution
|
||||
// context and eBPF programs will get it.
|
||||
#define bpf_map _ebpf_map_definition
|
||||
|
||||
#ifndef __doxygen
|
||||
#define EBPF_HELPER(return_type, name, args) typedef return_type(*name##_t) args
|
||||
#endif
|
||||
|
@ -20,9 +25,9 @@
|
|||
* @param[in] key Key to use when searching map.
|
||||
* @return Pointer to the value if found or NULL.
|
||||
*/
|
||||
EBPF_HELPER(void*, ebpf_map_lookup_element, (ebpf_map_definition_t * map, void* key));
|
||||
EBPF_HELPER(void*, bpf_map_lookup_elem, (struct bpf_map * map, void* key));
|
||||
#ifndef __doxygen
|
||||
#define ebpf_map_lookup_element ((ebpf_map_lookup_element_t)1)
|
||||
#define bpf_map_lookup_elem ((bpf_map_lookup_elem_t)1)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -36,9 +41,9 @@ EBPF_HELPER(void*, ebpf_map_lookup_element, (ebpf_map_definition_t * map, void*
|
|||
* @retval EBPF_NO_MEMORY Unable to allocate resources for this
|
||||
* entry.
|
||||
*/
|
||||
EBPF_HELPER(int64_t, ebpf_map_update_element, (ebpf_map_definition_t * map, void* key, void* value, uint64_t flags));
|
||||
EBPF_HELPER(int64_t, bpf_map_update_elem, (struct bpf_map * map, void* key, void* value, uint64_t flags));
|
||||
#ifndef __doxygen
|
||||
#define ebpf_map_update_element ((ebpf_map_update_element_t)2)
|
||||
#define bpf_map_update_elem ((bpf_map_update_elem_t)2)
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -50,20 +55,7 @@ EBPF_HELPER(int64_t, ebpf_map_update_element, (ebpf_map_definition_t * map, void
|
|||
* @retval EBPF_INVALID_ARGUMENT One or more parameters are
|
||||
* invalid.
|
||||
*/
|
||||
EBPF_HELPER(int64_t, ebpf_map_delete_element, (ebpf_map_definition_t * map, void* key));
|
||||
EBPF_HELPER(int64_t, bpf_map_delete_elem, (struct bpf_map * map, void* key));
|
||||
#ifndef __doxygen
|
||||
#define ebpf_map_delete_element ((ebpf_map_delete_element_t)3)
|
||||
#define bpf_map_delete_elem ((bpf_map_delete_elem_t)3)
|
||||
#endif
|
||||
|
||||
//
|
||||
// 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
|
||||
|
|
|
@ -9,15 +9,15 @@
|
|||
#include <stdint.h>
|
||||
#include "../external/ebpf-verifier/src/ebpf_base.h"
|
||||
|
||||
typedef enum _ebpf_map_type
|
||||
typedef enum bpf_map_type
|
||||
{
|
||||
EBPF_MAP_TYPE_UNSPECIFIED = 0, ///< Unspecified map type.
|
||||
EBPF_MAP_TYPE_HASH = 1, ///< Hash table.
|
||||
EBPF_MAP_TYPE_ARRAY = 2, ///< Array, wehere the map key is the array index.
|
||||
BPF_MAP_TYPE_UNSPECIFIED = 0, ///< Unspecified map type.
|
||||
BPF_MAP_TYPE_HASH = 1, ///< Hash table.
|
||||
BPF_MAP_TYPE_ARRAY = 2, ///< Array, wehere the map key is the array index.
|
||||
} ebpf_map_type_t;
|
||||
|
||||
/**
|
||||
* @brief eBPF Map Definition
|
||||
* @brief eBPF Map Definition.
|
||||
*/
|
||||
typedef struct _ebpf_map_definition
|
||||
{
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
// Copyright (c) Microsoft Corporation
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4200) // Zero-sized array in struct/union
|
||||
#include "../external/libbpf/src/libbpf.h"
|
||||
#pragma warning(pop)
|
|
@ -17,13 +17,6 @@ typedef uint32_t __u32;
|
|||
typedef uint64_t __u64;
|
||||
typedef uint32_t pid_t;
|
||||
|
||||
#define bpf_map _ebpf_map
|
||||
#define bpf_map_type _ebpf_map_type
|
||||
#define bpf_object _ebpf_object
|
||||
#define bpf_program _ebpf_program
|
||||
#define bpf_prog_info _ebpf_program_info
|
||||
#define BPF_MAP_TYPE_ARRAY EBPF_MAP_TYPE_ARRAY
|
||||
|
||||
enum bpf_prog_type
|
||||
{
|
||||
BPF_PROG_TYPE_UNKNOWN,
|
||||
|
@ -45,3 +38,8 @@ enum bpf_stats_type
|
|||
{
|
||||
BPF_STATS_TYPE_UNKNOWN
|
||||
};
|
||||
|
||||
struct bpf_prog_info
|
||||
{
|
||||
int data;
|
||||
};
|
||||
|
|
|
@ -8,11 +8,11 @@
|
|||
#include "ebpf_windows.h"
|
||||
#include "spec_type_descriptors.hpp"
|
||||
|
||||
struct _ebpf_object;
|
||||
struct bpf_object;
|
||||
|
||||
typedef struct _ebpf_program
|
||||
typedef struct bpf_program
|
||||
{
|
||||
struct _ebpf_object* object;
|
||||
struct bpf_object* object;
|
||||
char* section_name;
|
||||
char* program_name;
|
||||
uint8_t* byte_code;
|
||||
|
@ -23,9 +23,9 @@ typedef struct _ebpf_program
|
|||
fd_t fd;
|
||||
} ebpf_program_t;
|
||||
|
||||
typedef struct _ebpf_map
|
||||
typedef struct bpf_map
|
||||
{
|
||||
const struct _ebpf_object* object;
|
||||
const struct bpf_object* object;
|
||||
char* name;
|
||||
ebpf_handle_t map_handle;
|
||||
fd_t map_fd;
|
||||
|
@ -34,7 +34,7 @@ typedef struct _ebpf_map
|
|||
bool pinned;
|
||||
} ebpf_map_t;
|
||||
|
||||
typedef struct _ebpf_object
|
||||
typedef struct bpf_object
|
||||
{
|
||||
char* file_name = nullptr;
|
||||
std::vector<ebpf_program_t*> programs;
|
||||
|
@ -62,3 +62,70 @@ clean_up_ebpf_programs(_Inout_ std::vector<ebpf_program_t*>& programs);
|
|||
|
||||
void
|
||||
clean_up_ebpf_maps(_Inout_ std::vector<ebpf_map_t*>& maps);
|
||||
|
||||
/**
|
||||
* @brief Get next program in ebpf_object object.
|
||||
*
|
||||
* @param[in] previous Pointer to previous eBPF program, or NULL to get the first one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the next program, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct bpf_program*
|
||||
ebpf_program_next(_In_opt_ const struct bpf_program* previous, _In_ const struct bpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get previous program in ebpf_object object.
|
||||
*
|
||||
* @param[in] next Pointer to next eBPF program, or NULL to get the last one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the previous program, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct bpf_program*
|
||||
ebpf_program_previous(_In_opt_ const struct bpf_program* next, _In_ const struct bpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get next map in ebpf_object object.
|
||||
*
|
||||
* @param[in] previous Pointer to previous eBPF map, or NULL to get the first one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the next map, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct bpf_map*
|
||||
ebpf_map_next(_In_opt_ const struct bpf_map* previous, _In_ const struct bpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Get previous map in ebpf_object object.
|
||||
*
|
||||
* @param[in] next Pointer to next eBPF map, or NULL to get the last one.
|
||||
* @param[in] object Pointer to eBPF object.
|
||||
* @return Pointer to the previous map, or NULL if none.
|
||||
*/
|
||||
_Ret_maybenull_ struct bpf_map*
|
||||
ebpf_map_previous(_In_opt_ const struct bpf_map* next, _In_ const struct bpf_object* object);
|
||||
|
||||
/**
|
||||
* @brief Fetch fd for a program object.
|
||||
*
|
||||
* @param[in] program Pointer to eBPF program.
|
||||
* @return fd for the program on success, ebpf_fd_invalid on failure.
|
||||
*/
|
||||
fd_t
|
||||
ebpf_program_get_fd(_In_ const struct bpf_program* program);
|
||||
|
||||
/**
|
||||
* @brief Fetch fd for a map object.
|
||||
*
|
||||
* @param[in] map Pointer to eBPF map.
|
||||
* @return fd for the map on success, ebpf_fd_invalid on failure.
|
||||
*/
|
||||
fd_t
|
||||
ebpf_map_get_fd(_In_ const struct bpf_map* map);
|
||||
|
||||
/**
|
||||
* @brief Clean up ebpf_object. Also delete all the sub objects
|
||||
* (maps, programs) and close the related file descriptors.
|
||||
*
|
||||
* @param[in] object Pointer to ebpf_object.
|
||||
*/
|
||||
void
|
||||
ebpf_object_close(_In_ _Post_invalid_ struct bpf_object* object);
|
||||
|
|
|
@ -472,7 +472,8 @@ ebpf_api_get_next_map(ebpf_handle_t previous_handle, ebpf_handle_t* next_handle)
|
|||
uint32_t
|
||||
ebpf_api_get_next_program(ebpf_handle_t previous_handle, ebpf_handle_t* next_handle)
|
||||
{
|
||||
_ebpf_operation_get_next_program_request request{sizeof(request),
|
||||
_ebpf_operation_get_next_program_request request{
|
||||
sizeof(request),
|
||||
ebpf_operation_id_t::EBPF_OPERATION_GET_NEXT_PROGRAM,
|
||||
reinterpret_cast<uint64_t>(previous_handle)};
|
||||
|
||||
|
@ -832,7 +833,7 @@ ebpf_program_load(
|
|||
_In_opt_ const ebpf_program_type_t* program_type,
|
||||
_In_opt_ const ebpf_attach_type_t* attach_type,
|
||||
_In_ ebpf_execution_type_t execution_type,
|
||||
_Outptr_ struct _ebpf_object** object,
|
||||
_Outptr_ struct bpf_object** object,
|
||||
_Out_ fd_t* program_fd,
|
||||
_Outptr_result_maybenull_z_ const char** log_buffer)
|
||||
{
|
||||
|
@ -938,8 +939,8 @@ Done:
|
|||
return result;
|
||||
}
|
||||
|
||||
_Ret_maybenull_ struct _ebpf_program*
|
||||
ebpf_program_next(_In_opt_ const struct _ebpf_program* previous, _In_ const struct _ebpf_object* object)
|
||||
_Ret_maybenull_ struct bpf_program*
|
||||
ebpf_program_next(_In_opt_ const struct bpf_program* previous, _In_ const struct bpf_object* object)
|
||||
{
|
||||
ebpf_program_t* program = nullptr;
|
||||
if (object == nullptr) {
|
||||
|
@ -964,8 +965,8 @@ Exit:
|
|||
return program;
|
||||
}
|
||||
|
||||
_Ret_maybenull_ struct _ebpf_program*
|
||||
ebpf_program_previous(_In_opt_ const struct _ebpf_program* next, _In_ const struct _ebpf_object* object)
|
||||
_Ret_maybenull_ struct bpf_program*
|
||||
ebpf_program_previous(_In_opt_ const struct bpf_program* next, _In_ const struct bpf_object* object)
|
||||
{
|
||||
ebpf_program_t* program = nullptr;
|
||||
if (object == nullptr) {
|
||||
|
@ -990,8 +991,8 @@ Exit:
|
|||
return program;
|
||||
}
|
||||
|
||||
_Ret_maybenull_ struct _ebpf_map*
|
||||
ebpf_map_next(_In_opt_ const struct _ebpf_map* previous, _In_ const struct _ebpf_object* object)
|
||||
_Ret_maybenull_ struct bpf_map*
|
||||
ebpf_map_next(_In_opt_ const struct bpf_map* previous, _In_ const struct bpf_object* object)
|
||||
{
|
||||
ebpf_map_t* map = nullptr;
|
||||
if (object == nullptr) {
|
||||
|
@ -1016,8 +1017,8 @@ Exit:
|
|||
return map;
|
||||
}
|
||||
|
||||
_Ret_maybenull_ struct _ebpf_map*
|
||||
ebpf_map_previous(_In_opt_ const struct _ebpf_map* next, _In_ const struct _ebpf_object* object)
|
||||
_Ret_maybenull_ struct bpf_map*
|
||||
ebpf_map_previous(_In_opt_ const struct bpf_map* next, _In_ const struct bpf_object* object)
|
||||
{
|
||||
ebpf_map_t* map = nullptr;
|
||||
if (object == nullptr) {
|
||||
|
@ -1043,7 +1044,7 @@ Exit:
|
|||
}
|
||||
|
||||
fd_t
|
||||
ebpf_program_get_fd(_In_ const struct _ebpf_program* program)
|
||||
ebpf_program_get_fd(_In_ const struct bpf_program* program)
|
||||
{
|
||||
if (program == nullptr) {
|
||||
return ebpf_fd_invalid;
|
||||
|
@ -1052,7 +1053,7 @@ ebpf_program_get_fd(_In_ const struct _ebpf_program* program)
|
|||
}
|
||||
|
||||
fd_t
|
||||
ebpf_map_get_fd(_In_ const struct _ebpf_map* map)
|
||||
ebpf_map_get_fd(_In_ const struct bpf_map* map)
|
||||
{
|
||||
if (map == nullptr) {
|
||||
return ebpf_fd_invalid;
|
||||
|
@ -1061,7 +1062,7 @@ ebpf_map_get_fd(_In_ const struct _ebpf_map* map)
|
|||
}
|
||||
|
||||
void
|
||||
ebpf_object_close(_In_ _Post_invalid_ struct _ebpf_object* object)
|
||||
ebpf_object_close(_In_ _Post_invalid_ struct bpf_object* object)
|
||||
{
|
||||
if (object == nullptr) {
|
||||
return;
|
||||
|
|
|
@ -105,12 +105,12 @@ get_program_type_windows(const std::string& section, const std::string&)
|
|||
return windows_xdp_program_type;
|
||||
}
|
||||
|
||||
#define EBPF_MAP_TYPE(x) EBPF_MAP_TYPE_##x, #x
|
||||
#define BPF_MAP_TYPE(x) BPF_MAP_TYPE_##x, #x
|
||||
|
||||
static const EbpfMapType windows_map_types[] = {
|
||||
{EBPF_MAP_TYPE(UNSPECIFIED)},
|
||||
{EBPF_MAP_TYPE(HASH)},
|
||||
{EBPF_MAP_TYPE(ARRAY), true},
|
||||
{BPF_MAP_TYPE(UNSPECIFIED)},
|
||||
{BPF_MAP_TYPE(HASH)},
|
||||
{BPF_MAP_TYPE(ARRAY), true},
|
||||
};
|
||||
|
||||
EbpfMapType
|
||||
|
|
|
@ -32,16 +32,16 @@ _ebpf_core_map_delete_element(ebpf_map_t* map, const uint8_t* key);
|
|||
#define EBPF_CORE_GLOBAL_HELPER_EXTENSION_VERSION 0
|
||||
|
||||
static ebpf_helper_function_prototype_t _ebpf_map_helper_function_prototype[] = {
|
||||
{(uint32_t)(intptr_t)ebpf_map_lookup_element,
|
||||
"ebpf_map_lookup_element",
|
||||
{(uint32_t)(intptr_t)bpf_map_lookup_elem,
|
||||
"bpf_map_lookup_elem",
|
||||
EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
|
||||
{(uint32_t)(intptr_t)ebpf_map_update_element,
|
||||
"ebpf_map_update_element",
|
||||
{(uint32_t)(intptr_t)bpf_map_update_elem,
|
||||
"bpf_map_update_elem",
|
||||
EBPF_RETURN_TYPE_INTEGER,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE}},
|
||||
{(uint32_t)(intptr_t)ebpf_map_delete_element,
|
||||
"ebpf_map_delete_element",
|
||||
{(uint32_t)(intptr_t)bpf_map_delete_elem,
|
||||
"bpf_map_delete_elem",
|
||||
EBPF_RETURN_TYPE_INTEGER,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}}};
|
||||
|
||||
|
@ -158,7 +158,7 @@ _ebpf_core_protocol_load_code(_In_ const ebpf_operation_load_code_request_t* req
|
|||
retval = ebpf_program_load_machine_code(program, code, code_length);
|
||||
} else {
|
||||
retval =
|
||||
ebpf_program_load_byte_code(program, (ebpf_instuction_t*)code, code_length / sizeof(ebpf_instuction_t));
|
||||
ebpf_program_load_byte_code(program, (ebpf_instruction_t*)code, code_length / sizeof(ebpf_instruction_t));
|
||||
}
|
||||
|
||||
if (retval != EBPF_SUCCESS)
|
||||
|
|
|
@ -23,7 +23,7 @@ typedef struct _ebpf_map_function_table
|
|||
ebpf_result_t (*next_key)(_In_ ebpf_core_map_t* map, _In_ const uint8_t* previous_key, _Out_ uint8_t* next_key);
|
||||
} ebpf_map_function_table_t;
|
||||
|
||||
extern ebpf_map_function_table_t ebpf_map_function_tables[EBPF_MAP_TYPE_ARRAY + 1];
|
||||
extern ebpf_map_function_table_t ebpf_map_function_tables[BPF_MAP_TYPE_ARRAY + 1];
|
||||
|
||||
ebpf_result_t
|
||||
ebpf_map_create(_In_ const ebpf_map_definition_t* ebpf_map_definition, _Outptr_ ebpf_map_t** ebpf_map)
|
||||
|
@ -31,7 +31,7 @@ ebpf_map_create(_In_ const ebpf_map_definition_t* ebpf_map_definition, _Outptr_
|
|||
ebpf_map_t* local_map = NULL;
|
||||
size_t type = ebpf_map_definition->type;
|
||||
|
||||
if (ebpf_map_definition->type > EBPF_MAP_TYPE_ARRAY)
|
||||
if (ebpf_map_definition->type > BPF_MAP_TYPE_ARRAY)
|
||||
return EBPF_INVALID_ARGUMENT;
|
||||
|
||||
if (!ebpf_map_function_tables[type].create_map)
|
||||
|
@ -306,16 +306,16 @@ ebpf_next_hash_map_key(_In_ ebpf_core_map_t* map, _In_ const uint8_t* previous_k
|
|||
}
|
||||
|
||||
ebpf_map_function_table_t ebpf_map_function_tables[] = {
|
||||
{// EBPF_MAP_TYPE_UNSPECIFIED
|
||||
{// BPF_MAP_TYPE_UNSPECIFIED
|
||||
NULL},
|
||||
{// EBPF_MAP_TYPE_HASH
|
||||
{// BPF_MAP_TYPE_HASH
|
||||
ebpf_create_hash_map,
|
||||
ebpf_delete_hash_map,
|
||||
ebpf_find_hash_map_entry,
|
||||
ebpf_update_hash_map_entry,
|
||||
ebpf_delete_hash_map_entry,
|
||||
ebpf_next_hash_map_key},
|
||||
{// EBPF_MAP_TYPE_ARRAY
|
||||
{// BPF_MAP_TYPE_ARRAY
|
||||
ebpf_create_array_map,
|
||||
ebpf_delete_array_map,
|
||||
ebpf_find_array_map_entry,
|
||||
|
|
|
@ -389,7 +389,7 @@ _ebpf_program_register_helpers(ebpf_program_t* program)
|
|||
}
|
||||
|
||||
ebpf_result_t
|
||||
ebpf_program_load_byte_code(ebpf_program_t* program, ebpf_instuction_t* instructions, size_t instruction_count)
|
||||
ebpf_program_load_byte_code(ebpf_program_t* program, ebpf_instruction_t* instructions, size_t instruction_count)
|
||||
{
|
||||
ebpf_result_t return_value;
|
||||
char* error_message = NULL;
|
||||
|
@ -418,7 +418,7 @@ ebpf_program_load_byte_code(ebpf_program_t* program, ebpf_instuction_t* instruct
|
|||
if (ubpf_load(
|
||||
program->code_or_vm.vm,
|
||||
instructions,
|
||||
(uint32_t)(instruction_count * sizeof(ebpf_instuction_t)),
|
||||
(uint32_t)(instruction_count * sizeof(ebpf_instruction_t)),
|
||||
&error_message) != 0) {
|
||||
ebpf_free(error_message);
|
||||
return_value = EBPF_INVALID_ARGUMENT;
|
||||
|
|
|
@ -14,16 +14,15 @@ extern "C"
|
|||
#endif
|
||||
typedef enum _ebpf_code_type ebpf_code_type_t;
|
||||
|
||||
typedef struct _ebpf_instuction
|
||||
typedef struct _ebpf_instruction
|
||||
{
|
||||
uint8_t opcode;
|
||||
uint8_t dst : 4; //< Destination register
|
||||
uint8_t src : 4; //< Source register
|
||||
int16_t offset;
|
||||
int32_t imm; //< Immediate constant
|
||||
} ebpf_instuction_t;
|
||||
} ebpf_instruction_t;
|
||||
|
||||
typedef struct _ebpf_program ebpf_program_t;
|
||||
typedef struct _ebpf_program_parameters
|
||||
{
|
||||
ebpf_program_type_t program_type;
|
||||
|
@ -130,7 +129,7 @@ extern "C"
|
|||
* program instance.
|
||||
*/
|
||||
ebpf_result_t
|
||||
ebpf_program_load_byte_code(ebpf_program_t* program, ebpf_instuction_t* instructions, size_t instruction_count);
|
||||
ebpf_program_load_byte_code(ebpf_program_t* program, ebpf_instruction_t* instructions, size_t instruction_count);
|
||||
|
||||
/**
|
||||
* @brief Invoke an ebpf_program_t instance.
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#pragma once
|
||||
|
||||
// This file must only include headers that are safe
|
||||
// to include in both user mode and kernel mode.
|
||||
#include "ebpf_core_structs.h"
|
||||
#include "ebpf_helpers.h"
|
||||
#include "ebpf_windows.h"
|
||||
|
||||
typedef enum _ebpf_operation_id
|
||||
|
|
|
@ -95,9 +95,9 @@ test_crud_operations(ebpf_map_type_t map_type)
|
|||
REQUIRE(memcmp(retrieved_map_definition, &map_definition, sizeof(map_definition)) == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("map_crud_operations_array", "[execution_context]") { test_crud_operations(EBPF_MAP_TYPE_ARRAY); }
|
||||
TEST_CASE("map_crud_operations_array", "[execution_context]") { test_crud_operations(BPF_MAP_TYPE_ARRAY); }
|
||||
|
||||
TEST_CASE("map_crud_operations_hash", "[execution_context]") { test_crud_operations(EBPF_MAP_TYPE_HASH); }
|
||||
TEST_CASE("map_crud_operations_hash", "[execution_context]") { test_crud_operations(BPF_MAP_TYPE_HASH); }
|
||||
|
||||
#define TEST_FUNCTION_RETURN 42
|
||||
|
||||
|
@ -118,7 +118,7 @@ TEST_CASE("program", "[execution_context]")
|
|||
}
|
||||
|
||||
ebpf_map_definition_t map_definition{
|
||||
sizeof(ebpf_map_definition_t), EBPF_MAP_TYPE_HASH, sizeof(uint32_t), sizeof(uint64_t), 10};
|
||||
sizeof(ebpf_map_definition_t), BPF_MAP_TYPE_HASH, sizeof(uint32_t), sizeof(uint64_t), 10};
|
||||
map_ptr map;
|
||||
{
|
||||
ebpf_map_t* local_map;
|
||||
|
|
|
@ -22,6 +22,8 @@ extern "C"
|
|||
typedef struct _ebpf_object ebpf_object_t;
|
||||
typedef void (*ebpf_free_object_t)(ebpf_object_t* object);
|
||||
|
||||
// This type probably ought to be renamed to avoid confusion with
|
||||
// ebpf_object_t in libs\api\api_internal.h
|
||||
typedef struct _ebpf_object
|
||||
{
|
||||
uint32_t marker;
|
||||
|
|
|
@ -226,15 +226,15 @@ TEST_CASE("program_type_info", "[platform]")
|
|||
|
||||
ebpf_helper_function_prototype_t helper_functions[] = {
|
||||
{1,
|
||||
"ebpf_map_lookup_element",
|
||||
"bpf_map_lookup_elem",
|
||||
EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
|
||||
{2,
|
||||
"ebpf_map_update_element",
|
||||
"bpf_map_update_elem",
|
||||
EBPF_RETURN_TYPE_INTEGER,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE}},
|
||||
{3,
|
||||
"ebpf_map_delete_element",
|
||||
"bpf_map_delete_elem",
|
||||
EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
|
||||
};
|
||||
|
@ -355,7 +355,7 @@ TEST_CASE("serialize_map_test", "[platform]")
|
|||
for (int i = 0; i < map_count; i++) {
|
||||
ebpf_map_info_internal_t* map_info = &internal_map_info_array[i];
|
||||
map_info->definition.size = (i + 1) * 32;
|
||||
map_info->definition.type = static_cast<ebpf_map_type_t>(i % (EBPF_MAP_TYPE_ARRAY + 1));
|
||||
map_info->definition.type = static_cast<ebpf_map_type_t>(i % (BPF_MAP_TYPE_ARRAY + 1));
|
||||
map_info->definition.key_size = i + 1;
|
||||
map_info->definition.value_size = (i + 1) * (i + 1);
|
||||
map_info->definition.max_entries = (i + 1) * 128;
|
||||
|
|
|
@ -11,13 +11,7 @@
|
|||
#include "catch_wrapper.hpp"
|
||||
#include "common_tests.h"
|
||||
#include "service_helper.h"
|
||||
|
||||
namespace api_test {
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
|
||||
#include "../sample/ebpf.h"
|
||||
#pragma warning(pop)
|
||||
}; // namespace api_test
|
||||
#include "libbpf.h"
|
||||
|
||||
#define SAMPLE_PATH ""
|
||||
|
||||
|
@ -50,7 +44,7 @@ _program_load_helper(
|
|||
const char* file_name,
|
||||
const ebpf_program_type_t* program_type,
|
||||
ebpf_execution_type_t execution_type,
|
||||
struct _ebpf_object** object,
|
||||
struct bpf_object** object,
|
||||
fd_t* program_fd)
|
||||
{
|
||||
ebpf_result_t result;
|
||||
|
@ -69,7 +63,7 @@ _test_program_load(
|
|||
bool expected_to_load)
|
||||
{
|
||||
ebpf_result_t result;
|
||||
struct _ebpf_object* object = nullptr;
|
||||
struct bpf_object* object = nullptr;
|
||||
fd_t program_fd;
|
||||
ebpf_handle_t program_handle = INVALID_HANDLE_VALUE;
|
||||
ebpf_handle_t next_program_handle = INVALID_HANDLE_VALUE;
|
||||
|
@ -111,7 +105,7 @@ _test_program_load(
|
|||
|
||||
ebpf_api_close_handle(program_handle);
|
||||
program_handle = INVALID_HANDLE_VALUE;
|
||||
ebpf_object_close(object);
|
||||
bpf_object__close(object);
|
||||
|
||||
// We have closed both handles to the program. Program should be unloaded now.
|
||||
REQUIRE(ebpf_api_get_next_program(program_handle, &next_program_handle) == ERROR_SUCCESS);
|
||||
|
@ -122,68 +116,68 @@ static void
|
|||
_test_map_next_previous(const char* file_name, int expected_map_count)
|
||||
{
|
||||
ebpf_result_t result;
|
||||
struct _ebpf_object* object = nullptr;
|
||||
struct bpf_object* object = nullptr;
|
||||
fd_t program_fd;
|
||||
int map_count = 0;
|
||||
struct _ebpf_map* previous = nullptr;
|
||||
struct _ebpf_map* next = nullptr;
|
||||
struct bpf_map* previous = nullptr;
|
||||
struct bpf_map* next = nullptr;
|
||||
result = _program_load_helper(file_name, nullptr, EBPF_EXECUTION_ANY, &object, &program_fd);
|
||||
REQUIRE(result == EBPF_SUCCESS);
|
||||
|
||||
next = ebpf_map_next(previous, object);
|
||||
next = bpf_map__next(previous, object);
|
||||
while (next != nullptr) {
|
||||
map_count++;
|
||||
previous = next;
|
||||
next = ebpf_map_next(previous, object);
|
||||
next = bpf_map__next(previous, object);
|
||||
}
|
||||
REQUIRE(map_count == expected_map_count);
|
||||
|
||||
map_count = 0;
|
||||
previous = next = nullptr;
|
||||
|
||||
previous = ebpf_map_previous(next, object);
|
||||
previous = bpf_map__prev(next, object);
|
||||
while (previous != nullptr) {
|
||||
map_count++;
|
||||
next = previous;
|
||||
previous = ebpf_map_previous(next, object);
|
||||
previous = bpf_map__prev(next, object);
|
||||
}
|
||||
REQUIRE(map_count == expected_map_count);
|
||||
|
||||
ebpf_object_close(object);
|
||||
bpf_object__close(object);
|
||||
}
|
||||
|
||||
static void
|
||||
_test_program_next_previous(const char* file_name, int expected_program_count)
|
||||
{
|
||||
ebpf_result_t result;
|
||||
struct _ebpf_object* object = nullptr;
|
||||
struct bpf_object* object = nullptr;
|
||||
fd_t program_fd;
|
||||
int program_count = 0;
|
||||
struct _ebpf_program* previous = nullptr;
|
||||
struct _ebpf_program* next = nullptr;
|
||||
struct bpf_program* previous = nullptr;
|
||||
struct bpf_program* next = nullptr;
|
||||
result = _program_load_helper(file_name, nullptr, EBPF_EXECUTION_ANY, &object, &program_fd);
|
||||
REQUIRE(result == EBPF_SUCCESS);
|
||||
|
||||
next = ebpf_program_next(previous, object);
|
||||
next = bpf_program__next(previous, object);
|
||||
while (next != nullptr) {
|
||||
program_count++;
|
||||
previous = next;
|
||||
next = ebpf_program_next(previous, object);
|
||||
next = bpf_program__next(previous, object);
|
||||
}
|
||||
REQUIRE(program_count == expected_program_count);
|
||||
|
||||
program_count = 0;
|
||||
previous = next = nullptr;
|
||||
|
||||
previous = ebpf_program_previous(next, object);
|
||||
previous = bpf_program__prev(next, object);
|
||||
while (previous != nullptr) {
|
||||
program_count++;
|
||||
next = previous;
|
||||
previous = ebpf_program_previous(next, object);
|
||||
previous = bpf_program__prev(next, object);
|
||||
}
|
||||
REQUIRE(program_count == expected_program_count);
|
||||
|
||||
ebpf_object_close(object);
|
||||
bpf_object__close(object);
|
||||
}
|
||||
|
||||
TEST_CASE("pinned_map_enum", "[pinned_map_enum]")
|
||||
|
|
|
@ -578,10 +578,10 @@ TEST_CASE("enumerate_and_query_maps", "[end_to_end]")
|
|||
|
||||
ebpf_map_definition_t map_definitions[_countof(map_handles)];
|
||||
ebpf_map_definition_t process_map = {
|
||||
sizeof(ebpf_map_definition_t), EBPF_MAP_TYPE_HASH, sizeof(uint64_t), sizeof(process_entry_t), 1024};
|
||||
sizeof(ebpf_map_definition_t), BPF_MAP_TYPE_HASH, sizeof(uint64_t), sizeof(process_entry_t), 1024};
|
||||
|
||||
ebpf_map_definition_t limits_map = {
|
||||
sizeof(ebpf_map_definition_t), EBPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
|
||||
sizeof(ebpf_map_definition_t), BPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint32_t), 1};
|
||||
|
||||
for (size_t index = 0; index < _countof(map_handles); index++) {
|
||||
REQUIRE(
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "catch_wrapper.hpp"
|
||||
#include "common_tests.h"
|
||||
#include "libbpf.h"
|
||||
#include "service_helper.h"
|
||||
#include "test_ext_app.h"
|
||||
|
||||
|
@ -39,7 +40,7 @@ _program_load_helper(
|
|||
_In_z_ const char* file_name,
|
||||
_In_ const ebpf_program_type_t* program_type,
|
||||
ebpf_execution_type_t execution_type,
|
||||
_Outptr_ struct _ebpf_object** object,
|
||||
_Outptr_ struct bpf_object** object,
|
||||
_Out_ fd_t* program_fd)
|
||||
{
|
||||
ebpf_result_t result;
|
||||
|
@ -53,7 +54,7 @@ _program_load_helper(
|
|||
TEST_CASE("test_test", "[test_test]")
|
||||
{
|
||||
ebpf_result_t result;
|
||||
struct _ebpf_object* object = nullptr;
|
||||
struct bpf_object* object = nullptr;
|
||||
fd_t program_fd;
|
||||
ebpf_handle_t program_handle = INVALID_HANDLE_VALUE;
|
||||
ebpf_handle_t next_program_handle = INVALID_HANDLE_VALUE;
|
||||
|
@ -104,7 +105,7 @@ TEST_CASE("test_test", "[test_test]")
|
|||
nullptr) == TRUE);
|
||||
|
||||
ebpf_api_close_handle(program_handle);
|
||||
ebpf_object_close(object);
|
||||
bpf_object__close(object);
|
||||
if (device_handle != INVALID_HANDLE_VALUE)
|
||||
::CloseHandle(device_handle);
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ ebpf_test_pinned_map_enum()
|
|||
ebpf_map_info_t* map_info = nullptr;
|
||||
|
||||
REQUIRE(
|
||||
(result = ebpf_api_create_map(EBPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint64_t), 1024, 0, &map_handle)) ==
|
||||
(result = ebpf_api_create_map(BPF_MAP_TYPE_ARRAY, sizeof(uint32_t), sizeof(uint64_t), 1024, 0, &map_handle)) ==
|
||||
EBPF_SUCCESS);
|
||||
|
||||
if (result != EBPF_SUCCESS)
|
||||
|
|
|
@ -17,13 +17,13 @@ typedef struct _process_entry
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t process_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_HASH,
|
||||
.type = BPF_MAP_TYPE_HASH,
|
||||
.key_size = sizeof(uint64_t),
|
||||
.value_size = sizeof(process_entry_t),
|
||||
.max_entries = 1024};
|
||||
|
||||
ebpf_map_definition_t limits_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_ARRAY,
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint32_t),
|
||||
.max_entries = 1};
|
||||
|
@ -36,7 +36,7 @@ find_or_create_process_entry(bind_md_t* ctx)
|
|||
process_entry_t value = {0};
|
||||
int index;
|
||||
|
||||
entry = ebpf_map_lookup_element(&process_map, &key);
|
||||
entry = bpf_map_lookup_elem(&process_map, &key);
|
||||
if (entry)
|
||||
return entry;
|
||||
|
||||
|
@ -46,8 +46,8 @@ find_or_create_process_entry(bind_md_t* ctx)
|
|||
if (!ctx->app_id_start || !ctx->app_id_end)
|
||||
return entry;
|
||||
|
||||
ebpf_map_update_element(&process_map, &key, &value, 0);
|
||||
entry = ebpf_map_lookup_element(&process_map, &key);
|
||||
bpf_map_update_elem(&process_map, &key, &value, 0);
|
||||
entry = bpf_map_lookup_elem(&process_map, &key);
|
||||
if (!entry)
|
||||
return entry;
|
||||
|
||||
|
@ -71,7 +71,7 @@ BindMonitor(bind_md_t* ctx)
|
|||
{
|
||||
uint32_t limit_key = 0;
|
||||
process_entry_t* entry;
|
||||
uint32_t* limit = ebpf_map_lookup_element(&limits_map, &limit_key);
|
||||
uint32_t* limit = bpf_map_lookup_elem(&limits_map, &limit_key);
|
||||
if (!limit || *limit == 0)
|
||||
return BIND_PERMIT;
|
||||
|
||||
|
@ -99,7 +99,7 @@ BindMonitor(bind_md_t* ctx)
|
|||
|
||||
if (entry->count == 0) {
|
||||
uint64_t key = ctx->process_id;
|
||||
ebpf_map_delete_element(&process_map, &key);
|
||||
bpf_map_delete_elem(&process_map, &key);
|
||||
}
|
||||
|
||||
return BIND_PERMIT;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_ARRAY,
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint32_t),
|
||||
.max_entries = 1};
|
||||
|
@ -20,7 +20,7 @@ uint32_t
|
|||
divide_by_zero(xdp_md_t* ctx)
|
||||
{
|
||||
uint32_t key = 0;
|
||||
uint32_t* value = ebpf_map_lookup_element(&test_map, &key);
|
||||
uint32_t* value = bpf_map_lookup_elem(&test_map, &key);
|
||||
if (value) {
|
||||
return 100000 / *value;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t port_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_ARRAY,
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint64_t),
|
||||
.max_entries = 1};
|
||||
|
@ -29,7 +29,7 @@ DropPacket(xdp_md_t* ctx)
|
|||
if (iphdr->Protocol == 17) {
|
||||
if (ntohs(udphdr->length) <= sizeof(UDP_HEADER)) {
|
||||
long key = 0;
|
||||
long* count = ebpf_map_lookup_element(&port_map, &key);
|
||||
long* count = bpf_map_lookup_elem(&port_map, &key);
|
||||
if (count)
|
||||
*count = (*count + 1);
|
||||
rc = XDP_DROP;
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t port_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_ARRAY,
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint64_t),
|
||||
.max_entries = 1};
|
||||
|
@ -27,7 +27,7 @@ DropPacket(xdp_md_t* ctx)
|
|||
if (iphdr->Protocol == 17) {
|
||||
if (ntohs(udphdr->length) <= sizeof(UDP_HEADER)) {
|
||||
long key = 0;
|
||||
long* count = ebpf_map_lookup_element(&port_map, &key);
|
||||
long* count = bpf_map_lookup_elem(&port_map, &key);
|
||||
if (count)
|
||||
*count = (*count + 1);
|
||||
rc = XDP_DROP;
|
||||
|
|
|
@ -14,8 +14,10 @@ typedef unsigned char uint8_t;
|
|||
#include "ebpf_helpers.h"
|
||||
#include "ebpf_nethooks.h"
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable : 4201) // nonstandard extension used : nameless struct/union
|
||||
#endif
|
||||
|
||||
uint16_t
|
||||
ntohs(uint16_t us)
|
||||
|
@ -72,4 +74,6 @@ typedef struct UDP_HEADER_
|
|||
uint16_t checksum;
|
||||
} UDP_HEADER;
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
|
|
@ -22,7 +22,7 @@ typedef unsigned char uint8_t;
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_HASH,
|
||||
.type = BPF_MAP_TYPE_HASH,
|
||||
.key_size = sizeof(uint64_t),
|
||||
.value_size = sizeof(uint64_t),
|
||||
.max_entries = 1};
|
||||
|
@ -33,7 +33,7 @@ BindMonitor(bind_md_t* ctx)
|
|||
{
|
||||
uint64_t key = ctx->process_id;
|
||||
|
||||
uint64_t* value = ebpf_map_lookup_element(&test_map, &key);
|
||||
uint64_t* value = bpf_map_lookup_elem(&test_map, &key);
|
||||
|
||||
*value = 1;
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
#pragma clang section data = "maps"
|
||||
ebpf_map_definition_t test_map = {.size = sizeof(ebpf_map_definition_t),
|
||||
.type = EBPF_MAP_TYPE_ARRAY,
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(uint32_t),
|
||||
.value_size = sizeof(uint64_t),
|
||||
.max_entries = 128};
|
||||
|
|
|
@ -125,7 +125,7 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)external\libbpf\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
|
@ -144,7 +144,7 @@
|
|||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;$(SolutionDir)external\libbpf\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)include;$(SolutionDir)libs\api;$(SolutionDir)libs\ebpfnetsh;$(SolutionDir)tests\libs\util;$(SolutionDir)tests\libs\common;$(OutDir);$(SolutionDir)external\ebpf-verifier\src;$(SolutionDir)libs\service;$(SolutionDir)rpc_interface;$(SolutionDir)libs\platform;$(SolutionDir)libs\platform\user;$(SolutionDir)libs\execution_context;$(SolutionDir)tests\end_to_end;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||
</ClCompile>
|
||||
|
|
|
@ -33,15 +33,15 @@ _emit_program_info_file(const char* file_name, const char* symbol_name, uint8_t*
|
|||
|
||||
static ebpf_helper_function_prototype_t _ebpf_helper_function_prototype[] = {
|
||||
{1,
|
||||
"ebpf_map_lookup_element",
|
||||
"bpf_map_lookup_elem",
|
||||
EBPF_RETURN_TYPE_PTR_TO_MAP_VALUE_OR_NULL,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}},
|
||||
{2,
|
||||
"ebpf_map_update_element",
|
||||
"bpf_map_update_elem",
|
||||
EBPF_RETURN_TYPE_INTEGER,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_VALUE}},
|
||||
{3,
|
||||
"ebpf_map_delete_element",
|
||||
"bpf_map_delete_elem",
|
||||
EBPF_RETURN_TYPE_INTEGER,
|
||||
{EBPF_ARGUMENT_TYPE_PTR_TO_MAP, EBPF_ARGUMENT_TYPE_PTR_TO_MAP_KEY}}};
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче