child-sa: replace get_traffic_selectors() with create_ts_enumerator()

Not directly returning a linked list allows us to change the internals of
the CHILD_SA transparently.
This commit is contained in:
Martin Willi
2013-07-17 17:20:18 +02:00
parent 6207fadb6c
commit 553bb78730
12 changed files with 124 additions and 78 deletions
+18 -18
View File
@@ -1753,21 +1753,22 @@ METHOD(task_manager_t, queue_child, void,
/**
* Check if two CHILD_SAs have the same traffic selector
*/
static bool have_equal_ts(child_sa_t *a, child_sa_t *b, bool local)
static bool have_equal_ts(child_sa_t *child1, child_sa_t *child2, bool local)
{
linked_list_t *list;
traffic_selector_t *ts_a, *ts_b;
enumerator_t *e1, *e2;
traffic_selector_t *ts1, *ts2;
bool equal = FALSE;
list = a->get_traffic_selectors(a, local);
if (list->get_first(list, (void**)&ts_a) == SUCCESS)
e1 = child1->create_ts_enumerator(child1, local);
e2 = child2->create_ts_enumerator(child2, local);
if (e1->enumerate(e1, &ts1) && e2->enumerate(e2, &ts2))
{
list = b->get_traffic_selectors(b, local);
if (list->get_first(list, (void**)&ts_b) == SUCCESS)
{
return ts_a->equals(ts_a, ts_b);
}
equal = ts1->equals(ts1, ts2);
}
return FALSE;
e1->destroy(e1);
e1->destroy(e1);
return equal;
}
/**
@@ -1806,14 +1807,13 @@ static bool is_redundant(private_task_manager_t *this, child_sa_t *child_sa)
static traffic_selector_t* get_first_ts(child_sa_t *child_sa, bool local)
{
traffic_selector_t *ts = NULL;
linked_list_t *list;
enumerator_t *enumerator;
list = child_sa->get_traffic_selectors(child_sa, local);
if (list->get_first(list, (void**)&ts) == SUCCESS)
{
return ts;
}
return NULL;
enumerator = child_sa->create_ts_enumerator(child_sa, local);
enumerator->enumerate(enumerator, &ts);
enumerator->destroy(enumerator);
return ts;
}
METHOD(task_manager_t, queue_child_rekey, void,
+9 -5
View File
@@ -69,6 +69,7 @@ static bool delete_child(private_quick_delete_t *this,
{
u_int64_t bytes_in, bytes_out;
child_sa_t *child_sa;
linked_list_t *my_ts, *other_ts;
bool rekeyed;
child_sa = this->ike_sa->get_child_sa(this->ike_sa, protocol, spi, TRUE);
@@ -85,15 +86,17 @@ static bool delete_child(private_quick_delete_t *this,
rekeyed = child_sa->get_state(child_sa) == CHILD_REKEYING;
child_sa->set_state(child_sa, CHILD_DELETING);
my_ts = linked_list_create_from_enumerator(
child_sa->create_ts_enumerator(child_sa, TRUE));
other_ts = linked_list_create_from_enumerator(
child_sa->create_ts_enumerator(child_sa, FALSE));
if (this->expired)
{
DBG0(DBG_IKE, "closing expired CHILD_SA %s{%d} "
"with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
ntohl(child_sa->get_spi(child_sa, TRUE)),
ntohl(child_sa->get_spi(child_sa, FALSE)),
child_sa->get_traffic_selectors(child_sa, TRUE),
child_sa->get_traffic_selectors(child_sa, FALSE));
ntohl(child_sa->get_spi(child_sa, FALSE)), my_ts, other_ts);
}
else
{
@@ -105,9 +108,10 @@ static bool delete_child(private_quick_delete_t *this,
child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
ntohl(child_sa->get_spi(child_sa, TRUE)), bytes_in,
ntohl(child_sa->get_spi(child_sa, FALSE)), bytes_out,
child_sa->get_traffic_selectors(child_sa, TRUE),
child_sa->get_traffic_selectors(child_sa, FALSE));
my_ts, other_ts);
}
my_ts->destroy(my_ts);
other_ts->destroy(other_ts);
if (!rekeyed)
{
+10 -4
View File
@@ -259,7 +259,7 @@ static bool install(private_quick_mode_t *this)
{
status_t status, status_i, status_o;
chunk_t encr_i, encr_r, integ_i, integ_r;
linked_list_t *tsi, *tsr;
linked_list_t *tsi, *tsr, *my_ts, *other_ts;
child_sa_t *old = NULL;
this->child_sa->set_proposal(this->child_sa, this->proposal);
@@ -362,14 +362,20 @@ static bool install(private_quick_mode_t *this)
this->child_sa->set_state(this->child_sa, CHILD_INSTALLED);
this->ike_sa->add_child_sa(this->ike_sa, this->child_sa);
my_ts = linked_list_create_from_enumerator(
this->child_sa->create_ts_enumerator(this->child_sa, TRUE));
other_ts = linked_list_create_from_enumerator(
this->child_sa->create_ts_enumerator(this->child_sa, FALSE));
DBG0(DBG_IKE, "CHILD_SA %s{%d} established "
"with SPIs %.8x_i %.8x_o and TS %#R=== %#R",
this->child_sa->get_name(this->child_sa),
this->child_sa->get_reqid(this->child_sa),
ntohl(this->child_sa->get_spi(this->child_sa, TRUE)),
ntohl(this->child_sa->get_spi(this->child_sa, FALSE)),
this->child_sa->get_traffic_selectors(this->child_sa, TRUE),
this->child_sa->get_traffic_selectors(this->child_sa, FALSE));
ntohl(this->child_sa->get_spi(this->child_sa, FALSE)), my_ts, other_ts);
my_ts->destroy(my_ts);
other_ts->destroy(other_ts);
if (this->rekey)
{