aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins
diff options
context:
space:
mode:
authorMartin Willi <martin@revosec.ch>2013-03-21 10:29:23 +0100
committerMartin Willi <martin@revosec.ch>2013-03-21 10:29:23 +0100
commitdd3c243844e36fabad03e19238707cf8c715e095 (patch)
tree67d5f0e94d5437d6c800888fe45ec2906052e7d3 /src/libcharon/plugins
parent24b5e7152219e9eeb8d5856eee47b297e6c08793 (diff)
downloadstrongswan-dd3c243844e36fabad03e19238707cf8c715e095.tar.bz2
strongswan-dd3c243844e36fabad03e19238707cf8c715e095.tar.xz
Add a load-tester option to keep allocated external address until shutdown
Diffstat (limited to 'src/libcharon/plugins')
-rw-r--r--src/libcharon/plugins/load_tester/load_tester_config.c50
-rw-r--r--src/libcharon/plugins/load_tester/load_tester_listener.c1
2 files changed, 50 insertions, 1 deletions
diff --git a/src/libcharon/plugins/load_tester/load_tester_config.c b/src/libcharon/plugins/load_tester/load_tester_config.c
index ed1ca8156..a64affde8 100644
--- a/src/libcharon/plugins/load_tester/load_tester_config.c
+++ b/src/libcharon/plugins/load_tester/load_tester_config.c
@@ -159,6 +159,11 @@ struct private_load_tester_config_t {
int prefix;
/**
+ * Keep addresses until shutdown?
+ */
+ bool keep;
+
+ /**
* Hashtable with leases in "pools", host_t => entry_t
*/
hashtable_t *leases;
@@ -216,6 +221,8 @@ static void load_addrs(private_load_tester_config_t *this)
char *iface, *token, *pos;
mem_pool_t *pool;
+ this->keep = lib->settings->get_bool(lib->settings,
+ "%s.plugins.load-tester.addrs_keep", FALSE, charon->name);
this->prefix = lib->settings->get_int(lib->settings,
"%s.plugins.load-tester.addrs_prefix", 16, charon->name);
enumerator = lib->settings->create_key_value_enumerator(lib->settings,
@@ -636,6 +643,11 @@ METHOD(load_tester_config_t, delete_ip, void,
mem_pool_t *pool;
entry_t *entry;
+ if (this->keep)
+ {
+ return;
+ }
+
this->mutex->lock(this->mutex);
entry = this->leases->remove(this->leases, ip);
this->mutex->unlock(this->mutex);
@@ -657,9 +669,47 @@ METHOD(load_tester_config_t, delete_ip, void,
}
}
+/**
+ * Clean up leases for allocated external addresses, if have been kept
+ */
+static void cleanup_leases(private_load_tester_config_t *this)
+{
+ enumerator_t *pools, *leases;
+ mem_pool_t *pool;
+ identification_t *id;
+ host_t *addr;
+ entry_t *entry;
+ bool online;
+
+ pools = this->pools->create_enumerator(this->pools);
+ while (pools->enumerate(pools, &pool))
+ {
+ leases = pool->create_lease_enumerator(pool);
+ while (leases->enumerate(leases, &id, &addr, &online))
+ {
+ if (online)
+ {
+ hydra->kernel_interface->del_ip(hydra->kernel_interface,
+ addr, this->prefix, FALSE);
+ entry = this->leases->remove(this->leases, addr);
+ if (entry)
+ {
+ entry_destroy(entry);
+ }
+ }
+ }
+ leases->destroy(leases);
+ }
+ pools->destroy(pools);
+}
+
METHOD(load_tester_config_t, destroy, void,
private_load_tester_config_t *this)
{
+ if (this->keep)
+ {
+ cleanup_leases(this);
+ }
this->mutex->destroy(this->mutex);
this->leases->destroy(this->leases);
this->pools->destroy_offset(this->pools, offsetof(mem_pool_t, destroy));
diff --git a/src/libcharon/plugins/load_tester/load_tester_listener.c b/src/libcharon/plugins/load_tester/load_tester_listener.c
index 0192c8ff9..7e832ddc0 100644
--- a/src/libcharon/plugins/load_tester/load_tester_listener.c
+++ b/src/libcharon/plugins/load_tester/load_tester_listener.c
@@ -133,4 +133,3 @@ load_tester_listener_t *load_tester_listener_create(u_int shutdown_on,
return &this->public;
}
-