iptables/SOURCES/0054-xshared-Merge-and-share-parse_chain.patch

165 lines
5.0 KiB
Diff
Raw Permalink Normal View History

2023-10-17 13:52:06 +00:00
From 655e919be08b6ca9b5529f16c659ee93572b867d Mon Sep 17 00:00:00 2001
2022-09-27 19:54:47 +00:00
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
2023-10-17 13:52:06 +00:00
-> Context change due to missing commit 9dc50b5b8e441
("xshared: Merge invflags handling code").
2022-09-27 19:54:47 +00:00
---
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
2023-10-17 13:52:06 +00:00
index ce01ce8c04af6..6db91c807bcea 100644
2022-09-27 19:54:47 +00:00
--- a/iptables/ip6tables.c
+++ b/iptables/ip6tables.c
2023-10-17 13:52:06 +00:00
@@ -248,32 +248,6 @@ static int is_exthdr(uint16_t proto)
2022-09-27 19:54:47 +00:00
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
2023-10-17 13:52:06 +00:00
index 514238d924780..a33416a887ed4 100644
2022-09-27 19:54:47 +00:00
--- a/iptables/iptables.c
+++ b/iptables/iptables.c
2023-10-17 13:52:06 +00:00
@@ -239,31 +239,6 @@ iptables_exit_error(enum xtables_exittype status, const char *msg, ...)
2022-09-27 19:54:47 +00:00
/* 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
2023-10-17 13:52:06 +00:00
index 9a17a8fdf11cd..5ae158908b109 100644
2022-09-27 19:54:47 +00:00
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
2023-10-17 13:52:06 +00:00
@@ -848,3 +848,27 @@ char opt2char(int option)
2022-09-27 19:54:47 +00:00
2023-10-17 13:52:06 +00:00
return *ptr;
2022-09-27 19:54:47 +00:00
}
+
+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
2023-10-17 13:52:06 +00:00
index 7c881c56a25da..10f6e0b5a0e98 100644
2022-09-27 19:54:47 +00:00
--- a/iptables/xshared.h
+++ b/iptables/xshared.h
2023-10-17 13:52:06 +00:00
@@ -223,6 +223,7 @@ char cmd2char(int option);
2022-09-27 19:54:47 +00:00
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);
2023-10-17 13:52:06 +00:00
void generic_opt_check(int command, int options);
char opt2char(int option);
2022-09-27 19:54:47 +00:00
diff --git a/iptables/xtables.c b/iptables/xtables.c
2023-10-17 13:52:06 +00:00
index 9779bd83d53b3..54f887f80497e 100644
2022-09-27 19:54:47 +00:00
--- a/iptables/xtables.c
+++ b/iptables/xtables.c
2023-10-17 13:52:06 +00:00
@@ -587,14 +587,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
2022-09-27 19:54:47 +00:00
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;
--
2023-10-17 13:52:06 +00:00
2.40.0
2022-09-27 19:54:47 +00:00