child-sa: Move unique mark allocation to a separate helper function
This aligns the code with unique interface ID allocation, which uses a helper function for the same purpose and mechanic as well.
This commit is contained in:
@@ -150,6 +150,34 @@ bool mark_from_string(const char *value, mark_op_t ops, mark_t *mark)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
void allocate_unique_marks(uint32_t *in, uint32_t *out)
|
||||
{
|
||||
static refcount_t unique_mark = 0;
|
||||
|
||||
if (MARK_IS_UNIQUE(*in) || MARK_IS_UNIQUE(*out))
|
||||
{
|
||||
refcount_t mark = 0;
|
||||
bool unique_dir = *in == MARK_UNIQUE_DIR ||
|
||||
*out == MARK_UNIQUE_DIR;
|
||||
|
||||
if (!unique_dir)
|
||||
{
|
||||
mark = ref_get(&unique_mark);
|
||||
}
|
||||
if (MARK_IS_UNIQUE(*in))
|
||||
{
|
||||
*in = unique_dir ? ref_get(&unique_mark) : mark;
|
||||
}
|
||||
if (MARK_IS_UNIQUE(*out))
|
||||
{
|
||||
*out = unique_dir ? ref_get(&unique_mark) : mark;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
|
||||
@@ -242,6 +242,18 @@ enum mark_op_t {
|
||||
*/
|
||||
bool mark_from_string(const char *value, mark_op_t ops, mark_t *mark);
|
||||
|
||||
/**
|
||||
* Allocate up to two unique marks depending on the given values.
|
||||
*
|
||||
* If the given values are MARK_UNIQUE, the values get replaced by a single
|
||||
* unique mark. If the given values are MARK_UNIQUE_DIR, the values get
|
||||
* replaced by a single unique mark for each direction.
|
||||
*
|
||||
* @param[out] in inbound interface ID
|
||||
* @param[out] out outbound interface ID
|
||||
*/
|
||||
void allocate_unique_marks(uint32_t *in, uint32_t *out);
|
||||
|
||||
/**
|
||||
* Special interface ID values to allocate a unique ID for each CHILD_SA/dir
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user