Commit 4ee4975168 for frr

commit 4ee4975168bdae68d6aba605acd3da415fa2b178
Author: Philippe Guibert <philippe.guibert@6wind.com>
Date:   Wed May 31 17:01:04 2023 +0200

    bgpd: fix withdraw stale routes

    Incoming MPLS VPN staled routes are not flushing imported
    entries, upon expiration of the stalepath timer.

    The incoming MPLS VPN staled routes that are received from
    a given peer have a sub_type set to BGP_ROUTE_NORMAL. The
    original patch is wrong as it filters out the locally
    exported routes marked with the BGP_ROUTE_IMPORTED subtype.

    Fix this by extending the test to all MPLS VPN routes
    received from this peer.

    Fixes: 641065d4fc ("bgpd: VRF-Lite fix to clear stale leaked routes")

    Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
    Signed-off-by: Yuya Kusakabe <yuya.kusakabe@gmail.com>

diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 948c14c44a..ea764b1e85 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -8395,10 +8395,8 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi)
 					 * If this is VRF leaked route
 					 * process for withdraw.
 					 */
-					if (pi->sub_type ==
-						    BGP_ROUTE_IMPORTED &&
-					    peer->bgp->inst_type ==
-						    BGP_INSTANCE_TYPE_DEFAULT)
+					if (safi == SAFI_MPLS_VPN &&
+					    peer->bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)
 						vpn_leak_to_vrf_withdraw(pi);

 					bgp_rib_remove(rm, pi, peer, afi, safi);