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);
}
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;
if (linenumbers)
format |= FMT_LINENUMBERS;
- /* FIXME should return found or not, and errno = ENOENT in such case */
return nft_rule_list(h, chain, table, rulenum, format);
}