parse xfrm and pf_key acquire messages and subscribe to migrate messages
[strongswan.git] / src / charon / processing / jobs / acquire_job.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
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>.
9 *
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
13 * for more details.
14 *
15 * $Id$
16 */
17
18 #include "acquire_job.h"
19
20 #include <daemon.h>
21
22
23 typedef struct private_acquire_job_t private_acquire_job_t;
24
25 /**
26 * Private data of an acquire_job_t object.
27 */
28 struct private_acquire_job_t {
29 /**
30 * Public acquire_job_t interface.
31 */
32 acquire_job_t public;
33
34 /**
35 * reqid of the child to rekey
36 */
37 u_int32_t reqid;
38
39 /**
40 * acquired source traffic selector
41 */
42 traffic_selector_t *src_ts;
43
44 /**
45 * acquired destination traffic selector
46 */
47 traffic_selector_t *dst_ts;
48 };
49
50 /**
51 * Implementation of job_t.destroy.
52 */
53 static void destroy(private_acquire_job_t *this)
54 {
55 DESTROY_IF(this->src_ts);
56 DESTROY_IF(this->dst_ts);
57 free(this);
58 }
59
60 /**
61 * Implementation of job_t.execute.
62 */
63 static void execute(private_acquire_job_t *this)
64 {
65 ike_sa_t *ike_sa = NULL;
66
67 if (this->reqid)
68 {
69 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
70 this->reqid, TRUE);
71 }
72 if (ike_sa == NULL)
73 {
74 DBG1(DBG_JOB, "acquire job found no CHILD_SA with reqid {%d}",
75 this->reqid);
76 }
77 else
78 {
79 ike_sa->acquire(ike_sa, this->reqid);
80
81 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
82 }
83 destroy(this);
84 }
85
86 /*
87 * Described in header
88 */
89 acquire_job_t *acquire_job_create(u_int32_t reqid,
90 traffic_selector_t *src_ts,
91 traffic_selector_t *dst_ts)
92 {
93 private_acquire_job_t *this = malloc_thing(private_acquire_job_t);
94
95 /* interface functions */
96 this->public.job_interface.execute = (void (*) (job_t *)) execute;
97 this->public.job_interface.destroy = (void (*)(job_t*)) destroy;
98
99 /* private variables */
100 this->reqid = reqid;
101 this->src_ts = src_ts;
102 this->dst_ts = dst_ts;
103
104 return &this->public;
105 }