ike_sa_manager enumerable, not iterable

This commit is contained in:
Martin Willi
2008-04-14 11:37:46 +00:00
parent b010310517
commit a593db5d35
10 changed files with 131 additions and 113 deletions
+3 -3
View File
@@ -116,9 +116,9 @@ static void nop(job_t *job)
/**
* Implementation of controller_t.create_ike_sa_iterator.
*/
static iterator_t* create_ike_sa_iterator(controller_t *this)
static enumerator_t* create_ike_sa_enumerator(controller_t *this)
{
return charon->ike_sa_manager->create_iterator(charon->ike_sa_manager);
return charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
}
/**
@@ -561,7 +561,7 @@ controller_t *controller_create(void)
{
private_controller_t *this = malloc_thing(private_controller_t);
this->public.create_ike_sa_iterator = (iterator_t*(*)(controller_t*))create_ike_sa_iterator;
this->public.create_ike_sa_enumerator = (enumerator_t*(*)(controller_t*))create_ike_sa_enumerator;
this->public.initiate = (status_t(*)(controller_t*,peer_cfg_t*,child_cfg_t*,bool(*)(void*,signal_t,level_t,ike_sa_t*,char*,va_list),void*))initiate;
this->public.terminate_ike = (status_t(*)(controller_t*,u_int32_t,controller_cb_t, void*))terminate_ike;
this->public.terminate_child = (status_t(*)(controller_t*,u_int32_t,controller_cb_t, void *param))terminate_child;
+4 -4
View File
@@ -64,14 +64,14 @@ typedef struct controller_t controller_t;
struct controller_t {
/**
* Create an iterator for all IKE_SAs.
* Create an enumerator for all IKE_SAs.
*
* The iterator blocks the IKE_SA manager until it gets destroyed. Do
* The enumerator blocks the IKE_SA manager until it gets destroyed. Do
* not call another interface/manager method while the iterator is alive.
*
* @return iterator, locks IKE_SA manager until destroyed
* @return enumerator, locks IKE_SA manager until destroyed
*/
iterator_t* (*create_ike_sa_iterator)(controller_t *this);
enumerator_t* (*create_ike_sa_enumerator)(controller_t *this);
/**
* Initiate a CHILD_SA, and if required, an IKE_SA.
+6 -6
View File
@@ -203,7 +203,7 @@ static bool start_connection(private_dbus_t *this, DBusMessage* msg)
static bool stop_connection(private_dbus_t *this, DBusMessage* msg)
{
u_int32_t id;
iterator_t *iterator;
enumerator_t *enumerator;
ike_sa_t *ike_sa;
if (this->name == NULL)
@@ -215,8 +215,8 @@ static bool stop_connection(private_dbus_t *this, DBusMessage* msg)
set_state(this, NM_VPN_STATE_STOPPING);
iterator = charon->controller->create_ike_sa_iterator(charon->controller);
while (iterator->iterate(iterator, (void**)&ike_sa))
enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
while (enumerator->enumerate(enumerator, (void**)&ike_sa))
{
child_sa_t *child_sa;
iterator_t *children;
@@ -224,7 +224,7 @@ static bool stop_connection(private_dbus_t *this, DBusMessage* msg)
if (this->name && streq(this->name, ike_sa->get_name(ike_sa)))
{
id = ike_sa->get_unique_id(ike_sa);
iterator->destroy(iterator);
enumerator->destroy(enumerator);
charon->controller->terminate_ike(charon->controller, id, NULL, NULL);
set_state(this, NM_VPN_STATE_STOPPED);
return TRUE;;
@@ -236,7 +236,7 @@ static bool stop_connection(private_dbus_t *this, DBusMessage* msg)
{
id = child_sa->get_reqid(child_sa);
children->destroy(children);
iterator->destroy(iterator);
enumerator->destroy(enumerator);
charon->controller->terminate_child(charon->controller, id, NULL, NULL);
set_state(this, NM_VPN_STATE_STOPPED);
return TRUE;
@@ -244,7 +244,7 @@ static bool stop_connection(private_dbus_t *this, DBusMessage* msg)
}
children->destroy(children);
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
set_state(this, NM_VPN_STATE_STOPPED);
return TRUE;
}
+3 -3
View File
@@ -216,8 +216,8 @@ static void request_query_ikesa(xmlTextReaderPtr reader, xmlTextWriterPtr writer
/* <ikesalist> */
xmlTextWriterStartElement(writer, "ikesalist");
iterator = charon->ike_sa_manager->create_iterator(charon->ike_sa_manager);
while (iterator->iterate(iterator, (void**)&ike_sa))
enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
while (enumerator->enumerate(enumerator, &ike_sa))
{
ike_sa_id_t *id;
host_t *local, *remote;
@@ -283,7 +283,7 @@ static void request_query_ikesa(xmlTextReaderPtr reader, xmlTextWriterPtr writer
/* </ikesa> */
xmlTextWriterEndElement(writer);
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
/* </ikesalist> */
xmlTextWriterEndElement(writer);
+1 -1
View File
@@ -488,7 +488,7 @@ static peer_cfg_t *build_peer_cfg(private_stroke_config_t *this,
* uses to serve pool addresses. */
return peer_cfg_create(msg->add_conn.name,
msg->add_conn.ikev2 ? 2 : 1, ike_cfg, me, other,
msg->add_conn.me.sendcert, msg->add_conn.auth_method,
msg->add_conn.me.sendcert, UNIQUE_NO, msg->add_conn.auth_method,
msg->add_conn.eap_type, msg->add_conn.eap_vendor,
msg->add_conn.rekey.tries, rekey, reauth, jitter, over,
msg->add_conn.mobike, msg->add_conn.dpd.delay,
+11 -12
View File
@@ -147,7 +147,7 @@ static void terminate(private_stroke_control_t *this, stroke_msg_t *msg, FILE *o
bool child;
int len;
ike_sa_t *ike_sa;
iterator_t *iterator;
enumerator_t *enumerator;
stroke_log_info_t info;
string = msg->terminate.name;
@@ -197,8 +197,8 @@ static void terminate(private_stroke_control_t *this, stroke_msg_t *msg, FILE *o
info.out = out;
info.level = msg->output_verbosity;
iterator = charon->controller->create_ike_sa_iterator(charon->controller);
while (iterator->iterate(iterator, (void**)&ike_sa))
enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
while (enumerator->enumerate(enumerator, &ike_sa))
{
child_sa_t *child_sa;
iterator_t *children;
@@ -213,7 +213,7 @@ static void terminate(private_stroke_control_t *this, stroke_msg_t *msg, FILE *o
{
id = child_sa->get_reqid(child_sa);
children->destroy(children);
iterator->destroy(iterator);
enumerator->destroy(enumerator);
charon->controller->terminate_child(charon->controller, id,
(controller_cb_t)stroke_log, &info);
@@ -227,7 +227,7 @@ static void terminate(private_stroke_control_t *this, stroke_msg_t *msg, FILE *o
{
id = ike_sa->get_unique_id(ike_sa);
/* unlock manager first */
iterator->destroy(iterator);
enumerator->destroy(enumerator);
charon->controller->terminate_ike(charon->controller, id,
(controller_cb_t)stroke_log, &info);
@@ -235,9 +235,8 @@ static void terminate(private_stroke_control_t *this, stroke_msg_t *msg, FILE *o
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
DBG1(DBG_CFG, "no such SA found");
}
/**
@@ -285,7 +284,7 @@ static void unroute(private_stroke_control_t *this, stroke_msg_t *msg, FILE *out
{
char *name;
ike_sa_t *ike_sa;
iterator_t *iterator;
enumerator_t *enumerator;
stroke_log_info_t info;
name = msg->terminate.name;
@@ -293,8 +292,8 @@ static void unroute(private_stroke_control_t *this, stroke_msg_t *msg, FILE *out
info.out = out;
info.level = msg->output_verbosity;
iterator = charon->controller->create_ike_sa_iterator(charon->controller);
while (iterator->iterate(iterator, (void**)&ike_sa))
enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
while (enumerator->enumerate(enumerator, &ike_sa))
{
child_sa_t *child_sa;
iterator_t *children;
@@ -308,7 +307,7 @@ static void unroute(private_stroke_control_t *this, stroke_msg_t *msg, FILE *out
{
id = child_sa->get_reqid(child_sa);
children->destroy(children);
iterator->destroy(iterator);
enumerator->destroy(enumerator);
charon->controller->unroute(charon->controller, id,
(controller_cb_t)stroke_log, &info);
return;
@@ -316,7 +315,7 @@ static void unroute(private_stroke_control_t *this, stroke_msg_t *msg, FILE *out
}
children->destroy(children);
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
DBG1(DBG_CFG, "no such SA found");
}
+20 -8
View File
@@ -184,6 +184,7 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
child_cfg_t *child_cfg;
ike_sa_t *ike_sa;
char *name = NULL;
bool found = FALSE;
time_t uptime;
name = msg->status.name;
@@ -240,20 +241,18 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
enumerator->destroy(enumerator);
}
iterator = charon->ike_sa_manager->create_iterator(charon->ike_sa_manager);
if (all && iterator->get_count(iterator) > 0)
{
fprintf(out, "Security Associations:\n");
}
while (iterator->iterate(iterator, (void**)&ike_sa))
fprintf(out, "Security Associations:\n");
enumerator = charon->controller->create_ike_sa_enumerator(charon->controller);
while (enumerator->enumerate(enumerator, &ike_sa))
{
bool ike_printed = FALSE;
child_sa_t *child_sa;
iterator_t *children = ike_sa->create_child_sa_iterator(ike_sa);
if (name == NULL || streq(name, ike_sa->get_name(ike_sa)))
{
log_ike_sa(out, ike_sa, all);
found = TRUE;
ike_printed = TRUE;
}
@@ -264,6 +263,7 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
if (!ike_printed)
{
log_ike_sa(out, ike_sa, all);
found = TRUE;
ike_printed = TRUE;
}
log_child_sa(out, child_sa, all);
@@ -271,7 +271,19 @@ static void status(private_stroke_list_t *this, stroke_msg_t *msg, FILE *out, bo
}
children->destroy(children);
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
if (!found)
{
if (name)
{
fprintf(out, " no match\n");
}
else
{
fprintf(out, " none\n");
}
}
}
/**
+5 -5
View File
@@ -56,18 +56,18 @@ static void execute(private_roam_job_t *this)
ike_sa_t *ike_sa;
linked_list_t *list;
ike_sa_id_t *id;
iterator_t *iterator;
enumerator_t *enumerator;
/* iterating over all IKE_SAs gives us no way to checkin_and_destroy
/* enumerator over all IKE_SAs gives us no way to checkin_and_destroy
* after a DESTROY_ME, so we check out each available IKE_SA by hand. */
list = linked_list_create();
iterator = charon->ike_sa_manager->create_iterator(charon->ike_sa_manager);
while (iterator->iterate(iterator, (void**)&ike_sa))
enumerator = charon->ike_sa_manager->create_enumerator(charon->ike_sa_manager);
while (enumerator->enumerate(enumerator, &ike_sa))
{
id = ike_sa->get_id(ike_sa);
list->insert_last(list, id->clone(id));
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
while (list->remove_last(list, (void**)&id) == SUCCESS)
{
+74 -66
View File
@@ -155,20 +155,20 @@ struct private_ike_sa_manager_t {
/**
* Implementation of private_ike_sa_manager_t.get_entry_by_id.
*/
static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, entry_t **entry)
static status_t get_entry_by_id(private_ike_sa_manager_t *this,
ike_sa_id_t *ike_sa_id, entry_t **entry)
{
linked_list_t *list = this->ike_sa_list;
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *current;
status_t status;
/* create iterator over list of ike_sa's */
iterator = list->create_iterator(list, TRUE);
/* create enumerator over list of ike_sa's */
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
/* default status */
status = NOT_FOUND;
while (iterator->iterate(iterator, (void**)&current))
while (enumerator->enumerate(enumerator, &current))
{
if (current->ike_sa_id->equals(current->ike_sa_id, ike_sa_id))
{
@@ -194,26 +194,26 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
return status;
}
/**
* Implementation of private_ike_sa_manager_t.get_entry_by_sa.
*/
static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa, entry_t **entry)
static status_t get_entry_by_sa(private_ike_sa_manager_t *this,
ike_sa_t *ike_sa, entry_t **entry)
{
linked_list_t *list = this->ike_sa_list;
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *current;
status_t status;
iterator = list->create_iterator(list, TRUE);
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
/* default status */
status = NOT_FOUND;
while (iterator->iterate(iterator, (void**)&current))
while (enumerator->enumerate(enumerator, &current))
{
/* only pointers are compared */
if (current->ike_sa == ike_sa)
@@ -224,7 +224,7 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa
break;
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
return status;
}
@@ -234,16 +234,15 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa
*/
static status_t delete_entry(private_ike_sa_manager_t *this, entry_t *entry)
{
linked_list_t *list = this->ike_sa_list;
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *current;
status_t status;
iterator = list->create_iterator(list, TRUE);
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
status = NOT_FOUND;
while (iterator->iterate(iterator, (void**)&current))
while (enumerator->enumerate(enumerator, &current))
{
if (current == entry)
{
@@ -259,13 +258,13 @@ static status_t delete_entry(private_ike_sa_manager_t *this, entry_t *entry)
}
DBG2(DBG_MGR, "found entry by pointer, deleting it");
iterator->remove(iterator);
this->ike_sa_list->remove_at(this->ike_sa_list, enumerator);
entry_destroy(entry);
status = SUCCESS;
break;
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
return status;
}
@@ -382,7 +381,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
message->get_exchange_type(message) == IKE_SA_INIT)
{
/* IKE_SA_INIT request. Check for an IKE_SA with such a message hash. */
iterator_t *iterator;
enumerator_t *enumerator;
chunk_t data, hash;
data = message->get_packet_data(message);
@@ -390,14 +389,14 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
chunk_free(&data);
pthread_mutex_lock(&this->mutex);
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
if (chunk_equals(hash, entry->init_hash))
{
if (entry->message_id == 0)
{
iterator->destroy(iterator);
enumerator->destroy(enumerator);
pthread_mutex_unlock(&this->mutex);
chunk_free(&hash);
id->destroy(id);
@@ -414,7 +413,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
break;
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
pthread_mutex_unlock(&this->mutex);
if (ike_sa == NULL)
@@ -484,7 +483,7 @@ static ike_sa_t* checkout_by_message(private_ike_sa_manager_t* this,
static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
peer_cfg_t *peer_cfg)
{
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *entry;
ike_sa_t *ike_sa = NULL;
identification_t *my_id, *other_id;
@@ -499,8 +498,8 @@ static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
pthread_mutex_lock(&(this->mutex));
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
identification_t *found_my_id, *found_other_id;
host_t *found_my_host, *found_other_host;
@@ -549,7 +548,7 @@ static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
break;
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
if (!ike_sa)
{
@@ -584,15 +583,16 @@ static ike_sa_t* checkout_by_config(private_ike_sa_manager_t *this,
static ike_sa_t* checkout_by_id(private_ike_sa_manager_t *this, u_int32_t id,
bool child)
{
iterator_t *iterator, *children;
enumerator_t *enumerator;
iterator_t *children;
entry_t *entry;
ike_sa_t *ike_sa = NULL;
child_sa_t *child_sa;
pthread_mutex_lock(&(this->mutex));
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
if (wait_for_entry(this, entry))
{
@@ -625,7 +625,7 @@ static ike_sa_t* checkout_by_id(private_ike_sa_manager_t *this, u_int32_t id,
}
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
pthread_mutex_unlock(&(this->mutex));
charon->bus->set_sa(charon->bus, ike_sa);
@@ -638,15 +638,16 @@ static ike_sa_t* checkout_by_id(private_ike_sa_manager_t *this, u_int32_t id,
static ike_sa_t* checkout_by_name(private_ike_sa_manager_t *this, char *name,
bool child)
{
iterator_t *iterator, *children;
enumerator_t *enumerator;
iterator_t *children;
entry_t *entry;
ike_sa_t *ike_sa = NULL;
child_sa_t *child_sa;
pthread_mutex_lock(&(this->mutex));
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
if (wait_for_entry(this, entry))
{
@@ -679,7 +680,7 @@ static ike_sa_t* checkout_by_name(private_ike_sa_manager_t *this, char *name,
}
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
pthread_mutex_unlock(&(this->mutex));
charon->bus->set_sa(charon->bus, ike_sa);
@@ -687,31 +688,36 @@ static ike_sa_t* checkout_by_name(private_ike_sa_manager_t *this, char *name,
}
/**
* Iterator hook for iterate, gets ike_sas instead of entries
* enumerator cleanup function
*/
static hook_result_t iterator_hook(private_ike_sa_manager_t* this, entry_t *in,
ike_sa_t **out)
static void enumerator_unlock(private_ike_sa_manager_t *this)
{
/* check out entry */
if (wait_for_entry(this, in))
pthread_mutex_unlock(&this->mutex);
}
/**
* enumerator filter function
*/
static bool enumerator_filter(private_ike_sa_manager_t *this,
entry_t **in, ike_sa_t **out)
{
if (wait_for_entry(this, *in))
{
*out = in->ike_sa;
return HOOK_NEXT;
*out = (*in)->ike_sa;
return TRUE;
}
return HOOK_SKIP;
return FALSE;
}
/**
* Implementation of ike_sa_manager_t.create_iterator.
*/
static iterator_t *create_iterator(private_ike_sa_manager_t* this)
static enumerator_t *create_enumerator(private_ike_sa_manager_t* this)
{
iterator_t *iterator = this->ike_sa_list->create_iterator_locked(
this->ike_sa_list, &this->mutex);
/* register hook to iterator over ike_sas, not entries */
iterator->set_iterator_hook(iterator, (iterator_hook_t*)iterator_hook, this);
return iterator;
pthread_mutex_lock(&this->mutex);
return enumerator_create_filter(
this->ike_sa_list->create_enumerator(this->ike_sa_list),
(void*)enumerator_filter, this, (void*)enumerator_unlock);
}
/**
@@ -807,13 +813,13 @@ static status_t checkin_and_destroy(private_ike_sa_manager_t *this, ike_sa_t *ik
*/
static int get_half_open_count(private_ike_sa_manager_t *this, host_t *ip)
{
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *entry;
int count = 0;
pthread_mutex_lock(&(this->mutex));
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
/* we check if we have a responder CONNECTING IKE_SA without checkout */
if (!entry->ike_sa_id->is_initiator(entry->ike_sa_id) &&
@@ -834,7 +840,7 @@ static int get_half_open_count(private_ike_sa_manager_t *this, host_t *ip)
}
}
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
pthread_mutex_unlock(&(this->mutex));
return count;
@@ -846,25 +852,25 @@ static int get_half_open_count(private_ike_sa_manager_t *this, host_t *ip)
static void destroy(private_ike_sa_manager_t *this)
{
/* destroy all list entries */
linked_list_t *list = this->ike_sa_list;
iterator_t *iterator;
enumerator_t *enumerator;
entry_t *entry;
pthread_mutex_lock(&(this->mutex));
DBG2(DBG_MGR, "going to destroy IKE_SA manager and all managed IKE_SA's");
/* Step 1: drive out all waiting threads */
DBG2(DBG_MGR, "set driveout flags for all stored IKE_SA's");
iterator = list->create_iterator(list, TRUE);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
/* do not accept new threads, drive out waiting threads */
entry->driveout_new_threads = TRUE;
entry->driveout_waiting_threads = TRUE;
}
enumerator->destroy(enumerator);
DBG2(DBG_MGR, "wait for all threads to leave IKE_SA's");
/* Step 2: wait until all are gone */
iterator->reset(iterator);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
while (entry->waiting_threads)
{
@@ -874,18 +880,19 @@ static void destroy(private_ike_sa_manager_t *this)
pthread_cond_wait(&(entry->condvar), &(this->mutex));
}
}
enumerator->destroy(enumerator);
DBG2(DBG_MGR, "delete all IKE_SA's");
/* Step 3: initiate deletion of all IKE_SAs */
iterator->reset(iterator);
while (iterator->iterate(iterator, (void**)&entry))
enumerator = this->ike_sa_list->create_enumerator(this->ike_sa_list);
while (enumerator->enumerate(enumerator, &entry))
{
entry->ike_sa->delete(entry->ike_sa);
}
iterator->destroy(iterator);
enumerator->destroy(enumerator);
DBG2(DBG_MGR, "destroy all entries");
/* Step 4: destroy all entries */
list->destroy_function(list, (void*)entry_destroy);
this->ike_sa_list->destroy_function(this->ike_sa_list, (void*)entry_destroy);
pthread_mutex_unlock(&(this->mutex));
this->randomizer->destroy(this->randomizer);
@@ -909,7 +916,7 @@ ike_sa_manager_t *ike_sa_manager_create()
this->public.checkout_by_config = (ike_sa_t*(*)(ike_sa_manager_t*,peer_cfg_t*))checkout_by_config;
this->public.checkout_by_id = (ike_sa_t*(*)(ike_sa_manager_t*,u_int32_t,bool))checkout_by_id;
this->public.checkout_by_name = (ike_sa_t*(*)(ike_sa_manager_t*,char*,bool))checkout_by_name;
this->public.create_iterator = (iterator_t*(*)(ike_sa_manager_t*))create_iterator;
this->public.create_enumerator = (enumerator_t*(*)(ike_sa_manager_t*))create_enumerator;
this->public.checkin = (status_t(*)(ike_sa_manager_t*,ike_sa_t*))checkin;
this->public.checkin_and_destroy = (status_t(*)(ike_sa_manager_t*,ike_sa_t*))checkin_and_destroy;
this->public.get_half_open_count = (int(*)(ike_sa_manager_t*,host_t*))get_half_open_count;
@@ -927,3 +934,4 @@ ike_sa_manager_t *ike_sa_manager_create()
this->randomizer = randomizer_create();
return &this->public;
}
+4 -5
View File
@@ -135,15 +135,14 @@ struct ike_sa_manager_t {
bool child);
/**
* Create an iterator over all stored IKE_SAs.
* Create an enumerator over all stored IKE_SAs.
*
* The avoid synchronization issues, the iterator locks access
* The avoid synchronization issues, the enumerator locks access
* to the manager exclusively, until it gets destroyed.
* This iterator is for reading only! Writing will corrupt the manager.
*
* @return iterator over all IKE_SAs.
* @return enumerator over all IKE_SAs.
*/
iterator_t *(*create_iterator) (ike_sa_manager_t* this);
enumerator_t *(*create_enumerator) (ike_sa_manager_t* this);
/**
* Checkin the SA after usage.