if (com == NULL || com->size == 0)
str = "";
else
- str = community_str(com, false);
+ str = community_str(com, false, true);
regstr = bgp_alias2community_str(str);
if (com == NULL || com->size == 0)
str = "";
else
- str = lcommunity_str(com, false);
+ str = lcommunity_str(com, false, true);
regstr = bgp_alias2community_str(str);
0xFFFFFF04 "no-peer"
For other values, "AS:VAL" format is used. */
-static void set_community_string(struct community *com, bool make_json)
+static void set_community_string(struct community *com, bool make_json,
+ bool translate_alias)
{
int i;
char *str;
val = comval & 0xFFFF;
char buf[32];
snprintf(buf, sizeof(buf), "%u:%d", as, val);
- const char *com2alias = bgp_community2alias(buf);
+ const char *com2alias =
+ translate_alias ? bgp_community2alias(buf)
+ : buf;
strlcat(str, com2alias, len);
if (make_json) {
/* Make string. */
if (!find->str)
- set_community_string(find, false);
+ set_community_string(find, false, true);
return find;
}
}
/* Return string representation of communities attribute. */
-char *community_str(struct community *com, bool make_json)
+char *community_str(struct community *com, bool make_json, bool translate_alias)
{
if (!com)
return NULL;
XFREE(MTYPE_COMMUNITY_STR, com->str);
if (!com->str)
- set_community_string(com, make_json);
+ set_community_string(com, make_json, translate_alias);
return com->str;
}
extern struct community *community_parse(uint32_t *, unsigned short);
extern struct community *community_intern(struct community *);
extern void community_unintern(struct community **);
-extern char *community_str(struct community *, bool make_json);
+extern char *community_str(struct community *, bool make_json,
+ bool translate_alias);
extern unsigned int community_hash_make(const struct community *);
extern struct community *community_str2com(const char *);
extern bool community_match(const struct community *, const struct community *);
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", community %s",
- community_str(attr->community, false));
+ community_str(attr->community, false, true));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", large-community %s",
- lcommunity_str(attr->lcommunity, false));
+ lcommunity_str(attr->lcommunity, false, true));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
return lcom1;
}
-static void set_lcommunity_string(struct lcommunity *lcom, bool make_json)
+static void set_lcommunity_string(struct lcommunity *lcom, bool make_json,
+ bool translate_alias)
{
int i;
int len;
snprintf(lcsb, sizeof(lcsb), "%u:%u:%u", global, local1,
local2);
- const char *com2alias = bgp_community2alias(lcsb);
+ const char *com2alias =
+ translate_alias ? bgp_community2alias(lcsb) : lcsb;
len = strlcat(str_buf, com2alias, str_buf_sz);
assert((unsigned int)len < str_buf_sz);
find->refcnt++;
if (!find->str)
- set_lcommunity_string(find, false);
+ set_lcommunity_string(find, false, true);
return find;
}
}
/* Return string representation of lcommunities attribute. */
-char *lcommunity_str(struct lcommunity *lcom, bool make_json)
+char *lcommunity_str(struct lcommunity *lcom, bool make_json,
+ bool translate_alias)
{
if (!lcom)
return NULL;
XFREE(MTYPE_LCOMMUNITY_STR, lcom->str);
if (!lcom->str)
- set_lcommunity_string(lcom, make_json);
+ set_lcommunity_string(lcom, make_json, translate_alias);
return lcom->str;
}
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);
+extern char *lcommunity_str(struct lcommunity *, bool make_json,
+ bool translate_alias);
extern bool lcommunity_include(struct lcommunity *lcom, uint8_t *ptr);
extern void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr);
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) {
if (json_paths) {
if (!attr->community->json)
- community_str(attr->community, true);
+ community_str(attr->community, true, true);
json_object_lock(attr->community->json);
json_object_object_add(json_path, "community",
attr->community->json);
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
if (json_paths) {
if (!attr->lcommunity->json)
- lcommunity_str(attr->lcommunity, true);
+ lcommunity_str(attr->lcommunity, true, true);
json_object_lock(attr->lcommunity->json);
json_object_object_add(json_path, "largeCommunity",
attr->lcommunity->json);
str = buffer_getstr(b);
buffer_free(b);
- if (str) {
+ if (str)
com = community_str2com(str);
- XFREE(MTYPE_TMP, str);
- }
/* Can't compile user input into communities attribute. */
if (!com) {
- vty_out(vty, "%% Malformed communities attribute\n");
+ vty_out(vty, "%% Malformed communities attribute '%s'\n", str);
+ XFREE(MTYPE_TMP, str);
return CMD_WARNING_CONFIG_FAILED;
}
+ XFREE(MTYPE_TMP, str);
/* Set communites attribute string. */
- str = community_str(com, false);
+ str = community_str(com, false, false);
if (additive) {
size_t argstr_sz = strlen(str) + strlen(" additive") + 1;
com = (struct community *)bucket->data;
vty_out(vty, "[%p] (%ld) %s\n", (void *)com, com->refcnt,
- community_str(com, false));
+ community_str(com, false, false));
}
/* Show BGP's community internal data. */
lcom = (struct lcommunity *)bucket->data;
vty_out(vty, "[%p] (%ld) %s\n", (void *)lcom, lcom->refcnt,
- lcommunity_str(lcom, false));
+ lcommunity_str(lcom, false, false));
}
/* Show BGP's community internal data. */
str = "";
else {
if (entry->style == COMMUNITY_LIST_STANDARD)
- str = community_str(entry->u.com, false);
+ str = community_str(entry->u.com, false, false);
else if (entry->style == LARGE_COMMUNITY_LIST_STANDARD)
- str = lcommunity_str(entry->u.lcom, false);
+ str = lcommunity_str(entry->u.lcom, false, false);
else
str = entry->config;
}