entry->proto == *proto;
}
-CALLBACK(sad_entry_match_esa_id, bool,
- sad_entry_t * const entry, va_list args)
-{
- const esa_id_type *esa_id;
-
- VA_ARGS_VGET(args, esa_id);
- return entry->esa_id == *esa_id;
-}
-
-CALLBACK(sad_entry_match_other_esa, bool,
- sad_entry_t * const entry, va_list args)
-{
- const esa_id_type *esa_id;
- const uint32_t *reqid;
-
- VA_ARGS_VGET(args, esa_id, reqid);
- return entry->reqid == *reqid &&
- entry->esa_id != *esa_id;
-}
-
CALLBACK(sad_entry_equal, bool,
sad_entry_t * const left, va_list args)
{
return id;
}
-METHOD(tkm_kernel_sad_t, get_other_esa_id, esa_id_type,
- private_tkm_kernel_sad_t * const this, const esa_id_type esa_id)
-{
- esa_id_type id = 0;
- sad_entry_t *entry = NULL;
- uint32_t reqid;
- bool res;
-
- this->mutex->lock(this->mutex);
- res = this->data->find_first(this->data, sad_entry_match_esa_id,
- (void**)&entry, &esa_id);
- if (res && entry)
- {
- reqid = entry->reqid;
- }
- else
- {
- DBG3(DBG_KNL, "no SAD entry found for ESA id %llu", esa_id);
- this->mutex->unlock(this->mutex);
- return id;
- }
-
- res = this->data->find_first(this->data, sad_entry_match_other_esa,
- (void**)&entry, &esa_id, &reqid);
- if (res && entry)
- {
- id = entry->esa_id;
- DBG3(DBG_KNL, "returning ESA id %llu of other SAD entry with reqid %u",
- id, reqid);
- }
- this->mutex->unlock(this->mutex);
- return id;
-}
-
METHOD(tkm_kernel_sad_t, get_dst_host, host_t *,
private_tkm_kernel_sad_t * const this, const uint32_t reqid,
const uint32_t spi, const uint8_t proto)
.public = {
.insert = _insert,
.get_esa_id = _get_esa_id,
- .get_other_esa_id = _get_other_esa_id,
.get_dst_host = _get_dst_host,
.remove = __remove,
.destroy = _destroy,
const host_t * const src, const host_t * const dst,
const uint32_t spi, const uint8_t proto);
- /**
- * Get ESA id for entry associated with same security policy as the
- * specified ESA.
- *
- * @param esa_id id of ESA identifying the security policy
- * @return ESA id of entry if found, 0 otherwise
- */
- esa_id_type (*get_other_esa_id)(tkm_kernel_sad_t * const this,
- const esa_id_type esa_id);
-
/**
* Get destination host for entry with given parameters.
*
}
END_TEST
-START_TEST(test_get_other_esa_id)
-{
- host_t *addr = host_create_from_string("127.0.0.1", 1024);
- tkm_kernel_sad_t *sad = tkm_kernel_sad_create();
- fail_unless(sad->insert(sad, 23, 54, addr, addr, 27, 42, 50),
- "Error inserting SAD entry");
- fail_unless(sad->insert(sad, 24, 54, addr, addr, 27, 42, 50),
- "Error inserting SAD entry");
- fail_unless(sad->get_other_esa_id(sad, 23) == 24,
- "Error getting other esa id");
- sad->destroy(sad);
- addr->destroy(addr);
-}
-END_TEST
-
-START_TEST(test_get_other_esa_id_nonexistent)
-{
- host_t *addr = host_create_from_string("127.0.0.1", 1024);
- tkm_kernel_sad_t *sad = tkm_kernel_sad_create();
- fail_unless(sad->get_other_esa_id(sad, 1) == 0,
- "Got other esa id for nonexistent SAD entry");
- fail_unless(sad->insert(sad, 23, 54, addr, addr, 27, 42, 50),
- "Error inserting SAD entry");
- fail_unless(sad->get_other_esa_id(sad, 23) == 0,
- "Got own esa id");
-
- sad->destroy(sad);
- addr->destroy(addr);
-}
-END_TEST
-
START_TEST(test_get_dst_host)
{
host_t *addr = host_create_from_string("127.0.0.1", 1024);
tcase_add_test(tc, test_get_esa_id_nonexistent);
suite_add_tcase(s, tc);
- tc = tcase_create("get_other_esa_id");
- tcase_add_test(tc, test_get_other_esa_id);
- tcase_add_test(tc, test_get_other_esa_id_nonexistent);
- suite_add_tcase(s, tc);
-
tc = tcase_create("get_dst_host");
tcase_add_test(tc, test_get_dst_host);
tcase_add_test(tc, test_get_dst_host_nonexistent);