}
/**
- * Find a peer/child config from a child config name
+ * Find a peer/child config from a config name
*/
static child_cfg_t* find_child_cfg(char *name, char *pname, peer_cfg_t **out)
{
{
continue;
}
+ if (!name)
+ {
+ *out = peer_cfg->get_ref(peer_cfg);
+ break;
+ }
child_cfg = get_child_from_peer(peer_cfg, name);
if (child_cfg)
{
CALLBACK(initiate, vici_message_t*,
private_vici_control_t *this, char *name, u_int id, vici_message_t *request)
{
- child_cfg_t *child_cfg = NULL;
- peer_cfg_t *peer_cfg;
- char *child, *ike;
+ peer_cfg_t *peer_cfg = NULL;
+ child_cfg_t *child_cfg;
+ char *child, *ike, *type, *sa;
int timeout;
bool limits;
controller_cb_t log_cb = NULL;
limits = request->get_bool(request, FALSE, "init-limits");
log.level = request->get_int(request, 1, "loglevel");
- if (!child)
+ if (!child && !ike)
{
return send_reply(this, "missing configuration name");
}
log_cb = (controller_cb_t)log_vici;
}
- DBG1(DBG_CFG, "vici initiate '%s'", child);
+ type = child ? "CHILD_SA" : "IKE_SA";
+ sa = child ?: ike;
child_cfg = find_child_cfg(child, ike, &peer_cfg);
- if (!child_cfg)
+
+ DBG1(DBG_CFG, "vici initiate %s '%s'", type, sa);
+ if (!peer_cfg)
{
- return send_reply(this, "CHILD_SA config '%s' not found", child);
+ 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))
case SUCCESS:
return send_reply(this, NULL);
case OUT_OF_RES:
- return send_reply(this, "CHILD_SA '%s' not established after %dms",
- child, timeout);
+ return send_reply(this, "%s '%s' not established after %dms", type,
+ sa, timeout);
case INVALID_STATE:
- return send_reply(this, "establishing CHILD_SA '%s' not possible "
- "at the moment due to limits", child);
+ return send_reply(this, "establishing %s '%s' not possible at the "
+ "moment due to limits", type, sa);
case FAILED:
default:
- return send_reply(this, "establishing CHILD_SA '%s' failed", child);
+ return send_reply(this, "establishing %s '%s' failed", type, sa);
}
}
{
command_register((command_t) {
initiate, 'i', "initiate", "initiate a connection",
- {"--child <name> [--ike <name>] [--timeout <s>] [--raw|--pretty]"},
+ {"[--child <name>] [--ike <name>] [--timeout <s>] [--raw|--pretty]"},
{
{"help", 'h', 0, "show usage information"},
{"child", 'c', 1, "initiate a CHILD_SA configuration"},
- {"ike", 'i', 1, "name of the connection to which the child belongs"},
+ {"ike", 'i', 1, "initiate an IKE_SA, or name of child's parent"},
{"timeout", 't', 1, "timeout in seconds before detaching"},
{"raw", 'r', 0, "dump raw response message"},
{"pretty", 'P', 0, "dump raw response message in pretty print"},