]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Fix json output
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Wed, 26 Jul 2017 21:14:07 +0000 (14:14 -0700)
committerMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Thu, 17 Aug 2017 08:42:53 +0000 (01:42 -0700)
Ticket: CM-17259
Review: CCR-6512
Testing: Manual

Signed-off-by: Mitesh Kanjariya <mitesh@cumulusnetworks.com>
bgpd/bgp_route.c

index 40d6fd7bfd4c6885e3ce754627d75c806fc1d81a..3a3da6fc4e5c93eb3213f7f13425e10755fc4a50 100644 (file)
@@ -6235,17 +6235,26 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty,
        char buf[BUFSIZ];
 
        if (p->family == AF_INET) {
-               len = vty_out(vty, "%s",
-                             inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ));
-               destination = ntohl(p->u.prefix4.s_addr);
-
-               if ((IN_CLASSC(destination) && p->prefixlen == 24)
-                   || (IN_CLASSB(destination) && p->prefixlen == 16)
-                   || (IN_CLASSA(destination) && p->prefixlen == 8)
-                   || p->u.prefix4.s_addr == 0) {
-                       /* When mask is natural, mask is not displayed. */
-               } else
-                       len += vty_out(vty, "/%d", p->prefixlen);
+               if (!json) {
+                       len = vty_out(vty, "%s",
+                                     inet_ntop(p->family, &p->u.prefix, buf,
+                                               BUFSIZ));
+                       destination = ntohl(p->u.prefix4.s_addr);
+
+                       if ((IN_CLASSC(destination) && p->prefixlen == 24)
+                           || (IN_CLASSB(destination) && p->prefixlen == 16)
+                           || (IN_CLASSA(destination) && p->prefixlen == 8)
+                           || p->u.prefix4.s_addr == 0) {
+                               /* When mask is natural, mask is not displayed. */
+                       } else
+                               len += vty_out(vty, "/%d", p->prefixlen);
+               } else {
+                       json_object_string_add(json, "prefix",
+                                              inet_ntop(p->family,
+                                                        &p->u.prefix, buf,
+                                                        BUFSIZ));
+                       json_object_int_add(json, "prefixLen", p->prefixlen);
+               }
        } else if (p->family == AF_ETHERNET) {
                prefix2str(p, buf, PREFIX_STRLEN);
                len = vty_out(vty, "%s", buf);
@@ -6262,9 +6271,11 @@ static void route_vty_out_route(struct prefix *p, struct vty *vty,
                len = vty_out(vty, "%s", buf);
 #endif
        } else {
-               len = vty_out(vty, "%s/%d",
-                             inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
-                             p->prefixlen);
+               if (!json)
+                       len = vty_out(vty, "%s/%d",
+                                     inet_ntop(p->family, &p->u.prefix, buf,
+                                               BUFSIZ),
+                                     p->prefixlen);
        }
 
        if (!json) {