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/rule.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src/rule.c') diff --git a/src/rule.c b/src/rule.c index 1bd5c801..38cd648e 100644 --- a/src/rule.c +++ b/src/rule.c @@ -1017,8 +1017,16 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) { uint32_t flags = excl ? NLM_F_EXCL : 0; - if (ctx->octx->echo) + if (ctx->octx->echo) { + int ret; + + ret = cache_update(ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); + if (ret < 0) + return ret; + flags |= NLM_F_ECHO; + } switch (cmd->obj) { case CMD_OBJ_TABLE: @@ -1058,7 +1066,18 @@ static int do_command_replace(struct netlink_ctx *ctx, struct cmd *cmd) static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd) { - uint32_t flags = ctx->octx->echo ? NLM_F_ECHO : 0; + uint32_t flags = 0; + + if (ctx->octx->echo) { + int ret; + + ret = cache_update(ctx->nf_sock, ctx->cache, + cmd->obj, ctx->msgs); + if (ret < 0) + return ret; + + flags |= NLM_F_ECHO; + } switch (cmd->obj) { case CMD_OBJ_RULE: -- cgit v1.2.3