Moved update SA job creation to kernel event handler.
authorTobias Brunner <tobias@strongswan.org>
Tue, 6 Jul 2010 10:34:15 +0000 (12:34 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Sep 2010 17:01:24 +0000 (19:01 +0200)
src/libcharon/kernel/kernel_handler.c
src/libcharon/plugins/kernel_klips/kernel_klips_ipsec.c
src/libcharon/plugins/kernel_netlink/kernel_netlink_ipsec.c
src/libcharon/plugins/kernel_pfkey/kernel_pfkey_ipsec.c

index 64907b7..b4fe1ef 100644 (file)
@@ -20,6 +20,7 @@
 #include <processing/jobs/acquire_job.h>
 #include <processing/jobs/rekey_child_sa_job.h>
 #include <processing/jobs/delete_child_sa_job.h>
+#include <processing/jobs/update_sa_job.h>
 
 typedef struct private_kernel_handler_t private_kernel_handler_t;
 
@@ -74,6 +75,18 @@ METHOD(kernel_listener_t, expire, bool,
        return TRUE;
 }
 
+METHOD(kernel_listener_t, mapping, bool,
+          private_kernel_handler_t *this, u_int32_t reqid, u_int32_t spi,
+          host_t *remote)
+{
+       job_t *job;
+       DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and "
+                                 "reqid {%u} changed, queuing update job", ntohl(spi), reqid);
+       job = (job_t*)update_sa_job_create(reqid, remote);
+       hydra->processor->queue_job(hydra->processor, job);
+       return TRUE;
+}
+
 METHOD(kernel_handler_t, destroy, void,
           private_kernel_handler_t *this)
 {
@@ -91,6 +104,7 @@ kernel_handler_t *kernel_handler_create()
                        .listener = {
                                .acquire = _acquire,
                                .expire = _expire,
+                               .mapping = _mapping,
                        },
                        .destroy = _destroy,
                },
index 390d906..6622a96 100644 (file)
@@ -33,7 +33,6 @@
 #include <threading/thread.h>
 #include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
-#include <processing/jobs/update_sa_job.h>
 
 /** default timeout for generated SPIs (in seconds) */
 #define SPI_TIMEOUT 30
@@ -1306,7 +1305,6 @@ static void process_mapping(private_kernel_klips_ipsec_t *this, struct sadb_msg*
        pfkey_msg_t response;
        u_int32_t spi, reqid;
        host_t *old_src, *new_src;
-       job_t *job;
 
        DBG2(DBG_KNL, "received an SADB_X_NAT_T_NEW_MAPPING");
 
@@ -1355,10 +1353,8 @@ static void process_mapping(private_kernel_klips_ipsec_t *this, struct sadb_msg*
                new_src = host_create_from_sockaddr(addr);
                if (new_src)
                {
-                       DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and"
-                               " reqid {%d} changed, queuing update job", ntohl(spi), reqid);
-                       job = (job_t*)update_sa_job_create(reqid, new_src);
-                       hydra->processor->queue_job(hydra->processor, job);
+                       charon->kernel_interface->mapping(charon->kernel_interface, reqid,
+                                                                                         spi, new_src);
                }
        }
 }
index b603b13..8d4d2c9 100644 (file)
@@ -42,7 +42,6 @@
 #include <utils/hashtable.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/migrate_job.h>
-#include <processing/jobs/update_sa_job.h>
 
 /** required for Linux 2.6.26 kernel and later */
 #ifndef XFRM_STATE_AF_UNSPEC
@@ -705,7 +704,6 @@ static void process_migrate(private_kernel_netlink_ipsec_t *this, struct nlmsghd
 static void process_mapping(private_kernel_netlink_ipsec_t *this,
                                                        struct nlmsghdr *hdr)
 {
-       job_t *job;
        u_int32_t spi, reqid;
        struct xfrm_user_mapping *mapping;
        host_t *host;
@@ -722,10 +720,8 @@ static void process_mapping(private_kernel_netlink_ipsec_t *this,
                                                 mapping->new_sport);
                if (host)
                {
-                       DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and "
-                               "reqid {%u} changed, queuing update job", ntohl(spi), reqid);
-                       job = (job_t*)update_sa_job_create(reqid, host);
-                       hydra->processor->queue_job(hydra->processor, job);
+                       charon->kernel_interface->mapping(charon->kernel_interface, reqid,
+                                                                                         spi, host);
                }
        }
 }
index b91b6d1..28cc980 100644 (file)
@@ -61,7 +61,6 @@
 #include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
 #include <processing/jobs/migrate_job.h>
-#include <processing/jobs/update_sa_job.h>
 
 /** non linux specific */
 #ifndef IPPROTO_COMP
@@ -1040,7 +1039,6 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
        pfkey_msg_t response;
        u_int32_t spi, reqid;
        host_t *host;
-       job_t *job;
 
        DBG2(DBG_KNL, "received an SADB_X_NAT_T_NEW_MAPPING");
 
@@ -1052,7 +1050,8 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
 
        if (!response.x_sa2)
        {
-               DBG1(DBG_KNL, "received SADB_X_NAT_T_NEW_MAPPING is missing required information");
+               DBG1(DBG_KNL, "received SADB_X_NAT_T_NEW_MAPPING is missing required "
+                                         "information");
                return;
        }
 
@@ -1080,10 +1079,8 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
                host = host_create_from_sockaddr(sa);
                if (host)
                {
-                       DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and "
-                               "reqid {%u} changed, queuing update job", ntohl(spi), reqid);
-                       job = (job_t*)update_sa_job_create(reqid, host);
-                       hydra->processor->queue_job(hydra->processor, job);
+                       charon->kernel_interface->mapping(charon->kernel_interface, reqid,
+                                                                                         spi, host);
                }
        }
 }