lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-Id: <20190919155136.23758-1-dsahern@kernel.org>
Date:   Thu, 19 Sep 2019 08:51:36 -0700
From:   David Ahern <dsahern@...nel.org>
To:     stephen@...workplumber.org
Cc:     netdev@...r.kernel.org, David Ahern <dsahern@...il.com>
Subject: [PATCH iproute2-next] ip vrf: Add json support for show command

From: David Ahern <dsahern@...il.com>

Add json support to 'ip vrf sh':
$ ip -j -p vrf ls
[ {
        "name": "mgmt",
        "table": 1001
    } ]

Signed-off-by: David Ahern <dsahern@...il.com>
---
 ip/ipvrf.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index 43366f6e25f0..b9a43675cbd6 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -566,9 +566,12 @@ static int ipvrf_print(struct nlmsghdr *n)
 		return 0;
 	}
 
-	printf("%-16s %5u", name, tb_id);
+	open_json_object(NULL);
+	print_string(PRINT_ANY, "name", "%-16s", name);
+	print_uint(PRINT_ANY, "table", " %5u", tb_id);
+	print_string(PRINT_FP, NULL, "%s", "\n");
+	close_json_object();
 
-	printf("\n");
 	return 1;
 }
 
@@ -597,15 +600,21 @@ static int ipvrf_show(int argc, char **argv)
 	if (ip_link_list(ipvrf_filter_req, &linfo) == 0) {
 		struct nlmsg_list *l;
 		unsigned nvrf = 0;
-		int n;
 
-		n = printf("%-16s  %5s\n", "Name", "Table");
-		printf("%.*s\n", n-1, "-----------------------");
+		new_json_obj(json);
+
+		print_string(PRINT_FP, NULL, "%-16s", "Name");
+		print_string(PRINT_FP, NULL, "  %5s\n", "Table");
+		print_string(PRINT_FP, NULL, "%s\n",
+			     "-----------------------");
+
 		for (l = linfo.head; l; l = l->next)
 			nvrf += ipvrf_print(&l->h);
 
 		if (!nvrf)
-			printf("No VRF has been configured\n");
+			print_string(PRINT_FP, NULL, "%s\n",
+				     "No VRF has been configured");
+		delete_json_obj();
 	} else
 		rc = 1;
 
-- 
2.11.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ