Moved roam job creation to kernel event handler.
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include <processing/jobs/delete_child_sa_job.h>
|
#include <processing/jobs/delete_child_sa_job.h>
|
||||||
#include <processing/jobs/migrate_job.h>
|
#include <processing/jobs/migrate_job.h>
|
||||||
#include <processing/jobs/rekey_child_sa_job.h>
|
#include <processing/jobs/rekey_child_sa_job.h>
|
||||||
|
#include <processing/jobs/roam_job.h>
|
||||||
#include <processing/jobs/update_sa_job.h>
|
#include <processing/jobs/update_sa_job.h>
|
||||||
|
|
||||||
typedef struct private_kernel_handler_t private_kernel_handler_t;
|
typedef struct private_kernel_handler_t private_kernel_handler_t;
|
||||||
@@ -103,6 +104,15 @@ METHOD(kernel_listener_t, migrate, bool,
|
|||||||
return TRUE;
|
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,
|
METHOD(kernel_handler_t, destroy, void,
|
||||||
private_kernel_handler_t *this)
|
private_kernel_handler_t *this)
|
||||||
{
|
{
|
||||||
@@ -122,6 +132,7 @@ kernel_handler_t *kernel_handler_create()
|
|||||||
.expire = _expire,
|
.expire = _expire,
|
||||||
.mapping = _mapping,
|
.mapping = _mapping,
|
||||||
.migrate = _migrate,
|
.migrate = _migrate,
|
||||||
|
.roam = _roam,
|
||||||
},
|
},
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -54,9 +54,8 @@
|
|||||||
#include <threading/mutex.h>
|
#include <threading/mutex.h>
|
||||||
#include <utils/linked_list.h>
|
#include <utils/linked_list.h>
|
||||||
#include <processing/jobs/callback_job.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
|
#define ROAM_DELAY 100
|
||||||
|
|
||||||
typedef struct addr_entry_t addr_entry_t;
|
typedef struct addr_entry_t addr_entry_t;
|
||||||
@@ -159,7 +158,7 @@ struct private_kernel_netlink_net_t {
|
|||||||
int socket_events;
|
int socket_events;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* time of the last roam_job
|
* time of the last roam event
|
||||||
*/
|
*/
|
||||||
timeval_t last_roam;
|
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
|
* callback function that raises the delayed roam event
|
||||||
* for multiple events. Otherwise we would create too many jobs.
|
|
||||||
*/
|
*/
|
||||||
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;
|
timeval_t now;
|
||||||
|
job_t *job;
|
||||||
|
|
||||||
time_monotonic(&now);
|
time_monotonic(&now);
|
||||||
if (timercmp(&now, &this->last_roam, >))
|
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;
|
now.tv_usec -= 1000000;
|
||||||
}
|
}
|
||||||
this->last_roam = now;
|
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 */
|
/* send an update to all IKE_SAs */
|
||||||
if (update && event)
|
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 */
|
/* send an update to all IKE_SAs */
|
||||||
if (update && event && changed)
|
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);
|
this->mutex->lock(this->mutex);
|
||||||
if (!get_vip_refcount(this, host))
|
if (!get_vip_refcount(this, host))
|
||||||
{ /* ignore routes added for virtual IPs */
|
{ /* ignore routes added for virtual IPs */
|
||||||
fire_roam_job(this, FALSE);
|
fire_roam_event(this, FALSE);
|
||||||
}
|
}
|
||||||
this->mutex->unlock(this->mutex);
|
this->mutex->unlock(this->mutex);
|
||||||
host->destroy(host);
|
host->destroy(host);
|
||||||
|
|||||||
@@ -30,13 +30,12 @@
|
|||||||
#include <threading/mutex.h>
|
#include <threading/mutex.h>
|
||||||
#include <utils/linked_list.h>
|
#include <utils/linked_list.h>
|
||||||
#include <processing/jobs/callback_job.h>
|
#include <processing/jobs/callback_job.h>
|
||||||
#include <processing/jobs/roam_job.h>
|
|
||||||
|
|
||||||
#ifndef HAVE_STRUCT_SOCKADDR_SA_LEN
|
#ifndef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||||
#error Cannot compile this plugin on systems where 'struct sockaddr' has no sa_len member.
|
#error Cannot compile this plugin on systems where 'struct sockaddr' has no sa_len member.
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/** delay before firing roam jobs (ms) */
|
/** delay before firing roam events (ms) */
|
||||||
#define ROAM_DELAY 100
|
#define ROAM_DELAY 100
|
||||||
|
|
||||||
/** buffer size for PF_ROUTE messages */
|
/** buffer size for PF_ROUTE messages */
|
||||||
@@ -146,18 +145,28 @@ struct private_kernel_pfroute_net_t
|
|||||||
int seq;
|
int seq;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* time of last roam job
|
* time of last roam event
|
||||||
*/
|
*/
|
||||||
timeval_t last_roam;
|
timeval_t last_roam;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a roaming job. We delay it a bit and fire only one job
|
* callback function that raises the delayed roam event
|
||||||
* for multiple events. Otherwise we would create too many jobs.
|
|
||||||
*/
|
*/
|
||||||
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;
|
timeval_t now;
|
||||||
|
job_t *job;
|
||||||
|
|
||||||
time_monotonic(&now);
|
time_monotonic(&now);
|
||||||
if (timercmp(&now, &this->last_roam, >))
|
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;
|
now.tv_usec -= 1000000;
|
||||||
}
|
}
|
||||||
this->last_roam = now;
|
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)
|
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)
|
if (roam)
|
||||||
{
|
{
|
||||||
fire_roam_job(this, TRUE);
|
fire_roam_event(this, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user