Moved acquire job creation to kernel event handler.
authorTobias Brunner <tobias@strongswan.org>
Tue, 6 Jul 2010 09:50:43 +0000 (11:50 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Sep 2010 17:01:23 +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 0e967fe..5a12e35 100644 (file)
@@ -15,7 +15,9 @@
 
 #include "kernel_handler.h"
 
+#include <hydra.h>
 #include <daemon.h>
+#include <processing/jobs/acquire_job.h>
 
 typedef struct private_kernel_handler_t private_kernel_handler_t;
 
@@ -31,6 +33,25 @@ struct private_kernel_handler_t {
 
 };
 
+METHOD(kernel_listener_t, acquire, bool,
+          private_kernel_handler_t *this, u_int32_t reqid,
+          traffic_selector_t *src_ts, traffic_selector_t *dst_ts)
+{
+       job_t *job;
+       if (src_ts && dst_ts)
+       {
+               DBG1(DBG_KNL, "creating acquire job for policy %R === %R "
+                                         "with reqid {%u}", src_ts, dst_ts, reqid);
+       }
+       else
+       {
+               DBG1(DBG_KNL, "creating acquire job for policy with reqid {%u}", reqid);
+       }
+       job = (job_t*)acquire_job_create(reqid, src_ts, dst_ts);
+       hydra->processor->queue_job(hydra->processor, job);
+       return TRUE;
+}
+
 METHOD(kernel_handler_t, destroy, void,
           private_kernel_handler_t *this)
 {
@@ -46,7 +67,7 @@ kernel_handler_t *kernel_handler_create()
        INIT(this,
                .public = {
                        .listener = {
-                               .acquire = NULL,
+                               .acquire = _acquire,
                        },
                        .destroy = _destroy,
                },
index 81e46da..d21da6f 100644 (file)
@@ -33,7 +33,6 @@
 #include <threading/thread.h>
 #include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
-#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>
@@ -1237,7 +1236,6 @@ static void process_acquire(private_kernel_klips_ipsec_t *this, struct sadb_msg*
        u_int32_t reqid;
        u_int8_t proto;
        policy_entry_t *policy;
-       job_t *job;
 
        switch (msg->sadb_msg_satype)
        {
@@ -1298,10 +1296,8 @@ static void process_acquire(private_kernel_klips_ipsec_t *this, struct sadb_msg*
 
        this->mutex->unlock(this->mutex);
 
-       DBG2(DBG_KNL, "received an SADB_ACQUIRE");
-       DBG1(DBG_KNL, "creating acquire job for CHILD_SA with reqid {%d}", reqid);
-       job = (job_t*)acquire_job_create(reqid, NULL, NULL);
-       hydra->processor->queue_job(hydra->processor, job);
+       charon->kernel_interface->acquire(charon->kernel_interface, reqid, NULL,
+                                                                         NULL);
 }
 
 /**
index 9ba5391..68fcab8 100644 (file)
@@ -41,7 +41,6 @@
 #include <threading/mutex.h>
 #include <utils/hashtable.h>
 #include <processing/jobs/callback_job.h>
-#include <processing/jobs/acquire_job.h>
 #include <processing/jobs/migrate_job.h>
 #include <processing/jobs/rekey_child_sa_job.h>
 #include <processing/jobs/delete_child_sa_job.h>
@@ -557,7 +556,6 @@ static void process_acquire(private_kernel_netlink_ipsec_t *this, struct nlmsghd
        struct xfrm_user_acquire *acquire;
        struct rtattr *rta;
        size_t rtasize;
-       job_t *job;
 
        acquire = (struct xfrm_user_acquire*)NLMSG_DATA(hdr);
        rta = XFRM_RTA(hdr, struct xfrm_user_acquire);
@@ -591,10 +589,9 @@ static void process_acquire(private_kernel_netlink_ipsec_t *this, struct nlmsghd
        }
        src_ts = selector2ts(&acquire->sel, TRUE);
        dst_ts = selector2ts(&acquire->sel, FALSE);
-       DBG1(DBG_KNL, "creating acquire job for policy %R === %R with reqid {%u}",
-                                       src_ts, dst_ts, reqid);
-       job = (job_t*)acquire_job_create(reqid, src_ts, dst_ts);
-       hydra->processor->queue_job(hydra->processor, job);
+
+       charon->kernel_interface->acquire(charon->kernel_interface, reqid, src_ts,
+                                                                         dst_ts);
 }
 
 /**
index 6773dcf..b490095 100644 (file)
@@ -60,7 +60,6 @@
 #include <threading/thread.h>
 #include <threading/mutex.h>
 #include <processing/jobs/callback_job.h>
-#include <processing/jobs/acquire_job.h>
 #include <processing/jobs/migrate_job.h>
 #include <processing/jobs/rekey_child_sa_job.h>
 #include <processing/jobs/delete_child_sa_job.h>
@@ -902,7 +901,6 @@ static void process_acquire(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
        u_int32_t index, reqid = 0;
        traffic_selector_t *src_ts, *dst_ts;
        policy_entry_t *policy;
-       job_t *job;
 
        switch (msg->sadb_msg_satype)
        {
@@ -931,17 +929,15 @@ static void process_acquire(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
        }
        else
        {
-               DBG1(DBG_KNL, "received an SADB_ACQUIRE with policy id %d but no matching policy found",
-                                          index);
+               DBG1(DBG_KNL, "received an SADB_ACQUIRE with policy id %d but no"
+                                         " matching policy found", index);
        }
        src_ts = sadb_address2ts(response.src);
        dst_ts = sadb_address2ts(response.dst);
        this->mutex->unlock(this->mutex);
 
-       DBG1(DBG_KNL, "creating acquire job for policy %R === %R with reqid {%u}",
-                                  src_ts, dst_ts, reqid);
-       job = (job_t*)acquire_job_create(reqid, src_ts, dst_ts);
-       hydra->processor->queue_job(hydra->processor, job);
+       charon->kernel_interface->acquire(charon->kernel_interface, reqid, src_ts,
+                                                                         dst_ts);
 }
 
 /**