controller: Add parameter for maximum log level to initiate/terminate_*()
Previously, the logger installed by the controller always announced LEVEL_PRIVATE(4), which produced completely useless logging calls with the common clients (vici/stroke) whose default log level is LEVEL_CTRL(1). This can produce quite some overhead if there are e.g. a lot of concurrent initiate() calls.
This commit is contained in:
@@ -439,7 +439,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)
|
||||
controller_cb_empty, NULL, LEVEL_SILENT, 0, FALSE) != SUCCESS)
|
||||
{
|
||||
terminate(pid);
|
||||
}
|
||||
|
||||
@@ -1067,7 +1067,7 @@ static gboolean do_disconnect(gpointer plugin)
|
||||
if (id)
|
||||
{
|
||||
charon->controller->terminate_ike(charon->controller, id, FALSE,
|
||||
controller_cb_empty, NULL, 0);
|
||||
controller_cb_empty, NULL, LEVEL_SILENT, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -66,7 +66,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, 0, 0, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -211,7 +211,7 @@ static job_requeue_t close_ike(char *config)
|
||||
{
|
||||
DBG1(DBG_CFG, "closing IKE_SA '%s'", config);
|
||||
charon->controller->terminate_ike(charon->controller, id, FALSE, NULL,
|
||||
NULL, 0);
|
||||
NULL, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -251,7 +251,7 @@ static job_requeue_t close_child(char *config)
|
||||
{
|
||||
DBG1(DBG_CFG, "closing CHILD_SA '%s'", config);
|
||||
charon->controller->terminate_child(charon->controller, id,
|
||||
NULL, NULL, 0);
|
||||
NULL, NULL, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -440,7 +440,7 @@ CALLBACK(terminate, job_requeue_t,
|
||||
uint32_t *id)
|
||||
{
|
||||
charon->controller->terminate_ike(charon->controller, *id, FALSE,
|
||||
controller_cb_empty, NULL, 0);
|
||||
controller_cb_empty, NULL, LEVEL_SILENT, 0);
|
||||
return JOB_REQUEUE_NONE;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ static void stop_connection(private_xpc_channels_t *this, uint32_t ike_sa,
|
||||
status_t status;
|
||||
|
||||
status = charon->controller->terminate_ike(charon->controller, ike_sa, FALSE,
|
||||
NULL, NULL, 0);
|
||||
NULL, NULL, 0, 0);
|
||||
xpc_dictionary_set_bool(reply, "success", status != NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ void start_connection(private_xpc_dispatch_t *this,
|
||||
peer_cfg->add_child_cfg(peer_cfg, child_cfg->get_ref(child_cfg));
|
||||
|
||||
if (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
|
||||
(controller_cb_t)initiate_cb, &ike_sa, 0, FALSE) == NEED_MORE)
|
||||
(controller_cb_t)initiate_cb, &ike_sa, LEVEL_CTRL, 0, FALSE) == NEED_MORE)
|
||||
{
|
||||
this->channels->add(this->channels, channel, ike_sa);
|
||||
success = TRUE;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2011-2019 Tobias Brunner
|
||||
* Copyright (C) 2011-2023 Tobias Brunner
|
||||
* Copyright (C) 2007-2011 Martin Willi
|
||||
*
|
||||
* Copyright (C) secunet Security Networks AG
|
||||
@@ -56,6 +56,11 @@ struct interface_logger_t {
|
||||
*/
|
||||
interface_listener_t *listener;
|
||||
|
||||
/**
|
||||
* Maximum log level to pass to callback
|
||||
*/
|
||||
level_t max_level;
|
||||
|
||||
/**
|
||||
* interface callback (listener gets redirected to here)
|
||||
*/
|
||||
@@ -241,9 +246,7 @@ METHOD(logger_t, listener_log, void,
|
||||
METHOD(logger_t, listener_get_level, level_t,
|
||||
interface_logger_t *this, debug_t group)
|
||||
{
|
||||
/* in order to allow callback listeners to decide what they want to log
|
||||
* we request any log message, but only if we actually want logging */
|
||||
return this->callback == controller_cb_empty ? LEVEL_SILENT : LEVEL_PRIVATE;
|
||||
return this->max_level;
|
||||
}
|
||||
|
||||
METHOD(job_t, get_priority_medium, job_priority_t,
|
||||
@@ -496,7 +499,8 @@ 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,
|
||||
controller_cb_t callback, void *param, u_int timeout, bool limits)
|
||||
controller_cb_t callback, void *param, level_t max_level, u_int timeout,
|
||||
bool limits)
|
||||
{
|
||||
interface_job_t *job;
|
||||
status_t status;
|
||||
@@ -512,6 +516,7 @@ METHOD(controller_t, initiate, status_t,
|
||||
.log = _listener_log,
|
||||
.get_level = _listener_get_level,
|
||||
},
|
||||
.max_level = max_level,
|
||||
.callback = callback,
|
||||
.param = param,
|
||||
},
|
||||
@@ -587,7 +592,7 @@ METHOD(job_t, terminate_ike_execute, job_requeue_t,
|
||||
|
||||
METHOD(controller_t, terminate_ike, status_t,
|
||||
controller_t *this, uint32_t unique_id, bool force,
|
||||
controller_cb_t callback, void *param, u_int timeout)
|
||||
controller_cb_t callback, void *param, level_t max_level, u_int timeout)
|
||||
{
|
||||
interface_job_t *job;
|
||||
status_t status;
|
||||
@@ -602,6 +607,7 @@ METHOD(controller_t, terminate_ike, status_t,
|
||||
.log = _listener_log,
|
||||
.get_level = _listener_get_level,
|
||||
},
|
||||
.max_level = max_level,
|
||||
.callback = callback,
|
||||
.param = param,
|
||||
},
|
||||
@@ -688,7 +694,7 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
|
||||
|
||||
METHOD(controller_t, terminate_child, status_t,
|
||||
controller_t *this, uint32_t unique_id,
|
||||
controller_cb_t callback, void *param, u_int timeout)
|
||||
controller_cb_t callback, void *param, level_t max_level, u_int timeout)
|
||||
{
|
||||
interface_job_t *job;
|
||||
status_t status;
|
||||
@@ -704,6 +710,7 @@ METHOD(controller_t, terminate_child, status_t,
|
||||
.log = _listener_log,
|
||||
.get_level = _listener_get_level,
|
||||
},
|
||||
.max_level = max_level,
|
||||
.callback = callback,
|
||||
.param = param,
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2012-2023 Tobias Brunner
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
*
|
||||
* Copyright (C) secunet Security Networks AG
|
||||
@@ -82,6 +83,7 @@ struct controller_t {
|
||||
* @param child_cfg optional child_cfg to set up CHILD_SA from
|
||||
* @param cb logging callback
|
||||
* @param param parameter to include in each call of cb
|
||||
* @param max_level maximum log level for which cb is invoked
|
||||
* @param timeout timeout in ms to wait for callbacks, 0 to disable
|
||||
* @param limits whether to check limits regarding IKE_SA initiation
|
||||
* @return
|
||||
@@ -93,8 +95,8 @@ struct controller_t {
|
||||
*/
|
||||
status_t (*initiate)(controller_t *this,
|
||||
peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
|
||||
controller_cb_t callback, void *param, u_int timeout,
|
||||
bool limits);
|
||||
controller_cb_t callback, void *param,
|
||||
level_t max_level, u_int timeout, bool limits);
|
||||
|
||||
/**
|
||||
* Terminate an IKE_SA and all of its CHILD_SAs.
|
||||
@@ -110,6 +112,7 @@ struct controller_t {
|
||||
* retransmits are sent until then
|
||||
* @param cb logging callback
|
||||
* @param param parameter to include in each call of cb
|
||||
* @param max_level maximum log level for which cb is invoked
|
||||
* @param timeout timeout in ms to wait for callbacks, 0 to disable
|
||||
* @return
|
||||
* - SUCCESS, if CHILD_SA terminated
|
||||
@@ -119,7 +122,7 @@ struct controller_t {
|
||||
*/
|
||||
status_t (*terminate_ike)(controller_t *this, uint32_t unique_id,
|
||||
bool force, controller_cb_t callback, void *param,
|
||||
u_int timeout);
|
||||
level_t max_level, u_int timeout);
|
||||
|
||||
/**
|
||||
* Terminate a CHILD_SA.
|
||||
@@ -130,6 +133,7 @@ struct controller_t {
|
||||
* @param unique_id CHILD_SA unique ID to terminate
|
||||
* @param cb logging callback
|
||||
* @param param parameter to include in each call of cb
|
||||
* @param max_level maximum log level for which cb is invoked
|
||||
* @param timeout timeout in ms to wait for callbacks, 0 to disable
|
||||
* @return
|
||||
* - SUCCESS, if CHILD_SA terminated
|
||||
@@ -139,7 +143,7 @@ struct controller_t {
|
||||
*/
|
||||
status_t (*terminate_child)(controller_t *this, uint32_t unique_id,
|
||||
controller_cb_t callback, void *param,
|
||||
u_int timeout);
|
||||
level_t max_level, u_int timeout);
|
||||
|
||||
/**
|
||||
* Destroy a controller_t instance.
|
||||
|
||||
@@ -239,8 +239,8 @@ static bool on_accept(private_load_tester_control_t *this, stream_t *io)
|
||||
enumerator->destroy(enumerator);
|
||||
|
||||
switch (charon->controller->initiate(charon->controller,
|
||||
peer_cfg, child_cfg->get_ref(child_cfg),
|
||||
(void*)initiate_cb, listener, 0, FALSE))
|
||||
peer_cfg, child_cfg->get_ref(child_cfg),
|
||||
(void*)initiate_cb, listener, LEVEL_CTRL, 0, FALSE))
|
||||
{
|
||||
case NEED_MORE:
|
||||
/* Callback returns FALSE once it got track of this IKE_SA.
|
||||
|
||||
@@ -152,7 +152,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, 0, 0, FALSE);
|
||||
if (s)
|
||||
{
|
||||
sleep(s);
|
||||
|
||||
@@ -349,8 +349,8 @@ static job_requeue_t initiate_config(peer_cfg_t *peer_cfg)
|
||||
child_cfg->get_ref(child_cfg);
|
||||
peer_cfg->get_ref(peer_cfg);
|
||||
enumerator->destroy(enumerator);
|
||||
charon->controller->initiate(charon->controller,
|
||||
peer_cfg, child_cfg, NULL, NULL, 0, FALSE);
|
||||
charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
|
||||
NULL, NULL, 0, 0, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -423,13 +423,13 @@ static void request_control_terminate(xmlTextReaderPtr reader,
|
||||
{
|
||||
status = charon->controller->terminate_ike(
|
||||
charon->controller, id, FALSE,
|
||||
(controller_cb_t)xml_callback, writer, 0);
|
||||
(controller_cb_t)xml_callback, writer, LEVEL_CTRL, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = charon->controller->terminate_child(
|
||||
charon->controller, id,
|
||||
(controller_cb_t)xml_callback, writer, 0);
|
||||
(controller_cb_t)xml_callback, writer, LEVEL_CTRL, 0);
|
||||
}
|
||||
/* </log> */
|
||||
xmlTextWriterEndElement(writer);
|
||||
@@ -495,7 +495,7 @@ static void request_control_initiate(xmlTextReaderPtr reader,
|
||||
{
|
||||
status = charon->controller->initiate(charon->controller,
|
||||
peer, child, (controller_cb_t)xml_callback,
|
||||
writer, 0, FALSE);
|
||||
writer, LEVEL_CTRL, 0, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -109,7 +109,7 @@ 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, 0, 0, FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -118,7 +118,7 @@ static void charon_initiate(private_stroke_control_t *this, peer_cfg_t *peer_cfg
|
||||
|
||||
status = charon->controller->initiate(charon->controller,
|
||||
peer_cfg, child_cfg, (controller_cb_t)stroke_log,
|
||||
&info, this->timeout, FALSE);
|
||||
&info, msg->output_verbosity, this->timeout, FALSE);
|
||||
switch (status)
|
||||
{
|
||||
case SUCCESS:
|
||||
@@ -312,25 +312,26 @@ static void charon_terminate(private_stroke_control_t *this, uint32_t id,
|
||||
if (child)
|
||||
{
|
||||
status = charon->controller->terminate_child(charon->controller, id,
|
||||
(controller_cb_t)stroke_log, &info, this->timeout);
|
||||
(controller_cb_t)stroke_log, &info,
|
||||
msg->output_verbosity, this->timeout);
|
||||
}
|
||||
else
|
||||
{
|
||||
status = charon->controller->terminate_ike(charon->controller, id,
|
||||
FALSE, (controller_cb_t)stroke_log, &info,
|
||||
this->timeout);
|
||||
FALSE, (controller_cb_t)stroke_log, &info,
|
||||
msg->output_verbosity, this->timeout);
|
||||
}
|
||||
report_terminate_status(this, status, out, id, child);
|
||||
}
|
||||
else if (child)
|
||||
{
|
||||
charon->controller->terminate_child(charon->controller, id,
|
||||
NULL, NULL, 0);
|
||||
NULL, NULL, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
charon->controller->terminate_ike(charon->controller, id, FALSE,
|
||||
NULL, NULL, 0);
|
||||
NULL, NULL, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -147,8 +147,8 @@ static void initiate(private_uci_control_t *this, char *name)
|
||||
enumerator = peer_cfg->create_child_cfg_enumerator(peer_cfg);
|
||||
if (enumerator->enumerate(enumerator, &child_cfg) &&
|
||||
charon->controller->initiate(charon->controller, peer_cfg,
|
||||
child_cfg->get_ref(child_cfg),
|
||||
controller_cb_empty, NULL, 0, FALSE) == SUCCESS)
|
||||
child_cfg->get_ref(child_cfg), controller_cb_empty,
|
||||
NULL, LEVEL_SILENT, 0, FALSE) == SUCCESS)
|
||||
{
|
||||
write_fifo(this, "connection '%s' established\n", name);
|
||||
}
|
||||
@@ -182,7 +182,8 @@ static void terminate(private_uci_control_t *this, char *name)
|
||||
id = ike_sa->get_unique_id(ike_sa);
|
||||
enumerator->destroy(enumerator);
|
||||
charon->controller->terminate_ike(charon->controller, id, FALSE,
|
||||
controller_cb_empty, NULL, 0);
|
||||
controller_cb_empty, NULL,
|
||||
LEVEL_SILENT, 0);
|
||||
write_fifo(this, "connection '%s' terminated\n", name);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2252,7 +2252,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, 0, 0, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2348,7 +2348,7 @@ static void clear_start_action(private_vici_config_t *this, char *peer_name,
|
||||
{
|
||||
DBG1(DBG_CFG, "closing '%s' #%u", name, id);
|
||||
charon->controller->terminate_child(charon->controller,
|
||||
id, NULL, NULL, 0);
|
||||
id, NULL, NULL, 0, 0);
|
||||
}
|
||||
array_destroy(ids);
|
||||
}
|
||||
@@ -2358,7 +2358,7 @@ static void clear_start_action(private_vici_config_t *this, char *peer_name,
|
||||
{
|
||||
DBG1(DBG_CFG, "closing IKE_SA #%u", id);
|
||||
charon->controller->terminate_ike(charon->controller, id,
|
||||
FALSE, NULL, NULL, 0);
|
||||
FALSE, NULL, NULL, 0, 0);
|
||||
}
|
||||
array_destroy(ikeids);
|
||||
}
|
||||
|
||||
@@ -209,8 +209,8 @@ CALLBACK(initiate, vici_message_t*,
|
||||
{
|
||||
return send_reply(this, "%s config '%s' not found", type, sa);
|
||||
}
|
||||
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,
|
||||
log_cb, &log, log.level, timeout, limits))
|
||||
{
|
||||
case SUCCESS:
|
||||
return send_reply(this, NULL);
|
||||
@@ -328,7 +328,7 @@ CALLBACK(terminate, vici_message_t*,
|
||||
if (child || child_id)
|
||||
{
|
||||
if (charon->controller->terminate_child(charon->controller, *del,
|
||||
log_cb, &log, timeout) == SUCCESS)
|
||||
log_cb, &log, log.level, timeout) == SUCCESS)
|
||||
{
|
||||
done++;
|
||||
}
|
||||
@@ -336,7 +336,7 @@ CALLBACK(terminate, vici_message_t*,
|
||||
else
|
||||
{
|
||||
if (charon->controller->terminate_ike(charon->controller, *del, force,
|
||||
log_cb, &log, timeout) == SUCCESS)
|
||||
log_cb, &log, log.level, timeout) == SUCCESS)
|
||||
{
|
||||
done++;
|
||||
}
|
||||
|
||||
@@ -138,7 +138,8 @@ METHOD(job_t, initiate, job_requeue_t,
|
||||
mediation_cfg->get_ref(mediation_cfg);
|
||||
|
||||
if (charon->controller->initiate(charon->controller, mediation_cfg, NULL,
|
||||
(controller_cb_t)initiate_callback, this, 0, FALSE) != SUCCESS)
|
||||
(controller_cb_t)initiate_callback, this, LEVEL_CTRL,
|
||||
0, FALSE) != SUCCESS)
|
||||
{
|
||||
mediation_cfg->destroy(mediation_cfg);
|
||||
mediated_cfg->destroy(mediated_cfg);
|
||||
|
||||
@@ -84,7 +84,7 @@ METHOD(job_t, execute, job_requeue_t,
|
||||
charon->controller->initiate(charon->controller,
|
||||
peer_cfg->get_ref(peer_cfg),
|
||||
child_cfg->get_ref(child_cfg),
|
||||
NULL, NULL, 0, FALSE);
|
||||
NULL, NULL, 0, 0, FALSE);
|
||||
}
|
||||
}
|
||||
children->destroy(children);
|
||||
|
||||
Reference in New Issue
Block a user