summaryrefslogtreecommitdiffstats
path: root/iptables/xtables-restore.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-09-17 18:43:21 +0200
committerPhil Sutter <phil@nwl.cc>2019-10-18 11:57:24 +0200
commit4abb44c978d75656f69dd59f24522eb970881ccf (patch)
tree88a992be6606e03aeb378b79205d29316ca1eb7a /iptables/xtables-restore.c
parentfe2c53d570bf7a301b0cb5aa25b1186a47378a6b (diff)
xtables-restore: Introduce rule counter tokenizer function
The same piece of code appears three times, introduce a function to take care of tokenizing and error reporting. Pass buffer pointer via reference so it can be updated to point to after the counters (if found). While being at it, drop pointless casting when passing pcnt/bcnt to add_argv(). Signed-off-by: Phil Sutter <phil@nwl.cc> Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'iptables/xtables-restore.c')
-rw-r--r--iptables/xtables-restore.c35
1 files changed, 4 insertions, 31 deletions
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index 24bfce51..4652d631 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -230,47 +230,20 @@ void xtables_restore_parse(struct nft_handle *h,
int a;
char *pcnt = NULL;
char *bcnt = NULL;
- char *parsestart;
+ char *parsestart = buffer;
/* reset the newargv */
newargc = 0;
- if (buffer[0] == '[') {
- /* we have counters in our input */
- char *ptr = strchr(buffer, ']');
-
- if (!ptr)
- xtables_error(PARAMETER_PROBLEM,
- "Bad line %u: need ]\n",
- line);
-
- pcnt = strtok(buffer+1, ":");
- if (!pcnt)
- xtables_error(PARAMETER_PROBLEM,
- "Bad line %u: need :\n",
- line);
-
- bcnt = strtok(NULL, "]");
- if (!bcnt)
- xtables_error(PARAMETER_PROBLEM,
- "Bad line %u: need ]\n",
- line);
-
- /* start command parsing after counter */
- parsestart = ptr + 1;
- } else {
- /* start command parsing at start of line */
- parsestart = buffer;
- }
-
add_argv(xt_params->program_name, 0);
add_argv("-t", 0);
add_argv(curtable->name, 0);
+ tokenize_rule_counters(&parsestart, &pcnt, &bcnt, line);
if (counters && pcnt && bcnt) {
add_argv("--set-counters", 0);
- add_argv((char *) pcnt, 0);
- add_argv((char *) bcnt, 0);
+ add_argv(pcnt, 0);
+ add_argv(bcnt, 0);
}
add_param_to_argv(parsestart, line);