netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Westphal <fw@strlen.de>
To: netfilter-devel@vger.kernel.org
Cc: Florian Westphal <fw@strlen.de>
Subject: [PATCH 2/3] conntrack, expect: fix _cmp api with STRICT checking
Date: Sat,  1 Jun 2013 14:59:30 +0200	[thread overview]
Message-ID: <1370091571-23140-2-git-send-email-fw@strlen.de> (raw)
In-Reply-To: <1370091571-23140-1-git-send-email-fw@strlen.de>

Normal comparision succeeds when the _common_ attribute subset
have same values.

When STRICT matching is specified, the comparision should succeed only when
both objects have same attribute subset and attribute values match.

However, STRICT comparision often fails as an attribute missing in both
objects is erronously considered an error.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 src/conntrack/compare.c | 6 +++++-
 src/expect/compare.c    | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/conntrack/compare.c b/src/conntrack/compare.c
index e282a24..97c25cb 100644
--- a/src/conntrack/compare.c
+++ b/src/conntrack/compare.c
@@ -17,8 +17,12 @@ static int __cmp(int attr,
 		 	    const struct nf_conntrack *ct2,
 			    unsigned int flags))
 {
-	if (test_bit(attr, ct1->head.set) && test_bit(attr, ct2->head.set)) {
+	int a = test_bit(attr, ct1->head.set);
+	int b = test_bit(attr, ct2->head.set);
+	if (a && b) {
 		return cmp(ct1, ct2, flags);
+	} else if (!a && !b) {
+		return 1;
 	} else if (flags & NFCT_CMP_MASK &&
 		   test_bit(attr, ct1->head.set)) {
 		return 0;
diff --git a/src/expect/compare.c b/src/expect/compare.c
index a524f4c..484d7b1 100644
--- a/src/expect/compare.c
+++ b/src/expect/compare.c
@@ -18,8 +18,13 @@ static int exp_cmp(int attr,
 			      const struct nf_expect *exp2,
 			      unsigned int flags))
 {
-	if (test_bit(attr, exp1->set) && test_bit(attr, exp2->set)) {
+	int a = test_bit(attr, exp1->set);
+	int b = test_bit(attr, exp2->set);
+
+	if (a && b) {
 		return cmp(exp1, exp2, flags);
+	} else if (!a && !b) {
+		return 1;
 	} else if (flags & NFCT_CMP_MASK &&
 		   test_bit(attr, exp1->set)) {
 		return 0;
-- 
1.8.1.5


  reply	other threads:[~2013-06-01 13:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-01 12:59 [PATCH lnf-conntrack 1/3] qa: add api test for nfct_cmp and nfct_exp functions Florian Westphal
2013-06-01 12:59 ` Florian Westphal [this message]
2013-06-01 12:59 ` [PATCH 3/3] expect: consider all expect attributes when comparing Florian Westphal
2013-06-05  2:51   ` Pablo Neira Ayuso
2013-06-05  7:35     ` Florian Westphal
2013-06-05 15:41       ` Florian Westphal
2013-06-05 17:46         ` Pablo Neira Ayuso
2013-06-05 20:33           ` Florian Westphal

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=1370091571-23140-2-git-send-email-fw@strlen.de \
    --to=fw@strlen.de \
    --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).