]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cache: prepare nft_cache_evaluate() to return error
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 18 Jul 2022 13:56:00 +0000 (15:56 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 18 Jul 2022 14:20:33 +0000 (16:20 +0200)
Move flags as parameter reference and add list of error messages to prepare
for sanity checks.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/cache.h
src/cache.c
src/libnftables.c

index b6c7d48bfba6cdef6d4e5b04f15d0c5fa6c6bfee..575381ef971bc360c1ac716075a5b8abe92e8df0 100644 (file)
@@ -65,8 +65,9 @@ struct nft_cache_filter {
 struct nft_cache;
 enum cmd_ops;
 
-unsigned int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds,
-                               struct nft_cache_filter *filter);
+int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds,
+                      struct list_head *msgs, struct nft_cache_filter *filter,
+                      unsigned int *flags);
 int nft_cache_update(struct nft_ctx *ctx, enum cmd_ops cmd,
                     struct list_head *msgs,
                     const struct nft_cache_filter *filter);
index b6ae2310b175f8b6076b2530c3654a4370cb1769..9e2fe950a884f3781c8eef924af10d0eedd587e3 100644 (file)
@@ -262,8 +262,9 @@ static unsigned int evaluate_cache_list(struct nft_ctx *nft, struct cmd *cmd,
        return flags;
 }
 
-unsigned int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds,
-                               struct nft_cache_filter *filter)
+int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds,
+                      struct list_head *msgs, struct nft_cache_filter *filter,
+                      unsigned int *pflags)
 {
        unsigned int flags = NFT_CACHE_EMPTY;
        struct cmd *cmd;
@@ -318,8 +319,9 @@ unsigned int nft_cache_evaluate(struct nft_ctx *nft, struct list_head *cmds,
                        break;
                }
        }
+       *pflags = flags;
 
-       return flags;
+       return 0;
 }
 
 void table_cache_add(struct table *table, struct nft_cache *cache)
index f2a1ef04e80b05a61f82ddc2dd05350c7a0e6964..a376825d73098271b3f8e41f5211be6f264b0359 100644 (file)
@@ -506,7 +506,10 @@ static int nft_evaluate(struct nft_ctx *nft, struct list_head *msgs,
        int err = 0;
 
        filter = nft_cache_filter_init();
-       flags = nft_cache_evaluate(nft, cmds, filter);
+       if (nft_cache_evaluate(nft, cmds, msgs, filter, &flags) < 0) {
+               nft_cache_filter_fini(filter);
+               return -1;
+       }
        if (nft_cache_update(nft, flags, msgs, filter) < 0) {
                nft_cache_filter_fini(filter);
                return -1;