summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/xtables.h.in1
-rw-r--r--ip6tables-restore.c9
-rw-r--r--ip6tables-save.c9
-rw-r--r--ip6tables-standalone.c10
-rw-r--r--ip6tables.c1
-rw-r--r--iptables-restore.c9
-rw-r--r--iptables-save.c9
-rw-r--r--iptables-standalone.c9
-rw-r--r--iptables.c1
-rw-r--r--xtables.c57
10 files changed, 76 insertions, 39 deletions
diff --git a/include/xtables.h.in b/include/xtables.h.in
index aaadbbd6..4ab0ecbe 100644
--- a/include/xtables.h.in
+++ b/include/xtables.h.in
@@ -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,
diff --git a/ip6tables-restore.c b/ip6tables-restore.c
index 3d535def..0f06a1c0 100644
--- a/ip6tables-restore.c
+++ b/ip6tables-restore.c
@@ -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
diff --git a/ip6tables-save.c b/ip6tables-save.c
index 3af81abd..9de34b51 100644
--- a/ip6tables-save.c
+++ b/ip6tables-save.c
@@ -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
diff --git a/ip6tables-standalone.c b/ip6tables-standalone.c
index ab770655..b40c79bc 100644
--- a/ip6tables-standalone.c
+++ b/ip6tables-standalone.c
@@ -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
diff --git a/ip6tables.c b/ip6tables.c
index 250bb0ea..dca484f0 100644
--- a/ip6tables.c
+++ b/ip6tables.c
@@ -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) {
diff --git a/iptables-restore.c b/iptables-restore.c
index 01030166..c52af0ad 100644
--- a/iptables-restore.c
+++ b/iptables-restore.c
@@ -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
diff --git a/iptables-save.c b/iptables-save.c
index 396406fe..312673ac 100644
--- a/iptables-save.c
+++ b/iptables-save.c
@@ -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
diff --git a/iptables-standalone.c b/iptables-standalone.c
index 007f2c2d..6090ea15 100644
--- a/iptables-standalone.c
+++ b/iptables-standalone.c
@@ -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
diff --git a/iptables.c b/iptables.c
index e6b4aa04..2583ec6c 100644
--- a/iptables.c
+++ b/iptables.c
@@ -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) {
diff --git a/xtables.c b/xtables.c
index bdb0133d..a812ef16 100644
--- 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) {
@@ -242,6 +217,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
*/
void *xtables_calloc(size_t count, size_t size)