Blame SOURCES/0046-ebtables-Fix-rule-listing-with-counters.patch

8cce6c
From 9092e808178de68c21ef35faeff153ddde1cffd1 Mon Sep 17 00:00:00 2001
8cce6c
From: Phil Sutter <phil@nwl.cc>
8cce6c
Date: Mon, 21 Jan 2019 17:43:34 +0100
8cce6c
Subject: [PATCH] ebtables: Fix rule listing with counters
8cce6c
8cce6c
This is a partial revert of commit 583b27eabcad6 ("ebtables-save: add -c
8cce6c
option, using xtables-style counters") which broke ruleset listing with
8cce6c
'--Lc' flag turned on:
8cce6c
8cce6c
| # ebtables-nft -L --Lc
8cce6c
| Bridge table: filter
8cce6c
|
8cce6c
| Bridge chain: INPUT, entries: 0, policy: ACCEPT
8cce6c
|
8cce6c
| Bridge chain: FORWARD, entries: 2, policy: ACCEPT
8cce6c
| -j foo
8cce6c
|  , pcnt = 0 -- bcnt = 0-j ACCEPT
8cce6c
|  , pcnt = 0 -- bcnt = 0
8cce6c
| Bridge chain: OUTPUT, entries: 0, policy: ACCEPT
8cce6c
|
8cce6c
| Bridge chain: foo, entries: 1, policy: RETURN
8cce6c
| -j ACCEPT
8cce6c
|  , pcnt = 0 -- bcnt = 0%
8cce6c
8cce6c
(That percentage sign means no newline after last line of output and
8cce6c
doesn't belong to ebtables-nft's output.)
8cce6c
8cce6c
Problem was that nft_bridge_print_rule() printed the counters after
8cce6c
nft_bridge_save_rule() had already printed the newline character.
8cce6c
8cce6c
Note also that there is no need to remove FMT_EBT_SAVE bit from 'format'
8cce6c
variable: It is set only by ebtables-nft-save which doesn't call
8cce6c
nft_bridge_print_rule().
8cce6c
8cce6c
Fixes: 583b27eabcad6 ("ebtables-save: add -c option, using xtables-style counters")
8cce6c
Signed-off-by: Phil Sutter <phil@nwl.cc>
8cce6c
Signed-off-by: Florian Westphal <fw@strlen.de>
8cce6c
(cherry picked from commit 32ebc39f71e8107d6069a9f6fba8338a2823889d)
8cce6c
Signed-off-by: Phil Sutter <psutter@redhat.com>
8cce6c
---
8cce6c
 iptables/nft-bridge.c | 11 ++++++-----
8cce6c
 1 file changed, 6 insertions(+), 5 deletions(-)
8cce6c
8cce6c
diff --git a/iptables/nft-bridge.c b/iptables/nft-bridge.c
8cce6c
index 140fcf0a31b84..43b3e3e9649b8 100644
8cce6c
--- a/iptables/nft-bridge.c
8cce6c
+++ b/iptables/nft-bridge.c
8cce6c
@@ -479,6 +479,11 @@ static void nft_bridge_save_rule(const void *data, unsigned int format)
8cce6c
 		       (uint64_t)cs->counters.pcnt,
8cce6c
 		       (uint64_t)cs->counters.bcnt);
8cce6c
 
8cce6c
+	if (!(format & FMT_NOCOUNTS))
8cce6c
+		printf(" , pcnt = %"PRIu64" -- bcnt = %"PRIu64"",
8cce6c
+		       (uint64_t)cs->counters.pcnt,
8cce6c
+		       (uint64_t)cs->counters.bcnt);
8cce6c
+
8cce6c
 	if (!(format & FMT_NONEWLINE))
8cce6c
 		fputc('\n', stdout);
8cce6c
 }
8cce6c
@@ -492,11 +497,7 @@ static void nft_bridge_print_rule(struct nftnl_rule *r, unsigned int num,
8cce6c
 		printf("%d ", num);
8cce6c
 
8cce6c
 	nft_rule_to_ebtables_command_state(r, &cs);
8cce6c
-	nft_bridge_save_rule(&cs, format & ~FMT_EBT_SAVE);
8cce6c
-	if (!(format & FMT_NOCOUNTS))
8cce6c
-		printf(" , pcnt = %"PRIu64" -- bcnt = %"PRIu64"",
8cce6c
-		       (uint64_t)cs.counters.pcnt,
8cce6c
-		       (uint64_t)cs.counters.bcnt);
8cce6c
+	nft_bridge_save_rule(&cs, format);
8cce6c
 	ebt_cs_clean(&cs);
8cce6c
 }
8cce6c
 
8cce6c
-- 
8cce6c
2.20.1
8cce6c