2 * Copyright (C) 2010 Tobias Brunner
3 * Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "kernel_handler.h"
20 #include <processing/jobs/acquire_job.h>
21 #include <processing/jobs/rekey_child_sa_job.h>
22 #include <processing/jobs/delete_child_sa_job.h>
23 #include <processing/jobs/update_sa_job.h>
25 typedef struct private_kernel_handler_t private_kernel_handler_t
;
28 * Private data of a kernel_handler_t object.
30 struct private_kernel_handler_t
{
33 * Public part of kernel_handler_t object.
35 kernel_handler_t
public;
39 METHOD(kernel_listener_t
, acquire
, bool,
40 private_kernel_handler_t
*this, u_int32_t reqid
,
41 traffic_selector_t
*src_ts
, traffic_selector_t
*dst_ts
)
46 DBG1(DBG_KNL
, "creating acquire job for policy %R === %R "
47 "with reqid {%u}", src_ts
, dst_ts
, reqid
);
51 DBG1(DBG_KNL
, "creating acquire job for policy with reqid {%u}", reqid
);
53 job
= (job_t
*)acquire_job_create(reqid
, src_ts
, dst_ts
);
54 hydra
->processor
->queue_job(hydra
->processor
, job
);
58 METHOD(kernel_listener_t
, expire
, bool,
59 private_kernel_handler_t
*this, u_int32_t reqid
, protocol_id_t protocol
,
60 u_int32_t spi
, bool hard
)
63 DBG1(DBG_KNL
, "creating %s job for %N CHILD_SA with SPI %.8x "
64 "and reqid {%u}", hard ?
"delete" : "rekey",
65 protocol_id_names
, protocol
, ntohl(spi
), reqid
);
68 job
= (job_t
*)delete_child_sa_job_create(reqid
, protocol
, spi
);
72 job
= (job_t
*)rekey_child_sa_job_create(reqid
, protocol
, spi
);
74 hydra
->processor
->queue_job(hydra
->processor
, job
);
78 METHOD(kernel_listener_t
, mapping
, bool,
79 private_kernel_handler_t
*this, u_int32_t reqid
, u_int32_t spi
,
83 DBG1(DBG_KNL
, "NAT mappings of ESP CHILD_SA with SPI %.8x and "
84 "reqid {%u} changed, queuing update job", ntohl(spi
), reqid
);
85 job
= (job_t
*)update_sa_job_create(reqid
, remote
);
86 hydra
->processor
->queue_job(hydra
->processor
, job
);
90 METHOD(kernel_handler_t
, destroy
, void,
91 private_kernel_handler_t
*this)
93 charon
->kernel_interface
->remove_listener(charon
->kernel_interface
,
94 &this->public.listener
);
98 kernel_handler_t
*kernel_handler_create()
100 private_kernel_handler_t
*this;
113 charon
->kernel_interface
->add_listener(charon
->kernel_interface
,
114 &this->public.listener
);
116 return &this->public;