From nobody Mon Mar 2 06:39:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AF16A2EB856; Mon, 23 Feb 2026 15:31:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860682; cv=none; b=TQuWYnFNg9aYk7Dv1cXbvg8qbrwPY4yMNpp7GV2DNUjS4KQIuzRbVa0DLsUJfMjZqgSlhnSY7DxVI+J2YITBwh+4dU/KgLj2dFMXTX3CohCvzOLT+TH+2wusBc36dZ8Y4YNJZu851D5nVDHdH0UWYkI/X3lK8s+Hvwfg9OocBYc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860682; c=relaxed/simple; bh=asIr6HoAWgEgFuiqGCFTBNTg4dHGyiVNQ+Sg3mqF0j4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LM2i6/qSV8BpDexBsk8mdyj8/9iHkMzlsPDUGhvoDIYMH/hddGOIWvoebqNpkCrYCVh4RF+l/4Q4vsfjFYWcIj1DEbCwVstaDEr83+mxAGpfMqVkwvWtFVe1IvqBoZuCIRg/At6klczNTlKHCi6X6v24qlCdZSCWDaXwU5D+32s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NGRmqmhn; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NGRmqmhn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9E605C19423; Mon, 23 Feb 2026 15:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771860682; bh=asIr6HoAWgEgFuiqGCFTBNTg4dHGyiVNQ+Sg3mqF0j4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=NGRmqmhnOOdD80BaRp/I4lfutkLHmXko8tJNjSySshSpNIrfUbYviQ4FYVNdumi5C JaC48nMQ+FneQeeozs0gj3EprvwFmIh4tSIwpF2tME7XkXBB6FCVro2Ox62qfTcnYz o7ymu5gVUO6bU8oQ55idBSG32zLbxpCF5bqFqiKgcSGPYzN/8ebE4Aik1VNUof4Yox bcu8c1mz4JvA6gkg+eqhV9z++zlH2OV4xANtWuLlJbIpsL1iEV5zaiuIukupN/RhYf 5TEFjD559d2lnH0rQ+/6yOdRbEGZS/WOR1yBB8xQ94fNHJwVAcweSh3mHxgZJy4L1x C0NzBM96p2K6Q== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Feb 2026 16:28:38 +0100 Subject: [PATCH iproute2-next v2 1/3] mptcp: uniform stream closure Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-ipr-monitor-json-v2-1-f91fccccf917@kernel.org> References: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> In-Reply-To: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> To: Stephen Hemminger , David Ahern Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1131; i=matttbe@kernel.org; h=from:subject:message-id; bh=asIr6HoAWgEgFuiqGCFTBNTg4dHGyiVNQ+Sg3mqF0j4=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDLnFB3rmHxjvscM2U72CbMvFPMJBy65ZWuS/eynqpX2q +TC5XH2HaUsDGJcDLJiiizSbZH5M59X8ZZ4+VnAzGFlAhnCwMUpABN5W8TwP0Lm96dr95/H7rsV f/ZU7Bzpa58+M5/+/iBPvWT/w/7t7/YxMiy/zKdUVfPyZpMc+0tfIdcDM89JTrlyxacjdWrJrWN TkzgB X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Use print_nl() instead of print_string(), close the json object, then flush the stream to flush the end of the JSON object ASAP. Note that in print_mptcp_limit(), the flush should have been done before closing the JSON object, but because there is only one object and the closure was done just before exiting, there was no visual impact. Signed-off-by: Matthieu Baerts (NGI0) --- ip/ipmptcp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c index ec9ef62a..18ec05a8 100644 --- a/ip/ipmptcp.c +++ b/ip/ipmptcp.c @@ -273,8 +273,8 @@ static int print_mptcp_addrinfo(struct rtattr *addrinfo) } } =20 + print_nl(); close_json_object(); - print_string(PRINT_FP, NULL, "\n", NULL); fflush(stdout); =20 return 0; @@ -426,9 +426,11 @@ static int print_mptcp_limit(struct nlmsghdr *n, void = *arg) =20 print_uint(PRINT_ANY, "subflows", "subflows %d ", val); } - print_string(PRINT_FP, NULL, "%s", "\n"); - fflush(stdout); + + print_nl(); close_json_object(); + fflush(stdout); + return 0; } =20 --=20 2.51.0 From nobody Mon Mar 2 06:39:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D98352EDD45; Mon, 23 Feb 2026 15:31:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860683; cv=none; b=DfiJkp1vPDuCIB1jUvgl86p3Za9xB/fM8G/E156NjCpdWPJ/DgNh4DGH/i1wz3acPupZbFahgF9sqD86vWowGJpXF/M1uyRi/OuyypD5lFnp4+g6umJ/0bR1PEpqDNgLsq/FCJxFnO7fwSBPbSHvjoSp/VZeYRGCi8G/WP/riAQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860683; c=relaxed/simple; bh=Dweq7oqtgV5vV7+Nk9lIGffgPM0V6SHAR+/STKKhKtU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=L/Z5EwQkkMmU87IRk0swzhmOrO0fVp8K4ye1EhyrqXiGWqelSVPTNLfSwAgTnd9Ivq5b3Zan24dneFTSy5hHin3xh1Ise9el9PkKRygH2MQZZu1wD1TsnKWYRkuGEtX3vKqbTabSR5Cp57YZRqM4PPhlRL4PrDYDEY8wfNDxAEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lr1Bx+YA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lr1Bx+YA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFC44C19423; Mon, 23 Feb 2026 15:31:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771860683; bh=Dweq7oqtgV5vV7+Nk9lIGffgPM0V6SHAR+/STKKhKtU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=lr1Bx+YA/mLGpWK9i1+lMlKfCmdsGpaW6StW6iWN021zkTDatH6HLTnxBWOLIFf2i eVEIicffRptiEyYY/pQk/dB/Ts5KfrrmcfW6bqkHRAq9zAhL1tgOkR4RdmXyTUTljq /k901WJ/6qkFZO9c1vOvE7FWR171DS5ccb/Q+U+Z+I21m5N7O3T0FrpN4toJObCcin UTT3CEufeb0zC4KR3UvAl/0wj5BYEn8wMoUraIXSLr0qXGR58ZNkU/JNM5a4dxw8GJ kqL+Kba3X2Ka3yWU8Fe33sWS1wM6YuIDaK0wJwDDXXkcQKRRqyarkhnqMzhOGgn30A M3SHglLyNvQIQ== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Feb 2026 16:28:39 +0100 Subject: [PATCH iproute2-next v2 2/3] utils: timestamp: add JSON support Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-ipr-monitor-json-v2-2-f91fccccf917@kernel.org> References: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> In-Reply-To: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> To: Stephen Hemminger , David Ahern Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=1652; i=matttbe@kernel.org; h=from:subject:message-id; bh=Dweq7oqtgV5vV7+Nk9lIGffgPM0V6SHAR+/STKKhKtU=; b=kA0DAAoWfCLwwvNHCpcByyZiAGmccsejWdm87T3yB8ZgmVTPJrzXj9IvS2d+K3zeRMoG7YWJj 4h1BAAWCgAdFiEEG4ZZb5nneg10Sk44fCLwwvNHCpcFAmmccscACgkQfCLwwvNHCperpgD9E8nf jeUOoIdIzMc6YljYLJlp9TYXo7znMstVuO6X7kIBAMZYD96Ijewz3OqwZnDOgEYyIlf2WcRQNvP UJLcBUQIF X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Supporting JSON is easy with the helpers. The biggest modification is to extract the end value. Different keys are used depending on the short or long timestamp option being used, to ease the parsing. No behavioural changes intended for the moment, this is a preparation for a future usage of print_timestamp() within a JSON context. Like in other helpers supporting JSON, the output stream 'fp' is ignored, which is fine, because it is always set to 'stdout'. Signed-off-by: Matthieu Baerts (NGI0) --- v2: ignore 'fp' which is always set to 'stdout' (Stephen) --- lib/utils.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 13e8c098..1215fe31 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1277,21 +1277,23 @@ int print_timestamp(FILE *fp) { struct timeval tv; struct tm *tm; + char ts[40]; =20 gettimeofday(&tv, NULL); tm =3D localtime(&tv.tv_sec); =20 if (timestamp_short) { - char tshort[40]; + size_t len; =20 - strftime(tshort, sizeof(tshort), "%Y-%m-%dT%H:%M:%S", tm); - fprintf(fp, "[%s.%06ld] ", tshort, tv.tv_usec); + len =3D strftime(ts, sizeof(ts), "%Y-%m-%dT%H:%M:%S", tm); + snprintf(ts + len, sizeof(ts) - len, ".%06ld", tv.tv_usec); + print_string(PRINT_ANY, "timestamp_short", "[%s] ", ts); } else { char *tstr =3D asctime(tm); =20 tstr[strlen(tstr)-1] =3D 0; - fprintf(fp, "Timestamp: %s %ld usec\n", - tstr, tv.tv_usec); + snprintf(ts, sizeof(ts), "%s %ld usec", tstr, tv.tv_usec); + print_string(PRINT_ANY, "timestamp", "Timestamp: %s\n", ts); } =20 return 0; --=20 2.51.0 From nobody Mon Mar 2 06:39:57 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 162082F3621; Mon, 23 Feb 2026 15:31:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860685; cv=none; b=m4OXXsYPNsCLeI+Db5ScceB2pyK4IdsygHdsavG/LOdDO6PyAQyGLkPvSYV9EOT6lY4+tJMPrnHiUGsiyqFGu+ZoFMqvPhVvEgc7vcHMOo98LH5gqxHb1vWRbapM86noOBXMyYHkXP6q+agjanjJD6Hyz09SLvbpHULQUJvQLSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771860685; c=relaxed/simple; bh=Ht0t75qRYANDA/1+A7psyigJet3N9S4aK9ekPlRMMsI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=uLSck1bS+DVxBzF+1TGtKwq9TT6/A+6JuB6lKq8+71ECYCaVy5bvsghdAh5GU3n+hesiskG8nw83Qb23+2hxtM6Ids8gj2Lx7J5GK8IGpe/A8Z6PbopRimqk6zmz1cHIzeyCjpZlkNJXiNy2O1Ov9E8sZdD3d97IKxrq+bv0xAQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FvcUDEp9; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="FvcUDEp9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D0C3C116C6; Mon, 23 Feb 2026 15:31:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771860684; bh=Ht0t75qRYANDA/1+A7psyigJet3N9S4aK9ekPlRMMsI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FvcUDEp9nplL594VW7tBZtGhrrgE6quoEUBLVsndKdahNVVWjxUhx7JbkCE6GOQ+U D85XztQC+6LvEZU6CA8XAZmOd1nQp0M1Oii4N5bIXd3STyLI5ujnkPd/qmeOUZhb5s DCEgdwxx71NgOPAJXe1y0i9uE5JXE+o3Sw0rBrjOkzaVf33ISt0w4FrkxGg1KJzicL YUpTaMQm9PVLTAfc9hg1NIqSWdaA7vpmFXEpjusX+KTNuKVnsMs8zEivNnUxskWn/8 UjwrahOe182dvwCqaEPIkH2Ji0ntHRzE2QZCCeqnow/ApmRdGAucT2qKMzJiehav+M H760X4hRlRV3w== From: "Matthieu Baerts (NGI0)" Date: Mon, 23 Feb 2026 16:28:40 +0100 Subject: [PATCH iproute2-next v2 3/3] mptcp: monitor: add JSON support Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260223-ipr-monitor-json-v2-3-f91fccccf917@kernel.org> References: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> In-Reply-To: <20260223-ipr-monitor-json-v2-0-f91fccccf917@kernel.org> To: Stephen Hemminger , David Ahern Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=6581; i=matttbe@kernel.org; h=from:subject:message-id; bh=Ht0t75qRYANDA/1+A7psyigJet3N9S4aK9ekPlRMMsI=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDLnFB3PWfFJMu/Omvzfq6KurnlnydEgcWLjb+3idctYD kr7OWTyd5SyMIhxMciKKbJIt0Xmz3xexVvi5WcBM4eVCWQIAxenAEwk7AQjwxsPO6+XZTw5flOi eBP1A/wOBDs0zbwbeqiNz6Wv3POJNSPDnqBN6RPfdtkb+6b5LphzLiuvxvT4X7nDMv3Twh0DO26 yAAA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 The command 'ip [-t[s]] mptcp monitor' now produces an output with the JSON format. The previous text output has been preserved. The JSON support has been added thanks to the print_*() helpers. Note that it is also needed to add a signal handler to exit without errors in case of SIGINT or SIGTERM, and close the JSON. This last step will print the final ']' when stopping 'ip -j mptcp monitor'. Signed-off-by: Matthieu Baerts (NGI0) --- v2: - print token with print_0xhex(), and add missing space after ',' (AI) - use atexit() to close the JSON (Stephen) - always call delete_json_obj(): nothing is done when JSON is not used. --- ip/ipmptcp.c | 86 +++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 59 insertions(+), 27 deletions(-) diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c index 18ec05a8..3df89db5 100644 --- a/ip/ipmptcp.c +++ b/ip/ipmptcp.c @@ -2,6 +2,7 @@ =20 #include #include +#include #include #include #include @@ -476,8 +477,9 @@ static void print_addr(const char *key, int af, struct = rtattr *value) char str[INET6_ADDRSTRLEN]; =20 if (inet_ntop(af, data, str, sizeof(str))) { - printf(" %s=3D", key); - color_fprintf(stdout, ifa_family_color(af), "%s", str); + print_string(PRINT_FP, NULL, " %s=3D", key); + print_color_string(PRINT_ANY, ifa_family_color(af), key, "%s", + str); } } =20 @@ -485,12 +487,13 @@ static void print_iface(int index) { const char *ifname; =20 - printf(" ifindex=3D%d", index); + print_int(PRINT_ANY, "ifindex", " ifindex=3D%d", index); =20 ifname =3D index ? ll_index_to_name(index) : NULL; if (ifname) { - printf(" dev=3D"); - color_fprintf(stdout, COLOR_IFNAME, "%s", ifname); + print_string(PRINT_FP, NULL, " dev=3D", NULL); + print_color_string(PRINT_ANY, COLOR_IFNAME, "dev", "%s", + ifname); } } =20 @@ -509,30 +512,34 @@ static int mptcp_monitor_msg(struct rtnl_ctrl_data *c= trl, if (n->nlmsg_type !=3D genl_family) return 0; =20 + open_json_object(NULL); + if (timestamp) print_timestamp(stdout); =20 - if (ghdr->cmd >=3D ARRAY_SIZE(event_to_str)) { - printf("[UNKNOWN %u]\n", ghdr->cmd); + if (ghdr->cmd >=3D ARRAY_SIZE(event_to_str) || + event_to_str[ghdr->cmd] =3D=3D NULL) { + char event[40]; + + snprintf(event, sizeof(event), "UNKNOWN %u", ghdr->cmd); + print_string(PRINT_ANY, "event", "[%s]", event); goto out; } =20 - if (event_to_str[ghdr->cmd] =3D=3D NULL) { - printf("[UNKNOWN %u]\n", ghdr->cmd); - goto out; - } - - printf("[%16s]", event_to_str[ghdr->cmd]); + print_string(PRINT_ANY, "event", "[%16s]", event_to_str[ghdr->cmd]); =20 parse_rtattr(tb, MPTCP_ATTR_MAX, (void *) ghdr + GENL_HDRLEN, len); =20 if (tb[MPTCP_ATTR_TOKEN]) - printf(" token=3D%08x", rta_getattr_u32(tb[MPTCP_ATTR_TOKEN])); + print_0xhex(PRINT_ANY, "token", " token=3D%08x", + rta_getattr_u32(tb[MPTCP_ATTR_TOKEN])); =20 if (tb[MPTCP_ATTR_REM_ID]) - printf(" remid=3D%u", rta_getattr_u8(tb[MPTCP_ATTR_REM_ID])); + print_uint(PRINT_ANY, "remid", " remid=3D%u", + rta_getattr_u8(tb[MPTCP_ATTR_REM_ID])); if (tb[MPTCP_ATTR_LOC_ID]) - printf(" locid=3D%u", rta_getattr_u8(tb[MPTCP_ATTR_LOC_ID])); + print_uint(PRINT_ANY, "locid", " locid=3D%u", + rta_getattr_u8(tb[MPTCP_ATTR_LOC_ID])); =20 if (tb[MPTCP_ATTR_SADDR4]) print_addr("saddr4", AF_INET, tb[MPTCP_ATTR_SADDR4]); @@ -543,49 +550,74 @@ static int mptcp_monitor_msg(struct rtnl_ctrl_data *c= trl, if (tb[MPTCP_ATTR_DADDR6]) print_addr("daddr6", AF_INET6, tb[MPTCP_ATTR_DADDR6]); if (tb[MPTCP_ATTR_SPORT]) - printf(" sport=3D%u", rta_getattr_be16(tb[MPTCP_ATTR_SPORT])); + print_uint(PRINT_ANY, "sport", " sport=3D%u", + rta_getattr_be16(tb[MPTCP_ATTR_SPORT])); if (tb[MPTCP_ATTR_DPORT]) - printf(" dport=3D%u", rta_getattr_be16(tb[MPTCP_ATTR_DPORT])); + print_uint(PRINT_ANY, "dport", " dport=3D%u", + rta_getattr_be16(tb[MPTCP_ATTR_DPORT])); if (tb[MPTCP_ATTR_BACKUP]) - printf(" backup=3D%u", rta_getattr_u8(tb[MPTCP_ATTR_BACKUP])); + print_uint(PRINT_ANY, "backup", " backup=3D%u", + rta_getattr_u8(tb[MPTCP_ATTR_BACKUP])); if (tb[MPTCP_ATTR_ERROR]) - printf(" error=3D%u", rta_getattr_u8(tb[MPTCP_ATTR_ERROR])); + print_uint(PRINT_ANY, "error", " error=3D%u", + rta_getattr_u8(tb[MPTCP_ATTR_ERROR])); if (tb[MPTCP_ATTR_TIMEOUT]) - printf(" timeout=3D%u", rta_getattr_u32(tb[MPTCP_ATTR_TIMEOUT])); + print_uint(PRINT_ANY, "timeout", " timeout=3D%u", + rta_getattr_u32(tb[MPTCP_ATTR_TIMEOUT])); if (tb[MPTCP_ATTR_IF_IDX]) print_iface(rta_getattr_s32(tb[MPTCP_ATTR_IF_IDX])); if (tb[MPTCP_ATTR_RESET_REASON]) - printf(" reset_reason=3D%u", rta_getattr_u32(tb[MPTCP_ATTR_RESET_REASON]= )); + print_uint(PRINT_ANY, "reset_reason", " reset_reason=3D%u", + rta_getattr_u32(tb[MPTCP_ATTR_RESET_REASON])); if (tb[MPTCP_ATTR_RESET_FLAGS]) - printf(" reset_flags=3D0x%x", rta_getattr_u32(tb[MPTCP_ATTR_RESET_FLAGS]= )); + print_0xhex(PRINT_ANY, "reset_flags", " reset_flags=3D%#x", + rta_getattr_u32(tb[MPTCP_ATTR_RESET_FLAGS])); =20 if (tb[MPTCP_ATTR_FLAGS]) flags =3D rta_getattr_u16(tb[MPTCP_ATTR_FLAGS]); if ((flags & MPTCP_PM_EV_FLAG_SERVER_SIDE) || (tb[MPTCP_ATTR_SERVER_SIDE] && rta_getattr_u8(tb[MPTCP_ATTR_SERVER_SI= DE]))) { flags &=3D ~MPTCP_PM_EV_FLAG_SERVER_SIDE; - printf(" server_side"); + print_string(PRINT_FP, NULL, " server_side", NULL); + print_bool(PRINT_JSON, "server_side", NULL, true); } if (flags & MPTCP_PM_EV_FLAG_DENY_JOIN_ID0) { flags &=3D ~MPTCP_PM_EV_FLAG_DENY_JOIN_ID0; - printf(" deny_join_id0"); + print_string(PRINT_FP, NULL, " deny_join_id0", NULL); + print_bool(PRINT_JSON, "deny_join_id0", NULL, true); } if (flags) /* remaining bits */ - printf(" flags=3D0x%x", flags); + print_0xhex(PRINT_ANY, "flags", " flags=3D%#x", flags); =20 - puts(""); out: + print_nl(); + close_json_object(); fflush(stdout); + return 0; } =20 +static void sig_exit(int signo) +{ + exit(0); +} + static int mptcp_monitor(void) { + struct sigaction sa =3D { .sa_handler =3D sig_exit, + .sa_flags =3D SA_RESTART }; + if (genl_add_mcast_grp(&genl_rth, genl_family, MPTCP_PM_EV_GRP_NAME) < 0)= { perror("can't subscribe to mptcp events"); return 1; } =20 + new_json_obj(json); + atexit(delete_json_obj); + + sigaction(SIGINT, &sa, NULL); + sigaction(SIGTERM, &sa, NULL); + if (rtnl_listen(&genl_rth, mptcp_monitor_msg, stdout) < 0) return 2; =20 --=20 2.51.0