Blame SOURCES/0066-xshared-Merge-and-share-parse_chain.patch

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