From 2caecefe812e4d614687926d259ade3106935c56 Mon Sep 17 00:00:00 2001 From: Phil Sutter Date: Tue, 15 Aug 2017 13:59:12 +0200 Subject: echo: Fix for added delays in rule updates The added cache update upon every command dealing with rules was a bummer. Instead, perform the needed cache update only if echo option was set. Initially, I tried to perform the cache update from within netlink_echo_callback(), but that turned into a mess since the shared socket between cache_init() and mnl_batch_talk() would receive unexpected new input. So instead update the cache from do_command_add(), netlink_replace_rule_batch() and do_comand_insert() so it completes before mnl_batch_talk() starts listening. Signed-off-by: Phil Sutter Signed-off-by: Pablo Neira Ayuso --- src/netlink.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/netlink.c') diff --git a/src/netlink.c b/src/netlink.c index f631c26b..68f33625 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -464,7 +464,16 @@ int netlink_replace_rule_batch(struct netlink_ctx *ctx, const struct handle *h, const struct location *loc) { struct nftnl_rule *nlr; - int err, flags = ctx->octx->echo ? NLM_F_ECHO : 0; + int err, flags = 0; + + if (ctx->octx->echo) { + err = cache_update(ctx->nf_sock, ctx->cache, + CMD_INVALID, ctx->msgs); + if (err < 0) + return err; + + flags |= NLM_F_ECHO; + } nlr = alloc_nftnl_rule(&rule->handle); netlink_linearize_rule(ctx, nlr, rule); -- cgit v1.2.3