2021-06-10 22:02:00 +03:00
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
// SPDX-License-Identifier: MIT
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ebpf_platform.h"
|
2021-09-07 19:54:08 +03:00
|
|
|
#include "ebpf_structs.h"
|
2021-04-26 22:16:20 +03:00
|
|
|
#include "framework.h"
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
typedef enum _ebpf_object_type
|
|
|
|
{
|
2021-04-30 21:49:23 +03:00
|
|
|
EBPF_OBJECT_UNKNOWN,
|
2021-04-23 19:21:12 +03:00
|
|
|
EBPF_OBJECT_MAP,
|
2021-04-27 02:17:44 +03:00
|
|
|
EBPF_OBJECT_LINK,
|
2021-04-23 19:21:12 +03:00
|
|
|
EBPF_OBJECT_PROGRAM,
|
|
|
|
} ebpf_object_type_t;
|
|
|
|
|
2022-03-07 20:07:10 +03:00
|
|
|
typedef struct _ebpf_core_object ebpf_core_object_t;
|
|
|
|
typedef void (*ebpf_free_object_t)(ebpf_core_object_t* object);
|
|
|
|
typedef const ebpf_program_type_t* (*ebpf_object_get_program_type_t)(_In_ const ebpf_core_object_t* object);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
2022-03-07 20:07:10 +03:00
|
|
|
typedef struct _ebpf_core_object
|
2021-04-23 19:21:12 +03:00
|
|
|
{
|
|
|
|
uint32_t marker;
|
|
|
|
volatile int32_t reference_count;
|
|
|
|
ebpf_object_type_t type;
|
2021-04-30 22:55:21 +03:00
|
|
|
ebpf_free_object_t free_function;
|
2021-08-24 04:46:24 +03:00
|
|
|
ebpf_object_get_program_type_t get_program_type;
|
2021-09-07 19:54:08 +03:00
|
|
|
// ID for this object.
|
|
|
|
ebpf_id_t id;
|
2021-07-31 03:17:16 +03:00
|
|
|
// Used to insert object in an object specific list.
|
|
|
|
ebpf_list_entry_t object_list_entry;
|
2021-09-18 02:41:43 +03:00
|
|
|
// # of pinned paths, for diagnostic purposes.
|
2022-06-09 21:47:05 +03:00
|
|
|
volatile int32_t pinned_path_count;
|
2022-03-07 20:07:10 +03:00
|
|
|
} ebpf_core_object_t;
|
2021-04-23 19:21:12 +03:00
|
|
|
|
2021-04-30 22:55:21 +03:00
|
|
|
/**
|
|
|
|
* @brief Initiate object tracking.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_tracking_initiate();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Terminate object tracking.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_tracking_terminate();
|
|
|
|
|
2021-04-23 19:21:12 +03:00
|
|
|
/**
|
2022-03-07 20:07:10 +03:00
|
|
|
* @brief Initialize an ebpf_core_object_t structure.
|
2021-04-23 19:21:12 +03:00
|
|
|
*
|
2022-03-07 20:07:10 +03:00
|
|
|
* @param[in,out] object ebpf_core_object_t structure to initialize.
|
2021-04-23 19:21:12 +03:00
|
|
|
* @param[in] object_type The type of the object.
|
|
|
|
* @param[in] free_function The function used to free the object.
|
2021-08-24 04:46:24 +03:00
|
|
|
* @param[in] get_program_type_function The function used to get a program type, or NULL. Each program
|
|
|
|
* has a program type, and hence so do maps that can contain programs, whether directly (like
|
|
|
|
* BPF_MAP_TYPE_PROG_ARRAY) or indirectly (like BPF_MAP_TYPE_ARRAY_OF_MAPS containing a BPF_MAP_TYPE_PROG_ARRAY).
|
2021-09-07 19:54:08 +03:00
|
|
|
* @retval EBPF_SUCCESS Initialization succeeded.
|
|
|
|
* @retval EBPF_NO_MEMORY Could not insert into the tracking table.
|
2021-04-23 19:21:12 +03:00
|
|
|
*/
|
2021-09-07 19:54:08 +03:00
|
|
|
ebpf_result_t
|
2021-08-24 04:46:24 +03:00
|
|
|
ebpf_object_initialize(
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_core_object_t* object,
|
2021-08-24 04:46:24 +03:00
|
|
|
ebpf_object_type_t object_type,
|
|
|
|
ebpf_free_object_t free_function,
|
|
|
|
ebpf_object_get_program_type_t get_program_type_function);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Acquire a reference to this object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object on which to acquire a reference.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_object_acquire_reference(ebpf_core_object_t* object);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Release a reference on this object. If the reference count reaches
|
|
|
|
* zero, the free_function is invoked on the object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object on which to release a reference.
|
|
|
|
*/
|
|
|
|
void
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_object_release_reference(ebpf_core_object_t* object);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Query the stored type of the object.
|
|
|
|
*
|
|
|
|
* @param[in] object Object to be queried.
|
|
|
|
* @return Type of the object.
|
|
|
|
*/
|
|
|
|
ebpf_object_type_t
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_object_get_type(ebpf_core_object_t* object);
|
2021-04-23 19:21:12 +03:00
|
|
|
|
2021-04-30 22:55:21 +03:00
|
|
|
/**
|
|
|
|
* @brief Find the next object that is of this type and acquire reference
|
|
|
|
* on it.
|
|
|
|
*
|
|
|
|
* @param[in] previous_object Previous object that was found. Can be NULL
|
|
|
|
* to find first object.
|
|
|
|
* @param[in] type Type of object to find.
|
|
|
|
* @param[out] next_object Pointer to memory containing the next object or
|
|
|
|
* NULL if there are no more objects of that type.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ebpf_object_reference_next_object(
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_core_object_t* previous_object, ebpf_object_type_t type, ebpf_core_object_t** next_object);
|
2021-04-30 22:55:21 +03:00
|
|
|
|
2021-09-07 19:54:08 +03:00
|
|
|
/**
|
|
|
|
* @brief Find an ID in the ID table, verify the type matches,
|
|
|
|
* acquire a reference to the object and return it.
|
|
|
|
*
|
|
|
|
* @param[in] id ID to find in table.
|
|
|
|
* @param[in] object_type Object type to match.
|
|
|
|
* @param[out] object Pointer to memory that contains object success.
|
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_KEY_NOT_FOUND The provided ID is not valid.
|
|
|
|
*/
|
|
|
|
ebpf_result_t
|
2022-03-07 20:07:10 +03:00
|
|
|
ebpf_object_reference_by_id(ebpf_id_t id, ebpf_object_type_t object_type, _Outptr_ ebpf_core_object_t** object);
|
2021-09-07 19:54:08 +03:00
|
|
|
|
2021-09-10 02:02:42 +03:00
|
|
|
/**
|
|
|
|
* @brief Find an ID in the ID table, verify the type matches,
|
|
|
|
* and release a reference previously acquired via
|
|
|
|
* ebpf_object_reference_id.
|
|
|
|
*
|
|
|
|
* @param[in] id ID to find in table.
|
|
|
|
* @param[in] object_type Object type to match.
|
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_KEY_NOT_FOUND The provided ID is not valid.
|
|
|
|
*/
|
|
|
|
ebpf_result_t
|
|
|
|
ebpf_object_dereference_by_id(ebpf_id_t id, ebpf_object_type_t object_type);
|
|
|
|
|
2021-09-07 19:54:08 +03:00
|
|
|
/**
|
|
|
|
* @brief Find the object of a given type with the next ID greater than a given ID.
|
|
|
|
*
|
|
|
|
* @param[in] start_id ID to look for an ID after. The start_id
|
|
|
|
* need not exist.
|
|
|
|
* @retval EBPF_SUCCESS The operation was successful.
|
|
|
|
* @retval EBPF_NO_MORE_KEYS No such IDs found.
|
|
|
|
*/
|
|
|
|
ebpf_result_t
|
|
|
|
ebpf_object_get_next_id(ebpf_id_t start_id, ebpf_object_type_t object_type, _Out_ ebpf_id_t* next_id);
|
|
|
|
|
2021-04-23 19:21:12 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|