summaryrefslogtreecommitdiffstats
path: root/iptables/xtables-translate.c
diff options
context:
space:
mode:
authorFlorian Westphal <fw@strlen.de>2018-04-12 11:46:02 +0200
committerFlorian Westphal <fw@strlen.de>2018-04-13 20:06:47 +0200
commitd988274d8f2e7cee8deea954ca3e70b4080b7e86 (patch)
tree4146fba9e4c99918d6ecf7cd0f3c5fb150bb70e2 /iptables/xtables-translate.c
parent1650806382a7c45cafd42dccaf2ed8cd64a2bd94 (diff)
xlate-translate: split common parts into helper
Diffstat (limited to 'iptables/xtables-translate.c')
-rw-r--r--iptables/xtables-translate.c59
1 files changed, 26 insertions, 33 deletions
diff --git a/iptables/xtables-translate.c b/iptables/xtables-translate.c
index 61d4da17..ecb490f9 100644
--- a/iptables/xtables-translate.c
+++ b/iptables/xtables-translate.c
@@ -420,38 +420,50 @@ static struct nft_xt_restore_cb cb_xlate = {
.abort = commit,
};
-static int xtables_xlate_main(int family, const char *progname, int argc,
- char *argv[])
+static int xtables_xlate_main_common(struct nft_handle *h,
+ int family,
+ const char *progname)
{
int ret;
- char *table = "filter";
- struct nft_handle h = {
- .family = family,
- };
xtables_globals.program_name = progname;
xtables_globals.compat_rev = dummy_compat_rev;
ret = xtables_init_all(&xtables_globals, family);
if (ret < 0) {
fprintf(stderr, "%s/%s Failed to initialize xtables\n",
- xtables_globals.program_name,
- xtables_globals.program_version);
- exit(1);
+ xtables_globals.program_name,
+ xtables_globals.program_version);
+ return 1;
}
#if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
init_extensions();
init_extensions4();
#endif
- if (nft_init(&h, xtables_ipv4) < 0) {
+ if (nft_init(h, xtables_ipv4) < 0) {
fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
xtables_globals.program_name,
xtables_globals.program_version,
strerror(errno));
- nft_fini(&h);
- exit(EXIT_FAILURE);
+ return 1;
}
+ return 0;
+}
+
+static int xtables_xlate_main(int family, const char *progname, int argc,
+ char *argv[])
+{
+ int ret;
+ char *table = "filter";
+ struct nft_handle h = {
+ .family = family,
+ };
+
+ ret = xtables_xlate_main_common(&h, family, progname);
+ if (ret < 0)
+ exit(EXIT_FAILURE);
+
ret = do_command_xlate(&h, argc, argv, &table, false);
if (!ret)
fprintf(stderr, "Translation not implemented\n");
@@ -472,28 +484,9 @@ static int xtables_restore_xlate_main(int family, const char *progname,
time_t now = time(NULL);
int c;
- xtables_globals.program_name = progname;
- xtables_globals.compat_rev = dummy_compat_rev;
- ret = xtables_init_all(&xtables_globals, family);
- if (ret < 0) {
- fprintf(stderr, "%s/%s Failed to initialize xtables\n",
- xtables_globals.program_name,
- xtables_globals.program_version);
- exit(1);
- }
-#if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
- init_extensions();
- init_extensions4();
-#endif
-
- if (nft_init(&h, xtables_ipv4) < 0) {
- fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
- xtables_globals.program_name,
- xtables_globals.program_version,
- strerror(errno));
- nft_fini(&h);
+ ret = xtables_xlate_main_common(&h, family, progname);
+ if (ret < 0)
exit(EXIT_FAILURE);
- }
opterr = 0;
while ((c = getopt_long(argc, argv, "hf:", options, NULL)) != -1) {