libxtables: Introduce xtables_init_all()
PATCH 1/1 libxtables: Introduce xtables_init_all()
Ok, last one - a little cosmetics but it helps to reduce code on the app;
anything after this will be just cleanups etc.
cheers,
jamal
commit 2c2f361331ae498816be371c222ff363f7d83388
Author: Jamal Hadi Salim <[email protected]> Date: Fri Feb 13 09:14:17 2009 -0500
Introduce xtables_init_all() which hides three calls xtables_init(), xtables_set_nfproto(), and xtables_set_params(). Make ip[6]tables-restore, ip[6]tables-save and ip[6]tables-standalone use it.
I moved xtables_set_params around for readability reasons.
Signed-off-by Jamal Hadi Salim <[email protected]>
include/xtables.h.in +1 -1
@@ -209,7 +209,7 @@ extern void xtables_set_revision(char *name, u_int8_t revision); extern void xtables_free_opts(int reset_offset); extern struct option *xtables_merge_options(struct option *oldopts, const struct option *newopts, unsigned int *option_offset); - +extern int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto); extern struct xtables_match *xtables_find_match(const char *name, enum xtables_tryload, struct xtables_rule_match **match); extern struct xtables_target *xtables_find_target(const char *name,
ip6tables-restore.c +7 -2
@@ -131,9 +131,14 @@ int main(int argc, char *argv[]) line =0 ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV6 ); ip6tables_globals.program_name ="ip6tables-restore" ; + c =xtables_init_all (&ip6tables_globals,NFPROTO_IPV6 ); +if (c <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + ip6tables_globals.program_name, + ip6tables_globals.program_version); +exit (1 ); + }#ifdef NO_SHARED_LIBS init_extensions ();#endif
ip6tables-save.c +7 -2
@@ -140,9 +140,14 @@ int main(int argc, char *argv[]) program_version =IPTABLES_VERSION ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV6 ); ip6tables_globals.program_name ="ip6tables-save" ; + c =xtables_init_all (&ip6tables_globals,NFPROTO_IPV6 ); +if (c <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + ip6tables_globals.program_name, + ip6tables_globals.program_version); +exit (1 ); + }#ifdef NO_SHARED_LIBS init_extensions ();#endif
ip6tables-standalone.c +8 -2
@@ -53,9 +53,15 @@ main(int argc, char *argv[]) program_version =IPTABLES_VERSION ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV6 ); ip6tables_globals.program_name ="ip6tables" ; + ret =xtables_init_all (&ip6tables_globals,NFPROTO_IPV6 ); +if (ret <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + ip6tables_globals.program_name, + ip6tables_globals.program_version); +exit (1 ); + } +#ifdef NO_SHARED_LIBS init_extensions ();#endif
ip6tables.c +0 -1
@@ -1330,7 +1330,6 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handdemand-load a protocol. */ opterr =0 ; -xtables_set_params (&ip6tables_globals);while ((c =getopt_long (argc, argv,"-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:bvnt:m:xc:g:" , opts,NULL )) !=-1 ) {
iptables-restore.c +7 -2
@@ -133,9 +133,14 @@ main(int argc, char *argv[]) line =0 ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV4 ); iptables_globals.program_name ="iptables-restore" ; + c =xtables_init_all (&iptables_globals,NFPROTO_IPV4 ); +if (c <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + iptables_globals.program_name, + iptables_globals.program_version); +exit (1 ); + }#ifdef NO_SHARED_LIBS init_extensions ();#endif
iptables-save.c +7 -2
@@ -140,9 +140,14 @@ main(int argc, char *argv[]) program_version =IPTABLES_VERSION ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV4 ); iptables_globals.program_name ="iptables-save" ; + c =xtables_init_all (&iptables_globals,NFPROTO_IPV4 ); +if (c <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + iptables_globals.program_name, + iptables_globals.program_version); +exit (1 ); + }#ifdef NO_SHARED_LIBS init_extensions ();#endif
iptables-standalone.c +7 -2
@@ -54,9 +54,14 @@ main(int argc, char *argv[]) program_version =IPTABLES_VERSION ; xtables_program_name = program_name; -xtables_init (); -xtables_set_nfproto (NFPROTO_IPV4 ); iptables_globals.program_name ="iptables" ; + ret =xtables_init_all (&iptables_globals,NFPROTO_IPV4 ); +if (ret <0 ) { +fprintf (stderr,"%s/%s Failed to initialize xtables\n" , + iptables_globals.program_name, + iptables_globals.program_version); +exit (1 ); + }#ifdef NO_SHARED_LIBS init_extensions ();#endif
iptables.c +0 -1
@@ -1352,7 +1352,6 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handledemand-load a protocol. */ opterr =0 ; -xtables_set_params (&iptables_globals);while ((c =getopt_long (argc, argv,"-A:D:R:I:L::S::M:F::Z::N:X::E:P:Vh::o:p:s:d:j:i:fbvnt:m:xc:g:" , opts,NULL )) !=-1 ) {
xtables.c +32 -25
69 lines not on this page · raw message