From e1c95f0c7eff391b17a110c5b63ba316a03e23db Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Mon, 22 Jul 2019 12:16:27 +0200 Subject: arptables-save: Merge into xtables_save_main() With all preparations in place, xtables_save_main() can replace it with not further changes. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- iptables/xtables-save.c | 63 +++---------------------------------------------- 1 file changed, 3 insertions(+), 60 deletions(-) (limited to 'iptables') diff --git a/iptables/xtables-save.c b/iptables/xtables-save.c index 980a80ff..0c294e05 100644 --- a/iptables/xtables-save.c +++ b/iptables/xtables-save.c @@ -372,65 +372,8 @@ int xtables_eb_save_main(int argc_, char *argv_[]) return 0; } -int xtables_arp_save_main(int argc, char **argv) +int xtables_arp_save_main(int argc, char *argv[]) { - struct nft_handle h = { - .family = NFPROTO_ARP, - }; - time_t now; - int c; - - xtables_globals.program_name = basename(*argv);; - c = xtables_init_all(&xtables_globals, h.family); - if (c < 0) { - fprintf(stderr, "%s/%s Failed to initialize xtables\n", - xtables_globals.program_name, - xtables_globals.program_version); - exit(1); - } - - while ((c = getopt_long(argc, argv, arp_save_optstring, arp_save_options, NULL)) != -1) { - switch (c) { - case 'c': - show_counters = true; - break; - case 'M': - xtables_modprobe_program = optarg; - break; - case 'V': - printf("%s v%s (nf_tables)\n", prog_name, prog_vers); - exit(0); - default: - fprintf(stderr, - "Look at manual page `%s.8' for more information.\n", - prog_name); - exit(1); - } - } - - if (nft_init(&h, xtables_arp) < 0) { - fprintf(stderr, "%s/%s Failed to initialize nft: %s\n", - xtables_globals.program_name, - xtables_globals.program_version, - strerror(errno)); - exit(EXIT_FAILURE); - } - - if (!nft_table_find(&h, "filter")) - return 0; - - if (!nft_is_table_compatible(&h, "filter")) { - printf("# Table `filter' is incompatible, use 'nft' tool.\n"); - return 0; - } - - printf("# Generated by %s v%s on %s", prog_name, - prog_vers, ctime(&now)); - printf("*filter\n"); - nft_chain_save(&h, nft_chain_list_get(&h, "filter")); - nft_rule_save(&h, "filter", show_counters ? 0 : FMT_NOCOUNTS); - now = time(NULL); - printf("# Completed on %s", ctime(&now)); - nft_fini(&h); - return 0; + return xtables_save_main(NFPROTO_ARP, argc, argv, + arp_save_optstring, arp_save_options); } -- cgit v1.2.3