netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas CARRIER <nicolas.carrier.ext@parrot.com>
To: <netfilter-devel@vger.kernel.org>
Subject: [PATCH]iptables-save: fix don't show counters by default
Date: Thu, 10 May 2012 11:40:33 +0200	[thread overview]
Message-ID: <4FAB8D11.4040704@parrot.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 304 bytes --]

When one issue an iptables-save command, counters are always shown in front of policies, which doesn't seem to be the desired result.
The attached patch tries to fix this. It uses the global show_counters flag to decide if counters will be shown.

-- 
Nicolas CARRIER - Parrot France - Software Engineer

[-- Attachment #2: 0001-iptables-save-fix-don-t-show-counters-by-default.patch --]
[-- Type: text/x-diff, Size: 1857 bytes --]

>From 8ccc08a6b0fde5544145f6831b7f80d1bf8bbdf0 Mon Sep 17 00:00:00 2001
From: Nicolas CARRIER <nicolas.carrier.ext@parrot.com>
Date: Thu, 10 May 2012 11:25:53 +0200
Subject: [PATCH] iptables-save: fix don't show counters by default

---
 iptables/ip6tables-save.c |    9 ++++++---
 iptables/iptables-save.c  |    9 ++++++---
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/iptables/ip6tables-save.c b/iptables/ip6tables-save.c
index d819b30..4e7e4e8 100644
--- a/iptables/ip6tables-save.c
+++ b/iptables/ip6tables-save.c
@@ -90,11 +90,14 @@ static int do_output(const char *tablename)
 		printf(":%s ", chain);
 		if (ip6tc_builtin(chain, h)) {
 			struct xt_counters count;
-			printf("%s ",
+			printf("%s",
 			       ip6tc_get_policy(chain, &count, h));
-			printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
+			if (show_counters)
+				printf(" [%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
+			else
+				printf("\n");
 		} else {
-			printf("- [0:0]\n");
+			printf("-%s\n", show_counters ? " [0:0]" : "");
 		}
 	}
 
diff --git a/iptables/iptables-save.c b/iptables/iptables-save.c
index e599fce..6322c51 100644
--- a/iptables/iptables-save.c
+++ b/iptables/iptables-save.c
@@ -88,11 +88,14 @@ static int do_output(const char *tablename)
 		printf(":%s ", chain);
 		if (iptc_builtin(chain, h)) {
 			struct xt_counters count;
-			printf("%s ",
+			printf("%s",
 			       iptc_get_policy(chain, &count, h));
-			printf("[%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
+			if (show_counters)
+				printf(" [%llu:%llu]\n", (unsigned long long)count.pcnt, (unsigned long long)count.bcnt);
+			else
+				printf("\n");
 		} else {
-			printf("- [0:0]\n");
+			printf("-%s\n", show_counters ? " [0:0]" : "");
 		}
 	}
 
-- 
1.7.10


             reply	other threads:[~2012-05-10  9:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-10  9:40 Nicolas CARRIER [this message]
2012-05-14  8:39 ` [PATCH]iptables-save: fix don't show counters by default Pablo Neira Ayuso

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FAB8D11.4040704@parrot.com \
    --to=nicolas.carrier.ext@parrot.com \
    --cc=netfilter-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).