From 528cbf99ff6062420270e637df4d40a77514fe56 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 7 Aug 2018 12:29:35 +0200 Subject: xtables: Fix for wrong counter format in -S output Legacy iptables uses '-c PCNT BCNT' format in listed rules, nft-variant used '[PCNT BCNT]' prefix like with iptables-save. In order to pass the counter format preference along, FMT_C_COUNTS is introduced and related 'format' checks adjusted. Since legacy iptables prints the counters between matches and target, this change affects save_matches_and_target() function. In order to get access to the rule counters, it's declaration is adjusted to receive iptables_command_state pointer instead of match, target and jumpto pointers from the same object. While being at it, integrate jump to user-defined chain into it as well since the related code in both callers was almost identical. Though since different rule flags are used between iptables and ip6tables, pass a 'goto_flag' boolean instead of the actual 'flags' bitfield. Signed-off-by: Phil Sutter Signed-off-by: Florian Westphal --- iptables/nft.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'iptables/nft.c') diff --git a/iptables/nft.c b/iptables/nft.c index 1c076510..120039ed 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -1201,7 +1201,7 @@ nft_rule_print_save(const struct nftnl_rule *r, enum nft_rule_print type, ops = nft_family_ops_lookup(family); ops->rule_to_cs(r, &cs); - if (!(format & FMT_NOCOUNTS) && ops->save_counters) + if (!(format & (FMT_NOCOUNTS | FMT_C_COUNTS)) && ops->save_counters) ops->save_counters(&cs); /* print chain name */ @@ -2396,6 +2396,7 @@ int nft_rule_list_save(struct nft_handle *h, const char *chain, { struct nftnl_chain_list *list; struct nftnl_chain_list_iter *iter; + unsigned int format = 0; struct nftnl_chain *c; int ret = 1; @@ -2410,6 +2411,11 @@ int nft_rule_list_save(struct nft_handle *h, const char *chain, if (iter == NULL) goto err; + if (counters < 0) + format = FMT_C_COUNTS; + else if (counters == 0) + format = FMT_NOCOUNTS; + c = nftnl_chain_list_iter_next(iter); while (c != NULL) { const char *chain_table = @@ -2423,7 +2429,7 @@ int nft_rule_list_save(struct nft_handle *h, const char *chain, goto next; ret = __nft_rule_list(h, chain_name, table, rulenum, - counters ? 0 : FMT_NOCOUNTS, list_save); + format, list_save); /* we printed the chain we wanted, stop processing. */ if (chain) -- cgit v1.2.3