The old logic wasn't optimal: If e.g. current command was CMD_RESET and old command was CMD_LIST, cache was already fully populated but still refreshed. Introduce a simple scoring system which reflects how cache_init_objects() looks at the current command to decide if it is finished already or not. Then use that in cache_needs_more(): If current commands score is higher than old command's, cache needs an update. Signed-off-by: Phil Sutter <phil@xxxxxx> --- src/rule.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/rule.c b/src/rule.c index afe37cd90b1da..17bf5bbbe680c 100644 --- a/src/rule.c +++ b/src/rule.c @@ -220,13 +220,21 @@ static int cache_init(struct netlink_ctx *ctx, enum cmd_ops cmd) return 0; } -static int cache_needs_more(enum cmd_ops old_cmd, enum cmd_ops cmd) +/* Return a "score" of how complete local cache will be if + * cache_init_objects() ran for given cmd. Higher value + * means more complete. */ +static int cache_completeness(enum cmd_ops cmd) { - if (cmd == CMD_LIST && old_cmd != CMD_LIST) - return 1; - if (cmd == CMD_RESET && old_cmd != CMD_RESET) - return 1; - return 0; + if (cmd == CMD_LIST) + return 3; + if (cmd != CMD_RESET) + return 2; + return 1; +} + +static bool cache_needs_more(enum cmd_ops old_cmd, enum cmd_ops cmd) +{ + return cache_completeness(old_cmd) < cache_completeness(cmd); } int cache_update(struct nft_ctx *nft, enum cmd_ops cmd, struct list_head *msgs) -- 2.21.0