Moved roam job creation to kernel event handler.
authorTobias Brunner <tobias@strongswan.org>
Tue, 6 Jul 2010 14:03:09 +0000 (16:03 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Sep 2010 17:01:25 +0000 (19:01 +0200)
src/libcharon/kernel/kernel_handler.c
src/libcharon/plugins/kernel_netlink/kernel_netlink_net.c
src/libcharon/plugins/kernel_pfroute/kernel_pfroute_net.c

index 4fae6cd..482f149 100644 (file)
@@ -21,6 +21,7 @@
 #include <processing/jobs/delete_child_sa_job.h>
 #include <processing/jobs/migrate_job.h>
 #include <processing/jobs/rekey_child_sa_job.h>
+#include <processing/jobs/roam_job.h>
 #include <processing/jobs/update_sa_job.h>
 
 typedef struct private_kernel_handler_t private_kernel_handler_t;
@@ -103,6 +104,15 @@ METHOD(kernel_listener_t, migrate, bool,
        return TRUE;
 }
 
+METHOD(kernel_listener_t, roam, bool,
+          private_kernel_handler_t *this, bool address)
+{
+       job_t *job;
+       job = (job_t*)roam_job_create(address);
+       hydra->processor->queue_job(hydra->processor, job);
+       return TRUE;
+}
+
 METHOD(kernel_handler_t, destroy, void,
           private_kernel_handler_t *this)
 {
@@ -122,6 +132,7 @@ kernel_handler_t *kernel_handler_create()
                                .expire = _expire,
                                .mapping = _mapping,
                                .migrate = _migrate,
+                               .roam = _roam,
                        },
                        .destroy = _destroy,
                },
index fa4a501..e55329e 100644 (file)
@@ -54,9 +54,8 @@
 #include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/callback_job.h>
-#include <processing/jobs/roam_job.h>
 
-/** delay before firing roam jobs (ms) */
+/** delay before firing roam events (ms) */
 #define ROAM_DELAY 100
 
 typedef struct addr_entry_t addr_entry_t;
@@ -159,7 +158,7 @@ struct private_kernel_netlink_net_t {
        int socket_events;
 
        /**
-        * time of the last roam_job
+        * time of the last roam event
         */
        timeval_t last_roam;
 
@@ -224,12 +223,22 @@ static int get_vip_refcount(private_kernel_netlink_net_t *this, host_t* ip)
 }
 
 /**
- * start a roaming job. We delay it for a second and fire only one job
- * for multiple events. Otherwise we would create too many jobs.
+ * callback function that raises the delayed roam event
  */
-static void fire_roam_job(private_kernel_netlink_net_t *this, bool address)
+static job_requeue_t roam_event(uintptr_t address)
+{
+       charon->kernel_interface->roam(charon->kernel_interface, address != 0);
+       return JOB_REQUEUE_NONE;
+}
+
+/**
+ * fire a roaming event. we delay it for a bit and fire only one event
+ * for multiple calls. otherwise we would create too many events.
+ */
+static void fire_roam_event(private_kernel_netlink_net_t *this, bool address)
 {
        timeval_t now;
+       job_t *job;
 
        time_monotonic(&now);
        if (timercmp(&now, &this->last_roam, >))
@@ -241,8 +250,11 @@ static void fire_roam_job(private_kernel_netlink_net_t *this, bool address)
                        now.tv_usec -= 1000000;
                }
                this->last_roam = now;
-               hydra->scheduler->schedule_job_ms(hydra->scheduler,
-                               (job_t*)roam_job_create(address), ROAM_DELAY);
+
+               job = (job_t*)callback_job_create((callback_job_cb_t)roam_event,
+                                                                                 (void*)(uintptr_t)(address ? 1 : 0),
+                                                                                 NULL, NULL);
+               hydra->scheduler->schedule_job_ms(hydra->scheduler, job, ROAM_DELAY);
        }
 }
 
@@ -342,7 +354,7 @@ static void process_link(private_kernel_netlink_net_t *this,
        /* send an update to all IKE_SAs */
        if (update && event)
        {
-               fire_roam_job(this, TRUE);
+               fire_roam_event(this, TRUE);
        }
 }
 
@@ -459,7 +471,7 @@ static void process_addr(private_kernel_netlink_net_t *this,
        /* send an update to all IKE_SAs */
        if (update && event && changed)
        {
-               fire_roam_job(this, TRUE);
+               fire_roam_event(this, TRUE);
        }
 }
 
@@ -495,7 +507,7 @@ static void process_route(private_kernel_netlink_net_t *this, struct nlmsghdr *h
                this->mutex->lock(this->mutex);
                if (!get_vip_refcount(this, host))
                {       /* ignore routes added for virtual IPs */
-                       fire_roam_job(this, FALSE);
+                       fire_roam_event(this, FALSE);
                }
                this->mutex->unlock(this->mutex);
                host->destroy(host);
index ab82c1e..9f40dae 100644 (file)
 #include <threading/mutex.h>
 #include <utils/linked_list.h>
 #include <processing/jobs/callback_job.h>
-#include <processing/jobs/roam_job.h>
 
 #ifndef HAVE_STRUCT_SOCKADDR_SA_LEN
 #error Cannot compile this plugin on systems where 'struct sockaddr' has no sa_len member.
 #endif
 
-/** delay before firing roam jobs (ms) */
+/** delay before firing roam events (ms) */
 #define ROAM_DELAY 100
 
 /** buffer size for PF_ROUTE messages */
@@ -146,18 +145,28 @@ struct private_kernel_pfroute_net_t
        int seq;
 
        /**
-        * time of last roam job
+        * time of last roam event
         */
        timeval_t last_roam;
 };
 
 /**
- * Start a roaming job. We delay it a bit and fire only one job
- * for multiple events. Otherwise we would create too many jobs.
+ * callback function that raises the delayed roam event
  */
-static void fire_roam_job(private_kernel_pfroute_net_t *this, bool address)
+static job_requeue_t roam_event(uintptr_t address)
+{
+       charon->kernel_interface->roam(charon->kernel_interface, address != 0);
+       return JOB_REQUEUE_NONE;
+}
+
+/**
+ * fire a roaming event. we delay it for a bit and fire only one event
+ * for multiple calls. otherwise we would create too many events.
+ */
+static void fire_roam_event(private_kernel_pfroute_net_t *this, bool address)
 {
        timeval_t now;
+       job_t *job;
 
        time_monotonic(&now);
        if (timercmp(&now, &this->last_roam, >))
@@ -169,8 +178,11 @@ static void fire_roam_job(private_kernel_pfroute_net_t *this, bool address)
                        now.tv_usec -= 1000000;
                }
                this->last_roam = now;
-               hydra->scheduler->schedule_job_ms(hydra->scheduler,
-                       (job_t*)roam_job_create(address), ROAM_DELAY);
+
+               job = (job_t*)callback_job_create((callback_job_cb_t)roam_event,
+                                                                                 (void*)(uintptr_t)(address ? 1 : 0),
+                                                                                 NULL, NULL);
+               hydra->scheduler->schedule_job_ms(hydra->scheduler, job, ROAM_DELAY);
        }
 }
 
@@ -262,7 +274,7 @@ static void process_addr(private_kernel_pfroute_net_t *this,
 
        if (roam)
        {
-               fire_roam_job(this, TRUE);
+               fire_roam_event(this, TRUE);
        }
 }
 
@@ -307,7 +319,7 @@ static void process_link(private_kernel_pfroute_net_t *this,
 
        if (roam)
        {
-               fire_roam_job(this, TRUE);
+               fire_roam_event(this, TRUE);
        }
 }