summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2014-06-19 16:42:49 +0200
committerFlorian Westphal <fw@strlen.de>2014-06-19 17:03:50 +0200
commit169b1a3f37a70018aa402d90ba564ad01cb3a4cd (patch)
treef88e462fd221a7cba5b50713bd1c23da456e382c
parent877de12b85f3eb46096022c4933c7647bb89f17a (diff)
qa: add cmp ATTR_ZONE regression test cases
As reported by Ken-ichirou MATSUZAWA: "conntrack -L --zone 0" doesn't list any output. nfct_cmp(mask_obj, ct, NFCT_CMP_MASK) considers ct to not match since the zone attribute in ct is not set for the default (0) zone. libnetfilter_conntrack should be more permissive and return that these are equal iff 'mask_obj' has ATTR_ZONE with a 0 value, and ct object has ATTR_ZONE not set. These 3 checks currently fail, even though they really should not: assert(test_cmp_attr32(ATTR_ZONE, true, false, 0, 0, NFCT_CMP_STRICT) == 1); assert(test_cmp_attr32(ATTR_ZONE, false, true, 0, 0, NFCT_CMP_STRICT) == 1); assert(test_cmp_attr32(ATTR_ZONE, true, false, 0, 0, NFCT_CMP_MASK) == 1); Altough in all 3 cases the zone is only set in one conntrack, the value is zero, so it should be equal to a conntrack object without the zone bit set. Signed-off-by: Florian Westphal <fw@strlen.de>
-rw-r--r--qa/test_api.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/qa/test_api.c b/qa/test_api.c
index 583feb8..91b3dbf 100644
--- a/qa/test_api.c
+++ b/qa/test_api.c
@@ -4,6 +4,7 @@
#include <assert.h>
#include <stdio.h>
+#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
@@ -242,12 +243,57 @@ static int test_nfct_cmp_api_single(struct nf_conntrack *ct1,
return 0;
}
+static int test_cmp_attr32(int attr, bool at1, bool at2,
+ uint32_t v1, uint32_t v2, unsigned int flags)
+{
+ struct nf_conntrack *ct1 = nfct_new();
+ struct nf_conntrack *ct2 = nfct_new();
+ int ret;
+
+ if (at1)
+ nfct_set_attr_u32(ct1, attr, v1);
+ if (at2)
+ nfct_set_attr_u32(ct2, attr, v2);
+
+ ret = nfct_cmp(ct1, ct2, NFCT_CMP_ALL | flags);
+
+ nfct_destroy(ct1);
+ nfct_destroy(ct2);
+
+ return ret;
+}
+static void test_nfct_cmp_attr(int attr)
+{
+ assert(test_cmp_attr32(ATTR_ZONE, false, false, 0, 0, 0) == 1);
+ assert(test_cmp_attr32(ATTR_ZONE, true, true, 0, 0, 0) == 1);
+ assert(test_cmp_attr32(ATTR_ZONE, true, true, 1, 1, 0) == 1);
+
+ /* This compare should be true */
+ assert(test_cmp_attr32(ATTR_ZONE, false, true, 0, 1, 0) == 1);
+
+ assert(test_cmp_attr32(ATTR_ZONE, true, true, 1, 1, NFCT_CMP_STRICT) == 1);
+
+ assert(test_cmp_attr32(ATTR_ZONE, true, false, 0, 0, NFCT_CMP_STRICT) == 1);
+ assert(test_cmp_attr32(ATTR_ZONE, false, true, 0, 0, NFCT_CMP_STRICT) == 1);
+
+ assert(test_cmp_attr32(ATTR_ZONE, false, true, 0, 1, NFCT_CMP_STRICT) == 0);
+
+ assert(test_cmp_attr32(ATTR_ZONE, false, true, 0, 1, NFCT_CMP_MASK) == 1);
+ assert(test_cmp_attr32(ATTR_ZONE, true, true, 0, 1, NFCT_CMP_MASK) == 0);
+
+ assert(test_cmp_attr32(ATTR_ZONE, true, false, 0, 0, NFCT_CMP_MASK) == 1);
+
+ assert(test_cmp_attr32(ATTR_ZONE, true, false, 1, 0, NFCT_CMP_MASK) == 0);
+}
+
static void test_nfct_cmp_api(struct nf_conntrack *ct1, struct nf_conntrack *ct2)
{
int i;
printf("== test cmp API ==\n");
+ test_nfct_cmp_attr(ATTR_ZONE);
+
assert(nfct_cmp(ct1, ct2, NFCT_CMP_ALL) == 1);
assert(nfct_cmp(ct1, ct2, NFCT_CMP_ALL|NFCT_CMP_STRICT) == 0);