[iptables PATCH 09/27] xshared: Consolidate parse_counters()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Move this helper function into xshared. While being at it, drop the need
for temporary variables and take over null pointer tolerance from the
implementation in iptables-xml.c.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 iptables/ip6tables-restore.c | 11 -----------
 iptables/iptables-restore.c  | 11 -----------
 iptables/iptables-xml.c      | 16 ----------------
 iptables/xshared.c           | 14 ++++++++++++++
 iptables/xshared.h           |  1 +
 iptables/xtables-restore.c   | 11 -----------
 6 files changed, 15 insertions(+), 49 deletions(-)

diff --git a/iptables/ip6tables-restore.c b/iptables/ip6tables-restore.c
index 3065768ed8e6b..f2bd93d732d3c 100644
--- a/iptables/ip6tables-restore.c
+++ b/iptables/ip6tables-restore.c
@@ -79,17 +79,6 @@ static struct xtc_handle *create_handle(const char *tablename)
 	return handle;
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-	unsigned long long pcnt, bcnt;
-	int ret;
-
-	ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-	ctr->pcnt = pcnt;
-	ctr->bcnt = bcnt;
-	return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;
diff --git a/iptables/iptables-restore.c b/iptables/iptables-restore.c
index e52e8e47dda74..a1ae0311f508b 100644
--- a/iptables/iptables-restore.c
+++ b/iptables/iptables-restore.c
@@ -76,17 +76,6 @@ static struct xtc_handle *create_handle(const char *tablename)
 	return handle;
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-	unsigned long long pcnt, bcnt;
-	int ret;
-
-	ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-	ctr->pcnt = pcnt;
-	ctr->bcnt = bcnt;
-	return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;
diff --git a/iptables/iptables-xml.c b/iptables/iptables-xml.c
index a1b09f3ad745c..8ba45d55c079c 100644
--- a/iptables/iptables-xml.c
+++ b/iptables/iptables-xml.c
@@ -50,22 +50,6 @@ print_usage(const char *name, const char *version)
 	exit(1);
 }
 
-static int
-parse_counters(char *string, struct xt_counters *ctr)
-{
-	__u64 *pcnt, *bcnt;
-
-	if (string != NULL) {
-		pcnt = &ctr->pcnt;
-		bcnt = &ctr->bcnt;
-		return (sscanf
-			(string, "[%llu:%llu]",
-			 (unsigned long long *)pcnt,
-			 (unsigned long long *)bcnt) == 2);
-	} else
-		return (0 == 2);
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static unsigned int newargc;
diff --git a/iptables/xshared.c b/iptables/xshared.c
index 06db72d427e21..ec5c49556b38d 100644
--- a/iptables/xshared.c
+++ b/iptables/xshared.c
@@ -359,6 +359,20 @@ void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval)
 	xtables_error(PARAMETER_PROBLEM, "wait interval not numeric");
 }
 
+int parse_counters(const char *string, struct xt_counters *ctr)
+{
+	int ret;
+
+	if (!string)
+		return 0;
+
+	ret = sscanf(string, "[%llu:%llu]",
+		     (unsigned long long *)&ctr->pcnt,
+		     (unsigned long long *)&ctr->bcnt);
+
+	return ret == 2;
+}
+
 inline bool xs_has_arg(int argc, char *argv[])
 {
 	return optind < argc &&
diff --git a/iptables/xshared.h b/iptables/xshared.h
index 363549db78894..55249341a19ba 100644
--- a/iptables/xshared.h
+++ b/iptables/xshared.h
@@ -150,6 +150,7 @@ extern int xtables_lock_or_exit(int wait, struct timeval *tv);
 
 int parse_wait_time(int argc, char *argv[]);
 void parse_wait_interval(int argc, char *argv[], struct timeval *wait_interval);
+int parse_counters(const char *string, struct xt_counters *ctr);
 bool xs_has_arg(int argc, char *argv[]);
 
 extern const struct xtables_afinfo *afinfo;
diff --git a/iptables/xtables-restore.c b/iptables/xtables-restore.c
index 0a3d1a3116782..018d3fd3c80b0 100644
--- a/iptables/xtables-restore.c
+++ b/iptables/xtables-restore.c
@@ -56,17 +56,6 @@ static void print_usage(const char *name, const char *version)
 			"	   [ --ipv6 ]\n", name);
 }
 
-static int parse_counters(char *string, struct xt_counters *ctr)
-{
-	unsigned long long pcnt, bcnt;
-	int ret;
-
-	ret = sscanf(string, "[%llu:%llu]", &pcnt, &bcnt);
-	ctr->pcnt = pcnt;
-	ctr->bcnt = bcnt;
-	return ret == 2;
-}
-
 /* global new argv and argc */
 static char *newargv[255];
 static int newargc;
-- 
2.18.0

--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux