diff options
author | Martin Willi <martin@revosec.ch> | 2011-05-05 10:01:21 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2011-05-16 15:24:15 +0200 |
commit | 9a96ba4b6e432119a22245da7dec94bca44fb703 (patch) | |
tree | c8e0795c2eb49b9ae53c23fcf361c56efe1051c2 | |
parent | a836cf8085f08d0138d6b37f7aaea12a1348c2cd (diff) | |
download | strongswan-9a96ba4b6e432119a22245da7dec94bca44fb703.tar.bz2 strongswan-9a96ba4b6e432119a22245da7dec94bca44fb703.tar.xz |
Added a get_count() method to IKE_SA manager
-rw-r--r-- | src/libcharon/sa/ike_sa_manager.c | 21 | ||||
-rw-r--r-- | src/libcharon/sa/ike_sa_manager.h | 9 |
2 files changed, 27 insertions, 3 deletions
diff --git a/src/libcharon/sa/ike_sa_manager.c b/src/libcharon/sa/ike_sa_manager.c index 03ca45481..7f3ca7dd5 100644 --- a/src/libcharon/sa/ike_sa_manager.c +++ b/src/libcharon/sa/ike_sa_manager.c @@ -1556,14 +1556,30 @@ METHOD(ike_sa_manager_t, has_contact, bool, return found; } -METHOD(ike_sa_manager_t, get_half_open_count, int, +METHOD(ike_sa_manager_t, get_count, u_int, + private_ike_sa_manager_t *this) +{ + u_int segment, count = 0; + mutex_t *mutex; + + for (segment = 0; segment < this->segment_count; segment++) + { + mutex = this->segments[segment & this->segment_mask].mutex; + mutex->lock(mutex); + count += this->segments[segment].count; + mutex->unlock(mutex); + } + return count; +} + +METHOD(ike_sa_manager_t, get_half_open_count, u_int, private_ike_sa_manager_t *this, host_t *ip) { linked_list_t *list; u_int segment, row; rwlock_t *lock; chunk_t addr; - int count = 0; + u_int count = 0; if (ip) { @@ -1745,6 +1761,7 @@ ike_sa_manager_t *ike_sa_manager_create() .create_enumerator = _create_enumerator, .checkin = _checkin, .checkin_and_destroy = _checkin_and_destroy, + .get_count = _get_count, .get_half_open_count = _get_half_open_count, .flush = _flush, .destroy = _destroy, diff --git a/src/libcharon/sa/ike_sa_manager.h b/src/libcharon/sa/ike_sa_manager.h index 315e23592..5e542e7df 100644 --- a/src/libcharon/sa/ike_sa_manager.h +++ b/src/libcharon/sa/ike_sa_manager.h @@ -192,6 +192,13 @@ struct ike_sa_manager_t { void (*checkin_and_destroy) (ike_sa_manager_t* this, ike_sa_t *ike_sa); /** + * Get the number of IKE_SAs currently registered. + * + * @return number of registered IKE_SAs + */ + u_int (*get_count)(ike_sa_manager_t *this); + + /** * Get the number of IKE_SAs which are in the connecting state. * * To prevent the server from resource exhaustion, cookies and other @@ -204,7 +211,7 @@ struct ike_sa_manager_t { * @param ip NULL for all, IP for half open IKE_SAs with IP * @return number of half open IKE_SAs */ - int (*get_half_open_count) (ike_sa_manager_t *this, host_t *ip); + u_int (*get_half_open_count) (ike_sa_manager_t *this, host_t *ip); /** * Delete all existing IKE_SAs and destroy them immediately. |