]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: cache: Introduce struct nft_cache_req
authorPhil Sutter <phil@nwl.cc>
Tue, 7 Apr 2020 12:05:34 +0000 (14:05 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 11 May 2020 12:28:28 +0000 (14:28 +0200)
This embedded struct collects cache requirement info gathered from parsed
nft_cmds and is interpreted by __nft_build_cache().

While being at it, remove unused parameters passed to the latter
function, nft_handle pointer is sufficient.

Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft-cache.c
iptables/nft.h

index 2c6a170881eb321f948acca882147c10bdda1680..305f2c12307f7a22984e3517ba5201feecf3c45d 100644 (file)
 
 void nft_cache_level_set(struct nft_handle *h, int level)
 {
-       if (level <= h->cache_level)
+       struct nft_cache_req *req = &h->cache_req;
+
+       if (level <= req->level)
                return;
 
-       h->cache_level = level;
+       req->level = level;
 }
 
 static int genid_cb(const struct nlmsghdr *nlh, void *data)
@@ -430,26 +432,26 @@ static int fetch_rule_cache(struct nft_handle *h,
 }
 
 static void
-__nft_build_cache(struct nft_handle *h, enum nft_cache_level level,
-                 const struct builtin_table *t, const char *set,
-                 const char *chain)
+__nft_build_cache(struct nft_handle *h)
 {
+       struct nft_cache_req *req = &h->cache_req;
+
        if (h->cache_init)
                return;
 
        h->cache_init = true;
        mnl_genid_get(h, &h->nft_genid);
 
-       if (h->cache_level >= NFT_CL_TABLES)
+       if (req->level >= NFT_CL_TABLES)
                fetch_table_cache(h);
-       if (h->cache_level == NFT_CL_FAKE)
+       if (req->level == NFT_CL_FAKE)
                return;
-       if (h->cache_level >= NFT_CL_CHAINS)
-               fetch_chain_cache(h, t, chain);
-       if (h->cache_level >= NFT_CL_SETS)
-               fetch_set_cache(h, t, set);
-       if (h->cache_level >= NFT_CL_RULES)
-               fetch_rule_cache(h, t);
+       if (req->level >= NFT_CL_CHAINS)
+               fetch_chain_cache(h, NULL, NULL);
+       if (req->level >= NFT_CL_SETS)
+               fetch_set_cache(h, NULL, NULL);
+       if (req->level >= NFT_CL_RULES)
+               fetch_rule_cache(h, NULL);
 }
 
 static void __nft_flush_cache(struct nft_handle *h)
@@ -563,12 +565,12 @@ void nft_rebuild_cache(struct nft_handle *h)
                h->cache_init = false;
        }
 
-       __nft_build_cache(h, h->cache_level, NULL, NULL, NULL);
+       __nft_build_cache(h);
 }
 
 void nft_cache_build(struct nft_handle *h)
 {
-       __nft_build_cache(h, h->cache_level, NULL, NULL, NULL);
+       __nft_build_cache(h);
 }
 
 void nft_release_cache(struct nft_handle *h)
index 89c3620e7b7d7120c861fb890afbf943b3195426..c6aece7d1dac8de3fb074defdb63bc71054364f1 100644 (file)
@@ -71,6 +71,10 @@ enum obj_update_type {
        NFT_COMPAT_TABLE_NEW,
 };
 
+struct nft_cache_req {
+       enum nft_cache_level    level;
+};
+
 struct nft_handle {
        int                     family;
        struct mnl_socket       *nl;
@@ -89,7 +93,7 @@ struct nft_handle {
        unsigned int            cache_index;
        struct nft_cache        __cache[2];
        struct nft_cache        *cache;
-       enum nft_cache_level    cache_level;
+       struct nft_cache_req    cache_req;
        bool                    restore;
        bool                    noflush;
        int8_t                  config_done;