Commit 0e6eb9bbc3 for frr

commit 0e6eb9bbc3aef07b73fc813fac7fd1b8b556630a
Author: Carmine Scarpitta <cscarpit@cisco.com>
Date:   Sat Jul 4 16:09:11 2026 +0200

    bgpd: Make EVPN Type-5 helpers SAFI-aware

    EVPN Type-5 helper functions checked only the AFI and the EVPN
    advertise flags. This was enough while Type-5 export only handled
    unicast routes.

    VPN routes use a different SAFI, but they share some of the same
    update, withdraw, route-map, and addpath code paths. Thread the
    SAFI through these helpers and their callers so a later change can
    make VPN-specific decisions at the helper boundary.

    This commit keeps the helper predicates behaviorally unchanged: the
    new SAFI argument is ignored, and existing Type-5 behavior is
    preserved.

    Signed-off-by: Carmine Scarpitta <cscarpit@cisco.com>

diff --git a/bgpd/bgp_addpath.c b/bgpd/bgp_addpath.c
index 1b361e651d..2fe54d43e0 100644
--- a/bgpd/bgp_addpath.c
+++ b/bgpd/bgp_addpath.c
@@ -377,7 +377,7 @@ void bgp_addpath_type_changed(struct bgp *bgp)
 	}

 	FOREACH_AFI_SAFI (afi, safi) {
-		if (advertise_type5_routes_multipath(bgp, afi) && safi == SAFI_UNICAST) {
+		if (advertise_type5_routes_multipath(bgp, afi, safi) && safi == SAFI_UNICAST) {
 			peer_count[afi][safi][BGP_ADDPATH_ALL] += 1;
 			bgp->tx_addpath.total_peercount[afi][safi] += 1;
 		}
diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c
index 391ca55f09..2e7ec11fc0 100644
--- a/bgpd/bgp_evpn.c
+++ b/bgpd/bgp_evpn.c
@@ -4844,8 +4844,8 @@ static void delete_withdraw_vrf_routes(struct bgp *bgp_vrf)
 							 false);

 	/* delete all ipv4 routes and withdraw from peers */
-	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP) ||
-	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP))
+	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP, SAFI_UNICAST) ||
+	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP, SAFI_UNICAST))
 		bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST);

 	/* Delete ipv6 default route and withdraw from peers */
@@ -4854,8 +4854,8 @@ static void delete_withdraw_vrf_routes(struct bgp *bgp_vrf)
 							 false);

 	/* delete all ipv6 routes and withdraw from peers */
-	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP6) ||
-	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP6))
+	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP6, SAFI_UNICAST) ||
+	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP6, SAFI_UNICAST))
 		bgp_evpn_withdraw_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST);
 }

@@ -4875,8 +4875,8 @@ void update_advertise_vrf_routes(struct bgp *bgp_vrf)
 		return; /* Nothing to do if no l3vni */

 	/* update all ipv4 routes */
-	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP) ||
-	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP))
+	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP, SAFI_UNICAST) ||
+	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP, SAFI_UNICAST))
 		bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP, SAFI_UNICAST);

 	/* update ipv4 default route and withdraw from peers */
@@ -4884,8 +4884,8 @@ void update_advertise_vrf_routes(struct bgp *bgp_vrf)
 		bgp_evpn_install_uninstall_default_route(bgp_vrf, AFI_IP, SAFI_UNICAST, NULL, true);

 	/* update all ipv6 routes */
-	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP6) ||
-	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP6))
+	if (advertise_type5_routes_bestpath(bgp_vrf, AFI_IP6, SAFI_UNICAST) ||
+	    advertise_type5_routes_multipath(bgp_vrf, AFI_IP6, SAFI_UNICAST))
 		bgp_evpn_advertise_type5_routes(bgp_vrf, AFI_IP6, SAFI_UNICAST);

 	/* update ipv6 default route and withdraw from peers */
@@ -6188,7 +6188,7 @@ void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi, safi_t safi)
 			bgp_evpn_withdraw_type5_route(bgp_vrf, pi, bgp_dest_get_prefix(dest), afi,
 						      safi, addpath_id);

-			if (advertise_type5_routes_bestpath(bgp_vrf, afi))
+			if (advertise_type5_routes_bestpath(bgp_vrf, afi, safi))
 				break;
 		}
 	}
@@ -6303,7 +6303,7 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,

 			bgp_evpn_export_type5_route(bgp_vrf, dest, pi, afi, safi);

-			if (advertise_type5_routes_bestpath(bgp_vrf, afi))
+			if (advertise_type5_routes_bestpath(bgp_vrf, afi, safi))
 				break;
 		}
 	}
@@ -9129,8 +9129,8 @@ void bgp_aggr_supp_withdraw_from_evpn(struct bgp *bgp, afi_t afi, safi_t safi)
 	struct bgp_path_info *pi;
 	uint32_t addpath_id;

-	if (!bgp_get_evpn() || !(advertise_type5_routes_bestpath(bgp, afi) ||
-				 advertise_type5_routes_multipath(bgp, afi)))
+	if (!bgp_get_evpn() || !(advertise_type5_routes_bestpath(bgp, afi, safi) ||
+				 advertise_type5_routes_multipath(bgp, afi, safi)))
 		return;

 	/* Aggregate-address table walk. */
@@ -9189,7 +9189,7 @@ static uint32_t bgp_evpn_addpath_id_for_path(const struct bgp *bgp, const struct
 		return 0;
 	if (afi != AFI_IP && afi != AFI_IP6)
 		return 0;
-	if (!advertise_type5_routes_multipath(bgp, afi))
+	if (!advertise_type5_routes_multipath(bgp, afi, SAFI_UNICAST))
 		return 0;

 	return pi->tx_addpath.addpath_tx_id[BGP_ADDPATH_ALL];
diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h
index bee85e719c..6aa3dba3ca 100644
--- a/bgpd/bgp_evpn.h
+++ b/bgpd/bgp_evpn.h
@@ -21,7 +21,7 @@ static inline int is_evpn_enabled(void)
 	return bgp ? EVPN_ENABLED(bgp) : 0;
 }

-static inline int advertise_type5_routes_bestpath(const struct bgp *bgp_vrf, afi_t afi)
+static inline int advertise_type5_routes_bestpath(const struct bgp *bgp_vrf, afi_t afi, safi_t safi)
 {
 	uint16_t flags = bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN];

@@ -36,7 +36,8 @@ static inline int advertise_type5_routes_bestpath(const struct bgp *bgp_vrf, afi
 	return 0;
 }

-static inline int advertise_type5_routes_multipath(const struct bgp *bgp_vrf, afi_t afi)
+static inline int advertise_type5_routes_multipath(const struct bgp *bgp_vrf, afi_t afi,
+						   safi_t safi)
 {
 	uint16_t flags = bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN];

diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c
index e6b8c266ec..413799f15b 100644
--- a/bgpd/bgp_evpn_vty.c
+++ b/bgpd/bgp_evpn_vty.c
@@ -4385,8 +4385,8 @@ static int bgp_evpn_set_suppress_import_from_evpn(struct bgp *bgp_vrf, afi_t afi
 	if (already_set == set)
 		return CMD_SUCCESS;

-	was_advertising = advertise_type5_routes_bestpath(bgp_vrf, afi) ||
-			  advertise_type5_routes_multipath(bgp_vrf, afi);
+	was_advertising = advertise_type5_routes_bestpath(bgp_vrf, afi, safi) ||
+			  advertise_type5_routes_multipath(bgp_vrf, afi, safi);
 	if (was_advertising)
 		bgp_evpn_withdraw_local_type5_routes(bgp_vrf, afi, safi);

@@ -4565,8 +4565,8 @@ DEFUN (bgp_evpn_advertise_type5,
 	}

 	/* advertise type-5 routes */
-	if (advertise_type5_routes_bestpath(bgp_vrf, afi) ||
-	    advertise_type5_routes_multipath(bgp_vrf, afi))
+	if (advertise_type5_routes_bestpath(bgp_vrf, afi, safi) ||
+	    advertise_type5_routes_multipath(bgp_vrf, afi, safi))
 		bgp_evpn_advertise_type5_routes(bgp_vrf, afi, safi);
 	return CMD_SUCCESS;
 }
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 7b74da4ab7..f3d3bdde09 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -4124,7 +4124,7 @@ static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi,
 		return;


-	if (advertise_type5_routes_bestpath(bgp, afi) && new_select &&
+	if (advertise_type5_routes_bestpath(bgp, afi, safi) && new_select &&
 	    is_route_injectable_into_evpn(bgp, afi, safi, new_select)) {
 		/* apply the route-map */
 		if (bgp->adv_cmd_rmap[afi][safi].map) {
@@ -4162,7 +4162,7 @@ static void bgp_process_evpn_route_injection(struct bgp *bgp, afi_t afi,
 			bgp_evpn_advertise_type5_route(bgp, new_select, p, new_select->attr, afi,
 						       safi, 0);
 		}
-	} else if (advertise_type5_routes_bestpath(bgp, afi) && old_select &&
+	} else if (advertise_type5_routes_bestpath(bgp, afi, safi) && old_select &&
 		   is_route_injectable_into_evpn(bgp, afi, safi, old_select))
 		bgp_evpn_withdraw_type5_route(bgp, old_select, p, afi, safi, 0);
 }
@@ -5734,7 +5734,7 @@ static void bgp_rib_withdraw(const struct prefix *p, struct bgp_dest *dest, stru
 	if (safi == SAFI_EVPN)
 		bgp_evpn_unimport_route(peer->bgp, afi, safi, p, pi);
 	/* If this is a route exported to EVPN, process for un-export */
-	if (advertise_type5_routes_multipath(peer->bgp, afi) &&
+	if (advertise_type5_routes_multipath(peer->bgp, afi, safi) &&
 	    is_route_injectable_into_evpn(peer->bgp, afi, safi, pi))
 		bgp_evpn_unexport_type5_route(peer->bgp, dest, pi, afi, safi);

@@ -6650,7 +6650,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 		}
 #endif

-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, pi)) {
 			/* Implicit withdraw case */
 			bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);
@@ -6771,7 +6771,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 		}
 #endif

-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, pi) && force_evpn_export) {
 			/* Add back the route with its new attributes (e.g. local-pref). */
 			bgp_evpn_export_type5_route(bgp, dest, pi, afi, safi);
@@ -7010,7 +7010,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
 	if (safi == SAFI_EVPN && CHECK_FLAG(new->flags, BGP_PATH_VALID))
 		bgp_evpn_import_route(bgp, afi, safi, p, new);
 	/* If this is a route we should export for EVPN, process for export */
-	if (advertise_type5_routes_multipath(bgp, afi) &&
+	if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 	    is_route_injectable_into_evpn(bgp, afi, safi, new))
 		bgp_evpn_export_type5_route(bgp, dest, new, afi, safi);

@@ -7082,7 +7082,7 @@ filtered:
 		if (safi == SAFI_EVPN)
 			bgp_evpn_unimport_route(bgp, afi, safi, p, pi);
 		/* If this route is exported to EVPN, process for un-export as it is now filtered */
-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 			bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -7628,7 +7628,7 @@ static wq_item_status bgp_clear_route_node(struct work_queue *wq, void *data)
 					bgp, afi, safi,
 					bgp_dest_get_prefix(dest), pi);
 			/* If this is a route exported to EVPN, process for un-export. */
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 			    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 				bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -7887,7 +7887,7 @@ static void clearing_clear_one_pi(struct bgp_table *table, struct bgp_dest *dest
 				bgp, afi, safi,
 				bgp_dest_get_prefix(dest), pi);
 		/* If this is a route exported to EVPN, process for un-export */
-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 			bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -8441,7 +8441,7 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi)
 					vpn_leak_from_vrf_withdraw(
 						bgp_get_default(), peer->bgp,
 						pi);
-				if (advertise_type5_routes_multipath(peer->bgp, afi) &&
+				if (advertise_type5_routes_multipath(peer->bgp, afi, safi) &&
 				    is_route_injectable_into_evpn(peer->bgp, afi, safi, pi))
 					bgp_evpn_unexport_type5_route(peer->bgp, dest, pi, afi,
 								      safi);
@@ -8575,7 +8575,7 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table, afi_t af
 				bgp_evpn_unimport_route(bgp, AFI_L2VPN,
 							SAFI_EVPN, p, pi);
 			/* If this is a route exported to EVPN, process for un-export */
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 			    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 				bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -9057,7 +9057,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
 				vpn_leak_from_vrf_update(bgp_get_default(), bgp,
 							 pi);
 			}
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 			    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 				bgp_evpn_export_type5_route(bgp, dest, pi, afi, safi);

@@ -9110,7 +9110,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
 	}

 	/* If this is a route we should export to EVPN, process for export */
-	if (advertise_type5_routes_multipath(bgp, afi) &&
+	if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 	    is_route_injectable_into_evpn(bgp, afi, safi, new))
 		bgp_evpn_export_type5_route(bgp, dest, new, afi, safi);

@@ -9163,7 +9163,7 @@ void bgp_static_withdraw(struct bgp *bgp, const struct prefix *p, afi_t afi,
 			vpn_leak_to_vrf_withdraw(pi);
 		}
 		/* If this is a route exported to EVPN, process for un-export. */
-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 			bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -10499,7 +10499,7 @@ static void bgp_aggregate_install(
 		if (SAFI_UNICAST == safi && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
 					     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 			vpn_leak_from_vrf_update(bgp_get_default(), bgp, new);
-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 		    is_route_injectable_into_evpn(bgp, afi, safi, new))
 			bgp_evpn_export_type5_route(bgp, dest, new, afi, safi);
 		bgp_ls_originate_bgp_prefix(bgp, afi, safi, dest, new);
@@ -10516,7 +10516,7 @@ static void bgp_aggregate_install(
 				     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT)) {
 					vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp, pi);
 				}
-				if (advertise_type5_routes_multipath(bgp, afi) &&
+				if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 				    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 					bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -10634,7 +10634,7 @@ void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
 					     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 						vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp,
 									   pi);
-					if (advertise_type5_routes_multipath(bgp, afi) &&
+					if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 					    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 						bgp_evpn_unexport_type5_route(bgp, dest, pi, afi,
 									      safi);
@@ -10651,7 +10651,7 @@ void bgp_aggregate_toggle_suppressed(struct bgp_aggregate *aggregate,
 				    (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
 				     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 					vpn_leak_from_vrf_update(bgp_get_default(), bgp, pi);
-				if (advertise_type5_routes_multipath(bgp, afi) &&
+				if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 				    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 					bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, safi);

@@ -10788,7 +10788,7 @@ bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
 					     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 						vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp,
 									   pi);
-					if (advertise_type5_routes_multipath(bgp, afi) &&
+					if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 					    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 						bgp_evpn_unexport_type5_route(bgp, dest, pi, afi,
 									      safi);
@@ -10816,7 +10816,7 @@ bool bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
 					     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 						vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp,
 									   pi);
-					if (advertise_type5_routes_multipath(bgp, afi) &&
+					if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 					    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 						bgp_evpn_unexport_type5_route(bgp, dest, pi, afi,
 									      safi);
@@ -10984,7 +10984,7 @@ void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi,
 					    (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
 					     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 						vpn_leak_from_vrf_update(bgp_get_default(), bgp, pi);
-					if (advertise_type5_routes_multipath(bgp, afi) &&
+					if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 					    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 						bgp_evpn_export_type5_route(bgp, dest, pi, afi,
 									    safi);
@@ -11201,7 +11201,7 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, const struct prefix
 			if (SAFI_UNICAST == safi && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
 						     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 				vpn_leak_from_vrf_update(bgp_get_default(), bgp, pi);
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 			    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 				bgp_evpn_export_type5_route(bgp, pi->net, pi, afi, safi);

@@ -11215,7 +11215,7 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, const struct prefix
 			if (SAFI_UNICAST == safi && (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ||
 						     bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT))
 				vpn_leak_from_vrf_update(bgp_get_default(), bgp, pi);
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, safi) &&
 			    is_route_injectable_into_evpn(bgp, afi, safi, pi))
 				bgp_evpn_export_type5_route(bgp, pi->net, pi, afi, safi);

@@ -12051,7 +12051,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, const union g_addr
 					vpn_leak_from_vrf_update(
 						bgp_get_default(), bgp, bpi);
 				}
-				if (advertise_type5_routes_multipath(bgp, afi) &&
+				if (advertise_type5_routes_multipath(bgp, afi, SAFI_UNICAST) &&
 				    is_route_injectable_into_evpn(bgp, afi, SAFI_UNICAST, bpi))
 					bgp_evpn_export_type5_route(bgp, bn, bpi, afi,
 								    SAFI_UNICAST);
@@ -12075,7 +12075,7 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, const union g_addr

 			vpn_leak_from_vrf_update(bgp_get_default(), bgp, new);
 		}
-		if (advertise_type5_routes_multipath(bgp, afi) &&
+		if (advertise_type5_routes_multipath(bgp, afi, SAFI_UNICAST) &&
 		    is_route_injectable_into_evpn(bgp, afi, SAFI_UNICAST, new))
 			bgp_evpn_export_type5_route(bgp, bn, new, afi, SAFI_UNICAST);

@@ -12117,7 +12117,7 @@ void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, uint8_t type,
 				vpn_leak_from_vrf_withdraw(bgp_get_default(),
 							   bgp, pi);
 			}
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, SAFI_UNICAST) &&
 			    is_route_injectable_into_evpn(bgp, afi, SAFI_UNICAST, pi))
 				bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, SAFI_UNICAST);

@@ -12156,7 +12156,7 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type,
 				vpn_leak_from_vrf_withdraw(bgp_get_default(),
 							   bgp, pi);
 			}
-			if (advertise_type5_routes_multipath(bgp, afi) &&
+			if (advertise_type5_routes_multipath(bgp, afi, SAFI_UNICAST) &&
 			    is_route_injectable_into_evpn(bgp, afi, SAFI_UNICAST, pi))
 				bgp_evpn_unexport_type5_route(bgp, dest, pi, afi, SAFI_UNICAST);

diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 665654811f..7460332dd8 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -5149,8 +5149,8 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name,
 				"Processing route_map %s(%s:%s) update on advertise type5 route command",
 				rmap_name, afi2str(afi), safi2str(safi));

-		if (route_update && (advertise_type5_routes_bestpath(bgp, afi) ||
-				     advertise_type5_routes_multipath(bgp, afi))) {
+		if (route_update && (advertise_type5_routes_bestpath(bgp, afi, safi) ||
+				     advertise_type5_routes_multipath(bgp, afi, safi))) {
 			bgp_evpn_withdraw_type5_routes(bgp, afi, safi);
 			bgp_evpn_advertise_type5_routes(bgp, afi, safi);
 		}