summaryrefslogtreecommitdiff
path: root/src/charon/sa/mediation_manager.c
diff options
context:
space:
mode:
authorRene Mayrhofer <rene@mayrhofer.eu.org>2010-02-23 10:42:46 +0000
committerRene Mayrhofer <rene@mayrhofer.eu.org>2010-02-23 10:42:46 +0000
commitde6b12502cdf42d5d92118f1c0e38dc31becf7c5 (patch)
tree0edac9c79f5a43e01913dd7f71c7abc487e5727b /src/charon/sa/mediation_manager.c
parent172642669d4a23e17f1ed411fbc8629dcaa5fb46 (diff)
downloadvyos-strongswan-de6b12502cdf42d5d92118f1c0e38dc31becf7c5.tar.gz
vyos-strongswan-de6b12502cdf42d5d92118f1c0e38dc31becf7c5.zip
Updated to new upstream release. interfaces Patch is not from upstream.
Diffstat (limited to 'src/charon/sa/mediation_manager.c')
-rw-r--r--src/charon/sa/mediation_manager.c78
1 files changed, 41 insertions, 37 deletions
diff --git a/src/charon/sa/mediation_manager.c b/src/charon/sa/mediation_manager.c
index a69c00173..035f49053 100644
--- a/src/charon/sa/mediation_manager.c
+++ b/src/charon/sa/mediation_manager.c
@@ -16,11 +16,10 @@
#include "mediation_manager.h"
#include <daemon.h>
-#include <utils/mutex.h>
+#include <threading/mutex.h>
#include <utils/linked_list.h>
#include <processing/jobs/mediation_job.h>
-
typedef struct peer_t peer_t;
/**
@@ -28,13 +27,13 @@ typedef struct peer_t peer_t;
*/
struct peer_t {
/** id of the peer */
- identification_t *id;
+ identification_t *id;
/** sa id of the peer, NULL if offline */
- ike_sa_id_t *ike_sa_id;
-
- /** list of peer ids that reuested this peer */
- linked_list_t *requested_by;
+ ike_sa_id_t *ike_sa_id;
+
+ /** list of peer ids that reuested this peer */
+ linked_list_t *requested_by;
};
/**
@@ -43,8 +42,9 @@ struct peer_t {
static void peer_destroy(peer_t *this)
{
DESTROY_IF(this->id);
- DESTROY_IF(this->ike_sa_id);
- this->requested_by->destroy_offset(this->requested_by, offsetof(identification_t, destroy));
+ DESTROY_IF(this->ike_sa_id);
+ this->requested_by->destroy_offset(this->requested_by,
+ offsetof(identification_t, destroy));
free(this);
}
@@ -54,16 +54,15 @@ static void peer_destroy(peer_t *this)
static peer_t *peer_create(identification_t *id, ike_sa_id_t* ike_sa_id)
{
peer_t *this = malloc_thing(peer_t);
-
+
/* clone everything */
this->id = id->clone(id);
- this->ike_sa_id = ike_sa_id ? ike_sa_id->clone(ike_sa_id) : NULL;
- this->requested_by = linked_list_create();
-
+ this->ike_sa_id = ike_sa_id ? ike_sa_id->clone(ike_sa_id) : NULL;
+ this->requested_by = linked_list_create();
+
return this;
}
-
typedef struct private_mediation_manager_t private_mediation_manager_t;
/**
@@ -74,7 +73,7 @@ struct private_mediation_manager_t {
* Public interface of mediation_manager_t.
*/
mediation_manager_t public;
-
+
/**
* Lock for exclusivly accessing the manager.
*/
@@ -93,7 +92,7 @@ static void register_peer(peer_t *peer, identification_t *peer_id)
{
iterator_t *iterator;
identification_t *current;
-
+
iterator = peer->requested_by->create_iterator(peer->requested_by, TRUE);
while (iterator->iterate(iterator, (void**)&current))
{
@@ -104,20 +103,21 @@ static void register_peer(peer_t *peer, identification_t *peer_id)
}
}
iterator->destroy(iterator);
-
- peer->requested_by->insert_last(peer->requested_by, peer_id->clone(peer_id));
+
+ peer->requested_by->insert_last(peer->requested_by,
+ peer_id->clone(peer_id));
}
/**
* Get a peer_t object by a peer's id
*/
static status_t get_peer_by_id(private_mediation_manager_t *this,
- identification_t *id, peer_t **peer)
+ identification_t *id, peer_t **peer)
{
iterator_t *iterator;
peer_t *current;
status_t status = NOT_FOUND;
-
+
iterator = this->peers->create_iterator(this->peers, TRUE);
while (iterator->iterate(iterator, (void**)&current))
{
@@ -141,7 +141,8 @@ static status_t get_peer_by_id(private_mediation_manager_t *this,
* and then remove peers completely that are not online and have no registered
* peers.
*/
-static void unregister_peer(private_mediation_manager_t *this, identification_t *peer_id)
+static void unregister_peer(private_mediation_manager_t *this,
+ identification_t *peer_id)
{
iterator_t *iterator, *iterator_r;
peer_t *peer;
@@ -150,7 +151,8 @@ static void unregister_peer(private_mediation_manager_t *this, identification_t
iterator = this->peers->create_iterator(this->peers, TRUE);
while (iterator->iterate(iterator, (void**)&peer))
{
- iterator_r = peer->requested_by->create_iterator(peer->requested_by, TRUE);
+ iterator_r = peer->requested_by->create_iterator(peer->requested_by,
+ TRUE);
while (iterator_r->iterate(iterator_r, (void**)&registered))
{
if (peer_id->equals(peer_id, registered))
@@ -161,7 +163,7 @@ static void unregister_peer(private_mediation_manager_t *this, identification_t
}
}
iterator_r->destroy(iterator_r);
-
+
if (!peer->ike_sa_id && !peer->requested_by->get_count(peer->requested_by))
{
iterator->remove(iterator);
@@ -181,16 +183,16 @@ static void remove_sa(private_mediation_manager_t *this, ike_sa_id_t *ike_sa_id)
peer_t *peer;
this->mutex->lock(this->mutex);
-
+
iterator = this->peers->create_iterator(this->peers, TRUE);
while (iterator->iterate(iterator, (void**)&peer))
{
if (ike_sa_id->equals(ike_sa_id, peer->ike_sa_id))
{
iterator->remove(iterator);
-
+
unregister_peer(this, peer->id);
-
+
peer_destroy(peer);
break;
}
@@ -222,7 +224,7 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
}
}
iterator->destroy(iterator);
-
+
if (!found)
{
DBG2(DBG_IKE, "adding peer '%Y'", peer_id);
@@ -230,18 +232,19 @@ static void update_sa_id(private_mediation_manager_t *this, identification_t *pe
this->peers->insert_last(this->peers, peer);
}
- DBG2(DBG_IKE, "changing registered IKE_SA ID of peer '%Y'", peer_id);
+ DBG2(DBG_IKE, "changing registered IKE_SA ID of peer '%Y'", peer_id);
peer->ike_sa_id = ike_sa_id ? ike_sa_id->clone(ike_sa_id) : NULL;
-
+
/* send callbacks to registered peers */
identification_t *requester;
- while(peer->requested_by->remove_last(peer->requested_by, (void**)&requester) == SUCCESS)
+ while(peer->requested_by->remove_last(peer->requested_by,
+ (void**)&requester) == SUCCESS)
{
job_t *job = (job_t*)mediation_callback_job_create(requester, peer_id);
charon->processor->queue_job(charon->processor, job);
requester->destroy(requester);
}
-
+
this->mutex->unlock(this->mutex);
}
@@ -286,11 +289,12 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
peer = peer_create(peer_id, NULL);
this->peers->insert_last(this->peers, peer);
}
-
+
if (!peer->ike_sa_id)
{
/* the peer is not online */
- DBG2(DBG_IKE, "requested peer '%Y' is offline, registering peer '%Y'", peer_id, requester);
+ DBG2(DBG_IKE, "requested peer '%Y' is offline, registering peer '%Y'",
+ peer_id, requester);
register_peer(peer, requester);
this->mutex->unlock(this->mutex);
return NULL;
@@ -309,9 +313,9 @@ static ike_sa_id_t *check_and_register(private_mediation_manager_t *this,
static void destroy(private_mediation_manager_t *this)
{
this->mutex->lock(this->mutex);
-
+
this->peers->destroy_function(this->peers, (void*)peer_destroy);
-
+
this->mutex->unlock(this->mutex);
this->mutex->destroy(this->mutex);
free(this);
@@ -329,9 +333,9 @@ mediation_manager_t *mediation_manager_create()
this->public.update_sa_id = (void(*)(mediation_manager_t*,identification_t*,ike_sa_id_t*))update_sa_id;
this->public.check = (ike_sa_id_t*(*)(mediation_manager_t*,identification_t*))check;
this->public.check_and_register = (ike_sa_id_t*(*)(mediation_manager_t*,identification_t*,identification_t*))check_and_register;
-
+
this->peers = linked_list_create();
this->mutex = mutex_create(MUTEX_TYPE_DEFAULT);
-
+
return (mediation_manager_t*)this;
}