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);
16 static void cmp_devices(
const char *
const *adevs,
17 const char *
const *bdevs)
23 if (!!adevs ^ !!bdevs)
24 print_err(
"Flowtable devices mismatches");
25 for (i = 0; adevs[i] && bdevs[i]; i++) {
26 if (strcmp(adevs[i], bdevs[i]))
29 if (adevs[i] || bdevs[i])
30 print_err(
"Flowtable devices mismatches");
35 if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_NAME),
36 nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_NAME)) != 0)
37 print_err(
"Flowtable name mismatches");
38 if (strcmp(nftnl_flowtable_get_str(a, NFTNL_FLOWTABLE_TABLE),
39 nftnl_flowtable_get_str(b, NFTNL_FLOWTABLE_TABLE)) != 0)
40 print_err(
"Flowtable table mismatches");
41 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FAMILY) !=
42 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FAMILY))
43 print_err(
"Flowtable family mismatches");
44 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_HOOKNUM) !=
45 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_HOOKNUM))
46 print_err(
"Flowtable hooknum mismatches");
47 if (nftnl_flowtable_get_s32(a, NFTNL_FLOWTABLE_PRIO) !=
48 nftnl_flowtable_get_s32(b, NFTNL_FLOWTABLE_PRIO))
49 print_err(
"Flowtable prio mismatches");
50 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_USE) !=
51 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_USE))
52 print_err(
"Flowtable use mismatches");
54 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_SIZE) !=
55 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_SIZE))
56 print_err(
"Flowtable size mismatches");
58 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FLAGS) !=
59 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FLAGS))
60 print_err(
"Flowtable flags mismatches");
61 if (nftnl_flowtable_get_u64(a, NFTNL_FLOWTABLE_HANDLE) !=
62 nftnl_flowtable_get_u64(b, NFTNL_FLOWTABLE_HANDLE))
63 print_err(
"Flowtable handle mismatches");
64 cmp_devices(nftnl_flowtable_get_array(a, NFTNL_FLOWTABLE_DEVICES),
65 nftnl_flowtable_get_array(b, NFTNL_FLOWTABLE_DEVICES));
68 int main(
int argc,
char *argv[])
70 const char *devs[] = {
"eth0",
"eth1",
"eth2", NULL };
75 a = nftnl_flowtable_alloc();
76 b = nftnl_flowtable_alloc();
77 if (a == NULL || b == NULL)
80 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_NAME,
"test");
81 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FAMILY, AF_INET);
82 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_TABLE,
"Table");
83 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_HOOKNUM, 0x34567812);
84 nftnl_flowtable_set_s32(a, NFTNL_FLOWTABLE_PRIO, 0x56781234);
85 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_USE, 0x78123456);
86 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_SIZE, 0x89016745);
87 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FLAGS, 0x45016723);
88 nftnl_flowtable_set_u64(a, NFTNL_FLOWTABLE_HANDLE, 0x2345016789);
89 nftnl_flowtable_set_array(a, NFTNL_FLOWTABLE_DEVICES, devs);
91 nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWFLOWTABLE, AF_INET,
93 nftnl_flowtable_nlmsg_build_payload(nlh, a);
95 if (nftnl_flowtable_nlmsg_parse(nlh, b) < 0)
96 print_err(
"parsing problems");
98 cmp_nftnl_flowtable(a, b);
100 nftnl_flowtable_free(a);
101 nftnl_flowtable_free(b);
106 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);