Make cache_flush() set cache->cmd to CMD_FLUSH and treat that as a new
highest cache completeness level. Prevent cache_update() from doing its
thing if it's set even if kernel's ruleset is newer.

Signed-off-by: Phil Sutter <[email protected]>
---
 src/rule.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/rule.c b/src/rule.c
index 966948cd7ae90..f6ef1f6b0addd 100644
--- a/src/rule.c
+++ b/src/rule.c
@@ -225,6 +225,8 @@ static int cache_init(struct netlink_ctx *ctx, enum cmd_ops 
cmd)
  * means more complete. */
 static int cache_completeness(enum cmd_ops cmd)
 {
+       if (cmd == CMD_FLUSH)
+               return 4;
        if (cmd == CMD_LIST)
                return 3;
        if (cmd != CMD_RESET)
@@ -258,7 +260,8 @@ replay:
        ctx.seqnum = cache->seqnum++;
        genid = mnl_genid_get(&ctx);
        if (cache_is_complete(cache, cmd) &&
-           cache_is_updated(cache, genid))
+           (cache_is_updated(cache, genid) ||
+            cache_is_complete(cache, CMD_FLUSH)))
                return 0;
 
        if (cache->genid)
@@ -299,7 +302,7 @@ void cache_flush(struct nft_ctx *nft, enum cmd_ops cmd, 
struct list_head *msgs)
 
        __cache_flush(&cache->list);
        cache->genid = mnl_genid_get(&ctx);
-       cache->cmd = CMD_LIST;
+       cache->cmd = CMD_FLUSH;
 }
 
 void cache_release(struct nft_cache *cache)
-- 
2.21.0

Reply via email to