From 0b3bafcedff19b69ff5a51855da28e8e83c05b71 Mon Sep 17 00:00:00 2001 From: Giuseppe Longo Date: Fri, 12 Jul 2013 13:27:33 +0200 Subject: xtables: nft: display rule by number via -L This patch fixes the display of rule by number. [ Mangled this patch not to display the header, to mimic iptables --pablo ] Signed-off-by: Giuseppe Longo Signed-off-by: Pablo Neira Ayuso --- iptables/nft.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'iptables/nft.c') diff --git a/iptables/nft.c b/iptables/nft.c index e660878c..a9a391df 100644 --- a/iptables/nft.c +++ b/iptables/nft.c @@ -2394,19 +2394,21 @@ __nft_rule_list(struct nft_handle *h, struct nft_chain *c, const char *table, strcmp(chain, rule_chain) != 0) goto next; - if (rulenum > 0) { + if (rulenum > 0 && rule_ctr != rulenum) { /* List by rule number case */ - if (rule_ctr != rulenum) { - rule_ctr++; - goto next; - } - } else { - struct iptables_command_state cs = {}; - /* Show all rules case */ - nft_rule_to_iptables_command_state(r, &cs); + goto next; + } - cb(&cs, r, rule_ctr, format); + struct iptables_command_state cs = {}; + /* Show all rules case */ + nft_rule_to_iptables_command_state(r, &cs); + + cb(&cs, r, rule_ctr, format); + if (rulenum > 0 && rule_ctr == rulenum) { + ret = 1; + break; } + next: r = nft_rule_list_iter_next(iter); } @@ -2466,9 +2468,10 @@ int nft_rule_list(struct nft_handle *h, const char *chain, const char *table, if (found) printf("\n"); - print_header(format, chain_name, policy_name[policy], &ctrs, - basechain, refs); - + if (!rulenum) { + print_header(format, chain_name, policy_name[policy], + &ctrs, basechain, refs); + } __nft_rule_list(h, c, table, rulenum, format, print_firewall); found = true; -- cgit v1.2.3