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 for Android: free password hash cracker in your pocket
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <99a4a6ffec5d9e7b508863873bf2097bfbb79ec6.1572534380.git.aclaudi@redhat.com>
Date:   Thu, 31 Oct 2019 16:09:30 +0100
From:   Andrea Claudi <aclaudi@...hat.com>
To:     netdev@...r.kernel.org
Cc:     stephen@...workplumber.org, dsahern@...il.com
Subject: [PATCH iproute2] ip-route: fix json formatting for multipath routing

json output for multipath routing is broken due to some non-jsonified
print in print_rta_multipath(). To reproduce the issue:

$ ip route add default \
  nexthop via 192.168.1.1 weight 1 \
  nexthop via 192.168.2.1 weight 1
$ ip -j route | jq
parse error: Invalid numeric literal at line 1, column 58

Fix this opening a "multipath" json array that can contain multiple
route objects, and using print_*() instead of fprintf().

This is the output for the above commands applying this patch:

[
  {
    "dst": "default",
    "flags": [],
    "multipath": [
      {
        "gateway": "192.168.1.1",
        "dev": "wlp61s0",
        "weight": 1,
        "flags": [
          "linkdown"
        ]
      },
      {
        "gateway": "192.168.2.1",
        "dev": "ens1u1",
        "weight": 1,
        "flags": []
      }
    ]
  }
]

Fixes: f48e14880a0e5 ("iproute: refactor multipath print")
Signed-off-by: Andrea Claudi <aclaudi@...hat.com>
Reported-by: Patrick Hagara <phagara@...hat.com>
---
 ip/iproute.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index a453385113cb9..4c268c72c5bd6 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -649,12 +649,16 @@ static void print_rta_multipath(FILE *fp, const struct rtmsg *r,
 	int len = RTA_PAYLOAD(rta);
 	int first = 1;
 
+	open_json_array(PRINT_JSON, "multipath");
+
 	while (len >= sizeof(*nh)) {
 		struct rtattr *tb[RTA_MAX + 1];
 
 		if (nh->rtnh_len > len)
 			break;
 
+		open_json_object(NULL);
+
 		if (!is_json_context()) {
 			if ((r->rtm_flags & RTM_F_CLONED) &&
 			    r->rtm_type == RTN_MULTICAST) {
@@ -689,22 +693,29 @@ static void print_rta_multipath(FILE *fp, const struct rtmsg *r,
 
 		if ((r->rtm_flags & RTM_F_CLONED) &&
 		    r->rtm_type == RTN_MULTICAST) {
-			fprintf(fp, "%s", ll_index_to_name(nh->rtnh_ifindex));
+			print_string(PRINT_ANY, "dev", "%s",
+				     ll_index_to_name(nh->rtnh_ifindex));
 			if (nh->rtnh_hops != 1)
-				fprintf(fp, "(ttl>%d)", nh->rtnh_hops);
-			fprintf(fp, " ");
+				print_uint(PRINT_ANY, "ttl", "(ttl>%d)",
+					   nh->rtnh_hops);
+			print_string(PRINT_FP, NULL, " ", NULL);
 		} else {
-			fprintf(fp, "dev %s ", ll_index_to_name(nh->rtnh_ifindex));
+			print_string(PRINT_ANY, "dev", "dev %s ",
+				     ll_index_to_name(nh->rtnh_ifindex));
 			if (r->rtm_family != AF_MPLS)
-				fprintf(fp, "weight %d ",
-					nh->rtnh_hops+1);
+				print_uint(PRINT_ANY, "weight", "weight %d ",
+					   nh->rtnh_hops + 1);
 		}
 
 		print_rt_flags(fp, nh->rtnh_flags);
 
 		len -= NLMSG_ALIGN(nh->rtnh_len);
 		nh = RTNH_NEXT(nh);
+
+		close_json_object();
 	}
+
+	close_json_array(PRINT_JSON, "multipath");
 }
 
 int print_route(struct nlmsghdr *n, void *arg)
-- 
2.21.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ