return NULL;
new = community_new();
- ;
new->json = NULL;
for (i = 0; i < com->size; i++) {
0xFFFFFF03 "local-AS"
For other values, "AS:VAL" format is used. */
-static void set_community_string(struct community *com)
+static void set_community_string(struct community *com, bool make_json)
{
int i;
char *str;
if (!com)
return;
- com->json = json_object_new_object();
- json_community_list = json_object_new_array();
+ if (make_json) {
+ com->json = json_object_new_object();
+ json_community_list = json_object_new_array();
+ }
/* When communities attribute is empty. */
if (com->size == 0) {
str = XMALLOC(MTYPE_COMMUNITY_STR, 1);
str[0] = '\0';
- json_object_string_add(com->json, "string", "");
- json_object_object_add(com->json, "list", json_community_list);
+ if (make_json) {
+ json_object_string_add(com->json, "string", "");
+ json_object_object_add(com->json, "list", json_community_list);
+ }
com->str = str;
return;
}
case COMMUNITY_INTERNET:
strcpy(pnt, "internet");
pnt += strlen("internet");
- json_string = json_object_new_string("internet");
- json_object_array_add(json_community_list, json_string);
+ if (make_json) {
+ json_string = json_object_new_string("internet");
+ json_object_array_add(json_community_list, json_string);
+ }
break;
case COMMUNITY_NO_EXPORT:
strcpy(pnt, "no-export");
pnt += strlen("no-export");
- json_string = json_object_new_string("noExport");
- json_object_array_add(json_community_list, json_string);
+ if (make_json) {
+ json_string = json_object_new_string("noExport");
+ json_object_array_add(json_community_list, json_string);
+ }
break;
case COMMUNITY_NO_ADVERTISE:
strcpy(pnt, "no-advertise");
pnt += strlen("no-advertise");
- json_string = json_object_new_string("noAdvertise");
- json_object_array_add(json_community_list, json_string);
+ if (make_json) {
+ json_string = json_object_new_string("noAdvertise");
+ json_object_array_add(json_community_list, json_string);
+ }
break;
case COMMUNITY_LOCAL_AS:
strcpy(pnt, "local-AS");
pnt += strlen("local-AS");
- json_string = json_object_new_string("localAs");
- json_object_array_add(json_community_list, json_string);
+ if (make_json) {
+ json_string = json_object_new_string("localAs");
+ json_object_array_add(json_community_list, json_string);
+ }
break;
default:
as = (comval >> 16) & 0xFFFF;
val = comval & 0xFFFF;
sprintf(pnt, "%u:%d", as, val);
- json_string = json_object_new_string(pnt);
- json_object_array_add(json_community_list, json_string);
+ if (make_json) {
+ json_string = json_object_new_string(pnt);
+ json_object_array_add(json_community_list, json_string);
+ }
pnt += strlen(pnt);
break;
}
}
*pnt = '\0';
- json_object_string_add(com->json, "string", str);
- json_object_object_add(com->json, "list", json_community_list);
+ if (make_json) {
+ json_object_string_add(com->json, "string", str);
+ json_object_object_add(com->json, "list", json_community_list);
+ }
com->str = str;
}
/* Make string. */
if (!find->str)
- set_community_string(find);
+ set_community_string(find, false);
return find;
}
}
/* Retrun string representation of communities attribute. */
-char *community_str(struct community *com)
+char *community_str(struct community *com, bool make_json)
{
if (!com)
return NULL;
+ if (make_json && !com->json && com->str)
+ XFREE(MTYPE_COMMUNITY_STR, com->str);
+
if (!com->str)
- set_community_string(com);
+ set_community_string(com, make_json);
return com->str;
}
com = (struct community *)backet->data;
vty_out(vty, "[%p] (%ld) %s%s", (void *)backet, com->refcnt,
- community_str(com), VTY_NEWLINE);
+ community_str(com, false), VTY_NEWLINE);
}
/* Show BGP's community internal data. */
vty_out(vty, " %s %s%s",
community_direct_str(entry->direct),
entry->style == COMMUNITY_LIST_STANDARD
- ? community_str(entry->u.com)
- : entry->config,
+ ? community_str(entry->u.com, false)
+ : entry->config,
VTY_NEWLINE);
}
}
str = "";
else {
if (entry->style == COMMUNITY_LIST_STANDARD)
- str = community_str(entry->u.com);
+ str = community_str(entry->u.com, false);
else
str = entry->config;
}