entry->proto == *proto;
}
+/**
+ * Find a list entry with given esa id.
+ */
+static bool sad_entry_match_esa_id(sad_entry_t * const entry,
+ const esa_id_type * const esa_id)
+{
+ return entry->esa_id == *esa_id;
+}
+
+/**
+ * Find a list entry with given reqid and different esa id.
+ */
+static bool sad_entry_match_other_esa(sad_entry_t * const entry,
+ const esa_id_type * const esa_id,
+ const u_int32_t * const reqid)
+{
+ return entry->reqid == *reqid &&
+ entry->esa_id != *esa_id;
+}
+
/**
* Compare two SAD entries for equality.
*/
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;
+ u_int32_t reqid;
+ status_t res;
+
+ this->mutex->lock(this->mutex);
+ res = this->data->find_first(this->data,
+ (linked_list_match_t)sad_entry_match_esa_id,
+ (void**)&entry, &esa_id);
+ if (res == SUCCESS && 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,
+ (linked_list_match_t)sad_entry_match_other_esa,
+ (void**)&entry, &esa_id, &reqid);
+ if (res == SUCCESS && 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 u_int32_t reqid,
const u_int32_t spi, const u_int8_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 u_int32_t spi, const u_int8_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, 42, 50),
+ "Error inserting SAD entry");
+ fail_unless(sad->insert(sad, 24, 54, addr, addr, 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, 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);