]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
cache: Reduce caching for get command
authorPhil Sutter <phil@nwl.cc>
Thu, 14 Nov 2019 14:45:07 +0000 (15:45 +0100)
committerPhil Sutter <phil@nwl.cc>
Fri, 15 Nov 2019 09:51:28 +0000 (10:51 +0100)
Introduce a function to distinguish which command object was given and
request only the necessary bits to have sets and their elements
available for 'get element' command.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
src/cache.c

index a778650ac133af33549104248469ef98d57f961a..0c28a28d3b55421b8696621f873c3fc1c40416f0 100644 (file)
@@ -63,6 +63,21 @@ static unsigned int evaluate_cache_del(struct cmd *cmd, unsigned int flags)
        return flags;
 }
 
+static unsigned int evaluate_cache_get(struct cmd *cmd, unsigned int flags)
+{
+       switch (cmd->obj) {
+       case CMD_OBJ_SETELEM:
+               flags |= NFT_CACHE_TABLE |
+                        NFT_CACHE_SET |
+                        NFT_CACHE_SETELEM;
+               break;
+       default:
+               break;
+       }
+
+       return flags;
+}
+
 static unsigned int evaluate_cache_flush(struct cmd *cmd, unsigned int flags)
 {
        switch (cmd->obj) {
@@ -121,6 +136,8 @@ unsigned int cache_evaluate(struct nft_ctx *nft, struct list_head *cmds)
                        flags = evaluate_cache_del(cmd, flags);
                        break;
                case CMD_GET:
+                       flags = evaluate_cache_get(cmd, flags);
+                       break;
                case CMD_LIST:
                case CMD_RESET:
                case CMD_EXPORT: