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:
Martin Willi
2024-02-16 10:42:43 +01:00
parent 4aac88fadd
commit dde40bcb9e
4 changed files with 81 additions and 22 deletions
@@ -1124,6 +1124,41 @@ START_TEST(test_mark_from_string)
}
END_TEST
/*******************************************************************************
* allocate_unique_marks
*/
static struct {
uint32_t in;
uint32_t out;
uint32_t exp_in;
uint32_t exp_out;
} unique_mark_data[] = {
{0, 0, 0, 0 },
{42, 42, 42, 42 },
{42, 1337, 42, 1337 },
/* each call increases the internal counter by 1 or 2*/
{MARK_UNIQUE, 42, 1, 42 },
{42, MARK_UNIQUE, 42, 2 },
{MARK_UNIQUE_DIR, 42, 3, 42 },
{42, MARK_UNIQUE_DIR, 42, 4 },
{MARK_UNIQUE, MARK_UNIQUE, 5, 5 },
{MARK_UNIQUE_DIR, MARK_UNIQUE, 6, 7 },
{MARK_UNIQUE, MARK_UNIQUE_DIR, 8, 9 },
{MARK_UNIQUE_DIR, MARK_UNIQUE_DIR, 10, 11 },
};
START_TEST(test_allocate_unique_marks)
{
uint32_t mark_in = unique_mark_data[_i].in,
mark_out = unique_mark_data[_i].out;
allocate_unique_marks(&mark_in, &mark_out);
ck_assert_int_eq(mark_in, unique_mark_data[_i].exp_in);
ck_assert_int_eq(mark_out, unique_mark_data[_i].exp_out);
}
END_TEST
/*******************************************************************************
* if_id_from_string
*/
@@ -1364,6 +1399,10 @@ Suite *utils_suite_create()
tcase_add_loop_test(tc, test_mark_from_string, 0, countof(mark_data));
suite_add_tcase(s, tc);
tc = tcase_create("allocate_unique_marks");
tcase_add_loop_test(tc, test_allocate_unique_marks, 0, countof(unique_mark_data));
suite_add_tcase(s, tc);
tc = tcase_create("if_id_from_string");
tcase_add_loop_test(tc, test_if_id_from_string, 0, countof(if_id_data));
suite_add_tcase(s, tc);