]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xshared: Share a common implementation of parse_rulenumber()
authorPhil Sutter <phil@nwl.cc>
Tue, 22 Oct 2019 20:55:08 +0000 (22:55 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 30 Oct 2019 09:00:59 +0000 (10:00 +0100)
The function is really small, but still copied four times.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/ip6tables.c
iptables/iptables.c
iptables/xshared.c
iptables/xshared.h
iptables/xtables-arp.c
iptables/xtables.c

index 9a9d71f1cdadcaa2d2d08528f744964d66f1b150..f4ccfc60de95389415a13a8a15b3307c5f30e791 100644 (file)
@@ -352,19 +352,6 @@ static int is_exthdr(uint16_t proto)
                proto == IPPROTO_DSTOPTS);
 }
 
-/* Can't be zero. */
-static int
-parse_rulenumber(const char *rule)
-{
-       unsigned int rulenum;
-
-       if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
-               xtables_error(PARAMETER_PROBLEM,
-                          "Invalid rule number `%s'", rule);
-
-       return rulenum;
-}
-
 static void
 parse_chain(const char *chainname)
 {
index 5fec25376c24f8742cead8eaf20b5a444a0a7058..df371f410a9c2164dcdecfb97dce4c83fc380d91 100644 (file)
@@ -343,18 +343,6 @@ opt2char(int option)
 */
 
 /* Christophe Burki wants `-p 6' to imply `-m tcp'.  */
-/* Can't be zero. */
-static int
-parse_rulenumber(const char *rule)
-{
-       unsigned int rulenum;
-
-       if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
-               xtables_error(PARAMETER_PROBLEM,
-                          "Invalid rule number `%s'", rule);
-
-       return rulenum;
-}
 
 static void
 parse_chain(const char *chainname)
index 3baa805c64e6d668fbb8160294c3cfc537dd9e79..2a0077d9da846c7bc992359ffd46cf8818813cbe 100644 (file)
@@ -759,3 +759,15 @@ void add_command(unsigned int *cmd, const int newcmd,
                           cmd2char(newcmd), cmd2char(*cmd & (~othercmds)));
        *cmd |= newcmd;
 }
+
+/* Can't be zero. */
+int parse_rulenumber(const char *rule)
+{
+       unsigned int rulenum;
+
+       if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
+               xtables_error(PARAMETER_PROBLEM,
+                          "Invalid rule number `%s'", rule);
+
+       return rulenum;
+}
index 0b9b357c7bdaa4933e3c4933dbc4ac0e1302da1a..85bbfa1250aa3d81ba6449443f741fe6dc3f5047 100644 (file)
@@ -186,5 +186,6 @@ void command_jump(struct iptables_command_state *cs, const char *jumpto);
 char cmd2char(int option);
 void add_command(unsigned int *cmd, const int newcmd,
                 const int othercmds, int invert);
+int parse_rulenumber(const char *rule);
 
 #endif /* IPTABLES_XSHARED_H */
index 584b6f0646821fe336d7f475211c6cfe1a14bc1f..79cc83d354fc50d5c54c4353fb0a726f16f2d453 100644 (file)
@@ -518,19 +518,6 @@ parse_interface(const char *arg, char *vianame, unsigned char *mask)
        }
 }
 
-/* Can't be zero. */
-static int
-parse_rulenumber(const char *rule)
-{
-       unsigned int rulenum;
-
-       if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
-               xtables_error(PARAMETER_PROBLEM,
-                             "Invalid rule number `%s'", rule);
-
-       return rulenum;
-}
-
 static void
 set_option(unsigned int *options, unsigned int option, u_int16_t *invflg,
           int invert)
index 6dfa3f1171183a4a66db6ea06846a69b89366493..bb76e6a7a1ce86bb6dce29cf2e8345e24df52ed1 100644 (file)
@@ -327,18 +327,6 @@ opt2char(int option)
 */
 
 /* Christophe Burki wants `-p 6' to imply `-m tcp'.  */
-/* Can't be zero. */
-static int
-parse_rulenumber(const char *rule)
-{
-       unsigned int rulenum;
-
-       if (!xtables_strtoui(rule, NULL, &rulenum, 1, INT_MAX))
-               xtables_error(PARAMETER_PROBLEM,
-                          "Invalid rule number `%s'", rule);
-
-       return rulenum;
-}
 
 static void
 set_option(unsigned int *options, unsigned int option, uint8_t *invflg,