2 * Copyright (C) 2008 Andreas Steffen
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 "migrate_job.h"
20 #include <config/child_cfg.h>
23 typedef struct private_migrate_job_t private_migrate_job_t
;
26 * Private data of a migrate_job_t object.
28 struct private_migrate_job_t
{
30 * Public migrate_job_t interface.
35 * reqid of the CHILD_SA if it already exists
40 * source traffic selector
42 traffic_selector_t
*src_ts
;
45 * destination traffic selector
47 traffic_selector_t
*dst_ts
;
50 * local host address to be used for IKE
55 * remote host address to be used for IKE
60 METHOD(job_t
, destroy
, void,
61 private_migrate_job_t
*this)
63 DESTROY_IF(this->src_ts
);
64 DESTROY_IF(this->dst_ts
);
65 DESTROY_IF(this->local
);
66 DESTROY_IF(this->remote
);
70 METHOD(job_t
, execute
, job_requeue_t
,
71 private_migrate_job_t
*this)
73 ike_sa_t
*ike_sa
= NULL
;
77 ike_sa
= charon
->ike_sa_manager
->checkout_by_id(charon
->ike_sa_manager
,
82 enumerator_t
*children
, *enumerator
;
87 children
= ike_sa
->create_child_sa_enumerator(ike_sa
);
88 while (children
->enumerate(children
, (void**)&child_sa
))
90 if (child_sa
->get_reqid(child_sa
) == this->reqid
)
95 children
->destroy(children
);
96 DBG2(DBG_JOB
, "found CHILD_SA with reqid {%d}", this->reqid
);
98 ike_sa
->set_kmaddress(ike_sa
, this->local
, this->remote
);
100 host
= this->local
->clone(this->local
);
101 host
->set_port(host
, charon
->socket
->get_port(charon
->socket
, FALSE
));
102 ike_sa
->set_my_host(ike_sa
, host
);
104 host
= this->remote
->clone(this->remote
);
105 host
->set_port(host
, IKEV2_UDP_PORT
);
106 ike_sa
->set_other_host(ike_sa
, host
);
108 vips
= linked_list_create();
109 enumerator
= ike_sa
->create_virtual_ip_enumerator(ike_sa
, TRUE
);
110 while (enumerator
->enumerate(enumerator
, &host
))
112 vips
->insert_last(vips
, host
);
114 enumerator
->destroy(enumerator
);
116 if (child_sa
->update(child_sa
, this->local
, this->remote
, vips
,
117 ike_sa
->has_condition(ike_sa
, COND_NAT_ANY
)) == NOT_SUPPORTED
)
119 ike_sa
->rekey_child_sa(ike_sa
, child_sa
->get_protocol(child_sa
),
120 child_sa
->get_spi(child_sa
, TRUE
));
122 charon
->ike_sa_manager
->checkin(charon
->ike_sa_manager
, ike_sa
);
127 DBG1(DBG_JOB
, "no CHILD_SA found with reqid {%d}", this->reqid
);
129 return JOB_REQUEUE_NONE
;
132 METHOD(job_t
, get_priority
, job_priority_t
,
133 private_migrate_job_t
*this)
135 return JOB_PRIO_MEDIUM
;
139 * Described in header
141 migrate_job_t
*migrate_job_create(u_int32_t reqid
,
142 traffic_selector_t
*src_ts
,
143 traffic_selector_t
*dst_ts
,
145 host_t
*local
, host_t
*remote
)
147 private_migrate_job_t
*this;
153 .get_priority
= _get_priority
,
158 .src_ts
= (dir
== POLICY_OUT
) ? src_ts
: dst_ts
,
159 .dst_ts
= (dir
== POLICY_OUT
) ? dst_ts
: src_ts
,
164 return &this->public;