summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPablo Neira Ayuso <pablo@netfilter.org>2018-02-19 10:34:55 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2018-03-05 16:31:29 +0100
commit4d472c225ba089cef843754fa0237154f22eea0d (patch)
tree77004eefe5bc6911957e416d8bec54a990af7318 /tests
parent41fe3d38ba34b018e63ce75dc04c5db416293258 (diff)
tests: add flowtable regression test
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am4
-rw-r--r--tests/nft-flowtable-test.c81
2 files changed, 85 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 1467d99..5872bb1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,6 +9,7 @@ check_PROGRAMS = nft-parsing-test \
nft-object-test \
nft-rule-test \
nft-set-test \
+ nft-flowtable-test \
nft-expr_bitwise-test \
nft-expr_byteorder-test \
nft-expr_counter-test \
@@ -54,6 +55,9 @@ nft_rule_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
nft_set_test_SOURCES = nft-set-test.c
nft_set_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+nft_flowtable_test_SOURCES = nft-flowtable-test.c
+nft_flowtable_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
+
nft_expr_bitwise_test_SOURCES = nft-expr_bitwise-test.c
nft_expr_bitwise_test_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS}
diff --git a/tests/nft-flowtable-test.c b/tests/nft-flowtable-test.c
new file mode 100644
index 0000000..1311cf2
--- /dev/null
+++ b/tests/nft-flowtable-test.c
@@ -0,0 +1,81 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <linux/netfilter/nf_tables.h>
+#include <libnftnl/flowtable.h>
+
+static int test_ok = 1;
+
+static void print_err(const char *msg)
+{
+ test_ok = 0;
+ printf("\033[31mERROR:\e[0m %s\n", msg);
+}
+
+static void cmp_nftnl_flowtable(struct nftnl_flowtable *a, struct nftnl_flowtable *b)
+{
+ if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_NAME),
+ nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_NAME)) != 0)
+ print_err("Chain name mismatches");
+ if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_TABLE),
+ nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_TABLE)) != 0)
+ print_err("Chain table mismatches");
+ if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FAMILY) !=
+ nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FAMILY))
+ print_err("Chain family mismatches");
+ if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_HOOKNUM) !=
+ nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_HOOKNUM))
+ print_err("Chain hooknum mismatches");
+ if (nftnl_flowtable_get_s32(a, NFTNL_FLOWTABLE_PRIO) !=
+ nftnl_flowtable_get_s32(b, NFTNL_FLOWTABLE_PRIO))
+ print_err("Chain Prio mismatches");
+ if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_USE) !=
+ nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_USE))
+ print_err("Chain use mismatches");
+ if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_SIZE) !=
+ nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_SIZE))
+ print_err("Chain use mismatches");
+ if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FLAGS) !=
+ nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FLAGS))
+ print_err("Chain use mismatches");
+}
+
+int main(int argc, char *argv[])
+{
+ struct nftnl_flowtable *a, *b;
+ char buf[4096];
+ struct nlmsghdr *nlh;
+
+ a = nftnl_flowtable_alloc();
+ b = nftnl_flowtable_alloc();
+ if (a == NULL || b == NULL)
+ print_err("OOM");
+
+ nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_NAME, "test");
+ nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FAMILY, AF_INET);
+ nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_TABLE, "Table");
+ nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_HOOKNUM, 0x34567812);
+ nftnl_flowtable_set_s32(a, NFTNL_FLOWTABLE_PRIO, 0x56781234);
+ nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_USE, 0x78123456);
+ nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_SIZE, 0x89016745);
+ nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FLAGS, 0x45016723);
+
+ nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWFLOWTABLE, AF_INET,
+ 0, 1234);
+ nftnl_flowtable_nlmsg_build_payload(nlh, a);
+
+ if (nftnl_flowtable_nlmsg_parse(nlh, b) < 0)
+ print_err("parsing problems");
+
+ cmp_nftnl_flowtable(a, b);
+
+ nftnl_flowtable_free(a);
+ nftnl_flowtable_free(b);
+
+ if (!test_ok)
+ exit(EXIT_FAILURE);
+
+ printf("%s: \033[32mOK\e[0m\n", argv[0]);
+ return EXIT_SUCCESS;
+}