compat updates
Pablo Neira Ayuso
maintainercover compat updates
Hi,
This patchset contains three updates for the compatibility layer:
* Don't require libmnl and libnftnl if you choose to disable the compatibility layer via --disable-nftables.
* Provide a mechanism to distributors to switch to the compatibility layer in a transparent way (by updating the symlinks to the new binary xtables-compat-multi). Meanwhile, it installs {ip,ip6,arp}tables-compat-* utilities so you can use both native and compatibility layer tools.
* Add a emulated xtc_ops structure to avoid dependencies with libip4tc.
* A simple fix to replace a string that is wrong.
If no concerns, I'll push this to the nft-compat branch. After this, I'll merge this branch to master and will also prepare the first release of iptables including the nftables compatibility layer.
Pablo Neira Ayuso (4):
configure: rename --disable-xtables to --disable-nftables
configure: conditional dependencies for nftables-compat
xtables-restore: remove dependency with libip4tc
xtables: add xtables-compat-multi for the nftables compatibility layer
configure.ac | 75 +++++++++++++++++++------------------ iptables/Makefile.am | 41 ++++++++++++-------- iptables/xtables-arp-standalone.c | 2 +- iptables/xtables-arp.c | 2 +- iptables/xtables-compat-multi.c | 39 +++++++++++++++++++ iptables/xtables-multi.h | 13 +++++-- iptables/xtables-restore.c | 28 +++++++++++--- iptables/xtables-save.c | 18 +++++++-- iptables/xtables-standalone.c | 24 ++++++++---- 9 files changed, 166 insertions(+), 76 deletions(-) create mode 100644 iptables/xtables-compat-multi.c
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 1/4 configure: rename --disable-xtables to --disable-nftables
The compat utility name is xtables, the name used for the compatibility binary. Better explicitly refer to the compatibility later as nftables-compat.
--- configure.ac | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
configure.ac +1 -1
@@ -61,7 +61,7 @@ AC_ARG_WITH([pkgconfigdir], AS_HELP_STRING([--with-pkgconfigdir=PATH], [Path to the pkgconfig directory [[LIBDIR/pkgconfig]]]), [pkgconfigdir="$withval"], [pkgconfigdir='${libdir}/pkgconfig']) AC_ARG_ENABLE([nftables], - AS_HELP_STRING([--disable-xtables], [Do not build xtables]), + AS_HELP_STRING([--disable-nftables], [Do not build nftables compat]), [enable_nftables="$enableval"], [enable_nftables="yes"]) libiptc_LDFLAGS2="";
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 2/4 configure: conditional dependencies for nftables-compat
In reply to Pablo Neira AyusoDepend on libmnl, libnftnl, flex and bison if only if the nftables compatibility is enabled.
--- configure.ac | 73 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 36 deletions(-)
configure.ac +37 -36
@@ -119,44 +119,45 @@ PKG_CHECK_MODULES([libnfnetlink], [libnfnetlink >= 1.0], [nfnetlink=1], [nfnetlink=0]) AM_CONDITIONAL([HAVE_LIBNFNETLINK], [test "$nfnetlink" = 1]) -PKG_CHECK_MODULES([libmnl], [libmnl >= 1.0], - [mnl=1], [mnl=0]) -AM_CONDITIONAL([HAVE_LIBMNL], [test "$mnl" = 1]) - -PKG_CHECK_MODULES([libnftnl], [libnftnl >= 1.0], - [nftables=1], [nftables=0]) -AM_CONDITIONAL([HAVE_LIBNFTNL], [test "$nftables" = 1]) - -AM_PROG_LEX -AC_PROG_YACC - -if test -z "$ac_cv_prog_YACC" -then - echo "*** Error: No suitable bison/yacc found. ***" - echo " Please install the 'bison' package." - exit 1 -fi -if test -z "$ac_cv_prog_LEX" -then - echo "*** Error: No suitable flex/lex found. ***" - echo " Please install the 'flex' package." - exit 1 +if test "x$enable_nftables" = "xyes"; then + PKG_CHECK_MODULES([libmnl], [libmnl >= 1.0], [mnl=1], [mnl=0]) + + PKG_CHECK_MODULES([libnftnl], [libnftnl >= 1.0], [nftables=1], [nftables=0]) + + AM_PROG_LEX + AC_PROG_YACC + + if test -z "$ac_cv_prog_YACC" + then + echo "*** Error: No suitable bison/yacc found. ***" + echo " Please install the 'bison' package." + exit 1 + fi + if test -z "$ac_cv_prog_LEX" + then + echo "*** Error: No suitable flex/lex found. ***" + echo " Please install the 'flex' package." + exit 1 + fi + + AC_MSG_CHECKING(flex version) + flex_version=`$ac_cv_prog_LEX --version | sed 's/version//g' | awk '/flex/ {print $2}'` + flex_major=`echo $flex_version| cut -d . -f 1` + flex_minor=`echo $flex_version| cut -d . -f 2` + flex_rev=`echo $flex_version| cut -d . -f 3` + + if test "$flex_major" -eq "2" && test "$flex_minor" -eq "5" && test "$flex_rev" -ge "33"; then + AC_MSG_RESULT([$flex_version. OK]) + else + AC_MSG_WARN([flex version $flex_version found. + Version 2.5.33 or greater is required. You may experience problems + while compilating the nftables compatibility layer for iptables. + Please, consider to upgrade flex.]) + fi fi -AC_MSG_CHECKING(flex version) -flex_version=`$ac_cv_prog_LEX --version | sed 's/version//g' | awk '/flex/ {print $2}'` -flex_major=`echo $flex_version| cut -d . -f 1` -flex_minor=`echo $flex_version| cut -d . -f 2` -flex_rev=`echo $flex_version| cut -d . -f 3` - -if test "$flex_major" -eq "2" && test "$flex_minor" -eq "5" && test "$flex_rev" -ge "33"; then - AC_MSG_RESULT([$flex_version. OK]) -else - AC_MSG_WARN([flex version $flex_version found. - Version 2.5.33 or greater is required. You may experience problems - while compilating the nftables compatibility layer for iptables. - Please, consider to upgrade flex.]) -fi +AM_CONDITIONAL([HAVE_LIBMNL], [test "$mnl" = 1]) +AM_CONDITIONAL([HAVE_LIBNFTNL], [test "$nftables" = 1]) regular_CFLAGS="-Wall -Waggregate-return -Wmissing-declarations \ -Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes \
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 3/4 xtables-restore: remove dependency with libip4tc
In reply to Pablo Neira AyusoAdd a new operation structure, we don't actually need the libip4tc definition.
--- iptables/xtables-restore.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
iptables/xtables-restore.c +5 -1
@@ -161,6 +161,10 @@ static void add_param_to_argv(char *parsestart) } } +static const struct xtc_ops xtc_ops = { + .strerror = nft_strerror, +}; +int xtables_restore_main (int argc,char *argv[]) {
@@ -173,7 +177,7 @@ xtables_restore_main(int argc, char *argv[])FILE *in;int in_table =0 , testing =0 ;const char *tablename =NULL ; -const struct xtc_ops *ops = &iptc_ops; +const struct xtc_ops *ops = &xtc_ops;struct nft_chain_list *chain_list;struct nft_chain *chain_obj;
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerPATCH 4/4 xtables: add xtables-compat-multi for the nftables compatibility layer
In reply to Pablo Neira AyusoThis patch should allow distributors to switch to the iptables over nftables compatibility layer in a transparent way by updating symbolic links from:
lrwxrwxrwx 1 root root 13 feb 4 15:35 iptables -> xtables-multi
to:
lrwxrwxrwx 1 root root 13 feb 4 15:35 iptables -> xtables-compat-multi
Same thing with iptables-save, iptables-restore, ip6tables, ip6tables-save, ip6tables-restore and arptables.
Note that, after this patch, the following new symlinks are installed:
* iptables-compat
* iptables-compat-save
* iptables-compat-restore
* ip6tables-compat
* ip6tables-compat-save
* ip6tables-compat-restore
* arptables-compat
which point to the new binary xtables-compat-multi.
The idea is to keep both native and compatibility tools installed in the system, which should also make it easier for testing purposes.
The iptables over nftables compatibility layer is enabled by default and it requires the libmnl and libnftnl libraries. If you don't want to compile the compatibility layer, you can still disable it through --disable-nftables.
This patch also includes changes to adapt the existing code to this approach.
--- iptables/Makefile.am | 41 ++++++++++++++++++++++--------------- iptables/xtables-arp-standalone.c | 2 +- iptables/xtables-arp.c | 2 +- iptables/xtables-compat-multi.c | 39 +++++++++++++++++++++++++++++++++++ iptables/xtables-multi.h | 13 ++++++++---- iptables/xtables-restore.c | 22 +++++++++++++++----- iptables/xtables-save.c | 18 ++++++++++++---- iptables/xtables-standalone.c | 24 +++++++++++++++------- 8 files changed, 123 insertions(+), 38 deletions(-) create mode 100644 iptables/xtables-compat-multi.c
iptables/Makefile.am +25 -16
@@ -25,24 +25,32 @@ endif xtables_multi_SOURCES += xshared.c xtables_multi_LDADD += ../libxtables/libxtables.la -lm +# nftables compatibility layer if ENABLE_NFTABLES -if HAVE_LIBMNL -if HAVE_LIBNFTNL -xtables_multi_SOURCES += xtables-config-parser.y xtables-config-syntax.l -xtables_multi_SOURCES += xtables-save.c xtables-restore.c \ - xtables-standalone.c xtables.c nft.c \ - nft-shared.c nft-ipv4.c nft-ipv6.c nft-arp.c \ - xtables-config.c xtables-events.c \ - xtables-arp-standalone.c xtables-arp.c -xtables_multi_LDADD += ${libmnl_LIBS} ${libnftnl_LIBS} -xtables_multi_CFLAGS += -DENABLE_NFTABLES -# yacc and lex generate dirty code -xtables_multi-xtables-config-parser.o xtables_multi-xtables-config-syntax.o: AM_CFLAGS += -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-nested-externs -Wno-undef -Wno-redundant-decls -endif +xtables_compat_multi_SOURCES = xtables-compat-multi.c iptables-xml.c +xtables_compat_multi_CFLAGS = ${AM_CFLAGS} +xtables_compat_multi_LDADD = ../extensions/libext.a +if ENABLE_STATIC +xtables_compat_multi_CFLAGS += -DALL_INCLUSIVE endif +xtables_compat_multi_CFLAGS += -DENABLE_NFTABLES -DENABLE_IPV4 -DENABLE_IPV6 +xtables_compat_multi_SOURCES += xtables-config-parser.y xtables-config-syntax.l +xtables_compat_multi_SOURCES += xtables-save.c xtables-restore.c \ + xtables-standalone.c xtables.c nft.c \ + nft-shared.c nft-ipv4.c nft-ipv6.c nft-arp.c \ + xtables-config.c xtables-events.c \ + xtables-arp-standalone.c xtables-arp.c +xtables_compat_multi_LDADD += ${libmnl_LIBS} ${libnftnl_LIBS} +# yacc and lex generate dirty code +xtables_compat_multi-xtables-config-parser.o xtables_compat_multi-xtables-config-syntax.o: AM_CFLAGS += -Wno-missing-prototypes -Wno-missing-declarations -Wno-implicit-function-declaration -Wno-nested-externs -Wno-undef -Wno-redundant-decls +xtables_compat_multi_SOURCES += xshared.c +xtables_compat_multi_LDADD += ../libxtables/libxtables.la -lm endif sbin_PROGRAMS = xtables-multi +if ENABLE_NFTABLES +sbin_PROGRAMS += xtables-compat-multi +endif man_MANS = iptables.8 iptables-restore.8 iptables-save.8 \ iptables-xml.1 ip6tables.8 ip6tables-restore.8 \ ip6tables-save.8 iptables-extensions.8
@@ -57,8 +65,9 @@ if ENABLE_IPV6 v6_sbin_links = ip6tables ip6tables-restore ip6tables-save endif if ENABLE_NFTABLES -x_sbin_links = xtables xtables-restore xtables-save xtables-config \ - xtables-events xtables-arp +x_sbin_links = iptables-compat iptables-compat-restore iptables-compat-save \ + ip6tables-compat ip6tables-compat-restore ip6tables-compat-save \ + arptables-compat xtables-config xtables-events endif iptables-extensions.8: iptables-extensions.8.tmpl ../extensions/matches.man ../extensions/targets.man
@@ -75,4 +84,4 @@ install-exec-hook: for i in ${vx_bin_links}; do ${LN_S} -f "${sbindir}/xtables-multi" "${DESTDIR}${bindir}/$$i"; done; for i in ${v4_sbin_links}; do ${LN_S} -f xtables-multi "${DESTDIR}${sbindir}/$$i"; done; for i in ${v6_sbin_links}; do ${LN_S} -f xtables-multi "${DESTDIR}${sbindir}/$$i"; done; - for i in ${x_sbin_links}; do ${LN_S} -f xtables-multi "${DESTDIR}${sbindir}/$$i"; done; + for i in ${x_sbin_links}; do ${LN_S} -f xtables-compat-multi "${DESTDIR}${sbindir}/$$i"; done;
iptables/xtables-arp-standalone.c +1 -1
@@ -62,7 +62,7 @@ int xtables_arp_main(int argc, char *argv[]) .family = NFPROTO_ARP, }; - xtables_globals.program_name ="xtables-arp" ; + xtables_globals.program_name ="arptables" ;/* This code below could be replaced by xtables_init_all, which * doesn't support NFPROTO_ARP yet. */
iptables/xtables-arp.c +1 -1
@@ -202,7 +202,7 @@ static int inverse_for_options[NUMBER_OF_OPT] = };const char *program_version =XTABLES_VERSION ; -const char *program_name ="xtables-arp" ; +const char *program_name ="arptables" ;/* A few hardcoded protocols for 'all' and in case the user has no /etc/protocols */
iptables/xtables-compat-multi.c new file +39 -0
@@ -0,0 +1,39 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include "xshared.h" + +#include "xtables-multi.h" + +static const struct subcommand multi_subcommands[] = { + {"iptables-xml" , iptables_xml_main}, + {"xml" , iptables_xml_main}, + {"iptables" , xtables_ip4_main}, + {"iptables-compat" , xtables_ip4_main}, + {"main4" , xtables_ip4_main}, + {"save4" , xtables_ip4_save_main}, + {"restore4" , xtables_ip4_restore_main}, + {"iptables-save" , xtables_ip4_save_main}, + {"iptables-restore" , xtables_ip4_restore_main}, + {"iptables-compat-save" , xtables_ip4_save_main}, + {"iptables-compat-restore" , xtables_ip4_restore_main}, + {"ip6tables" , xtables_ip6_main}, + {"ip6tables-compat" , xtables_ip6_main}, + {"main6" , xtables_ip6_main}, + {"save6" , xtables_ip6_save_main}, + {"restore6" , xtables_ip6_restore_main}, + {"ip6tables-save" , xtables_ip6_save_main}, + {"ip6tables-restore" , xtables_ip6_restore_main}, + {"ip6tables-compat-save" , xtables_ip6_save_main}, + {"ip6tables-compat-restore" , xtables_ip6_restore_main}, + {"arptables" , xtables_arp_main}, + {"arptables-compat" , xtables_arp_main}, + {"xtables-config" , xtables_config_main}, + {"xtables-events" , xtables_events_main}, + {NULL }, +}; + +int main (int argc,char **argv) +{ +return subcmd_main (argc, argv, multi_subcommands); +}
iptables/xtables-multi.h +9 -4
@@ -2,11 +2,16 @@#define _XTABLES_MULTI_H 1extern int iptables_xml_main (int ,char **); -extern int xtables_main (int ,char **); -extern int xtables_save_main (int ,char **); -extern int xtables_restore_main (int ,char **); +#ifdef ENABLE_NFTABLES +extern int xtables_ip4_main (int ,char **); +extern int xtables_ip4_save_main (int ,char **); +extern int xtables_ip4_restore_main (int ,char **); +extern int xtables_ip6_main (int ,char **); +extern int xtables_ip6_save_main (int ,char **); +extern int xtables_ip6_restore_main (int ,char **); +extern int xtables_arp_main (int ,char **);extern int xtables_config_main (int ,char **);extern int xtables_events_main (int ,char **); -extern int xtables_arp_main (int ,char **); +#endif #endif /* _XTABLES_MULTI_H */
iptables/xtables-restore.c +17 -5
@@ -165,11 +165,11 @@ static const struct xtc_ops xtc_ops = { .strerror = nft_strerror, }; -int -xtables_restore_main (int argc,char *argv[]) +static int +xtables_restore_main (int family,const char *progname,int argc,char *argv[]) {struct nft_handle h = { - .family =AF_INET ,/* default to IPv4 */ + .family = family, };char buffer[10240 ];int c;
@@ -183,8 +183,8 @@ xtables_restore_main(int argc, char *argv[]) line =0 ; - xtables_globals.program_name ="xtables-restore" ; - c =xtables_init_all (&xtables_globals,NFPROTO_IPV4 ); + xtables_globals.program_name = progname; + c =xtables_init_all (&xtables_globals, family);if (c <0 ) { fprintf(stderr, "%s/%s Failed to initialize xtables\n", xtables_globals.program_name,
@@ -472,3 +472,15 @@ xtables_restore_main(int argc, char *argv[])fclose (in);return 0 ; } + +int xtables_ip4_restore_main (int argc,char *argv[]) +{ +return xtables_restore_main (NFPROTO_IPV4 ,"iptables-restore" , + argc, argv); +} + +int xtables_ip6_restore_main (int argc,char *argv[]) +{ +return xtables_restore_main (NFPROTO_IPV6 ,"ip6tables-restore" , + argc, argv); +}
iptables/xtables-save.c +14 -4
@@ -74,17 +74,17 @@ do_output(struct nft_handle *h, const char *tablename, bool counters)* :Chain name POLICY packets bytes * rule */ -int -xtables_save_main (int argc,char *argv[]) +static int +xtables_save_main (int family,const char *progname,int argc,char *argv[]) {const char *tablename =NULL ;bool dump = false;struct nft_handle h = { - .family =AF_INET ,/* default to AF_INET */ + .family = family, };int c; - xtables_globals.program_name ="xtables-save" ; + xtables_globals.program_name = progname;/* XXX xtables_init_all does several things we don't want */ c =xtables_init_all (&xtables_globals,NFPROTO_IPV4 );if (c <0 ) {
@@ -143,3 +143,13 @@ xtables_save_main(int argc, char *argv[])return !do_output (&h, tablename, show_counters); } + +int xtables_ip4_save_main (int argc,char *argv[]) +{ +return xtables_save_main (NFPROTO_IPV4 ,"iptables-save" , argc, argv); +} + +int xtables_ip6_save_main (int argc,char *argv[]) +{ +return xtables_save_main (NFPROTO_IPV6 ,"ip6tables-save" , argc, argv); +}
iptables/xtables-standalone.c +17 -7
@@ -39,17 +39,17 @@#include "xtables-multi.h" #include "nft.h" -int -xtables_main (int argc,char *argv[]) +static int +xtables_main (int family,const char *progname,int argc,char *argv[]) {int ret;char *table ="filter" ; -struct nft_handle h; +struct nft_handle h = { + .family = family, + }; -memset (&h,0 ,sizeof (h)); - - xtables_globals.program_name ="xtables" ; - ret =xtables_init_all (&xtables_globals,NFPROTO_IPV4 ); + xtables_globals.program_name = progname; + ret =xtables_init_all (&xtables_globals, family);if (ret <0 ) { fprintf(stderr, "%s/%s Failed to initialize xtables\n", xtables_globals.program_name,
@@ -92,3 +92,13 @@ xtables_main(int argc, char *argv[])exit (!ret); } + +int xtables_ip4_main (int argc,char *argv[]) +{ +return xtables_main (NFPROTO_IPV4 ,"iptables" , argc, argv); +} + +int xtables_ip6_main (int argc,char *argv[]) +{ +return xtables_main (NFPROTO_IPV6 ,"ip6tables" , argc, argv); +}
Signature · 1 line
1.7.10.4