]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Merge and share parse_chain()
authorPhil Sutter <phil@nwl.cc>
Fri, 5 Apr 2019 11:21:19 +0000 (13:21 +0200)
committerPhil Sutter <phil@nwl.cc>
Tue, 23 Nov 2021 14:01:23 +0000 (15:01 +0100)
Have a common routine to perform chain name checks, combining all
variants' requirements.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/ip6tables.c
iptables/iptables.c
iptables/xshared.c
iptables/xshared.h
iptables/xtables.c

index e967c040fd3c9832977961731be7400bfd890a3f..ec0ae759875e712c260c5131b50fba2b62bdb365 100644 (file)
@@ -233,32 +233,6 @@ static int is_exthdr(uint16_t proto)
                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
 print_header(unsigned int format, const char *chain, struct xtc_handle *handle)
 {
index b925f0892e0d5fc4d68cfd6d57e07c71a7cef44c..246526a55a3c9b4924779f355701fad068e17f6b 100644 (file)
@@ -223,31 +223,6 @@ iptables_exit_error(enum xtables_exittype status, const char *msg, ...)
 
 /* 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
 print_header(unsigned int format, const char *chain, struct xtc_handle *handle)
index 2d3ef679fd765044413ec086607c024216c56d17..bd545d6b31908206baf846c5dcb51a9538bd95b9 100644 (file)
@@ -892,3 +892,27 @@ set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
                *invflg |= inverse_for_options[i];
        }
 }
+
+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);
+}
index b59116ac497472e9b6bed36c27926922979d4eef..6d6acbca13da27f1cee8ef30e8632db91043aa37 100644 (file)
@@ -235,6 +235,7 @@ char cmd2char(int option);
 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);
 
 void generic_opt_check(int command, int options);
 char opt2char(int option);
index 5c69af7e0f1f0f433658aa96e10d008650702399..32b93d2bfc8cd658e3f6c2e69721b0fa3de6e8bf 100644 (file)
@@ -424,14 +424,7 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
                        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,
                                    invert);
                        p->chain = optarg;