summaryrefslogtreecommitdiffstats
path: root/src/nfct-extensions/helper.c
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2015-08-21 19:18:38 +0200
committerPablo Neira Ayuso <pablo@netfilter.org>2015-08-26 20:43:55 +0200
commitdd73ceecdbe87b6ecf9e96643cd5326e520d7a1c (patch)
treec4c3a7b933dde6bd9094abad606a9435256e383d /src/nfct-extensions/helper.c
parent1c36d487cda8d1bed799b4daa28c44aa7198bb31 (diff)
nfct: Update syntax to specify command before subsystem
This patch gets the nfct syntax in sync with nft so it looks like this: nfct <add|delete|...> object ... instead of: nfct object <add|delete|...> ... This patch retains backward compatibility so you can still use the old syntax. The manpage and tests have been also updated to promote the adoption of this syntax. We should have little existing clients of this tool as we can only use this to configure the cttimeout and cthelper infrastructures. Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src/nfct-extensions/helper.c')
-rw-r--r--src/nfct-extensions/helper.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/src/nfct-extensions/helper.c b/src/nfct-extensions/helper.c
index bfb153f..dfc55e7 100644
--- a/src/nfct-extensions/helper.c
+++ b/src/nfct-extensions/helper.c
@@ -45,36 +45,31 @@ static int nfct_cmd_helper_flush(struct mnl_socket *nl, int argc, char *argv[]);
static int nfct_cmd_helper_disable(struct mnl_socket *nl, int argc, char *argv[]);
static int
-nfct_cmd_helper_parse_params(struct mnl_socket *nl, int argc, char *argv[])
+nfct_helper_parse_params(struct mnl_socket *nl, int argc, char *argv[], int cmd)
{
- int cmd = NFCT_CMD_NONE, ret = 0;
+ int ret;
if (argc < 3) {
- fprintf(stderr, "nfct v%s: Missing command\n"
- "%s helper list|add|delete|get|flush "
- "[parameters...]\n", VERSION, argv[0]);
- exit(EXIT_FAILURE);
+ nfct_cmd_helper_usage(argv);
+ return -1;
}
- if (strncmp(argv[2], "list", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_LIST;
- else if (strncmp(argv[2], "add", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_ADD;
- else if (strncmp(argv[2], "delete", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_DELETE;
- else if (strncmp(argv[2], "get", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_GET;
- else if (strncmp(argv[2], "flush", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_FLUSH;
- else if (strncmp(argv[2], "disable", strlen(argv[2])) == 0)
- cmd = NFCT_CMD_DISABLE;
- else {
+
+ switch (cmd) {
+ case NFCT_CMD_LIST:
+ case NFCT_CMD_ADD:
+ case NFCT_CMD_DELETE:
+ case NFCT_CMD_GET:
+ case NFCT_CMD_FLUSH:
+ case NFCT_CMD_DISABLE:
+ break;
+ default:
fprintf(stderr, "nfct v%s: Unknown command: %s\n",
VERSION, argv[2]);
nfct_cmd_helper_usage(argv);
exit(EXIT_FAILURE);
}
- switch(cmd) {
+ switch (cmd) {
case NFCT_CMD_LIST:
ret = nfct_cmd_helper_list(nl, argc, argv);
break;
@@ -93,6 +88,9 @@ nfct_cmd_helper_parse_params(struct mnl_socket *nl, int argc, char *argv[])
case NFCT_CMD_DISABLE:
ret = nfct_cmd_helper_disable(nl, argc, argv);
break;
+ default:
+ nfct_cmd_helper_usage(argv);
+ return -1;
}
return ret;
@@ -160,8 +158,7 @@ static int nfct_cmd_helper_add(struct mnl_socket *nl, int argc, char *argv[])
if (argc < 6) {
nfct_perror("missing parameters\n"
- "syntax: nfct helper add name "
- "family protocol");
+ "syntax: nfct add helper name family protocol");
return -1;
}
@@ -411,8 +408,7 @@ nfct_cmd_helper_disable(struct mnl_socket *nl, int argc, char *argv[])
if (argc < 6) {
nfct_perror("missing parameters\n"
- "syntax: nfct helper add name "
- "family protocol");
+ "syntax: nfct add helper name family protocol");
return -1;
}
@@ -469,7 +465,7 @@ nfct_cmd_helper_disable(struct mnl_socket *nl, int argc, char *argv[])
static struct nfct_extension helper = {
.type = NFCT_SUBSYS_HELPER,
- .parse_params = nfct_cmd_helper_parse_params,
+ .parse_params = nfct_helper_parse_params,
};
static void __init helper_init(void)