Merge branch 'stroke-timeout'

Add a strongswan.conf timeout option for stroke control commands.
This commit is contained in:
Martin Willi
2013-03-18 10:11:46 +01:00
2 changed files with 94 additions and 22 deletions
+12 -4
View File
@@ -363,7 +363,10 @@ METHOD(job_t, initiate_execute, job_requeue_t,
if (ike_sa->initiate(ike_sa, listener->child_cfg, 0, NULL, NULL) == SUCCESS) if (ike_sa->initiate(ike_sa, listener->child_cfg, 0, NULL, NULL) == SUCCESS)
{ {
listener->status = SUCCESS; if (!listener->logger.callback)
{
listener->status = SUCCESS;
}
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
} }
else else
@@ -454,7 +457,10 @@ METHOD(job_t, terminate_ike_execute, job_requeue_t,
} }
else else
{ {
listener->status = SUCCESS; if (!listener->logger.callback)
{
listener->status = SUCCESS;
}
charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager, charon->ike_sa_manager->checkin_and_destroy(charon->ike_sa_manager,
ike_sa); ike_sa);
} }
@@ -561,7 +567,10 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa), if (ike_sa->delete_child_sa(ike_sa, child_sa->get_protocol(child_sa),
child_sa->get_spi(child_sa, TRUE), FALSE) != DESTROY_ME) child_sa->get_spi(child_sa, TRUE), FALSE) != DESTROY_ME)
{ {
listener->status = SUCCESS; if (!listener->logger.callback)
{
listener->status = SUCCESS;
}
charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa); charon->ike_sa_manager->checkin(charon->ike_sa_manager, ike_sa);
} }
else else
@@ -657,4 +666,3 @@ controller_t *controller_create(void)
return &this->public; return &this->public;
} }
+82 -18
View File
@@ -33,6 +33,11 @@ struct private_stroke_control_t {
* public functions * public functions
*/ */
stroke_control_t public; stroke_control_t public;
/**
* Timeout for stroke commands, im ms
*/
u_int timeout;
}; };
@@ -97,8 +102,8 @@ static child_cfg_t* get_child_from_peer(peer_cfg_t *peer_cfg, char *name)
/** /**
* call the charon controller to initiate the connection * call the charon controller to initiate the connection
*/ */
static void charon_initiate(peer_cfg_t *peer_cfg, child_cfg_t *child_cfg, static void charon_initiate(private_stroke_control_t *this, peer_cfg_t *peer_cfg,
stroke_msg_t *msg, FILE *out) child_cfg_t *child_cfg, stroke_msg_t *msg, FILE *out)
{ {
if (msg->output_verbosity < 0) if (msg->output_verbosity < 0)
{ {
@@ -108,9 +113,27 @@ static void charon_initiate(peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
else else
{ {
stroke_log_info_t info = { msg->output_verbosity, out }; stroke_log_info_t info = { msg->output_verbosity, out };
status_t status;
charon->controller->initiate(charon->controller, peer_cfg, child_cfg, status = charon->controller->initiate(charon->controller,
(controller_cb_t)stroke_log, &info, 0); peer_cfg, child_cfg, (controller_cb_t)stroke_log,
&info, this->timeout);
switch (status)
{
case SUCCESS:
fprintf(out, "connection '%s' established successfully\n",
msg->initiate.name);
break;
case OUT_OF_RES:
fprintf(out, "connection '%s' not established after %dms, "
"detaching\n", msg->initiate.name, this->timeout);
break;
default:
case FAILED:
fprintf(out, "establishing connection '%s' failed\n",
msg->initiate.name);
break;
}
} }
} }
@@ -133,7 +156,7 @@ METHOD(stroke_control_t, initiate, void,
while (enumerator->enumerate(enumerator, &child_cfg)) while (enumerator->enumerate(enumerator, &child_cfg))
{ {
empty = FALSE; empty = FALSE;
charon_initiate(peer_cfg->get_ref(peer_cfg), charon_initiate(this, peer_cfg->get_ref(peer_cfg),
child_cfg->get_ref(child_cfg), msg, out); child_cfg->get_ref(child_cfg), msg, out);
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
@@ -169,7 +192,7 @@ METHOD(stroke_control_t, initiate, void,
return; return;
} }
} }
charon_initiate(peer_cfg, child_cfg, msg, out); charon_initiate(this, peer_cfg, child_cfg, msg, out);
} }
/** /**
@@ -239,6 +262,41 @@ static bool parse_specifier(char *string, u_int32_t *id,
return TRUE; return TRUE;
} }
/**
* Report the result of a terminate() call to console
*/
static void report_terminate_status(private_stroke_control_t *this,
status_t status, FILE *out, u_int32_t id, bool child)
{
char *prefix, *postfix;
if (child)
{
prefix = "CHILD_SA {";
postfix = "}";
}
else
{
prefix = "IKE_SA [";
postfix = "]";
}
switch (status)
{
case SUCCESS:
fprintf(out, "%s%d%s closed successfully\n", prefix, id, postfix);
break;
case OUT_OF_RES:
fprintf(out, "%s%d%s not closed after %dms, detaching\n",
prefix, id, postfix, this->timeout);
break;
default:
case FAILED:
fprintf(out, "closing %s%d%s failed\n", prefix, id, postfix);
break;
}
}
METHOD(stroke_control_t, terminate, void, METHOD(stroke_control_t, terminate, void,
private_stroke_control_t *this, stroke_msg_t *msg, FILE *out) private_stroke_control_t *this, stroke_msg_t *msg, FILE *out)
{ {
@@ -250,6 +308,7 @@ METHOD(stroke_control_t, terminate, void,
linked_list_t *ike_list, *child_list; linked_list_t *ike_list, *child_list;
stroke_log_info_t info; stroke_log_info_t info;
uintptr_t del; uintptr_t del;
status_t status;
if (!parse_specifier(msg->terminate.name, &id, &name, &child, &all)) if (!parse_specifier(msg->terminate.name, &id, &name, &child, &all))
{ {
@@ -264,15 +323,15 @@ METHOD(stroke_control_t, terminate, void,
{ {
if (child) if (child)
{ {
charon->controller->terminate_child(charon->controller, id, status = charon->controller->terminate_child(charon->controller, id,
(controller_cb_t)stroke_log, &info, 0); (controller_cb_t)stroke_log, &info, this->timeout);
} }
else else
{ {
charon->controller->terminate_ike(charon->controller, id, status = charon->controller->terminate_ike(charon->controller, id,
(controller_cb_t)stroke_log, &info, 0); (controller_cb_t)stroke_log, &info, this->timeout);
} }
return; return report_terminate_status(this, status, out, id, child);
} }
ike_list = linked_list_create(); ike_list = linked_list_create();
@@ -320,16 +379,18 @@ METHOD(stroke_control_t, terminate, void,
enumerator = child_list->create_enumerator(child_list); enumerator = child_list->create_enumerator(child_list);
while (enumerator->enumerate(enumerator, &del)) while (enumerator->enumerate(enumerator, &del))
{ {
charon->controller->terminate_child(charon->controller, del, status = charon->controller->terminate_child(charon->controller, del,
(controller_cb_t)stroke_log, &info, 0); (controller_cb_t)stroke_log, &info, this->timeout);
report_terminate_status(this, status, out, del, TRUE);
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
enumerator = ike_list->create_enumerator(ike_list); enumerator = ike_list->create_enumerator(ike_list);
while (enumerator->enumerate(enumerator, &del)) while (enumerator->enumerate(enumerator, &del))
{ {
charon->controller->terminate_ike(charon->controller, del, status = charon->controller->terminate_ike(charon->controller, del,
(controller_cb_t)stroke_log, &info, 0); (controller_cb_t)stroke_log, &info, this->timeout);
report_terminate_status(this, status, out, del, FALSE);
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
@@ -487,6 +548,7 @@ METHOD(stroke_control_t, purge_ike, void,
linked_list_t *list; linked_list_t *list;
uintptr_t del; uintptr_t del;
stroke_log_info_t info; stroke_log_info_t info;
status_t status;
info.out = out; info.out = out;
info.level = msg->output_verbosity; info.level = msg->output_verbosity;
@@ -509,8 +571,9 @@ METHOD(stroke_control_t, purge_ike, void,
enumerator = list->create_enumerator(list); enumerator = list->create_enumerator(list);
while (enumerator->enumerate(enumerator, &del)) while (enumerator->enumerate(enumerator, &del))
{ {
charon->controller->terminate_ike(charon->controller, del, status = charon->controller->terminate_ike(charon->controller, del,
(controller_cb_t)stroke_log, &info, 0); (controller_cb_t)stroke_log, &info, this->timeout);
report_terminate_status(this, status, out, del, TRUE);
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
list->destroy(list); list->destroy(list);
@@ -670,8 +733,9 @@ stroke_control_t *stroke_control_create()
.unroute = _unroute, .unroute = _unroute,
.destroy = _destroy, .destroy = _destroy,
}, },
.timeout = lib->settings->get_int(lib->settings,
"%s.plugins.stroke.timeout", 0, charon->name),
); );
return &this->public; return &this->public;
} }