Merge pull request #14013 from opensourcerouting/fix/backport_aggregate_memory_leaks_8.5

bgpd: Memory leaks for aggregate (backports)
This commit is contained in:
Russ White 2023-07-18 09:41:29 -04:00 committed by GitHub
commit cdbca826e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 12 deletions

View File

@ -2169,11 +2169,15 @@ static void bgp_aggr_aspath_prepare(struct hash_bucket *hb, void *arg)
{ {
struct aspath *hb_aspath = hb->data; struct aspath *hb_aspath = hb->data;
struct aspath **aggr_aspath = arg; struct aspath **aggr_aspath = arg;
struct aspath *aspath = NULL;
if (*aggr_aspath) if (*aggr_aspath) {
*aggr_aspath = aspath_aggregate(*aggr_aspath, hb_aspath); aspath = aspath_aggregate(*aggr_aspath, hb_aspath);
else aspath_free(*aggr_aspath);
*aggr_aspath = aspath;
} else {
*aggr_aspath = aspath_dup(hb_aspath); *aggr_aspath = aspath_dup(hb_aspath);
}
} }
void bgp_aggr_aspath_remove(void *arg) void bgp_aggr_aspath_remove(void *arg)

View File

@ -7252,7 +7252,7 @@ static struct bgp_aggregate *bgp_aggregate_new(void)
return XCALLOC(MTYPE_BGP_AGGREGATE, sizeof(struct bgp_aggregate)); return XCALLOC(MTYPE_BGP_AGGREGATE, sizeof(struct bgp_aggregate));
} }
static void bgp_aggregate_free(struct bgp_aggregate *aggregate) void bgp_aggregate_free(struct bgp_aggregate *aggregate)
{ {
XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->suppress_map_name); XFREE(MTYPE_ROUTE_MAP_NAME, aggregate->suppress_map_name);
route_map_counter_decrement(aggregate->suppress_map); route_map_counter_decrement(aggregate->suppress_map);
@ -7652,7 +7652,7 @@ static void bgp_aggregate_med_update(struct bgp_aggregate *aggregate,
} }
/* Update an aggregate as routes are added/removed from the BGP table */ /* Update an aggregate as routes are added/removed from the BGP table */
void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi, bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
safi_t safi, struct bgp_aggregate *aggregate) safi_t safi, struct bgp_aggregate *aggregate)
{ {
struct bgp_table *table; struct bgp_table *table;
@ -7670,9 +7670,9 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
/* If the bgp instance is being deleted or self peer is deleted /* If the bgp instance is being deleted or self peer is deleted
* then do not create aggregate route * then do not create aggregate route
*/ */
if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS) ||
|| (bgp->peer_self == NULL)) bgp->peer_self == NULL)
return; return false;
/* Initialize and test routes for MED difference. */ /* Initialize and test routes for MED difference. */
if (aggregate->match_med) if (aggregate->match_med)
@ -7864,6 +7864,8 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
bgp_aggregate_install(bgp, afi, safi, p, origin, aspath, community, bgp_aggregate_install(bgp, afi, safi, p, origin, aspath, community,
ecommunity, lcommunity, atomic_aggregate, ecommunity, lcommunity, atomic_aggregate,
aggregate); aggregate);
return true;
} }
void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi, void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi,
@ -8454,7 +8456,10 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi,
bgp_dest_set_bgp_aggregate_info(dest, aggregate); bgp_dest_set_bgp_aggregate_info(dest, aggregate);
/* Aggregate address insert into BGP routing table. */ /* Aggregate address insert into BGP routing table. */
bgp_aggregate_route(bgp, &p, afi, safi, aggregate); if (!bgp_aggregate_route(bgp, &p, afi, safi, aggregate)) {
bgp_aggregate_free(aggregate);
bgp_dest_unlock_node(dest);
}
return CMD_SUCCESS; return CMD_SUCCESS;
} }

View File

@ -780,7 +780,7 @@ extern void bgp_config_write_distance(struct vty *, struct bgp *, afi_t,
extern void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, extern void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi, afi_t afi, safi_t safi,
struct bgp_aggregate *aggregate); struct bgp_aggregate *aggregate);
extern void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, extern bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p,
afi_t afi, safi_t safi, afi_t afi, safi_t safi,
struct bgp_aggregate *aggregate); struct bgp_aggregate *aggregate);
extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p, extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p,
@ -889,6 +889,7 @@ extern void bgp_path_info_free_with_caller(const char *caller,
extern void bgp_path_info_add_with_caller(const char *caller, extern void bgp_path_info_add_with_caller(const char *caller,
struct bgp_dest *dest, struct bgp_dest *dest,
struct bgp_path_info *pi); struct bgp_path_info *pi);
extern void bgp_aggregate_free(struct bgp_aggregate *aggregate);
#define bgp_path_info_add(A, B) \ #define bgp_path_info_add(A, B) \
bgp_path_info_add_with_caller(__func__, (A), (B)) bgp_path_info_add_with_caller(__func__, (A), (B))
#define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B)) #define bgp_path_info_free(B) bgp_path_info_free_with_caller(__func__, (B))

View File

@ -4211,7 +4211,7 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
inet_ntop(bn_p->family, inet_ntop(bn_p->family,
&bn_p->u.prefix, buf, &bn_p->u.prefix, buf,
sizeof(buf))); sizeof(buf)));
bgp_aggregate_route(bgp, bn_p, afi, safi, (void)bgp_aggregate_route(bgp, bn_p, afi, safi,
aggregate); aggregate);
} }
} }