aboutsummaryrefslogtreecommitdiffstats
path: root/src/libcharon/plugins/vici
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcharon/plugins/vici')
-rw-r--r--src/libcharon/plugins/vici/README.md1
-rw-r--r--src/libcharon/plugins/vici/suites/test_message.c31
-rw-r--r--src/libcharon/plugins/vici/vici_config.c2
-rw-r--r--src/libcharon/plugins/vici/vici_control.c9
-rw-r--r--src/libcharon/plugins/vici/vici_message.c40
-rw-r--r--src/libcharon/plugins/vici/vici_message.h23
6 files changed, 103 insertions, 3 deletions
diff --git a/src/libcharon/plugins/vici/README.md b/src/libcharon/plugins/vici/README.md
index 1273bb8fc..e20e8ab26 100644
--- a/src/libcharon/plugins/vici/README.md
+++ b/src/libcharon/plugins/vici/README.md
@@ -259,6 +259,7 @@ Initiates an SA while streaming _control-log_ events.
{
child = <CHILD_SA configuration name to initiate>
timeout = <timeout in seconds before returning>
+ init-limits = <whether limits may prevent initiating the CHILD_SA>
loglevel = <loglevel to issue "control-log" events for>
} => {
success = <yes or no>
diff --git a/src/libcharon/plugins/vici/suites/test_message.c b/src/libcharon/plugins/vici/suites/test_message.c
index e76d27332..045e34fff 100644
--- a/src/libcharon/plugins/vici/suites/test_message.c
+++ b/src/libcharon/plugins/vici/suites/test_message.c
@@ -1,4 +1,7 @@
/*
+ * Copyright (C) 2015 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 revosec AG
*
@@ -355,6 +358,33 @@ START_TEST(test_get_int)
}
END_TEST
+START_TEST(test_get_bool)
+{
+ vici_message_t *m;
+
+ m = build_getter_msg();
+
+ ck_assert(m->get_bool(m, TRUE, "key1"));
+ ck_assert(m->get_bool(m, FALSE, "key1"));
+
+ ck_assert(m->get_bool(m, TRUE, "section1.key2"));
+ ck_assert(m->get_bool(m, TRUE, "section1.section2.key3"));
+ ck_assert(m->get_bool(m, TRUE, "section1.key4"));
+ ck_assert(m->get_bool(m, TRUE, "key5"));
+ ck_assert(m->get_bool(m, TRUE, "nonexistent"));
+ ck_assert(m->get_bool(m, TRUE, "n.o.n.e.x.i.s.t.e.n.t"));
+
+ ck_assert(!m->get_bool(m, FALSE, "section1.key2"));
+ ck_assert(!m->get_bool(m, FALSE, "section1.section2.key3"));
+ ck_assert(!m->get_bool(m, FALSE, "section1.key4"));
+ ck_assert(!m->get_bool(m, FALSE, "key5"));
+ ck_assert(!m->get_bool(m, FALSE, "nonexistent"));
+ ck_assert(!m->get_bool(m, FALSE, "n.o.n.e.x.i.s.t.e.n.t"));
+
+ m->destroy(m);
+}
+END_TEST
+
START_TEST(test_get_value)
{
vici_message_t *m;
@@ -400,6 +430,7 @@ Suite *message_suite_create()
tc = tcase_create("convenience getters");
tcase_add_test(tc, test_get_str);
tcase_add_test(tc, test_get_int);
+ tcase_add_test(tc, test_get_bool);
tcase_add_test(tc, test_get_value);
suite_add_tcase(s, tc);
diff --git a/src/libcharon/plugins/vici/vici_config.c b/src/libcharon/plugins/vici/vici_config.c
index d442bd69e..ea6d2958a 100644
--- a/src/libcharon/plugins/vici/vici_config.c
+++ b/src/libcharon/plugins/vici/vici_config.c
@@ -1589,7 +1589,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);
+ NULL, NULL, 0, FALSE);
break;
case ACTION_ROUTE:
DBG1(DBG_CFG, "installing '%s'", child_cfg->get_name(child_cfg));
diff --git a/src/libcharon/plugins/vici/vici_control.c b/src/libcharon/plugins/vici/vici_control.c
index 408d29985..752007c24 100644
--- a/src/libcharon/plugins/vici/vici_control.c
+++ b/src/libcharon/plugins/vici/vici_control.c
@@ -163,6 +163,7 @@ CALLBACK(initiate, vici_message_t*,
peer_cfg_t *peer_cfg;
char *child;
u_int timeout;
+ bool limits;
log_info_t log = {
.dispatcher = this->dispatcher,
.id = id,
@@ -170,6 +171,7 @@ CALLBACK(initiate, vici_message_t*,
child = request->get_str(request, NULL, "child");
timeout = request->get_int(request, 0, "timeout");
+ limits = request->get_bool(request, FALSE, "init-limits");
log.level = request->get_int(request, 1, "loglevel");
if (!child)
@@ -184,14 +186,17 @@ CALLBACK(initiate, vici_message_t*,
{
return send_reply(this, "CHILD_SA config '%s' not found", child);
}
- switch (charon->controller->initiate(charon->controller,
- peer_cfg, child_cfg, (controller_cb_t)log_vici, &log, timeout))
+ switch (charon->controller->initiate(charon->controller, peer_cfg,
+ child_cfg, (controller_cb_t)log_vici, &log, timeout, limits))
{
case SUCCESS:
return send_reply(this, NULL);
case OUT_OF_RES:
return send_reply(this, "CHILD_SA '%s' not established after %dms",
child, timeout);
+ case INVALID_STATE:
+ return send_reply(this, "establishing CHILD_SA '%s' not possible "
+ "at the moment due to limits", child);
case FAILED:
default:
return send_reply(this, "establishing CHILD_SA '%s' failed", child);
diff --git a/src/libcharon/plugins/vici/vici_message.c b/src/libcharon/plugins/vici/vici_message.c
index e79fbc8d3..fb6e8a1ab 100644
--- a/src/libcharon/plugins/vici/vici_message.c
+++ b/src/libcharon/plugins/vici/vici_message.c
@@ -1,4 +1,7 @@
/*
+ * Copyright (C) 2015 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 revosec AG
*
@@ -385,6 +388,41 @@ METHOD(vici_message_t, get_int, int,
return val;
}
+METHOD(vici_message_t, vget_bool, bool,
+ private_vici_message_t *this, bool def, char *fmt, va_list args)
+{
+ chunk_t value;
+ bool found;
+ char buf[16];
+
+ found = find_value(this, &value, fmt, args);
+ if (found)
+ {
+ if (value.len == 0)
+ {
+ return def;
+ }
+ if (chunk_printable(value, NULL, 0))
+ {
+ snprintf(buf, sizeof(buf), "%.*s", (int)value.len, value.ptr);
+ return settings_value_as_bool(buf, def);
+ }
+ }
+ return def;
+}
+
+METHOD(vici_message_t, get_bool, bool,
+ private_vici_message_t *this, bool def, char *fmt, ...)
+{
+ va_list args;
+ bool val;
+
+ va_start(args, fmt);
+ val = vget_bool(this, def, fmt, args);
+ va_end(args);
+ return val;
+}
+
METHOD(vici_message_t, vget_value, chunk_t,
private_vici_message_t *this, chunk_t def, char *fmt, va_list args)
{
@@ -633,6 +671,8 @@ vici_message_t *vici_message_create_from_data(chunk_t data, bool cleanup)
.vget_str = _vget_str,
.get_int = _get_int,
.vget_int = _vget_int,
+ .get_bool = _get_bool,
+ .vget_bool = _vget_bool,
.get_value = _get_value,
.vget_value = _vget_value,
.get_encoding = _get_encoding,
diff --git a/src/libcharon/plugins/vici/vici_message.h b/src/libcharon/plugins/vici/vici_message.h
index 1a89cf829..7f357b8ec 100644
--- a/src/libcharon/plugins/vici/vici_message.h
+++ b/src/libcharon/plugins/vici/vici_message.h
@@ -1,4 +1,7 @@
/*
+ * Copyright (C) 2015 Tobias Brunner
+ * Hochschule fuer Technik Rapperswil
+ *
* Copyright (C) 2014 Martin Willi
* Copyright (C) 2014 revosec AG
*
@@ -138,6 +141,26 @@ struct vici_message_t {
int (*vget_int)(vici_message_t *this, int def, char *fmt, va_list args);
/**
+ * Get the value of a key/value pair as boolean.
+ *
+ * @param def default value if not found
+ * @param fmt printf style format string for key, with sections
+ * @param ... arguments to fmt string
+ * @return value
+ */
+ bool (*get_bool)(vici_message_t *this, bool def, char *fmt, ...);
+
+ /**
+ * Get the value of a key/value pair as boolean, va_list variant
+ *
+ * @param def default value if not found
+ * @param fmt printf style format string for key, with sections
+ * @param args arguments to fmt string
+ * @return value
+ */
+ bool (*vget_bool)(vici_message_t *this, bool def, char *fmt, va_list args);
+
+ /**
* Get the raw value of a key/value pair.
*
* @param def default value if not found