From 284a3e67563a8984fb0f513e1dc27a2364a12ce2 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 22 Oct 2019 22:55:08 +0200 Subject: xshared: Share a common implementation of parse_rulenumber() The function is really small, but still copied four times. Signed-off-by: Phil Sutter Acked-by: Pablo Neira Ayuso --- iptables/ip6tables.c | 13 ------------- iptables/iptables.c | 12 ------------ iptables/xshared.c | 12 ++++++++++++ iptables/xshared.h | 1 + iptables/xtables-arp.c | 13 ------------- iptables/xtables.c | 12 ------------ 6 files changed, 13 insertions(+), 50 deletions(-) (limited to 'iptables') diff --git a/iptables/ip6tables.c b/iptables/ip6tables.c index 9a9d71f1..f4ccfc60 100644 --- a/iptables/ip6tables.c +++ b/iptables/ip6tables.c @@ -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) { diff --git a/iptables/iptables.c b/iptables/iptables.c index 5fec2537..df371f41 100644 --- a/iptables/iptables.c +++ b/iptables/iptables.c @@ -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) diff --git a/iptables/xshared.c b/iptables/xshared.c index 3baa805c..2a0077d9 100644 --- a/iptables/xshared.c +++ b/iptables/xshared.c @@ -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; +} diff --git a/iptables/xshared.h b/iptables/xshared.h index 0b9b357c..85bbfa12 100644 --- a/iptables/xshared.h +++ b/iptables/xshared.h @@ -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 */ diff --git a/iptables/xtables-arp.c b/iptables/xtables-arp.c index 584b6f06..79cc83d3 100644 --- a/iptables/xtables-arp.c +++ b/iptables/xtables-arp.c @@ -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) diff --git a/iptables/xtables.c b/iptables/xtables.c index 6dfa3f11..bb76e6a7 100644 --- a/iptables/xtables.c +++ b/iptables/xtables.c @@ -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, -- cgit v1.2.3