Skip to content

Commit

Permalink
bgpd: remove make_json option from bgp large community
Browse files Browse the repository at this point in the history
The bgp large community library stores a json pointer that is no more
used. Remove the 'make_json' argument of the associated
functions. Remove the 'json' attribute from the bgp large community
structure.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Sep 20, 2024
1 parent 82932d0 commit 107585e
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 54 deletions.
2 changes: 1 addition & 1 deletion bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_clist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions bgpd/bgp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
52 changes: 9 additions & 43 deletions bgpd/bgp_lcommunity.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 1 addition & 5 deletions bgpd/bgp_lcommunity.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 107585e

Please sign in to comment.