diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-10-29 12:11:09 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2018-10-29 15:07:35 +0100 |
commit | 48636e1fe6f6d3141de735f9faf4c359938b837c (patch) | |
tree | 261623cb4aa26de34f1432fd2b6964f9a57ae789 /src | |
parent | 7a6f12d75034fed940ce635e76a13123430f088e (diff) |
src: add nft_ctx_output_{get,set}_echo() to nft_ctx_output_{get,set}_flags
Add NFT_CTX_OUTPUT_ECHO flag and echo the command that has been send to
the kernel.
Acked-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/libnftables.c | 18 | ||||
-rw-r--r-- | src/main.c | 2 | ||||
-rw-r--r-- | src/mnl.c | 2 | ||||
-rw-r--r-- | src/monitor.c | 2 | ||||
-rw-r--r-- | src/parser_json.c | 4 | ||||
-rw-r--r-- | src/rule.c | 4 |
6 files changed, 13 insertions, 19 deletions
diff --git a/src/libnftables.c b/src/libnftables.c index ff7a53d2..03c15fba 100644 --- a/src/libnftables.c +++ b/src/libnftables.c @@ -342,16 +342,6 @@ void nft_ctx_output_set_debug(struct nft_ctx *ctx, unsigned int mask) ctx->debug_mask = mask; } -bool nft_ctx_output_get_echo(struct nft_ctx *ctx) -{ - return ctx->output.echo; -} - -void nft_ctx_output_set_echo(struct nft_ctx *ctx, bool val) -{ - ctx->output.echo = val; -} - static const struct input_descriptor indesc_cmdline = { .type = INDESC_BUFFER, .name = "<cmdline>", @@ -431,7 +421,9 @@ err: } free(nlbuf); - if (!rc && nft_output_json(&nft->output) && nft->output.echo) + if (!rc && + nft_output_json(&nft->output) && + nft_output_echo(&nft->output)) json_print_echo(nft); return rc; } @@ -472,7 +464,9 @@ err: nft->scanner = NULL; } - if (!rc && nft_output_json(&nft->output) && nft->output.echo) + if (!rc && + nft_output_json(&nft->output) && + nft_output_echo(&nft->output)) json_print_echo(nft); return rc; } @@ -269,7 +269,7 @@ int main(int argc, char * const *argv) output_flags |= NFT_CTX_OUTPUT_HANDLE; break; case OPT_ECHO: - nft_ctx_output_set_echo(nft, true); + output_flags |= NFT_CTX_OUTPUT_ECHO; break; case OPT_JSON: #ifdef HAVE_LIBJANSSON @@ -350,7 +350,7 @@ int mnl_nft_rule_replace(struct netlink_ctx *ctx, const struct cmd *cmd) struct nlmsghdr *nlh; int err; - if (ctx->nft->output.echo) { + if (nft_output_echo(&ctx->nft->output)) { err = cache_update(ctx->nft, CMD_INVALID, ctx->msgs); if (err < 0) return err; diff --git a/src/monitor.c b/src/monitor.c index 01480cd7..b2267e1f 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -905,7 +905,7 @@ int netlink_echo_callback(const struct nlmsghdr *nlh, void *data) .cache_needed = true, }; - if (!echo_monh.ctx->nft->output.echo) + if (!nft_output_echo(&echo_monh.ctx->nft->output)) return MNL_CB_OK; if (nft_output_json(&ctx->nft->output)) diff --git a/src/parser_json.c b/src/parser_json.c index bc682e92..412f5cf2 100644 --- a/src/parser_json.c +++ b/src/parser_json.c @@ -3399,7 +3399,7 @@ int nft_parse_json_buffer(struct nft_ctx *nft, const char *buf, ret = __json_parse(&ctx); - if (!nft->output.echo) { + if (!nft_output_echo(&nft->output)) { json_decref(nft->json_root); nft->json_root = NULL; } @@ -3427,7 +3427,7 @@ int nft_parse_json_filename(struct nft_ctx *nft, const char *filename, ret = __json_parse(&ctx); - if (!nft->output.echo) { + if (!nft_output_echo(&nft->output)) { json_decref(nft->json_root); nft->json_root = NULL; } @@ -1388,7 +1388,7 @@ static int do_command_add(struct netlink_ctx *ctx, struct cmd *cmd, bool excl) { uint32_t flags = excl ? NLM_F_EXCL : 0; - if (ctx->nft->output.echo) { + if (nft_output_echo(&ctx->nft->output)) { int ret; ret = cache_update(ctx->nft, cmd->obj, ctx->msgs); @@ -1439,7 +1439,7 @@ static int do_command_insert(struct netlink_ctx *ctx, struct cmd *cmd) { uint32_t flags = 0; - if (ctx->nft->output.echo) { + if (nft_output_echo(&ctx->nft->output)) { int ret; ret = cache_update(ctx->nft, cmd->obj, ctx->msgs); |