You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
165 lines
5.0 KiB
165 lines
5.0 KiB
11 months ago
|
From 655e919be08b6ca9b5529f16c659ee93572b867d Mon Sep 17 00:00:00 2001
|
||
2 years ago
|
From: Phil Sutter <phil@nwl.cc>
|
||
|
Date: Fri, 5 Apr 2019 13:21:19 +0200
|
||
|
Subject: [PATCH] xshared: Merge and share parse_chain()
|
||
|
|
||
|
Have a common routine to perform chain name checks, combining all
|
||
|
variants' requirements.
|
||
|
|
||
|
Signed-off-by: Phil Sutter <phil@nwl.cc>
|
||
|
(cherry picked from commit 1189d830ea4fd269da87761d400ebabca02e1ef3)
|
||
|
|
||
|
Conflicts:
|
||
|
iptables/ip6tables.c
|
||
|
iptables/xshared.c
|
||
11 months ago
|
-> Context change due to missing commit 9dc50b5b8e441
|
||
|
("xshared: Merge invflags handling code").
|
||
2 years ago
|
---
|
||
|
iptables/ip6tables.c | 26 --------------------------
|
||
|
iptables/iptables.c | 25 -------------------------
|
||
|
iptables/xshared.c | 24 ++++++++++++++++++++++++
|
||
|
iptables/xshared.h | 1 +
|
||
|
iptables/xtables.c | 9 +--------
|
||
|
5 files changed, 26 insertions(+), 59 deletions(-)
|
||
|
|
||
|
diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c
|
||
11 months ago
|
index ce01ce8c04af6..6db91c807bcea 100644
|
||
2 years ago
|
--- a/iptables/ip6tables.c
|
||
|
+++ b/iptables/ip6tables.c
|
||
11 months ago
|
@@ -248,32 +248,6 @@ static int is_exthdr(uint16_t proto)
|
||
2 years ago
|
proto == IPPROTO_DSTOPTS);
|
||
|
}
|
||
|
|
||
|
-static void
|
||
|
-parse_chain(const char *chainname)
|
||
|
-{
|
||
|
- const char *ptr;
|
||
|
-
|
||
|
- if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name `%s' too long (must be under %u chars)",
|
||
|
- chainname, XT_EXTENSION_MAXNAMELEN);
|
||
|
-
|
||
|
- if (*chainname == '-' || *chainname == '!')
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name not allowed to start "
|
||
|
- "with `%c'\n", *chainname);
|
||
|
-
|
||
|
- if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name may not clash "
|
||
|
- "with target name\n");
|
||
|
-
|
||
|
- for (ptr = chainname; *ptr; ptr++)
|
||
|
- if (isspace(*ptr))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "Invalid chain name `%s'", chainname);
|
||
|
-}
|
||
|
-
|
||
|
static void
|
||
|
set_option(unsigned int *options, unsigned int option, uint8_t *invflg,
|
||
|
int invert)
|
||
|
diff --git a/iptables/iptables.c b/iptables/iptables.c
|
||
11 months ago
|
index 514238d924780..a33416a887ed4 100644
|
||
2 years ago
|
--- a/iptables/iptables.c
|
||
|
+++ b/iptables/iptables.c
|
||
11 months ago
|
@@ -239,31 +239,6 @@ iptables_exit_error(enum xtables_exittype status, const char *msg, ...)
|
||
2 years ago
|
|
||
|
/* Christophe Burki wants `-p 6' to imply `-m tcp'. */
|
||
|
|
||
|
-static void
|
||
|
-parse_chain(const char *chainname)
|
||
|
-{
|
||
|
- const char *ptr;
|
||
|
-
|
||
|
- if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name `%s' too long (must be under %u chars)",
|
||
|
- chainname, XT_EXTENSION_MAXNAMELEN);
|
||
|
-
|
||
|
- if (*chainname == '-' || *chainname == '!')
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name not allowed to start "
|
||
|
- "with `%c'\n", *chainname);
|
||
|
-
|
||
|
- if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name may not clash "
|
||
|
- "with target name\n");
|
||
|
-
|
||
|
- for (ptr = chainname; *ptr; ptr++)
|
||
|
- if (isspace(*ptr))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "Invalid chain name `%s'", chainname);
|
||
|
-}
|
||
|
|
||
|
static void
|
||
|
set_option(unsigned int *options, unsigned int option, uint8_t *invflg,
|
||
|
diff --git a/iptables/xshared.c b/iptables/xshared.c
|
||
11 months ago
|
index 9a17a8fdf11cd..5ae158908b109 100644
|
||
2 years ago
|
--- a/iptables/xshared.c
|
||
|
+++ b/iptables/xshared.c
|
||
11 months ago
|
@@ -848,3 +848,27 @@ char opt2char(int option)
|
||
2 years ago
|
|
||
11 months ago
|
return *ptr;
|
||
2 years ago
|
}
|
||
|
+
|
||
|
+void parse_chain(const char *chainname)
|
||
|
+{
|
||
|
+ const char *ptr;
|
||
|
+
|
||
|
+ if (strlen(chainname) >= XT_EXTENSION_MAXNAMELEN)
|
||
|
+ xtables_error(PARAMETER_PROBLEM,
|
||
|
+ "chain name `%s' too long (must be under %u chars)",
|
||
|
+ chainname, XT_EXTENSION_MAXNAMELEN);
|
||
|
+
|
||
|
+ if (*chainname == '-' || *chainname == '!')
|
||
|
+ xtables_error(PARAMETER_PROBLEM,
|
||
|
+ "chain name not allowed to start with `%c'\n",
|
||
|
+ *chainname);
|
||
|
+
|
||
|
+ if (xtables_find_target(chainname, XTF_TRY_LOAD))
|
||
|
+ xtables_error(PARAMETER_PROBLEM,
|
||
|
+ "chain name may not clash with target name\n");
|
||
|
+
|
||
|
+ for (ptr = chainname; *ptr; ptr++)
|
||
|
+ if (isspace(*ptr))
|
||
|
+ xtables_error(PARAMETER_PROBLEM,
|
||
|
+ "Invalid chain name `%s'", chainname);
|
||
|
+}
|
||
|
diff --git a/iptables/xshared.h b/iptables/xshared.h
|
||
11 months ago
|
index 7c881c56a25da..10f6e0b5a0e98 100644
|
||
2 years ago
|
--- a/iptables/xshared.h
|
||
|
+++ b/iptables/xshared.h
|
||
11 months ago
|
@@ -223,6 +223,7 @@ char cmd2char(int option);
|
||
2 years ago
|
void add_command(unsigned int *cmd, const int newcmd,
|
||
|
const int othercmds, int invert);
|
||
|
int parse_rulenumber(const char *rule);
|
||
|
+void parse_chain(const char *chainname);
|
||
|
|
||
11 months ago
|
void generic_opt_check(int command, int options);
|
||
|
char opt2char(int option);
|
||
2 years ago
|
diff --git a/iptables/xtables.c b/iptables/xtables.c
|
||
11 months ago
|
index 9779bd83d53b3..54f887f80497e 100644
|
||
2 years ago
|
--- a/iptables/xtables.c
|
||
|
+++ b/iptables/xtables.c
|
||
11 months ago
|
@@ -587,14 +587,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
|
||
2 years ago
|
break;
|
||
|
|
||
|
case 'N':
|
||
|
- if (optarg && (*optarg == '-' || *optarg == '!'))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name not allowed to start "
|
||
|
- "with `%c'\n", *optarg);
|
||
|
- if (xtables_find_target(optarg, XTF_TRY_LOAD))
|
||
|
- xtables_error(PARAMETER_PROBLEM,
|
||
|
- "chain name may not clash "
|
||
|
- "with target name\n");
|
||
|
+ parse_chain(optarg);
|
||
|
add_command(&p->command, CMD_NEW_CHAIN, CMD_NONE,
|
||
|
cs->invert);
|
||
|
p->chain = optarg;
|
||
|
--
|
||
11 months ago
|
2.40.0
|
||
2 years ago
|
|