replaced ipsec up %startall command by start_action job
authorAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 9 Feb 2011 21:27:04 +0000 (22:27 +0100)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 9 Feb 2011 21:27:04 +0000 (22:27 +0100)
src/libcharon/Makefile.am
src/libcharon/daemon.c
src/libcharon/plugins/stroke/stroke_control.c
src/libcharon/processing/jobs/start_action_job.c [new file with mode: 0644]
src/libcharon/processing/jobs/start_action_job.h [new file with mode: 0644]
testing/tests/sql/net2net-route-pem/pretest.dat
testing/tests/sql/net2net-start-pem/pretest.dat

index 350f3fe..1e78c9d 100644 (file)
@@ -53,6 +53,7 @@ processing/jobs/rekey_ike_sa_job.c processing/jobs/rekey_ike_sa_job.h \
 processing/jobs/retransmit_job.c processing/jobs/retransmit_job.h \
 processing/jobs/send_dpd_job.c processing/jobs/send_dpd_job.h \
 processing/jobs/send_keepalive_job.c processing/jobs/send_keepalive_job.h \
+processing/jobs/start_action_job.c processing/jobs/start_action_job.h \
 processing/jobs/roam_job.c processing/jobs/roam_job.h \
 processing/jobs/update_sa_job.c processing/jobs/update_sa_job.h \
 processing/jobs/inactivity_job.c processing/jobs/inactivity_job.h \
index e400986..4f2831e 100644 (file)
@@ -34,6 +34,7 @@
 #include <library.h>
 #include <config/proposal.h>
 #include <kernel/kernel_handler.h>
+#include <processing/jobs/start_action_job.h>
 
 typedef struct private_daemon_t private_daemon_t;
 
@@ -246,6 +247,9 @@ METHOD(daemon_t, initialize, bool,
                return FALSE;
        }
 
+       /* Queue start_action job */
+       lib->processor->queue_job(lib->processor, (job_t*)start_action_job_create());
+
 #ifdef ME
        this->public.connect_manager = connect_manager_create();
        if (this->public.connect_manager == NULL)
index 3318406..3541ab8 100644 (file)
@@ -92,59 +92,6 @@ static child_cfg_t* get_child_from_peer(peer_cfg_t *peer_cfg, char *name)
        return found;
 }
 
-/**
- * Handles all connections that must be either started or routed
- * Currently only for connections stored in an SQL database
- * Connection defined in ipsec.conf are started via stroke commands
- */
-static void start_all_connections(void)
-{
-       enumerator_t *enumerator, *children;
-       peer_cfg_t *peer_cfg;
-       child_cfg_t *child_cfg;
-       char *name;
-
-       enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends,
-                                                                                                       NULL, NULL, NULL, NULL);
-       while (enumerator->enumerate(enumerator, &peer_cfg))
-       {
-               if (peer_cfg->get_ike_version(peer_cfg) != 2)
-               {
-                       continue;
-               }
-
-               children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
-               while (children->enumerate(children, &child_cfg))
-               {
-                       name = child_cfg->get_name(child_cfg);
-
-                       switch (child_cfg->get_start_action(child_cfg))
-                       {
-                               case ACTION_RESTART:
-                                       charon->controller->initiate(charon->controller,
-                                                                                                peer_cfg->get_ref(peer_cfg),
-                                                                                                child_cfg->get_ref(child_cfg),
-                                                                                                NULL, NULL);
-                                       break;
-                               case ACTION_ROUTE:
-                                       if (charon->traps->install(charon->traps, peer_cfg, child_cfg))
-                                       {
-                                               DBG1(DBG_CFG, "configuration '%s' routed", name);
-                                       }
-                                       else
-                                       {
-                                               DBG1(DBG_CFG, "routing configuration '%s' failed", name);
-                                       }
-                                       break;
-                               case ACTION_NONE:
-                                       break;
-                       }
-               }
-               children->destroy(children);
-       }
-       enumerator->destroy(enumerator);
-}
-
 METHOD(stroke_control_t, initiate, void,
        private_stroke_control_t *this, stroke_msg_t *msg, FILE *out)
 {
@@ -152,12 +99,6 @@ METHOD(stroke_control_t, initiate, void,
        child_cfg_t *child_cfg;
        stroke_log_info_t info;
 
-       if (streq(msg->initiate.name, "%startall"))
-       {
-               start_all_connections();
-               return;
-       }
-
        peer_cfg = charon->backends->get_peer_cfg_by_name(charon->backends,
                                                                                                          msg->initiate.name);
        if (peer_cfg == NULL)
diff --git a/src/libcharon/processing/jobs/start_action_job.c b/src/libcharon/processing/jobs/start_action_job.c
new file mode 100644 (file)
index 0000000..9ffe9b0
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (C) 2011 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "start_action_job.h"
+
+#include <daemon.h>
+
+
+typedef struct private_start_action_job_t private_start_action_job_t;
+
+/**
+ * Private data of an start_action_job_t object.
+ */
+struct private_start_action_job_t {
+       /**
+        * Public start_action_job_t interface.
+        */
+       start_action_job_t public;
+};
+
+METHOD(job_t, destroy, void,
+       private_start_action_job_t *this)
+{
+       free(this);
+}
+
+METHOD(job_t, execute, void,
+       private_start_action_job_t *this)
+{
+       enumerator_t *enumerator, *children;
+       peer_cfg_t *peer_cfg;
+       child_cfg_t *child_cfg;
+       char *name;
+
+       enumerator = charon->backends->create_peer_cfg_enumerator(charon->backends,
+                                                                                                       NULL, NULL, NULL, NULL);
+       while (enumerator->enumerate(enumerator, &peer_cfg))
+       {
+               if (peer_cfg->get_ike_version(peer_cfg) != 2)
+               {
+                       continue;
+               }
+
+               children = peer_cfg->create_child_cfg_enumerator(peer_cfg);
+               while (children->enumerate(children, &child_cfg))
+               {
+                       name = child_cfg->get_name(child_cfg);
+
+                       switch (child_cfg->get_start_action(child_cfg))
+                       {
+                               case ACTION_RESTART:
+                                       DBG1(DBG_JOB, "start action: initiate '%s'", name);
+                                       charon->controller->initiate(charon->controller,
+                                                                                                peer_cfg->get_ref(peer_cfg),
+                                                                                                child_cfg->get_ref(child_cfg),
+                                                                                                NULL, NULL);
+                                       break;
+                               case ACTION_ROUTE:
+                                       DBG1(DBG_JOB, "start action: route '%s'", name);
+                                       charon->traps->install(charon->traps, peer_cfg, child_cfg);
+                                       break;
+                               case ACTION_NONE:
+                                       break;
+                       }
+               }
+               children->destroy(children);
+       }
+       enumerator->destroy(enumerator);
+       free(this);
+}
+
+/*
+ * Described in header
+ */
+start_action_job_t *start_action_job_create(void)
+{
+       private_start_action_job_t *this;
+
+       INIT(this,
+               .public = {
+                       .job_interface = {
+                               .execute = _execute,
+                               .destroy = _destroy,
+                       },
+               },
+       )
+       return &this->public;
+}
+
diff --git a/src/libcharon/processing/jobs/start_action_job.h b/src/libcharon/processing/jobs/start_action_job.h
new file mode 100644 (file)
index 0000000..ffc167c
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 Andreas Steffen
+ * HSR Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+/**
+ * @defgroup start_action_job start_action_job
+ * @{ @ingroup cjobs
+ */
+
+#ifndef START_ACTION_JOB_H_
+#define START_ACTION_JOB_H_
+
+typedef struct start_action_job_t start_action_job_t;
+
+#include <library.h>
+#include <processing/jobs/job.h>
+
+/**
+ * Class representing a start_action Job.
+ *
+ * This job handles all child configurations stored in an [SQL database]
+ * backend according to their start_action field (start, route, none).
+ */
+struct start_action_job_t {
+       /**
+        * The job_t interface.
+        */
+       job_t job_interface;
+};
+
+/**
+ * Creates a job of type start_action.
+ *
+ * @return                     start_action_job_t object
+ */
+start_action_job_t *start_action_job_create(void);
+
+#endif /** START_ACTION_JOB_H_ @}*/
index 0fe12ec..5a537e1 100644 (file)
@@ -6,10 +6,8 @@ moon::cat /etc/ipsec.d/ipsec.sql | sqlite3 /etc/ipsec.d/ipsec.db
 sun::cat /etc/ipsec.d/ipsec.sql | sqlite3 /etc/ipsec.d/ipsec.db
 moon::/etc/init.d/iptables start 2> /dev/null
 sun::/etc/init.d/iptables start 2> /dev/null
-moon::ipsec start
 sun::ipsec start
+moon::ipsec start
 moon::sleep 1
-moon::ipsec up %startall
-sun::ipsec up %startall
 alice::ping -c 1 PH_IP_BOB
 bob::ping -c 1 PH_IP_VENUS
index 51fd0c6..3e16896 100644 (file)
@@ -6,9 +6,6 @@ moon::cat /etc/ipsec.d/ipsec.sql | sqlite3 /etc/ipsec.d/ipsec.db
 sun::cat /etc/ipsec.d/ipsec.sql | sqlite3 /etc/ipsec.d/ipsec.db
 moon::/etc/init.d/iptables start 2> /dev/null
 sun::/etc/init.d/iptables start 2> /dev/null
-moon::ipsec start
 sun::ipsec start
-moon::sleep 1
-moon::ipsec up %startall
-sun::ipsec up %startall
+moon::ipsec start
 moon::sleep 2