]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
evaluate: use chain hashtable for lookups
authorPablo Neira Ayuso <pablo@netfilter.org>
Thu, 1 Apr 2021 20:25:24 +0000 (22:25 +0200)
committerPablo Neira Ayuso <pablo@netfilter.org>
Sat, 3 Apr 2021 17:41:02 +0000 (19:41 +0200)
Instead of the linear list lookup.

Before this patch:

real    0m21,735s
user    0m20,329s
sys     0m1,384s

After:

real    0m10,910s
user    0m9,448s
sys     0m1,434s

chain_lookup() is removed since linear list lookups are only used by the
fuzzy chain name matching for error reporting.

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

index 6c6ada6b5537a9cbfe1296a801f3e8e874b7351f..ad9cca90570d99a5534eef40f734e4e6f4cb586a 100644 (file)
@@ -259,8 +259,6 @@ extern const char *chain_hookname_lookup(const char *name);
 extern struct chain *chain_alloc(const char *name);
 extern struct chain *chain_get(struct chain *chain);
 extern void chain_free(struct chain *chain);
-extern struct chain *chain_lookup(const struct table *table,
-                                 const struct handle *h);
 extern struct chain *chain_lookup_fuzzy(const struct handle *h,
                                        const struct nft_cache *cache,
                                        const struct table **table);
index 8105d8d5c8a9f8ec5799e1c6fa53f92f4d8de2c8..50f100db4a5db928d7886f678a1a1d82fe3fd0f0 100644 (file)
@@ -4109,14 +4109,14 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
                return table_not_found(ctx);
 
        if (chain == NULL) {
-               if (chain_lookup(table, &ctx->cmd->handle) == NULL) {
+               if (chain_cache_find(table, &ctx->cmd->handle) == NULL) {
                        chain = chain_alloc(NULL);
                        handle_merge(&chain->handle, &ctx->cmd->handle);
                        chain_cache_add(chain, table);
                }
                return 0;
        } else if (!(chain->flags & CHAIN_F_BINDING)) {
-               if (chain_lookup(table, &chain->handle) == NULL)
+               if (chain_cache_find(table, &chain->handle) == NULL)
                        chain_cache_add(chain_get(chain), table);
        }
 
@@ -4443,7 +4443,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
                if (table == NULL)
                        return table_not_found(ctx);
 
-               if (chain_lookup(table, &cmd->handle) == NULL)
+               if (chain_cache_find(table, &cmd->handle) == NULL)
                        return chain_not_found(ctx);
 
                return 0;
@@ -4603,7 +4603,7 @@ static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
                if (table == NULL)
                        return table_not_found(ctx);
 
-               if (chain_lookup(table, &ctx->cmd->handle) == NULL)
+               if (chain_cache_find(table, &ctx->cmd->handle) == NULL)
                        return chain_not_found(ctx);
 
                break;
index 97ae88c72789441cc788655639bb66ff308c273f..89d224ed722de92e8c4c41c0f0e08c3e0934390f 100644 (file)
@@ -1749,7 +1749,7 @@ static struct rule *trace_lookup_rule(const struct nftnl_trace *nlt,
        if (!table)
                return NULL;
 
-       chain = chain_lookup(table, &h);
+       chain = chain_cache_find(table, &h);
        if (!chain)
                return NULL;
 
index 5be9c0c82444640ed4c8a3984b61cc2e7db85fa6..9c9fd7fdac6d7449ceeb199606704fdc72ea8640 100644 (file)
@@ -761,17 +761,6 @@ void chain_free(struct chain *chain)
        xfree(chain);
 }
 
-struct chain *chain_lookup(const struct table *table, const struct handle *h)
-{
-       struct chain *chain;
-
-       list_for_each_entry(chain, &table->cache_chain, cache_list) {
-               if (!strcmp(chain->handle.chain.name, h->chain.name))
-                       return chain;
-       }
-       return NULL;
-}
-
 struct chain *chain_binding_lookup(const struct table *table,
                                   const char *chain_name)
 {
@@ -2625,7 +2614,7 @@ static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
 
        switch (cmd->obj) {
        case CMD_OBJ_CHAIN:
-               chain = chain_lookup(table, &cmd->handle);
+               chain = chain_cache_find(table, &cmd->handle);
 
                return mnl_nft_chain_rename(ctx, cmd, chain);
        default: