Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: Implement changes for dmvpn #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/charon-cmd/cmd/cmd_connection.c
Expand Up @@ -438,7 +438,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
child_cfg = create_child_cfg(this, peer_cfg);

if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
controller_cb_empty, NULL, 0, FALSE) != SUCCESS)
NULL, NULL, controller_cb_empty, NULL, 0, FALSE) != SUCCESS)
{
terminate(pid);
}
Expand Down
2 changes: 1 addition & 1 deletion src/charon-nm/nm/nm_service.c
Expand Up @@ -883,7 +883,7 @@ static gboolean connect_(NMVpnServicePlugin *plugin, NMConnection *connection,
* Prepare IKE_SA
*/
ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
peer_cfg);
peer_cfg, NULL, NULL);
peer_cfg->destroy(peer_cfg);
if (!ike_sa)
{
Expand Down
2 changes: 1 addition & 1 deletion src/conftest/actions.c
Expand Up @@ -65,7 +65,7 @@ static job_requeue_t initiate(char *config)
{
DBG1(DBG_CFG, "initiating IKE_SA for CHILD_SA config '%s'", config);
charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
NULL, NULL, 0, FALSE);
NULL, NULL, NULL, NULL, 0, FALSE);
}
else
{
Expand Down
Expand Up @@ -910,7 +910,7 @@ static job_requeue_t initiate(private_android_service_t *this)

/* get us an IKE_SA */
ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
peer_cfg);
peer_cfg, NULL, NULL);
peer_cfg->destroy(peer_cfg);
if (!ike_sa)
{
Expand Down
44 changes: 42 additions & 2 deletions src/libcharon/control/controller.c
Expand Up @@ -15,6 +15,28 @@
* for more details.
*/

/*
* Copyright (C) 2014 Timo Teräs <timo.teras@iki.fi>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "controller.h"

#include <sys/types.h>
Expand Down Expand Up @@ -102,6 +124,16 @@ struct interface_listener_t {
*/
ike_sa_t *ike_sa;

/**
* Our host hint.
*/
host_t *my_host;

/**
* Other host hint.
*/
host_t *other_host;

/**
* unique ID, used for various methods
*/
Expand Down Expand Up @@ -414,9 +446,13 @@ METHOD(job_t, initiate_execute, job_requeue_t,
ike_sa_t *ike_sa;
interface_listener_t *listener = &job->listener;
peer_cfg_t *peer_cfg = listener->peer_cfg;

host_t *my_host = listener->my_host;
host_t *other_host = listener->other_host;
ike_sa = charon->ike_sa_manager->checkout_by_config(charon->ike_sa_manager,
peer_cfg);
peer_cfg, my_host, other_host);
DESTROY_IF(my_host);
DESTROY_IF(other_host);

peer_cfg->destroy(peer_cfg);
if (!ike_sa)
{
Expand All @@ -425,6 +461,7 @@ METHOD(job_t, initiate_execute, job_requeue_t,
listener_done(listener);
return JOB_REQUEUE_NONE;
}

listener->lock->lock(listener->lock);
listener->ike_sa = ike_sa;
listener->lock->unlock(listener->lock);
Expand Down Expand Up @@ -492,6 +529,7 @@ METHOD(job_t, initiate_execute, job_requeue_t,

METHOD(controller_t, initiate, status_t,
private_controller_t *this, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
host_t *my_host, host_t *other_host,
controller_cb_t callback, void *param, u_int timeout, bool limits)
{
interface_job_t *job;
Expand All @@ -514,6 +552,8 @@ METHOD(controller_t, initiate, status_t,
.status = FAILED,
.child_cfg = child_cfg,
.peer_cfg = peer_cfg,
.my_host = my_host ? my_host->clone(my_host) : NULL,
.other_host = other_host ? other_host->clone(other_host) : NULL,
.lock = spinlock_create(),
.options.limits = limits,
},
Expand Down
3 changes: 3 additions & 0 deletions src/libcharon/control/controller.h
Expand Up @@ -79,6 +79,8 @@ struct controller_t {
*
* @param peer_cfg peer_cfg to use for IKE_SA setup
* @param child_cfg optional child_cfg to set up CHILD_SA from
* @param my_host optional address hint for source
* @param other_host optional address hint for destination
* @param cb logging callback
* @param param parameter to include in each call of cb
* @param timeout timeout in ms to wait for callbacks, 0 to disable
Expand All @@ -92,6 +94,7 @@ struct controller_t {
*/
status_t (*initiate)(controller_t *this,
peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
host_t *my_host, host_t *other_host,
controller_cb_t callback, void *param, u_int timeout,
bool limits);

Expand Down
3 changes: 2 additions & 1 deletion src/libcharon/plugins/load_tester/load_tester_control.c
Expand Up @@ -239,7 +239,8 @@ static bool on_accept(private_load_tester_control_t *this, stream_t *io)

switch (charon->controller->initiate(charon->controller,
peer_cfg, child_cfg->get_ref(child_cfg),
(void*)initiate_cb, listener, 0, FALSE))
NULL, NULL, (void*)initiate_cb,
listener, 0, FALSE))
{
case NEED_MORE:
/* Callback returns FALSE once it got track of this IKE_SA.
Expand Down
2 changes: 1 addition & 1 deletion src/libcharon/plugins/load_tester/load_tester_plugin.c
Expand Up @@ -151,7 +151,7 @@ static job_requeue_t do_load_test(private_load_tester_plugin_t *this)

charon->controller->initiate(charon->controller,
peer_cfg, child_cfg->get_ref(child_cfg),
NULL, NULL, 0, FALSE);
NULL, NULL, NULL, NULL, 0, FALSE);
if (s)
{
sleep(s);
Expand Down
3 changes: 2 additions & 1 deletion src/libcharon/plugins/medcli/medcli_config.c
Expand Up @@ -349,7 +349,8 @@ static job_requeue_t initiate_config(peer_cfg_t *peer_cfg)
peer_cfg->get_ref(peer_cfg);
enumerator->destroy(enumerator);
charon->controller->initiate(charon->controller,
peer_cfg, child_cfg, NULL, NULL, 0, FALSE);
peer_cfg, child_cfg, NULL, NULL,
NULL, NULL, 0, FALSE);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions src/libcharon/plugins/smp/smp.c
Expand Up @@ -493,8 +493,8 @@ static void request_control_initiate(xmlTextReaderPtr reader,
if (child)
{
status = charon->controller->initiate(charon->controller,
peer, child, (controller_cb_t)xml_callback,
writer, 0, FALSE);
peer, child, NULL, NULL,
(controller_cb_t)xml_callback, writer, 0, FALSE);
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/libcharon/plugins/stroke/stroke_control.c
Expand Up @@ -108,15 +108,16 @@ static void charon_initiate(private_stroke_control_t *this, peer_cfg_t *peer_cfg
if (msg->output_verbosity < 0)
{
charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
NULL, NULL, 0, FALSE);
NULL, NULL, NULL, NULL, 0, FALSE);
}
else
{
stroke_log_info_t info = { msg->output_verbosity, out };
status_t status;

status = charon->controller->initiate(charon->controller,
peer_cfg, child_cfg, (controller_cb_t)stroke_log,
peer_cfg, child_cfg, NULL, NULL,
(controller_cb_t)stroke_log,
&info, this->timeout, FALSE);
switch (status)
{
Expand Down
2 changes: 1 addition & 1 deletion src/libcharon/plugins/vici/vici_config.c
Expand Up @@ -2149,7 +2149,7 @@ static void run_start_action(private_vici_config_t *this, peer_cfg_t *peer_cfg,
DBG1(DBG_CFG, "initiating '%s'", child_cfg->get_name(child_cfg));
charon->controller->initiate(charon->controller,
peer_cfg->get_ref(peer_cfg), child_cfg->get_ref(child_cfg),
NULL, NULL, 0, FALSE);
NULL, NULL, NULL, NULL, 0, FALSE);
break;
case ACTION_ROUTE:
DBG1(DBG_CFG, "installing '%s'", child_cfg->get_name(child_cfg));
Expand Down
64 changes: 55 additions & 9 deletions src/libcharon/plugins/vici/vici_control.c
Expand Up @@ -16,6 +16,28 @@
* for more details.
*/

/*
* Copyright (C) 2014 Timo Teräs <timo.teras@iki.fi>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

#include "vici_control.h"
#include "vici_builder.h"

Expand Down Expand Up @@ -174,9 +196,11 @@ static child_cfg_t* find_child_cfg(char *name, char *pname, peer_cfg_t **out)
CALLBACK(initiate, vici_message_t*,
private_vici_control_t *this, char *name, u_int id, vici_message_t *request)
{
vici_message_t* msg;
peer_cfg_t *peer_cfg = NULL;
child_cfg_t *child_cfg;
char *child, *ike, *type, *sa;
host_t *my_host = NULL, *other_host = NULL;
char *child, *ike, *type, *sa, *my_host_str, *other_host_str;
int timeout;
bool limits;
controller_cb_t log_cb = NULL;
Expand All @@ -190,6 +214,8 @@ CALLBACK(initiate, vici_message_t*,
timeout = request->get_int(request, 0, "timeout");
limits = request->get_bool(request, FALSE, "init-limits");
log.level = request->get_int(request, 1, "loglevel");
my_host_str = request->get_str(request, NULL, "my-host");
other_host_str = request->get_str(request, NULL, "other-host");

if (!child && !ike)
{
Expand All @@ -200,31 +226,51 @@ CALLBACK(initiate, vici_message_t*,
log_cb = (controller_cb_t)log_vici;
}

if (my_host_str)
{
my_host = host_create_from_string(my_host_str, 0);
}
if (other_host_str)
{
other_host = host_create_from_string(other_host_str, 0);
}


type = child ? "CHILD_SA" : "IKE_SA";
sa = child ?: ike;

child_cfg = find_child_cfg(child, ike, &peer_cfg);

DBG1(DBG_CFG, "vici initiate %s '%s'", type, sa);
DBG1(DBG_CFG, "vici initiate %s '%s', me %H, other %H, limits %d", type, sa, my_host, other_host, limits);
if (!peer_cfg)
{
return send_reply(this, "%s config '%s' not found", type, sa);
msg = send_reply(this, "%s config '%s' not found", type, sa);
goto ret;
}
switch (charon->controller->initiate(charon->controller, peer_cfg,
child_cfg, log_cb, &log, timeout, limits))
switch (charon->controller->initiate(charon->controller,
peer_cfg, child_cfg, my_host, other_host,
log_cb, &log, timeout, limits))
{
case SUCCESS:
return send_reply(this, NULL);
msg = send_reply(this, NULL);
break;
case OUT_OF_RES:
return send_reply(this, "%s '%s' not established after %dms", type,
msg = send_reply(this, "%s '%s' not established after %dms", type,
sa, timeout);
break;
case INVALID_STATE:
return send_reply(this, "establishing %s '%s' not possible at the "
msg = send_reply(this, "establishing %s '%s' not possible at the "
"moment due to limits", type, sa);
break;
case FAILED:
default:
return send_reply(this, "establishing %s '%s' failed", type, sa);
msg = send_reply(this, "establishing %s '%s' failed", type, sa);
break;
}
ret:
if (my_host) my_host->destroy(my_host);
if (other_host) other_host->destroy(other_host);
return msg;
}

CALLBACK(terminate, vici_message_t*,
Expand Down