From cda0f501fb9a3b0dca429dac628ea4cc9566e233 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 9 Dec 2022 08:51:34 -0500 Subject: [PATCH] zebra: Free up routemap name memory on vrf deletion event Signed-off-by: Donald Sharp --- zebra/zebra_routemap.c | 17 +++++++++++++++++ zebra/zebra_routemap.h | 2 ++ zebra/zebra_vrf.c | 1 + 3 files changed, 20 insertions(+) diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 13d1995d58..066ef8a8d0 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1818,6 +1818,23 @@ static void zebra_route_map_event(const char *rmap_name) route_map_notify_dependencies(rmap_name, RMAP_EVENT_MATCH_ADDED); } +void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf) +{ + afi_t afi; + uint8_t type; + + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + for (type = 0; type <= ZEBRA_ROUTE_MAX; type++) { + if (PROTO_RM_NAME(zvrf, afi, type)) + XFREE(MTYPE_ROUTE_MAP_NAME, + PROTO_RM_NAME(zvrf, afi, type)); + if (NHT_RM_NAME(zvrf, afi, type)) + XFREE(MTYPE_ROUTE_MAP_NAME, + NHT_RM_NAME(zvrf, afi, type)); + } + } +} + /* ip protocol configuration write function */ void zebra_routemap_config_write_protocol(struct vty *vty, struct zebra_vrf *zvrf) diff --git a/zebra/zebra_routemap.h b/zebra/zebra_routemap.h index 3f58e14e10..02b01fa53a 100644 --- a/zebra/zebra_routemap.h +++ b/zebra/zebra_routemap.h @@ -50,6 +50,8 @@ zebra_nht_route_map_check(afi_t afi, int client_proto, const struct prefix *p, struct zebra_vrf *zvrf, struct route_entry *, struct nexthop *nexthop); +extern void zebra_routemap_vrf_delete(struct zebra_vrf *zvrf); + #ifdef __cplusplus } #endif diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index c99aa2e8ff..be5e91495f 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -268,6 +268,7 @@ static int zebra_vrf_delete(struct vrf *vrf) /* Cleanup EVPN states for vrf */ zebra_vxlan_vrf_delete(zvrf); + zebra_routemap_vrf_delete(zvrf); list_delete_all_node(zvrf->rid_all_sorted_list); list_delete_all_node(zvrf->rid_lo_sorted_list); -- 2.39.5