Moving charon to libcharon.
[strongswan.git] / src / libcharon / processing / jobs / update_sa_job.c
1 /*
2 * Copyright (C) 2008 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
16 #include <stdlib.h>
17
18 #include "update_sa_job.h"
19
20 #include <sa/ike_sa.h>
21 #include <daemon.h>
22
23
24 typedef struct private_update_sa_job_t private_update_sa_job_t;
25
26 /**
27 * Private data of an update_sa_job_t Object
28 */
29 struct private_update_sa_job_t {
30 /**
31 * public update_sa_job_t interface
32 */
33 update_sa_job_t public;
34
35 /**
36 * reqid of the CHILD_SA
37 */
38 u_int32_t reqid;
39
40 /**
41 * New SA address and port
42 */
43 host_t *new;
44 };
45
46 /**
47 * Implements job_t.destroy.
48 */
49 static void destroy(private_update_sa_job_t *this)
50 {
51 this->new->destroy(this->new);
52 free(this);
53 }
54
55 /**
56 * Implementation of job_t.execute.
57 */
58 static void execute(private_update_sa_job_t *this)
59 {
60 ike_sa_t *ike_sa;
61
62 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
63 this->reqid, TRUE);
64 if (ike_sa == NULL)
65 {
66 DBG1(DBG_JOB, "CHILD_SA with reqid %d not found for update", this->reqid);
67 }
68 else
69 {
70 /* we update only if other host is NATed, but not our */
71 if (ike_sa->has_condition(ike_sa, COND_NAT_THERE) &&
72 !ike_sa->has_condition(ike_sa, COND_NAT_HERE))
73 {
74 ike_sa->update_hosts(ike_sa, NULL, this->new);
75 }
76 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
77 }
78 destroy(this);
79 }
80
81 /*
82 * Described in header
83 */
84 update_sa_job_t *update_sa_job_create(u_int32_t reqid, host_t *new)
85 {
86 private_update_sa_job_t *this = malloc_thing(private_update_sa_job_t);
87
88 this->public.job_interface.execute = (void (*) (job_t *)) execute;
89 this->public.job_interface.destroy = (void (*) (job_t *)) destroy;
90
91 this->reqid = reqid;
92 this->new = new;
93
94 return &this->public;
95 }
96