11#include <linux/netfilter/nf_tables.h>
12#include <libnftnl/object.h>
14static int test_ok = 1;
16static void print_err(
const char *msg)
19 printf(
"\033[31mERROR:\e[0m %s\n", msg);
22static void cmp_nftnl_obj(
struct nftnl_obj *a,
struct nftnl_obj *b)
24 if (strcmp(nftnl_obj_get_str(a, NFTNL_OBJ_TABLE),
25 nftnl_obj_get_str(b, NFTNL_OBJ_TABLE)) != 0)
26 print_err(
"table name mismatches");
27 if (strcmp(nftnl_obj_get_str(a, NFTNL_OBJ_NAME),
28 nftnl_obj_get_str(b, NFTNL_OBJ_NAME)) != 0)
29 print_err(
"name mismatches");
30 if (nftnl_obj_get_u32(a, NFTNL_OBJ_FAMILY) !=
31 nftnl_obj_get_u32(b, NFTNL_OBJ_FAMILY))
32 print_err(
"family mismatches");
33 if (nftnl_obj_get_u32(a, NFTNL_OBJ_TYPE) !=
34 nftnl_obj_get_u32(b, NFTNL_OBJ_TYPE))
35 print_err(
"type mismatches");
38int main(
int argc,
char *argv[])
45 a = nftnl_obj_alloc();
46 b = nftnl_obj_alloc();
47 if (a == NULL || b == NULL)
50 nftnl_obj_set_str(a, NFTNL_OBJ_TABLE,
"test");
51 nftnl_obj_set_str(a, NFTNL_OBJ_NAME,
"test");
52 nftnl_obj_set_u32(a, NFTNL_OBJ_FAMILY, AF_INET);
53 nftnl_obj_set_u32(a, NFTNL_OBJ_USE, 1);
54 nftnl_obj_set_u64(a, NFTNL_OBJ_CTR_BYTES, 0x12345678abcd);
55 nftnl_obj_set_u64(a, NFTNL_OBJ_CTR_PKTS, 0xcd12345678ab);
58 nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWOBJ, AF_INET, 0, 1234);
59 nftnl_obj_nlmsg_build_payload(nlh, a);
61 if (nftnl_obj_nlmsg_parse(nlh, b) < 0)
62 print_err(
"parsing problems");
71 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);