1- From db627ec8a8e72bc6b23dc8ab00f4e6b4f448d01c Mon Sep 17 00:00:00 2001
1+ From 309525ae10f390991f3bda79596142ba14b4994d Mon Sep 17 00:00:00 2001
22From: =?UTF-8?q?Timo=20Ter=C3=A4s?= <timo.teras@iki.fi>
33Date: Mon, 21 Sep 2015 13:41:58 +0300
4- Subject: [PATCH 1/3] charon: add optional source and remote overrides for
5- initiate
4+ Subject: [PATCH] charon: add optional source and remote overrides for initiate
65MIME-Version: 1.0
76Content-Type: text/plain; charset=UTF-8
87Content-Transfer-Encoding: 8bit
@@ -21,19 +20,19 @@ Signed-off-by: Timo Teräs <timo.teras@iki.fi>
2120 src/libcharon/control/controller.h | 3 +
2221 src/libcharon/plugins/stroke/stroke_control.c | 5 +-
2322 src/libcharon/plugins/vici/vici_config.c | 2 +-
24- src/libcharon/plugins/vici/vici_control.c | 64 ++++++++++++++++---
23+ src/libcharon/plugins/vici/vici_control.c | 65 ++++++++++++++++---
2524 .../processing/jobs/start_action_job.c | 2 +-
26- src/libcharon/sa/ike_sa_manager.c | 50 ++++++++++++++ -
25+ src/libcharon/sa/ike_sa_manager.c | 50 +++++++++++++-
2726 src/libcharon/sa/ike_sa_manager.h | 8 ++-
2827 src/libcharon/sa/trap_manager.c | 44 +++++--------
2928 src/swanctl/commands/initiate.c | 40 +++++++++++-
30- 11 files changed, 215 insertions(+), 47 deletions(-)
29+ 11 files changed, 216 insertions(+), 47 deletions(-)
3130
3231diff --git a/src/charon-cmd/cmd/cmd_connection.c b/src/charon-cmd/cmd/cmd_connection.c
33- index 2e2cb3c..b9369a8 100644
32+ index 65e522765..bfa07b812 100644
3433--- a/src/charon-cmd/cmd/cmd_connection.c
3534+++ b/src/charon-cmd/cmd/cmd_connection.c
36- @@ -439 ,7 +439 ,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
35+ @@ -453 ,7 +453 ,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
3736 child_cfg = create_child_cfg(this, peer_cfg);
3837
3938 if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
@@ -43,7 +42,7 @@ index 2e2cb3c..b9369a8 100644
4342 terminate(pid);
4443 }
4544diff --git a/src/libcharon/control/controller.c b/src/libcharon/control/controller.c
46- index 027f48e..4ce8616 100644
45+ index 42a4822bb..99133ee94 100644
4746--- a/src/libcharon/control/controller.c
4847+++ b/src/libcharon/control/controller.c
4948@@ -15,6 +15,28 @@
@@ -92,32 +91,31 @@ index 027f48e..4ce8616 100644
9291 /**
9392 * unique ID, used for various methods
9493 */
95- @@ -417,10 +449,15 @@ METHOD(job_t, initiate_execute, job_requeue_t,
94+ @@ -438,9 +470,14 @@ METHOD(job_t, initiate_execute, job_requeue_t,
95+ {
9696 ike_sa_t *ike_sa;
9797 interface_listener_t *listener = &job->listener;
98- peer_cfg_t *peer_cfg = listener->peer_cfg;
9998+ host_t *my_host = listener->my_host;
10099+ host_t *other_host = listener->other_host;
101100
102101 ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
103- - peer_cfg);
104- + peer_cfg, my_host, other_host);
105- peer_cfg->destroy(peer_cfg);
102+ - listener->peer_cfg);
103+ + listener->peer_cfg, my_host, other_host);
106104+ DESTROY_IF(my_host);
107105+ DESTROY_IF(other_host);
108106+
109107 if (!ike_sa)
110108 {
111- DESTROY_IF( listener->child_cfg) ;
112- @@ -499 ,6 +536 ,7 @@ METHOD(job_t, initiate_execute, job_requeue_t,
109+ listener->status = FAILED ;
110+ @@ -520 ,6 +557 ,7 @@ METHOD(job_t, initiate_execute, job_requeue_t,
113111
114112 METHOD(controller_t, initiate, status_t,
115113 private_controller_t *this, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
116114+ host_t *my_host, host_t *other_host,
117115 controller_cb_t callback, void *param, level_t max_level, u_int timeout,
118116 bool limits)
119117 {
120- @@ -523 ,6 +561 ,8 @@ METHOD(controller_t, initiate, status_t,
118+ @@ -545 ,6 +583 ,8 @@ METHOD(controller_t, initiate, status_t,
121119 .status = FAILED,
122120 .child_cfg = child_cfg,
123121 .peer_cfg = peer_cfg,
@@ -127,7 +125,7 @@ index 027f48e..4ce8616 100644
127125 .options.limits = limits,
128126 },
129127diff --git a/src/libcharon/control/controller.h b/src/libcharon/control/controller.h
130- index 36a1d46..a130fbb 100644
128+ index 36a1d4631..a130fbb6b 100644
131129--- a/src/libcharon/control/controller.h
132130+++ b/src/libcharon/control/controller.h
133131@@ -81,6 +81,8 @@ struct controller_t {
@@ -148,7 +146,7 @@ index 36a1d46..a130fbb 100644
148146 level_t max_level, u_int timeout, bool limits);
149147
150148diff --git a/src/libcharon/plugins/stroke/stroke_control.c b/src/libcharon/plugins/stroke/stroke_control.c
151- index 2824c93..21ff6b3 100644
149+ index 2824c93cb..21ff6b31f 100644
152150--- a/src/libcharon/plugins/stroke/stroke_control.c
153151+++ b/src/libcharon/plugins/stroke/stroke_control.c
154152@@ -109,7 +109,7 @@ static void charon_initiate(private_stroke_control_t *this, peer_cfg_t *peer_cfg
@@ -171,11 +169,11 @@ index 2824c93..21ff6b3 100644
171169 switch (status)
172170 {
173171diff --git a/src/libcharon/plugins/vici/vici_config.c b/src/libcharon/plugins/vici/vici_config.c
174- index 5221225..b1486e3 100644
172+ index dd426df53..324935be1 100644
175173--- a/src/libcharon/plugins/vici/vici_config.c
176174+++ b/src/libcharon/plugins/vici/vici_config.c
177- @@ -2252 ,7 +2252 ,7 @@ static void run_start_action(private_vici_config_t *this, peer_cfg_t *peer_cfg,
178- DBG1(DBG_CFG, "initiating '%s'", child_cfg->get_name(child_cfg));
175+ @@ -2395 ,7 +2395 ,7 @@ static void run_start_action(private_vici_config_t *this, peer_cfg_t *peer_cfg,
176+ DBG1(DBG_CFG, "vici initiating '%s'", child_cfg->get_name(child_cfg));
179177 charon->controller->initiate(charon->controller,
180178 peer_cfg->get_ref(peer_cfg), child_cfg->get_ref(child_cfg),
181179- NULL, NULL, 0, 0, FALSE);
@@ -184,7 +182,7 @@ index 5221225..b1486e3 100644
184182 }
185183
186184diff --git a/src/libcharon/plugins/vici/vici_control.c b/src/libcharon/plugins/vici/vici_control.c
187- index 1c236d2..811d8db 100644
185+ index 1c236d249..811d8dbc7 100644
188186--- a/src/libcharon/plugins/vici/vici_control.c
189187+++ b/src/libcharon/plugins/vici/vici_control.c
190188@@ -15,6 +15,28 @@
@@ -300,7 +298,7 @@ index 1c236d2..811d8db 100644
300298
301299 /**
302300diff --git a/src/libcharon/processing/jobs/start_action_job.c b/src/libcharon/processing/jobs/start_action_job.c
303- index 122e5ce..dec458c 100644
301+ index 122e5cee9..dec458c84 100644
304302--- a/src/libcharon/processing/jobs/start_action_job.c
305303+++ b/src/libcharon/processing/jobs/start_action_job.c
306304@@ -84,7 +84,7 @@ METHOD(job_t, execute, job_requeue_t,
@@ -313,7 +311,7 @@ index 122e5ce..dec458c 100644
313311 }
314312 children->destroy(children);
315313diff --git a/src/libcharon/sa/ike_sa_manager.c b/src/libcharon/sa/ike_sa_manager.c
316- index fc31c2a..51e28bc 100644
314+ index 7796efb65..39852578d 100644
317315--- a/src/libcharon/sa/ike_sa_manager.c
318316+++ b/src/libcharon/sa/ike_sa_manager.c
319317@@ -16,6 +16,28 @@
@@ -345,7 +343,7 @@ index fc31c2a..51e28bc 100644
345343 #include <string.h>
346344 #include <inttypes.h>
347345
348- @@ -1497 ,7 +1519 ,8 @@ typedef struct {
346+ @@ -1515 ,7 +1537 ,8 @@ typedef struct {
349347 } config_entry_t;
350348
351349 METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
@@ -355,7 +353,7 @@ index fc31c2a..51e28bc 100644
355353 {
356354 enumerator_t *enumerator;
357355 entry_t *entry;
358- @@ -1508 ,7 +1531 ,17 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
356+ @@ -1526 ,7 +1549 ,17 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
359357 u_int segment;
360358 int i;
361359
@@ -374,7 +372,7 @@ index fc31c2a..51e28bc 100644
374372
375373 if (!this->reuse_ikesa && peer_cfg->get_ike_version(peer_cfg) != IKEV1)
376374 { /* IKE_SA reuse disabled by config (not possible for IKEv1) */
377- @@ -1566 ,6 +1599 ,15 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
375+ @@ -1586 ,6 +1619 ,15 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
378376 continue;
379377 }
380378
@@ -390,7 +388,7 @@ index fc31c2a..51e28bc 100644
390388 current_peer = entry->ike_sa->get_peer_cfg(entry->ike_sa);
391389 if (current_peer && current_peer->equals(current_peer, peer_cfg))
392390 {
393- @@ -1592 ,6 +1634 ,10 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
391+ @@ -1612 ,6 +1654 ,10 @@ METHOD(ike_sa_manager_t, checkout_by_config, ike_sa_t*,
394392 {
395393 ike_sa->set_peer_cfg(ike_sa, peer_cfg);
396394 checkout_new(this, ike_sa);
@@ -402,7 +400,7 @@ index fc31c2a..51e28bc 100644
402400 }
403401 charon->bus->set_sa(charon->bus, ike_sa);
404402diff --git a/src/libcharon/sa/ike_sa_manager.h b/src/libcharon/sa/ike_sa_manager.h
405- index 004cc22..50f8246 100644
403+ index 004cc2216..50f8246f8 100644
406404--- a/src/libcharon/sa/ike_sa_manager.h
407405+++ b/src/libcharon/sa/ike_sa_manager.h
408406@@ -123,7 +123,8 @@ struct ike_sa_manager_t {
@@ -430,19 +428,19 @@ index 004cc22..50f8246 100644
430428 /**
431429 * Reset initiator SPI.
432430diff --git a/src/libcharon/sa/trap_manager.c b/src/libcharon/sa/trap_manager.c
433- index d8d8a42..e7c906e 100644
431+ index 90a29b29b..0d8447bfe 100644
434432--- a/src/libcharon/sa/trap_manager.c
435433+++ b/src/libcharon/sa/trap_manager.c
436- @@ -523 ,7 +523 ,7 @@ METHOD(trap_manager_t, acquire, void,
434+ @@ -532 ,7 +532 ,7 @@ METHOD(trap_manager_t, acquire, void,
437435 peer_cfg_t *peer;
438436 child_cfg_t *child;
439437 ike_sa_t *ike_sa;
440- - host_t *host;
441- + host_t *host, *my_host = NULL, *other_host = NULL;
442- bool wildcard, ignore = FALSE;
438+ - host_t *host = NULL;
439+ + host_t *host = NULL, *my_host = NULL, *other_host = NULL;
440+ uint32_t allocated_reqid, seq = 0;
441+ bool wildcard;
443442
444- this->lock->read_lock(this->lock);
445- @@ -600,37 +600,27 @@ METHOD(trap_manager_t, acquire, void,
443+ @@ -617,37 +617,27 @@ METHOD(trap_manager_t, acquire, void,
446444 this->lock->unlock(this->lock);
447445
448446 if (wildcard)
@@ -457,34 +455,32 @@ index d8d8a42..e7c906e 100644
457455-
458456- ike_sa->set_peer_cfg(ike_sa, peer);
459457- ike_cfg = ike_sa->get_ike_cfg(ike_sa);
460- -
458+ + {
459+ + ike_cfg_t *ike_cfg;
460+ + uint16_t port;
461+ + uint8_t mask;
462+
461463- port = ike_cfg->get_other_port(ike_cfg);
462464- data->dst->to_subnet(data->dst, &host, &mask);
463465- host->set_port(host, port);
464466- ike_sa->set_other_host(ike_sa, host);
465- -
467+ + ike_cfg = peer->get_ike_cfg(peer);
468+
466469- port = ike_cfg->get_my_port(ike_cfg);
467470- data->src->to_subnet(data->src, &host, &mask);
468471- host->set_port(host, port);
469472- ike_sa->set_my_host(ike_sa, host);
470- -
473+ + port = ike_cfg->get_other_port(ike_cfg);
474+ + data->dst->to_subnet(data->dst, &other_host, &mask);
475+ + other_host->set_port(other_host, port);
476+
471477- charon->bus->set_sa(charon->bus, ike_sa);
472478- }
473479- }
474480- else
475- {
481+ - {
476482- ike_sa = charon->ike_sa_manager->checkout_by_config(
477483- charon->ike_sa_manager, peer);
478- + ike_cfg_t *ike_cfg;
479- + uint16_t port;
480- + uint8_t mask;
481- +
482- + ike_cfg = peer->get_ike_cfg(peer);
483- +
484- + port = ike_cfg->get_other_port(ike_cfg);
485- + data->dst->to_subnet(data->dst, &other_host, &mask);
486- + other_host->set_port(other_host, port);
487- +
488484+ port = ike_cfg->get_my_port(ike_cfg);
489485+ data->src->to_subnet(data->src, &my_host, &mask);
490486+ my_host->set_port(my_host, port);
@@ -499,7 +495,7 @@ index d8d8a42..e7c906e 100644
499495 if (ike_sa)
500496 {
501497diff --git a/src/swanctl/commands/initiate.c b/src/swanctl/commands/initiate.c
502- index e0fffb9..dcaded5 100644
498+ index e0fffb907..dcaded59d 100644
503499--- a/src/swanctl/commands/initiate.c
504500+++ b/src/swanctl/commands/initiate.c
505501@@ -14,6 +14,28 @@
@@ -577,3 +573,6 @@ index e0fffb9..dcaded5 100644
577573 {"timeout", 't', 1, "timeout in seconds before detaching"},
578574 {"raw", 'r', 0, "dump raw response message"},
579575 {"pretty", 'P', 0, "dump raw response message in pretty print"},
576+ - -
577+ 2.51.2
578+
0 commit comments