child-sa: replace traffic selector lists by arrays
Saves up to another 0.5KB of memory per CHILD_SA.
This commit is contained in:
+19
-18
@@ -25,6 +25,7 @@
|
||||
|
||||
#include <hydra.h>
|
||||
#include <daemon.h>
|
||||
#include <collections/array.h>
|
||||
|
||||
ENUM(child_sa_state_names, CHILD_CREATED, CHILD_DESTROYING,
|
||||
"CREATED",
|
||||
@@ -79,14 +80,14 @@ struct private_child_sa_t {
|
||||
u_int16_t other_cpi;
|
||||
|
||||
/**
|
||||
* List for local traffic selectors
|
||||
* Array for local traffic selectors
|
||||
*/
|
||||
linked_list_t *my_ts;
|
||||
array_t *my_ts;
|
||||
|
||||
/**
|
||||
* List for remote traffic selectors
|
||||
* Array for remote traffic selectors
|
||||
*/
|
||||
linked_list_t *other_ts;
|
||||
array_t *other_ts;
|
||||
|
||||
/**
|
||||
* Protocol used to protect this SA, ESP|AH
|
||||
@@ -336,9 +337,9 @@ METHOD(child_sa_t, create_ts_enumerator, enumerator_t*,
|
||||
{
|
||||
if (local)
|
||||
{
|
||||
return this->my_ts->create_enumerator(this->my_ts);
|
||||
return array_create_enumerator(this->my_ts);
|
||||
}
|
||||
return this->other_ts->create_enumerator(this->other_ts);
|
||||
return array_create_enumerator(this->other_ts);
|
||||
}
|
||||
|
||||
typedef struct policy_enumerator_t policy_enumerator_t;
|
||||
@@ -353,8 +354,8 @@ struct policy_enumerator_t {
|
||||
enumerator_t *mine;
|
||||
/** enumerator over others TS */
|
||||
enumerator_t *other;
|
||||
/** list of others TS, to recreate enumerator */
|
||||
linked_list_t *list;
|
||||
/** array of others TS, to recreate enumerator */
|
||||
array_t *array;
|
||||
/** currently enumerating TS for "me" side */
|
||||
traffic_selector_t *ts;
|
||||
};
|
||||
@@ -370,7 +371,7 @@ METHOD(enumerator_t, policy_enumerate, bool,
|
||||
if (!this->other->enumerate(this->other, &other_ts))
|
||||
{ /* end of others list, restart with new of mine */
|
||||
this->other->destroy(this->other);
|
||||
this->other = this->list->create_enumerator(this->list);
|
||||
this->other = array_create_enumerator(this->array);
|
||||
this->ts = NULL;
|
||||
continue;
|
||||
}
|
||||
@@ -409,9 +410,9 @@ METHOD(child_sa_t, create_policy_enumerator, enumerator_t*,
|
||||
.enumerate = (void*)_policy_enumerate,
|
||||
.destroy = _policy_destroy,
|
||||
},
|
||||
.mine = this->my_ts->create_enumerator(this->my_ts),
|
||||
.other = this->other_ts->create_enumerator(this->other_ts),
|
||||
.list = this->other_ts,
|
||||
.mine = array_create_enumerator(this->my_ts),
|
||||
.other = array_create_enumerator(this->other_ts),
|
||||
.array = this->other_ts,
|
||||
.ts = NULL,
|
||||
);
|
||||
|
||||
@@ -776,13 +777,13 @@ METHOD(child_sa_t, add_policies, status_t,
|
||||
enumerator = my_ts_list->create_enumerator(my_ts_list);
|
||||
while (enumerator->enumerate(enumerator, &my_ts))
|
||||
{
|
||||
this->my_ts->insert_last(this->my_ts, my_ts->clone(my_ts));
|
||||
array_insert(this->my_ts, ARRAY_TAIL, my_ts->clone(my_ts));
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
enumerator = other_ts_list->create_enumerator(other_ts_list);
|
||||
while (enumerator->enumerate(enumerator, &other_ts))
|
||||
{
|
||||
this->other_ts->insert_last(this->other_ts, other_ts->clone(other_ts));
|
||||
array_insert(this->other_ts, ARRAY_TAIL, other_ts->clone(other_ts));
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
@@ -1073,8 +1074,8 @@ METHOD(child_sa_t, destroy, void,
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
this->my_ts->destroy_offset(this->my_ts, offsetof(traffic_selector_t, destroy));
|
||||
this->other_ts->destroy_offset(this->other_ts, offsetof(traffic_selector_t, destroy));
|
||||
array_destroy_offset(this->my_ts, offsetof(traffic_selector_t, destroy));
|
||||
array_destroy_offset(this->other_ts, offsetof(traffic_selector_t, destroy));
|
||||
this->my_addr->destroy(this->my_addr);
|
||||
this->other_addr->destroy(this->other_addr);
|
||||
DESTROY_IF(this->proposal);
|
||||
@@ -1130,8 +1131,8 @@ child_sa_t * child_sa_create(host_t *me, host_t* other,
|
||||
.encap = encap,
|
||||
.ipcomp = IPCOMP_NONE,
|
||||
.state = CHILD_CREATED,
|
||||
.my_ts = linked_list_create(),
|
||||
.other_ts = linked_list_create(),
|
||||
.my_ts = array_create(0, 0),
|
||||
.other_ts = array_create(0, 0),
|
||||
.protocol = PROTO_NONE,
|
||||
.mode = MODE_TUNNEL,
|
||||
.close_action = config->get_close_action(config),
|
||||
|
||||
Reference in New Issue
Block a user