All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nftables 1/2] monitor: add assignment check for json_echo
@ 2020-12-06 10:12 Jose M. Guisado Gomez
  2020-12-06 10:12 ` [PATCH nftables 2/2] monitor: fix formatting of if statements Jose M. Guisado Gomez
  2020-12-08 11:43 ` [PATCH nftables 1/2] monitor: add assignment check for json_echo Pablo Neira Ayuso
  0 siblings, 2 replies; 4+ messages in thread
From: Jose M. Guisado Gomez @ 2020-12-06 10:12 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

When --echo and --json is specified and native syntax is read, only the
last instruction is printed. This happens because the reference to the
json_echo is reassigned each time netlink_echo_callback is executed for
an instruction to be echoed.

Add an assignment check for json_echo to avoid reassigning it.

Fixes: cb7e02f4 (src: enable json echo output when reading native
syntax)
Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
---
 src/monitor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/monitor.c b/src/monitor.c
index a733a9f0..2b5325ea 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -939,8 +939,8 @@ int netlink_echo_callback(const struct nlmsghdr *nlh, void *data)
 	if (nft_output_json(&nft->output)) {
 		if (nft->json_root)
 			return json_events_cb(nlh, &echo_monh);
-
-		json_alloc_echo(nft);
+		if (!nft->json_echo)
+			json_alloc_echo(nft);
 		echo_monh.format = NFTNL_OUTPUT_JSON;
 	}
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH nftables 2/2] monitor: fix formatting of if statements
  2020-12-06 10:12 [PATCH nftables 1/2] monitor: add assignment check for json_echo Jose M. Guisado Gomez
@ 2020-12-06 10:12 ` Jose M. Guisado Gomez
  2020-12-08 11:45   ` Pablo Neira Ayuso
  2020-12-08 11:43 ` [PATCH nftables 1/2] monitor: add assignment check for json_echo Pablo Neira Ayuso
  1 sibling, 1 reply; 4+ messages in thread
From: Jose M. Guisado Gomez @ 2020-12-06 10:12 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

Replace some "if(" introduced in cb7e02f4 by "if ("

Signed-off-by: Jose M. Guisado Gomez <guigom@riseup.net>
---
 src/monitor.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/monitor.c b/src/monitor.c
index 2b5325ea..af2998d4 100644
--- a/src/monitor.c
+++ b/src/monitor.c
@@ -225,7 +225,7 @@ static int netlink_events_table_cb(const struct nlmsghdr *nlh, int type,
 		break;
 	case NFTNL_OUTPUT_JSON:
 		monitor_print_table_json(monh, cmd, t);
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
@@ -264,7 +264,7 @@ static int netlink_events_chain_cb(const struct nlmsghdr *nlh, int type,
 		break;
 	case NFTNL_OUTPUT_JSON:
 		monitor_print_chain_json(monh, cmd, c);
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
@@ -312,7 +312,7 @@ static int netlink_events_set_cb(const struct nlmsghdr *nlh, int type,
 		break;
 	case NFTNL_OUTPUT_JSON:
 		monitor_print_set_json(monh, cmd, set);
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
@@ -457,7 +457,7 @@ static int netlink_events_setelem_cb(const struct nlmsghdr *nlh, int type,
 		/* prevent set_free() from trying to free those */
 		dummyset->handle.set.name = NULL;
 		dummyset->handle.table.name = NULL;
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
@@ -504,7 +504,7 @@ static int netlink_events_obj_cb(const struct nlmsghdr *nlh, int type,
 		break;
 	case NFTNL_OUTPUT_JSON:
 		monitor_print_obj_json(monh, cmd, obj);
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
@@ -556,7 +556,7 @@ static int netlink_events_rule_cb(const struct nlmsghdr *nlh, int type,
 		break;
 	case NFTNL_OUTPUT_JSON:
 		monitor_print_rule_json(monh, cmd, r);
-		if(!nft_output_echo(&monh->ctx->nft->output))
+		if (!nft_output_echo(&monh->ctx->nft->output))
 			nft_mon_print(monh, "\n");
 		break;
 	}
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH nftables 1/2] monitor: add assignment check for json_echo
  2020-12-06 10:12 [PATCH nftables 1/2] monitor: add assignment check for json_echo Jose M. Guisado Gomez
  2020-12-06 10:12 ` [PATCH nftables 2/2] monitor: fix formatting of if statements Jose M. Guisado Gomez
@ 2020-12-08 11:43 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-12-08 11:43 UTC (permalink / raw)
  To: Jose M. Guisado Gomez; +Cc: netfilter-devel

On Sun, Dec 06, 2020 at 11:12:33AM +0100, Jose M. Guisado Gomez wrote:
> When --echo and --json is specified and native syntax is read, only the
> last instruction is printed. This happens because the reference to the
> json_echo is reassigned each time netlink_echo_callback is executed for
> an instruction to be echoed.
> 
> Add an assignment check for json_echo to avoid reassigning it.

Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH nftables 2/2] monitor: fix formatting of if statements
  2020-12-06 10:12 ` [PATCH nftables 2/2] monitor: fix formatting of if statements Jose M. Guisado Gomez
@ 2020-12-08 11:45   ` Pablo Neira Ayuso
  0 siblings, 0 replies; 4+ messages in thread
From: Pablo Neira Ayuso @ 2020-12-08 11:45 UTC (permalink / raw)
  To: Jose M. Guisado Gomez; +Cc: netfilter-devel

On Sun, Dec 06, 2020 at 11:12:34AM +0100, Jose M. Guisado Gomez wrote:
> Replace some "if(" introduced in cb7e02f4 by "if ("

Also applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-12-08 11:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-06 10:12 [PATCH nftables 1/2] monitor: add assignment check for json_echo Jose M. Guisado Gomez
2020-12-06 10:12 ` [PATCH nftables 2/2] monitor: fix formatting of if statements Jose M. Guisado Gomez
2020-12-08 11:45   ` Pablo Neira Ayuso
2020-12-08 11:43 ` [PATCH nftables 1/2] monitor: add assignment check for json_echo Pablo Neira Ayuso

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.