diff options
| author | Quentin Young <qlyoung@nvidia.com> | 2021-08-10 11:42:52 -0400 |
|---|---|---|
| committer | Quentin Young <qlyoung@nvidia.com> | 2021-08-12 16:26:01 -0400 |
| commit | 6ddb368d6be64b7ec8cc68630944a6e06088e7af (patch) | |
| tree | 07919331cbda9ca64aa121f5cd5de47d037fade6 /ospf6d/ospf6_lsa.c | |
| parent | 0c0830c599d61bcbb45a6a7ef6b6dea5b77f957b (diff) | |
ospf6d: JSON output for database dump show command
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>
Diffstat (limited to 'ospf6d/ospf6_lsa.c')
| -rw-r--r-- | ospf6d/ospf6_lsa.c | 55 |
1 files changed, 38 insertions, 17 deletions
diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 9c03ce21ed..1bc1ce9cdf 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -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; } |
