4 #include <netinet/in.h>
5 #include <linux/netfilter/nf_tables.h>
6 #include <libnftnl/flowtable.h>
8 static int test_ok = 1;
10 static void print_err(
const char *msg)
13 printf(
"\033[31mERROR:\e[0m %s\n", msg);
18 if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_NAME),
19 nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_NAME)) != 0)
20 print_err(
"Flowtable name mismatches");
21 if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_TABLE),
22 nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_TABLE)) != 0)
23 print_err(
"Flowtable table mismatches");
24 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FAMILY) !=
25 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FAMILY))
26 print_err(
"Flowtable family mismatches");
27 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_HOOKNUM) !=
28 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_HOOKNUM))
29 print_err(
"Flowtable hooknum mismatches");
30 if (nftnl_flowtable_get_s32(a, NFTNL_FLOWTABLE_PRIO) !=
31 nftnl_flowtable_get_s32(b, NFTNL_FLOWTABLE_PRIO))
32 print_err(
"Flowtable prio mismatches");
33 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_USE) !=
34 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_USE))
35 print_err(
"Flowtable use mismatches");
36 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_SIZE) !=
37 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_SIZE))
38 print_err(
"Flowtable size mismatches");
39 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FLAGS) !=
40 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FLAGS))
41 print_err(
"Flowtable flags mismatches");
42 if (nftnl_flowtable_get_u64(a, NFTNL_FLOWTABLE_HANDLE) !=
43 nftnl_flowtable_get_u64(b, NFTNL_FLOWTABLE_HANDLE))
44 print_err(
"Flowtable handle mismatches");
47 int main(
int argc,
char *argv[])
53 a = nftnl_flowtable_alloc();
54 b = nftnl_flowtable_alloc();
55 if (a == NULL || b == NULL)
58 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_NAME,
"test");
59 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FAMILY, AF_INET);
60 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_TABLE,
"Table");
61 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_HOOKNUM, 0x34567812);
62 nftnl_flowtable_set_s32(a, NFTNL_FLOWTABLE_PRIO, 0x56781234);
63 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_USE, 0x78123456);
64 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_SIZE, 0x89016745);
65 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FLAGS, 0x45016723);
66 nftnl_flowtable_set_u64(a, NFTNL_FLOWTABLE_HANDLE, 0x2345016789);
68 nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWFLOWTABLE, AF_INET,
70 nftnl_flowtable_nlmsg_build_payload(nlh, a);
72 if (nftnl_flowtable_nlmsg_parse(nlh, b) < 0)
73 print_err(
"parsing problems");
75 cmp_nftnl_flowtable(a, b);
77 nftnl_flowtable_free(a);
78 nftnl_flowtable_free(b);
83 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);