]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Introduce builtin_tables_lookup()
authorPhil Sutter <phil@nwl.cc>
Mon, 27 Sep 2021 14:59:49 +0000 (16:59 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 20 Oct 2021 09:32:54 +0000 (11:32 +0200)
The set of builtin tables to use is fully determined by the given family
so just look it up instead of having callers pass it explicitly.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft.c
iptables/nft.h
iptables/xtables-arp.c
iptables/xtables-eb.c
iptables/xtables-monitor.c
iptables/xtables-restore.c
iptables/xtables-save.c
iptables/xtables-standalone.c
iptables/xtables-translate.c

index dc1f5160eb98347b0b0f32107c8148e0c44a686e..1d3f3a3da1cbbedd899a9ed9ccb361f153ecfcdc 100644 (file)
@@ -863,7 +863,22 @@ int nft_restart(struct nft_handle *h)
        return 0;
 }
 
-int nft_init(struct nft_handle *h, int family, const struct builtin_table *t)
+static const struct builtin_table *builtin_tables_lookup(int family)
+{
+       switch (family) {
+       case AF_INET:
+       case AF_INET6:
+               return xtables_ipv4;
+       case NFPROTO_ARP:
+               return xtables_arp;
+       case NFPROTO_BRIDGE:
+               return xtables_bridge;
+       default:
+               return NULL;
+       }
+}
+
+int nft_init(struct nft_handle *h, int family)
 {
        memset(h, 0, sizeof(*h));
 
@@ -881,7 +896,7 @@ int nft_init(struct nft_handle *h, int family, const struct builtin_table *t)
                xtables_error(PARAMETER_PROBLEM, "Unknown family");
 
        h->portid = mnl_socket_get_portid(h->nl);
-       h->tables = t;
+       h->tables = builtin_tables_lookup(family);
        h->cache = &h->__cache[0];
        h->family = family;
 
index ef79b018f78360d953daadc2fab6e35cf18153d1..f189b03fbc6b9348c606d6f2a73eb7202921f38d 100644 (file)
@@ -123,7 +123,7 @@ extern const struct builtin_table xtables_bridge[NFT_TABLE_MAX];
 int mnl_talk(struct nft_handle *h, struct nlmsghdr *nlh,
             int (*cb)(const struct nlmsghdr *nlh, void *data),
             void *data);
-int nft_init(struct nft_handle *h, int family, const struct builtin_table *t);
+int nft_init(struct nft_handle *h, int family);
 void nft_fini(struct nft_handle *h);
 int nft_restart(struct nft_handle *h);
 
index 9a079f06b948a9fd36c03270d975fbee12fd3814..1d132bdf23546fe44061d74570100d585a919f2e 100644 (file)
@@ -397,7 +397,7 @@ int nft_init_arp(struct nft_handle *h, const char *pname)
        init_extensionsa();
 #endif
 
-       if (nft_init(h, NFPROTO_ARP, xtables_arp) < 0)
+       if (nft_init(h, NFPROTO_ARP) < 0)
                xtables_error(OTHER_PROBLEM,
                              "Could not initialize nftables layer.");
 
index 23023ce13e4b8950558f326b8806db590af5e608..1ed6bcd8a7877160caa87797013d4ad1c4f92ad4 100644 (file)
@@ -672,7 +672,7 @@ int nft_init_eb(struct nft_handle *h, const char *pname)
        init_extensionsb();
 #endif
 
-       if (nft_init(h, NFPROTO_BRIDGE, xtables_bridge) < 0)
+       if (nft_init(h, NFPROTO_BRIDGE) < 0)
                xtables_error(OTHER_PROBLEM,
                              "Could not initialize nftables layer.");
 
index 21d4bec08fd9acea306805752140270d500c3e80..73dc80c24d7220f5e97f4d482aa3ed7c24474051 100644 (file)
@@ -631,7 +631,7 @@ int xtables_monitor_main(int argc, char *argv[])
        init_extensions6();
 #endif
 
-       if (nft_init(&h, AF_INET, xtables_ipv4)) {
+       if (nft_init(&h, AF_INET)) {
                fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
                        xtables_globals.program_name,
                        xtables_globals.program_version,
index 72832103d6bc3e8e1b49ba385a5b26b1381a02f6..86dcede395e0782dad36eab37c451f5368654f3d 100644 (file)
@@ -281,7 +281,6 @@ void xtables_restore_parse(struct nft_handle *h,
 static int
 xtables_restore_main(int family, const char *progname, int argc, char *argv[])
 {
-       const struct builtin_table *tables;
        struct nft_xt_restore_parse p = {
                .commit = true,
                .cb = &restore_cb,
@@ -360,7 +359,6 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
        switch (family) {
        case NFPROTO_IPV4:
        case NFPROTO_IPV6: /* fallthough, same table */
-               tables = xtables_ipv4;
 #if defined(ALL_INCLUSIVE) || defined(NO_SHARED_LIBS)
                init_extensions();
                init_extensions4();
@@ -368,17 +366,14 @@ xtables_restore_main(int family, const char *progname, int argc, char *argv[])
 #endif
                break;
        case NFPROTO_ARP:
-               tables = xtables_arp;
-               break;
        case NFPROTO_BRIDGE:
-               tables = xtables_bridge;
                break;
        default:
                fprintf(stderr, "Unknown family %d\n", family);
                return 1;
        }
 
-       if (nft_init(&h, family, tables) < 0) {
+       if (nft_init(&h, family) < 0) {
                fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
                                xtables_globals.program_name,
                                xtables_globals.program_version,
index f794e3ff1e31854d28466c2f44b1f27708720932..c6ebb0ec94c4f4adc4792fa63b731bb6a6bad42d 100644 (file)
@@ -131,7 +131,6 @@ static int
 xtables_save_main(int family, int argc, char *argv[],
                  const char *optstring, const struct option *longopts)
 {
-       const struct builtin_table *tables;
        const char *tablename = NULL;
        struct do_output_data d = {
                .format = FMT_NOCOUNTS,
@@ -208,11 +207,9 @@ xtables_save_main(int family, int argc, char *argv[],
                init_extensions4();
                init_extensions6();
 #endif
-               tables = xtables_ipv4;
                d.commit = true;
                break;
        case NFPROTO_ARP:
-               tables = xtables_arp;
                break;
        case NFPROTO_BRIDGE: {
                const char *ctr = getenv("EBTABLES_SAVE_COUNTER");
@@ -223,7 +220,6 @@ xtables_save_main(int family, int argc, char *argv[],
                        d.format &= ~FMT_NOCOUNTS;
                        d.format |= FMT_C_COUNTS | FMT_EBT_SAVE;
                }
-               tables = xtables_bridge;
                break;
        }
        default:
@@ -231,7 +227,7 @@ xtables_save_main(int family, int argc, char *argv[],
                return 1;
        }
 
-       if (nft_init(&h, family, tables) < 0) {
+       if (nft_init(&h, family) < 0) {
                fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
                                xtables_globals.program_name,
                                xtables_globals.program_version,
index 1a6b7cf73a4bb2b3f5de999e52cc4a085a3e47f1..f4d40cda6ae43679e4cc31321e287fb1bbaa9550 100644 (file)
@@ -60,7 +60,7 @@ xtables_main(int family, const char *progname, int argc, char *argv[])
        init_extensions6();
 #endif
 
-       if (nft_init(&h, family, xtables_ipv4) < 0) {
+       if (nft_init(&h, family) < 0) {
                fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
                                xtables_globals.program_name,
                                xtables_globals.program_version,
index 2a00a85088e2c9da4d132aa0baaefcb6f239c2e2..086b85d2f9ceffac657b586e213374b74943c417 100644 (file)
@@ -465,7 +465,6 @@ static int xtables_xlate_main_common(struct nft_handle *h,
                                     int family,
                                     const char *progname)
 {
-       const struct builtin_table *tables;
        int ret;
 
        xtables_globals.program_name = progname;
@@ -485,20 +484,16 @@ static int xtables_xlate_main_common(struct nft_handle *h,
        init_extensions4();
        init_extensions6();
 #endif
-               tables = xtables_ipv4;
                break;
        case NFPROTO_ARP:
-               tables = xtables_arp;
-               break;
        case NFPROTO_BRIDGE:
-               tables = xtables_bridge;
                break;
        default:
                fprintf(stderr, "Unknown family %d\n", family);
                return 1;
        }
 
-       if (nft_init(h, family, tables) < 0) {
+       if (nft_init(h, family) < 0) {
                fprintf(stderr, "%s/%s Failed to initialize nft: %s\n",
                                xtables_globals.program_name,
                                xtables_globals.program_version,