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:
Tobias Brunner
2023-04-27 13:52:34 +02:00
parent 77b9f3abb0
commit d96d15b588
18 changed files with 60 additions and 46 deletions
+1 -1
View File
@@ -439,7 +439,7 @@ static job_requeue_t initiate(private_cmd_connection_t *this)
child_cfg = create_child_cfg(this, peer_cfg); child_cfg = create_child_cfg(this, peer_cfg);
if (charon->controller->initiate(charon->controller, peer_cfg, child_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); terminate(pid);
} }
+1 -1
View File
@@ -1067,7 +1067,7 @@ static gboolean do_disconnect(gpointer plugin)
if (id) if (id)
{ {
charon->controller->terminate_ike(charon->controller, id, FALSE, charon->controller->terminate_ike(charon->controller, id, FALSE,
controller_cb_empty, NULL, 0); controller_cb_empty, NULL, LEVEL_SILENT, 0);
} }
else else
{ {
+3 -3
View File
@@ -66,7 +66,7 @@ static job_requeue_t initiate(char *config)
{ {
DBG1(DBG_CFG, "initiating IKE_SA for CHILD_SA config '%s'", config); DBG1(DBG_CFG, "initiating IKE_SA for CHILD_SA config '%s'", config);
charon->controller->initiate(charon->controller, peer_cfg, child_cfg, charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
NULL, NULL, 0, FALSE); NULL, NULL, 0, 0, FALSE);
} }
else else
{ {
@@ -211,7 +211,7 @@ static job_requeue_t close_ike(char *config)
{ {
DBG1(DBG_CFG, "closing IKE_SA '%s'", config); DBG1(DBG_CFG, "closing IKE_SA '%s'", config);
charon->controller->terminate_ike(charon->controller, id, FALSE, NULL, charon->controller->terminate_ike(charon->controller, id, FALSE, NULL,
NULL, 0); NULL, 0, 0);
} }
else else
{ {
@@ -251,7 +251,7 @@ static job_requeue_t close_child(char *config)
{ {
DBG1(DBG_CFG, "closing CHILD_SA '%s'", config); DBG1(DBG_CFG, "closing CHILD_SA '%s'", config);
charon->controller->terminate_child(charon->controller, id, charon->controller->terminate_child(charon->controller, id,
NULL, NULL, 0); NULL, NULL, 0, 0);
} }
else else
{ {
@@ -440,7 +440,7 @@ CALLBACK(terminate, job_requeue_t,
uint32_t *id) uint32_t *id)
{ {
charon->controller->terminate_ike(charon->controller, *id, FALSE, charon->controller->terminate_ike(charon->controller, *id, FALSE,
controller_cb_empty, NULL, 0); controller_cb_empty, NULL, LEVEL_SILENT, 0);
return JOB_REQUEUE_NONE; return JOB_REQUEUE_NONE;
} }
+1 -1
View File
@@ -133,7 +133,7 @@ static void stop_connection(private_xpc_channels_t *this, uint32_t ike_sa,
status_t status; status_t status;
status = charon->controller->terminate_ike(charon->controller, ike_sa, FALSE, 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); xpc_dictionary_set_bool(reply, "success", status != NOT_FOUND);
} }
+1 -1
View File
@@ -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)); peer_cfg->add_child_cfg(peer_cfg, child_cfg->get_ref(child_cfg));
if (charon->controller->initiate(charon->controller, peer_cfg, 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); this->channels->add(this->channels, channel, ike_sa);
success = TRUE; success = TRUE;
+14 -7
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2011-2019 Tobias Brunner * Copyright (C) 2011-2023 Tobias Brunner
* Copyright (C) 2007-2011 Martin Willi * Copyright (C) 2007-2011 Martin Willi
* *
* Copyright (C) secunet Security Networks AG * Copyright (C) secunet Security Networks AG
@@ -56,6 +56,11 @@ struct interface_logger_t {
*/ */
interface_listener_t *listener; interface_listener_t *listener;
/**
* Maximum log level to pass to callback
*/
level_t max_level;
/** /**
* interface callback (listener gets redirected to here) * 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, METHOD(logger_t, listener_get_level, level_t,
interface_logger_t *this, debug_t group) interface_logger_t *this, debug_t group)
{ {
/* in order to allow callback listeners to decide what they want to log return this->max_level;
* we request any log message, but only if we actually want logging */
return this->callback == controller_cb_empty ? LEVEL_SILENT : LEVEL_PRIVATE;
} }
METHOD(job_t, get_priority_medium, job_priority_t, 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, METHOD(controller_t, initiate, status_t,
private_controller_t *this, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg, 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; interface_job_t *job;
status_t status; status_t status;
@@ -512,6 +516,7 @@ METHOD(controller_t, initiate, status_t,
.log = _listener_log, .log = _listener_log,
.get_level = _listener_get_level, .get_level = _listener_get_level,
}, },
.max_level = max_level,
.callback = callback, .callback = callback,
.param = param, .param = param,
}, },
@@ -587,7 +592,7 @@ METHOD(job_t, terminate_ike_execute, job_requeue_t,
METHOD(controller_t, terminate_ike, status_t, METHOD(controller_t, terminate_ike, status_t,
controller_t *this, uint32_t unique_id, bool force, 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; interface_job_t *job;
status_t status; status_t status;
@@ -602,6 +607,7 @@ METHOD(controller_t, terminate_ike, status_t,
.log = _listener_log, .log = _listener_log,
.get_level = _listener_get_level, .get_level = _listener_get_level,
}, },
.max_level = max_level,
.callback = callback, .callback = callback,
.param = param, .param = param,
}, },
@@ -688,7 +694,7 @@ METHOD(job_t, terminate_child_execute, job_requeue_t,
METHOD(controller_t, terminate_child, status_t, METHOD(controller_t, terminate_child, status_t,
controller_t *this, uint32_t unique_id, 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; interface_job_t *job;
status_t status; status_t status;
@@ -704,6 +710,7 @@ METHOD(controller_t, terminate_child, status_t,
.log = _listener_log, .log = _listener_log,
.get_level = _listener_get_level, .get_level = _listener_get_level,
}, },
.max_level = max_level,
.callback = callback, .callback = callback,
.param = param, .param = param,
}, },
+8 -4
View File
@@ -1,4 +1,5 @@
/* /*
* Copyright (C) 2012-2023 Tobias Brunner
* Copyright (C) 2007 Martin Willi * Copyright (C) 2007 Martin Willi
* *
* Copyright (C) secunet Security Networks AG * 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 child_cfg optional child_cfg to set up CHILD_SA from
* @param cb logging callback * @param cb logging callback
* @param param parameter to include in each call of cb * @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 timeout timeout in ms to wait for callbacks, 0 to disable
* @param limits whether to check limits regarding IKE_SA initiation * @param limits whether to check limits regarding IKE_SA initiation
* @return * @return
@@ -93,8 +95,8 @@ struct controller_t {
*/ */
status_t (*initiate)(controller_t *this, status_t (*initiate)(controller_t *this,
peer_cfg_t *peer_cfg, child_cfg_t *child_cfg, peer_cfg_t *peer_cfg, child_cfg_t *child_cfg,
controller_cb_t callback, void *param, u_int timeout, controller_cb_t callback, void *param,
bool limits); level_t max_level, u_int timeout, bool limits);
/** /**
* Terminate an IKE_SA and all of its CHILD_SAs. * Terminate an IKE_SA and all of its CHILD_SAs.
@@ -110,6 +112,7 @@ struct controller_t {
* retransmits are sent until then * retransmits are sent until then
* @param cb logging callback * @param cb logging callback
* @param param parameter to include in each call of cb * @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 timeout timeout in ms to wait for callbacks, 0 to disable
* @return * @return
* - SUCCESS, if CHILD_SA terminated * - SUCCESS, if CHILD_SA terminated
@@ -119,7 +122,7 @@ struct controller_t {
*/ */
status_t (*terminate_ike)(controller_t *this, uint32_t unique_id, status_t (*terminate_ike)(controller_t *this, uint32_t unique_id,
bool force, controller_cb_t callback, void *param, bool force, controller_cb_t callback, void *param,
u_int timeout); level_t max_level, u_int timeout);
/** /**
* Terminate a CHILD_SA. * Terminate a CHILD_SA.
@@ -130,6 +133,7 @@ struct controller_t {
* @param unique_id CHILD_SA unique ID to terminate * @param unique_id CHILD_SA unique ID to terminate
* @param cb logging callback * @param cb logging callback
* @param param parameter to include in each call of cb * @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 timeout timeout in ms to wait for callbacks, 0 to disable
* @return * @return
* - SUCCESS, if CHILD_SA terminated * - SUCCESS, if CHILD_SA terminated
@@ -139,7 +143,7 @@ struct controller_t {
*/ */
status_t (*terminate_child)(controller_t *this, uint32_t unique_id, status_t (*terminate_child)(controller_t *this, uint32_t unique_id,
controller_cb_t callback, void *param, controller_cb_t callback, void *param,
u_int timeout); level_t max_level, u_int timeout);
/** /**
* Destroy a controller_t instance. * 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); enumerator->destroy(enumerator);
switch (charon->controller->initiate(charon->controller, switch (charon->controller->initiate(charon->controller,
peer_cfg, child_cfg->get_ref(child_cfg), peer_cfg, child_cfg->get_ref(child_cfg),
(void*)initiate_cb, listener, 0, FALSE)) (void*)initiate_cb, listener, LEVEL_CTRL, 0, FALSE))
{ {
case NEED_MORE: case NEED_MORE:
/* Callback returns FALSE once it got track of this IKE_SA. /* 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, charon->controller->initiate(charon->controller,
peer_cfg, child_cfg->get_ref(child_cfg), peer_cfg, child_cfg->get_ref(child_cfg),
NULL, NULL, 0, FALSE); NULL, NULL, 0, 0, FALSE);
if (s) if (s)
{ {
sleep(s); sleep(s);
+2 -2
View File
@@ -349,8 +349,8 @@ static job_requeue_t initiate_config(peer_cfg_t *peer_cfg)
child_cfg->get_ref(child_cfg); child_cfg->get_ref(child_cfg);
peer_cfg->get_ref(peer_cfg); peer_cfg->get_ref(peer_cfg);
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
charon->controller->initiate(charon->controller, charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
peer_cfg, child_cfg, NULL, NULL, 0, FALSE); NULL, NULL, 0, 0, FALSE);
} }
else else
{ {
+3 -3
View File
@@ -423,13 +423,13 @@ static void request_control_terminate(xmlTextReaderPtr reader,
{ {
status = charon->controller->terminate_ike( status = charon->controller->terminate_ike(
charon->controller, id, FALSE, charon->controller, id, FALSE,
(controller_cb_t)xml_callback, writer, 0); (controller_cb_t)xml_callback, writer, LEVEL_CTRL, 0);
} }
else else
{ {
status = charon->controller->terminate_child( status = charon->controller->terminate_child(
charon->controller, id, charon->controller, id,
(controller_cb_t)xml_callback, writer, 0); (controller_cb_t)xml_callback, writer, LEVEL_CTRL, 0);
} }
/* </log> */ /* </log> */
xmlTextWriterEndElement(writer); xmlTextWriterEndElement(writer);
@@ -495,7 +495,7 @@ static void request_control_initiate(xmlTextReaderPtr reader,
{ {
status = charon->controller->initiate(charon->controller, status = charon->controller->initiate(charon->controller,
peer, child, (controller_cb_t)xml_callback, peer, child, (controller_cb_t)xml_callback,
writer, 0, FALSE); writer, LEVEL_CTRL, 0, FALSE);
} }
else else
{ {
@@ -109,7 +109,7 @@ static void charon_initiate(private_stroke_control_t *this, peer_cfg_t *peer_cfg
if (msg->output_verbosity < 0) if (msg->output_verbosity < 0)
{ {
charon->controller->initiate(charon->controller, peer_cfg, child_cfg, charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
NULL, NULL, 0, FALSE); NULL, NULL, 0, 0, FALSE);
} }
else 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, status = charon->controller->initiate(charon->controller,
peer_cfg, child_cfg, (controller_cb_t)stroke_log, peer_cfg, child_cfg, (controller_cb_t)stroke_log,
&info, this->timeout, FALSE); &info, msg->output_verbosity, this->timeout, FALSE);
switch (status) switch (status)
{ {
case SUCCESS: case SUCCESS:
@@ -312,25 +312,26 @@ static void charon_terminate(private_stroke_control_t *this, uint32_t id,
if (child) if (child)
{ {
status = charon->controller->terminate_child(charon->controller, id, 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 else
{ {
status = charon->controller->terminate_ike(charon->controller, id, status = charon->controller->terminate_ike(charon->controller, id,
FALSE, (controller_cb_t)stroke_log, &info, FALSE, (controller_cb_t)stroke_log, &info,
this->timeout); msg->output_verbosity, this->timeout);
} }
report_terminate_status(this, status, out, id, child); report_terminate_status(this, status, out, id, child);
} }
else if (child) else if (child)
{ {
charon->controller->terminate_child(charon->controller, id, charon->controller->terminate_child(charon->controller, id,
NULL, NULL, 0); NULL, NULL, 0, 0);
} }
else else
{ {
charon->controller->terminate_ike(charon->controller, id, FALSE, charon->controller->terminate_ike(charon->controller, id, FALSE,
NULL, NULL, 0); NULL, NULL, 0, 0);
} }
} }
+4 -3
View File
@@ -147,8 +147,8 @@ static void initiate(private_uci_control_t *this, char *name)
enumerator = peer_cfg->create_child_cfg_enumerator(peer_cfg); enumerator = peer_cfg->create_child_cfg_enumerator(peer_cfg);
if (enumerator->enumerate(enumerator, &child_cfg) && if (enumerator->enumerate(enumerator, &child_cfg) &&
charon->controller->initiate(charon->controller, peer_cfg, charon->controller->initiate(charon->controller, peer_cfg,
child_cfg->get_ref(child_cfg), child_cfg->get_ref(child_cfg), controller_cb_empty,
controller_cb_empty, NULL, 0, FALSE) == SUCCESS) NULL, LEVEL_SILENT, 0, FALSE) == SUCCESS)
{ {
write_fifo(this, "connection '%s' established\n", name); 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); id = ike_sa->get_unique_id(ike_sa);
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
charon->controller->terminate_ike(charon->controller, id, FALSE, 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); write_fifo(this, "connection '%s' terminated\n", name);
return; return;
} }
+3 -3
View File
@@ -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)); DBG1(DBG_CFG, "initiating '%s'", child_cfg->get_name(child_cfg));
charon->controller->initiate(charon->controller, charon->controller->initiate(charon->controller,
peer_cfg->get_ref(peer_cfg), child_cfg->get_ref(child_cfg), 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); DBG1(DBG_CFG, "closing '%s' #%u", name, id);
charon->controller->terminate_child(charon->controller, charon->controller->terminate_child(charon->controller,
id, NULL, NULL, 0); id, NULL, NULL, 0, 0);
} }
array_destroy(ids); 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); DBG1(DBG_CFG, "closing IKE_SA #%u", id);
charon->controller->terminate_ike(charon->controller, id, charon->controller->terminate_ike(charon->controller, id,
FALSE, NULL, NULL, 0); FALSE, NULL, NULL, 0, 0);
} }
array_destroy(ikeids); array_destroy(ikeids);
} }
+4 -4
View File
@@ -209,8 +209,8 @@ CALLBACK(initiate, vici_message_t*,
{ {
return send_reply(this, "%s config '%s' not found", type, sa); return send_reply(this, "%s config '%s' not found", type, sa);
} }
switch (charon->controller->initiate(charon->controller, peer_cfg, switch (charon->controller->initiate(charon->controller, peer_cfg, child_cfg,
child_cfg, log_cb, &log, timeout, limits)) log_cb, &log, log.level, timeout, limits))
{ {
case SUCCESS: case SUCCESS:
return send_reply(this, NULL); return send_reply(this, NULL);
@@ -328,7 +328,7 @@ CALLBACK(terminate, vici_message_t*,
if (child || child_id) if (child || child_id)
{ {
if (charon->controller->terminate_child(charon->controller, *del, if (charon->controller->terminate_child(charon->controller, *del,
log_cb, &log, timeout) == SUCCESS) log_cb, &log, log.level, timeout) == SUCCESS)
{ {
done++; done++;
} }
@@ -336,7 +336,7 @@ CALLBACK(terminate, vici_message_t*,
else else
{ {
if (charon->controller->terminate_ike(charon->controller, *del, force, if (charon->controller->terminate_ike(charon->controller, *del, force,
log_cb, &log, timeout) == SUCCESS) log_cb, &log, log.level, timeout) == SUCCESS)
{ {
done++; done++;
} }
@@ -138,7 +138,8 @@ METHOD(job_t, initiate, job_requeue_t,
mediation_cfg->get_ref(mediation_cfg); mediation_cfg->get_ref(mediation_cfg);
if (charon->controller->initiate(charon->controller, mediation_cfg, NULL, 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); mediation_cfg->destroy(mediation_cfg);
mediated_cfg->destroy(mediated_cfg); mediated_cfg->destroy(mediated_cfg);
@@ -84,7 +84,7 @@ METHOD(job_t, execute, job_requeue_t,
charon->controller->initiate(charon->controller, charon->controller->initiate(charon->controller,
peer_cfg->get_ref(peer_cfg), peer_cfg->get_ref(peer_cfg),
child_cfg->get_ref(child_cfg), child_cfg->get_ref(child_cfg),
NULL, NULL, 0, FALSE); NULL, NULL, 0, 0, FALSE);
} }
} }
children->destroy(children); children->destroy(children);