]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
libxtables: consolidate init calls into one function
authorJamal Hadi Salim <hadi@cyberus.ca>
Fri, 13 Feb 2009 14:14:17 +0000 (09:14 -0500)
committerJan Engelhardt <jengelh@medozas.de>
Fri, 13 Feb 2009 14:46:52 +0000 (15:46 +0100)
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 <hadi@cyberus.ca>
include/xtables.h.in
ip6tables-restore.c
ip6tables-save.c
ip6tables-standalone.c
ip6tables.c
iptables-restore.c
iptables-save.c
iptables-standalone.c
iptables.c
xtables.c

index aaadbbd65072a2aef59e92f856a02ef852efae20..4ab0ecbed03b0f58e9839fde9dbfb22aa88b04d7 100644 (file)
@@ -210,6 +210,7 @@ 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,
index 3d535defc9819595ecb0b8fa1392b15273974662..0f06a1c0202aae09d4acebd71742419f0e487705 100644 (file)
@@ -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
index 3af81abd78a1e0fced7fe800b1518f4ff5bcd737..9de34b51a76202075fe76b45e2b1ecc020278c7c 100644 (file)
@@ -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
index ab770655968ce86406a2798de0fc20109a842edc..b40c79bccd1df0b40963d59cb9ef9ccdedb47fcd 100644 (file)
@@ -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
index 250bb0ea5fd3df72fdf53ad8d1c353c24d62ed39..dca484f0b4f34b4ee8470a69e843e53b2a85ea7d 100644 (file)
@@ -1330,7 +1330,6 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **hand
            demand-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) {
index 01030166008465e1eec4b676ef8e80b695184f25..c52af0adb7a02ebf3af3543003d498c8698b35e9 100644 (file)
@@ -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
index 396406feed84523956677e04951c98aeb4230870..312673acc040833449e0662c201d7a94fd2b654b 100644 (file)
@@ -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
index 007f2c2d79be818d2bc475fe525d7b3b467fcdf4..6090ea15fd73dc4eb44faaac6e9bfc6aa322fb8e 100644 (file)
@@ -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
index e6b4aa04c31cbde042aa4bffb43355e4fad70e06..2583ec6c364dabf74bf9815ac70be268fe53cc65 100644 (file)
@@ -1352,7 +1352,6 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handle
            demand-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) {
index bdb0133dd121dc84d15b0fa913392570935ddbe9..a812ef163da25871b7fee21132f5b9d0cc3d309b 100644 (file)
--- a/xtables.c
+++ b/xtables.c
@@ -73,31 +73,6 @@ void basic_exit_err(enum xtables_exittype status, const char *msg, ...)
 }
 
 
-/**
- * xtables_set_params - set the global parameters used by xtables
- * @xtp:       input xtables_globals structure
- *
- * The app is expected to pass a valid xtables_globals data-filled
- * with proper values
- * @xtp cannot be NULL
- *
- * Returns -1 on failure to set and 0 on success
- */
-int xtables_set_params(struct xtables_globals *xtp)
-{
-       if (!xtp) {
-               fprintf(stderr, "%s: Illegal global params\n",__func__);
-               return -1;
-       }
-
-       xt_params = xtp;
-
-       if (!xt_params->exit_err)
-               xt_params->exit_err = basic_exit_err;
-
-       return 0;
-}
-
 void xtables_free_opts(int reset_offset)
 {
        if (xt_params->opts != xt_params->orig_opts) {
@@ -241,6 +216,38 @@ void xtables_set_nfproto(uint8_t nfproto)
        }
 }
 
+/**
+ * xtables_set_params - set the global parameters used by xtables
+ * @xtp:       input xtables_globals structure
+ *
+ * The app is expected to pass a valid xtables_globals data-filled
+ * with proper values
+ * @xtp cannot be NULL
+ *
+ * Returns -1 on failure to set and 0 on success
+ */
+int xtables_set_params(struct xtables_globals *xtp)
+{
+       if (!xtp) {
+               fprintf(stderr, "%s: Illegal global params\n",__func__);
+               return -1;
+       }
+
+       xt_params = xtp;
+
+       if (!xt_params->exit_err)
+               xt_params->exit_err = basic_exit_err;
+
+       return 0;
+}
+
+int xtables_init_all(struct xtables_globals *xtp, uint8_t nfproto)
+{
+       xtables_init();
+       xtables_set_nfproto(nfproto);
+       return xtables_set_params(xtp);
+}
+
 /**
  * xtables_*alloc - wrappers that exit on failure
  */