From nobody Mon Mar 2 06:39:59 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 38D7E366DAB; Fri, 20 Feb 2026 18:54:17 +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=1771613657; cv=none; b=si0dTmjsb/UHdE0iNsLqSdz3Pgcj+iUP9jc5/ALOQNIJUbz2fWjltu55s3mYPDZurLdSvbnvKp85UR2LZrYzhislqofHRa0+ROky8RkgPGtlRE0o5beJEMfkuX0cW9u6HSEWXm4bdAyG9kujzvlg1uUA8iZvc0CltEc/BEnqde8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771613657; c=relaxed/simple; bh=VT10bXnZOZstjp5Z5qwmfPi+JX233sJrsM9ySP83Dxo=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ukr5VCu5vz6XZnbhddV7hBx8ar6Txmp94nHUKX+NYDqAP3qYJwozVSpSFgGajeGvNPsA9n85G3+3AmeH9ZVPlzhJjMoQ9I5XZD5SJVnBnTnsIBKqQvGtOgfkgYODAfHAfHvIOiUbtgyx7H5WRbjC1tOzmlqbysBH8XSy0OZHaj8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hf5h3Tz6; 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="hf5h3Tz6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CD83C19425; Fri, 20 Feb 2026 18:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771613657; bh=VT10bXnZOZstjp5Z5qwmfPi+JX233sJrsM9ySP83Dxo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=hf5h3Tz6+sMQQLjbFBrnQcBFWC0SlXNRV7/ZmwKPx8SdCo0uH/vdIRzBc+DT7Pp9y a2wEEoZbbUip647+RucobHmgI0g9IMZ/HGMS/RpnagkTkdkJTv3cadSJDXLT/82NPN vGCqyZG4HARi3x0dxnEPIWJWhXeEdc3qI3Uiq5T629p4i0Gf82jZJlnaGtnD4dKw6I +dePGqXTblVj1c4tPrky48oGqUZWwxn8WV8pNx2E5oGPZg6XD9BBSY32aDq8gOM7SB b6o0Iq/iDhGrrSbUQGreVkxTBpb5VOwx4Vg4OSa/1dvT5H6lv0OTaUHerF/wFjWeDV 5F5u47e+m3qMg== From: "Matthieu Baerts (NGI0)" Date: Fri, 20 Feb 2026 19:54:01 +0100 Subject: [PATCH iproute2-next 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: <20260220-ipr-monitor-json-v1-1-eb4b0d5f7820@kernel.org> References: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@kernel.org> In-Reply-To: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@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=917; i=matttbe@kernel.org; h=from:subject:message-id; bh=VT10bXnZOZstjp5Z5qwmfPi+JX233sJrsM9ySP83Dxo=; b=kA0DAAoWfCLwwvNHCpcByyZiAGmYrdTIGeRqWFY3yOeED5a6jA9m2fRAjZwlfr2z6xRlfcuMM Yh1BAAWCgAdFiEEG4ZZb5nneg10Sk44fCLwwvNHCpcFAmmYrdQACgkQfCLwwvNHCpf31AEA9+5g w8WnKnsu/TFb5KAEF+wDUT70Z2ruCYR1aNIENfoA/i2pjaRb0MEYKlyQKCzT0DLv1mMUTqWD40q ilEs9444L 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. 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:59 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 55A4C366DBE; Fri, 20 Feb 2026 18:54:18 +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=1771613658; cv=none; b=ZC6FzCi5gw2lSVscav9+qJIP9DNfWKGE0VLMo7jc66ggmlyzRnG5eUlAp7eoQ3KQUpAN/Nfals4671++Pwv5rxfsLKrtMsi0HN3I+yd3A9joBEc4i+bPqZHgFxmf13AI/EvrpmYIPH+JqmivbubKfw16/dsir3IaaLVNRM1TZv8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771613658; c=relaxed/simple; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=p3z1Zsygwc8TWjiWtVvB/xYiMApDFk4mQjDbCiXwcOKvNf7Je7n82MTuoncVsiX6JrIKhC82MFSW15sMQaQNIHMl5qvGjDRKhs1+Nn+9V4zxg29Jobf1WnrTviqGL3LkBLODeOf5UXE7m1mFmmRTZsyQ/GJnrYWFxYFPaRpiDXA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ElPgYIf0; 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="ElPgYIf0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5DD7BC116C6; Fri, 20 Feb 2026 18:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771613658; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ElPgYIf0zwKggKMPLF1/mu25RlHvSTsWcDMXFFnTL8YRyZqmWMeIaF4tf7NC4lWNc r9oC88bK6dZVmF/ewy28ZcRk+gX61l5k1spX9q9nG3+rKRoeBDxNc31z9mF41pBKJa 2P7M8WBb69DjPV2S0DpHZM7QT8i4L+IAQvrxJ6PQyAkW1NiIV4idu3K7Pxjds6KvhQ QqpzWav3z0jpjGmeQdncd3afQDU61yAY8ITlAgzounPaipdvAQFdJeAH1YEqs7UsR/ 5V532GYpdFjwYiNgLMQxCqdUl3wRj4Pg0JXrB3g0+e4GBH2WpxzhZAM/XEid/ZZqGY EHJNukc71nRfw== From: "Matthieu Baerts (NGI0)" Date: Fri, 20 Feb 2026 19:54:02 +0100 Subject: [PATCH iproute2-next 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: <20260220-ipr-monitor-json-v1-2-eb4b0d5f7820@kernel.org> References: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@kernel.org> In-Reply-To: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@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=1618; i=matttbe@kernel.org; h=from:subject:message-id; bh=9ND4Te+vCD8kxlRnTEnyhPCkkUOH5B3APGIVy4z0UiM=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJnrL1aNlHkRPy2eSs4bksaaYXnFU+1v3Nr8rz01G2ez /bHPGGu7ihlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZjIu2MMv1m8zDyu71ketrdN zGb/hleXpi6dWb9A8tWz9uwf5rM4WkMYfrMzNpgvj/KqFH7I/v7C/KIJNUsz9JJW7wxysQ8Lexe zkB8A X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 Only if the output stream is 'stdout', because all JSON helpers like print_string() only write on 'stdout'. Supporting JSON is easy with the helpers. The biggest modification is to extract the end value. No behavioural changes intended for the moment, this is a preparation for a future usage of print_timestamp() within a JSON context. Signed-off-by: Matthieu Baerts (NGI0) --- lib/utils.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/utils.c b/lib/utils.c index 13e8c098..d7581709 100644 --- a/lib/utils.c +++ b/lib/utils.c @@ -1277,21 +1277,30 @@ 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); + if (fp =3D=3D stdout) + print_string(PRINT_ANY, "timestamp_short", "[%s] ", ts); + else + fprintf(fp, "[%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); + if (fp =3D=3D stdout) + print_string(PRINT_ANY, "timestamp", + "Timestamp: %s\n", ts); + else + fprintf(fp, "Timestamp: %s\n", ts); } =20 return 0; --=20 2.51.0 From nobody Mon Mar 2 06:39:59 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 CAD8E309DDC; Fri, 20 Feb 2026 18:54:19 +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=1771613659; cv=none; b=qwKD2tDP9JH2K20LMRpwM+K/O07TBiMcupXfifIf+Gw+mlczwi+58x52f6uRL/otZ+y5bU6NY46CqmkQJLxw71Sqi9FdB0xA6i5n4l9CdOWd9w9rCFNi5CQRJbKMocGgfx+3M9OuV2/fo38KteSPpHozPIEZ9k7tVZ8tvJWMfxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771613659; c=relaxed/simple; bh=kZ7T4vbLUXDKQ17IlLgmTMSibj0aZOJgM0z313YivSY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Eb/MG3dXUkwgSNjh9FzPTx+4YUdBRRXd1XLN4bxgq4fB3bZ8cf8LdCKUZxWiNVBu+Cfm0Y2/5OveajYKQWv2Y4Zw5Rt9Row7e55ekdiMBZ/hNzHiz8fXVrqnLBTW4WKsMBomsqgXuc3hstvIA9y2o9fPsW9WLrbU9c+VN7R4Vec= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HuUAWBP8; 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="HuUAWBP8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F30BC19424; Fri, 20 Feb 2026 18:54:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771613659; bh=kZ7T4vbLUXDKQ17IlLgmTMSibj0aZOJgM0z313YivSY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=HuUAWBP880lAmefrMpf0L+bo/05NRCNZoqPjqnfyIsFrFIgAWo1QIIR0AVLUxjc8W xVARvpO/R+amslmMVdxEzkPKIL37vgjAH2DL1sK+ylX3CEQOko6X/cci0f5hs0Htax STQt3l6vZNfAvm/CPY7HQCL1h4s1y86ihVofcdhXd/FfiHwuuajhx6j1VJ9U0pPqnV MclrfGQ+QhSAVP1OZa1FyKQ+FX17siGhzOI6QQF3s4F23r+kVO/0n/edM9p3FtwXON Kpd1mXi6jO+HcgkcrURhKot5I2JJWYXKVy2hTvTO5Rwaltl7nXqB7FDDH0E1fGi3nu pQf1wGlnqzxrw== From: "Matthieu Baerts (NGI0)" Date: Fri, 20 Feb 2026 19:54:03 +0100 Subject: [PATCH iproute2-next 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: <20260220-ipr-monitor-json-v1-3-eb4b0d5f7820@kernel.org> References: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@kernel.org> In-Reply-To: <20260220-ipr-monitor-json-v1-0-eb4b0d5f7820@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=6393; i=matttbe@kernel.org; h=from:subject:message-id; bh=kZ7T4vbLUXDKQ17IlLgmTMSibj0aZOJgM0z313YivSY=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJnrL3mKcsztbdixvRpW+50xbN+aPx2pzkqUjRr97oFQ ouEZXgdO0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACbiv5aR4c9V2bgtpfcY+bIN yrw0mcUurZdTW3amkqHoxpq0CUntVxkZXj1eH+J9sdrTMXFie1KAv+zaDsUFapfrNk24r+uwmUG XCwA= 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 close the JSON and print the final ']' when stopping 'ip mptcp monitor' which can only be done via a SIGINT or a SIGTERM. Signed-off-by: Matthieu Baerts (NGI0) --- ip/ipmptcp.c | 88 +++++++++++++++++++++++++++++++++++++++++---------------= ---- 1 file changed, 61 insertions(+), 27 deletions(-) diff --git a/ip/ipmptcp.c b/ip/ipmptcp.c index 18ec05a8..87557998 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_uint(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,42 +550,60 @@ 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_json(int signo) +{ + delete_json_obj(); + rtnl_close(&genl_rth); + exit(0); +} + static int mptcp_monitor(void) { if (genl_add_mcast_grp(&genl_rth, genl_family, MPTCP_PM_EV_GRP_NAME) < 0)= { @@ -586,6 +611,15 @@ static int mptcp_monitor(void) return 1; } =20 + new_json_obj(json); + + if (is_json_context()) { + struct sigaction sa =3D { .sa_handler =3D sig_exit_json }; + + 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