Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions bgpd/bgp_mpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -685,12 +685,24 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,

attr.aspath = aspath;
attr.origin = origin;
if (community)
if (community) {
struct community *old_comm = bgp_attr_get_community(&attr);
if (old_comm && !old_comm->refcnt)
community_free(&old_comm);
bgp_attr_set_community(&attr, community);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this is a regular problem, why not do this inside "set_community", "set_ecommunity", etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thats the right way to do. I tried to do that, but two things I faced , 1) many places they have local free, so I need to change all of them to handle double free 2) all of bgp_attr_set_* are inline functions.., if we are fine for both then I can change accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is far preferable to fix the problem once and right such that people coming along behind do not re-introduce the problem or use a pattern that is broken.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, that if this can be fixed completely (bad pattern), then let's do it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I will make change accordingly.

if (ecomm)
}
if (ecomm) {
struct ecommunity *old_ecom = bgp_attr_get_ecommunity(&attr);
if (old_ecom && !old_ecom->refcnt)
ecommunity_free(&old_ecom);
bgp_attr_set_ecommunity(&attr, ecomm);
if (lcomm)
}
if (lcomm) {
struct lcommunity *old_lcomm = bgp_attr_get_lcommunity(&attr);
if (old_lcomm && !old_lcomm->refcnt)
lcommunity_free(&old_lcomm);
bgp_attr_set_lcommunity(&attr, lcomm);
}

/* Zap multipath attr nexthop so we set nexthop to self */
attr.nexthop.s_addr = INADDR_ANY;
Expand Down
11 changes: 9 additions & 2 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2858,14 +2858,20 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
if (nh_reset && bgp_path_info_mpath_chkwtd(bgp, pi) &&
(cum_bw = bgp_path_info_mpath_cumbw(pi)) != 0 &&
!CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_LINK_BW_SET)) {
if (CHECK_FLAG(peer->flags, PEER_FLAG_EXTENDED_LINK_BANDWIDTH))
if (CHECK_FLAG(peer->flags, PEER_FLAG_EXTENDED_LINK_BANDWIDTH)) {
struct ecommunity *old_ecom = bgp_attr_get_ipv6_ecommunity(attr);
if (old_ecom && !old_ecom->refcnt)
ecommunity_free(&old_ecom);
bgp_attr_set_ipv6_ecommunity(
attr,
ecommunity_replace_linkbw(bgp->as,
bgp_attr_get_ipv6_ecommunity(
attr),
cum_bw, false, true));
else
} else {
struct ecommunity *old_ecom = bgp_attr_get_ecommunity(attr);
if (old_ecom && !old_ecom->refcnt)
ecommunity_free(&old_ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_replace_linkbw(
Expand All @@ -2874,6 +2880,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE),
false));
}
}

/*
Expand Down
Loading