]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables-restore: Integrate restore callbacks into struct nft_xt_restore_parse
authorPhil Sutter <phil@nwl.cc>
Thu, 17 Oct 2019 20:26:50 +0000 (22:26 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 6 Nov 2019 12:41:32 +0000 (13:41 +0100)
There's really no point in passing those as separate parameter. While
being at it, make them static const everywhere.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft-shared.h
iptables/xtables-restore.c
iptables/xtables-translate.c

index e236a981119acfef4f0e411d67d05cc6c0957f0d..4ca551bddc081658df7ebb4a6d4143f6d209e776 100644 (file)
@@ -215,13 +215,6 @@ void do_parse(struct nft_handle *h, int argc, char *argv[],
              struct nft_xt_cmd_parse *p, struct iptables_command_state *cs,
              struct xtables_args *args);
 
-struct nft_xt_restore_parse {
-       FILE            *in;
-       int             testing;
-       const char      *tablename;
-       bool            commit;
-};
-
 struct nftnl_chain_list;
 
 struct nft_xt_restore_cb {
@@ -241,9 +234,16 @@ struct nft_xt_restore_cb {
        int (*abort)(struct nft_handle *h);
 };
 
+struct nft_xt_restore_parse {
+       FILE                            *in;
+       int                             testing;
+       const char                      *tablename;
+       bool                            commit;
+       const struct nft_xt_restore_cb  *cb;
+};
+
 void xtables_restore_parse(struct nft_handle *h,
-                          const struct nft_xt_restore_parse *p,
-                          const struct nft_xt_restore_cb *cb);
+                          const struct nft_xt_restore_parse *p);
 
 void nft_check_xt_legacy(int family, bool is_ipt_save);
 #endif
index 8d6cb7a97ea37d1343d070ffe7986cb89ca4b808..341579bd8d1c3e9c428655c2bb7f57fb69ff8eb6 100644 (file)
@@ -69,10 +69,10 @@ static const struct nft_xt_restore_cb restore_cb = {
 };
 
 void xtables_restore_parse(struct nft_handle *h,
-                          const struct nft_xt_restore_parse *p,
-                          const struct nft_xt_restore_cb *cb)
+                          const struct nft_xt_restore_parse *p)
 {
        const struct builtin_table *curtable = NULL;
+       const struct nft_xt_restore_cb *cb = p->cb;
        struct argv_store av_store = {};
        char buffer[10240];
        int in_table = 0;
@@ -279,6 +279,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
        int c;
        struct nft_xt_restore_parse p = {
                .commit = true,
+               .cb = &restore_cb,
        };
 
        line = 0;
@@ -383,7 +384,7 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
                exit(EXIT_FAILURE);
        }
 
-       xtables_restore_parse(&h, &p, &restore_cb);
+       xtables_restore_parse(&h, &p);
 
        nft_fini(&h);
        fclose(p.in);
@@ -427,6 +428,7 @@ int xtables_eb_restore_main(int argc, char *argv[])
 {
        struct nft_xt_restore_parse p = {
                .in = stdin,
+               .cb = &ebt_restore_cb,
        };
        bool noflush = false;
        struct nft_handle h;
@@ -448,7 +450,7 @@ int xtables_eb_restore_main(int argc, char *argv[])
 
        nft_init_eb(&h, "ebtables-restore");
        h.noflush = noflush;
-       xtables_restore_parse(&h, &p, &ebt_restore_cb);
+       xtables_restore_parse(&h, &p);
        nft_fini(&h);
 
        return 0;
@@ -467,11 +469,12 @@ int xtables_arp_restore_main(int argc, char *argv[])
 {
        struct nft_xt_restore_parse p = {
                .in = stdin,
+               .cb = &arp_restore_cb,
        };
        struct nft_handle h;
 
        nft_init_arp(&h, "arptables-restore");
-       xtables_restore_parse(&h, &p, &arp_restore_cb);
+       xtables_restore_parse(&h, &p);
        nft_fini(&h);
 
        return 0;
index 43607901fc62b49c230e3ab669b74a7ad525a206..a42c60a3b64c6309293a6f024f07860219b40536 100644 (file)
@@ -498,7 +498,9 @@ static int xtables_restore_xlate_main(int family, const char *progname,
                .family = family,
        };
        const char *file = NULL;
-       struct nft_xt_restore_parse p = {};
+       struct nft_xt_restore_parse p = {
+               .cb = &cb_xlate,
+       };
        time_t now = time(NULL);
        int c;
 
@@ -535,7 +537,7 @@ static int xtables_restore_xlate_main(int family, const char *progname,
 
        printf("# Translated by %s v%s on %s",
               argv[0], PACKAGE_VERSION, ctime(&now));
-       xtables_restore_parse(&h, &p, &cb_xlate);
+       xtables_restore_parse(&h, &p);
        printf("# Completed on %s", ctime(&now));
 
        nft_fini(&h);