add ipset to nftables translation infrastructure
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v3 3/3 add ipset to nftables translation infrastructure
This patch provides the ipset-translate utility which allows you to translate your existing ipset file to nftables.
The ipset-translate utility is actually a symlink to ipset, which checks for 'argv[0] == ipset-translate' to exercise the translation path.
You can translate your ipset file through:
ipset-translate restore < sets.ipt
This patch reuses the existing parser and API to represent the sets and the elements.
There is a new ipset_xlate_set dummy object that allows to store a created set to fetch the type without interactions with the kernel.
---
v3: This round fixes a few bugs:
- fix ASAN warning: use calloc to allocate the ipset_xlate_set object.
- Set ipset->xlate = true; from ipset_xlate_argv() to access argv[0], instead of using prog_name from ipset_init().
- Call ipset_session_data_set(..., IPSET_OPT_TYPE, ...) to attach the type, this fixes a "Internal error" report.
I'm finishing the automated test infrastructure for this new utility.
configure.ac | 1 + include/libipset/Makefile.am | 3 +- include/libipset/xlate.h | 6 + lib/ipset.c | 518 ++++++++++++++++++++++++++++++++++- src/Makefile.am | 8 +- src/ipset-translate.8 | 91 ++++++ src/ipset.c | 8 +- 7 files changed, 631 insertions(+), 4 deletions(-) create mode 100644 include/libipset/xlate.h create mode 100644 src/ipset-translate.8
configure.ac +1 -0
@@ -7,6 +7,7 @@ AC_CONFIG_HEADER([config.h]) AM_INIT_AUTOMAKE([foreign subdir-objects tar-pax]) m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) +AC_PROG_LN_S AC_ENABLE_STATIC LT_INIT([dlopen]) LT_CONFIG_LTDL_DIR([libltdl])
include/libipset/Makefile.am +2 -1
@@ -17,6 +17,7 @@ pkginclude_HEADERS = \ transport.h \ types.h \ ipset.h \ - utils.h + utils.h \ + xlate.h EXTRA_DIST = debug.h icmp.h icmpv6.h
include/libipset/xlate.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef LIBIPSET_XLATE_H +#define LIBIPSET_XLATE_H + +int ipset_xlate_argv (struct ipset *ipset,int argc,char *argv[]); + +#endif
lib/ipset.c +517 -1
566 lines not on this page · raw message
src/Makefile.am +7 -1
@@ -12,10 +12,16 @@ AM_LDFLAGS = -static endif endif -dist_man_MANS = ipset.8 +dist_man_MANS = ipset.8 ipset-translate.8 sparse-check: $(ipset_SOURCES:.c=.d) %.d: %.c $(IPSET_AM_V_CHECK)\ $(SPARSE) -I.. $(SPARSE_FLAGS) $(AM_CFLAGS) $(AM_CPPFLAGS) $< || : + +install-exec-hook: + ${LN_S} -f "${sbindir}/ipset" "${DESTDIR}${sbindir}/ipset-translate"; + +uninstall-hook: + rm -f ${DESTDIR}${sbindir}/ipset-translate
src/ipset-translate.8 new file +91 -0
91 lines not on this page · raw message
src/ipset.c +7 -1
@@ -9,9 +9,11 @@#include <assert.h> /* assert */ #include <stdio.h> /* fprintf */ #include <stdlib.h> /* exit */ +#include <string.h> /* strcmp */ #include <config.h> #include <libipset/ipset.h> /* ipset library */ +#include <libipset/xlate.h> /* translate to nftables */ int main (int argc,char *argv[])
@@ -29,7 +31,11 @@ main(int argc, char *argv[])exit (1 ); } - ret =ipset_parse_argv (ipset, argc, argv); +if (!strcmp (argv[0 ],"ipset-translate" )) { + ret =ipset_xlate_argv (ipset, argc, argv); + }else { + ret =ipset_parse_argv (ipset, argc, argv); + }ipset_fini (ipset);
Signature · 1 line
2.20.1