static bool community_regexp_match(struct community *com, regex_t *reg)
{
const char *str;
+ char *regstr;
+ int rv;
/* When there is no communities attribute it is treated as empty
string. */
else
str = community_str(com, false);
+ regstr = bgp_alias2community_str(str);
+
/* Regular expression match. */
- if (regexec(reg, bgp_alias2community_str(str), 0, NULL, 0) == 0)
- return true;
+ rv = regexec(reg, regstr, 0, NULL, 0);
- /* No match. */
- return false;
+ XFREE(MTYPE_TMP, regstr);
+
+ return rv == 0;
}
static char *lcommunity_str_get(struct lcommunity *lcom, int i)
static bool lcommunity_regexp_match(struct lcommunity *com, regex_t *reg)
{
const char *str;
+ char *regstr;
+ int rv;
/* When there is no communities attribute it is treated as empty
string. */
else
str = lcommunity_str(com, false);
+ regstr = bgp_alias2community_str(str);
+
/* Regular expression match. */
- if (regexec(reg, bgp_alias2community_str(str), 0, NULL, 0) == 0)
- return true;
+ rv = regexec(reg, regstr, 0, NULL, 0);
- /* No match. */
- return false;
+ XFREE(MTYPE_TMP, regstr);
+
+ return rv == 0;
}
* This is a helper to convert already aliased version
* of communities into numerical-only format.
*/
-const char *bgp_alias2community_str(const char *str)
+char *bgp_alias2community_str(const char *str)
{
char **aliases;
- int num;
+ char *comstr;
+ int num, i;
frrstr_split(str, " ", &aliases, &num);
- const char *communities[num + 1];
+ const char *communities[num];
- for (int i = 0; i < num; i++) {
- communities[i] =
- XSTRDUP(MTYPE_TMP, bgp_alias2community(aliases[i]));
+ for (i = 0; i < num; i++)
+ communities[i] = bgp_alias2community(aliases[i]);
+
+ comstr = frrstr_join(communities, num, " ");
+
+ for (i = 0; i < num; i++)
XFREE(MTYPE_TMP, aliases[i]);
- }
XFREE(MTYPE_TMP, aliases);
- return frrstr_join(communities, num, " ");
+ return comstr;
}
extern int bgp_community_alias_write(struct vty *vty);
extern const char *bgp_community2alias(char *community);
extern const char *bgp_alias2community(char *alias);
-extern const char *bgp_alias2community_str(const char *str);
+extern char *bgp_alias2community_str(const char *str);
#endif /* FRR_BGP_COMMUNITY_ALIAS_H */