39 assert(strlen(self->name) <
sizeof(self->name));
47 assert(self->location > 0);
48 assert(self->dst_eid_pattern.
handle != NULL);
49 assert(self->src_eid_pattern.
handle != NULL);
50 assert(self->secsrc_eid_pattern.
handle != NULL);
57 assert(strlen(self->description) <
sizeof(self->description));
58 assert(self->params != NULL);
59 assert(BSL_SECROLE_ISVALID(self->role));
60 assert(self->sec_block_type > 0);
61 assert(self->context_id > 0);
63 assert(BSLP_PolicyPredicate_IsConsistent(self->predicate));
68static uint64_t get_target_block_id(
const BSL_BundleRef_t *bundle, uint64_t target_block_type)
70 uint64_t target_block_num = 0;
71 for (uint64_t block_index = 1; block_index < 100; block_index++)
76 if (test_block.
type_code == target_block_type)
78 target_block_num = block_index;
84 return target_block_num;
95 assert(BSLP_PolicyProvider_IsConsistent(self));
107 for (
size_t index = 0; index < self->rule_count && index < capacity; index++)
110 CHK_PROPERTY(BSLP_PolicyRule_IsConsistent(rule));
111 BSL_LOG_DEBUG(
"Evaluating against rule `%s`", rule->description);
120 uint64_t target_block_num = get_target_block_id(bundle, rule->target_block_type);
123 BSL_LOG_WARNING(
"Cannot find target block type = %lu", rule->target_block_type);
138 BSL_LOG_INFO(
"Created sec operation for rule `%s`", rule->description);
150 memset(self, 0,
sizeof(*self));
153void BSLP_Deinit(
void *user_data)
156 assert(BSLP_PolicyProvider_IsConsistent(self));
157 for (
size_t index = 0; index < self->rule_count; index++)
159 BSL_LOG_INFO(
"Sample Policy Provider deinit rule index %lu", index);
163 for (
size_t index = 0; index < self->predicate_count; index++)
165 BSLP_PolicyPredicate_Deinit(&self->predicates[index]);
167 memset(self, 0,
sizeof(*self));
175 assert(self != NULL);
176 memset(self, 0,
sizeof(*self));
178 self->location = location;
179 self->src_eid_pattern = src_eid_pattern;
180 self->secsrc_eid_pattern = secsrc_eid_pattern;
181 self->dst_eid_pattern = dst_eid_pattern;
183 assert(BSLP_PolicyPredicate_IsConsistent(self));
189 assert(BSLP_PolicyPredicate_IsConsistent(self));
191 bool is_location_match = location == self->location;
195 BSL_LOG_DEBUG(
"Match: location=%d, src_pattern=%d, dst_pattern=%d", is_location_match, is_src_pattern_match,
196 is_dst_pattern_match);
198 return is_location_match && is_src_pattern_match && is_dst_pattern_match;
215 assert(self != NULL);
216 memset(self, 0,
sizeof(*self));
217 strncpy(self->description, desc,
sizeof(self->description) - 1);
218 self->sec_block_type = sec_block_type;
219 self->target_block_type = target_block_type;
220 self->predicate = predicate;
221 self->context_id = context_id;
223 self->failure_action_code = failure_action_code;
227 assert(BSLP_PolicyRule_IsConsistent(self));
233 assert(BSLP_PolicyRule_IsConsistent(self));
234 BSL_LOG_INFO(
"BSLP_PolicyRule_Deinit: %s, nparams=%lu", self->description, self->nparams);
236 memset(self, 0,
sizeof(*self));
242 assert(BSLP_PolicyRule_IsConsistent(self));
245 assert(self->nparams < 10);
251 assert(BSLP_PolicyRule_IsConsistent(self));
257 CHK_ARG_NONNULL(sec_oper);
258 CHK_ARG_NONNULL(bundle);
259 CHK_PRECONDITION(BSLP_PolicyRule_IsConsistent(self));
270 uint64_t target_block_num = get_target_block_id(bundle, self->target_block_type);
273 BSL_LOG_WARNING(
"Cannot find target block type = %lu", self->target_block_type);
278 BSL_SecOper_Init(sec_oper, self->context_id, target_block_num, 0, self->sec_block_type, self->role,
279 self->failure_action_code);
282 for (
size_t index = 0; index < self->nparams; index++)
286 uint8_t *ptr = &((uint8_t *)(self->params))[offset];
289 BSL_LOG_INFO(
"Created sec operation for rule `%s`", self->description);
Single entry-point include file for all of the BPSec Lib (BSL) frontend API.
#define BSL_LOG_DEBUG(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
BSL_SecBlockType_e
RFC 9172-specified block type codes for BIB and BCB.
BSL_BundleBlockTypeCode_e
Block types using IANA-assigned code points from .
@ BSL_BLOCK_TYPE_PRIMARY
Primary block ID (a special case)
BSL_PolicyAction_e
Codes indicating the fate of a block if a security operation over it fails.
#define BSL_LOG_INFO(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
#define BSL_LOG_WARNING(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
BSL_SecRole_e
Security role of an operation.
#define BSL_LOG_ERR(...)
This is an overloaded member function, provided for convenience. It differs from the above function o...
@ BSL_ERR_SECURITY_CONTEXT_FAILED
Security Context errors start at 200.
@ BSL_SUCCESS
Placeholder for non-error code.
@ BSL_ERR_HOST_CALLBACK_FAILED
Callback to the host BPA returned a non-zero code.
BSL_PolicyLocation_e
Indicates where in the lifecycle of the BPA the bundle is querying for security policy.
int BSL_BundleCtx_GetBlockMetadata(const BSL_BundleRef_t *bundle, uint64_t block_num, BSL_CanonicalBlock_t *result_block)
Returns information about the bundle Canonical block.
bool BSL_HostEIDPattern_IsMatch(const BSL_HostEIDPattern_t *pat, const BSL_HostEID_t *eid)
Determine if an EID Pattern matches a specific EID.
void BSL_HostEIDPattern_Deinit(BSL_HostEIDPattern_t *pat)
De-initialize an abstract EID Pattern.
int BSL_BundleCtx_GetBundleMetadata(const BSL_BundleRef_t *bundle, BSL_PrimaryBlock_t *result_primary_block)
Calls the host interface to get a bundle primary block information.abort.
int BSLP_PolicyRule_EvaluateAsSecOper(const BSLP_PolicyRule_t *self, BSL_SecOper_t *sec_oper, const BSL_BundleRef_t *bundle, BSL_PolicyLocation_e location)
Critical function creating a security operation from a bundle and location.
int BSLP_PolicyRule_Init(BSLP_PolicyRule_t *self, const char *desc, BSLP_PolicyPredicate_t *predicate, uint64_t context_id, BSL_SecRole_e role, BSL_SecBlockType_e sec_block_type, BSL_BundleBlockTypeCode_e target_block_type, BSL_PolicyAction_e failure_action_code)
Initialize this policy rule.
bool BSLP_PolicyPredicate_IsMatch(const BSLP_PolicyPredicate_t *self, BSL_PolicyLocation_e location, BSL_HostEID_t src_eid, BSL_HostEID_t dst_eid)
Returns true if the given predicate matches the arguments.
void BSLP_PolicyRule_AddParam(BSLP_PolicyRule_t *self, const BSL_SecParam_t *param)
Include a BPSec parameter to this rule.
void BSLP_PolicyPredicate_Init(BSLP_PolicyPredicate_t *self, BSL_PolicyLocation_e location, BSL_HostEIDPattern_t src_eid_pattern, BSL_HostEIDPattern_t secsrc_eid_pattern, BSL_HostEIDPattern_t dst_eid_pattern)
Initialize this policy predicate.
int BSLP_QueryPolicy(const void *user_data, BSL_SecurityActionSet_t *output_action_set, const BSL_BundleRef_t *bundle, BSL_PolicyLocation_e location)
Note that criticality is HIGH.
void BSLP_PolicyRule_Deinit(BSLP_PolicyRule_t *self)
De-initialize, release any resources, and zero this struct.
Spec of locally-defined data structures.
void BSL_SecOper_Init(BSL_SecOper_t *self, uint64_t context_id, uint64_t target_block_num, uint64_t sec_block_num, BSL_SecBlockType_e sec_type, BSL_SecRole_e sec_role, BSL_PolicyAction_e failure_code)
Populate a pre-allocated Security Operation with the given values.
void BSL_SecOper_AppendParam(BSL_SecOper_t *self, const BSL_SecParam_t *param)
Add the given security parameter to this list of parameters.
size_t BSL_SecParam_Sizeof(void)
Return size of BSL_SecParam_t struct type.
bool BSL_SecParam_IsConsistent(const BSL_SecParam_t *self)
Return true if invariant conditions pass.
int BSL_SecurityActionSet_AppendSecOper(BSL_SecurityActionSet_t *self, const BSL_SecOper_t *sec_oper)
Append a security operation to the security action set.
size_t BSL_SecurityActionSet_Sizeof(void)
Returns size of the struct, helpful for dynamic allocation.
bool BSL_SecurityActionSet_IsConsistent(const BSL_SecurityActionSet_t *self)
Return true if internal sanity and consistency checks pass.
void BSL_SecurityActionSet_IncrError(BSL_SecurityActionSet_t *self)
Increment a security failure for this action set.
size_t BSL_SecurityActionSet_CountErrors(const BSL_SecurityActionSet_t *self)
Returns count of failures after processing this action set.
void BSL_SecurityActionSet_Init(BSL_SecurityActionSet_t *self)
Initialize a new security action set.
THE key function that matches a bundle against a rule to provide the output action and specific param...
Concrete definition of the BSL_PolicyProvider_t.
Represents a policy rule.
Reference to a Bundle owned and stored in the host BPA.
Structure containing parsed Canonical Block fields.
uint64_t type_code
CBOR-decoded block type code (should be > 0)
Reference to a EID pattern owned and stored in the BPA.
void * handle
Opaque pointer for BPA backend to use.
Opaque pointer to BPA-specific Endpoint ID storage.
Contains Bundle Primary Block fields and metadata.
BSL_HostEID_t field_src_node_id
Source in host BPA's internal representation of an EID.
BSL_HostEID_t field_dest_eid
Destination in host BPA's internal representation of an EID.
Contains the populated security operations for this bundle.