netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Woerner <twoerner@redhat.com>
To: netfilter-devel@vger.kernel.org
Cc: Thomas Woerner <twoerner@redhat.com>
Subject: [IPTABLES 2/2] iptables-compat: Increase rule number only for the selected table and chain
Date: Tue, 21 Jul 2015 15:45:42 +0200	[thread overview]
Message-ID: <1437486342-6917-3-git-send-email-twoerner@redhat.com> (raw)
In-Reply-To: <1437486342-6917-1-git-send-email-twoerner@redhat.com>

This patch fixes the rule number handling in nft_rule_find and __nft_rule_list. The rule number is only valid in the selected table and chain and therefore may
not be increased for other tables or chains.

Signed-off-by: Thomas Woerner <twoerner@redhat.com>
---
:100644 100644 323f124... 139cf5a... M	iptables/nft.c
 iptables/nft.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/iptables/nft.c b/iptables/nft.c
index 323f124..139cf5a 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1746,17 +1746,17 @@ nft_rule_find(struct nft_handle *h, struct nft_rule_list *list,
 
 		if (rulenum >= 0) {
 			/* Delete by rule number case */
-			if (rule_ctr != rulenum)
-				goto next;
-			found = true;
-			break;
+			if (rule_ctr == rulenum) {
+			    found = true;
+			    break;
+			}
 		} else {
 			found = h->ops->rule_find(h->ops, r, data);
 			if (found)
 				break;
 		}
-next:
 		rule_ctr++;
+next:
 		r = nft_rule_list_iter_next(iter);
 	}
 
@@ -1965,12 +1965,12 @@ __nft_rule_list(struct nft_handle *h, const char *chain, const char *table,
 		const char *rule_chain =
 			nft_rule_attr_get_str(r, NFT_RULE_ATTR_CHAIN);
 
-		rule_ctr++;
-
 		if (strcmp(table, rule_table) != 0 ||
 		    strcmp(chain, rule_chain) != 0)
 			goto next;
 
+		rule_ctr++;
+
 		if (rulenum > 0 && rule_ctr != rulenum) {
 			/* List by rule number case */
 			goto next;
-- 
2.4.3


  parent reply	other threads:[~2015-07-21 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-21 13:45 [IPTABLES 0/2] iptables-compat fixes Thomas Woerner
2015-07-21 13:45 ` [IPTABLES 1/2] iptables-compat: Allow to insert into rule_count+1 position Thomas Woerner
2015-07-21 13:45 ` Thomas Woerner [this message]
2015-07-23 14:58 ` [IPTABLES 0/2] iptables-compat fixes 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=1437486342-6917-3-git-send-email-twoerner@redhat.com \
    --to=twoerner@redhat.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).