Linux Netfilter development
 help / color / mirror / Atom feed
* [PATCH nft] src: add cache_is_complete() and cache_is_updated()
@ 2019-05-24 18:46 Pablo Neira Ayuso
  2019-05-27 10:01 ` Phil Sutter
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Neira Ayuso @ 2019-05-24 18:46 UTC (permalink / raw)
  To: netfilter-devel; +Cc: phil, eric

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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH nft] src: add cache_is_complete() and cache_is_updated()
  2019-05-24 18:46 [PATCH nft] src: add cache_is_complete() and cache_is_updated() Pablo Neira Ayuso
@ 2019-05-27 10:01 ` Phil Sutter
  0 siblings, 0 replies; 2+ messages in thread
From: Phil Sutter @ 2019-05-27 10:01 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel, eric

On Fri, May 24, 2019 at 08:46:18PM +0200, Pablo Neira Ayuso wrote:
> Just a few functions to help clarify cache update logic.
> 
> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

Acked-by: Phil Sutter <phil@nwl.cc>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-05-27 10:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-24 18:46 [PATCH nft] src: add cache_is_complete() and cache_is_updated() Pablo Neira Ayuso
2019-05-27 10:01 ` Phil Sutter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox