|
BSL v1.0.0 - 16.g9d98179
AMMOS Bundle Protocol Security Library (BSL)
|
Definitions for Agent initialization. More...
#include <BPSecLib_Public.h>#include <BPSecLib_Private.h>#include <backend/UtilDefs_SeqReadWrite.h>#include <security_context/DefaultSecContext.h>#include <policy_provider/SamplePolicyProvider.h>#include <assert.h>#include <errno.h>#include <poll.h>#include "agent.h"#include "log.h"#include "eid.h"#include "eidpat.h"#include "encode.h"#include "decode.h"#include "policy_config.h"#include "policy_registry.h"
Include dependency graph for agent.c:Data Structures | |
| struct | MockBPA_BTSD_Data_s |
| Internal state for reader and writer. More... | |
Macros | |
| #define | TLM_COUNTER_FMT "7" PRIu64 |
| Display form for counters. | |
Functions | |
| static int | MockBPA_GetEid (void *user_data, BSL_HostEID_t *result_eid) |
| int | MockBPA_GetBundleMetadata (const BSL_BundleRef_t *bundle_ref, BSL_PrimaryBlock_t *result_primary_block) |
| int | MockBPA_GetBlockMetadata (const BSL_BundleRef_t *bundle_ref, uint64_t block_num, BSL_CanonicalBlock_t *result_canonical_block) |
| int | MockBPA_ReallocBTSD (BSL_BundleRef_t *bundle_ref, uint64_t block_num, size_t bytesize) |
| static int | MockBPA_ReadBTSD_Read (void *user_data, void *buf, size_t *bufsize) |
| static void | MockBPA_ReadBTSD_Deinit (void *user_data) |
| static struct BSL_SeqReader_s * | MockBPA_ReadBTSD (const BSL_BundleRef_t *bundle_ref, uint64_t block_num) |
| static int | MockBPA_WriteBTSD_Write (void *user_data, const void *buf, size_t size) |
| static void | MockBPA_WriteBTSD_Deinit (void *user_data) |
| static struct BSL_SeqWriter_s * | MockBPA_WriteBTSD (BSL_BundleRef_t *bundle_ref, uint64_t block_num, size_t total_size) |
| int | MockBPA_CreateBlock (BSL_BundleRef_t *bundle_ref, uint64_t block_type_code, uint64_t *result_block_num) |
| int | MockBPA_RemoveBlock (BSL_BundleRef_t *bundle_ref, uint64_t block_num) |
| int | MockBPA_DeleteBundle (BSL_BundleRef_t *bundle_ref, BSL_ReasonCode_t reason) |
| BSL_HostDescriptors_t | MockBPA_Agent_Descriptors (MockBPA_Agent_t *agent) |
| Get host descriptors without a specific agent. | |
| int | MockBPA_Agent_Init (MockBPA_Agent_t *agent) |
| Initialize and register this mock BPA for the current process. | |
| void | MockBPA_Agent_Deinit (MockBPA_Agent_t *agent) |
| Clean up the mock BPA for the current process. | |
| static int | bind_udp (int *sock, const struct sockaddr_in *addr) |
| static void | MockBPA_Agent_DumpTelemetry (MockBPA_Agent_t *agent) |
| Aggregate and log telemetry from all BSL contexts. | |
| static int | MockBPA_Agent_process (MockBPA_Agent_t *agent, MockBPA_Agent_BSL_Ctx_t *ctx, BSL_PolicyLocation_e loc, MockBPA_Bundle_t *bundle) |
| Process a single bundle at one of the interaction points. | |
| static void * | MockBPA_Agent_work_over_rx (void *arg) |
| static void * | MockBPA_Agent_work_under_rx (void *arg) |
| static void * | MockBPA_Agent_work_deliver (void *arg) |
| static void * | MockBPA_Agent_work_forward (void *arg) |
| int | MockBPA_Agent_Start (MockBPA_Agent_t *agent) |
| Start worker threads. | |
| void | MockBPA_Agent_Stop (MockBPA_Agent_t *agent) |
| Stop an agent from another thread or a signal handler. | |
| int | MockBPA_Agent_Exec (MockBPA_Agent_t *agent) |
| Execute the main thread activity while work threads are running. | |
| int | MockBPA_Agent_Join (MockBPA_Agent_t *agent) |
| Wait for and join worker threads. | |
Definitions for Agent initialization.
| #define TLM_COUNTER_FMT "7" PRIu64 |
Display form for counters.
|
static |
References BSL_LOG_DEBUG, and BSL_LOG_ERR.
Referenced by MockBPA_Agent_Exec().
| void MockBPA_Agent_Deinit | ( | MockBPA_Agent_t * | agent | ) |
Clean up the mock BPA for the current process.
| [out] | agent | The agent to deinitialize. |
References agent, MockBPA_Agent_t::appin, MockBPA_Agent_t::appout, BSL_API_DeinitLib(), BSL_free(), BSL_LOG_ERR, MockBPA_Agent_t::clin, MockBPA_Agent_t::clout, ctx, MockBPA_Agent_t::deliver, MockBPA_Agent_t::forward, MockBPA_Agent_t::over_rx, MockBPA_Agent_t::over_tx, MockBPA_Agent_t::tx_notify_r, MockBPA_Agent_t::tx_notify_w, MockBPA_Agent_t::under_rx, and MockBPA_Agent_t::under_tx.
Referenced by main().
| BSL_HostDescriptors_t MockBPA_Agent_Descriptors | ( | MockBPA_Agent_t * | agent | ) |
Get host descriptors without a specific agent.
| [in] | agent | The agent to associate as user data. |
References agent, bsl_mock_decode_eid(), bsl_mock_encode_eid(), mock_bpa_eid_from_text(), mock_bpa_eidpat_deinit(), mock_bpa_eidpat_from_text(), mock_bpa_eidpat_init(), mock_bpa_eidpat_match(), mock_bpa_LogEvent(), mock_bpa_LogIsEnabledFor(), MockBPA_CreateBlock(), MockBPA_DeleteBundle(), MockBPA_EID_Deinit(), MockBPA_EID_Init(), MockBPA_GetBlockMetadata(), MockBPA_GetBundleMetadata(), MockBPA_GetEid(), MockBPA_ReadBTSD(), MockBPA_ReallocBTSD(), MockBPA_RemoveBlock(), MockBPA_WriteBTSD(), and BSL_HostDescriptors_t::user_data.
Referenced by LLVMFuzzerInitialize(), main(), and suiteSetUp().
|
static |
Aggregate and log telemetry from all BSL contexts.
References agent, MockBPA_Agent_t::appin, MockBPA_Agent_t::appout, BSL_LibCtx_AccumulateTlmCounters(), BSL_LOG_CRIT, BSL_LOG_ERR, BSL_LOG_INFO, BSL_TLM_ASB_DECODE_BYTES, BSL_TLM_ASB_DECODE_COUNT, BSL_TLM_ASB_ENCODE_BYTES, BSL_TLM_ASB_ENCODE_COUNT, BSL_TLM_BUNDLE_INSPECTED_COUNT, BSL_TLM_COUNTERS_ZERO, BSL_TLM_SECOP_ACCEPTOR_COUNT, BSL_TLM_SECOP_FAIL_COUNT, BSL_TLM_SECOP_SOURCE_COUNT, BSL_TLM_SECOP_VERIFIER_COUNT, BSL_TLM_TOTAL_COUNT, MockBPA_Agent_t::clin, MockBPA_Agent_t::clout, BSL_TlmCounters_t::counters, ctx, and TLM_COUNTER_FMT.
Referenced by MockBPA_Agent_process().
| int MockBPA_Agent_Exec | ( | MockBPA_Agent_t * | agent | ) |
Execute the main thread activity while work threads are running.
This will block until MockBPA_Agent_Stop() is called.
| [out] | agent | The agent to work for. |
References agent, MockBPA_Agent_t::app_addr, bind_udp(), BSL_Data_AppendFrom(), BSL_LOG_DEBUG, BSL_LOG_ERR, BSL_LOG_INFO, buf, mock_bpa_ctr_t::encoded, BSL_Data_t::len, mock_bpa_ctr_deinit(), mock_bpa_ctr_init(), MockBPA_Agent_t::over_addr, MockBPA_Agent_t::over_rx, MockBPA_Agent_t::over_tx, BSL_Data_t::ptr, MockBPA_Agent_t::router_addr, MockBPA_Agent_t::stop_state, MockBPA_Agent_t::tx_notify_r, MockBPA_Agent_t::under_addr, MockBPA_Agent_t::under_rx, and MockBPA_Agent_t::under_tx.
Referenced by main().
| int MockBPA_Agent_Init | ( | MockBPA_Agent_t * | agent | ) |
Initialize and register this mock BPA for the current process.
| [out] | agent | The agent to initialize. |
References agent, MockBPA_Agent_t::app_addr, MockBPA_Agent_t::appin, MockBPA_Agent_t::appout, ASSERT_PROPERTY, MockBPA_Agent_BSL_Ctx_t::bsl, BSL_API_InitLib(), BSL_API_RegisterPolicyProvider(), BSL_API_RegisterSecurityContext(), BSL_calloc(), BSL_LibCtx_Sizeof(), BSL_LOG_ERR, BSL_SUCCESS, BSLP_Deinit(), BSLP_FinalizePolicy(), BSLP_QueryPolicy(), BSLX_BCB_Execute(), BSLX_BCB_Validate(), BSLX_BIB_Execute(), BSLX_BIB_Validate(), MockBPA_Agent_t::clin, MockBPA_Agent_t::clout, ctx, MockBPA_Agent_t::deliver, MockBPA_Agent_t::forward, MOCKBPA_DATA_QUEUE_SIZE, MockBPA_Agent_t::over_addr, MockBPA_Agent_t::over_rx, MockBPA_Agent_t::over_tx, MockBPA_Agent_BSL_Ctx_t::policy, BSLP_PolicyProvider_t::pp_id, MockBPA_Agent_t::router_addr, MockBPA_Agent_t::stop_state, MockBPA_Agent_t::tx_notify_r, MockBPA_Agent_t::tx_notify_w, MockBPA_Agent_t::under_addr, MockBPA_Agent_t::under_rx, and MockBPA_Agent_t::under_tx.
Referenced by main().
| int MockBPA_Agent_Join | ( | MockBPA_Agent_t * | agent | ) |
Wait for and join worker threads.
| [out] | agent | The agent to start threads for. |
References agent, BSL_LOG_ERR, BSL_LOG_INFO, MockBPA_Agent_t::deliver, MockBPA_Agent_t::forward, mock_bpa_ctr_init(), MockBPA_Agent_t::over_rx, MockBPA_Agent_t::thr_deliver, MockBPA_Agent_t::thr_forward, MockBPA_Agent_t::thr_over_rx, MockBPA_Agent_t::thr_under_rx, and MockBPA_Agent_t::under_rx.
Referenced by main().
|
static |
Process a single bundle at one of the interaction points.
| [in] | agent | The agent state, which is not locked for the work thread. |
| [in,out] | bsl | The specific BSL instance to process with. |
| loc | The interaction point for policy use. | |
| [in,out] | bundle | The bundle to process. |
References agent, BSL_API_ApplySecurity(), BSL_API_QuerySecurity(), BSL_calloc(), BSL_free(), BSL_LOG_CRIT, BSL_LOG_ERR, BSL_LOG_INFO, BSL_SecurityActionSet_Deinit(), BSL_SecurityActionSet_Sizeof(), BSL_SecurityResponseSet_Sizeof(), ctx, BSL_BundleRef_t::data, and MockBPA_Agent_DumpTelemetry().
Referenced by MockBPA_Agent_work_deliver(), MockBPA_Agent_work_forward(), MockBPA_Agent_work_over_rx(), and MockBPA_Agent_work_under_rx().
| int MockBPA_Agent_Start | ( | MockBPA_Agent_t * | agent | ) |
Start worker threads.
| [out] | agent | The agent to start threads for. |
References agent, MockBPA_Agent_work_deliver(), MockBPA_Agent_work_forward(), MockBPA_Agent_work_over_rx(), MockBPA_Agent_work_under_rx(), MockBPA_Agent_t::thr_deliver, MockBPA_Agent_t::thr_forward, MockBPA_Agent_t::thr_over_rx, and MockBPA_Agent_t::thr_under_rx.
Referenced by main().
| void MockBPA_Agent_Stop | ( | MockBPA_Agent_t * | agent | ) |
Stop an agent from another thread or a signal handler.
| [in,out] | agent | The agent to set the stopping state on. |
References agent, BSL_LOG_ERR, buf, MockBPA_Agent_t::stop_state, and MockBPA_Agent_t::tx_notify_w.
Referenced by sig_stop().
|
static |
References agent, MockBPA_Agent_t::appout, BSL_LOG_ERR, BSL_LOG_INFO, BSL_POLICYLOCATION_APPOUT, buf, mock_bpa_ctr_t::bundle_ref, BSL_BundleRef_t::data, MockBPA_Agent_t::deliver, mock_bpa_ctr_t::encoded, BSL_Data_t::len, mock_bpa_ctr_deinit(), mock_bpa_encode(), MockBPA_Agent_process(), MockBPA_Agent_t::over_tx, MockBPA_Bundle_t::retain, and MockBPA_Agent_t::tx_notify_w.
Referenced by MockBPA_Agent_Start().
|
static |
References agent, BSL_LOG_ERR, BSL_LOG_INFO, BSL_POLICYLOCATION_CLOUT, buf, mock_bpa_ctr_t::bundle_ref, MockBPA_Agent_t::clout, BSL_BundleRef_t::data, mock_bpa_ctr_t::encoded, MockBPA_Agent_t::forward, BSL_Data_t::len, mock_bpa_ctr_deinit(), mock_bpa_encode(), MockBPA_Agent_process(), MockBPA_Bundle_t::retain, MockBPA_Agent_t::tx_notify_w, and MockBPA_Agent_t::under_tx.
Referenced by MockBPA_Agent_Start().
|
static |
References agent, MockBPA_Agent_t::appin, BSL_LOG_ERR, BSL_LOG_INFO, BSL_POLICYLOCATION_APPIN, mock_bpa_ctr_t::bundle_ref, BSL_BundleRef_t::data, MockBPA_Agent_t::deliver, mock_bpa_ctr_t::encoded, BSL_Data_t::len, mock_bpa_ctr_deinit(), mock_bpa_decode(), MockBPA_Agent_process(), MockBPA_Agent_t::over_rx, and MockBPA_Bundle_t::retain.
Referenced by MockBPA_Agent_Start().
|
static |
References agent, BSL_LOG_ERR, BSL_LOG_INFO, BSL_POLICYLOCATION_CLIN, mock_bpa_ctr_t::bundle_ref, MockBPA_Agent_t::clin, BSL_BundleRef_t::data, mock_bpa_ctr_t::encoded, MockBPA_Agent_t::forward, BSL_Data_t::len, mock_bpa_ctr_deinit(), mock_bpa_decode(), MockBPA_Agent_process(), MockBPA_Bundle_t::retain, and MockBPA_Agent_t::under_rx.
Referenced by MockBPA_Agent_Start().
| int MockBPA_CreateBlock | ( | BSL_BundleRef_t * | bundle_ref, |
| uint64_t | block_type_code, | ||
| uint64_t * | result_block_num | ||
| ) |
References MockBPA_CanonicalBlock_t::blk_num, MockBPA_CanonicalBlock_t::blk_type, MockBPA_Bundle_t::blocks, MockBPA_Bundle_t::blocks_num, MockBPA_CanonicalBlock_t::btsd, MockBPA_CanonicalBlock_t::btsd_len, MockBPA_CanonicalBlock_t::crc_type, BSL_BundleRef_t::data, and MockBPA_CanonicalBlock_t::flags.
Referenced by MockBPA_Agent_Descriptors().
| int MockBPA_DeleteBundle | ( | BSL_BundleRef_t * | bundle_ref, |
| BSL_ReasonCode_t | reason | ||
| ) |
References BSL_LOG_INFO, BSL_BundleRef_t::data, and MockBPA_Bundle_t::retain.
Referenced by MockBPA_Agent_Descriptors().
| int MockBPA_GetBlockMetadata | ( | const BSL_BundleRef_t * | bundle_ref, |
| uint64_t | block_num, | ||
| BSL_CanonicalBlock_t * | result_canonical_block | ||
| ) |
References MockBPA_CanonicalBlock_t::blk_num, MockBPA_CanonicalBlock_t::blk_type, BSL_CanonicalBlock_t::block_num, MockBPA_Bundle_t::blocks_num, BSL_CanonicalBlock_t::btsd_len, MockBPA_CanonicalBlock_t::btsd_len, BSL_CanonicalBlock_t::crc_type, MockBPA_CanonicalBlock_t::crc_type, BSL_BundleRef_t::data, BSL_CanonicalBlock_t::flags, MockBPA_CanonicalBlock_t::flags, and BSL_CanonicalBlock_t::type_code.
Referenced by MockBPA_Agent_Descriptors().
| int MockBPA_GetBundleMetadata | ( | const BSL_BundleRef_t * | bundle_ref, |
| BSL_PrimaryBlock_t * | result_primary_block | ||
| ) |
References MockBPA_PrimaryBlock_t::adu_length, MockBPA_CanonicalBlock_t::blk_num, BSL_PrimaryBlock_t::block_count, BSL_PrimaryBlock_t::block_numbers, MockBPA_Bundle_t::blocks, BSL_calloc(), BSL_Data_InitView(), MockBPA_CreationTimestamp_t::bundle_creation_time, MockBPA_PrimaryBlock_t::crc_type, BSL_BundleRef_t::data, MockBPA_PrimaryBlock_t::dest_eid, BSL_PrimaryBlock_t::encoded, MockBPA_PrimaryBlock_t::encoded, BSL_PrimaryBlock_t::field_adu_length, BSL_PrimaryBlock_t::field_bundle_creation_time, BSL_PrimaryBlock_t::field_crc_type, BSL_PrimaryBlock_t::field_dest_eid, BSL_PrimaryBlock_t::field_flags, BSL_PrimaryBlock_t::field_frag_offset, BSL_PrimaryBlock_t::field_lifetime, BSL_PrimaryBlock_t::field_report_to_eid, BSL_PrimaryBlock_t::field_seq_num, BSL_PrimaryBlock_t::field_src_node_id, BSL_PrimaryBlock_t::field_version, MockBPA_PrimaryBlock_t::flags, MockBPA_PrimaryBlock_t::frag_offset, BSL_Data_t::len, MockBPA_PrimaryBlock_t::lifetime, MockBPA_Bundle_t::primary_block, BSL_Data_t::ptr, MockBPA_PrimaryBlock_t::report_to_eid, MockBPA_CreationTimestamp_t::seq_num, MockBPA_PrimaryBlock_t::src_node_id, MockBPA_PrimaryBlock_t::timestamp, and MockBPA_PrimaryBlock_t::version.
Referenced by MockBPA_Agent_Descriptors().
|
static |
References mock_bpa_eid_from_text().
Referenced by MockBPA_Agent_Descriptors().
|
static |
References MockBPA_BTSD_Data_s::block, MockBPA_Bundle_t::blocks_num, BSL_calloc(), BSL_free(), MockBPA_CanonicalBlock_t::btsd, MockBPA_CanonicalBlock_t::btsd_len, BSL_BundleRef_t::data, MockBPA_BTSD_Data_s::file, MockBPA_ReadBTSD_Deinit(), MockBPA_ReadBTSD_Read(), MockBPA_BTSD_Data_s::ptr, and MockBPA_BTSD_Data_s::size.
Referenced by MockBPA_Agent_Descriptors().
|
static |
References ASSERT_ARG_NONNULL, ASSERT_PRECONDITION, BSL_free(), and MockBPA_BTSD_Data_s::file.
Referenced by MockBPA_ReadBTSD().
|
static |
References ASSERT_ARG_NONNULL, ASSERT_PRECONDITION, BSL_LOG_DEBUG, buf, CHK_ARG_NONNULL, and MockBPA_BTSD_Data_s::file.
Referenced by MockBPA_ReadBTSD().
| int MockBPA_ReallocBTSD | ( | BSL_BundleRef_t * | bundle_ref, |
| uint64_t | block_num, | ||
| size_t | bytesize | ||
| ) |
References MockBPA_Bundle_t::blocks_num, BSL_calloc(), BSL_realloc(), MockBPA_CanonicalBlock_t::btsd, MockBPA_CanonicalBlock_t::btsd_len, and BSL_BundleRef_t::data.
Referenced by MockBPA_Agent_Descriptors().
| int MockBPA_RemoveBlock | ( | BSL_BundleRef_t * | bundle_ref, |
| uint64_t | block_num | ||
| ) |
|
static |
References MockBPA_BTSD_Data_s::block, MockBPA_Bundle_t::blocks_num, BSL_calloc(), BSL_free(), BSL_LOG_DEBUG, BSL_BundleRef_t::data, MockBPA_BTSD_Data_s::file, MockBPA_WriteBTSD_Deinit(), MockBPA_WriteBTSD_Write(), MockBPA_BTSD_Data_s::ptr, and MockBPA_BTSD_Data_s::size.
Referenced by MockBPA_Agent_Descriptors().
|
static |
|
static |
References ASSERT_ARG_NONNULL, ASSERT_PRECONDITION, BSL_ERR_FAILURE, BSL_LOG_DEBUG, BSL_SUCCESS, buf, CHK_ARG_NONNULL, MockBPA_BTSD_Data_s::file, and MockBPA_BTSD_Data_s::size.
Referenced by MockBPA_WriteBTSD().