swanctl: Pass optional connection name to --initiate/install/uninstall

This commit is contained in:
Tobias Brunner
2017-02-16 19:24:07 +01:00
parent 7627f5f9c7
commit ebb517581f
2 changed files with 22 additions and 5 deletions
+10 -2
View File
@@ -37,7 +37,7 @@ static int initiate(vici_conn_t *conn)
vici_req_t *req; vici_req_t *req;
vici_res_t *res; vici_res_t *res;
command_format_options_t format = COMMAND_FORMAT_NONE; command_format_options_t format = COMMAND_FORMAT_NONE;
char *arg, *child = NULL; char *arg, *child = NULL, *ike = NULL;
int ret = 0, timeout = 0, level = 1; int ret = 0, timeout = 0, level = 1;
while (TRUE) while (TRUE)
@@ -55,6 +55,9 @@ static int initiate(vici_conn_t *conn)
case 'c': case 'c':
child = arg; child = arg;
continue; continue;
case 'i':
ike = arg;
continue;
case 't': case 't':
timeout = atoi(arg); timeout = atoi(arg);
continue; continue;
@@ -80,6 +83,10 @@ static int initiate(vici_conn_t *conn)
{ {
vici_add_key_valuef(req, "child", "%s", child); vici_add_key_valuef(req, "child", "%s", child);
} }
if (ike)
{
vici_add_key_valuef(req, "ike", "%s", ike);
}
if (timeout) if (timeout)
{ {
vici_add_key_valuef(req, "timeout", "%d", timeout * 1000); vici_add_key_valuef(req, "timeout", "%d", timeout * 1000);
@@ -121,10 +128,11 @@ static void __attribute__ ((constructor))reg()
{ {
command_register((command_t) { command_register((command_t) {
initiate, 'i', "initiate", "initiate a connection", initiate, 'i', "initiate", "initiate a connection",
{"--child <name> [--timeout <s>] [--raw|--pretty]"}, {"--child <name> [--ike <name>] [--timeout <s>] [--raw|--pretty]"},
{ {
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"child", 'c', 1, "initate a CHILD_SA configuration"}, {"child", 'c', 1, "initate a CHILD_SA configuration"},
{"ike", 'i', 1, "name of the connection to which the child belongs"},
{"timeout", 't', 1, "timeout in seconds before detaching"}, {"timeout", 't', 1, "timeout in seconds before detaching"},
{"raw", 'r', 0, "dump raw response message"}, {"raw", 'r', 0, "dump raw response message"},
{"pretty", 'P', 0, "dump raw response message in pretty print"}, {"pretty", 'P', 0, "dump raw response message in pretty print"},
+12 -3
View File
@@ -22,7 +22,7 @@ static int manage_policy(vici_conn_t *conn, char *label)
vici_req_t *req; vici_req_t *req;
vici_res_t *res; vici_res_t *res;
command_format_options_t format = COMMAND_FORMAT_NONE; command_format_options_t format = COMMAND_FORMAT_NONE;
char *arg, *child = NULL; char *arg, *child = NULL, *ike = NULL;
int ret = 0; int ret = 0;
while (TRUE) while (TRUE)
@@ -40,6 +40,9 @@ static int manage_policy(vici_conn_t *conn, char *label)
case 'c': case 'c':
child = arg; child = arg;
continue; continue;
case 'i':
ike = arg;
continue;
case EOF: case EOF:
break; break;
default: default:
@@ -52,6 +55,10 @@ static int manage_policy(vici_conn_t *conn, char *label)
{ {
vici_add_key_valuef(req, "child", "%s", child); vici_add_key_valuef(req, "child", "%s", child);
} }
if (ike)
{
vici_add_key_valuef(req, "ike", "%s", ike);
}
res = vici_submit(req, conn); res = vici_submit(req, conn);
if (!res) if (!res)
{ {
@@ -98,10 +105,11 @@ static void __attribute__ ((constructor))reg_uninstall()
{ {
command_register((command_t) { command_register((command_t) {
uninstall, 'u', "uninstall", "uninstall a trap or shunt policy", uninstall, 'u', "uninstall", "uninstall a trap or shunt policy",
{"--child <name> [--raw|--pretty]"}, {"--child <name> [--ike <name>] [--raw|--pretty]"},
{ {
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"child", 'c', 1, "CHILD_SA configuration to uninstall"}, {"child", 'c', 1, "CHILD_SA configuration to uninstall"},
{"ike", 'i', 1, "name of the connection to which the child belongs"},
{"raw", 'r', 0, "dump raw response message"}, {"raw", 'r', 0, "dump raw response message"},
{"pretty", 'P', 0, "dump raw response message in pretty print"}, {"pretty", 'P', 0, "dump raw response message in pretty print"},
} }
@@ -115,10 +123,11 @@ static void __attribute__ ((constructor))reg_install()
{ {
command_register((command_t) { command_register((command_t) {
install, 'p', "install", "install a trap or shunt policy", install, 'p', "install", "install a trap or shunt policy",
{"--child <name> [--raw|--pretty]"}, {"--child <name> [--ike <name>] [--raw|--pretty]"},
{ {
{"help", 'h', 0, "show usage information"}, {"help", 'h', 0, "show usage information"},
{"child", 'c', 1, "CHILD_SA configuration to install"}, {"child", 'c', 1, "CHILD_SA configuration to install"},
{"ike", 'i', 1, "name of the connection to which the child belongs"},
{"raw", 'r', 0, "dump raw response message"}, {"raw", 'r', 0, "dump raw response message"},
{"pretty", 'P', 0, "dump raw response message in pretty print"}, {"pretty", 'P', 0, "dump raw response message in pretty print"},
} }