]> git.ipfire.org Git - thirdparty/strongswan.git/blame - src/libcharon/processing/jobs/migrate_job.c
Make the UDP ports charon listens for packets on (and uses as source ports) configurable.
[thirdparty/strongswan.git] / src / libcharon / processing / jobs / migrate_job.c
CommitLineData
ef6d339c 1/*
bab075b1 2 * Copyright (C) 2008 Andreas Steffen
ef6d339c
AS
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.
ef6d339c
AS
14 */
15
16#include "migrate_job.h"
17
18#include <daemon.h>
19
20#include <config/child_cfg.h>
21
22
23typedef struct private_migrate_job_t private_migrate_job_t;
24
25/**
26 * Private data of a migrate_job_t object.
27 */
28struct private_migrate_job_t {
29 /**
30 * Public migrate_job_t interface.
31 */
32 migrate_job_t public;
7daf5226 33
ef6d339c
AS
34 /**
35 * reqid of the CHILD_SA if it already exists
36 */
37 u_int32_t reqid;
38
39 /**
40 * source traffic selector
41 */
42 traffic_selector_t *src_ts;
43
44 /**
45 * destination traffic selector
46 */
47 traffic_selector_t *dst_ts;
48
49 /**
bab075b1 50 * local host address to be used for IKE
ef6d339c
AS
51 */
52 host_t *local;
bab075b1
AS
53
54 /**
55 * remote host address to be used for IKE
56 */
57 host_t *remote;
ef6d339c
AS
58};
59
8125dcca
AS
60METHOD(job_t, destroy, void,
61 private_migrate_job_t *this)
ef6d339c
AS
62{
63 DESTROY_IF(this->src_ts);
64 DESTROY_IF(this->dst_ts);
65 DESTROY_IF(this->local);
bab075b1 66 DESTROY_IF(this->remote);
ef6d339c
AS
67 free(this);
68}
69
7fec83af 70METHOD(job_t, execute, job_requeue_t,
8125dcca 71 private_migrate_job_t *this)
ef6d339c
AS
72{
73 ike_sa_t *ike_sa = NULL;
7daf5226 74
ef6d339c
AS
75 if (this->reqid)
76 {
77 ike_sa = charon->ike_sa_manager->checkout_by_id(charon->ike_sa_manager,
78 this->reqid, TRUE);
79 }
d487b4b7 80 if (ike_sa)
ef6d339c 81 {
4bbce1ef 82 enumerator_t *children;
7a915d62
AS
83 child_sa_t *child_sa;
84 host_t *host;
85
4bbce1ef
TB
86 children = ike_sa->create_child_sa_enumerator(ike_sa);
87 while (children->enumerate(children, (void**)&child_sa))
7a915d62
AS
88 {
89 if (child_sa->get_reqid(child_sa) == this->reqid)
90 {
91 break;
92 }
93 }
94 children->destroy(children);
d487b4b7 95 DBG2(DBG_JOB, "found CHILD_SA with reqid {%d}", this->reqid);
7a915d62 96
d487b4b7 97 ike_sa->set_kmaddress(ike_sa, this->local, this->remote);
7a915d62
AS
98
99 host = this->local->clone(this->local);
e7ea057f 100 host->set_port(host, CHARON_UDP_PORT);
7a915d62
AS
101 ike_sa->set_my_host(ike_sa, host);
102
103 host = this->remote->clone(this->remote);
104 host->set_port(host, IKEV2_UDP_PORT);
105 ike_sa->set_other_host(ike_sa, host);
106
3aaf7908 107 if (child_sa->update(child_sa, this->local, this->remote,
7a915d62 108 ike_sa->get_virtual_ip(ike_sa, TRUE),
b9b8a98f 109 ike_sa->has_condition(ike_sa, COND_NAT_ANY)) == NOT_SUPPORTED)
7a915d62
AS
110 {
111 ike_sa->rekey_child_sa(ike_sa, child_sa->get_protocol(child_sa),
112 child_sa->get_spi(child_sa, TRUE));
113 }
d487b4b7 114 charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
ef6d339c
AS
115 }
116 else
117 {
d487b4b7 118 DBG1(DBG_JOB, "no CHILD_SA found with reqid {%d}", this->reqid);
ef6d339c 119 }
7fec83af 120 return JOB_REQUEUE_NONE;
ef6d339c
AS
121}
122
f77203bb
MW
123METHOD(job_t, get_priority, job_priority_t,
124 private_migrate_job_t *this)
125{
126 return JOB_PRIO_MEDIUM;
127}
128
ef6d339c
AS
129/*
130 * Described in header
131 */
132migrate_job_t *migrate_job_create(u_int32_t reqid,
133 traffic_selector_t *src_ts,
134 traffic_selector_t *dst_ts,
135 policy_dir_t dir,
bab075b1 136 host_t *local, host_t *remote)
ef6d339c 137{
8125dcca
AS
138 private_migrate_job_t *this;
139
140 INIT(this,
141 .public = {
142 .job_interface = {
143 .execute = _execute,
f77203bb 144 .get_priority = _get_priority,
8125dcca
AS
145 .destroy = _destroy,
146 },
147 },
148 .reqid = reqid,
149 .src_ts = (dir == POLICY_OUT) ? src_ts : dst_ts,
150 .dst_ts = (dir == POLICY_OUT) ? dst_ts : src_ts,
151 .local = local,
152 .remote = remote,
153 );
7daf5226 154
ef6d339c
AS
155 return &this->public;
156}