- connection termination is handled cleanly by name now
This commit is contained in:
@@ -367,8 +367,7 @@ static status_t build_interface_list(private_socket_t *this, u_int16_t port)
|
||||
|
||||
/* add socket with interface name to list */
|
||||
interface = malloc_thing(interface_t);
|
||||
memcpy(interface->name, buf[i].ifr_name, IFNAMSIZ);
|
||||
interface->name[IFNAMSIZ-1] = '\0';
|
||||
strncpy(interface->name, buf[i].ifr_name, IFNAMSIZ);
|
||||
interface->socket_fd = skt;
|
||||
interface->address = host_create_from_sockaddr((struct sockaddr*)current);
|
||||
this->logger->log(this->logger, CONTROL, "listening on %s (%s)",
|
||||
|
||||
@@ -573,6 +573,36 @@ linked_list_t *get_ike_sa_list(private_ike_sa_manager_t* this)
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_manager_t.get_ike_sa_list_by_name.
|
||||
*/
|
||||
linked_list_t *get_ike_sa_list_by_name(private_ike_sa_manager_t* this, const char *name)
|
||||
{
|
||||
linked_list_t *list;
|
||||
iterator_t *iterator;
|
||||
|
||||
pthread_mutex_lock(&(this->mutex));
|
||||
|
||||
list = linked_list_create();
|
||||
iterator = this->ike_sa_list->create_iterator(this->ike_sa_list, TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
ike_sa_entry_t *entry;
|
||||
connection_t *connection;
|
||||
|
||||
iterator->current(iterator, (void**)&entry);
|
||||
connection = entry->ike_sa->get_connection(entry->ike_sa);
|
||||
if (strcmp(name, connection->get_name(connection)) == 0)
|
||||
{
|
||||
list->insert_last(list, (void*)entry->ike_sa_id->clone(entry->ike_sa_id));
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
pthread_mutex_unlock(&(this->mutex));
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of ike_sa_manager_t.log_status.
|
||||
*/
|
||||
@@ -788,6 +818,7 @@ ike_sa_manager_t *ike_sa_manager_create()
|
||||
this->public.checkout = (status_t(*)(ike_sa_manager_t*, ike_sa_id_t*,ike_sa_t**))checkout;
|
||||
this->public.checkout_by_hosts = (status_t(*)(ike_sa_manager_t*,host_t*,host_t*,ike_sa_t**))checkout_by_hosts;
|
||||
this->public.get_ike_sa_list = (linked_list_t*(*)(ike_sa_manager_t*))get_ike_sa_list;
|
||||
this->public.get_ike_sa_list_by_name = (linked_list_t*(*)(ike_sa_manager_t*,const char*))get_ike_sa_list_by_name;
|
||||
this->public.log_status = (void(*)(ike_sa_manager_t*,logger_t*,char*))log_status;
|
||||
this->public.checkin = (status_t(*)(ike_sa_manager_t*,ike_sa_t*))checkin;
|
||||
this->public.delete = (status_t(*)(ike_sa_manager_t*,ike_sa_id_t*))delete;
|
||||
|
||||
@@ -110,6 +110,15 @@ struct ike_sa_manager_t {
|
||||
*/
|
||||
linked_list_t *(*get_ike_sa_list) (ike_sa_manager_t* this);
|
||||
|
||||
/**
|
||||
* @brief Get a list of all IKE_SA SAs currently set up specified
|
||||
* by the connections name.
|
||||
*
|
||||
* @param this the manager object
|
||||
* @return a list with ike_sa_id_t s
|
||||
*/
|
||||
linked_list_t *(*get_ike_sa_list_by_name) (ike_sa_manager_t* this, const char *name);
|
||||
|
||||
/**
|
||||
* @brief Log the status of the IKE_SA's in the manager.
|
||||
*
|
||||
|
||||
@@ -322,43 +322,27 @@ static void stroke_initiate(private_stroke_t *this, stroke_msg_t *msg)
|
||||
*/
|
||||
static void stroke_terminate(private_stroke_t *this, stroke_msg_t *msg)
|
||||
{
|
||||
connection_t *connection;
|
||||
ike_sa_t *ike_sa;
|
||||
host_t *my_host, *other_host;
|
||||
status_t status;
|
||||
linked_list_t *ike_sas;
|
||||
iterator_t *iterator;
|
||||
int instances = 0;
|
||||
|
||||
pop_string(msg, &(msg->terminate.name));
|
||||
this->logger->log(this->logger, CONTROL, "received stroke: terminate \"%s\"", msg->terminate.name);
|
||||
connection = charon->connections->get_connection_by_name(charon->connections, msg->terminate.name);
|
||||
|
||||
if (connection)
|
||||
{
|
||||
my_host = connection->get_my_host(connection);
|
||||
other_host = connection->get_other_host(connection);
|
||||
|
||||
/* TODO: Do this directly by name now */
|
||||
/* TODO: terminate any instance of the name */
|
||||
status = charon->ike_sa_manager->checkout_by_hosts(charon->ike_sa_manager,
|
||||
my_host, other_host, &ike_sa);
|
||||
|
||||
if (status == SUCCESS)
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, CONTROL, "deleting IKE SA between %s - %s",
|
||||
my_host->get_address(my_host), other_host->get_address(other_host));
|
||||
|
||||
charon->ike_sa_manager->checkin_and_delete(charon->ike_sa_manager, ike_sa);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "no active connection found between %s - %s",
|
||||
my_host->get_address(my_host), other_host->get_address(other_host));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->stroke_logger->log(this->stroke_logger, ERROR, "could not find a connection named \"%s\"", msg->terminate.name);
|
||||
}
|
||||
ike_sas = charon->ike_sa_manager->get_ike_sa_list_by_name(charon->ike_sa_manager, msg->terminate.name);
|
||||
|
||||
iterator = ike_sas->create_iterator(ike_sas, TRUE);
|
||||
while (iterator->has_next(iterator))
|
||||
{
|
||||
ike_sa_id_t *ike_sa_id;
|
||||
iterator->current(iterator, (void**)&ike_sa_id);
|
||||
charon->ike_sa_manager->delete(charon->ike_sa_manager, ike_sa_id);
|
||||
ike_sa_id->destroy(ike_sa_id);
|
||||
instances++;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
ike_sas->destroy(ike_sas);
|
||||
this->stroke_logger->log(this->stroke_logger, CONTROL, "terminated %d instances of %s", instances, msg->terminate.name);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
- intiating the same connection twice makes trouble
|
||||
- leak_detective gets confused from libpthread (invalid frees)
|
||||
- installing to many SAs in the kernel at the same time causes troubles. Threading issue?
|
||||
|
||||
|
||||
Reference in New Issue
Block a user