Moved update SA job creation to kernel event handler.

This commit is contained in:
Tobias Brunner
2010-09-02 19:01:24 +02:00
parent a22853b302
commit 01563352e8
4 changed files with 22 additions and 19 deletions
+14
View File
@@ -20,6 +20,7 @@
#include <processing/jobs/acquire_job.h> #include <processing/jobs/acquire_job.h>
#include <processing/jobs/rekey_child_sa_job.h> #include <processing/jobs/rekey_child_sa_job.h>
#include <processing/jobs/delete_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; typedef struct private_kernel_handler_t private_kernel_handler_t;
@@ -74,6 +75,18 @@ METHOD(kernel_listener_t, expire, bool,
return TRUE; 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, METHOD(kernel_handler_t, destroy, void,
private_kernel_handler_t *this) private_kernel_handler_t *this)
{ {
@@ -91,6 +104,7 @@ kernel_handler_t *kernel_handler_create()
.listener = { .listener = {
.acquire = _acquire, .acquire = _acquire,
.expire = _expire, .expire = _expire,
.mapping = _mapping,
}, },
.destroy = _destroy, .destroy = _destroy,
}, },
@@ -33,7 +33,6 @@
#include <threading/thread.h> #include <threading/thread.h>
#include <threading/mutex.h> #include <threading/mutex.h>
#include <processing/jobs/callback_job.h> #include <processing/jobs/callback_job.h>
#include <processing/jobs/update_sa_job.h>
/** default timeout for generated SPIs (in seconds) */ /** default timeout for generated SPIs (in seconds) */
#define SPI_TIMEOUT 30 #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; pfkey_msg_t response;
u_int32_t spi, reqid; u_int32_t spi, reqid;
host_t *old_src, *new_src; host_t *old_src, *new_src;
job_t *job;
DBG2(DBG_KNL, "received an SADB_X_NAT_T_NEW_MAPPING"); 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); new_src = host_create_from_sockaddr(addr);
if (new_src) if (new_src)
{ {
DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and" charon->kernel_interface->mapping(charon->kernel_interface, reqid,
" reqid {%d} changed, queuing update job", ntohl(spi), reqid); spi, new_src);
job = (job_t*)update_sa_job_create(reqid, new_src);
hydra->processor->queue_job(hydra->processor, job);
} }
} }
} }
@@ -42,7 +42,6 @@
#include <utils/hashtable.h> #include <utils/hashtable.h>
#include <processing/jobs/callback_job.h> #include <processing/jobs/callback_job.h>
#include <processing/jobs/migrate_job.h> #include <processing/jobs/migrate_job.h>
#include <processing/jobs/update_sa_job.h>
/** required for Linux 2.6.26 kernel and later */ /** required for Linux 2.6.26 kernel and later */
#ifndef XFRM_STATE_AF_UNSPEC #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, static void process_mapping(private_kernel_netlink_ipsec_t *this,
struct nlmsghdr *hdr) struct nlmsghdr *hdr)
{ {
job_t *job;
u_int32_t spi, reqid; u_int32_t spi, reqid;
struct xfrm_user_mapping *mapping; struct xfrm_user_mapping *mapping;
host_t *host; host_t *host;
@@ -722,10 +720,8 @@ static void process_mapping(private_kernel_netlink_ipsec_t *this,
mapping->new_sport); mapping->new_sport);
if (host) if (host)
{ {
DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and " charon->kernel_interface->mapping(charon->kernel_interface, reqid,
"reqid {%u} changed, queuing update job", ntohl(spi), reqid); spi, host);
job = (job_t*)update_sa_job_create(reqid, host);
hydra->processor->queue_job(hydra->processor, job);
} }
} }
} }
@@ -61,7 +61,6 @@
#include <threading/mutex.h> #include <threading/mutex.h>
#include <processing/jobs/callback_job.h> #include <processing/jobs/callback_job.h>
#include <processing/jobs/migrate_job.h> #include <processing/jobs/migrate_job.h>
#include <processing/jobs/update_sa_job.h>
/** non linux specific */ /** non linux specific */
#ifndef IPPROTO_COMP #ifndef IPPROTO_COMP
@@ -1040,7 +1039,6 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
pfkey_msg_t response; pfkey_msg_t response;
u_int32_t spi, reqid; u_int32_t spi, reqid;
host_t *host; host_t *host;
job_t *job;
DBG2(DBG_KNL, "received an SADB_X_NAT_T_NEW_MAPPING"); 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) 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; return;
} }
@@ -1080,10 +1079,8 @@ static void process_mapping(private_kernel_pfkey_ipsec_t *this, struct sadb_msg*
host = host_create_from_sockaddr(sa); host = host_create_from_sockaddr(sa);
if (host) if (host)
{ {
DBG1(DBG_KNL, "NAT mappings of ESP CHILD_SA with SPI %.8x and " charon->kernel_interface->mapping(charon->kernel_interface, reqid,
"reqid {%u} changed, queuing update job", ntohl(spi), reqid); spi, host);
job = (job_t*)update_sa_job_create(reqid, host);
hydra->processor->queue_job(hydra->processor, job);
} }
} }
} }