summaryrefslogtreecommitdiff
path: root/src/libcharon/plugins/ipseckey/ipseckey_plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/plugins/ipseckey/ipseckey_plugin.c')
-rw-r--r--src/libcharon/plugins/ipseckey/ipseckey_plugin.c95
1 files changed, 67 insertions, 28 deletions
diff --git a/src/libcharon/plugins/ipseckey/ipseckey_plugin.c b/src/libcharon/plugins/ipseckey/ipseckey_plugin.c
index 9593cf939..2fd820f94 100644
--- a/src/libcharon/plugins/ipseckey/ipseckey_plugin.c
+++ b/src/libcharon/plugins/ipseckey/ipseckey_plugin.c
@@ -1,4 +1,5 @@
/*
+ * Copyright (C) 2013 Tobias Brunner
* Copyright (C) 2012 Reto Guadagnini
* Hochschule fuer Technik Rapperswil
*
@@ -32,11 +33,6 @@ struct private_ipseckey_plugin_t {
ipseckey_plugin_t public;
/**
- * DNS resolver instance
- */
- resolver_t *res;
-
- /**
* credential set
*/
ipseckey_cred_t *cred;
@@ -53,15 +49,74 @@ METHOD(plugin_t, get_name, char*,
return "ipseckey";
}
-METHOD(plugin_t, destroy, void,
+METHOD(plugin_t, reload, bool,
private_ipseckey_plugin_t *this)
{
- if (this->enabled)
+ bool enabled = lib->settings->get_bool(lib->settings,
+ "%s.plugins.ipseckey.enable", FALSE, charon->name);
+
+ if (enabled != this->enabled)
+ {
+ if (enabled)
+ {
+ lib->credmgr->add_set(lib->credmgr, &this->cred->set);
+ }
+ else
+ {
+ lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
+ }
+ this->enabled = enabled;
+ }
+ DBG1(DBG_CFG, "ipseckey plugin is %sabled", this->enabled ? "en" : "dis");
+ return TRUE;
+}
+
+/**
+ * Create resolver and register credential set
+ */
+static bool plugin_cb(private_ipseckey_plugin_t *this,
+ plugin_feature_t *feature, bool reg, void *cb_data)
+{
+ if (reg)
+ {
+ resolver_t *res;
+
+ res = lib->resolver->create(lib->resolver);
+ if (!res)
+ {
+ DBG1(DBG_CFG, "failed to create a DNS resolver instance");
+ return FALSE;
+ }
+
+ this->cred = ipseckey_cred_create(res);
+ reload(this);
+ }
+ else
{
- lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
+ if (this->enabled)
+ {
+ lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
+ }
+ this->cred->destroy(this->cred);
}
- DESTROY_IF(this->res);
- DESTROY_IF(this->cred);
+ return TRUE;
+}
+
+METHOD(plugin_t, get_features, int,
+ private_ipseckey_plugin_t *this, plugin_feature_t *features[])
+{
+ static plugin_feature_t f[] = {
+ PLUGIN_CALLBACK((plugin_feature_callback_t)plugin_cb, NULL),
+ PLUGIN_PROVIDE(CUSTOM, "ipseckey"),
+ PLUGIN_DEPENDS(RESOLVER),
+ };
+ *features = f;
+ return countof(f);
+}
+
+METHOD(plugin_t, destroy, void,
+ private_ipseckey_plugin_t *this)
+{
free(this);
}
@@ -76,28 +131,12 @@ plugin_t *ipseckey_plugin_create()
.public = {
.plugin = {
.get_name = _get_name,
- .reload = (void*)return_false,
+ .get_features = _get_features,
+ .reload = _reload,
.destroy = _destroy,
},
},
- .res = lib->resolver->create(lib->resolver),
- .enabled = lib->settings->get_bool(lib->settings,
- "%s.plugins.ipseckey.enable", FALSE, charon->name),
);
- if (!this->res)
- {
- DBG1(DBG_CFG, "failed to create a DNS resolver instance");
- destroy(this);
- return NULL;
- }
-
- if (this->enabled)
- {
- this->cred = ipseckey_cred_create(this->res);
- lib->credmgr->add_set(lib->credmgr, &this->cred->set);
- }
-
return &this->public.plugin;
}
-