summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_route.c111
-rw-r--r--bgpd/bgp_route.h1
-rw-r--r--bgpd/bgpd.c17
3 files changed, 76 insertions, 53 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 94f9e5b1e7..ebb6a5b909 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -8322,59 +8322,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);
-
- if (aggregate->community_hash) {
- /* Delete all communities in the hash.
- */
- hash_clean(aggregate->community_hash,
- bgp_aggr_community_remove);
- /* Free up the community_hash.
- */
- hash_free(aggregate->community_hash);
- }
-
- if (aggregate->ecommunity)
- ecommunity_free(&aggregate->ecommunity);
-
- if (aggregate->ecommunity_hash) {
- /* Delete all ecommunities in the hash.
- */
- hash_clean(aggregate->ecommunity_hash,
- bgp_aggr_ecommunity_remove);
- /* Free up the ecommunity_hash.
- */
- hash_free(aggregate->ecommunity_hash);
- }
-
- if (aggregate->lcommunity)
- lcommunity_free(&aggregate->lcommunity);
-
- if (aggregate->lcommunity_hash) {
- /* Delete all lcommunities in the hash.
- */
- hash_clean(aggregate->lcommunity_hash,
- bgp_aggr_lcommunity_remove);
- /* Free up the lcommunity_hash.
- */
- hash_free(aggregate->lcommunity_hash);
- }
-
- if (aggregate->aspath)
- aspath_free(aggregate->aspath);
-
- if (aggregate->aspath_hash) {
- /* Delete all as-paths in the hash.
- */
- hash_clean(aggregate->aspath_hash,
- bgp_aggr_aspath_remove);
- /* Free up the aspath_hash.
- */
- hash_free(aggregate->aspath_hash);
- }
-
- bgp_aggregate_free(aggregate);
+ bgp_free_aggregate_info(aggregate);
bgp_dest_unlock_node(dest);
bgp_dest_unlock_node(dest);
@@ -8555,6 +8503,63 @@ 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);
+
+ if (aggregate->community_hash) {
+ /* Delete all communities in the hash.
+ */
+ hash_clean(aggregate->community_hash,
+ bgp_aggr_community_remove);
+ /* Free up the community_hash.
+ */
+ hash_free(aggregate->community_hash);
+ }
+
+ if (aggregate->ecommunity)
+ ecommunity_free(&aggregate->ecommunity);
+
+ if (aggregate->ecommunity_hash) {
+ /* Delete all ecommunities in the hash.
+ */
+ hash_clean(aggregate->ecommunity_hash,
+ bgp_aggr_ecommunity_remove);
+ /* Free up the ecommunity_hash.
+ */
+ hash_free(aggregate->ecommunity_hash);
+ }
+
+ if (aggregate->lcommunity)
+ lcommunity_free(&aggregate->lcommunity);
+
+ if (aggregate->lcommunity_hash) {
+ /* Delete all lcommunities in the hash.
+ */
+ hash_clean(aggregate->lcommunity_hash,
+ bgp_aggr_lcommunity_remove);
+ /* Free up the lcommunity_hash.
+ */
+ hash_free(aggregate->lcommunity_hash);
+ }
+
+ if (aggregate->aspath)
+ aspath_free(aggregate->aspath);
+
+ if (aggregate->aspath_hash) {
+ /* Delete all as-paths in the hash.
+ */
+ hash_clean(aggregate->aspath_hash,
+ bgp_aggr_aspath_remove);
+ /* Free up the aspath_hash.
+ */
+ hash_free(aggregate->aspath_hash);
+ }
+
+ 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 24fc25f82f..2afd97c4dd 100644
--- a/bgpd/bgp_route.h
+++ b/bgpd/bgp_route.h
@@ -674,6 +674,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 bd3e8c7b24..8b3a1e3dd4 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -3801,6 +3801,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) {