Skip to content

introduce libnftables

Eric Leblond netfilter-devel 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 Latest16 patches 20 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/16libnftables: introduce libraryconfigure.ac include/Makefile.am include/nftables/Makefile.am +4 more+99 -356 replies
2/16libnftables: add context new and freeinclude/nftables.h include/nftables/nftables.h src/libnftables.c +1 more+37 -141 reply
3/16libnftables: add nft_run_command_from_bufferinclude/nftables/nftables.h src/libnftables.c src/main.c+37 -131 reply
4/16libnftables: add nft_run_command_from_filenameinclude/nftables/nftables.h src/libnftables.c src/main.c+30 -130 replies
5/16libnftables: put nft_run in libraryinclude/nftables.h include/nftables_common.h src/Makefile.am +4 more+126 -890 replies
6/16libnftables: add missing variable to librarysrc/libnftables.c src/main.c+2 -12 replies
7/16libnftables: add NFT_EXIT_* to libraryinclude/nftables.h include/nftables/nftables.h src/netlink.c +1 more+9 -70 replies
8/16libnftables: add a nft_cache to nft_ctxinclude/cli.h include/nftables.h include/nftables/nftables.h +3 more+32 -281 reply
9/16libnftables: move iface_cache_release to deinitsrc/libnftables.c src/main.c+1 -10 replies
10/16libnftables: get rid of printfinclude/datatype.h include/expression.h include/nftables.h +12 more+279 -2512 replies
11/16libnftables: add nft_context_set_printinclude/nftables/nftables.h src/libnftables.c+12 -00 replies
12/16libnftables: transaction supportinclude/netlink.h include/nftables/nftables.h src/libnftables.c+101 -01 reply
13/16libnftables: set max_errors to 1 in libraryinclude/nftables/nftables.h src/libnftables.c src/main.c+9 -10 replies
14/16erec: add function to free listinclude/erec.h src/erec.c+11 -00 replies
15/16libnftables: add error handlinginclude/nftables.h include/nftables/nftables.h src/libnftables.c+20 -112 replies
16/16libnftables: basic doxygen documentationsrc/libnftables.c+51 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [nft PATCH 0/16] introduce libnftables

Hello,

This patchset adds a basi high level libnftables to nftables code. It is currently supporting running a command from a buffer or from a file as well as batch support allowing to chain commands and commit them at once.

The API is mostly using existing structures such as nft_ctx that are updated to contain enough information. It also adds a structure dedicated to batch.

A simple program running a command is the following:

 	nft_global_init();
	nft = nft_context_new();
	nft_context_set_print_func(nft, my_print, buf);
	rc = nft_run_command_from_buffer(nft, CMD, sizeof(CMD));
	if (rc != NFT_EXIT_SUCCESS) {
		nft_get_error(nft, err_buf, sizeof(err_buf));
		printf("%s\n", err_buf);
		return -1;
	}
	nft_context_free(nft);
	nft_global_deinit(); 

Transaction support is similar with:

	nft = nft_context_new();
	batch = nft_batch_start(nft);
	if (nft_batch_add(nft, batch, ADD1, strlen(ADD1)) !=0) {
		printf("FAIL add 1\n");
		goto out;
	}
	if (nft_batch_add(nft, batch, ADD2, strlen(ADD2)) !=0) {
		printf("FAIL add 2\n");
		goto out;
	}
	if (nft_batch_commit(nft, batch) != 0) {
		goto out;
	}

out:

	nft_batch_free(batch);
	nft_context_free(nft);
	nft_global_deinit();

The library provides a way to get standard output via nft_context_set_print_func and error handling is done via nft_get_error that get error message in a buffer.

This is early stage code as it does not feature things like set handling but IMO it can already be used as a starting point to build more things.

BR,
--
Eric