From: Pablo Neira Ayuso Date: Mon, 27 May 2024 16:12:05 +0000 (+0200) Subject: cache: check for NFT_CACHE_REFRESH in current requested cache too X-Git-Tag: v1.0.6.1~205 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=470e94cffc31631ef7e16b31ffecf1d222839f07;p=thirdparty%2Fnftables.git cache: check for NFT_CACHE_REFRESH in current requested cache too commit bbb0e944b59d355085e8f50b4b7b5057ae0d33a4 upstream. NFT_CACHE_REFRESH is set on inconditionally by ruleset list commands to deal with stateful information in this ruleset. This flag results in dropping the existing cache and fully fetching all objects from the kernel. Set on this flag for reset commands too, this is missing. List/reset commands allow for filtering by specific family and object, therefore, NFT_CACHE_REFRESH also signals that the cache is partially populated. Check if this flag is requested by the current list/reset command, as well as cache->flags which represents the cache after the _previous_ list of commands. A follow up patch allows to recycle the existing cache if the flags report that the same objects are already available in the cache, NFT_CACHE_REFRESH is useful to report that cache cannot be recycled. Fixes: 407c54f71255 ("src: cache gets out of sync in interactive mode") Signed-off-by: Pablo Neira Ayuso --- diff --git a/src/cache.c b/src/cache.c index 7ff4b34d..bd6ba177 100644 --- a/src/cache.c +++ b/src/cache.c @@ -1131,9 +1131,10 @@ static bool nft_cache_is_complete(struct nft_cache *cache, unsigned int flags) return (cache->flags & flags) == flags; } -static bool nft_cache_needs_refresh(struct nft_cache *cache) +static bool nft_cache_needs_refresh(struct nft_cache *cache, unsigned int flags) { - return cache->flags & NFT_CACHE_REFRESH; + return (cache->flags & NFT_CACHE_REFRESH) || + (flags & NFT_CACHE_REFRESH); } static bool nft_cache_is_updated(struct nft_cache *cache, uint16_t genid) @@ -1161,7 +1162,7 @@ int nft_cache_update(struct nft_ctx *nft, unsigned int flags, replay: ctx.seqnum = cache->seqnum++; genid = mnl_genid_get(&ctx); - if (!nft_cache_needs_refresh(cache) && + if (!nft_cache_needs_refresh(cache, flags) && nft_cache_is_complete(cache, flags) && nft_cache_is_updated(cache, genid)) return 0;