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:
@@ -58,19 +58,30 @@ METHOD(listener_t, child_updown, bool,
|
||||
bool up)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
traffic_selector_t *ts;
|
||||
entry_t *entry;
|
||||
|
||||
if (up)
|
||||
{
|
||||
INIT(entry,
|
||||
.local = child_sa->get_traffic_selectors(child_sa, TRUE),
|
||||
.remote = child_sa->get_traffic_selectors(child_sa, FALSE),
|
||||
.local = linked_list_create(),
|
||||
.remote = linked_list_create(),
|
||||
.reqid = child_sa->get_reqid(child_sa),
|
||||
);
|
||||
entry->local = entry->local->clone_offset(entry->local,
|
||||
offsetof(traffic_selector_t, clone));
|
||||
entry->remote = entry->remote->clone_offset(entry->remote,
|
||||
offsetof(traffic_selector_t, clone));
|
||||
|
||||
enumerator = child_sa->create_ts_enumerator(child_sa, TRUE);
|
||||
while (enumerator->enumerate(enumerator, &ts))
|
||||
{
|
||||
entry->local->insert_last(entry->local, ts->clone(ts));
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
enumerator = child_sa->create_ts_enumerator(child_sa, FALSE);
|
||||
while (enumerator->enumerate(enumerator, &ts))
|
||||
{
|
||||
entry->remote->insert_last(entry->remote, ts->clone(ts));
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
this->lock->write_lock(this->lock);
|
||||
this->entries->insert_last(this->entries, entry);
|
||||
@@ -160,4 +171,3 @@ farp_listener_t *farp_listener_create()
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -103,18 +103,22 @@ METHOD(listener_t, child_keys, bool,
|
||||
chunk_clear(&secret);
|
||||
}
|
||||
|
||||
local_ts = child_sa->get_traffic_selectors(child_sa, TRUE);
|
||||
enumerator = local_ts->create_enumerator(local_ts);
|
||||
local_ts = linked_list_create();
|
||||
remote_ts = linked_list_create();
|
||||
|
||||
enumerator = child_sa->create_ts_enumerator(child_sa, TRUE);
|
||||
while (enumerator->enumerate(enumerator, &ts))
|
||||
{
|
||||
m->add_attribute(m, HA_LOCAL_TS, ts);
|
||||
local_ts->insert_last(local_ts, ts);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
remote_ts = child_sa->get_traffic_selectors(child_sa, FALSE);
|
||||
enumerator = remote_ts->create_enumerator(remote_ts);
|
||||
|
||||
enumerator = child_sa->create_ts_enumerator(child_sa, FALSE);
|
||||
while (enumerator->enumerate(enumerator, &ts))
|
||||
{
|
||||
m->add_attribute(m, HA_REMOTE_TS, ts);
|
||||
remote_ts->insert_last(remote_ts, ts);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
@@ -128,6 +132,9 @@ METHOD(listener_t, child_keys, bool,
|
||||
seg_i, this->segments->is_active(this->segments, seg_i) ? "*" : "",
|
||||
seg_o, this->segments->is_active(this->segments, seg_o) ? "*" : "");
|
||||
|
||||
local_ts->destroy(local_ts);
|
||||
remote_ts->destroy(remote_ts);
|
||||
|
||||
this->socket->push(this->socket, m);
|
||||
m->destroy(m);
|
||||
|
||||
@@ -195,4 +202,3 @@ ha_child_t *ha_child_create(ha_socket_t *socket, ha_tunnel_t *tunnel,
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
@@ -165,8 +165,10 @@ static void write_childend(xmlTextWriterPtr writer, child_sa_t *child, bool loca
|
||||
|
||||
xmlTextWriterWriteFormatElement(writer, "spi", "%x",
|
||||
htonl(child->get_spi(child, local)));
|
||||
list = child->get_traffic_selectors(child, local);
|
||||
list = linked_list_create_from_enumerator(
|
||||
child->create_ts_enumerator(child, local));
|
||||
write_networks(writer, "networks", list);
|
||||
list->destroy(list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -207,8 +207,10 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
|
||||
time_t use_in, use_out, rekey, now;
|
||||
u_int64_t bytes_in, bytes_out, packets_in, packets_out;
|
||||
proposal_t *proposal;
|
||||
child_cfg_t *config = child_sa->get_config(child_sa);
|
||||
linked_list_t *my_ts, *other_ts;
|
||||
child_cfg_t *config;
|
||||
|
||||
config = child_sa->get_config(child_sa);
|
||||
now = time_monotonic(NULL);
|
||||
|
||||
fprintf(out, "%12s{%d}: %N, %N%s",
|
||||
@@ -319,10 +321,15 @@ static void log_child_sa(FILE *out, child_sa_t *child_sa, bool all)
|
||||
fprintf(out, ", expires in %V", &now, &rekey);
|
||||
}
|
||||
|
||||
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));
|
||||
fprintf(out, "\n%12s{%d}: %#R=== %#R\n",
|
||||
child_sa->get_name(child_sa), child_sa->get_reqid(child_sa),
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -72,6 +72,7 @@ static void write_fifo(private_uci_control_t *this, char *format, ...)
|
||||
static void status(private_uci_control_t *this, char *name)
|
||||
{
|
||||
enumerator_t *configs, *sas, *children;
|
||||
linked_list_t *list;
|
||||
ike_sa_t *ike_sa;
|
||||
child_sa_t *child_sa;
|
||||
peer_cfg_t *peer_cfg;
|
||||
@@ -108,8 +109,10 @@ static void status(private_uci_control_t *this, char *name)
|
||||
children = ike_sa->create_child_sa_enumerator(ike_sa);
|
||||
while (children->enumerate(children, (void**)&child_sa))
|
||||
{
|
||||
fprintf(out, "%#R",
|
||||
child_sa->get_traffic_selectors(child_sa, FALSE));
|
||||
list = linked_list_create_from_enumerator(
|
||||
child_sa->create_ts_enumerator(child_sa, FALSE));
|
||||
fprintf(out, "%#R", list);
|
||||
list->destroy(list);
|
||||
}
|
||||
children->destroy(children);
|
||||
fprintf(out, "\n");
|
||||
@@ -296,4 +299,3 @@ uci_control_t *uci_control_create()
|
||||
}
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user