15 #include <netinet/in.h>
16 #include <linux/netfilter/nf_tables.h>
17 #include <libnftnl/rule.h>
19 static int test_ok = 1;
21 static void print_err(
const char *msg)
24 printf(
"\033[31mERROR:\e[0m %s\n", msg);
29 if (nftnl_rule_get_u32(a, NFTNL_RULE_FAMILY) !=
30 nftnl_rule_get_u32(b, NFTNL_RULE_FAMILY))
31 print_err(
"Rule family mismatches");
32 if (strcmp(nftnl_rule_get_str(a, NFTNL_RULE_TABLE),
33 nftnl_rule_get_str(b, NFTNL_RULE_TABLE)) != 0)
34 print_err(
"Rule table mismatches");
35 if (strcmp(nftnl_rule_get_str(a, NFTNL_RULE_CHAIN),
36 nftnl_rule_get_str(b, NFTNL_RULE_CHAIN)) != 0)
37 print_err(
"Rule table mismatches");
38 if (nftnl_rule_get_u64(a, NFTNL_RULE_HANDLE) !=
39 nftnl_rule_get_u64(b, NFTNL_RULE_HANDLE))
40 print_err(
"Rule handle mismatches");
41 if (nftnl_rule_get_u32(a, NFTNL_RULE_COMPAT_PROTO) !=
42 nftnl_rule_get_u32(b, NFTNL_RULE_COMPAT_PROTO))
43 print_err(
"Rule compat_proto mismatches");
44 if (nftnl_rule_get_u32(a, NFTNL_RULE_COMPAT_FLAGS) !=
45 nftnl_rule_get_u32(b, NFTNL_RULE_COMPAT_FLAGS))
46 print_err(
"Rule compat_flags mismatches");
47 if (nftnl_rule_get_u64(a, NFTNL_RULE_POSITION) !=
48 nftnl_rule_get_u64(b, NFTNL_RULE_POSITION))
49 print_err(
"Rule compat_position mismatches");
52 int main(
int argc,
char *argv[])
58 a = nftnl_rule_alloc();
59 b = nftnl_rule_alloc();
60 if (a == NULL || b == NULL)
63 nftnl_rule_set_u32(a, NFTNL_RULE_FAMILY, AF_INET);
64 nftnl_rule_set_str(a, NFTNL_RULE_TABLE,
"table");
65 nftnl_rule_set_str(a, NFTNL_RULE_CHAIN,
"chain");
66 nftnl_rule_set_u64(a, NFTNL_RULE_HANDLE, 0x1234567812345678);
67 nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_PROTO, 0x12345678);
68 nftnl_rule_set_u32(a, NFTNL_RULE_COMPAT_FLAGS, 0x12345678);
69 nftnl_rule_set_u64(a, NFTNL_RULE_POSITION, 0x1234567812345678);
71 nlh = nftnl_rule_nlmsg_build_hdr(buf, NFT_MSG_NEWRULE, AF_INET, 0, 1234);
72 nftnl_rule_nlmsg_build_payload(nlh, a);
74 if (nftnl_rule_nlmsg_parse(nlh, b) < 0)
75 print_err(
"parsing problems");
84 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);