From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Cc: phil@nwl.cc, eric@garver.life
Subject: [PATCH nft] src: add cache_is_complete() and cache_is_updated()
Date: Fri, 24 May 2019 20:46:18 +0200 [thread overview]
Message-ID: <20190524184618.5315-1-pablo@netfilter.org> (raw)
Just a few functions to help clarify cache update logic.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
src/rule.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/rule.c b/src/rule.c
index 17bf5bbbe680..326edb5dd459 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -232,9 +232,14 @@ static int cache_completeness(enum cmd_ops cmd)
return 1;
}
-static bool cache_needs_more(enum cmd_ops old_cmd, enum cmd_ops cmd)
+static bool cache_is_complete(struct nft_cache *cache, enum cmd_ops cmd)
{
- return cache_completeness(old_cmd) < cache_completeness(cmd);
+ return cache_completeness(cache->cmd) >= cache_completeness(cmd);
+}
+
+static bool cache_is_updated(struct nft_cache *cache, uint16_t genid)
+{
+ return genid && genid == cache->genid;
}
int cache_update(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs)
@@ -252,10 +257,10 @@ int cache_update(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs)
replay:
ctx.seqnum = cache->seqnum++;
genid = mnl_genid_get(&ctx);
- if (cache->genid && cache_needs_more(cache->cmd, cmd))
- cache_release(cache);
- if (genid && genid == cache->genid)
+ if (cache_is_complete(cache, cmd) &&
+ cache_is_updated(cache, genid))
return 0;
+
if (cache->genid)
cache_release(cache);
--
2.11.0
next reply other threads:[~2019-05-24 18:46 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-24 18:46 Pablo Neira Ayuso [this message]
2019-05-27 10:01 ` [PATCH nft] src: add cache_is_complete() and cache_is_updated() Phil Sutter
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=20190524184618.5315-1-pablo@netfilter.org \
--to=pablo@netfilter.org \
--cc=eric@garver.life \
--cc=netfilter-devel@vger.kernel.org \
--cc=phil@nwl.cc \
/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