]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ospf6d: JSON output for database dump show command
authorQuentin Young <qlyoung@nvidia.com>
Tue, 10 Aug 2021 15:42:52 +0000 (11:42 -0400)
committerQuentin Young <qlyoung@nvidia.com>
Thu, 12 Aug 2021 20:26:01 +0000 (16:26 -0400)
Added missing output to "show ipv6 ospf6 databse dump json" VTY shell
command.

Co-authored-by: David Schweizer dschweizer@opensourcerouting.org
Signed-off-by: Quentin Young <qlyoung@nvidia.com>
ospf6d/ospf6_lsa.c

index 9c03ce21ed355cd21079acd49d02a3d514c01d3c..1bc1ce9cdf7c00c9edecdcac34fce281feadf7e6 100644 (file)
@@ -29,6 +29,7 @@
 #include "memory.h"
 #include "thread.h"
 #include "checksum.h"
+#include "frrstr.h"
 
 #include "ospf6_proto.h"
 #include "ospf6_lsa.h"
@@ -80,7 +81,6 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
                                  json_object *json_obj, bool use_json)
 {
        uint8_t *start, *end, *current;
-       char byte[4];
 
        start = (uint8_t *)lsa->header + sizeof(struct ospf6_lsa_header);
        end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
@@ -95,8 +95,7 @@ static int ospf6_unknown_lsa_show(struct vty *vty, struct ospf6_lsa *lsa,
                        else if ((current - start) % 4 == 0)
                                vty_out(vty, " ");
 
-                       snprintf(byte, sizeof(byte), "%02x", *current);
-                       vty_out(vty, "%s", byte);
+                       vty_out(vty, "%02x", *current);
                }
 
                vty_out(vty, "\n\n");
@@ -553,29 +552,51 @@ void ospf6_lsa_show_summary(struct vty *vty, struct ospf6_lsa *lsa,
 void ospf6_lsa_show_dump(struct vty *vty, struct ospf6_lsa *lsa,
                         json_object *json_array, bool use_json)
 {
-       uint8_t *start, *end, *current;
+       uint8_t *start = NULL;
+       uint8_t *end = NULL;
+       uint8_t *current = NULL;
        char byte[4];
+       char *header_str = NULL;
+       char adv_router[INET6_ADDRSTRLEN];
+       char id[INET6_ADDRSTRLEN];
+       json_object *json = NULL;
 
        start = (uint8_t *)lsa->header;
        end = (uint8_t *)lsa->header + ntohs(lsa->header->length);
 
-       if (use_json)
-               return;
+       if (use_json) {
+               json = json_object_new_object();
+               size_t header_str_sz = (2 * (end - start)) + 1;
 
-       vty_out(vty, "\n");
-       vty_out(vty, "%s:\n", lsa->name);
+               header_str = XMALLOC(MTYPE_TMP, header_str_sz);
 
-       for (current = start; current < end; current++) {
-               if ((current - start) % 16 == 0)
-                       vty_out(vty, "\n        ");
-               else if ((current - start) % 4 == 0)
-                       vty_out(vty, " ");
+               inet_ntop(AF_INET, &lsa->header->id, id, sizeof(id));
+               inet_ntop(AF_INET, &lsa->header->adv_router, adv_router,
+                         sizeof(adv_router));
 
-               snprintf(byte, sizeof(byte), "%02x", *current);
-               vty_out(vty, "%s", byte);
-       }
+               frrstr_hex(header_str, header_str_sz, start, end - start);
+
+               json_object_string_add(json, "linkStateId", id);
+               json_object_string_add(json, "advertisingRouter", adv_router);
+               json_object_string_add(json, "header", header_str);
+               json_object_array_add(json_array, json);
+
+               XFREE(MTYPE_TMP, header_str);
+       } else {
+               vty_out(vty, "\n%s:\n", lsa->name);
+
+               for (current = start; current < end; current++) {
+                       if ((current - start) % 16 == 0)
+                               vty_out(vty, "\n        ");
+                       else if ((current - start) % 4 == 0)
+                               vty_out(vty, " ");
 
-       vty_out(vty, "\n\n");
+                       snprintf(byte, sizeof(byte), "%02x", *current);
+                       vty_out(vty, "%s", byte);
+               }
+
+               vty_out(vty, "\n\n");
+       }
 
        return;
 }