diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-05-24 20:46:18 +0200 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2019-05-27 12:03:57 +0200 |
commit | 9e64df7227507aaced570c23ebd665cb24a1073f (patch) | |
tree | 11f6294763adb456c93fbc184ffb3adaaac7ec05 /src/rule.c | |
parent | c64457cff9673fbb41f613a67e158b4d62235c09 (diff) |
src: add cache_is_complete() and cache_is_updated()
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>
Diffstat (limited to 'src/rule.c')
-rw-r--r-- | src/rule.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -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); |