ipseckey: Allow en-/disabling at runtime using plugin reload feature
authorTobias Brunner <tobias@strongswan.org>
Fri, 7 Jun 2013 16:38:16 +0000 (18:38 +0200)
committerTobias Brunner <tobias@strongswan.org>
Tue, 11 Jun 2013 09:18:18 +0000 (11:18 +0200)
src/libcharon/plugins/ipseckey/ipseckey_plugin.c

index a62a974..2fd820f 100644 (file)
@@ -49,6 +49,28 @@ METHOD(plugin_t, get_name, char*,
        return "ipseckey";
 }
 
+METHOD(plugin_t, reload, bool,
+       private_ipseckey_plugin_t *this)
+{
+       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
  */
@@ -66,23 +88,16 @@ static bool plugin_cb(private_ipseckey_plugin_t *this,
                        return FALSE;
                }
 
-               if (this->enabled)
-               {
-                       this->cred = ipseckey_cred_create(res);
-                       lib->credmgr->add_set(lib->credmgr, &this->cred->set);
-               }
-               else
-               {
-                       res->destroy(res);
-               }
+               this->cred = ipseckey_cred_create(res);
+               reload(this);
        }
        else
        {
                if (this->enabled)
                {
                        lib->credmgr->remove_set(lib->credmgr, &this->cred->set);
-                       this->cred->destroy(this->cred);
                }
+               this->cred->destroy(this->cred);
        }
        return TRUE;
 }
@@ -117,11 +132,10 @@ plugin_t *ipseckey_plugin_create()
                        .plugin = {
                                .get_name = _get_name,
                                .get_features = _get_features,
+                               .reload = _reload,
                                .destroy = _destroy,
                        },
                },
-               .enabled = lib->settings->get_bool(lib->settings,
-                                                       "%s.plugins.ipseckey.enable", FALSE, charon->name),
        );
 
        return &this->public.plugin;