bgpd:Fixing the signature of community_free function

community_free, lcommunity_free and ecommunity_free are similar type of functions. Most of the places, these three are called together. The signature of community_free is different from other two functions. Modified the community_free API signature to align with other two functions to avoid any confusion. There is no functionality impact with this and this is just to avoid any confusion.

Testing: manual testing and show commands
Signed-off-by: Sri Mohana Singamsetty msingamsetty@vmware.com
This commit is contained in:
Sri Mohana Singamsetty 2018-10-22 12:58:39 -07:00
parent 9a2deb2473
commit 3c1f53dee9
7 changed files with 36 additions and 40 deletions

View File

@ -849,7 +849,7 @@ void bgp_attr_undup(struct attr *new, struct attr *old)
aspath_free(new->aspath); aspath_free(new->aspath);
if (new->community != old->community) if (new->community != old->community)
community_free(new->community); community_free(&new->community);
if (new->ecommunity != old->ecommunity) if (new->ecommunity != old->ecommunity)
ecommunity_free(&new->ecommunity); ecommunity_free(&new->ecommunity);
@ -887,11 +887,8 @@ void bgp_attr_flush(struct attr *attr)
aspath_free(attr->aspath); aspath_free(attr->aspath);
attr->aspath = NULL; attr->aspath = NULL;
} }
if (attr->community && !attr->community->refcnt) { if (attr->community && !attr->community->refcnt)
community_free(attr->community); community_free(&attr->community);
attr->community = NULL;
}
if (attr->ecommunity && !attr->ecommunity->refcnt) if (attr->ecommunity && !attr->ecommunity->refcnt)
ecommunity_free(&attr->ecommunity); ecommunity_free(&attr->ecommunity);
if (attr->lcommunity && !attr->lcommunity->refcnt) if (attr->lcommunity && !attr->lcommunity->refcnt)

View File

@ -65,7 +65,7 @@ static void community_entry_free(struct community_entry *entry)
switch (entry->style) { switch (entry->style) {
case COMMUNITY_LIST_STANDARD: case COMMUNITY_LIST_STANDARD:
if (entry->u.com) if (entry->u.com)
community_free(entry->u.com); community_free(&entry->u.com);
break; break;
case LARGE_COMMUNITY_LIST_STANDARD: case LARGE_COMMUNITY_LIST_STANDARD:
if (entry->u.lcom) if (entry->u.lcom)
@ -903,7 +903,7 @@ int community_list_unset(struct community_list_handler *ch, const char *name,
if (com) { if (com) {
entry = community_list_entry_lookup(list, com, direct); entry = community_list_entry_lookup(list, com, direct);
community_free(com); community_free(&com);
} else } else
entry = community_list_entry_lookup(list, str, direct); entry = community_list_entry_lookup(list, str, direct);

View File

@ -39,19 +39,19 @@ static struct community *community_new(void)
} }
/* Free communities value. */ /* Free communities value. */
void community_free(struct community *com) void community_free(struct community **com)
{ {
if (com->val) if ((*com)->val)
XFREE(MTYPE_COMMUNITY_VAL, com->val); XFREE(MTYPE_COMMUNITY_VAL, (*com)->val);
if (com->str) if ((*com)->str)
XFREE(MTYPE_COMMUNITY_STR, com->str); XFREE(MTYPE_COMMUNITY_STR, (*com)->str);
if (com->json) { if ((*com)->json) {
json_object_free(com->json); json_object_free((*com)->json);
com->json = NULL; (*com)->json = NULL;
} }
XFREE(MTYPE_COMMUNITY, com); XFREE(MTYPE_COMMUNITY, (*com));
} }
/* Add one community value to the community. */ /* Add one community value to the community. */
@ -498,7 +498,7 @@ struct community *community_intern(struct community *com)
/* Arguemnt com is allocated temporary. So when it is not used in /* Arguemnt com is allocated temporary. So when it is not used in
hash, it should be freed. */ hash, it should be freed. */
if (find != com) if (find != com)
community_free(com); community_free(&com);
/* Increment refrence counter. */ /* Increment refrence counter. */
find->refcnt++; find->refcnt++;
@ -524,8 +524,7 @@ void community_unintern(struct community **com)
ret = (struct community *)hash_release(comhash, *com); ret = (struct community *)hash_release(comhash, *com);
assert(ret != NULL); assert(ret != NULL);
community_free(*com); community_free(com);
*com = NULL;
} }
} }
@ -874,13 +873,13 @@ struct community *community_str2com(const char *str)
break; break;
case community_token_unknown: case community_token_unknown:
if (com) if (com)
community_free(com); community_free(&com);
return NULL; return NULL;
} }
} while (str); } while (str);
com_sort = community_uniq_sort(com); com_sort = community_uniq_sort(com);
community_free(com); community_free(&com);
return com_sort; return com_sort;
} }

View File

@ -68,7 +68,7 @@ struct community {
/* Prototypes of communities attribute functions. */ /* Prototypes of communities attribute functions. */
extern void community_init(void); extern void community_init(void);
extern void community_finish(void); extern void community_finish(void);
extern void community_free(struct community *); extern void community_free(struct community **comm);
extern struct community *community_uniq_sort(struct community *); extern struct community *community_uniq_sort(struct community *);
extern struct community *community_parse(uint32_t *, unsigned short); extern struct community *community_parse(uint32_t *, unsigned short);
extern struct community *community_intern(struct community *); extern struct community *community_intern(struct community *);

View File

@ -749,7 +749,7 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
mpinfo->attr->community); mpinfo->attr->community);
community = community =
community_uniq_sort(commerge); community_uniq_sort(commerge);
community_free(commerge); community_free(&commerge);
} else } else
community = community_dup( community = community_dup(
mpinfo->attr->community); mpinfo->attr->community);

View File

@ -1345,15 +1345,15 @@ void bgp_attr_add_gshut_community(struct attr *attr)
merge = community_merge(community_dup(old), gshut); merge = community_merge(community_dup(old), gshut);
if (old->refcnt == 0) if (old->refcnt == 0)
community_free(old); community_free(&old);
new = community_uniq_sort(merge); new = community_uniq_sort(merge);
community_free(merge); community_free(&merge);
} else { } else {
new = community_dup(gshut); new = community_dup(gshut);
} }
community_free(gshut); community_free(&gshut);
attr->community = new; attr->community = new;
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
@ -5549,7 +5549,7 @@ static void bgp_aggregate_install(struct bgp *bgp, afi_t afi, safi_t safi,
if (aspath) if (aspath)
aspath_free(aspath); aspath_free(aspath);
if (community) if (community)
community_free(community); community_free(&community);
if (ecommunity) if (ecommunity)
ecommunity_free(&ecommunity); ecommunity_free(&ecommunity);
if (lcommunity) if (lcommunity)
@ -5696,7 +5696,7 @@ static void bgp_aggregate_route(struct bgp *bgp, struct prefix *p,
community, pi->attr->community); community, pi->attr->community);
community = community =
community_uniq_sort(commerge); community_uniq_sort(commerge);
community_free(commerge); community_free(&commerge);
} else } else
community = community_dup( community = community_dup(
pi->attr->community); pi->attr->community);
@ -5758,7 +5758,7 @@ static void bgp_aggregate_route(struct bgp *bgp, struct prefix *p,
pinew->attr->community); pinew->attr->community);
community = community =
community_uniq_sort(commerge); community_uniq_sort(commerge);
community_free(commerge); community_free(&commerge);
} else } else
community = community_dup( community = community_dup(
pinew->attr->community); pinew->attr->community);
@ -5800,7 +5800,7 @@ static void bgp_aggregate_route(struct bgp *bgp, struct prefix *p,
if (aspath) if (aspath)
aspath_free(aspath); aspath_free(aspath);
if (community) if (community)
community_free(community); community_free(&community);
if (ecommunity) if (ecommunity)
ecommunity_free(&ecommunity); ecommunity_free(&ecommunity);
if (lcommunity) if (lcommunity)
@ -9607,7 +9607,7 @@ static int bgp_show_community(struct vty *vty, struct bgp *bgp,
(exact ? bgp_show_type_community_exact (exact ? bgp_show_type_community_exact
: bgp_show_type_community), : bgp_show_type_community),
com, use_json); com, use_json);
community_free(com); community_free(&com);
return ret; return ret;
} }

View File

@ -1717,7 +1717,7 @@ static route_map_result_t route_set_community(void *rule,
attr->community = NULL; attr->community = NULL;
/* See the longer comment down below. */ /* See the longer comment down below. */
if (old && old->refcnt == 0) if (old && old->refcnt == 0)
community_free(old); community_free(&old);
return RMAP_OKAY; return RMAP_OKAY;
} }
@ -1726,7 +1726,7 @@ static route_map_result_t route_set_community(void *rule,
merge = community_merge(community_dup(old), rcs->com); merge = community_merge(community_dup(old), rcs->com);
new = community_uniq_sort(merge); new = community_uniq_sort(merge);
community_free(merge); community_free(&merge);
} else } else
new = community_dup(rcs->com); new = community_dup(rcs->com);
@ -1736,7 +1736,7 @@ static route_map_result_t route_set_community(void *rule,
* Really need to cleanup attribute caching sometime. * Really need to cleanup attribute caching sometime.
*/ */
if (old && old->refcnt == 0) if (old && old->refcnt == 0)
community_free(old); community_free(&old);
/* will be interned by caller if required */ /* will be interned by caller if required */
attr->community = new; attr->community = new;
@ -1790,7 +1790,7 @@ static void route_set_community_free(void *rule)
struct rmap_com_set *rcs = rule; struct rmap_com_set *rcs = rule;
if (rcs->com) if (rcs->com)
community_free(rcs->com); community_free(&rcs->com);
XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs); XFREE(MTYPE_ROUTE_MAP_COMPILED, rcs);
} }
@ -2031,7 +2031,7 @@ static route_map_result_t route_set_community_delete(
merge = community_list_match_delete(community_dup(old), merge = community_list_match_delete(community_dup(old),
list); list);
new = community_uniq_sort(merge); new = community_uniq_sort(merge);
community_free(merge); community_free(&merge);
/* HACK: if the old community is not intern'd, /* HACK: if the old community is not intern'd,
* we should free it here, or all reference to it may be * we should free it here, or all reference to it may be
@ -2039,13 +2039,13 @@ static route_map_result_t route_set_community_delete(
* Really need to cleanup attribute caching sometime. * Really need to cleanup attribute caching sometime.
*/ */
if (old->refcnt == 0) if (old->refcnt == 0)
community_free(old); community_free(&old);
if (new->size == 0) { if (new->size == 0) {
path->attr->community = NULL; path->attr->community = NULL;
path->attr->flag &= path->attr->flag &=
~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
community_free(new); community_free(&new);
} else { } else {
path->attr->community = new; path->attr->community = new;
path->attr->flag |= path->attr->flag |=
@ -4171,7 +4171,7 @@ DEFUN (set_community,
ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index), ret = generic_set_add(vty, VTY_GET_CONTEXT(route_map_index),
"community", str); "community", str);
community_free(com); community_free(&com);
return ret; return ret;
} }