5#include <linux/netfilter/nf_tables.h>
6#include <libnftnl/flowtable.h>
10static 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");
37 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_SIZE) !=
38 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_SIZE))
39 print_err(
"Flowtable size mismatches");
41 if (nftnl_flowtable_get_u32(a, NFTNL_FLOWTABLE_FLAGS) !=
42 nftnl_flowtable_get_u32(b, NFTNL_FLOWTABLE_FLAGS))
43 print_err(
"Flowtable flags mismatches");
44 if (nftnl_flowtable_get_u64(a, NFTNL_FLOWTABLE_HANDLE) !=
45 nftnl_flowtable_get_u64(b, NFTNL_FLOWTABLE_HANDLE))
46 print_err(
"Flowtable handle mismatches");
49int main(
int argc,
char *argv[])
55 a = nftnl_flowtable_alloc();
56 b = nftnl_flowtable_alloc();
57 if (a == NULL || b == NULL)
60 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_NAME,
"test");
61 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FAMILY, AF_INET);
62 nftnl_flowtable_set_str(a, NFTNL_FLOWTABLE_TABLE,
"Table");
63 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_HOOKNUM, 0x34567812);
64 nftnl_flowtable_set_s32(a, NFTNL_FLOWTABLE_PRIO, 0x56781234);
65 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_USE, 0x78123456);
66 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_SIZE, 0x89016745);
67 nftnl_flowtable_set_u32(a, NFTNL_FLOWTABLE_FLAGS, 0x45016723);
68 nftnl_flowtable_set_u64(a, NFTNL_FLOWTABLE_HANDLE, 0x2345016789);
70 nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWFLOWTABLE, AF_INET,
72 nftnl_flowtable_nlmsg_build_payload(nlh, a);
74 if (nftnl_flowtable_nlmsg_parse(nlh, b) < 0)
75 print_err(
"parsing problems");
77 cmp_nftnl_flowtable(a, b);
79 nftnl_flowtable_free(a);
80 nftnl_flowtable_free(b);
85 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);