implemented periodic IF-MAP RenewSession request
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 2 Apr 2013 14:49:53 +0000 (16:49 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Wed, 3 Apr 2013 19:38:04 +0000 (21:38 +0200)
man/strongswan.conf.5.in
src/libcharon/plugins/tnc_ifmap/Makefile.am
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_listener.c
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c [new file with mode: 0644]
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.h [new file with mode: 0644]
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.c
src/libcharon/plugins/tnc_ifmap/tnc_ifmap_soap.h

index 99c4c76..d483add 100644 (file)
@@ -660,7 +660,10 @@ Path to private key file of IF-MAP client
 .BR charon.plugins.tnc-ifmap.device_name
 Unique name of strongSwan server as a PEP and/or PDP device
 .TP
-.BR charon.plugins.tnc-ifmap.server_uri " [https://localhost:8444/imap]
+.BR charon.plugins.tnc-ifmap.renew_session_interval " [150]"
+Interval in seconds between periodic IF-MAP RenewSession requests
+.TP
+.BR charon.plugins.tnc-ifmap.server_uri " [https://localhost:8444/imap]"
 URI of the form [https://]servername[:port][/path]
 .TP
 .BR charon.plugins.tnc-ifmap.server_cert
index d055bbc..7d8b0f5 100644 (file)
@@ -21,7 +21,8 @@ libstrongswan_tnc_ifmap_la_SOURCES = \
        tnc_ifmap_plugin.h tnc_ifmap_plugin.c \
        tnc_ifmap_listener.h tnc_ifmap_listener.c \
        tnc_ifmap_soap.h tnc_ifmap_soap.c \
-       tnc_ifmap_soap_msg.h tnc_ifmap_soap_msg.c
+       tnc_ifmap_soap_msg.h tnc_ifmap_soap_msg.c \
+       tnc_ifmap_renew_session_job.h tnc_ifmap_renew_session_job.c
 
 libstrongswan_tnc_ifmap_la_LDFLAGS = -module -avoid-version
 
index 0280b30..d204405 100644 (file)
 
 #include "tnc_ifmap_listener.h"
 #include "tnc_ifmap_soap.h"
+#include "tnc_ifmap_renew_session_job.h"
 
 #include <daemon.h>
 #include <hydra.h>
 #include <utils/debug.h>
 
+#define IFMAP_RENEW_SESSION_INTERVAL   150
+
 typedef struct private_tnc_ifmap_listener_t private_tnc_ifmap_listener_t;
 
 /**
@@ -127,6 +130,8 @@ METHOD(tnc_ifmap_listener_t, destroy, void,
 tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload)
 {
        private_tnc_ifmap_listener_t *this;
+       job_t *job;
+       u_int32_t reschedule;
 
        INIT(this,
                .public = {
@@ -168,6 +173,14 @@ tnc_ifmap_listener_t *tnc_ifmap_listener_create(bool reload)
                }
        }
 
+       /* schedule periodic transmission of IF-MAP renewSession request */
+       reschedule =  lib->settings->get_int(lib->settings,
+                                               "%s.plugins.tnc-ifmap.renew_session_interval",
+                                                IFMAP_RENEW_SESSION_INTERVAL, charon->name);
+
+       job = (job_t*)tnc_ifmap_renew_session_job_create(this->ifmap, reschedule);
+       lib->scheduler->schedule_job(lib->scheduler, job, reschedule);
+
        return &this->public;
 }
 
diff --git a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.c
new file mode 100644 (file)
index 0000000..eb20bb6
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * Copyright (C) 2013 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 <stdlib.h>
+
+#include "tnc_ifmap_renew_session_job.h"
+
+#include <daemon.h>
+
+
+typedef struct private_tnc_ifmap_renew_session_job_t private_tnc_ifmap_renew_session_job_t;
+
+/**
+ * Private data
+ */
+struct private_tnc_ifmap_renew_session_job_t {
+
+       /**
+        * public tnc_ifmap_renew_session_job_t interface
+        */
+       tnc_ifmap_renew_session_job_t public;
+
+       /**
+        * TNC IF-MAP 2.0 SOAP interface
+        */
+       tnc_ifmap_soap_t *ifmap;
+
+       /**
+        * Reschedule time interval in seconds
+        */
+       u_int32_t reschedule;
+};
+
+METHOD(job_t, destroy, void,
+       private_tnc_ifmap_renew_session_job_t *this)
+{
+       free(this);
+}
+
+METHOD(job_t, execute, job_requeue_t,
+       private_tnc_ifmap_renew_session_job_t *this)
+{
+       this->ifmap->renewSession(this->ifmap);
+
+       return JOB_RESCHEDULE(this->reschedule);
+}
+
+METHOD(job_t, get_priority, job_priority_t,
+       private_tnc_ifmap_renew_session_job_t *this)
+{
+       return JOB_PRIO_MEDIUM;
+}
+
+/*
+ * Described in header
+ */
+tnc_ifmap_renew_session_job_t *tnc_ifmap_renew_session_job_create(
+                                                               tnc_ifmap_soap_t *ifmap, u_int32_t reschedule)
+{
+       private_tnc_ifmap_renew_session_job_t *this;
+
+       INIT(this,
+               .public = {
+                       .job_interface = {
+                               .execute = _execute,
+                               .get_priority = _get_priority,
+                               .destroy = _destroy,
+                       },
+               },
+               .ifmap = ifmap,
+               .reschedule = reschedule,
+       );
+
+       return &this->public;
+}
diff --git a/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.h b/src/libcharon/plugins/tnc_ifmap/tnc_ifmap_renew_session_job.h
new file mode 100644 (file)
index 0000000..91e8fe4
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 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 tnc_ifmap_renew_session_job tnc_ifmap_renew_session_job
+ * @{ @ingroup cjobs
+ */
+
+#ifndef TNC_IFMAP_RENEW_SESSION_JOB_H_
+#define TNC_IFMAP_RENEW_SESSION_JOB_H_
+
+typedef struct tnc_ifmap_renew_session_job_t tnc_ifmap_renew_session_job_t;
+
+#include "tnc_ifmap_soap.h"
+
+#include <library.h>
+#include <processing/jobs/job.h>
+
+/**
+ * Job periodically sending an IF-MAP RenewSession request.
+ */
+struct tnc_ifmap_renew_session_job_t {
+
+       /**
+        * implements job_t interface
+        */
+       job_t job_interface;
+};
+
+/**
+ * Creates an tnc_ifmap_renew_session job.
+ *
+ * @param ifmap                TNC IF-MAP object
+ * @param reschedule   reschedule time in seconds
+ */
+tnc_ifmap_renew_session_job_t *tnc_ifmap_renew_session_job_create(
+                                                               tnc_ifmap_soap_t *ifmap, u_int32_t reschedule);
+
+#endif /** TNC_IFMAP_RENEW_SESSION_JOB_H_ @}*/
index 246b2af..d189f6f 100644 (file)
@@ -136,6 +136,26 @@ METHOD(tnc_ifmap_soap_t, newSession, bool,
     return this->session_id && this->ifmap_publisher_id;
 }
 
+METHOD(tnc_ifmap_soap_t, renewSession, bool,
+       private_tnc_ifmap_soap_t *this)
+{
+       tnc_ifmap_soap_msg_t *soap_msg;
+       xmlNodePtr request;
+       bool success;
+
+       /* build renewSession request */
+       request = xmlNewNode(NULL, "renewSession");
+       this->ns = xmlNewNs(request, IFMAP_NS, "ifmap");
+       xmlSetNs(request, this->ns);
+       xmlNewProp(request, "session-id", this->session_id);
+
+       soap_msg = tnc_ifmap_soap_msg_create(this->uri, this->user_pass, this->tls);
+       success = soap_msg->post(soap_msg, request, "renewSessionResult", NULL);
+       soap_msg->destroy(soap_msg);
+
+       return success;
+}
+
 METHOD(tnc_ifmap_soap_t, purgePublisher, bool,
        private_tnc_ifmap_soap_t *this)
 {
@@ -798,6 +818,7 @@ tnc_ifmap_soap_t *tnc_ifmap_soap_create()
        INIT(this,
                .public = {
                        .newSession = _newSession,
+                       .renewSession = _renewSession,
                        .purgePublisher = _purgePublisher,
                        .publish_ike_sa = _publish_ike_sa,
                        .publish_device_ip = _publish_device_ip,
index 5ab31ef..9c5a53b 100644 (file)
@@ -40,6 +40,13 @@ struct tnc_ifmap_soap_t {
        bool (*newSession)(tnc_ifmap_soap_t *this);
 
        /**
+        * Check if the IF-MAP session is still active
+        *
+        * @return                              TRUE if command was successful
+        */
+       bool (*renewSession)(tnc_ifmap_soap_t *this);
+
+       /**
         * Purges all metadata published by this publisher
         *
         * @return                              TRUE if command was successful