public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode
@ 2026-03-29  7:51 Vitaly Grinberg
  2026-03-29 11:47 ` Petr Oros
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Vitaly Grinberg @ 2026-03-29  7:51 UTC (permalink / raw)
  To: netdev; +Cc: stephen, Vitaly Grinberg

Previously, monitor mode wrapped all events in a single JSON array
inside a top-level object, which made piping the output to external
tools (such as `jq`) impossible.
Send a separate JSON object for each event in monitor mode,
making the output suitable for line-by-line consumers. Skip the
global JSON wrapper for monitor mode.

Signed-off-by: Vitaly Grinberg <vgrinber@redhat.com>
---
v2:
  - Fixed indentation
---
 dpll/dpll.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/dpll/dpll.c b/dpll/dpll.c
index 9893ca8c..49576d23 100644
--- a/dpll/dpll.c
+++ b/dpll/dpll.c
@@ -571,8 +571,15 @@ int main(int argc, char **argv)
 	argc -= optind;
 	argv += optind;
 
-	new_json_obj_plain(json);
-	open_json_object(NULL);
+	/* Monitor emits one JSON object per event for streaming;
+	 * other commands use a single JSON wrapper object.
+	 */
+	bool is_monitor = argc > 0 && strcmp(argv[0], "monitor") == 0;
+
+	if (!is_monitor) {
+		new_json_obj_plain(json);
+		open_json_object(NULL);
+	}
 
 	/* Skip netlink init for help commands */
 	bool need_nl = true;
@@ -602,8 +609,10 @@ dpll_fini:
 	if (need_nl)
 		dpll_fini(dpll);
 json_cleanup:
-	close_json_object();
-	delete_json_obj_plain();
+	if (!is_monitor) {
+		close_json_object();
+		delete_json_obj_plain();
+	}
 dpll_free:
 	dpll_free(dpll);
 	return ret;
@@ -2173,6 +2182,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 
 		mnl_attr_parse(nlh, sizeof(struct genlmsghdr), attr_cb, tb);
 
+		new_json_obj_plain(json);
 		open_json_object(NULL);
 		print_string(PRINT_JSON, "name", NULL, json_name);
 		open_json_object("msg");
@@ -2182,6 +2192,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 
 		close_json_object();
 		close_json_object();
+		delete_json_obj_plain();
 		break;
 	}
 	case DPLL_CMD_PIN_CREATE_NTF:
@@ -2200,6 +2211,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 			json_name = "pin-delete-ntf";
 		}
 
+		new_json_obj_plain(json);
 		open_json_object(NULL);
 		print_string(PRINT_JSON, "name", NULL, json_name);
 		open_json_object("msg");
@@ -2209,6 +2221,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
 
 		close_json_object();
 		close_json_object();
+		delete_json_obj_plain();
 		break;
 	}
 	default:
@@ -2273,8 +2286,6 @@ static int cmd_monitor(struct dpll *dpll)
 		goto err_signalfd;
 	}
 
-	open_json_array(PRINT_JSON, "monitor");
-
 	pfds[0].fd = signal_fd;
 	pfds[0].events = POLLIN;
 	pfds[1].fd = netlink_fd;
@@ -2307,8 +2318,6 @@ static int cmd_monitor(struct dpll *dpll)
 		}
 	}
 
-	close_json_array(PRINT_JSON, NULL);
-
 err_signalfd:
 	if (signal_fd >= 0)
 		close(signal_fd);

---
base-commit: 36252727bfc653905bb39bec115a32869452beb1
change-id: 20260328-dpll-mon-j-d88eb48c1f09

Best regards,
--  
Vitaly Grinberg <vgrinber@redhat.com>


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

* Re: [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode
  2026-03-29  7:51 [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
@ 2026-03-29 11:47 ` Petr Oros
  2026-03-30  8:50 ` Ivan Vecera
  2026-04-05 17:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Petr Oros @ 2026-03-29 11:47 UTC (permalink / raw)
  To: Vitaly Grinberg, netdev; +Cc: stephen

> Previously, monitor mode wrapped all events in a single JSON array
> inside a top-level object, which made piping the output to external
> tools (such as `jq`) impossible.
> Send a separate JSON object for each event in monitor mode,
> making the output suitable for line-by-line consumers. Skip the
> global JSON wrapper for monitor mode.
>
> Signed-off-by: Vitaly Grinberg <vgrinber@redhat.com>
> ---
> v2:
>    - Fixed indentation
> ---
>   dpll/dpll.c | 25 +++++++++++++++++--------
>   1 file changed, 17 insertions(+), 8 deletions(-)
>
> diff --git a/dpll/dpll.c b/dpll/dpll.c
> index 9893ca8c..49576d23 100644
> --- a/dpll/dpll.c
> +++ b/dpll/dpll.c
> @@ -571,8 +571,15 @@ int main(int argc, char **argv)
>   	argc -= optind;
>   	argv += optind;
>   
> -	new_json_obj_plain(json);
> -	open_json_object(NULL);
> +	/* Monitor emits one JSON object per event for streaming;
> +	 * other commands use a single JSON wrapper object.
> +	 */
> +	bool is_monitor = argc > 0 && strcmp(argv[0], "monitor") == 0;
> +
> +	if (!is_monitor) {
> +		new_json_obj_plain(json);
> +		open_json_object(NULL);
> +	}
>   
>   	/* Skip netlink init for help commands */
>   	bool need_nl = true;
> @@ -602,8 +609,10 @@ dpll_fini:
>   	if (need_nl)
>   		dpll_fini(dpll);
>   json_cleanup:
> -	close_json_object();
> -	delete_json_obj_plain();
> +	if (!is_monitor) {
> +		close_json_object();
> +		delete_json_obj_plain();
> +	}
>   dpll_free:
>   	dpll_free(dpll);
>   	return ret;
> @@ -2173,6 +2182,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		mnl_attr_parse(nlh, sizeof(struct genlmsghdr), attr_cb, tb);
>   
> +		new_json_obj_plain(json);
>   		open_json_object(NULL);
>   		print_string(PRINT_JSON, "name", NULL, json_name);
>   		open_json_object("msg");
> @@ -2182,6 +2192,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		close_json_object();
>   		close_json_object();
> +		delete_json_obj_plain();
>   		break;
>   	}
>   	case DPLL_CMD_PIN_CREATE_NTF:
> @@ -2200,6 +2211,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   			json_name = "pin-delete-ntf";
>   		}
>   
> +		new_json_obj_plain(json);
>   		open_json_object(NULL);
>   		print_string(PRINT_JSON, "name", NULL, json_name);
>   		open_json_object("msg");
> @@ -2209,6 +2221,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		close_json_object();
>   		close_json_object();
> +		delete_json_obj_plain();
>   		break;
>   	}
>   	default:
> @@ -2273,8 +2286,6 @@ static int cmd_monitor(struct dpll *dpll)
>   		goto err_signalfd;
>   	}
>   
> -	open_json_array(PRINT_JSON, "monitor");
> -
>   	pfds[0].fd = signal_fd;
>   	pfds[0].events = POLLIN;
>   	pfds[1].fd = netlink_fd;
> @@ -2307,8 +2318,6 @@ static int cmd_monitor(struct dpll *dpll)
>   		}
>   	}
>   
> -	close_json_array(PRINT_JSON, NULL);
> -
>   err_signalfd:
>   	if (signal_fd >= 0)
>   		close(signal_fd);
>
> ---
> base-commit: 36252727bfc653905bb39bec115a32869452beb1
> change-id: 20260328-dpll-mon-j-d88eb48c1f09
>
> Best regards,
> --
> Vitaly Grinberg <vgrinber@redhat.com>
>
>
Good idea, Thanks

Reviewed-by: Petr Oros <poros@redhat.com>



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

* Re: [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode
  2026-03-29  7:51 [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
  2026-03-29 11:47 ` Petr Oros
@ 2026-03-30  8:50 ` Ivan Vecera
  2026-04-05 17:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Ivan Vecera @ 2026-03-30  8:50 UTC (permalink / raw)
  To: Vitaly Grinberg, netdev; +Cc: stephen

On 3/29/26 9:51 AM, Vitaly Grinberg wrote:
> Previously, monitor mode wrapped all events in a single JSON array
> inside a top-level object, which made piping the output to external
> tools (such as `jq`) impossible.
> Send a separate JSON object for each event in monitor mode,
> making the output suitable for line-by-line consumers. Skip the
> global JSON wrapper for monitor mode.
> 
> Signed-off-by: Vitaly Grinberg <vgrinber@redhat.com>
> ---
> v2:
>    - Fixed indentation
> ---
>   dpll/dpll.c | 25 +++++++++++++++++--------
>   1 file changed, 17 insertions(+), 8 deletions(-)
> 
> diff --git a/dpll/dpll.c b/dpll/dpll.c
> index 9893ca8c..49576d23 100644
> --- a/dpll/dpll.c
> +++ b/dpll/dpll.c
> @@ -571,8 +571,15 @@ int main(int argc, char **argv)
>   	argc -= optind;
>   	argv += optind;
>   
> -	new_json_obj_plain(json);
> -	open_json_object(NULL);
> +	/* Monitor emits one JSON object per event for streaming;
> +	 * other commands use a single JSON wrapper object.
> +	 */
> +	bool is_monitor = argc > 0 && strcmp(argv[0], "monitor") == 0;
> +
> +	if (!is_monitor) {
> +		new_json_obj_plain(json);
> +		open_json_object(NULL);
> +	}
>   
>   	/* Skip netlink init for help commands */
>   	bool need_nl = true;
> @@ -602,8 +609,10 @@ dpll_fini:
>   	if (need_nl)
>   		dpll_fini(dpll);
>   json_cleanup:
> -	close_json_object();
> -	delete_json_obj_plain();
> +	if (!is_monitor) {
> +		close_json_object();
> +		delete_json_obj_plain();
> +	}
>   dpll_free:
>   	dpll_free(dpll);
>   	return ret;
> @@ -2173,6 +2182,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		mnl_attr_parse(nlh, sizeof(struct genlmsghdr), attr_cb, tb);
>   
> +		new_json_obj_plain(json);
>   		open_json_object(NULL);
>   		print_string(PRINT_JSON, "name", NULL, json_name);
>   		open_json_object("msg");
> @@ -2182,6 +2192,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		close_json_object();
>   		close_json_object();
> +		delete_json_obj_plain();
>   		break;
>   	}
>   	case DPLL_CMD_PIN_CREATE_NTF:
> @@ -2200,6 +2211,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   			json_name = "pin-delete-ntf";
>   		}
>   
> +		new_json_obj_plain(json);
>   		open_json_object(NULL);
>   		print_string(PRINT_JSON, "name", NULL, json_name);
>   		open_json_object("msg");
> @@ -2209,6 +2221,7 @@ static int cmd_monitor_cb(const struct nlmsghdr *nlh, void *data)
>   
>   		close_json_object();
>   		close_json_object();
> +		delete_json_obj_plain();
>   		break;
>   	}
>   	default:
> @@ -2273,8 +2286,6 @@ static int cmd_monitor(struct dpll *dpll)
>   		goto err_signalfd;
>   	}
>   
> -	open_json_array(PRINT_JSON, "monitor");
> -
>   	pfds[0].fd = signal_fd;
>   	pfds[0].events = POLLIN;
>   	pfds[1].fd = netlink_fd;
> @@ -2307,8 +2318,6 @@ static int cmd_monitor(struct dpll *dpll)
>   		}
>   	}
>   
> -	close_json_array(PRINT_JSON, NULL);
> -
>   err_signalfd:
>   	if (signal_fd >= 0)
>   		close(signal_fd);
> 
> ---
> base-commit: 36252727bfc653905bb39bec115a32869452beb1
> change-id: 20260328-dpll-mon-j-d88eb48c1f09
> 
> Best regards,
> --
> Vitaly Grinberg <vgrinber@redhat.com>
> 
> 
Thanks Vitaly... next time please do not forget to CC me and Petr.

Reviewed-by: Ivan Vecera <ivecera@redhat.com>


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

* Re: [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode
  2026-03-29  7:51 [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
  2026-03-29 11:47 ` Petr Oros
  2026-03-30  8:50 ` Ivan Vecera
@ 2026-04-05 17:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-04-05 17:30 UTC (permalink / raw)
  To: Vitaly Grinberg; +Cc: netdev, stephen

Hello:

This patch was applied to iproute2/iproute2-next.git (main)
by David Ahern <dsahern@kernel.org>:

On Sun, 29 Mar 2026 10:51:01 +0300 you wrote:
> Previously, monitor mode wrapped all events in a single JSON array
> inside a top-level object, which made piping the output to external
> tools (such as `jq`) impossible.
> Send a separate JSON object for each event in monitor mode,
> making the output suitable for line-by-line consumers. Skip the
> global JSON wrapper for monitor mode.
> 
> [...]

Here is the summary with links:
  - [iproute2-next,v2] dpll: Send object per event in JSON monitor mode
    https://git.kernel.org/pub/scm/network/iproute2/iproute2-next.git/commit/?id=52204702bde3

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-04-05 17:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-29  7:51 [PATCH iproute2-next v2] dpll: Send object per event in JSON monitor mode Vitaly Grinberg
2026-03-29 11:47 ` Petr Oros
2026-03-30  8:50 ` Ivan Vecera
2026-04-05 17:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox