14#include <netinet/in.h>
16#include <linux/netfilter/nf_tables.h>
17#include <libnftnl/object.h>
19static int test_ok = 1;
21static void print_err(
const char *msg)
24 printf(
"\033[31mERROR:\e[0m %s\n", msg);
27static void cmp_nftnl_obj(
struct nftnl_obj *a,
struct nftnl_obj *b)
29 if (strcmp(nftnl_obj_get_str(a, NFTNL_OBJ_TABLE),
30 nftnl_obj_get_str(b, NFTNL_OBJ_TABLE)) != 0)
31 print_err(
"table name mismatches");
32 if (strcmp(nftnl_obj_get_str(a, NFTNL_OBJ_NAME),
33 nftnl_obj_get_str(b, NFTNL_OBJ_NAME)) != 0)
34 print_err(
"name mismatches");
35 if (nftnl_obj_get_u32(a, NFTNL_OBJ_FAMILY) !=
36 nftnl_obj_get_u32(b, NFTNL_OBJ_FAMILY))
37 print_err(
"family mismatches");
38 if (nftnl_obj_get_u32(a, NFTNL_OBJ_TYPE) !=
39 nftnl_obj_get_u32(b, NFTNL_OBJ_TYPE))
40 print_err(
"type mismatches");
43int main(
int argc,
char *argv[])
50 a = nftnl_obj_alloc();
51 b = nftnl_obj_alloc();
52 if (a == NULL || b == NULL)
55 nftnl_obj_set_str(a, NFTNL_OBJ_TABLE,
"test");
56 nftnl_obj_set_str(a, NFTNL_OBJ_NAME,
"test");
57 nftnl_obj_set_u32(a, NFTNL_OBJ_FAMILY, AF_INET);
58 nftnl_obj_set_u32(a, NFTNL_OBJ_USE, 1);
59 nftnl_obj_set_u64(a, NFTNL_OBJ_CTR_BYTES, 0x12345678abcd);
60 nftnl_obj_set_u64(a, NFTNL_OBJ_CTR_PKTS, 0xcd12345678ab);
63 nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_NEWOBJ, AF_INET, 0, 1234);
64 nftnl_obj_nlmsg_build_payload(nlh, a);
66 if (nftnl_obj_nlmsg_parse(nlh, b) < 0)
67 print_err(
"parsing problems");
76 printf(
"%s: \033[32mOK\e[0m\n", argv[0]);