summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_route.c53
-rw-r--r--bgpd/bgp_route.h1
-rw-r--r--bgpd/bgpd.c17
3 files changed, 47 insertions, 24 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 4441e86fbb..12c959a298 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -8338,30 +8338,7 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str,
/* Unlock aggregate address configuration. */
bgp_dest_set_bgp_aggregate_info(dest, NULL);
- if (aggregate->community)
- community_free(&aggregate->community);
-
- hash_clean_and_free(&aggregate->community_hash,
- bgp_aggr_community_remove);
-
- if (aggregate->ecommunity)
- ecommunity_free(&aggregate->ecommunity);
-
- hash_clean_and_free(&aggregate->ecommunity_hash,
- bgp_aggr_ecommunity_remove);
-
- if (aggregate->lcommunity)
- lcommunity_free(&aggregate->lcommunity);
-
- hash_clean_and_free(&aggregate->lcommunity_hash,
- bgp_aggr_lcommunity_remove);
-
- if (aggregate->aspath)
- aspath_free(aggregate->aspath);
-
- hash_clean_and_free(&aggregate->aspath_hash, bgp_aggr_aspath_remove);
-
- bgp_aggregate_free(aggregate);
+ bgp_free_aggregate_info(aggregate);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
@@ -8545,6 +8522,34 @@ DEFPY(aggregate_addressv4, aggregate_addressv4_cmd,
match_med != NULL, suppress_map);
}
+void bgp_free_aggregate_info(struct bgp_aggregate *aggregate)
+{
+ if (aggregate->community)
+ community_free(&aggregate->community);
+
+ hash_clean_and_free(&aggregate->community_hash,
+ bgp_aggr_community_remove);
+
+ if (aggregate->ecommunity)
+ ecommunity_free(&aggregate->ecommunity);
+
+ hash_clean_and_free(&aggregate->ecommunity_hash,
+ bgp_aggr_ecommunity_remove);
+
+ if (aggregate->lcommunity)
+ lcommunity_free(&aggregate->lcommunity);
+
+ hash_clean_and_free(&aggregate->lcommunity_hash,
+ bgp_aggr_lcommunity_remove);
+
+ if (aggregate->aspath)
+ aspath_free(aggregate->aspath);
+
+ hash_clean_and_free(&aggregate->aspath_hash, bgp_aggr_aspath_remove);
+
+ bgp_aggregate_free(aggregate);
+}
+
DEFPY(aggregate_addressv6, aggregate_addressv6_cmd,
"[no] aggregate-address X:X::X:X/M$prefix [{"
"as-set$as_set_s"
diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h
index b48e8eda11..a64144b625 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -661,6 +661,7 @@ extern void bgp_process_queue_init(struct bgp *bgp);
extern void bgp_route_init(void);
extern void bgp_route_finish(void);
extern void bgp_cleanup_routes(struct bgp *);
+extern void bgp_free_aggregate_info(struct bgp_aggregate *aggregate);
extern void bgp_announce_route(struct peer *peer, afi_t afi, safi_t safi,
bool force);
extern void bgp_stop_announce_route_timer(struct peer_af *paf);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 97238bc38b..9d7a1f967e 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -3844,6 +3844,23 @@ int bgp_delete(struct bgp *bgp)
#ifdef ENABLE_BGP_VNC
rfapi_delete(bgp);
#endif
+
+ /* Free memory allocated with aggregate address configuration. */
+ FOREACH_AFI_SAFI (afi, safi) {
+ struct bgp_aggregate *aggregate = NULL;
+
+ for (struct bgp_dest *dest =
+ bgp_table_top(bgp->aggregate[afi][safi]);
+ dest; dest = bgp_route_next(dest)) {
+ aggregate = bgp_dest_get_bgp_aggregate_info(dest);
+ if (aggregate == NULL)
+ continue;
+
+ bgp_dest_set_bgp_aggregate_info(dest, NULL);
+ bgp_free_aggregate_info(aggregate);
+ }
+ }
+
bgp_cleanup_routes(bgp);
for (afi = 0; afi < AFI_MAX; ++afi) {