Esempio n. 1
0
int main(int argc, char *argv[])
{
	struct nftnl_chain *a, *b;
	char buf[4096];
	struct nlmsghdr *nlh;

	a = nftnl_chain_alloc();
	b = nftnl_chain_alloc();
	if (a == NULL || b == NULL)
		print_err("OOM");

	nftnl_chain_set_str(a, NFTNL_CHAIN_NAME, "test");
	nftnl_chain_set_u32(a, NFTNL_CHAIN_FAMILY, AF_INET);
	nftnl_chain_set_str(a, NFTNL_CHAIN_TABLE, "Table");
	nftnl_chain_set_u32(a, NFTNL_CHAIN_POLICY,0x12345678);
	nftnl_chain_set_u32(a, NFTNL_CHAIN_HOOKNUM, 0x34567812);
	nftnl_chain_set_s32(a, NFTNL_CHAIN_PRIO, 0x56781234);
	nftnl_chain_set_u32(a, NFTNL_CHAIN_USE, 0x78123456);
	nftnl_chain_set_u64(a, NFTNL_CHAIN_PACKETS, 0x1234567812345678);
	nftnl_chain_set_u64(a, NFTNL_CHAIN_BYTES, 0x7812345678123456);
	nftnl_chain_set_u64(a, NFTNL_CHAIN_HANDLE, 0x5678123456781234);
	nftnl_chain_set_str(a, NFTNL_CHAIN_TYPE, "Prueba");
	nftnl_chain_set_str(a, NFTNL_CHAIN_DEV, "eth0");

	/* cmd extracted from include/linux/netfilter/nf_tables.h */
	nlh = nftnl_chain_nlmsg_build_hdr(buf, NFT_MSG_NEWCHAIN, AF_INET,
					0, 1234);
	nftnl_chain_nlmsg_build_payload(nlh, a);

	if (nftnl_chain_nlmsg_parse(nlh, b) < 0)
		print_err("parsing problems");

	cmp_nftnl_chain(a, b);

	nftnl_chain_free(a);
	nftnl_chain_free(b);

	if (!test_ok)
		exit(EXIT_FAILURE);

	printf("%s: \033[32mOK\e[0m\n", argv[0]);
	return EXIT_SUCCESS;

}
Esempio n. 2
0
static struct nftnl_chain *build_chain(const char *name, const char *table,
				const char *type, int hooknum, int prio)
{
	struct nftnl_chain *chain;

        chain = nftnl_chain_alloc();
        if (!chain)
                return NULL;

        nftnl_chain_set(chain, NFTNL_CHAIN_TABLE, table);
        nftnl_chain_set(chain, NFTNL_CHAIN_NAME, name);

	if (type)
		nftnl_chain_set_str(chain, NFTNL_CHAIN_TYPE, type);

        if (hooknum >= 0)
                nftnl_chain_set_u32(chain, NFTNL_CHAIN_HOOKNUM, hooknum);

        if (prio >= 0)
                nftnl_chain_set_u32(chain, NFTNL_CHAIN_PRIO, prio);

	return chain;
}