aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2010-03-19 13:49:37 +0100
committerMartin Willi <martin@revosec.ch>2010-03-25 14:39:32 +0100
commit479a7b7d1763861311798c5da02590e82bc5ccc4 (patch)
tree57b102b1a3f0cb240b6c531ce2bdc8976a6020f0 /src
parent660e16f5b2154412f9bfbc54136010307feede26 (diff)
downloadstrongswan-479a7b7d1763861311798c5da02590e82bc5ccc4.tar.bz2
strongswan-479a7b7d1763861311798c5da02590e82bc5ccc4.tar.xz
Added locking to farp listener
Diffstat (limited to 'src')
-rw-r--r--src/libcharon/plugins/farp/farp_listener.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/src/libcharon/plugins/farp/farp_listener.c b/src/libcharon/plugins/farp/farp_listener.c
index 698815f07..018768144 100644
--- a/src/libcharon/plugins/farp/farp_listener.c
+++ b/src/libcharon/plugins/farp/farp_listener.c
@@ -16,6 +16,7 @@
#include "farp_listener.h"
#include <utils/hashtable.h>
+#include <threading/rwlock.h>
typedef struct private_farp_listener_t private_farp_listener_t;
@@ -33,6 +34,11 @@ struct private_farp_listener_t {
* Hashtable with active virtual IPs
*/
hashtable_t *ips;
+
+ /**
+ * RWlock for IP list
+ */
+ rwlock_t *lock;
};
/**
@@ -59,6 +65,7 @@ METHOD(listener_t, ike_updown, bool,
ip = ike_sa->get_virtual_ip(ike_sa, FALSE);
if (ip)
{
+ this->lock->write_lock(this->lock);
if (up)
{
ip = ip->clone(ip);
@@ -68,6 +75,7 @@ METHOD(listener_t, ike_updown, bool,
{
ip = this->ips->remove(this->ips, ip);
}
+ this->lock->unlock(this->lock);
DESTROY_IF(ip);
}
return TRUE;
@@ -76,7 +84,12 @@ METHOD(listener_t, ike_updown, bool,
METHOD(farp_listener_t, is_active, bool,
private_farp_listener_t *this, host_t *ip)
{
- return this->ips->get(this->ips, ip) != NULL;
+ bool active;
+
+ this->lock->read_lock(this->lock);
+ active = this->ips->get(this->ips, ip) != NULL;
+ this->lock->unlock(this->lock);
+ return active;
}
METHOD(farp_listener_t, destroy, void,
@@ -93,6 +106,7 @@ METHOD(farp_listener_t, destroy, void,
enumerator->destroy(enumerator);
this->ips->destroy(this->ips);
+ this->lock->destroy(this->lock);
free(this);
}
@@ -111,6 +125,7 @@ farp_listener_t *farp_listener_create()
},
.ips = hashtable_create((hashtable_hash_t)hash,
(hashtable_equals_t)equals, 8),
+ .lock = rwlock_create(RWLOCK_TYPE_DEFAULT),
);
return &this->public;