Return-Path: Received: from mail-pg0-f67.google.com ([74.125.83.67]:35728 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754078AbeCFVHg (ORCPT ); Tue, 6 Mar 2018 16:07:36 -0500 Received: by mail-pg0-f67.google.com with SMTP id l131so19930pga.2 for ; Tue, 06 Mar 2018 13:07:36 -0800 (PST) From: Stephen Hemminger To: dsahern@gmail.com Cc: netdev@vger.kernel.org, Stephen Hemminger , Stephen Hemminger Subject: [PATCH iproute2-next v2 09/12] token: support JSON Date: Tue, 6 Mar 2018 13:07:17 -0800 Message-Id: <20180306210720.19802-10-stephen@networkplumber.org> In-Reply-To: <20180306210720.19802-1-stephen@networkplumber.org> References: <20180306210720.19802-1-stephen@networkplumber.org> Sender: netdev-owner@vger.kernel.org List-ID: From: Stephen Hemminger Add JSON output to ip token command. Signed-off-by: Stephen Hemminger --- ip/iptoken.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ip/iptoken.c b/ip/iptoken.c index 48cc14b502c6..fb64da4ec262 100644 --- a/ip/iptoken.c +++ b/ip/iptoken.c @@ -25,6 +25,7 @@ #include "rt_names.h" #include "utils.h" #include "ip_common.h" +#include "json_print.h" extern struct rtnl_handle rth; @@ -77,9 +78,17 @@ static int print_token(const struct sockaddr_nl *who, struct nlmsghdr *n, void * return -1; } - fprintf(fp, "token %s dev %s\n", - format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN]), - ll_index_to_name(ifi->ifi_index)); + open_json_object(NULL); + print_string(PRINT_FP, NULL, "token ", NULL); + print_color_string(PRINT_ANY, + ifa_family_color(ifi->ifi_family), + "token", "%s", + format_host_rta(ifi->ifi_family, ltb[IFLA_INET6_TOKEN])); + print_string(PRINT_FP, NULL, " dev ", NULL); + print_color_string(PRINT_ANY, COLOR_IFNAME, + "ifname", "%s\n", + ll_index_to_name(ifi->ifi_index)); + close_json_object(); fflush(fp); return 0; @@ -105,10 +114,13 @@ static int iptoken_list(int argc, char **argv) return -1; } + new_json_obj(json); if (rtnl_dump_filter(&rth, print_token, &da) < 0) { + delete_json_obj(); fprintf(stderr, "Dump terminated\n"); return -1; } + delete_json_obj(); return 0; } -- 2.16.1