From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH nft] cache: provide a empty list for flowtables and objects when request fails
Date: Wed, 25 Aug 2021 16:34:28 +0200 [thread overview]
Message-ID: <20210825143428.15622-1-pablo@netfilter.org> (raw)
Old kernels do not support for dumping the flowtable and object lists,
provide an empty list instead to unbreak the cache initialization.
Fixes: 560963c4d41e ("cache: add hashtable cache for flowtable")
Fixes: 45a84088ecbd ("cache: add hashtable cache for object")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/cache.c | 38 ++++++++++++++++++++++----------------
1 file changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/cache.c b/src/cache.c
index 8300ce8e707a..15eb4522eb75 100644
--- a/src/cache.c
+++ b/src/cache.c
@@ -415,8 +415,7 @@ static int obj_cache_init(struct netlink_ctx *ctx, struct table *table,
}
static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
- const struct table *table,
- int *err)
+ const struct table *table)
{
struct nftnl_obj_list *obj_list;
@@ -424,12 +423,15 @@ static struct nftnl_obj_list *obj_cache_dump(struct netlink_ctx *ctx,
table->handle.table.name, NULL,
0, true, false);
if (!obj_list) {
- if (errno == EINTR) {
- *err = -1;
+ if (errno == EINTR)
return NULL;
- }
- *err = 0;
- return NULL;
+
+ /* old kernels do not support this, provide an empty list. */
+ obj_list = nftnl_obj_list_alloc();
+ if (!obj_list)
+ memory_allocation_error();
+
+ return obj_list;
}
return obj_list;
@@ -500,20 +502,22 @@ static int ft_cache_init(struct netlink_ctx *ctx, struct table *table,
}
static struct nftnl_flowtable_list *ft_cache_dump(struct netlink_ctx *ctx,
- const struct table *table,
- int *err)
+ const struct table *table)
{
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;
+ if (errno == EINTR)
return NULL;
- }
- *err = 0;
- return NULL;
+
+ /* old kernels do not support this, provide an empty list. */
+ ft_list = nftnl_flowtable_list_alloc();
+ if (!ft_list)
+ memory_allocation_error();
+
+ return ft_list;
}
return ft_list;
@@ -628,11 +632,12 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
}
}
if (flags & NFT_CACHE_FLOWTABLE_BIT) {
- ft_list = ft_cache_dump(ctx, table, &ret);
+ ft_list = ft_cache_dump(ctx, table);
if (!ft_list) {
ret = -1;
goto cache_fails;
}
+
ret = ft_cache_init(ctx, table, ft_list);
nftnl_flowtable_list_free(ft_list);
@@ -643,11 +648,12 @@ static int cache_init_objects(struct netlink_ctx *ctx, unsigned int flags)
}
}
if (flags & NFT_CACHE_OBJECT_BIT) {
- obj_list = obj_cache_dump(ctx, table, &ret);
+ obj_list = obj_cache_dump(ctx, table);
if (!obj_list) {
ret = -1;
goto cache_fails;
}
+
ret = obj_cache_init(ctx, table, obj_list);
nftnl_obj_list_free(obj_list);
--
2.20.1
reply other threads:[~2021-08-25 14:34 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210825143428.15622-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=netfilter-devel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).