diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 08f60cde1aa0..9182e9cce6fe 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -990,7 +990,7 @@ static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty) vty_out(vty, "\taspath: %s Community: %s Large Community: %s\n", aspath_print(attr->aspath), community_str(attr->community, false), - lcommunity_str(attr->lcommunity, false, false)); + lcommunity_str(attr->lcommunity, false)); vty_out(vty, "\tExtended Community: %s Extended IPv6 Community: %s\n", ecommunity_str(attr->ecommunity), ecommunity_str(attr->ipv6_ecommunity)); diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 3f4871464ea9..01ec5b4b6bbf 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -614,7 +614,7 @@ static bool lcommunity_regexp_match(struct lcommunity *com, regex_t *reg) if (com == NULL || com->size == 0) str = ""; else - str = lcommunity_str(com, false, true); + str = lcommunity_str(com, true); regstr = bgp_alias2community_str(str); diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index af1beb5fcd41..7f0520c0fa0a 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -439,8 +439,7 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), ", large-community %s", - lcommunity_str(bgp_attr_get_lcommunity(attr), false, - true)); + lcommunity_str(bgp_attr_get_lcommunity(attr), true)); if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index 96c1e00f8368..a1b94f5d0501 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -36,8 +36,6 @@ void lcommunity_free(struct lcommunity **lcom) XFREE(MTYPE_LCOMMUNITY_VAL, (*lcom)->val); XFREE(MTYPE_LCOMMUNITY_STR, (*lcom)->str); - if ((*lcom)->json) - json_object_free((*lcom)->json); XFREE(MTYPE_LCOMMUNITY, *lcom); } @@ -167,17 +165,15 @@ struct lcommunity *lcommunity_merge(struct lcommunity *lcom1, /* Convert large communities attribute to string and optionally add json objects * into the pased json_community_list string */ -static char *lcommunity_json_list(struct lcommunity *lcom, - json_object *json_lcommunity_list, - bool translate_alias, bool return_buffer, - struct printbuf *pb, bool incremental_print) +static char *lcommunity_json_list(struct lcommunity *lcom, bool translate_alias, + bool return_buffer, struct printbuf *pb, + bool incremental_print) { int i, len; const uint8_t *pnt; uint32_t global, local1, local2; char *str_buf = NULL; size_t str_buf_sz = 0; - json_object *json_string = NULL; /* 1 space + lcom->size lcom strings + null terminator */ if (return_buffer) { @@ -221,51 +217,25 @@ static char *lcommunity_json_list(struct lcommunity *lcom, if (incremental_print) sprintbuf(pb, "%s\"%s\"", i ? "," : "", com2alias); - else if (json_lcommunity_list) { - json_string = json_object_new_string(com2alias); - json_object_array_add(json_lcommunity_list, - json_string); - } } return str_buf; } -static void set_lcommunity_string(struct lcommunity *lcom, bool make_json, - bool translate_alias) +static void set_lcommunity_string(struct lcommunity *lcom, bool translate_alias) { char *str_buf; - json_object *json_lcommunity_list = NULL; if (!lcom) return; - if (make_json) { - lcom->json = json_object_new_object(); - json_lcommunity_list = json_object_new_array(); - } - if (lcom->size == 0) { str_buf = XCALLOC(MTYPE_LCOMMUNITY_STR, 1); - if (make_json) { - json_object_string_add(lcom->json, "string", ""); - json_object_object_add(lcom->json, "list", - json_lcommunity_list); - } - lcom->str = str_buf; return; } - str_buf = lcommunity_json_list(lcom, - make_json ? json_lcommunity_list : NULL, - translate_alias, true, NULL, false); - - if (make_json) { - json_object_string_add(lcom->json, "string", str_buf); - json_object_object_add(lcom->json, "list", - json_lcommunity_list); - } + str_buf = lcommunity_json_list(lcom, translate_alias, true, NULL, false); lcom->str = str_buf; } @@ -285,7 +255,7 @@ struct lcommunity *lcommunity_intern(struct lcommunity *lcom) find->refcnt++; if (!find->str) - set_lcommunity_string(find, false, true); + set_lcommunity_string(find, true); return find; } @@ -312,17 +282,13 @@ void lcommunity_unintern(struct lcommunity **lcom) } /* Return string representation of lcommunities attribute. */ -char *lcommunity_str(struct lcommunity *lcom, bool make_json, - bool translate_alias) +char *lcommunity_str(struct lcommunity *lcom, bool translate_alias) { if (!lcom) return NULL; - if (make_json && !lcom->json && lcom->str) - XFREE(MTYPE_LCOMMUNITY_STR, lcom->str); - if (!lcom->str) - set_lcommunity_string(lcom, make_json, translate_alias); + set_lcommunity_string(lcom, translate_alias); return lcom->str; } @@ -586,7 +552,7 @@ static int lcommunity_json_to_string(struct json_object *jso, printbuf_memappend(pb, lcom->str, strlen(lcom->str)); printbuf_strappend(pb, "\",\"list\":["); - lcommunity_json_list(lcom, NULL, 0, false, pb, true); + lcommunity_json_list(lcom, 0, false, pb, true); printbuf_strappend(pb, "]}"); return 0; } diff --git a/bgpd/bgp_lcommunity.h b/bgpd/bgp_lcommunity.h index 91a04595f40e..0d96c56875cb 100644 --- a/bgpd/bgp_lcommunity.h +++ b/bgpd/bgp_lcommunity.h @@ -25,9 +25,6 @@ struct lcommunity { /* Large Communities value. */ uint8_t *val; - /* Large Communities as a json object */ - json_object *json; - /* Human readable format string. */ char *str; }; @@ -56,8 +53,7 @@ extern struct hash *lcommunity_hash(void); extern struct lcommunity *lcommunity_str2com(const char *); extern bool lcommunity_match(const struct lcommunity *, const struct lcommunity *); -extern char *lcommunity_str(struct lcommunity *, bool make_json, - bool translate_alias); +extern char *lcommunity_str(struct lcommunity *, bool translate_alias); extern bool lcommunity_include(struct lcommunity *lcom, uint8_t *ptr); extern void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a9d21c337c44..2d758091d1ce 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -16454,7 +16454,7 @@ static void lcommunity_show_all_iterator(struct hash_bucket *bucket, lcom = (struct lcommunity *)bucket->data; vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt, - lcommunity_str(lcom, false, false)); + lcommunity_str(lcom, false)); } /* Show BGP's community internal data. */ @@ -22216,7 +22216,7 @@ static const char *community_list_config_str(struct community_entry *entry) if (entry->style == COMMUNITY_LIST_STANDARD) str = community_str(entry->u.com, false); else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) - str = lcommunity_str(entry->u.lcom, false, false); + str = lcommunity_str(entry->u.lcom, false); else str = entry->config;