Save funcs, installation, const
The following changes since commit d797d0ff0338d2938d18b03038d6f4455b000579:
build: bump version to 1.4.18 (2013-03-03 22:40:11 +0100)
are available in the git repository at:
git://git.inai.de/iptables master
for you to fetch changes up to 8b83282ec032ecf643f2f47cd86a3f2c5991d10a:
libxtables: constify xtables_option_[mt]fcall argument (2013-03-05 02:05:46 +0100)
----------------------------------------------------------------
Jan Engelhardt (5):
libxtables: centralize checking for a .save function
extensions: eui64: set userspacesize=0
iptables: fall back to using save function when print is not defined
build: do not dereference symlinks on installation
libxtables: constify xtables_option_[mt]fcall argument
extensions/GNUmakefile.in | 15 ++++++++++----- extensions/libip6t_eui64.c | 2 +- extensions/libxt_standard.c | 14 ++++++++++++++ include/xtables.h | 4 ++-- iptables/ip6tables.c | 22 ++++++++-------------- iptables/iptables.c | 22 ++++++++-------------- libxtables/xtables.c | 21 +++++++++++++++++++++ libxtables/xtoptions.c | 4 ++-- tests/options-most.rules | 2 ++ 9 files changed, 68 insertions(+), 38 deletions(-)
PATCH 1/5 libxtables: centralize checking for a .save function
Both iptables.c and ip6tables.c check for target->save == NULL, which can be consolidated. In fact, we should also check for match->save == NULL, which this patch addds to libxtables.
--- extensions/libxt_standard.c | 14 ++++++++++++++ iptables/ip6tables.c | 12 ------------ iptables/iptables.c | 12 ------------ libxtables/xtables.c | 21 +++++++++++++++++++++ 4 files changed, 35 insertions(+), 24 deletions(-)
extensions/libxt_standard.c +14 -0
@@ -9,12 +9,26 @@ static void standard_help(void) "(If target is DROP, ACCEPT, RETURN or nothing)\n"); } +static void standard_save (const void *ip,const struct xt_entry_target *t) +{ +/* +* This function left blank intentionally - it only serves to make +* iptables not exit with "target lacks a save function". The +* "standard" target is special, since we do not emit -j standard, but +* -j <verdict>. This is printed by iptables.c's function +* print_rule4(), which ultimately calls TC_GET_TARGET in +* libiptc/libiptc.c that will emit the verdict name based upon data in +* the parameter block (@t->data in this "standard_save" function). +*/ +} +static struct xtables_target standard_target = { .family =NFPROTO_UNSPEC , .name ="standard" , .version =XTABLES_VERSION , .size =XT_ALIGN (sizeof (int )), .userspacesize =XT_ALIGN (sizeof (int )), + .save = standard_save, .help = standard_help, };
iptables/ip6tables.c +0 -12
@@ -1106,18 +1106,6 @@ void print_rule6(const struct ip6t_entry *e,printf (" -j %s" , target->alias ? target->alias (t) : target_name);if (target->save) target->save (&e->ipv6, t); -else { -/* If the target size is greater than xt_entry_target -* there is something to be saved, we just don't know -* how to print it */ -if (t->u.target_size != -sizeof (struct xt_entry_target )) { -fprintf (stderr,"Target `%s' is missing " -"save function\n" , - t->u.user.name); -exit (1 ); - } - } } else if (target_name && (*target_name != '\0'))#ifdef IP6T_F_GOTO printf (" -%c %s" , e->ipv6.flags &IP6T_F_GOTO ?'g' :'j' , target_name);
iptables/iptables.c +0 -12
@@ -1097,18 +1097,6 @@ void print_rule4(const struct ipt_entry *e,printf (" -j %s" , target->alias ? target->alias (t) : target_name);if (target->save) target->save (&e->ip, t); -else { -/* If the target size is greater than xt_entry_target -* there is something to be saved, we just don't know -* how to print it */ -if (t->u.target_size != -sizeof (struct xt_entry_target )) { -fprintf (stderr,"Target `%s' is missing " -"save function\n" , - t->u.user.name); -exit (1 ); - } - } } else if (target_name && (*target_name != '\0'))#ifdef IPT_F_GOTO printf (" -%c %s" , e->ip.flags &IPT_F_GOTO ?'g' :'j' , target_name);
libxtables/xtables.c +21 -0
@@ -852,6 +852,16 @@ void xtables_register_match(struct xtables_match *me)xtables_option_metavalidate (me->name, me->x6_options);if (me->extra_opts !=NULL )xtables_check_options (me->name, me->extra_opts); +if (me->userspacesize >0 && me->save ==NULL && + me->real_name ==NULL ) { +/* +* Catch extensions that have data to be saved, but which +* forgot to define a save method. +*/ +fprintf (stderr,"Match \"%s\" is missing a save function\n" , + me->name); +exit (1 ); + }/* ignore not interested match */ if (me->family != afinfo->family && me->family !=AF_UNSPEC )
@@ -1010,6 +1020,17 @@ void xtables_register_target(struct xtables_target *me)xtables_option_metavalidate (me->name, me->x6_options);if (me->extra_opts !=NULL )xtables_check_options (me->name, me->extra_opts); +if (me->userspacesize >0 && me->save ==NULL && + me->real_name ==NULL ) { +/* +* Catch extensions that have data to be saved, but which +* forgot to define a save method. This only applies to true +* modules (real_name==NULL), not aliases. +*/ +fprintf (stderr,"Target \"%s\" is missing a save function\n" , + me->name); +exit (1 ); + }/* ignore not interested target */ if (me->family != afinfo->family && me->family !=AF_UNSPEC )
Signature · 1 line
1.7.10.4
PATCH 2/5 extensions: eui64: set userspacesize=0
In reply to Jan EngelhardtThe eui64 match does not use its parameter block at all, so userspacesize should be 0. This resolves "eui64 is missing a save function".
--- extensions/libip6t_eui64.c | 2 +- tests/options-most.rules | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-)
extensions/libip6t_eui64.c +1 -1
@@ -6,7 +6,7 @@ static struct xtables_match eui64_mt6_reg = { .version = XTABLES_VERSION, .family = NFPROTO_IPV6, .size = XT_ALIGN(sizeof(int)), - .userspacesize = XT_ALIGN(sizeof(int)), + .userspacesize = 0, };void _init (void )
tests/options-most.rules +2 -0
@@ -91,6 +91,8 @@ -A matches -A matches -p esp -m esp --espspi 5:4294967295 -A matches +-A matches -m eui64 +-A matches -A matches -m hashlimit --hashlimit-upto 1/sec --hashlimit-burst 1 --hashlimit-name mini1 --hashlimit-htable-expire 2000 -A matches -m hashlimit --hashlimit-upto 1/sec --hashlimit-burst 1 --hashlimit-name mini1 -A matches -m hashlimit --hashlimit-upto 1/min --hashlimit-burst 1 --hashlimit-name mini2
Signature · 1 line
1.7.10.4
PATCH 3/5 iptables: fall back to using save function when print is not defined
In reply to Jan EngelhardtThis way we can avoid having to provide two dumping function for new plugins.
--- iptables/ip6tables.c | 10 ++++++++-- iptables/iptables.c | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-)
iptables/ip6tables.c +8 -2
@@ -487,10 +487,14 @@ print_match(const struct xt_entry_match *m,xtables_find_match (m->u.user.name,XTF_TRY_LOAD ,NULL );if (match) { -if (match->print) +if (match->print) { match->else + }else if (match->save !=NULL ) { +printf ("-m %s " , match->name); + match->save (ip, m); + }else {printf ("%s " , match->name); + } }else {if (m->u.user.name[0 ])printf ("UNKNOWN match `%s' " , m->u.user.name);
@@ -617,6 +621,8 @@ print_firewall(const struct ip6t_entry *fw,if (target->print)/* Print the target information. */ target->FMT_NUMERIC ); +else if (target->save !=NULL ) + target->save (&fw->ipv6, t); }else if (t->u.target_size !=sizeof (*t))printf ("[%u bytes of unknown target data] " , (unsigned int )(t->u.target_size -sizeof (*t)));
iptables/iptables.c +8 -2
@@ -472,10 +472,14 @@ print_match(const struct xt_entry_match *m,xtables_find_match (m->u.user.name,XTF_TRY_LOAD ,NULL );if (match) { -if (match->print) +if (match->print) { match->else + }else if (match->save !=NULL ) { +printf ("-m %s " , match->name); + match->save (ip, m); + }else {printf ("%s " , match->name); + } }else {if (m->u.user.name[0 ])printf ("UNKNOWN match `%s' " , m->u.user.name);
@@ -602,6 +606,8 @@ print_firewall(const struct ipt_entry *fw,if (target->print)/* Print the target information. */ target->FMT_NUMERIC ); +else if (target->save !=NULL ) + target->save (&fw->ip, t); }else if (t->u.target_size !=sizeof (*t))printf ("[%u bytes of unknown target data] " , (unsigned int )(t->u.target_size -sizeof (*t)));
Signature · 1 line
1.7.10.4
PATCH 4/5 build: do not dereference symlinks on installation
In reply to Jan EngelhardtBy using install(1), libxt_NOTRACK.so was inadvertently installed as an actual file to /usr/lib/xtables rather than as a symlink. Switch to using cp(1).
--- extensions/GNUmakefile.in | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
extensions/GNUmakefile.in +10 -5
@@ -40,7 +40,7 @@ endif # Wildcard module list # pfx_build_mod := $(patsubst ${srcdir}/libxt_%.c,%,$(sort $(wildcard ${srcdir}/libxt_*.c))) -pfx_symlinks := NOTRACK state +pfx_symlinks := libxt_NOTRACK.so libxt_state.so @ENABLE_IPV4_TRUE@ pf4_build_mod := $(patsubst ${srcdir}/libipt_%.c,%,$(sort $(wildcard ${srcdir}/libipt_*.c))) @ENABLE_IPV6_TRUE@ pf6_build_mod := $(patsubst ${srcdir}/libip6t_%.c,%,$(sort $(wildcard ${srcdir}/libip6t_*.c))) pfx_build_mod := $(filter-out @blacklist_modules@,${pfx_build_mod})
@@ -49,7 +49,7 @@ pf6_build_mod := $(filter-out @blacklist_modules@,${pf6_build_mod}) pfx_objs := $(patsubst %,libxt_%.o,${pfx_build_mod}) pf4_objs := $(patsubst %,libipt_%.o,${pf4_build_mod}) pf6_objs := $(patsubst %,libip6t_%.o,${pf6_build_mod}) -pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod} ${pfx_symlinks}) +pfx_solibs := $(patsubst %,libxt_%.so,${pfx_build_mod}) pf4_solibs := $(patsubst %,libipt_%.so,${pf4_build_mod}) pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod})
@@ -59,11 +59,13 @@ pf6_solibs := $(patsubst %,libip6t_%.so,${pf6_build_mod}) # targets := libext.a libext4.a libext6.a matches.man targets.man targets_install := +targets_instlink := @ENABLE_STATIC_TRUE@ libext_objs := ${pfx_objs} @ENABLE_STATIC_TRUE@ libext4_objs := ${pf4_objs} @ENABLE_STATIC_TRUE@ libext6_objs := ${pf6_objs} -@ENABLE_STATIC_FALSE@ targets += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} +@ENABLE_STATIC_FALSE@ targets += ${pfx_solibs} ${pfx_symlinks} ${pf4_solibs} ${pf6_solibs} @ENABLE_STATIC_FALSE@ targets_install += ${pfx_solibs} ${pf4_solibs} ${pf6_solibs} +@ENABLE_STATIC_FALSE@ targets_instlink += ${pfx_symlinks} .SECONDARY:
@@ -71,9 +73,12 @@ targets_install := all: ${targets} -install: ${targets_install} +install: ${targets_install} ${targets_instlink} @mkdir -p "${DESTDIR}${xtlibdir}"; - if test -n "${targets_install}"; then install -pm0755 $^ "${DESTDIR}${xtlibdir}/"; fi; + if test -n "${targets_install}"; then \ + install -pm0755 ${targets_install} "${DESTDIR}${xtlibdir}/"; \ + cp -a ${pfx_symlinks} "${DESTDIR}${xtlibdir}/"; \ + fi; clean: rm -f *.la *.o *.lo *.so *.a {matches,targets}.man initext.c initext4.c initext6.c;
Signature · 1 line
1.7.10.4
PATCH 5/5 libxtables: constify xtables_option_[mt]fcall argument
In reply to Jan EngelhardtNothing modifies the match/target, so we can mark it const.
--- include/xtables.h | 4 ++-- libxtables/xtoptions.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
include/xtables.h +2 -2
@@ -535,8 +535,8 @@ extern void xtables_option_tpcall(unsigned int, char **, bool, struct xtables_target *, void *);extern void xtables_option_mpcall (unsigned int ,char **,bool ,struct xtables_match *,void *); -extern void xtables_option_tfcall (struct xtables_target *); -extern void xtables_option_mfcall (struct xtables_match *); +extern void xtables_option_tfcall (const struct xtables_target *); +extern void xtables_option_mfcall (const struct xtables_match *);extern void xtables_options_fcheck (const char *,unsigned int ,const struct xt_option_entry *);
libxtables/xtoptions.c +2 -2
@@ -1034,7 +1034,7 @@ void xtables_options_fcheck(const char *name, unsigned int xflags,* Dispatch arguments to the appropriate final_check function, based upon the * extension's choice of API. */ -void xtables_option_tfcall (struct xtables_target *t) +void xtables_option_tfcall (const struct xtables_target *t) {if (t->x6_fcheck !=NULL ) {struct xt_fcheck_call cb;
@@ -1055,7 +1055,7 @@ void xtables_option_tfcall(struct xtables_target *t)* Dispatch arguments to the appropriate final_check function, based upon the * extension's choice of API. */ -void xtables_option_mfcall (struct xtables_match *m) +void xtables_option_mfcall (const struct xtables_match *m) {if (m->x6_fcheck !=NULL ) {struct xt_fcheck_call cb;
Signature · 1 line
1.7.10.4