2021-06-10 22:02:00 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-10 05:38:31 +03:00
|
|
|
#pragma once
|
2021-04-16 02:15:00 +03:00
|
|
|
|
2021-05-06 23:47:09 +03:00
|
|
|
#include "ebpf_helpers.h"
|
2021-03-10 05:38:31 +03:00
|
|
|
#include "ebpf_platform.h"
|
|
|
|
|
2021-04-23 18:42:55 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-04-23 18:42:55 +03:00
|
|
|
typedef struct _ebpf_core_map ebpf_map_t;
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Allocate a new map.
|
|
|
|
*
|
2021-08-11 03:04:07 +03:00
|
|
|
* @param[in] map_name Name of the map.
|
2021-04-23 19:48:13 +03:00
|
|
|
* @param[in] ebpf_map_definition Definition of the new map.
|
2021-08-31 05:14:08 +03:00
|
|
|
* @param[in] inner_map_handle Handle to inner map, or ebpf_handle_invalid if none.
|
2021-04-23 19:48:13 +03:00
|
|
|
* @param[out] map Pointer to memory that will contain the map on success.
|
2021-05-20 22:38:58 +03:00
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_NO_MEMORY Unable to allocate resources for this
|
2021-04-23 19:48:13 +03:00
|
|
|
* map.
|
|
|
|
*/
|
2021-05-20 22:38:58 +03:00
|
|
|
ebpf_result_t
|
2021-08-11 03:04:07 +03:00
|
|
|
ebpf_map_create(
|
|
|
|
_In_ const ebpf_utf8_string_t* map_name,
|
2021-08-31 05:14:08 +03:00
|
|
|
_In_ const ebpf_map_definition_in_memory_t* ebpf_map_definition,
|
|
|
|
uintptr_t inner_map_handle,
|
2021-08-11 03:04:07 +03:00
|
|
|
_Outptr_ ebpf_map_t** map);
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Get a pointer to the map definition.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to get definition from.
|
|
|
|
* @return Pointer to map definition.
|
|
|
|
*/
|
2021-08-31 05:14:08 +03:00
|
|
|
const ebpf_map_definition_in_memory_t*
|
2021-06-16 23:27:22 +03:00
|
|
|
ebpf_map_get_definition(_In_ const ebpf_map_t* map);
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-08-18 02:22:32 +03:00
|
|
|
/**
|
|
|
|
* @brief Get the map value size specified when the map was originally
|
|
|
|
* created. For per-cpu maps this will be different from the value in the
|
|
|
|
* returned ebpf_map_definition_t.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to query
|
|
|
|
* @return uint32_t effective value size of the entry.
|
|
|
|
*/
|
|
|
|
uint32_t
|
|
|
|
ebpf_map_get_effective_value_size(_In_ const ebpf_map_t* map);
|
|
|
|
|
2021-08-13 22:13:16 +03:00
|
|
|
#define EBPF_MAP_FLAG_HELPER 0x01 /* Called by an eBPF program */
|
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Get a pointer to an entry in the map.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to search.
|
|
|
|
* @param[in] key Key to use when searching map.
|
2021-08-06 23:18:47 +03:00
|
|
|
* @param[in] flags Zero or more EBPF_MAP_FIND_ENTRY_FLAG_* flags.
|
2021-04-23 19:48:13 +03:00
|
|
|
* @return Pointer to the value if found or NULL.
|
|
|
|
*/
|
2021-08-13 22:13:16 +03:00
|
|
|
ebpf_result_t
|
|
|
|
ebpf_map_find_entry(
|
|
|
|
_In_ ebpf_map_t* map,
|
|
|
|
size_t key_size,
|
|
|
|
_In_reads_(key_size) const uint8_t* key,
|
|
|
|
size_t value_size,
|
|
|
|
_Out_writes_(value_size) uint8_t* value,
|
|
|
|
int flags);
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Insert or update an entry in the map.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to update.
|
|
|
|
* @param[in] key Key to use when searching and updating the map.
|
|
|
|
* @param[in] value Value to insert into the map.
|
2021-08-24 00:49:50 +03:00
|
|
|
* @param[in] option One of ebpf_map_option_t options.
|
|
|
|
* @param[in] flags EBPF_MAP_FLAG_HELPER if called from helper function.
|
2021-05-20 22:38:58 +03:00
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_NO_MEMORY Unable to allocate resources for this
|
2021-04-23 19:48:13 +03:00
|
|
|
* entry.
|
|
|
|
*/
|
2021-05-20 22:38:58 +03:00
|
|
|
ebpf_result_t
|
2021-08-13 22:13:16 +03:00
|
|
|
ebpf_map_update_entry(
|
|
|
|
_In_ ebpf_map_t* map,
|
|
|
|
size_t key_size,
|
|
|
|
_In_reads_(key_size) const uint8_t* key,
|
|
|
|
size_t value_size,
|
|
|
|
_In_reads_(value_size) const uint8_t* value,
|
2021-08-24 00:49:50 +03:00
|
|
|
ebpf_map_option_t option,
|
2021-08-13 22:13:16 +03:00
|
|
|
int flags);
|
2021-04-16 21:59:38 +03:00
|
|
|
|
2021-08-06 23:18:47 +03:00
|
|
|
/**
|
|
|
|
* @brief Insert or update an entry in the map.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to update.
|
|
|
|
* @param[in] key Key to use when searching and updating the map.
|
|
|
|
* @param[in] value Value to insert into the map.
|
|
|
|
* @param[in] value_handle Handle associated with the value.
|
2021-08-24 04:46:24 +03:00
|
|
|
* @param[in] option One of ebpf_map_option_t options.
|
2021-08-06 23:18:47 +03:00
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_NO_MEMORY Unable to allocate resources for this
|
|
|
|
* entry.
|
|
|
|
*/
|
|
|
|
ebpf_result_t
|
|
|
|
ebpf_map_update_entry_with_handle(
|
2021-08-13 22:13:16 +03:00
|
|
|
_In_ ebpf_map_t* map,
|
|
|
|
size_t key_size,
|
|
|
|
_In_reads_(key_size) const uint8_t* key,
|
|
|
|
size_t value_size,
|
|
|
|
_In_reads_(value_size) const uint8_t* value,
|
2021-08-24 04:46:24 +03:00
|
|
|
uintptr_t value_handle,
|
|
|
|
ebpf_map_option_t option);
|
2021-08-06 23:18:47 +03:00
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Remove an entry from the map.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to update.
|
|
|
|
* @param[in] key Key to use when searching and updating the map.
|
2021-05-20 22:38:58 +03:00
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_INVALID_ARGUMENT One or more parameters are
|
2021-04-23 19:48:13 +03:00
|
|
|
* invalid.
|
|
|
|
*/
|
2021-05-20 22:38:58 +03:00
|
|
|
ebpf_result_t
|
2021-08-24 00:49:50 +03:00
|
|
|
ebpf_map_delete_entry(_In_ ebpf_map_t* map, size_t key_size, _In_reads_(key_size) const uint8_t* key, int flags);
|
2021-04-23 18:42:55 +03:00
|
|
|
|
2021-04-23 19:48:13 +03:00
|
|
|
/**
|
|
|
|
* @brief Retrieve the next key from the map.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to search.
|
|
|
|
* @param[in] previous_key The previous key need not be present. This will
|
2021-06-16 23:27:22 +03:00
|
|
|
* return the next key lexicographically after the specified key. A value of
|
|
|
|
* null indicates that the first key is to be returned.
|
|
|
|
* @param[out] next_key Next key on success.
|
2021-05-20 22:38:58 +03:00
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_NO_MORE_KEYS There is no key following the specified
|
2021-04-23 19:48:13 +03:00
|
|
|
* key in lexicographically order.
|
|
|
|
*/
|
2021-05-20 22:38:58 +03:00
|
|
|
ebpf_result_t
|
2021-08-13 22:13:16 +03:00
|
|
|
ebpf_map_next_key(
|
|
|
|
_In_ ebpf_map_t* map,
|
|
|
|
size_t key_size,
|
|
|
|
_In_reads_opt_(key_size) const uint8_t* previous_key,
|
|
|
|
_Out_writes_(key_size) uint8_t* next_key);
|
2021-04-23 18:42:55 +03:00
|
|
|
|
2021-08-06 23:18:47 +03:00
|
|
|
/**
|
|
|
|
* @brief Get a program from an entry in a map that holds programs. The
|
|
|
|
* program returned holds a reference that the caller is responsible for
|
|
|
|
* releasing.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to search.
|
|
|
|
* @param[in] key Pointer to key to search for.
|
|
|
|
* @param[in] key_size Size of value to search for.
|
|
|
|
* @returns Program pointer, or NULL if none.
|
|
|
|
*/
|
|
|
|
_Ret_maybenull_ struct _ebpf_program*
|
2021-08-13 22:13:16 +03:00
|
|
|
ebpf_map_get_program_from_entry(_In_ ebpf_map_t* map, size_t key_size, _In_reads_(key_size) const uint8_t* key);
|
2021-08-06 23:18:47 +03:00
|
|
|
|
2021-08-11 22:17:10 +03:00
|
|
|
/**
|
|
|
|
* @brief Let a map take any actions when first
|
|
|
|
* associated with a program.
|
|
|
|
*
|
|
|
|
* @param[in] map Map to update.
|
|
|
|
* @param[in] program Program being associated with.
|
|
|
|
*
|
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_INVALID_FD The program is incompatible with this map.
|
|
|
|
*/
|
|
|
|
ebpf_result_t
|
|
|
|
ebpf_map_associate_program(_In_ ebpf_map_t* map, _In_ const struct _ebpf_program* program);
|
|
|
|
|
2021-04-23 18:42:55 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|