|
|
df4535 |
From 767c668628296fb3236aeeea1699ce06e66e5270 Mon Sep 17 00:00:00 2001
|
|
|
df4535 |
From: Phil Sutter <phil@nwl.cc>
|
|
|
df4535 |
Date: Fri, 5 Apr 2019 13:21:19 +0200
|
|
|
df4535 |
Subject: [PATCH] xshared: Merge and share parse_chain()
|
|
|
df4535 |
|
|
|
df4535 |
Have a common routine to perform chain name checks, combining all
|
|
|
df4535 |
variants' requirements.
|
|
|
df4535 |
|
|
|
df4535 |
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
|
|
df4535 |
(cherry picked from commit 1189d830ea4fd269da87761d400ebabca02e1ef3)
|
|
|
df4535 |
|
|
|
df4535 |
Conflicts:
|
|
|
df4535 |
iptables/ip6tables.c
|
|
|
df4535 |
iptables/xshared.c
|
|
|
df4535 |
-> Context changes due to missing commit 9dc50b5b8e441
|
|
|
df4535 |
("xshared: Merge invflags handling code")
|
|
|
df4535 |
---
|
|
|
df4535 |
iptables/ip6tables.c | 26 --------------------------
|
|
|
df4535 |
iptables/iptables.c | 25 -------------------------
|
|
|
df4535 |
iptables/xshared.c | 24 ++++++++++++++++++++++++
|
|
|
df4535 |
iptables/xshared.h | 1 +
|
|
|
df4535 |
iptables/xtables.c | 9 +--------
|
|
|
df4535 |
5 files changed, 26 insertions(+), 59 deletions(-)
|
|
|
df4535 |
|
|
|
df4535 |
diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c
|
|
|
df4535 |
index 576c2cf8b0d9f..614d1e249c06d 100644
|
|
|
df4535 |
--- a/iptables/ip6tables.c
|
|
|
df4535 |
+++ b/iptables/ip6tables.c
|
|
|
df4535 |
@@ -327,32 +327,6 @@ static int is_exthdr(uint16_t proto)
|
|
|
df4535 |
proto == IPPROTO_DSTOPTS);
|
|
|
df4535 |
}
|
|
|
df4535 |
|
|
|
df4535 |
-static void
|
|
|
df4535 |
-parse_chain(const char *chainname)
|
|
|
df4535 |
-{
|
|
|
df4535 |
- const char *ptr;
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name `%s' too long (must be under %u chars)",
|
|
|
df4535 |
- chainname, XT_EXTENSION_MAXNAMELEN);
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (*chainname == '-' || *chainname == '!')
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name not allowed to start "
|
|
|
df4535 |
- "with `%c'\n", *chainname);
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name may not clash "
|
|
|
df4535 |
- "with target name\n");
|
|
|
df4535 |
-
|
|
|
df4535 |
- for (ptr = chainname; *ptr; ptr++)
|
|
|
df4535 |
- if (isspace(*ptr))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "Invalid chain name `%s'", chainname);
|
|
|
df4535 |
-}
|
|
|
df4535 |
-
|
|
|
df4535 |
static void
|
|
|
df4535 |
set_option(unsigned int *options, unsigned int option, uint8_t *invflg,
|
|
|
df4535 |
int invert)
|
|
|
df4535 |
diff --git a/iptables/iptables.c b/iptables/iptables.c
|
|
|
df4535 |
index 88ef6cf666d4b..3b395981cc8ea 100644
|
|
|
df4535 |
--- a/iptables/iptables.c
|
|
|
df4535 |
+++ b/iptables/iptables.c
|
|
|
df4535 |
@@ -319,31 +319,6 @@ opt2char(int option)
|
|
|
df4535 |
|
|
|
df4535 |
/* Christophe Burki wants `-p 6' to imply `-m tcp'. */
|
|
|
df4535 |
|
|
|
df4535 |
-static void
|
|
|
df4535 |
-parse_chain(const char *chainname)
|
|
|
df4535 |
-{
|
|
|
df4535 |
- const char *ptr;
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name `%s' too long (must be under %u chars)",
|
|
|
df4535 |
- chainname, XT_EXTENSION_MAXNAMELEN);
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (*chainname == '-' || *chainname == '!')
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name not allowed to start "
|
|
|
df4535 |
- "with `%c'\n", *chainname);
|
|
|
df4535 |
-
|
|
|
df4535 |
- if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name may not clash "
|
|
|
df4535 |
- "with target name\n");
|
|
|
df4535 |
-
|
|
|
df4535 |
- for (ptr = chainname; *ptr; ptr++)
|
|
|
df4535 |
- if (isspace(*ptr))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "Invalid chain name `%s'", chainname);
|
|
|
df4535 |
-}
|
|
|
df4535 |
|
|
|
df4535 |
static void
|
|
|
df4535 |
set_option(unsigned int *options, unsigned int option, uint8_t *invflg,
|
|
|
df4535 |
diff --git a/iptables/xshared.c b/iptables/xshared.c
|
|
|
df4535 |
index dcc995a9cabe6..de8326b6c7b05 100644
|
|
|
df4535 |
--- a/iptables/xshared.c
|
|
|
df4535 |
+++ b/iptables/xshared.c
|
|
|
df4535 |
@@ -775,3 +775,27 @@ int parse_rulenumber(const char *rule)
|
|
|
df4535 |
|
|
|
df4535 |
return rulenum;
|
|
|
df4535 |
}
|
|
|
df4535 |
+
|
|
|
df4535 |
+void parse_chain(const char *chainname)
|
|
|
df4535 |
+{
|
|
|
df4535 |
+ const char *ptr;
|
|
|
df4535 |
+
|
|
|
df4535 |
+ if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
|
|
df4535 |
+ xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
+ "chain name `%s' too long (must be under %u chars)",
|
|
|
df4535 |
+ chainname, XT_EXTENSION_MAXNAMELEN);
|
|
|
df4535 |
+
|
|
|
df4535 |
+ if (*chainname == '-' || *chainname == '!')
|
|
|
df4535 |
+ xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
+ "chain name not allowed to start with `%c'\n",
|
|
|
df4535 |
+ *chainname);
|
|
|
df4535 |
+
|
|
|
df4535 |
+ if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
|
|
df4535 |
+ xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
+ "chain name may not clash with target name\n");
|
|
|
df4535 |
+
|
|
|
df4535 |
+ for (ptr = chainname; *ptr; ptr++)
|
|
|
df4535 |
+ if (isspace(*ptr))
|
|
|
df4535 |
+ xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
+ "Invalid chain name `%s'", chainname);
|
|
|
df4535 |
+}
|
|
|
df4535 |
diff --git a/iptables/xshared.h b/iptables/xshared.h
|
|
|
df4535 |
index e4015c00e2a35..f5d2f8d0a2bc5 100644
|
|
|
df4535 |
--- a/iptables/xshared.h
|
|
|
df4535 |
+++ b/iptables/xshared.h
|
|
|
df4535 |
@@ -217,5 +217,6 @@ char cmd2char(int option);
|
|
|
df4535 |
void add_command(unsigned int *cmd, const int newcmd,
|
|
|
df4535 |
const int othercmds, int invert);
|
|
|
df4535 |
int parse_rulenumber(const char *rule);
|
|
|
df4535 |
+void parse_chain(const char *chainname);
|
|
|
df4535 |
|
|
|
df4535 |
#endif /* IPTABLES_XSHARED_H */
|
|
|
df4535 |
diff --git a/iptables/xtables.c b/iptables/xtables.c
|
|
|
df4535 |
index 8c2d21d42b7d2..3ea293ee7c411 100644
|
|
|
df4535 |
--- a/iptables/xtables.c
|
|
|
df4535 |
+++ b/iptables/xtables.c
|
|
|
df4535 |
@@ -668,14 +668,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
|
|
|
df4535 |
break;
|
|
|
df4535 |
|
|
|
df4535 |
case 'N':
|
|
|
df4535 |
- if (optarg && (*optarg == '-' || *optarg == '!'))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name not allowed to start "
|
|
|
df4535 |
- "with `%c'\n", *optarg);
|
|
|
df4535 |
- if (xtables_find_target(optarg, XTF_TRY_LOAD))
|
|
|
df4535 |
- xtables_error(PARAMETER_PROBLEM,
|
|
|
df4535 |
- "chain name may not clash "
|
|
|
df4535 |
- "with target name\n");
|
|
|
df4535 |
+ parse_chain(optarg);
|
|
|
df4535 |
add_command(&p->command, CMD_NEW_CHAIN, CMD_NONE,
|
|
|
df4535 |
cs->invert);
|
|
|
df4535 |
p->chain = optarg;
|
|
|
df4535 |
--
|
|
|
df4535 |
2.34.1
|
|
|
df4535 |
|