* [PATCH nft 0/10] cache updates
@ 2021-04-15 13:13 Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 01/10] cache: add hashtable cache for object Pablo Neira Ayuso
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Hi,
The following patchset contains cache updates for nft:
#1 adds a object hashtable for lookups by name.
#2 adds a flowtable hashtable for lookups by name.
#3 adds set_cache_del() and use it from the monitor path.
#4 adds ruleset-defined sets to the cache.
#5 adds ruleset-defined flowtables to the cache.
#6 populates the table cache for several objects.
#7 adds ruleset-define policy objects to the cache.
#8 move struct nft_cache declaration to include/cache.h
#9 adds a table hashtable for lookups by name.
#10 removes table_lookup_global() which is not required
anymore after the previous updates.
Pablo Neira Ayuso (10):
cache: add hashtable cache for object
cache: add hashtable cache for flowtable
cache: add set_cache_del() and use it
evaluate: add set to the cache
evaluate: add flowtable to the cache
cache: missing table cache for several policy objects
evaluate: add object to the cache
cache: move struct nft_cache declaration to cache.h
cache: add hashtable cache for table
evaluate: remove table_lookup_global()
include/cache.h | 25 ++++
include/netlink.h | 2 +
include/nftables.h | 8 +-
include/rule.h | 18 +--
src/cache.c | 244 ++++++++++++++++++++++++++++++++++++--
src/evaluate.c | 83 ++++++-------
src/json.c | 24 ++--
src/libnftables.c | 8 ++
src/monitor.c | 20 ++--
src/netlink.c | 23 +---
src/netlink_delinearize.c | 4 +-
src/rule.c | 125 ++++++++-----------
12 files changed, 399 insertions(+), 185 deletions(-)
--
2.20.1
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH nft 01/10] cache: add hashtable cache for object
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 02/10] cache: add hashtable cache for flowtable Pablo Neira Ayuso
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
This patch adds a hashtable for object lookups.
This patch also splits table->objs in two:
- Sets that reside in the cache are stored in the new
tables->cache_obj and tables->cache_obj_ht.
- Set that defined via command line / ruleset file reside in
tables->obj.
Sets in the cache (already in the kernel) are not placed in the
table->objs list.
By keeping separated lists, objs defined via command line / ruleset file
can be added to cache.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cache.h | 5 +++
include/rule.h | 7 ++--
src/cache.c | 101 +++++++++++++++++++++++++++++++++++++++++++++++-
src/evaluate.c | 2 +-
src/json.c | 4 +-
src/monitor.c | 6 +--
src/netlink.c | 19 ---------
src/rule.c | 43 +++++++++------------
8 files changed, 133 insertions(+), 54 deletions(-)
diff --git a/include/cache.h b/include/cache.h
index f500e1b19e45..b0458dc9c284 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -62,4 +62,9 @@ struct chain *chain_cache_find(const struct table *table,
void set_cache_add(struct set *set, struct table *table);
struct set *set_cache_find(const struct table *table, const char *name);
+void obj_cache_add(struct obj *obj, struct table *table);
+void obj_cache_del(struct obj *obj);
+struct obj *obj_cache_find(const struct table *table, const char *name,
+ uint32_t obj_type);
+
#endif /* _NFT_CACHE_H_ */
diff --git a/include/rule.h b/include/rule.h
index 90c01e9014c8..226171a8def7 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -161,6 +161,8 @@ struct table {
struct list_head *cache_set_ht;
struct list_head cache_set;
struct list_head sets;
+ struct list_head *cache_obj_ht;
+ struct list_head cache_obj;
struct list_head objs;
struct list_head flowtables;
struct list_head chain_bindings;
@@ -488,6 +490,8 @@ struct secmark {
*/
struct obj {
struct list_head list;
+ struct list_head cache_hlist;
+ struct list_head cache_list;
struct location location;
struct handle handle;
uint32_t type;
@@ -508,9 +512,6 @@ struct obj {
struct obj *obj_alloc(const struct location *loc);
extern struct obj *obj_get(struct obj *obj);
void obj_free(struct obj *obj);
-void obj_add_hash(struct obj *obj, struct table *table);
-struct obj *obj_lookup(const struct table *table, const char *name,
- uint32_t type);
struct obj *obj_lookup_fuzzy(const char *obj_name,
const struct nft_cache *cache,
const struct table **t);
diff --git a/src/cache.c b/src/cache.c
index f032171a95ff..baf8dc12e5b6 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -338,6 +338,95 @@ struct set *set_cache_find(const struct table *table, const char *name)
return NULL;
}
+struct obj_cache_dump_ctx {
+ struct netlink_ctx *nlctx;
+ struct table *table;
+};
+
+static int obj_cache_cb(struct nftnl_obj *nlo, void *arg)
+{
+ struct obj_cache_dump_ctx *ctx = arg;
+ const char *obj_name;
+ struct obj *obj;
+ uint32_t hash;
+
+ obj = netlink_delinearize_obj(ctx->nlctx, nlo);
+ if (!obj)
+ return -1;
+
+ obj_name = nftnl_obj_get_str(nlo, NFTNL_OBJ_NAME);
+ hash = djb_hash(obj_name) % NFT_CACHE_HSIZE;
+ list_add_tail(&obj->cache_hlist, &ctx->table->cache_obj_ht[hash]);
+ list_add_tail(&obj->cache_list, &ctx->table->cache_obj);
+
+ return 0;
+}
+
+static int obj_cache_init(struct netlink_ctx *ctx, struct table *table,
+ struct nftnl_obj_list *obj_list)
+{
+ struct obj_cache_dump_ctx dump_ctx = {
+ .nlctx = ctx,
+ .table = table,
+ };
+ nftnl_obj_list_foreach(obj_list, obj_cache_cb, &dump_ctx);
+
+ return 0;
+}
+
+static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
+ const struct table *table,
+ int *err)
+{
+ struct nftnl_obj_list *obj_list;
+
+ obj_list = mnl_nft_obj_dump(ctx, table->handle.family,
+ table->handle.table.name, NULL,
+ 0, true, false);
+ if (!obj_list) {
+ if (errno == EINTR) {
+ *err = -1;
+ return NULL;
+ }
+ *err = 0;
+ return NULL;
+ }
+
+ return obj_list;
+}
+
+void obj_cache_add(struct obj *obj, struct table *table)
+{
+ uint32_t hash;
+
+ hash = djb_hash(obj->handle.obj.name) % NFT_CACHE_HSIZE;
+ list_add_tail(&obj->cache_hlist, &table->cache_obj_ht[hash]);
+ list_add_tail(&obj->cache_list, &table->cache_obj);
+}
+
+void obj_cache_del(struct obj *obj)
+{
+ list_del(&obj->cache_hlist);
+ list_del(&obj->cache_list);
+}
+
+struct obj *obj_cache_find(const struct table *table, const char *name,
+ uint32_t obj_type)
+{
+ struct obj *obj;
+ uint32_t hash;
+
+ hash = djb_hash(name) % NFT_CACHE_HSIZE;
+ list_for_each_entry(obj, &table->cache_obj_ht[hash], cache_hlist) {
+ if (!strcmp(obj->handle.obj.name, name) &&
+ obj->type == obj_type)
+ return obj;
+ }
+
+ return NULL;
+}
+
+
static int cache_init_tables(struct netlink_ctx *ctx, struct handle *h,
struct nft_cache *cache)
{
@@ -356,6 +445,7 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
{
struct nftnl_chain_list *chain_list = NULL;
struct nftnl_set_list *set_list = NULL;
+ struct nftnl_obj_list *obj_list;
struct rule *rule, *nrule;
struct table *table;
struct chain *chain;
@@ -410,12 +500,19 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
list_splice_tail_init(&ctx->list, &table->flowtables);
}
if (flags & NFT_CACHE_OBJECT_BIT) {
- ret = netlink_list_objs(ctx, &table->handle);
+ obj_list = obj_cache_dump(ctx, table, &ret);
+ if (!obj_list) {
+ ret = -1;
+ goto cache_fails;
+ }
+ ret = obj_cache_init(ctx, table, obj_list);
+
+ nftnl_obj_list_free(obj_list);
+
if (ret < 0) {
ret = -1;
goto cache_fails;
}
- list_splice_tail_init(&ctx->list, &table->objs);
}
if (flags & NFT_CACHE_RULE_BIT) {
diff --git a/src/evaluate.c b/src/evaluate.c
index 85cf9e05b641..d33a152c3de4 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -4373,7 +4373,7 @@ static int cmd_evaluate_list_obj(struct eval_ctx *ctx, const struct cmd *cmd,
if (table == NULL)
return table_not_found(ctx);
- if (obj_lookup(table, cmd->handle.obj.name, obj_type) == NULL)
+ if (obj_cache_find(table, cmd->handle.obj.name, obj_type) == NULL)
return obj_not_found(ctx, &cmd->handle.obj.location,
cmd->handle.obj.name);
diff --git a/src/json.c b/src/json.c
index 52603a57de50..bf151e927661 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1570,7 +1570,7 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
tmp = table_print_json(table);
json_array_append_new(root, tmp);
- list_for_each_entry(obj, &table->objs, list) {
+ list_for_each_entry(obj, &table->cache_obj, cache_list) {
tmp = obj_print_json(obj);
json_array_append_new(root, tmp);
}
@@ -1740,7 +1740,7 @@ static json_t *do_list_obj_json(struct netlink_ctx *ctx,
strcmp(cmd->handle.table.name, table->handle.table.name))
continue;
- list_for_each_entry(obj, &table->objs, list) {
+ list_for_each_entry(obj, &table->cache_obj, cache_list) {
if (obj->type != type ||
(cmd->handle.obj.name &&
strcmp(cmd->handle.obj.name, obj->handle.obj.name)))
diff --git a/src/monitor.c b/src/monitor.c
index dc3f0848ba66..1f0f8a361fbd 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -727,7 +727,7 @@ static void netlink_events_cache_addobj(struct netlink_mon_handler *monh,
goto out;
}
- obj_add_hash(obj, t);
+ obj_cache_add(obj, t);
out:
nftnl_obj_free(nlo);
}
@@ -756,13 +756,13 @@ static void netlink_events_cache_delobj(struct netlink_mon_handler *monh,
goto out;
}
- obj = obj_lookup(t, name, type);
+ obj = obj_cache_find(t, name, type);
if (obj == NULL) {
fprintf(stderr, "W: Unable to find object in cache\n");
goto out;
}
- list_del(&obj->list);
+ obj_cache_del(obj);
obj_free(obj);
out:
nftnl_obj_free(nlo);
diff --git a/src/netlink.c b/src/netlink.c
index e8b016096b67..2286a6ffabf8 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1517,25 +1517,6 @@ static int list_obj_cb(struct nftnl_obj *nls, void *arg)
return 0;
}
-int netlink_list_objs(struct netlink_ctx *ctx, const struct handle *h)
-{
- struct nftnl_obj_list *obj_cache;
- int err;
-
- obj_cache = mnl_nft_obj_dump(ctx, h->family,
- h->table.name, NULL, 0, true, false);
- if (obj_cache == NULL) {
- if (errno == EINTR)
- return -1;
-
- return 0;
- }
-
- err = nftnl_obj_list_foreach(obj_cache, list_obj_cb, ctx);
- nftnl_obj_list_free(obj_cache);
- return err;
-}
-
int netlink_reset_objs(struct netlink_ctx *ctx, const struct cmd *cmd,
uint32_t type, bool dump)
{
diff --git a/src/rule.c b/src/rule.c
index 2c6292c4e173..b78d4e7f9cd3 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1110,6 +1110,7 @@ struct table *table_alloc(void)
init_list_head(&table->sets);
init_list_head(&table->cache_set);
init_list_head(&table->objs);
+ init_list_head(&table->cache_obj);
init_list_head(&table->flowtables);
init_list_head(&table->chain_bindings);
init_list_head(&table->scope.symbols);
@@ -1125,6 +1126,11 @@ struct table *table_alloc(void)
for (i = 0; i < NFT_CACHE_HSIZE; i++)
init_list_head(&table->cache_set_ht[i]);
+ table->cache_obj_ht =
+ xmalloc(sizeof(struct list_head) * NFT_CACHE_HSIZE);
+ for (i = 0; i < NFT_CACHE_HSIZE; i++)
+ init_list_head(&table->cache_obj_ht[i]);
+
return table;
}
@@ -1155,10 +1161,15 @@ void table_free(struct table *table)
flowtable_free(ft);
list_for_each_entry_safe(obj, nobj, &table->objs, list)
obj_free(obj);
+ /* this is implicitly releasing objs in the hashtable cache */
+ list_for_each_entry_safe(obj, nobj, &table->cache_obj, cache_list)
+ obj_free(obj);
+
handle_free(&table->handle);
scope_release(&table->scope);
xfree(table->cache_chain_ht);
xfree(table->cache_set_ht);
+ xfree(table->cache_obj_ht);
xfree(table);
}
@@ -1264,7 +1275,7 @@ static void table_print(const struct table *table, struct output_ctx *octx)
if (table->comment)
nft_print(octx, "\tcomment \"%s\"\n", table->comment);
- list_for_each_entry(obj, &table->objs, list) {
+ list_for_each_entry(obj, &table->cache_obj, cache_list) {
nft_print(octx, "%s", delim);
obj_print(obj, octx);
delim = "\n";
@@ -1737,24 +1748,6 @@ void obj_free(struct obj *obj)
xfree(obj);
}
-void obj_add_hash(struct obj *obj, struct table *table)
-{
- list_add_tail(&obj->list, &table->objs);
-}
-
-struct obj *obj_lookup(const struct table *table, const char *name,
- uint32_t type)
-{
- struct obj *obj;
-
- list_for_each_entry(obj, &table->objs, list) {
- if (!strcmp(obj->handle.obj.name, name) &&
- obj->type == type)
- return obj;
- }
- return NULL;
-}
-
struct obj *obj_lookup_fuzzy(const char *obj_name,
const struct nft_cache *cache,
const struct table **t)
@@ -1766,7 +1759,7 @@ struct obj *obj_lookup_fuzzy(const char *obj_name,
string_misspell_init(&st);
list_for_each_entry(table, &cache->list, list) {
- list_for_each_entry(obj, &table->objs, list) {
+ list_for_each_entry(obj, &table->cache_obj, cache_list) {
if (!strcmp(obj->handle.obj.name, obj_name)) {
*t = table;
return obj;
@@ -2111,14 +2104,14 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
strcmp(cmd->handle.table.name, table->handle.table.name))
continue;
- if (list_empty(&table->objs))
+ if (list_empty(&table->cache_obj))
continue;
nft_print(&ctx->nft->output, "table %s %s {\n",
family2str(table->handle.family),
table->handle.table.name);
- list_for_each_entry(obj, &table->objs, list) {
+ list_for_each_entry(obj, &table->cache_obj, cache_list) {
if (obj->type != type ||
(cmd->handle.obj.name != NULL &&
strcmp(cmd->handle.obj.name, obj->handle.obj.name)))
@@ -2574,8 +2567,10 @@ static int do_command_reset(struct netlink_ctx *ctx, struct cmd *cmd)
ret = netlink_reset_objs(ctx, cmd, type, dump);
list_for_each_entry_safe(obj, next, &ctx->list, list) {
table = table_lookup(&obj->handle, &ctx->nft->cache);
- if (!obj_lookup(table, obj->handle.obj.name, obj->type))
- list_move(&obj->list, &table->objs);
+ if (!obj_cache_find(table, obj->handle.obj.name, obj->type)) {
+ list_del(&obj->list);
+ obj_cache_add(obj, table);
+ }
}
if (ret < 0)
return ret;
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 02/10] cache: add hashtable cache for flowtable
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 01/10] cache: add hashtable cache for object Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 03/10] cache: add set_cache_del() and use it Pablo Neira Ayuso
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Add flowtable hashtable cache.
Actually I am not expecting that many flowtables to benefit from the
hashtable to be created by streamline this code with tables, chains,
sets and policy objects.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cache.h | 4 +++
include/netlink.h | 2 ++
include/rule.h | 6 ++--
src/cache.c | 90 +++++++++++++++++++++++++++++++++++++++++++++--
src/evaluate.c | 2 +-
src/json.c | 6 ++--
src/netlink.c | 2 +-
src/rule.c | 32 +++++++----------
8 files changed, 116 insertions(+), 28 deletions(-)
diff --git a/include/cache.h b/include/cache.h
index b0458dc9c284..6fa21742503c 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -67,4 +67,8 @@ void obj_cache_del(struct obj *obj);
struct obj *obj_cache_find(const struct table *table, const char *name,
uint32_t obj_type);
+struct flowtable;
+void ft_cache_add(struct flowtable *ft, struct table *table);
+struct flowtable *ft_cache_find(const struct table *table, const char *name);
+
#endif /* _NFT_CACHE_H_ */
diff --git a/include/netlink.h b/include/netlink.h
index f93c5322100f..a7c524ca9674 100644
--- a/include/netlink.h
+++ b/include/netlink.h
@@ -163,6 +163,8 @@ extern struct obj *netlink_delinearize_obj(struct netlink_ctx *ctx,
extern int netlink_list_flowtables(struct netlink_ctx *ctx,
const struct handle *h);
+extern struct flowtable *netlink_delinearize_flowtable(struct netlink_ctx *ctx,
+ struct nftnl_flowtable *nlo);
extern void netlink_dump_chain(const struct nftnl_chain *nlc,
struct netlink_ctx *ctx);
diff --git a/include/rule.h b/include/rule.h
index 226171a8def7..44e057ab341f 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -164,6 +164,8 @@ struct table {
struct list_head *cache_obj_ht;
struct list_head cache_obj;
struct list_head objs;
+ struct list_head *cache_ft_ht;
+ struct list_head cache_ft;
struct list_head flowtables;
struct list_head chain_bindings;
enum table_flags flags;
@@ -522,6 +524,8 @@ uint32_t obj_type_to_cmd(uint32_t type);
struct flowtable {
struct list_head list;
+ struct list_head cache_hlist;
+ struct list_head cache_list;
struct handle handle;
struct scope scope;
struct location location;
@@ -537,8 +541,6 @@ struct flowtable {
extern struct flowtable *flowtable_alloc(const struct location *loc);
extern struct flowtable *flowtable_get(struct flowtable *flowtable);
extern void flowtable_free(struct flowtable *flowtable);
-extern void flowtable_add_hash(struct flowtable *flowtable, struct table *table);
-extern struct flowtable *flowtable_lookup(const struct table *table, const char *name);
extern struct flowtable *flowtable_lookup_fuzzy(const char *ft_name,
const struct nft_cache *cache,
const struct table **table);
diff --git a/src/cache.c b/src/cache.c
index baf8dc12e5b6..95b5c46306c3 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -426,6 +426,84 @@ struct obj *obj_cache_find(const struct table *table, const char *name,
return NULL;
}
+struct ft_cache_dump_ctx {
+ struct netlink_ctx *nlctx;
+ struct table *table;
+};
+
+static int ft_cache_cb(struct nftnl_flowtable *nlf, void *arg)
+{
+ struct ft_cache_dump_ctx *ctx = arg;
+ const char *ft_name;
+ struct flowtable *ft;
+ uint32_t hash;
+
+ ft = netlink_delinearize_flowtable(ctx->nlctx, nlf);
+ if (!ft)
+ return -1;
+
+ ft_name = nftnl_flowtable_get_str(nlf, NFTNL_FLOWTABLE_NAME);
+ hash = djb_hash(ft_name) % NFT_CACHE_HSIZE;
+ list_add_tail(&ft->cache_hlist, &ctx->table->cache_ft_ht[hash]);
+ list_add_tail(&ft->cache_list, &ctx->table->cache_ft);
+
+ return 0;
+}
+
+static int ft_cache_init(struct netlink_ctx *ctx, struct table *table,
+ struct nftnl_flowtable_list *ft_list)
+{
+ struct ft_cache_dump_ctx dump_ctx = {
+ .nlctx = ctx,
+ .table = table,
+ };
+ nftnl_flowtable_list_foreach(ft_list, ft_cache_cb, &dump_ctx);
+
+ return 0;
+}
+
+static struct nftnl_flowtable_list *ft_cache_dump(struct netlink_ctx *ctx,
+ const struct table *table,
+ int *err)
+{
+ struct nftnl_flowtable_list *ft_list;
+
+ ft_list = mnl_nft_flowtable_dump(ctx, table->handle.family,
+ table->handle.table.name);
+ if (!ft_list) {
+ if (errno == EINTR) {
+ *err = -1;
+ return NULL;
+ }
+ *err = 0;
+ return NULL;
+ }
+
+ return ft_list;
+}
+
+void ft_cache_add(struct flowtable *ft, struct table *table)
+{
+ uint32_t hash;
+
+ hash = djb_hash(ft->handle.flowtable.name) % NFT_CACHE_HSIZE;
+ list_add_tail(&ft->cache_hlist, &table->cache_ft_ht[hash]);
+ list_add_tail(&ft->cache_list, &table->cache_ft);
+}
+
+struct flowtable *ft_cache_find(const struct table *table, const char *name)
+{
+ struct flowtable *ft;
+ uint32_t hash;
+
+ hash = djb_hash(name) % NFT_CACHE_HSIZE;
+ list_for_each_entry(ft, &table->cache_ft_ht[hash], cache_hlist) {
+ if (!strcmp(ft->handle.flowtable.name, name))
+ return ft;
+ }
+
+ return NULL;
+}
static int cache_init_tables(struct netlink_ctx *ctx, struct handle *h,
struct nft_cache *cache)
@@ -443,6 +521,7 @@ static int cache_init_tables(struct netlink_ctx *ctx, struct handle *h,
static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
{
+ struct nftnl_flowtable_list *ft_list = NULL;
struct nftnl_chain_list *chain_list = NULL;
struct nftnl_set_list *set_list = NULL;
struct nftnl_obj_list *obj_list;
@@ -492,12 +571,19 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
}
}
if (flags & NFT_CACHE_FLOWTABLE_BIT) {
- ret = netlink_list_flowtables(ctx, &table->handle);
+ ft_list = ft_cache_dump(ctx, table, &ret);
+ if (!ft_list) {
+ ret = -1;
+ goto cache_fails;
+ }
+ ret = ft_cache_init(ctx, table, ft_list);
+
+ nftnl_flowtable_list_free(ft_list);
+
if (ret < 0) {
ret = -1;
goto cache_fails;
}
- list_splice_tail_init(&ctx->list, &table->flowtables);
}
if (flags & NFT_CACHE_OBJECT_BIT) {
obj_list = obj_cache_dump(ctx, table, &ret);
diff --git a/src/evaluate.c b/src/evaluate.c
index d33a152c3de4..a516a01ffc30 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -4452,7 +4452,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
if (table == NULL)
return table_not_found(ctx);
- ft = flowtable_lookup(table, cmd->handle.flowtable.name);
+ ft = ft_cache_find(table, cmd->handle.flowtable.name);
if (ft == NULL)
return flowtable_not_found(ctx, &ctx->cmd->handle.flowtable.location,
ctx->cmd->handle.flowtable.name);
diff --git a/src/json.c b/src/json.c
index bf151e927661..29923092d12c 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1580,7 +1580,7 @@ static json_t *table_print_json_full(struct netlink_ctx *ctx,
tmp = set_print_json(&ctx->nft->output, set);
json_array_append_new(root, tmp);
}
- list_for_each_entry(flowtable, &table->flowtables, list) {
+ list_for_each_entry(flowtable, &table->cache_ft, cache_list) {
tmp = flowtable_print_json(flowtable);
json_array_append_new(root, tmp);
}
@@ -1759,7 +1759,7 @@ static json_t *do_list_flowtable_json(struct netlink_ctx *ctx,
json_t *root = json_array();
struct flowtable *ft;
- ft = flowtable_lookup(table, cmd->handle.flowtable.name);
+ ft = ft_cache_find(table, cmd->handle.flowtable.name);
if (ft == NULL)
return json_null();
@@ -1779,7 +1779,7 @@ static json_t *do_list_flowtables_json(struct netlink_ctx *ctx, struct cmd *cmd)
cmd->handle.family != table->handle.family)
continue;
- list_for_each_entry(flowtable, &table->flowtables, list) {
+ list_for_each_entry(flowtable, &table->cache_ft, cache_list) {
tmp = flowtable_print_json(flowtable);
json_array_append_new(root, tmp);
}
diff --git a/src/netlink.c b/src/netlink.c
index 2286a6ffabf8..5b2ad676f3e5 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1534,7 +1534,7 @@ int netlink_reset_objs(struct netlink_ctx *ctx, const struct cmd *cmd,
return err;
}
-static struct flowtable *
+struct flowtable *
netlink_delinearize_flowtable(struct netlink_ctx *ctx,
struct nftnl_flowtable *nlo)
{
diff --git a/src/rule.c b/src/rule.c
index b78d4e7f9cd3..414e53e7d2f6 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -1112,6 +1112,7 @@ struct table *table_alloc(void)
init_list_head(&table->objs);
init_list_head(&table->cache_obj);
init_list_head(&table->flowtables);
+ init_list_head(&table->cache_ft);
init_list_head(&table->chain_bindings);
init_list_head(&table->scope.symbols);
table->refcnt = 1;
@@ -1131,6 +1132,11 @@ struct table *table_alloc(void)
for (i = 0; i < NFT_CACHE_HSIZE; i++)
init_list_head(&table->cache_obj_ht[i]);
+ table->cache_ft_ht =
+ xmalloc(sizeof(struct list_head) * NFT_CACHE_HSIZE);
+ for (i = 0; i < NFT_CACHE_HSIZE; i++)
+ init_list_head(&table->cache_ft_ht[i]);
+
return table;
}
@@ -1159,6 +1165,9 @@ void table_free(struct table *table)
set_free(set);
list_for_each_entry_safe(ft, nft, &table->flowtables, list)
flowtable_free(ft);
+ /* this is implicitly releasing flowtables in the hashtable cache */
+ list_for_each_entry_safe(ft, nft, &table->cache_ft, cache_list)
+ flowtable_free(ft);
list_for_each_entry_safe(obj, nobj, &table->objs, list)
obj_free(obj);
/* this is implicitly releasing objs in the hashtable cache */
@@ -1170,6 +1179,7 @@ void table_free(struct table *table)
xfree(table->cache_chain_ht);
xfree(table->cache_set_ht);
xfree(table->cache_obj_ht);
+ xfree(table->cache_ft_ht);
xfree(table);
}
@@ -1287,7 +1297,7 @@ static void table_print(const struct table *table, struct output_ctx *octx)
set_print(set, octx);
delim = "\n";
}
- list_for_each_entry(flowtable, &table->flowtables, list) {
+ list_for_each_entry(flowtable, &table->cache_ft, cache_list) {
nft_print(octx, "%s", delim);
flowtable_print(flowtable, octx);
delim = "\n";
@@ -2161,11 +2171,6 @@ void flowtable_free(struct flowtable *flowtable)
xfree(flowtable);
}
-void flowtable_add_hash(struct flowtable *flowtable, struct table *table)
-{
- list_add_tail(&flowtable->list, &table->flowtables);
-}
-
static void flowtable_print_declaration(const struct flowtable *flowtable,
struct print_fmt_options *opts,
struct output_ctx *octx)
@@ -2231,17 +2236,6 @@ void flowtable_print(const struct flowtable *s, struct output_ctx *octx)
do_flowtable_print(s, &opts, octx);
}
-struct flowtable *flowtable_lookup(const struct table *table, const char *name)
-{
- struct flowtable *ft;
-
- list_for_each_entry(ft, &table->flowtables, list) {
- if (!strcmp(ft->handle.flowtable.name, name))
- return ft;
- }
- return NULL;
-}
-
struct flowtable *flowtable_lookup_fuzzy(const char *ft_name,
const struct nft_cache *cache,
const struct table **t)
@@ -2271,7 +2265,7 @@ static int do_list_flowtable(struct netlink_ctx *ctx, struct cmd *cmd,
{
struct flowtable *ft;
- ft = flowtable_lookup(table, cmd->handle.flowtable.name);
+ ft = ft_cache_find(table, cmd->handle.flowtable.name);
if (ft == NULL)
return -1;
@@ -2304,7 +2298,7 @@ static int do_list_flowtables(struct netlink_ctx *ctx, struct cmd *cmd)
family2str(table->handle.family),
table->handle.table.name);
- list_for_each_entry(flowtable, &table->flowtables, list) {
+ list_for_each_entry(flowtable, &table->cache_ft, cache_list) {
flowtable_print_declaration(flowtable, &opts, &ctx->nft->output);
nft_print(&ctx->nft->output, "%s}%s", opts.tab, opts.nl);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 03/10] cache: add set_cache_del() and use it
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 01/10] cache: add hashtable cache for object Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 02/10] cache: add hashtable cache for flowtable Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 04/10] evaluate: add set to the cache Pablo Neira Ayuso
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Update set_cache_del() from the monitor path to remove sets
in the cache.
Fixes: df48e56e987f ("cache: add hashtable cache for sets")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cache.h | 1 +
src/cache.c | 6 ++++++
src/monitor.c | 2 +-
3 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/cache.h b/include/cache.h
index 6fa21742503c..d3be4c8a8693 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -60,6 +60,7 @@ void chain_cache_add(struct chain *chain, struct table *table);
struct chain *chain_cache_find(const struct table *table,
const struct handle *handle);
void set_cache_add(struct set *set, struct table *table);
+void set_cache_del(struct set *set);
struct set *set_cache_find(const struct table *table, const char *name);
void obj_cache_add(struct obj *obj, struct table *table);
diff --git a/src/cache.c b/src/cache.c
index 95b5c46306c3..73c96a17704a 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -324,6 +324,12 @@ void set_cache_add(struct set *set, struct table *table)
list_add_tail(&set->cache_list, &table->cache_set);
}
+void set_cache_del(struct set *set)
+{
+ list_del(&set->cache_hlist);
+ list_del(&set->cache_list);
+}
+
struct set *set_cache_find(const struct table *table, const char *name)
{
struct set *set;
diff --git a/src/monitor.c b/src/monitor.c
index 1f0f8a361fbd..eb887d9344fa 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -687,7 +687,7 @@ out:
static void netlink_events_cache_delset_cb(struct set *s,
void *data)
{
- list_del(&s->list);
+ set_cache_del(s);
set_free(s);
}
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 04/10] evaluate: add set to the cache
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (2 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 03/10] cache: add set_cache_del() and use it Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 05/10] evaluate: add flowtable " Pablo Neira Ayuso
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
If the cache does not contain the set that is defined in this batch, add
it to the cache. This allows for references to this new set in the same
batch.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/evaluate.c b/src/evaluate.c
index a516a01ffc30..d0dfbabdf538 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -3718,6 +3718,10 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
if (table == NULL)
return table_not_found(ctx);
+ if (!(set->flags & NFT_SET_ANONYMOUS) &&
+ !set_cache_find(table, set->handle.set.name))
+ set_cache_add(set_get(set), table);
+
if (!(set->flags & NFT_SET_INTERVAL) && set->automerge)
return set_error(ctx, set, "auto-merge only works with interval sets");
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 05/10] evaluate: add flowtable to the cache
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (3 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 04/10] evaluate: add set to the cache Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 06/10] cache: missing table cache for several policy objects Pablo Neira Ayuso
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
If the cache does not contain this flowtable that is defined in this
batch, then add it to the cache. This allows for references to this new
flowtable in the same batch.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 3 +++
src/rule.c | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index d0dfbabdf538..7b2d01c5dee1 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -3925,6 +3925,9 @@ static int flowtable_evaluate(struct eval_ctx *ctx, struct flowtable *ft)
if (table == NULL)
return table_not_found(ctx);
+ if (ft_cache_find(table, ft->handle.flowtable.name) == NULL)
+ ft_cache_add(flowtable_get(ft), table);
+
if (ft->hook.name) {
ft->hook.num = str2hooknum(NFPROTO_NETDEV, ft->hook.name);
if (ft->hook.num == NF_INET_NUMHOOKS)
diff --git a/src/rule.c b/src/rule.c
index 414e53e7d2f6..a6909fc75060 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -2247,7 +2247,7 @@ struct flowtable *flowtable_lookup_fuzzy(const char *ft_name,
string_misspell_init(&st);
list_for_each_entry(table, &cache->list, list) {
- list_for_each_entry(ft, &table->flowtables, list) {
+ list_for_each_entry(ft, &table->cache_ft, cache_list) {
if (!strcmp(ft->handle.flowtable.name, ft_name)) {
*t = table;
return ft;
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 06/10] cache: missing table cache for several policy objects
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (4 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 05/10] evaluate: add flowtable " Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 07/10] evaluate: add object to the cache Pablo Neira Ayuso
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Populate the cache with tables for several policy objects types.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/cache.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/cache.c b/src/cache.c
index 73c96a17704a..8590e14cfa33 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -26,6 +26,10 @@ static unsigned int evaluate_cache_add(struct cmd *cmd, unsigned int flags)
case CMD_OBJ_QUOTA:
case CMD_OBJ_LIMIT:
case CMD_OBJ_SECMARK:
+ case CMD_OBJ_CT_HELPER:
+ case CMD_OBJ_CT_TIMEOUT:
+ case CMD_OBJ_CT_EXPECT:
+ case CMD_OBJ_SYNPROXY:
case CMD_OBJ_FLOWTABLE:
flags |= NFT_CACHE_TABLE;
break;
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 07/10] evaluate: add object to the cache
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (5 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 06/10] cache: missing table cache for several policy objects Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 08/10] cache: move struct nft_cache declaration to cache.h Pablo Neira Ayuso
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
If the cache does not contain this object that is defined in this batch,
add it to the cache. This allows for references to this new object in
the same batch.
This patch also adds missing handle_merge() to set the object name,
otherwise object name is NULL and obj_cache_find() crashes.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/src/evaluate.c b/src/evaluate.c
index 7b2d01c5dee1..72cf756bbb5c 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -4210,6 +4210,15 @@ static int ct_timeout_evaluate(struct eval_ctx *ctx, struct obj *obj)
static int obj_evaluate(struct eval_ctx *ctx, struct obj *obj)
{
+ struct table *table;
+
+ table = table_lookup_global(ctx);
+ if (table == NULL)
+ return table_not_found(ctx);
+
+ if (obj_cache_find(table, obj->handle.obj.name, obj->type) == NULL)
+ obj_cache_add(obj_get(obj), table);
+
switch (obj->type) {
case NFT_OBJECT_CT_TIMEOUT:
return ct_timeout_evaluate(ctx, obj);
@@ -4296,6 +4305,7 @@ static int cmd_evaluate_add(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_SECMARK:
case CMD_OBJ_CT_EXPECT:
case CMD_OBJ_SYNPROXY:
+ handle_merge(&cmd->object->handle, &cmd->handle);
return obj_evaluate(ctx, cmd->object);
default:
BUG("invalid command object type %u\n", cmd->obj);
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 08/10] cache: move struct nft_cache declaration to cache.h
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (6 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 07/10] evaluate: add object to the cache Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 09/10] cache: add hashtable cache for table Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 10/10] evaluate: remove table_lookup_global() Pablo Neira Ayuso
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Move struct nft_cache declaration to include/cache.h.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cache.h | 9 +++++++++
include/nftables.h | 8 +-------
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/include/cache.h b/include/cache.h
index d3be4c8a8693..cab8a6bcca05 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -1,6 +1,15 @@
#ifndef _NFT_CACHE_H_
#define _NFT_CACHE_H_
+#include <string.h>
+
+struct nft_cache {
+ uint32_t genid;
+ struct list_head list;
+ uint32_t seqnum;
+ uint32_t flags;
+};
+
enum cache_level_bits {
NFT_CACHE_TABLE_BIT = (1 << 0),
NFT_CACHE_CHAIN_BIT = (1 << 1),
diff --git a/include/nftables.h b/include/nftables.h
index 9095ff3d0b79..f239fcf0e1f4 100644
--- a/include/nftables.h
+++ b/include/nftables.h
@@ -5,6 +5,7 @@
#include <stdarg.h>
#include <limits.h>
#include <utils.h>
+#include <cache.h>
#include <nftables/libnftables.h>
struct cookie {
@@ -95,13 +96,6 @@ static inline bool nft_output_terse(const struct output_ctx *octx)
return octx->flags & NFT_CTX_OUTPUT_TERSE;
}
-struct nft_cache {
- uint32_t genid;
- struct list_head list;
- uint32_t seqnum;
- uint32_t flags;
-};
-
struct mnl_socket;
struct parser_state;
struct scope;
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 09/10] cache: add hashtable cache for table
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (7 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 08/10] cache: move struct nft_cache declaration to cache.h Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 10/10] evaluate: remove table_lookup_global() Pablo Neira Ayuso
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
Add a hashtable for fast table lookups.
Tables that reside in the cache use the table->cache_hlist and
table->cache_list heads.
Table that are created from command line / ruleset are also added
to the cache.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
include/cache.h | 8 ++++++-
include/rule.h | 5 ++--
src/cache.c | 43 +++++++++++++++++++++++++++++++----
src/evaluate.c | 40 ++++++++++++++++----------------
src/json.c | 14 ++++++------
src/libnftables.c | 8 +++++++
src/monitor.c | 12 +++++-----
src/netlink.c | 2 +-
src/netlink_delinearize.c | 4 ++--
src/rule.c | 48 ++++++++++++---------------------------
10 files changed, 107 insertions(+), 77 deletions(-)
diff --git a/include/cache.h b/include/cache.h
index cab8a6bcca05..de27697072a1 100644
--- a/include/cache.h
+++ b/include/cache.h
@@ -5,7 +5,8 @@
struct nft_cache {
uint32_t genid;
- struct list_head list;
+ struct list_head *ht;
+ struct list_head list;
uint32_t seqnum;
uint32_t flags;
};
@@ -65,6 +66,11 @@ int cache_init(struct netlink_ctx *ctx, unsigned int flags);
int cache_update(struct nft_ctx *nft, unsigned int flags, struct list_head *msgs);
void cache_release(struct nft_cache *cache);
+void table_cache_add(struct table *table, struct nft_cache *cache);
+void table_cache_del(struct table *table);
+struct table *table_cache_find(const struct handle *h,
+ const struct nft_cache *cache);
+
void chain_cache_add(struct chain *chain, struct table *table);
struct chain *chain_cache_find(const struct table *table,
const struct handle *handle);
diff --git a/include/rule.h b/include/rule.h
index 44e057ab341f..a39788284bc1 100644
--- a/include/rule.h
+++ b/include/rule.h
@@ -152,6 +152,8 @@ const char *table_flag_name(uint32_t flag);
*/
struct table {
struct list_head list;
+ struct list_head cache_hlist;
+ struct list_head cache_list;
struct handle handle;
struct location location;
struct scope scope;
@@ -177,9 +179,6 @@ struct table {
extern struct table *table_alloc(void);
extern struct table *table_get(struct table *table);
extern void table_free(struct table *table);
-extern void table_add_hash(struct table *table, struct nft_cache *cache);
-extern struct table *table_lookup(const struct handle *h,
- const struct nft_cache *cache);
extern struct table *table_lookup_fuzzy(const struct handle *h,
const struct nft_cache *cache);
diff --git a/src/cache.c b/src/cache.c
index 8590e14cfa33..8bb9688e8eb4 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -173,6 +173,37 @@ unsigned int cache_evaluate(struct nft_ctx *nft, struct list_head *cmds)
return flags;
}
+void table_cache_add(struct table *table, struct nft_cache *cache)
+{
+ uint32_t hash;
+
+ hash = djb_hash(table->handle.table.name) % NFT_CACHE_HSIZE;
+ list_add_tail(&table->cache_hlist, &cache->ht[hash]);
+ list_add_tail(&table->cache_list, &cache->list);
+}
+
+void table_cache_del(struct table *table)
+{
+ list_del(&table->cache_hlist);
+ list_del(&table->cache_list);
+}
+
+struct table *table_cache_find(const struct handle *handle,
+ const struct nft_cache *cache)
+{
+ struct table *table;
+ uint32_t hash;
+
+ hash = djb_hash(handle->table.name) % NFT_CACHE_HSIZE;
+ list_for_each_entry(table, &cache->ht[hash], cache_hlist) {
+ if (table->handle.family == handle->family &&
+ !strcmp(table->handle.table.name, handle->table.name))
+ return table;
+ }
+
+ return NULL;
+}
+
struct chain_cache_dump_ctx {
struct netlink_ctx *nlctx;
struct table *table;
@@ -518,13 +549,17 @@ struct flowtable *ft_cache_find(const struct table *table, const char *name)
static int cache_init_tables(struct netlink_ctx *ctx, struct handle *h,
struct nft_cache *cache)
{
+ struct table *table, *next;
int ret;
ret = netlink_list_tables(ctx, h);
if (ret < 0)
return -1;
- list_splice_tail_init(&ctx->list, &cache->list);
+ list_for_each_entry_safe(table, next, &ctx->list, list) {
+ list_del(&table->list);
+ table_cache_add(table, cache);
+ }
return 0;
}
@@ -547,7 +582,7 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
return -1;
}
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (flags & NFT_CACHE_SET_BIT) {
set_list = set_cache_dump(ctx, table, &ret);
if (!set_list) {
@@ -733,8 +768,8 @@ static void __cache_flush(struct list_head *table_list)
{
struct table *table, *next;
- list_for_each_entry_safe(table, next, table_list, list) {
- list_del(&table->list);
+ list_for_each_entry_safe(table, next, table_list, cache_list) {
+ table_cache_del(table);
table_free(table);
}
}
diff --git a/src/evaluate.c b/src/evaluate.c
index 72cf756bbb5c..c33e7268d655 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -173,7 +173,7 @@ static struct table *table_lookup_global(struct eval_ctx *ctx)
if (ctx->table != NULL)
return ctx->table;
- table = table_lookup(&ctx->cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return NULL;
@@ -3969,7 +3969,7 @@ static int rule_cache_update(struct eval_ctx *ctx, enum cmd_ops op)
struct table *table;
struct chain *chain;
- table = table_lookup(&rule->handle, &ctx->nft->cache);
+ table = table_cache_find(&rule->handle, &ctx->nft->cache);
if (!table)
return table_not_found(ctx);
@@ -4238,13 +4238,13 @@ static int table_evaluate(struct eval_ctx *ctx, struct table *table)
struct set *set;
struct obj *obj;
- if (table_lookup(&ctx->cmd->handle, &ctx->nft->cache) == NULL) {
+ if (table_cache_find(&ctx->cmd->handle, &ctx->nft->cache) == NULL) {
if (table == NULL) {
table = table_alloc();
handle_merge(&table->handle, &ctx->cmd->handle);
- table_add_hash(table, &ctx->nft->cache);
+ table_cache_add(table, &ctx->nft->cache);
} else {
- table_add_hash(table_get(table), &ctx->nft->cache);
+ table_cache_add(table_get(table), &ctx->nft->cache);
}
}
@@ -4316,11 +4316,11 @@ static void table_del_cache(struct eval_ctx *ctx, struct cmd *cmd)
{
struct table *table;
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (!table)
return;
- list_del(&table->list);
+ table_cache_del(table);
table_free(table);
}
@@ -4386,7 +4386,7 @@ static int cmd_evaluate_list_obj(struct eval_ctx *ctx, const struct cmd *cmd,
if (obj_type == NFT_OBJECT_UNSPEC)
obj_type = NFT_OBJECT_COUNTER;
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4408,13 +4408,13 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
if (cmd->handle.table.name == NULL)
return 0;
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
return 0;
case CMD_OBJ_SET:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4428,7 +4428,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_METER:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4442,7 +4442,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_MAP:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4456,7 +4456,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_CHAIN:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4465,7 +4465,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_FLOWTABLE:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4501,7 +4501,7 @@ static int cmd_evaluate_list(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_SYNPROXYS:
if (cmd->handle.table.name == NULL)
return 0;
- if (table_lookup(&cmd->handle, &ctx->nft->cache) == NULL)
+ if (table_cache_find(&cmd->handle, &ctx->nft->cache) == NULL)
return table_not_found(ctx);
return 0;
@@ -4524,7 +4524,7 @@ static int cmd_evaluate_reset(struct eval_ctx *ctx, struct cmd *cmd)
case CMD_OBJ_QUOTAS:
if (cmd->handle.table.name == NULL)
return 0;
- if (table_lookup(&cmd->handle, &ctx->nft->cache) == NULL)
+ if (table_cache_find(&cmd->handle, &ctx->nft->cache) == NULL)
return table_not_found(ctx);
return 0;
@@ -4557,7 +4557,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
/* Chains don't hold sets */
break;
case CMD_OBJ_SET:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4573,7 +4573,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_MAP:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4589,7 +4589,7 @@ static int cmd_evaluate_flush(struct eval_ctx *ctx, struct cmd *cmd)
return 0;
case CMD_OBJ_METER:
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4616,7 +4616,7 @@ static int cmd_evaluate_rename(struct eval_ctx *ctx, struct cmd *cmd)
switch (cmd->obj) {
case CMD_OBJ_CHAIN:
- table = table_lookup(&ctx->cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
diff --git a/src/json.c b/src/json.c
index 29923092d12c..744efc49d04e 100644
--- a/src/json.c
+++ b/src/json.c
@@ -1603,7 +1603,7 @@ static json_t *do_list_ruleset_json(struct netlink_ctx *ctx, struct cmd *cmd)
json_t *root = json_array(), *tmp;
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (family != NFPROTO_UNSPEC &&
table->handle.family != family)
continue;
@@ -1622,7 +1622,7 @@ static json_t *do_list_tables_json(struct netlink_ctx *ctx, struct cmd *cmd)
json_t *root = json_array();
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (family != NFPROTO_UNSPEC &&
table->handle.family != family)
continue;
@@ -1669,7 +1669,7 @@ static json_t *do_list_chains_json(struct netlink_ctx *ctx, struct cmd *cmd)
struct table *table;
struct chain *chain;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -1702,7 +1702,7 @@ static json_t *do_list_sets_json(struct netlink_ctx *ctx, struct cmd *cmd)
struct table *table;
struct set *set;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -1731,7 +1731,7 @@ static json_t *do_list_obj_json(struct netlink_ctx *ctx,
struct table *table;
struct obj *obj;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -1774,7 +1774,7 @@ static json_t *do_list_flowtables_json(struct netlink_ctx *ctx, struct cmd *cmd)
struct flowtable *flowtable;
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -1802,7 +1802,7 @@ int do_command_list_json(struct netlink_ctx *ctx, struct cmd *cmd)
json_t *root;
if (cmd->handle.table.name)
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
switch (cmd->obj) {
case CMD_OBJ_TABLE:
diff --git a/src/libnftables.c b/src/libnftables.c
index 044365914747..8c1e4c34f682 100644
--- a/src/libnftables.c
+++ b/src/libnftables.c
@@ -96,15 +96,23 @@ out:
static void nft_init(struct nft_ctx *ctx)
{
+ int i;
+
mark_table_init(ctx);
realm_table_rt_init(ctx);
devgroup_table_init(ctx);
ct_label_table_init(ctx);
expr_handler_init();
+
+ init_list_head(&ctx->cache.list);
+ ctx->cache.ht = xmalloc(sizeof(struct list_head) * NFT_CACHE_HSIZE);
+ for (i = 0; i < NFT_CACHE_HSIZE; i++)
+ init_list_head(&ctx->cache.ht[i]);
}
static void nft_exit(struct nft_ctx *ctx)
{
+ xfree(ctx->cache.ht);
expr_handler_exit();
ct_label_table_exit(ctx);
realm_table_rt_exit(ctx);
diff --git a/src/monitor.c b/src/monitor.c
index eb887d9344fa..5745633610d2 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -575,7 +575,7 @@ static void netlink_events_cache_addtable(struct netlink_mon_handler *monh,
t = netlink_delinearize_table(monh->ctx, nlt);
nftnl_table_free(nlt);
- table_add_hash(t, &monh->ctx->nft->cache);
+ table_cache_add(t, &monh->ctx->nft->cache);
}
static void netlink_events_cache_deltable(struct netlink_mon_handler *monh,
@@ -589,11 +589,11 @@ static void netlink_events_cache_deltable(struct netlink_mon_handler *monh,
h.family = nftnl_table_get_u32(nlt, NFTNL_TABLE_FAMILY);
h.table.name = nftnl_table_get_str(nlt, NFTNL_TABLE_NAME);
- t = table_lookup(&h, &monh->ctx->nft->cache);
+ t = table_cache_find(&h, &monh->ctx->nft->cache);
if (t == NULL)
goto out;
- list_del(&t->list);
+ table_cache_del(t);
table_free(t);
out:
nftnl_table_free(nlt);
@@ -619,7 +619,7 @@ static void netlink_events_cache_addset(struct netlink_mon_handler *monh,
goto out;
s->init = set_expr_alloc(monh->loc, s);
- t = table_lookup(&s->handle, &monh->ctx->nft->cache);
+ t = table_cache_find(&s->handle, &monh->ctx->nft->cache);
if (t == NULL) {
fprintf(stderr, "W: Unable to cache set: table not found.\n");
set_free(s);
@@ -720,7 +720,7 @@ static void netlink_events_cache_addobj(struct netlink_mon_handler *monh,
if (obj == NULL)
goto out;
- t = table_lookup(&obj->handle, &monh->ctx->nft->cache);
+ t = table_cache_find(&obj->handle, &monh->ctx->nft->cache);
if (t == NULL) {
fprintf(stderr, "W: Unable to cache object: table not found.\n");
obj_free(obj);
@@ -750,7 +750,7 @@ static void netlink_events_cache_delobj(struct netlink_mon_handler *monh,
type = nftnl_obj_get_u32(nlo, NFTNL_OBJ_TYPE);
h.handle.id = nftnl_obj_get_u64(nlo, NFTNL_OBJ_HANDLE);
- t = table_lookup(&h, &monh->ctx->nft->cache);
+ t = table_cache_find(&h, &monh->ctx->nft->cache);
if (t == NULL) {
fprintf(stderr, "W: Unable to cache object: table not found.\n");
goto out;
diff --git a/src/netlink.c b/src/netlink.c
index 5b2ad676f3e5..3ed49c10bbee 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -1695,7 +1695,7 @@ static struct rule *trace_lookup_rule(const struct nftnl_trace *nlt,
if (!h.table.name)
return NULL;
- table = table_lookup(&h, cache);
+ table = table_cache_find(&h, cache);
if (!table)
return NULL;
diff --git a/src/netlink_delinearize.c b/src/netlink_delinearize.c
index 710c668a0258..9e282a61708c 100644
--- a/src/netlink_delinearize.c
+++ b/src/netlink_delinearize.c
@@ -1792,7 +1792,7 @@ struct stmt *netlink_parse_set_expr(const struct set *set,
handle_merge(&h, &set->handle);
pctx->rule = rule_alloc(&netlink_location, &h);
- pctx->table = table_lookup(&set->handle, cache);
+ pctx->table = table_cache_find(&set->handle, cache);
assert(pctx->table != NULL);
if (netlink_parse_expr(nle, pctx) < 0)
@@ -2938,7 +2938,7 @@ struct rule *netlink_delinearize_rule(struct netlink_ctx *ctx,
h.position.id = nftnl_rule_get_u64(nlr, NFTNL_RULE_POSITION);
pctx->rule = rule_alloc(&netlink_location, &h);
- pctx->table = table_lookup(&h, &ctx->nft->cache);
+ pctx->table = table_cache_find(&h, &ctx->nft->cache);
assert(pctx->table != NULL);
pctx->rule->comment = nftnl_rule_get_comment(nlr);
diff --git a/src/rule.c b/src/rule.c
index a6909fc75060..106d8c33cf6b 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -211,7 +211,7 @@ struct set *set_lookup_fuzzy(const char *set_name,
string_misspell_init(&st);
- list_for_each_entry(table, &cache->list, list) {
+ list_for_each_entry(table, &cache->list, cache_list) {
list_for_each_entry(set, &table->cache_set, cache_list) {
if (set_is_anonymous(set->flags))
continue;
@@ -236,7 +236,7 @@ struct set *set_lookup_global(uint32_t family, const char *table,
h.family = family;
h.table.name = table;
- t = table_lookup(&h, cache);
+ t = table_cache_find(&h, cache);
if (t == NULL)
return NULL;
@@ -767,7 +767,7 @@ struct chain *chain_lookup_fuzzy(const struct handle *h,
string_misspell_init(&st);
- list_for_each_entry(table, &cache->list, list) {
+ list_for_each_entry(table, &cache->list, cache_list) {
list_for_each_entry(chain, &table->cache_chain, cache_list) {
if (!strcmp(chain->handle.chain.name, h->chain.name)) {
*t = table;
@@ -1189,24 +1189,6 @@ struct table *table_get(struct table *table)
return table;
}
-void table_add_hash(struct table *table, struct nft_cache *cache)
-{
- list_add_tail(&table->list, &cache->list);
-}
-
-struct table *table_lookup(const struct handle *h,
- const struct nft_cache *cache)
-{
- struct table *table;
-
- list_for_each_entry(table, &cache->list, list) {
- if (table->handle.family == h->family &&
- !strcmp(table->handle.table.name, h->table.name))
- return table;
- }
- return NULL;
-}
-
struct table *table_lookup_fuzzy(const struct handle *h,
const struct nft_cache *cache)
{
@@ -1215,7 +1197,7 @@ struct table *table_lookup_fuzzy(const struct handle *h,
string_misspell_init(&st);
- list_for_each_entry(table, &cache->list, list) {
+ list_for_each_entry(table, &cache->list, cache_list) {
if (!strcmp(table->handle.table.name, h->table.name))
return table;
@@ -1703,7 +1685,7 @@ static int do_list_sets(struct netlink_ctx *ctx, struct cmd *cmd)
struct table *table;
struct set *set;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -1768,7 +1750,7 @@ struct obj *obj_lookup_fuzzy(const char *obj_name,
string_misspell_init(&st);
- list_for_each_entry(table, &cache->list, list) {
+ list_for_each_entry(table, &cache->list, cache_list) {
list_for_each_entry(obj, &table->cache_obj, cache_list) {
if (!strcmp(obj->handle.obj.name, obj_name)) {
*t = table;
@@ -2105,7 +2087,7 @@ static int do_list_obj(struct netlink_ctx *ctx, struct cmd *cmd, uint32_t type)
struct table *table;
struct obj *obj;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -2246,7 +2228,7 @@ struct flowtable *flowtable_lookup_fuzzy(const char *ft_name,
string_misspell_init(&st);
- list_for_each_entry(table, &cache->list, list) {
+ list_for_each_entry(table, &cache->list, cache_list) {
list_for_each_entry(ft, &table->cache_ft, cache_list) {
if (!strcmp(ft->handle.flowtable.name, ft_name)) {
*t = table;
@@ -2289,7 +2271,7 @@ static int do_list_flowtables(struct netlink_ctx *ctx, struct cmd *cmd)
struct flowtable *flowtable;
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -2313,7 +2295,7 @@ static int do_list_ruleset(struct netlink_ctx *ctx, struct cmd *cmd)
unsigned int family = cmd->handle.family;
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (family != NFPROTO_UNSPEC &&
table->handle.family != family)
continue;
@@ -2334,7 +2316,7 @@ static int do_list_tables(struct netlink_ctx *ctx, struct cmd *cmd)
{
struct table *table;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -2380,7 +2362,7 @@ static int do_list_chains(struct netlink_ctx *ctx, struct cmd *cmd)
struct table *table;
struct chain *chain;
- list_for_each_entry(table, &ctx->nft->cache.list, list) {
+ list_for_each_entry(table, &ctx->nft->cache.list, cache_list) {
if (cmd->handle.family != NFPROTO_UNSPEC &&
cmd->handle.family != table->handle.family)
continue;
@@ -2433,7 +2415,7 @@ static int do_command_list(struct netlink_ctx *ctx, struct cmd *cmd)
return do_command_list_json(ctx, cmd);
if (cmd->handle.table.name != NULL)
- table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ table = table_cache_find(&cmd->handle, &ctx->nft->cache);
switch (cmd->obj) {
case CMD_OBJ_TABLE:
@@ -2560,7 +2542,7 @@ static int do_command_reset(struct netlink_ctx *ctx, struct cmd *cmd)
ret = netlink_reset_objs(ctx, cmd, type, dump);
list_for_each_entry_safe(obj, next, &ctx->list, list) {
- table = table_lookup(&obj->handle, &ctx->nft->cache);
+ table = table_cache_find(&obj->handle, &ctx->nft->cache);
if (!obj_cache_find(table, obj->handle.obj.name, obj->type)) {
list_del(&obj->list);
obj_cache_add(obj, table);
@@ -2592,7 +2574,7 @@ static int do_command_flush(struct netlink_ctx *ctx, struct cmd *cmd)
static int do_command_rename(struct netlink_ctx *ctx, struct cmd *cmd)
{
- struct table *table = table_lookup(&cmd->handle, &ctx->nft->cache);
+ struct table *table = table_cache_find(&cmd->handle, &ctx->nft->cache);
const struct chain *chain;
switch (cmd->obj) {
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH nft 10/10] evaluate: remove table_lookup_global()
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
` (8 preceding siblings ...)
2021-04-15 13:13 ` [PATCH nft 09/10] cache: add hashtable cache for table Pablo Neira Ayuso
@ 2021-04-15 13:13 ` Pablo Neira Ayuso
9 siblings, 0 replies; 11+ messages in thread
From: Pablo Neira Ayuso @ 2021-04-15 13:13 UTC (permalink / raw)
To: netfilter-devel
No need to check for ctx->table, use the existing table in the cache.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/evaluate.c | 26 ++++++--------------------
1 file changed, 6 insertions(+), 20 deletions(-)
diff --git a/src/evaluate.c b/src/evaluate.c
index c33e7268d655..ca13ad9e25e1 100644
--- a/src/evaluate.c
+++ b/src/evaluate.c
@@ -166,20 +166,6 @@ static int byteorder_conversion(struct eval_ctx *ctx, struct expr **expr,
return 0;
}
-static struct table *table_lookup_global(struct eval_ctx *ctx)
-{
- struct table *table;
-
- if (ctx->table != NULL)
- return ctx->table;
-
- table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
- if (table == NULL)
- return NULL;
-
- return table;
-}
-
static int table_not_found(struct eval_ctx *ctx)
{
struct table *table;
@@ -269,7 +255,7 @@ static int expr_evaluate_symbol(struct eval_ctx *ctx, struct expr **expr)
}
break;
case SYMBOL_SET:
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -3673,7 +3659,7 @@ static int setelem_evaluate(struct eval_ctx *ctx, struct cmd *cmd)
struct table *table;
struct set *set;
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -3714,7 +3700,7 @@ static int set_evaluate(struct eval_ctx *ctx, struct set *set)
struct stmt *stmt;
const char *type;
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -3921,7 +3907,7 @@ static int flowtable_evaluate(struct eval_ctx *ctx, struct flowtable *ft)
{
struct table *table;
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4111,7 +4097,7 @@ static int chain_evaluate(struct eval_ctx *ctx, struct chain *chain)
struct table *table;
struct rule *rule;
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
@@ -4212,7 +4198,7 @@ static int obj_evaluate(struct eval_ctx *ctx, struct obj *obj)
{
struct table *table;
- table = table_lookup_global(ctx);
+ table = table_cache_find(&ctx->cmd->handle, &ctx->nft->cache);
if (table == NULL)
return table_not_found(ctx);
--
2.20.1
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-04-15 13:13 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-04-15 13:13 [PATCH nft 0/10] cache updates Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 01/10] cache: add hashtable cache for object Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 02/10] cache: add hashtable cache for flowtable Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 03/10] cache: add set_cache_del() and use it Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 04/10] evaluate: add set to the cache Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 05/10] evaluate: add flowtable " Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 06/10] cache: missing table cache for several policy objects Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 07/10] evaluate: add object to the cache Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 08/10] cache: move struct nft_cache declaration to cache.h Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 09/10] cache: add hashtable cache for table Pablo Neira Ayuso
2021-04-15 13:13 ` [PATCH nft 10/10] evaluate: remove table_lookup_global() Pablo Neira Ayuso
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).