netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh
@ 2016-08-10 15:12 Carlos Falgueras García
  2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: Carlos Falgueras García @ 2016-08-10 15:12 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 tests/test-script.sh | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tests/test-script.sh b/tests/test-script.sh
index b040158..ba13571 100755
--- a/tests/test-script.sh
+++ b/tests/test-script.sh
@@ -4,7 +4,9 @@
 ./nft-expr_cmp-test
 ./nft-expr_counter-test
 ./nft-expr_ct-test
+./nft-expr_dup-test
 ./nft-expr_exthdr-test
+./nft-expr_fwd-test
 ./nft-expr_immediate-test
 ./nft-expr_limit-test
 ./nft-expr_log-test
@@ -12,6 +14,7 @@
 ./nft-expr_match-test
 ./nft-expr_masq-test
 ./nft-expr_meta-test
+./nft-expr_queue-test
 ./nft-expr_redir-test
 ./nft-expr_nat-test
 ./nft-expr_payload-test
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3, libnftnl] expr: Fix lookup builder
  2016-08-10 15:12 [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Carlos Falgueras García
@ 2016-08-10 15:12 ` Carlos Falgueras García
  2016-08-10 16:48   ` Pablo Neira Ayuso
  2016-08-11 23:52   ` Pablo Neira Ayuso
  2016-08-10 15:12 ` [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions Carlos Falgueras García
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 8+ messages in thread
From: Carlos Falgueras García @ 2016-08-10 15:12 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

Deleted wrong braces that cause unwanted behaviour.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 src/expr/lookup.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 57612d1..60da653 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -122,12 +122,11 @@ nftnl_expr_lookup_build(struct nlmsghdr *nlh, const struct nftnl_expr *e)
 		mnl_attr_put_u32(nlh, NFTA_LOOKUP_DREG, htonl(lookup->dreg));
 	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET))
 		mnl_attr_put_strz(nlh, NFTA_LOOKUP_SET, lookup->set_name);
-	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET_ID)) {
+	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_SET_ID))
 		mnl_attr_put_u32(nlh, NFTA_LOOKUP_SET_ID,
 				 htonl(lookup->set_id));
 	if (e->flags & (1 << NFTNL_EXPR_LOOKUP_FLAGS))
 		mnl_attr_put_u32(nlh, NFTA_LOOKUP_FLAGS, htonl(lookup->flags));
-	}
 }
 
 static int
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions
  2016-08-10 15:12 [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Carlos Falgueras García
  2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
@ 2016-08-10 15:12 ` Carlos Falgueras García
  2016-08-10 16:49   ` Pablo Neira Ayuso
  2016-08-10 16:48 ` [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Pablo Neira Ayuso
  2016-08-11 23:52 ` Pablo Neira Ayuso
  3 siblings, 1 reply; 8+ messages in thread
From: Carlos Falgueras García @ 2016-08-10 15:12 UTC (permalink / raw)
  To: netfilter-devel; +Cc: pablo

An error at Makefile.am has caused that the tests
'nft-expr_immediate-test.c' and 'nft-expr_lookup-tests.c' have not been
compiled since they were created. This patch fix that error and some errors
in both tests.

Signed-off-by: Carlos Falgueras García <carlosfg@riseup.net>
---
 tests/Makefile.am               |  4 +--
 tests/nft-expr_immediate-test.c | 72 ++++++++++++++++++++++++++++-------------
 tests/nft-expr_lookup-test.c    | 26 +++++++++------
 3 files changed, 67 insertions(+), 35 deletions(-)

diff --git a/tests/Makefile.am b/tests/Makefile.am
index c246034..0377081 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -70,13 +70,13 @@ nft_expr_dup_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 nft_expr_fwd_test_SOURCES = nft-expr_fwd-test.c
 nft_expr_fwd_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_expr_immediate_test_SOURCES = nft-expr_counter-test.c
+nft_expr_immediate_test_SOURCES = nft-expr_immediate-test.c
 nft_expr_immediate_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
 nft_expr_limit_test_SOURCES = nft-expr_limit-test.c
 nft_expr_limit_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
-nft_expr_lookup_test_SOURCES = nft-expr_limit-test.c
+nft_expr_lookup_test_SOURCES = nft-expr_lookup-test.c
 nft_expr_lookup_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
 
 nft_expr_log_test_SOURCES = nft-expr_log-test.c
diff --git a/tests/nft-expr_immediate-test.c b/tests/nft-expr_immediate-test.c
index 695e0b0..e07092f 100644
--- a/tests/nft-expr_immediate-test.c
+++ b/tests/nft-expr_immediate-test.c
@@ -27,52 +27,71 @@ static void print_err(const char *msg)
 	printf("\033[31mERROR:\e[0m %s\n", msg);
 }
 
-static void cmp_nftnl_expr(struct nftnl_expr *rule_a,
-			      struct nftnl_expr *rule_b)
+static void cmp_nftnl_expr_verdict(struct nftnl_expr *rule_a,
+				   struct nftnl_expr *rule_b)
 {
-	uint32_t data_a, data_b, chain_a, chain_b;
+	uint32_t len_a, len_b;
+	const char *chain_a, *chain_b;
 
 	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_IMM_DREG) !=
 	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_IMM_DREG))
 		print_err("Expr NFTNL_EXPR_IMM_DREG mismatches");
-	nftnl_expr_get(rule_a, NFTNL_EXPR_IMM_DATA, data_a);
-	nftnl_expr_get(rule_b, NFTNL_EXPR_IMM_DATA, data_b)
+
 	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_IMM_VERDICT) !=
 	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_IMM_VERDICT))
 		print_err("Expr NFTNL_EXPR_IMM_VERDICT mismatches");
-	nftnl_expr_get(rule_a, NFTNL_EXPR_IMM_CHAIN, chain_a);
-	nftnl_expr_get(rule_b, NFTNL_EXPR_IMM_CHAIN, chain_b);
-	if (data_a != data_b)
-		print_err("Expr NFTNL_EXPR_IMM_DATA. Size mismatches");
-	if (chain_a != chain_b)
-		print_err("Expr NFTNL_EXPR_IMM_CHAIN. Size mismatches");
+
+	chain_a = nftnl_expr_get(rule_a, NFTNL_EXPR_IMM_CHAIN, &len_a);
+	chain_b = nftnl_expr_get(rule_b, NFTNL_EXPR_IMM_CHAIN, &len_b);
+	if (len_a != len_b || strncmp(chain_a, chain_b, len_a))
+		print_err("Expr NFTNL_EXPR_IMM_CHAIN mismatches");
+}
+
+static void cmp_nftnl_expr_value(struct nftnl_expr *rule_a,
+				 struct nftnl_expr *rule_b)
+{
+	const uint32_t *data_a, *data_b;
+	uint32_t len_a, len_b;
+
+	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_IMM_DREG) !=
+	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_IMM_DREG))
+		print_err("Expr NFTNL_EXPR_IMM_DREG mismatches");
+
+	data_a = nftnl_expr_get(rule_a, NFTNL_EXPR_IMM_DATA, &len_a);
+	data_b = nftnl_expr_get(rule_b, NFTNL_EXPR_IMM_DATA, &len_b);
+	if (len_a != len_b || memcmp(data_a, data_b, len_a))
+		print_err("Expr NFTNL_EXPR_IMM_DATA mismatches");
 }
 
 int main(int argc, char *argv[])
 {
 	struct nftnl_rule *a, *b;
-	struct nftnl_expr *ex;
+	struct nftnl_expr *ex_val, *ex_ver;
 	struct nlmsghdr *nlh;
 	char buf[4096];
 	struct nftnl_expr_iter *iter_a, *iter_b;
 	struct nftnl_expr *rule_a, *rule_b;
-	uint32_t chain = 0x12345678;
-	uint32_t data = 0x56781234;
+	char chain[] = "tests_chain01234";
+	char data[] = "test_data_01234";
 
 	a = nftnl_rule_alloc();
 	b = nftnl_rule_alloc();
 	if (a == NULL || b == NULL)
 		print_err("OOM");
-	ex = nftnl_expr_alloc("immediate");
-	if (ex == NULL)
+	ex_val = nftnl_expr_alloc("immediate");
+	ex_ver = nftnl_expr_alloc("immediate");
+	if (!ex_val || !ex_ver)
 		print_err("OOM");
 
-	nftnl_expr_set_u32(ex, NFTNL_EXPR_IMM_DREG, 0x1234568);
-	nftnl_expr_set(ex, NFTNL_EXPR_IMM_DATA, &data, sizeof(data));
-	nftnl_expr_set_u32(ex, NFTNL_EXPR_IMM_VERDICT, 0x78123456);
-	nftnl_expr_set(ex, NFTNL_EXPR_IMM_CHAIN, &chain, sizeof(chain));
+	nftnl_expr_set_u32(ex_val, NFTNL_EXPR_IMM_DREG, 0x1234568);
+	nftnl_expr_set(ex_val,     NFTNL_EXPR_IMM_DATA, data, sizeof(data));
+
+	nftnl_expr_set_u32(ex_ver, NFTNL_EXPR_IMM_DREG,    0x1234568);
+	nftnl_expr_set_u32(ex_ver, NFTNL_EXPR_IMM_VERDICT, NFT_GOTO);
+	nftnl_expr_set(ex_ver,     NFTNL_EXPR_IMM_CHAIN, chain, sizeof(chain));
 
-	nftnl_rule_add_expr(a, ex);
+	nftnl_rule_add_expr(a, ex_val);
+	nftnl_rule_add_expr(a, ex_ver);
 
 	nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234);
 	nftnl_rule_nlmsg_build_payload(nlh, a);
@@ -90,11 +109,18 @@ int main(int argc, char *argv[])
 	if (rule_a == NULL || rule_b == NULL)
 		print_err("OOM");
 
-	cmp_nftnl_expr(rule_a, rule_b);
+	cmp_nftnl_expr_value(rule_a, rule_b);
+
+	rule_a = nftnl_expr_iter_next(iter_a);
+	rule_b = nftnl_expr_iter_next(iter_b);
+	if (rule_a == NULL || rule_b == NULL)
+		print_err("OOM");
+
+	cmp_nftnl_expr_verdict(rule_a, rule_b);
 
 	if (nftnl_expr_iter_next(iter_a) != NULL ||
 	    nftnl_expr_iter_next(iter_b) != NULL)
-		print_err("More 1 expr.");
+		print_err("More 2 expr.");
 
 	nftnl_expr_iter_destroy(iter_a);
 	nftnl_expr_iter_destroy(iter_b);
diff --git a/tests/nft-expr_lookup-test.c b/tests/nft-expr_lookup-test.c
index e52345f..d1f017b 100644
--- a/tests/nft-expr_lookup-test.c
+++ b/tests/nft-expr_lookup-test.c
@@ -31,17 +31,24 @@ static void cmp_nftnl_expr(struct nftnl_expr *rule_a,
 			      struct nftnl_expr *rule_b)
 {
 	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_LOOKUP_SREG) !=
-	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOPUP_SREG))
-		print_err("Expr NFTNL_EXPR_LOOkUP_SREG mismatches");
+	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOKUP_SREG))
+		print_err("Expr NFTNL_EXPR_LOOKUP_SREG mismatches");
 	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_LOOKUP_DREG) !=
-	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOPUP_DREG))
-		print_err("Expr NFTNL_EXPR_LOOkUP_DREG mismatches");
+	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOKUP_DREG))
+		print_err("Expr NFTNL_EXPR_LOOKUP_DREG mismatches");
 	if (strcmp(nftnl_expr_get_str(rule_a, NFTNL_EXPR_LOOKUP_SET),
 		   nftnl_expr_get_str(rule_b, NFTNL_EXPR_LOOKUP_SET)))
 		print_err("Expr NFTNL_EXPR_LOOKUP_SET mismatches");
+	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_LOOKUP_SET_ID) !=
+	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOKUP_SET_ID))
+		print_err("Expr NFTNL_EXPR_LOOKUP_SET_ID mismatches");
 	if (nftnl_expr_get_u32(rule_a, NFTNL_EXPR_LOOKUP_FLAGS) !=
-	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOPUP_FLAGS))
-		print_err("Expr NFTNL_EXPR_LOOkUP_FLAGS mismatches");
+	    nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOKUP_FLAGS)) {
+		print_err("Expr NFTNL_EXPR_LOOKUP_FLAGS mismatches");
+		printf("%X %X\n",
+			nftnl_expr_get_u32(rule_a, NFTNL_EXPR_LOOKUP_FLAGS),
+			nftnl_expr_get_u32(rule_b, NFTNL_EXPR_LOOKUP_FLAGS));
+	}
 }
 
 int main(int argc, char *argv[])
@@ -52,7 +59,7 @@ int main(int argc, char *argv[])
 	char buf[4096];
 	struct nftnl_expr_iter *iter_a, *iter_b;
 	struct nftnl_expr *rule_a, *rule_b;
-	uint32_t lookup_set = 0x12345678;
+	char lookup_set[] = "test_set_01243";
 
 	a = nftnl_rule_alloc();
 	b = nftnl_rule_alloc();
@@ -64,8 +71,7 @@ int main(int argc, char *argv[])
 
 	nftnl_expr_set_u32(ex, NFTNL_EXPR_LOOKUP_SREG, 0x12345678);
 	nftnl_expr_set_u32(ex, NFTNL_EXPR_LOOKUP_DREG, 0x78123456);
-	nftnl_expr_set(ex, NFTNL_EXPR_LOOKUP_SET, &lookup_set,
-			  sizeof(lookup_set));
+	nftnl_expr_set_str(ex, NFTNL_EXPR_LOOKUP_SET,  lookup_set);
 	nftnl_expr_set_u32(ex, NFTNL_EXPR_LOOKUP_FLAGS, 0x12345678);
 
 	nftnl_rule_add_expr(a, ex);
@@ -99,7 +105,7 @@ int main(int argc, char *argv[])
 	if (!test_ok)
 		exit(EXIT_FAILURE);
 
-	print(_"%s: \033[32mOK\e[0m\n", argv[0]);
+	printf("%s: \033[32mOK\e[0m\n", argv[0]);
 
 	return EXIT_SUCCESS;
 }
-- 
2.8.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh
  2016-08-10 15:12 [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Carlos Falgueras García
  2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
  2016-08-10 15:12 ` [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions Carlos Falgueras García
@ 2016-08-10 16:48 ` Pablo Neira Ayuso
  2016-08-11 23:52 ` Pablo Neira Ayuso
  3 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-10 16:48 UTC (permalink / raw)
  To: Carlos Falgueras García; +Cc: netfilter-devel

Applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3, libnftnl] expr: Fix lookup builder
  2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
@ 2016-08-10 16:48   ` Pablo Neira Ayuso
  2016-08-11 23:52   ` Pablo Neira Ayuso
  1 sibling, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-10 16:48 UTC (permalink / raw)
  To: Carlos Falgueras García; +Cc: netfilter-devel

On Wed, Aug 10, 2016 at 05:12:04PM +0200, Carlos Falgueras García wrote:
> Deleted wrong braces that cause unwanted behaviour.

Also applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions
  2016-08-10 15:12 ` [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions Carlos Falgueras García
@ 2016-08-10 16:49   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-10 16:49 UTC (permalink / raw)
  To: Carlos Falgueras García; +Cc: netfilter-devel

On Wed, Aug 10, 2016 at 05:12:05PM +0200, Carlos Falgueras García wrote:
> An error at Makefile.am has caused that the tests
> 'nft-expr_immediate-test.c' and 'nft-expr_lookup-tests.c' have not been
> compiled since they were created. This patch fix that error and some errors
> in both tests.

Applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh
  2016-08-10 15:12 [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Carlos Falgueras García
                   ` (2 preceding siblings ...)
  2016-08-10 16:48 ` [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Pablo Neira Ayuso
@ 2016-08-11 23:52 ` Pablo Neira Ayuso
  3 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-11 23:52 UTC (permalink / raw)
  To: Carlos Falgueras García; +Cc: netfilter-devel

Applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 2/3, libnftnl] expr: Fix lookup builder
  2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
  2016-08-10 16:48   ` Pablo Neira Ayuso
@ 2016-08-11 23:52   ` Pablo Neira Ayuso
  1 sibling, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2016-08-11 23:52 UTC (permalink / raw)
  To: Carlos Falgueras García; +Cc: netfilter-devel

On Wed, Aug 10, 2016 at 05:12:04PM +0200, Carlos Falgueras García wrote:
> Deleted wrong braces that cause unwanted behaviour.

Applied, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-08-11 23:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-10 15:12 [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Carlos Falgueras García
2016-08-10 15:12 ` [PATCH 2/3, libnftnl] expr: Fix lookup builder Carlos Falgueras García
2016-08-10 16:48   ` Pablo Neira Ayuso
2016-08-11 23:52   ` Pablo Neira Ayuso
2016-08-10 15:12 ` [PATCH 3/3, libnftnl] tests: Fix tests for immediate and lookup expressions Carlos Falgueras García
2016-08-10 16:49   ` Pablo Neira Ayuso
2016-08-10 16:48 ` [PATCH 1/3, libnftnl] tests: Add missing tests to test-script.sh Pablo Neira Ayuso
2016-08-11 23:52 ` Pablo Neira Ayuso

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).