1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Ethernet-VPN Packet and vty Processing File
3 * Copyright (C) 2016 6WIND
4 * Copyright (C) 2017 Cumulus Networks, Inc.
19 #include "lib/printfrr.h"
21 #include "bgpd/bgp_attr_evpn.h"
22 #include "bgpd/bgpd.h"
23 #include "bgpd/bgp_table.h"
24 #include "bgpd/bgp_route.h"
25 #include "bgpd/bgp_attr.h"
26 #include "bgpd/bgp_mplsvpn.h"
27 #include "bgpd/bgp_label.h"
28 #include "bgpd/bgp_evpn.h"
29 #include "bgpd/bgp_evpn_private.h"
30 #include "bgpd/bgp_evpn_mh.h"
31 #include "bgpd/bgp_ecommunity.h"
32 #include "bgpd/bgp_encap_types.h"
33 #include "bgpd/bgp_debug.h"
34 #include "bgpd/bgp_errors.h"
35 #include "bgpd/bgp_aspath.h"
36 #include "bgpd/bgp_zebra.h"
37 #include "bgpd/bgp_nexthop.h"
38 #include "bgpd/bgp_addpath.h"
39 #include "bgpd/bgp_mac.h"
40 #include "bgpd/bgp_vty.h"
41 #include "bgpd/bgp_nht.h"
42 #include "bgpd/bgp_trace.h"
43 #include "bgpd/bgp_mpath.h"
46 * Definitions and external declarations.
48 DEFINE_QOBJ_TYPE(bgpevpn
);
49 DEFINE_QOBJ_TYPE(bgp_evpn_es
);
51 DEFINE_MTYPE_STATIC(BGPD
, VRF_ROUTE_TARGET
, "L3 Route Target");
54 * Static function declarations
56 static void bgp_evpn_remote_ip_hash_init(struct bgpevpn
*evpn
);
57 static void bgp_evpn_remote_ip_hash_destroy(struct bgpevpn
*evpn
);
58 static void bgp_evpn_remote_ip_hash_add(struct bgpevpn
*vpn
,
59 struct bgp_path_info
*pi
);
60 static void bgp_evpn_remote_ip_hash_del(struct bgpevpn
*vpn
,
61 struct bgp_path_info
*pi
);
62 static void bgp_evpn_remote_ip_hash_iterate(struct bgpevpn
*vpn
,
63 void (*func
)(struct hash_bucket
*,
66 static void bgp_evpn_link_to_vni_svi_hash(struct bgp
*bgp
, struct bgpevpn
*vpn
);
67 static void bgp_evpn_unlink_from_vni_svi_hash(struct bgp
*bgp
,
69 static unsigned int vni_svi_hash_key_make(const void *p
);
70 static bool vni_svi_hash_cmp(const void *p1
, const void *p2
);
71 static void bgp_evpn_remote_ip_process_nexthops(struct bgpevpn
*vpn
,
74 static void bgp_evpn_remote_ip_hash_link_nexthop(struct hash_bucket
*bucket
,
76 static void bgp_evpn_remote_ip_hash_unlink_nexthop(struct hash_bucket
*bucket
,
78 static struct in_addr zero_vtep_ip
;
87 static unsigned int vni_hash_key_make(const void *p
)
89 const struct bgpevpn
*vpn
= p
;
90 return (jhash_1word(vpn
->vni
, 0));
94 * Comparison function for vni hash
96 static bool vni_hash_cmp(const void *p1
, const void *p2
)
98 const struct bgpevpn
*vpn1
= p1
;
99 const struct bgpevpn
*vpn2
= p2
;
101 return vpn1
->vni
== vpn2
->vni
;
104 int vni_list_cmp(void *p1
, void *p2
)
106 const struct bgpevpn
*vpn1
= p1
;
107 const struct bgpevpn
*vpn2
= p2
;
109 return vpn1
->vni
- vpn2
->vni
;
113 * Make vrf import route target hash key.
115 static unsigned int vrf_import_rt_hash_key_make(const void *p
)
117 const struct vrf_irt_node
*irt
= p
;
118 const char *pnt
= irt
->rt
.val
;
120 return jhash(pnt
, 8, 0x5abc1234);
124 * Comparison function for vrf import rt hash
126 static bool vrf_import_rt_hash_cmp(const void *p1
, const void *p2
)
128 const struct vrf_irt_node
*irt1
= p1
;
129 const struct vrf_irt_node
*irt2
= p2
;
131 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
135 * Create a new vrf import_rt in evpn instance
137 static struct vrf_irt_node
*vrf_import_rt_new(struct ecommunity_val
*rt
)
139 struct bgp
*bgp_evpn
= NULL
;
140 struct vrf_irt_node
*irt
;
142 bgp_evpn
= bgp_get_evpn();
144 flog_err(EC_BGP_NO_DFLT
,
145 "vrf import rt new - evpn instance not created yet");
149 irt
= XCALLOC(MTYPE_BGP_EVPN_VRF_IMPORT_RT
,
150 sizeof(struct vrf_irt_node
));
153 irt
->vrfs
= list_new();
156 (void)hash_get(bgp_evpn
->vrf_import_rt_hash
, irt
, hash_alloc_intern
);
162 * Free the vrf import rt node
164 static void vrf_import_rt_free(struct vrf_irt_node
*irt
)
166 struct bgp
*bgp_evpn
= NULL
;
168 bgp_evpn
= bgp_get_evpn();
170 flog_err(EC_BGP_NO_DFLT
,
171 "vrf import rt free - evpn instance not created yet");
175 hash_release(bgp_evpn
->vrf_import_rt_hash
, irt
);
176 list_delete(&irt
->vrfs
);
177 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
180 static void hash_vrf_import_rt_free(struct vrf_irt_node
*irt
)
182 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
186 * Function to lookup Import RT node - used to map a RT to set of
187 * VNIs importing routes with that RT.
189 static struct vrf_irt_node
*lookup_vrf_import_rt(struct ecommunity_val
*rt
)
191 struct bgp
*bgp_evpn
= NULL
;
192 struct vrf_irt_node
*irt
;
193 struct vrf_irt_node tmp
;
195 bgp_evpn
= bgp_get_evpn();
199 "vrf import rt lookup - evpn instance not created yet");
203 memset(&tmp
, 0, sizeof(tmp
));
204 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
205 irt
= hash_lookup(bgp_evpn
->vrf_import_rt_hash
, &tmp
);
210 * Is specified VRF present on the RT's list of "importing" VRFs?
212 static int is_vrf_present_in_irt_vrfs(struct list
*vrfs
, struct bgp
*bgp_vrf
)
214 struct listnode
*node
= NULL
, *nnode
= NULL
;
215 struct bgp
*tmp_bgp_vrf
= NULL
;
217 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, tmp_bgp_vrf
)) {
218 if (tmp_bgp_vrf
== bgp_vrf
)
225 * Make import route target hash key.
227 static unsigned int import_rt_hash_key_make(const void *p
)
229 const struct irt_node
*irt
= p
;
230 const char *pnt
= irt
->rt
.val
;
232 return jhash(pnt
, 8, 0xdeadbeef);
236 * Comparison function for import rt hash
238 static bool import_rt_hash_cmp(const void *p1
, const void *p2
)
240 const struct irt_node
*irt1
= p1
;
241 const struct irt_node
*irt2
= p2
;
243 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
247 * Create a new import_rt
249 static struct irt_node
*import_rt_new(struct bgp
*bgp
,
250 struct ecommunity_val
*rt
)
252 struct irt_node
*irt
;
254 irt
= XCALLOC(MTYPE_BGP_EVPN_IMPORT_RT
, sizeof(struct irt_node
));
257 irt
->vnis
= list_new();
260 (void)hash_get(bgp
->import_rt_hash
, irt
, hash_alloc_intern
);
266 * Free the import rt node
268 static void import_rt_free(struct bgp
*bgp
, struct irt_node
*irt
)
270 hash_release(bgp
->import_rt_hash
, irt
);
271 list_delete(&irt
->vnis
);
272 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
275 static void hash_import_rt_free(struct irt_node
*irt
)
277 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
281 * Function to lookup Import RT node - used to map a RT to set of
282 * VNIs importing routes with that RT.
284 static struct irt_node
*lookup_import_rt(struct bgp
*bgp
,
285 struct ecommunity_val
*rt
)
287 struct irt_node
*irt
;
290 memset(&tmp
, 0, sizeof(tmp
));
291 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
292 irt
= hash_lookup(bgp
->import_rt_hash
, &tmp
);
297 * Is specified VNI present on the RT's list of "importing" VNIs?
299 static int is_vni_present_in_irt_vnis(struct list
*vnis
, struct bgpevpn
*vpn
)
301 struct listnode
*node
, *nnode
;
302 struct bgpevpn
*tmp_vpn
;
304 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, tmp_vpn
)) {
313 * Compare Route Targets.
315 int bgp_evpn_route_target_cmp(struct ecommunity
*ecom1
,
316 struct ecommunity
*ecom2
)
324 if (!ecom1
&& !ecom2
)
327 if (ecom1
->str
&& !ecom2
->str
)
330 if (!ecom1
->str
&& ecom2
->str
)
333 if (!ecom1
->str
&& !ecom2
->str
)
336 return strcmp(ecom1
->str
, ecom2
->str
);
340 * Compare L3 Route Targets.
342 static int evpn_vrf_route_target_cmp(struct vrf_route_target
*rt1
,
343 struct vrf_route_target
*rt2
)
345 return bgp_evpn_route_target_cmp(rt1
->ecom
, rt2
->ecom
);
348 void bgp_evpn_xxport_delete_ecomm(void *val
)
350 struct ecommunity
*ecomm
= val
;
351 ecommunity_free(&ecomm
);
355 * Delete l3 Route Target.
357 static void evpn_vrf_rt_del(void *val
)
359 struct vrf_route_target
*l3rt
= val
;
361 ecommunity_free(&l3rt
->ecom
);
363 XFREE(MTYPE_VRF_ROUTE_TARGET
, l3rt
);
367 * Allocate a new l3 Route Target.
369 static struct vrf_route_target
*evpn_vrf_rt_new(struct ecommunity
*ecom
)
371 struct vrf_route_target
*l3rt
;
373 l3rt
= XCALLOC(MTYPE_VRF_ROUTE_TARGET
, sizeof(struct vrf_route_target
));
381 * Mask off global-admin field of specified extended community (RT),
382 * just retain the local-admin field.
384 static inline void mask_ecom_global_admin(struct ecommunity_val
*dst
,
385 const struct ecommunity_val
*src
)
391 if (type
== ECOMMUNITY_ENCODE_AS
) {
392 dst
->val
[2] = dst
->val
[3] = 0;
393 } else if (type
== ECOMMUNITY_ENCODE_AS4
394 || type
== ECOMMUNITY_ENCODE_IP
) {
395 dst
->val
[2] = dst
->val
[3] = 0;
396 dst
->val
[4] = dst
->val
[5] = 0;
401 * Converts the RT to Ecommunity Value and adjusts masking based
402 * on flags set for RT.
404 static void vrf_rt2ecom_val(struct ecommunity_val
*to_eval
,
405 const struct vrf_route_target
*l3rt
, int iter
)
407 const struct ecommunity_val
*eval
;
409 eval
= (const struct ecommunity_val
*)(l3rt
->ecom
->val
+
410 (iter
* ECOMMUNITY_SIZE
));
411 /* If using "automatic" or "wildcard *" RT,
412 * we only care about the local-admin sub-field.
413 * This is to facilitate using L3VNI(VRF-VNI)
414 * as the RT for EBGP peering too and simplify
415 * configurations by allowing any ASN via '*'.
417 memcpy(to_eval
, eval
, ECOMMUNITY_SIZE
);
419 if (CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
) ||
420 CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_WILD
))
421 mask_ecom_global_admin(to_eval
, eval
);
425 * Map one RT to specified VRF.
426 * bgp_vrf = BGP vrf instance
428 static void map_vrf_to_rt(struct bgp
*bgp_vrf
, struct vrf_route_target
*l3rt
)
432 for (i
= 0; i
< l3rt
->ecom
->size
; i
++) {
433 struct vrf_irt_node
*irt
= NULL
;
434 struct ecommunity_val eval_tmp
;
436 /* Adjust masking for value */
437 vrf_rt2ecom_val(&eval_tmp
, l3rt
, i
);
439 irt
= lookup_vrf_import_rt(&eval_tmp
);
441 if (irt
&& is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
442 return; /* Already mapped. */
445 irt
= vrf_import_rt_new(&eval_tmp
);
447 /* Add VRF to the list for this RT. */
448 listnode_add(irt
->vrfs
, bgp_vrf
);
453 * Unmap specified VRF from specified RT. If there are no other
454 * VRFs for this RT, then the RT hash is deleted.
455 * bgp_vrf: BGP VRF specific instance
457 static void unmap_vrf_from_rt(struct bgp
*bgp_vrf
,
458 struct vrf_route_target
*l3rt
)
462 for (i
= 0; i
< l3rt
->ecom
->size
; i
++) {
463 struct vrf_irt_node
*irt
;
464 struct ecommunity_val eval_tmp
;
466 /* Adjust masking for value */
467 vrf_rt2ecom_val(&eval_tmp
, l3rt
, i
);
469 irt
= lookup_vrf_import_rt(&eval_tmp
);
472 return; /* Not mapped */
474 /* Delete VRF from list for this RT. */
475 listnode_delete(irt
->vrfs
, bgp_vrf
);
477 if (!listnode_head(irt
->vrfs
))
478 vrf_import_rt_free(irt
);
483 * Map one RT to specified VNI.
485 static void map_vni_to_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
486 struct ecommunity_val
*eval
)
488 struct irt_node
*irt
;
489 struct ecommunity_val eval_tmp
;
491 /* If using "automatic" RT, we only care about the local-admin
493 * This is to facilitate using VNI as the RT for EBGP peering too.
495 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
496 if (!is_import_rt_configured(vpn
))
497 mask_ecom_global_admin(&eval_tmp
, eval
);
499 irt
= lookup_import_rt(bgp
, &eval_tmp
);
501 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
502 /* Already mapped. */
506 irt
= import_rt_new(bgp
, &eval_tmp
);
508 /* Add VNI to the hash list for this RT. */
509 listnode_add(irt
->vnis
, vpn
);
513 * Unmap specified VNI from specified RT. If there are no other
514 * VNIs for this RT, then the RT hash is deleted.
516 static void unmap_vni_from_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
517 struct irt_node
*irt
)
519 /* Delete VNI from hash list for this RT. */
520 listnode_delete(irt
->vnis
, vpn
);
521 if (!listnode_head(irt
->vnis
)) {
522 import_rt_free(bgp
, irt
);
526 static void bgp_evpn_get_rmac_nexthop(struct bgpevpn
*vpn
,
527 const struct prefix_evpn
*p
,
528 struct attr
*attr
, uint8_t flags
)
530 struct bgp
*bgp_vrf
= vpn
->bgp_vrf
;
532 memset(&attr
->rmac
, 0, sizeof(struct ethaddr
));
536 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
539 /* Copy sys (pip) RMAC and PIP IP as nexthop
540 * in case of route is self MAC-IP,
541 * advertise-pip and advertise-svi-ip features
543 * Otherwise, for all host MAC-IP route's
546 if (CHECK_FLAG(flags
, BGP_EVPN_MACIP_TYPE_SVI_IP
)
547 && bgp_vrf
->evpn_info
->advertise_pip
&&
548 bgp_vrf
->evpn_info
->is_anycast_mac
) {
550 memcpy(&attr
->rmac
, &bgp_vrf
->evpn_info
->pip_rmac
,
552 attr
->nexthop
= bgp_vrf
->evpn_info
->pip_ip
;
553 attr
->mp_nexthop_global_in
=
554 bgp_vrf
->evpn_info
->pip_ip
;
556 memcpy(&attr
->rmac
, &bgp_vrf
->rmac
, ETH_ALEN
);
560 * Create RT extended community automatically from passed information:
561 * of the form AS:VNI.
562 * NOTE: We use only the lower 16 bits of the AS. This is sufficient as
563 * the need is to get a RT value that will be unique across different
564 * VNIs but the same across routers (in the same AS) for a particular
567 static void form_auto_rt(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
,
570 struct ecommunity_val eval
;
571 struct ecommunity
*ecomadd
;
572 struct ecommunity
*ecom
;
573 struct vrf_route_target
*l3rt
;
574 struct vrf_route_target
*newrt
;
575 bool ecom_found
= false;
576 struct listnode
*node
;
578 if (bgp
->advertise_autort_rfc8365
)
579 vni
|= EVPN_AUTORT_VXLAN
;
580 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
, true);
582 ecomadd
= ecommunity_new();
583 ecommunity_add_val(ecomadd
, &eval
, false, false);
586 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, l3rt
))
587 if (ecommunity_cmp(ecomadd
, l3rt
->ecom
)) {
592 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, ecom
))
593 if (ecommunity_cmp(ecomadd
, ecom
)) {
601 newrt
= evpn_vrf_rt_new(ecomadd
);
602 /* Label it as autoderived */
603 SET_FLAG(newrt
->flags
, BGP_VRF_RT_AUTO
);
604 listnode_add_sort(rtl
, newrt
);
606 listnode_add_sort(rtl
, ecomadd
);
608 ecommunity_free(&ecomadd
);
612 * Derive RD and RT for a VNI automatically. Invoked at the time of
615 static void derive_rd_rt_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
617 bgp_evpn_derive_auto_rd(bgp
, vpn
);
618 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
619 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
623 * Convert nexthop (remote VTEP IP) into an IPv6 address.
625 static void evpn_convert_nexthop_to_ipv6(struct attr
*attr
)
627 if (BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
629 ipv4_to_ipv4_mapped_ipv6(&attr
->mp_nexthop_global
, attr
->nexthop
);
630 attr
->mp_nexthop_len
= IPV6_MAX_BYTELEN
;
634 * Wrapper for node get in global table.
636 struct bgp_dest
*bgp_evpn_global_node_get(struct bgp_table
*table
, afi_t afi
,
638 const struct prefix_evpn
*evp
,
639 struct prefix_rd
*prd
,
640 const struct bgp_path_info
*local_pi
)
642 struct prefix_evpn global_p
;
644 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
645 /* prefix in the global table doesn't include the VTEP-IP so
646 * we need to create a different copy of the prefix
648 evpn_type1_prefix_global_copy(&global_p
, evp
);
650 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
653 * prefix in the global table needs MAC/IP, ensure they are
654 * present, using one's from local table's path_info.
656 if (is_evpn_prefix_ipaddr_none(evp
)) {
657 /* VNI MAC -> Global */
658 evpn_type2_prefix_global_copy(
659 &global_p
, evp
, NULL
/* mac */,
660 evpn_type2_path_info_get_ip(local_pi
));
662 /* VNI IP -> Global */
663 evpn_type2_prefix_global_copy(
665 evpn_type2_path_info_get_mac(local_pi
),
671 return bgp_afi_node_get(table
, afi
, safi
, (struct prefix
*)evp
, prd
);
675 * Wrapper for node lookup in global table.
677 struct bgp_dest
*bgp_evpn_global_node_lookup(
678 struct bgp_table
*table
, safi_t safi
, const struct prefix_evpn
*evp
,
679 struct prefix_rd
*prd
, const struct bgp_path_info
*local_pi
)
681 struct prefix_evpn global_p
;
683 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
684 /* prefix in the global table doesn't include the VTEP-IP so
685 * we need to create a different copy of the prefix
687 evpn_type1_prefix_global_copy(&global_p
, evp
);
689 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
692 * prefix in the global table needs MAC/IP, ensure they are
693 * present, using one's from local table's path_info.
695 if (is_evpn_prefix_ipaddr_none(evp
)) {
696 /* VNI MAC -> Global */
697 evpn_type2_prefix_global_copy(
698 &global_p
, evp
, NULL
/* mac */,
699 evpn_type2_path_info_get_ip(local_pi
));
701 /* VNI IP -> Global */
702 evpn_type2_prefix_global_copy(
704 evpn_type2_path_info_get_mac(local_pi
),
710 return bgp_safi_node_lookup(table
, safi
, (struct prefix
*)evp
, prd
);
714 * Wrapper for node get in VNI IP table.
716 struct bgp_dest
*bgp_evpn_vni_ip_node_get(struct bgp_table
*const table
,
717 const struct prefix_evpn
*evp
,
718 const struct bgp_path_info
*parent_pi
)
720 struct prefix_evpn vni_p
;
722 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
723 /* prefix in the global table doesn't include the VTEP-IP so
724 * we need to create a different copy for the VNI
726 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
727 parent_pi
->attr
->nexthop
);
729 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
730 /* Only MAC-IP should go into this table, not mac-only */
731 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
734 * prefix in the vni IP table doesn't include MAC so
735 * we need to create a different copy of the prefix.
737 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
740 return bgp_node_get(table
, (struct prefix
*)evp
);
744 * Wrapper for node lookup in VNI IP table.
747 bgp_evpn_vni_ip_node_lookup(const struct bgp_table
*const table
,
748 const struct prefix_evpn
*evp
,
749 const struct bgp_path_info
*parent_pi
)
751 struct prefix_evpn vni_p
;
753 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
754 /* prefix in the global table doesn't include the VTEP-IP so
755 * we need to create a different copy for the VNI
757 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
758 parent_pi
->attr
->nexthop
);
760 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
761 /* Only MAC-IP should go into this table, not mac-only */
762 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
765 * prefix in the vni IP table doesn't include MAC so
766 * we need to create a different copy of the prefix.
768 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
771 return bgp_node_lookup(table
, (struct prefix
*)evp
);
775 * Wrapper for node get in VNI MAC table.
778 bgp_evpn_vni_mac_node_get(struct bgp_table
*const table
,
779 const struct prefix_evpn
*evp
,
780 const struct bgp_path_info
*parent_pi
)
782 struct prefix_evpn vni_p
;
784 /* Only type-2 should ever go into this table */
785 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
788 * prefix in the vni MAC table doesn't include IP so
789 * we need to create a different copy of the prefix.
791 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
793 return bgp_node_get(table
, (struct prefix
*)evp
);
797 * Wrapper for node lookup in VNI MAC table.
800 bgp_evpn_vni_mac_node_lookup(const struct bgp_table
*const table
,
801 const struct prefix_evpn
*evp
,
802 const struct bgp_path_info
*parent_pi
)
804 struct prefix_evpn vni_p
;
806 /* Only type-2 should ever go into this table */
807 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
810 * prefix in the vni MAC table doesn't include IP so
811 * we need to create a different copy of the prefix.
813 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
815 return bgp_node_lookup(table
, (struct prefix
*)evp
);
819 * Wrapper for node get in both VNI tables.
821 struct bgp_dest
*bgp_evpn_vni_node_get(struct bgpevpn
*vpn
,
822 const struct prefix_evpn
*p
,
823 const struct bgp_path_info
*parent_pi
)
825 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
826 (is_evpn_prefix_ipaddr_none(p
) == true))
827 return bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
829 return bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
833 * Wrapper for node lookup in both VNI tables.
835 struct bgp_dest
*bgp_evpn_vni_node_lookup(const struct bgpevpn
*vpn
,
836 const struct prefix_evpn
*p
,
837 const struct bgp_path_info
*parent_pi
)
839 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
840 (is_evpn_prefix_ipaddr_none(p
) == true))
841 return bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
,
844 return bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
848 * Add (update) or delete MACIP from zebra.
850 static int bgp_zebra_send_remote_macip(struct bgp
*bgp
, struct bgpevpn
*vpn
,
851 const struct prefix_evpn
*p
,
852 const struct ethaddr
*mac
,
853 struct in_addr remote_vtep_ip
, int add
,
854 uint8_t flags
, uint32_t seq
, esi_t
*esi
)
858 static struct in_addr zero_remote_vtep_ip
;
862 if (!zclient
|| zclient
->sock
< 0)
865 /* Don't try to register if Zebra doesn't know of this instance. */
866 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
867 if (BGP_DEBUG(zebra
, ZEBRA
))
869 "%s: No zebra instance to talk to, not installing remote macip",
879 zclient_create_header(
880 s
, add
? ZEBRA_REMOTE_MACIP_ADD
: ZEBRA_REMOTE_MACIP_DEL
,
882 stream_putl(s
, vpn
->vni
);
884 if (mac
) /* Mac Addr */
885 stream_put(s
, &mac
->octet
, ETH_ALEN
);
887 stream_put(s
, &p
->prefix
.macip_addr
.mac
.octet
, ETH_ALEN
);
889 /* IP address length and IP address, if any. */
890 if (is_evpn_prefix_ipaddr_none(p
))
893 ipa_len
= is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BYTELEN
895 stream_putw(s
, ipa_len
);
896 stream_put(s
, &p
->prefix
.macip_addr
.ip
.ip
.addr
, ipa_len
);
898 /* If the ESI is valid that becomes the nexthop; tape out the
899 * VTEP-IP for that case
901 if (bgp_evpn_is_esi_valid(esi
)) {
903 stream_put_in_addr(s
, &zero_remote_vtep_ip
);
906 stream_put_in_addr(s
, &remote_vtep_ip
);
909 /* TX flags - MAC sticky status and/or gateway mac */
910 /* Also TX the sequence number of the best route. */
912 stream_putc(s
, flags
);
914 stream_put(s
, esi
, sizeof(esi_t
));
917 stream_putw_at(s
, 0, stream_get_endp(s
));
919 if (bgp_debug_zebra(NULL
)) {
920 char esi_buf
[ESI_STR_LEN
];
923 esi_to_str(esi
, esi_buf
, sizeof(esi_buf
));
925 snprintf(esi_buf
, sizeof(esi_buf
), "-");
927 "Tx %s MACIP, VNI %u MAC %pEA IP %pIA flags 0x%x seq %u remote VTEP %pI4 esi %s",
928 add
? "ADD" : "DEL", vpn
->vni
,
929 (mac
? mac
: &p
->prefix
.macip_addr
.mac
),
930 &p
->prefix
.macip_addr
.ip
, flags
, seq
, &remote_vtep_ip
,
934 frrtrace(5, frr_bgp
, evpn_mac_ip_zsend
, add
, vpn
, p
, remote_vtep_ip
,
937 return zclient_send_message(zclient
);
941 * Add (update) or delete remote VTEP from zebra.
943 static int bgp_zebra_send_remote_vtep(struct bgp
*bgp
, struct bgpevpn
*vpn
,
944 const struct prefix_evpn
*p
,
945 int flood_control
, int add
)
950 if (!zclient
|| zclient
->sock
< 0)
953 /* Don't try to register if Zebra doesn't know of this instance. */
954 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
955 if (BGP_DEBUG(zebra
, ZEBRA
))
957 "%s: No zebra instance to talk to, not installing remote vtep",
965 zclient_create_header(
966 s
, add
? ZEBRA_REMOTE_VTEP_ADD
: ZEBRA_REMOTE_VTEP_DEL
,
968 stream_putl(s
, vpn
->vni
);
969 if (is_evpn_prefix_ipaddr_v4(p
))
970 stream_put_in_addr(s
, &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
971 else if (is_evpn_prefix_ipaddr_v6(p
)) {
974 "Bad remote IP when trying to %s remote VTEP for VNI %u",
975 add
? "ADD" : "DEL", vpn
->vni
);
978 stream_putl(s
, flood_control
);
980 stream_putw_at(s
, 0, stream_get_endp(s
));
982 if (bgp_debug_zebra(NULL
))
983 zlog_debug("Tx %s Remote VTEP, VNI %u remote VTEP %pI4",
984 add
? "ADD" : "DEL", vpn
->vni
,
985 &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
987 frrtrace(3, frr_bgp
, evpn_bum_vtep_zsend
, add
, vpn
, p
);
989 return zclient_send_message(zclient
);
993 * Build extended communities for EVPN prefix route.
995 static void build_evpn_type5_route_extcomm(struct bgp
*bgp_vrf
,
998 struct ecommunity ecom_encap
;
999 struct ecommunity_val eval
;
1000 struct ecommunity_val eval_rmac
;
1001 bgp_encap_types tnl_type
;
1002 struct listnode
*node
, *nnode
;
1003 struct vrf_route_target
*l3rt
;
1004 struct ecommunity
*old_ecom
;
1005 struct ecommunity
*ecom
;
1006 struct list
*vrf_export_rtl
= NULL
;
1009 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1010 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1011 encode_encap_extcomm(tnl_type
, &eval
);
1012 ecom_encap
.size
= 1;
1013 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1014 ecom_encap
.val
= (uint8_t *)eval
.val
;
1017 if (bgp_attr_get_ecommunity(attr
)) {
1018 old_ecom
= bgp_attr_get_ecommunity(attr
);
1019 ecom
= ecommunity_merge(ecommunity_dup(old_ecom
), &ecom_encap
);
1020 if (!old_ecom
->refcnt
)
1021 ecommunity_free(&old_ecom
);
1023 ecom
= ecommunity_dup(&ecom_encap
);
1024 bgp_attr_set_ecommunity(attr
, ecom
);
1025 attr
->encap_tunneltype
= tnl_type
;
1027 /* Add the export RTs for L3VNI/VRF */
1028 vrf_export_rtl
= bgp_vrf
->vrf_export_rtl
;
1029 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
, l3rt
))
1030 bgp_attr_set_ecommunity(
1031 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1034 /* add the router mac extended community */
1035 if (!is_zero_mac(&attr
->rmac
)) {
1036 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1037 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1043 * Build extended communities for EVPN route.
1044 * This function is applicable for type-2 and type-3 routes. The layer-2 RT
1045 * and ENCAP extended communities are applicable for all routes.
1046 * The default gateway extended community and MAC mobility (sticky) extended
1047 * community are added as needed based on passed settings - only for type-2
1048 * routes. Likewise, the layer-3 RT and Router MAC extended communities are
1049 * added, if present, based on passed settings - only for non-link-local
1052 static void build_evpn_route_extcomm(struct bgpevpn
*vpn
, struct attr
*attr
,
1055 struct ecommunity ecom_encap
;
1056 struct ecommunity ecom_sticky
;
1057 struct ecommunity ecom_default_gw
;
1058 struct ecommunity ecom_na
;
1059 struct ecommunity_val eval
;
1060 struct ecommunity_val eval_sticky
;
1061 struct ecommunity_val eval_default_gw
;
1062 struct ecommunity_val eval_rmac
;
1063 struct ecommunity_val eval_na
;
1066 bgp_encap_types tnl_type
;
1067 struct listnode
*node
, *nnode
;
1068 struct ecommunity
*ecom
;
1069 struct vrf_route_target
*l3rt
;
1071 struct list
*vrf_export_rtl
= NULL
;
1074 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1075 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1076 encode_encap_extcomm(tnl_type
, &eval
);
1077 ecom_encap
.size
= 1;
1078 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1079 ecom_encap
.val
= (uint8_t *)eval
.val
;
1082 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
1083 attr
->encap_tunneltype
= tnl_type
;
1085 /* Add the export RTs for L2VNI */
1086 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
))
1087 bgp_attr_set_ecommunity(
1089 ecommunity_merge(bgp_attr_get_ecommunity(attr
), ecom
));
1091 /* Add the export RTs for L3VNI if told to - caller determines
1092 * when this should be done.
1095 vrf_export_rtl
= bgpevpn_get_vrf_export_rtl(vpn
);
1096 if (vrf_export_rtl
&& !list_isempty(vrf_export_rtl
)) {
1097 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
,
1099 bgp_attr_set_ecommunity(
1102 bgp_attr_get_ecommunity(attr
),
1107 /* Add MAC mobility (sticky) if needed. */
1110 memset(&ecom_sticky
, 0, sizeof(ecom_sticky
));
1111 encode_mac_mobility_extcomm(1, seqnum
, &eval_sticky
);
1112 ecom_sticky
.size
= 1;
1113 ecom_sticky
.unit_size
= ECOMMUNITY_SIZE
;
1114 ecom_sticky
.val
= (uint8_t *)eval_sticky
.val
;
1115 bgp_attr_set_ecommunity(
1116 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1120 /* Add RMAC, if told to. */
1122 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1123 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1127 /* Add default gateway, if needed. */
1128 if (attr
->default_gw
) {
1129 memset(&ecom_default_gw
, 0, sizeof(ecom_default_gw
));
1130 encode_default_gw_extcomm(&eval_default_gw
);
1131 ecom_default_gw
.size
= 1;
1132 ecom_default_gw
.unit_size
= ECOMMUNITY_SIZE
;
1133 ecom_default_gw
.val
= (uint8_t *)eval_default_gw
.val
;
1134 bgp_attr_set_ecommunity(
1135 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1139 proxy
= !!(attr
->es_flags
& ATTR_ES_PROXY_ADVERT
);
1140 if (attr
->router_flag
|| proxy
) {
1141 memset(&ecom_na
, 0, sizeof(ecom_na
));
1142 encode_na_flag_extcomm(&eval_na
, attr
->router_flag
, proxy
);
1144 ecom_na
.unit_size
= ECOMMUNITY_SIZE
;
1145 ecom_na
.val
= (uint8_t *)eval_na
.val
;
1146 bgp_attr_set_ecommunity(
1147 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1153 * Add MAC mobility extended community to attribute.
1155 static void add_mac_mobility_to_attr(uint32_t seq_num
, struct attr
*attr
)
1157 struct ecommunity ecom_tmp
;
1158 struct ecommunity_val eval
;
1159 uint8_t *ecom_val_ptr
;
1164 struct ecommunity
*ecomm
= bgp_attr_get_ecommunity(attr
);
1167 encode_mac_mobility_extcomm(0, seq_num
, &eval
);
1169 /* Find current MM ecommunity */
1170 ecom_val_ptr
= NULL
;
1173 for (i
= 0; i
< ecomm
->size
; i
++) {
1174 pnt
= ecomm
->val
+ (i
* ecomm
->unit_size
);
1178 if (type
== ECOMMUNITY_ENCODE_EVPN
1180 == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY
) {
1182 (ecomm
->val
+ (i
* ecomm
->unit_size
));
1188 /* Update the existing MM ecommunity */
1190 memcpy(ecom_val_ptr
, eval
.val
, sizeof(char) * ecomm
->unit_size
);
1192 /* Add MM to existing */
1194 memset(&ecom_tmp
, 0, sizeof(ecom_tmp
));
1196 ecom_tmp
.unit_size
= ECOMMUNITY_SIZE
;
1197 ecom_tmp
.val
= (uint8_t *)eval
.val
;
1200 bgp_attr_set_ecommunity(
1201 attr
, ecommunity_merge(ecomm
, &ecom_tmp
));
1203 bgp_attr_set_ecommunity(attr
,
1204 ecommunity_dup(&ecom_tmp
));
1208 /* Install EVPN route into zebra. */
1209 static int evpn_zebra_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1210 const struct prefix_evpn
*p
,
1211 struct bgp_path_info
*pi
)
1215 int flood_control
= VXLAN_FLOOD_DISABLED
;
1218 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1221 if (pi
->sub_type
== BGP_ROUTE_IMPORTED
) {
1222 if (pi
->attr
->sticky
)
1223 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1224 if (pi
->attr
->default_gw
)
1225 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1226 if (is_evpn_prefix_ipaddr_v6(p
) &&
1227 pi
->attr
->router_flag
)
1228 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1230 seq
= mac_mobility_seqnum(pi
->attr
);
1231 /* if local ES notify zebra that this is a sync path */
1232 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
1233 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1234 if (bgp_evpn_attr_is_proxy(pi
->attr
))
1236 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1239 if (!bgp_evpn_attr_is_sync(pi
->attr
))
1242 /* if a local path is being turned around and sent
1243 * to zebra it is because it is a sync path on
1246 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1247 /* supply the highest peer seq number to zebra
1248 * for MM seq syncing
1250 seq
= bgp_evpn_attr_get_sync_seq(pi
->attr
);
1251 /* if any of the paths from the peer have the ROUTER
1252 * flag set install the local entry as a router entry
1254 if (is_evpn_prefix_ipaddr_v6(p
) &&
1255 (pi
->attr
->es_flags
&
1256 ATTR_ES_PEER_ROUTER
))
1258 ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1260 if (!(pi
->attr
->es_flags
& ATTR_ES_PEER_ACTIVE
))
1262 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1265 ret
= bgp_zebra_send_remote_macip(
1267 (is_evpn_prefix_ipaddr_none(p
)
1268 ? NULL
/* MAC update */
1269 : evpn_type2_path_info_get_mac(
1270 pi
) /* MAC-IP update */),
1271 pi
->attr
->nexthop
, 1, flags
, seq
,
1272 bgp_evpn_attr_get_esi(pi
->attr
));
1273 } else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
1274 ret
= bgp_evpn_remote_es_evi_add(bgp
, vpn
, p
);
1276 switch (bgp_attr_get_pmsi_tnl_type(pi
->attr
)) {
1277 case PMSI_TNLTYPE_INGR_REPL
:
1278 flood_control
= VXLAN_FLOOD_HEAD_END_REPL
;
1281 case PMSI_TNLTYPE_PIM_SM
:
1282 flood_control
= VXLAN_FLOOD_PIM_SM
;
1285 case PMSI_TNLTYPE_NO_INFO
:
1286 case PMSI_TNLTYPE_RSVP_TE_P2MP
:
1287 case PMSI_TNLTYPE_MLDP_P2MP
:
1288 case PMSI_TNLTYPE_PIM_SSM
:
1289 case PMSI_TNLTYPE_PIM_BIDIR
:
1290 case PMSI_TNLTYPE_MLDP_MP2MP
:
1291 flood_control
= VXLAN_FLOOD_DISABLED
;
1294 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
, flood_control
, 1);
1300 /* Uninstall EVPN route from zebra. */
1301 static int evpn_zebra_uninstall(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1302 const struct prefix_evpn
*p
,
1303 struct bgp_path_info
*pi
, bool is_sync
)
1307 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
1308 ret
= bgp_zebra_send_remote_macip(
1310 (is_evpn_prefix_ipaddr_none(p
)
1311 ? NULL
/* MAC update */
1312 : evpn_type2_path_info_get_mac(
1313 pi
) /* MAC-IP update */),
1314 (is_sync
? zero_vtep_ip
: pi
->attr
->nexthop
), 0, 0, 0,
1316 else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
1317 ret
= bgp_evpn_remote_es_evi_del(bgp
, vpn
, p
);
1319 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
,
1320 VXLAN_FLOOD_DISABLED
, 0);
1326 * Due to MAC mobility, the prior "local" best route has been supplanted
1327 * by a "remote" best route. The prior route has to be deleted and withdrawn
1330 static void evpn_delete_old_local_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1331 struct bgp_dest
*dest
,
1332 struct bgp_path_info
*old_local
,
1333 struct bgp_path_info
*new_select
)
1335 struct bgp_dest
*global_dest
;
1336 struct bgp_path_info
*pi
;
1337 afi_t afi
= AFI_L2VPN
;
1338 safi_t safi
= SAFI_EVPN
;
1340 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1341 char esi_buf
[ESI_STR_LEN
];
1342 char esi_buf2
[ESI_STR_LEN
];
1343 struct prefix_evpn
*evp
=
1344 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1346 zlog_debug("local path deleted %pFX es %s; new-path-es %s", evp
,
1347 esi_to_str(&old_local
->attr
->esi
, esi_buf
,
1349 new_select
? esi_to_str(&new_select
->attr
->esi
,
1350 esi_buf2
, sizeof(esi_buf2
))
1354 /* Locate route node in the global EVPN routing table. Note that
1355 * this table is a 2-level tree (RD-level + Prefix-level) similar to
1358 global_dest
= bgp_evpn_global_node_lookup(
1359 bgp
->rib
[afi
][safi
], safi
,
1360 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1361 &vpn
->prd
, old_local
);
1363 /* Delete route entry in the global EVPN table. */
1364 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
1366 /* Schedule for processing - withdraws to peers happen from
1370 bgp_process(bgp
, global_dest
, afi
, safi
);
1371 bgp_dest_unlock_node(global_dest
);
1374 /* Delete route entry in the VNI route table, caller to remove. */
1375 bgp_path_info_delete(dest
, old_local
);
1379 * Calculate the best path for an EVPN route. Install/update best path in zebra,
1381 * Note: vpn is NULL for local EAD-ES routes.
1383 int evpn_route_select_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1384 struct bgp_dest
*dest
)
1386 struct bgp_path_info
*old_select
, *new_select
;
1387 struct bgp_path_info_pair old_and_new
;
1388 afi_t afi
= AFI_L2VPN
;
1389 safi_t safi
= SAFI_EVPN
;
1392 /* Compute the best path. */
1393 bgp_best_selection(bgp
, dest
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
1395 old_select
= old_and_new
.old
;
1396 new_select
= old_and_new
.new;
1398 /* If the best path hasn't changed - see if there is still something to
1399 * update to zebra RIB.
1400 * Remote routes and SYNC route (i.e. local routes with
1401 * SYNCED_FROM_PEER flag) need to updated to zebra on any attr
1404 if (old_select
&& old_select
== new_select
1405 && old_select
->type
== ZEBRA_ROUTE_BGP
1406 && (old_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1407 bgp_evpn_attr_is_sync(old_select
->attr
))
1408 && !CHECK_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
)
1409 && !CHECK_FLAG(old_select
->flags
, BGP_PATH_ATTR_CHANGED
)
1410 && !bgp_addpath_is_addpath_used(&bgp
->tx_addpath
, afi
, safi
)) {
1411 if (bgp_zebra_has_route_changed(old_select
))
1412 ret
= evpn_zebra_install(
1414 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1417 UNSET_FLAG(old_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1418 UNSET_FLAG(old_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1419 bgp_zebra_clear_route_change_flags(dest
);
1423 /* If the user did a "clear" this flag will be set */
1424 UNSET_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
);
1426 /* bestpath has changed; update relevant fields and install or uninstall
1427 * into the zebra RIB.
1429 if (old_select
|| new_select
)
1430 bgp_bump_version(dest
);
1433 bgp_path_info_unset_flag(dest
, old_select
, BGP_PATH_SELECTED
);
1435 bgp_path_info_set_flag(dest
, new_select
, BGP_PATH_SELECTED
);
1436 bgp_path_info_unset_flag(dest
, new_select
,
1437 BGP_PATH_ATTR_CHANGED
);
1438 UNSET_FLAG(new_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1439 UNSET_FLAG(new_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1442 /* a local entry with the SYNC flag also results in a MAC-IP update
1445 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
1446 && (new_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1447 bgp_evpn_attr_is_sync(new_select
->attr
))) {
1448 ret
= evpn_zebra_install(
1450 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1453 /* If an old best existed and it was a "local" route, the only
1455 * it would be supplanted is due to MAC mobility procedures. So,
1457 * need to do an implicit delete and withdraw that route from
1460 if (new_select
->sub_type
== BGP_ROUTE_IMPORTED
&&
1461 old_select
&& old_select
->peer
== bgp
->peer_self
1462 && old_select
->type
== ZEBRA_ROUTE_BGP
1463 && old_select
->sub_type
== BGP_ROUTE_STATIC
1465 evpn_delete_old_local_route(bgp
, vpn
, dest
,
1466 old_select
, new_select
);
1468 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
1469 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
1470 ret
= evpn_zebra_uninstall(
1472 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1477 /* Clear any route change flags. */
1478 bgp_zebra_clear_route_change_flags(dest
);
1480 /* Reap old select bgp_path_info, if it has been removed */
1481 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_PATH_REMOVED
))
1482 bgp_path_info_reap(dest
, old_select
);
1487 static struct bgp_path_info
*bgp_evpn_route_get_local_path(
1488 struct bgp
*bgp
, struct bgp_dest
*dest
)
1490 struct bgp_path_info
*tmp_pi
;
1491 struct bgp_path_info
*local_pi
= NULL
;
1493 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1494 tmp_pi
= tmp_pi
->next
) {
1495 if (bgp_evpn_is_path_local(bgp
, tmp_pi
)) {
1504 static int update_evpn_type5_route_entry(struct bgp
*bgp_evpn
,
1505 struct bgp
*bgp_vrf
, afi_t afi
,
1506 safi_t safi
, struct bgp_dest
*dest
,
1507 struct attr
*attr
, int *route_changed
)
1509 struct attr
*attr_new
= NULL
;
1510 struct bgp_path_info
*pi
= NULL
;
1511 mpls_label_t label
= MPLS_INVALID_LABEL
;
1512 struct bgp_path_info
*local_pi
= NULL
;
1513 struct bgp_path_info
*tmp_pi
= NULL
;
1517 /* See if this is an update of an existing route, or a new add. */
1518 local_pi
= bgp_evpn_route_get_local_path(bgp_evpn
, dest
);
1521 * create a new route entry if one doesn't exist.
1522 * Otherwise see if route attr has changed
1526 /* route has changed as this is the first entry */
1529 /* Add (or update) attribute to hash. */
1530 attr_new
= bgp_attr_intern(attr
);
1532 /* create the route info from attribute */
1533 pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1534 bgp_evpn
->peer_self
, attr_new
, dest
);
1535 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
1537 /* Type-5 routes advertise the L3-VNI */
1538 bgp_path_info_extra_get(pi
);
1539 vni2label(bgp_vrf
->l3vni
, &label
);
1540 memcpy(&pi
->extra
->label
, &label
, sizeof(label
));
1541 pi
->extra
->num_labels
= 1;
1543 /* add the route entry to route node*/
1544 bgp_path_info_add(dest
, pi
);
1548 if (!attrhash_cmp(tmp_pi
->attr
, attr
)) {
1550 /* attribute changed */
1553 /* The attribute has changed. */
1554 /* Add (or update) attribute to hash. */
1555 attr_new
= bgp_attr_intern(attr
);
1556 bgp_path_info_set_flag(dest
, tmp_pi
,
1557 BGP_PATH_ATTR_CHANGED
);
1559 /* Restore route, if needed. */
1560 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1561 bgp_path_info_restore(dest
, tmp_pi
);
1563 /* Unintern existing, set to new. */
1564 bgp_attr_unintern(&tmp_pi
->attr
);
1565 tmp_pi
->attr
= attr_new
;
1566 tmp_pi
->uptime
= monotime(NULL
);
1572 /* update evpn type-5 route entry */
1573 static int update_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
,
1574 struct attr
*src_attr
, afi_t src_afi
,
1577 afi_t afi
= AFI_L2VPN
;
1578 safi_t safi
= SAFI_EVPN
;
1580 struct bgp_dest
*dest
= NULL
;
1581 struct bgp
*bgp_evpn
= NULL
;
1582 int route_changed
= 0;
1584 bgp_evpn
= bgp_get_evpn();
1588 /* Build path attribute for this route - use the source attr, if
1589 * present, else treat as locally originated.
1594 memset(&attr
, 0, sizeof(attr
));
1595 bgp_attr_default_set(&attr
, bgp_vrf
, BGP_ORIGIN_IGP
);
1598 /* Advertise Primary IP (PIP) is enabled, send individual
1599 * IP (default instance router-id) as nexthop.
1600 * PIP is disabled or vrr interface is not present
1601 * use anycast-IP as nexthop and anycast RMAC.
1603 if (!bgp_vrf
->evpn_info
->advertise_pip
||
1604 (!bgp_vrf
->evpn_info
->is_anycast_mac
)) {
1605 attr
.nexthop
= bgp_vrf
->originator_ip
;
1606 attr
.mp_nexthop_global_in
= bgp_vrf
->originator_ip
;
1607 memcpy(&attr
.rmac
, &bgp_vrf
->rmac
, ETH_ALEN
);
1610 memcpy(&attr
.rmac
, &bgp_vrf
->evpn_info
->pip_rmac
, ETH_ALEN
);
1611 if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
!= INADDR_ANY
) {
1612 attr
.nexthop
= bgp_vrf
->evpn_info
->pip_ip
;
1613 attr
.mp_nexthop_global_in
= bgp_vrf
->evpn_info
->pip_ip
;
1614 } else if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
== INADDR_ANY
)
1615 if (bgp_debug_zebra(NULL
))
1617 "VRF %s evp %pFX advertise-pip primary ip is not configured",
1618 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
);
1621 if (bgp_debug_zebra(NULL
))
1623 "VRF %s type-5 route evp %pFX RMAC %pEA nexthop %pI4",
1624 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, &attr
.rmac
,
1627 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1629 if (src_afi
== AFI_IP6
&&
1630 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1631 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
)) {
1633 !IN6_IS_ADDR_UNSPECIFIED(&src_attr
->mp_nexthop_global
)) {
1634 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1635 SET_IPADDR_V6(&attr
.evpn_overlay
.gw_ip
);
1636 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
1637 &src_attr
->mp_nexthop_global
,
1638 sizeof(struct in6_addr
));
1640 } else if (src_afi
== AFI_IP
&&
1641 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1642 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
)) {
1643 if (src_attr
&& src_attr
->nexthop
.s_addr
!= 0) {
1644 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1645 SET_IPADDR_V4(&attr
.evpn_overlay
.gw_ip
);
1646 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v4
,
1647 &src_attr
->nexthop
, sizeof(struct in_addr
));
1651 /* Setup RT and encap extended community */
1652 build_evpn_type5_route_extcomm(bgp_vrf
, &attr
);
1654 /* get the route node in global table */
1655 dest
= bgp_evpn_global_node_get(bgp_evpn
->rib
[afi
][safi
], afi
, safi
,
1656 evp
, &bgp_vrf
->vrf_prd
, NULL
);
1659 /* create or update the route entry within the route node */
1660 update_evpn_type5_route_entry(bgp_evpn
, bgp_vrf
, afi
, safi
, dest
, &attr
,
1663 /* schedule for processing and unlock node */
1664 if (route_changed
) {
1665 bgp_process(bgp_evpn
, dest
, afi
, safi
);
1666 bgp_dest_unlock_node(dest
);
1669 /* uninten temporary */
1671 aspath_unintern(&attr
.aspath
);
1675 static void bgp_evpn_get_sync_info(struct bgp
*bgp
, esi_t
*esi
,
1676 struct bgp_dest
*dest
, uint32_t loc_seq
,
1677 uint32_t *max_sync_seq
, bool *active_on_peer
,
1678 bool *peer_router
, bool *proxy_from_peer
,
1679 const struct ethaddr
*mac
)
1681 struct bgp_path_info
*tmp_pi
;
1682 struct bgp_path_info
*second_best_path
= NULL
;
1683 uint32_t tmp_mm_seq
= 0;
1686 struct ethaddr
*tmp_mac
;
1687 bool mac_cmp
= false;
1688 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&dest
->p
;
1691 /* mac comparison is not needed for MAC-only routes */
1692 if (mac
&& !is_evpn_prefix_ipaddr_none(evp
))
1695 /* find the best non-local path. a local path can only be present
1698 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1699 tmp_pi
= tmp_pi
->next
) {
1700 if (tmp_pi
->sub_type
!= BGP_ROUTE_IMPORTED
||
1701 !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
))
1704 /* ignore paths that have a different mac */
1706 tmp_mac
= evpn_type2_path_info_get_mac(tmp_pi
);
1707 if (memcmp(mac
, tmp_mac
, sizeof(*mac
)))
1711 if (bgp_evpn_path_info_cmp(bgp
, tmp_pi
,
1712 second_best_path
, &paths_eq
))
1713 second_best_path
= tmp_pi
;
1716 if (!second_best_path
)
1719 tmp_esi
= bgp_evpn_attr_get_esi(second_best_path
->attr
);
1720 /* if this has the same ES desination as the local path
1723 if (!memcmp(esi
, tmp_esi
, sizeof(esi_t
))) {
1724 tmp_mm_seq
= mac_mobility_seqnum(second_best_path
->attr
);
1725 if (tmp_mm_seq
< loc_seq
)
1728 /* we have a non-proxy path from the ES peer. */
1729 if (second_best_path
->attr
->es_flags
&
1730 ATTR_ES_PROXY_ADVERT
) {
1731 *proxy_from_peer
= true;
1733 *active_on_peer
= true;
1736 if (second_best_path
->attr
->router_flag
)
1737 *peer_router
= true;
1739 /* we use both proxy and non-proxy imports to
1740 * determine the max sync sequence
1742 if (tmp_mm_seq
> *max_sync_seq
)
1743 *max_sync_seq
= tmp_mm_seq
;
1747 /* Bubble up sync-info from all paths (non-best) to the local-path.
1748 * This is need for MM sequence number syncing and proxy advertisement.
1749 * Note: The local path can only exist as a best path in the
1750 * VPN route table. It will take precedence over all sync paths.
1752 static void update_evpn_route_entry_sync_info(struct bgp
*bgp
,
1753 struct bgp_dest
*dest
,
1755 uint32_t loc_seq
, bool setup_sync
,
1756 const struct ethaddr
*mac
)
1759 struct prefix_evpn
*evp
=
1760 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1762 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
1765 esi
= bgp_evpn_attr_get_esi(attr
);
1766 if (bgp_evpn_is_esi_valid(esi
)) {
1768 uint32_t max_sync_seq
= 0;
1769 bool active_on_peer
= false;
1770 bool peer_router
= false;
1771 bool proxy_from_peer
= false;
1773 bgp_evpn_get_sync_info(bgp
, esi
, dest
, loc_seq
,
1774 &max_sync_seq
, &active_on_peer
,
1775 &peer_router
, &proxy_from_peer
,
1777 attr
->mm_sync_seqnum
= max_sync_seq
;
1779 attr
->es_flags
|= ATTR_ES_PEER_ACTIVE
;
1781 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1782 if (proxy_from_peer
)
1783 attr
->es_flags
|= ATTR_ES_PEER_PROXY
;
1785 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1787 attr
->es_flags
|= ATTR_ES_PEER_ROUTER
;
1789 attr
->es_flags
&= ~ATTR_ES_PEER_ROUTER
;
1791 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1792 char esi_buf
[ESI_STR_LEN
];
1795 "setup sync info for %pFX es %s max_seq %d %s%s%s",
1797 esi_to_str(esi
, esi_buf
,
1800 (attr
->es_flags
& ATTR_ES_PEER_ACTIVE
)
1803 (attr
->es_flags
& ATTR_ES_PEER_PROXY
)
1806 (attr
->es_flags
& ATTR_ES_PEER_ROUTER
)
1812 attr
->mm_sync_seqnum
= 0;
1813 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1814 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1819 * Create or update EVPN route entry. This could be in the VNI route tables
1820 * or the global route table.
1822 static int update_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1823 afi_t afi
, safi_t safi
,
1824 struct bgp_dest
*dest
, struct attr
*attr
,
1825 const struct ethaddr
*mac
,
1826 const struct ipaddr
*ip
, int add
,
1827 struct bgp_path_info
**pi
, uint8_t flags
,
1828 uint32_t seq
, bool vpn_rt
, bool *old_is_sync
)
1830 struct bgp_path_info
*tmp_pi
;
1831 struct bgp_path_info
*local_pi
;
1832 struct attr
*attr_new
;
1833 struct attr local_attr
;
1834 mpls_label_t label
[BGP_MAX_LABELS
];
1835 uint32_t num_labels
= 1;
1836 int route_change
= 1;
1838 const struct prefix_evpn
*evp
;
1841 evp
= (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1842 memset(&label
, 0, sizeof(label
));
1844 /* See if this is an update of an existing route, or a new add. */
1845 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
1847 /* If route doesn't exist already, create a new one, if told to.
1848 * Otherwise act based on whether the attributes of the route have
1851 if (!local_pi
&& !add
)
1854 if (old_is_sync
&& local_pi
)
1855 *old_is_sync
= bgp_evpn_attr_is_sync(local_pi
->attr
);
1857 /* if a local path is being added with a non-zero esi look
1858 * for SYNC paths from ES peers and bubble up the sync-info
1860 update_evpn_route_entry_sync_info(bgp
, dest
, attr
, seq
, vpn_rt
, mac
);
1862 /* For non-GW MACs, update MAC mobility seq number, if needed. */
1863 if (seq
&& !CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
))
1864 add_mac_mobility_to_attr(seq
, attr
);
1869 /* Extract MAC mobility sequence number, if any. */
1870 local_attr
.mm_seqnum
=
1871 bgp_attr_mac_mobility_seqnum(&local_attr
, &sticky
);
1872 local_attr
.sticky
= sticky
;
1874 /* Add (or update) attribute to hash. */
1875 attr_new
= bgp_attr_intern(&local_attr
);
1877 /* Create new route with its attribute. */
1878 tmp_pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1879 bgp
->peer_self
, attr_new
, dest
);
1880 SET_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
);
1881 bgp_path_info_extra_get(tmp_pi
);
1883 /* The VNI goes into the 'label' field of the route */
1884 vni2label(vpn
->vni
, &label
[0]);
1886 /* Type-2 routes may carry a second VNI - the L3-VNI.
1887 * Only attach second label if we are advertising two labels for
1890 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1891 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
1894 l3vni
= bgpevpn_get_l3vni(vpn
);
1896 vni2label(l3vni
, &label
[1]);
1901 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1902 tmp_pi
->extra
->num_labels
= num_labels
;
1904 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1906 evpn_type2_path_info_set_mac(tmp_pi
, *mac
);
1908 evpn_type2_path_info_set_ip(tmp_pi
, *ip
);
1911 /* Mark route as self type-2 route */
1912 if (flags
&& CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
1913 tmp_pi
->extra
->af_flags
= BGP_EVPN_MACIP_TYPE_SVI_IP
;
1914 bgp_path_info_add(dest
, tmp_pi
);
1917 if (attrhash_cmp(tmp_pi
->attr
, attr
)
1918 && !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1922 * The attributes have changed, type-2 routes needs to
1923 * be advertised with right labels.
1925 vni2label(vpn
->vni
, &label
[0]);
1926 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1927 && CHECK_FLAG(vpn
->flags
,
1928 VNI_FLAG_USE_TWO_LABELS
)) {
1931 l3vni
= bgpevpn_get_l3vni(vpn
);
1933 vni2label(l3vni
, &label
[1]);
1937 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1938 tmp_pi
->extra
->num_labels
= num_labels
;
1940 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1942 evpn_type2_path_info_set_mac(tmp_pi
,
1945 evpn_type2_path_info_set_ip(tmp_pi
,
1949 /* The attribute has changed. */
1950 /* Add (or update) attribute to hash. */
1952 bgp_path_info_set_flag(dest
, tmp_pi
,
1953 BGP_PATH_ATTR_CHANGED
);
1955 /* Extract MAC mobility sequence number, if any. */
1956 local_attr
.mm_seqnum
= bgp_attr_mac_mobility_seqnum(
1957 &local_attr
, &sticky
);
1958 local_attr
.sticky
= sticky
;
1960 attr_new
= bgp_attr_intern(&local_attr
);
1962 /* Restore route, if needed. */
1963 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1964 bgp_path_info_restore(dest
, tmp_pi
);
1966 /* Unintern existing, set to new. */
1967 bgp_attr_unintern(&tmp_pi
->attr
);
1968 tmp_pi
->attr
= attr_new
;
1969 tmp_pi
->uptime
= monotime(NULL
);
1973 /* local MAC-IP routes in the VNI table are linked to
1974 * the destination ES
1976 if (route_change
&& vpn_rt
1977 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
))
1978 bgp_evpn_path_es_link(tmp_pi
, vpn
->vni
,
1979 bgp_evpn_attr_get_esi(tmp_pi
->attr
));
1981 /* Return back the route entry. */
1983 return route_change
;
1986 static void evpn_zebra_reinstall_best_route(struct bgp
*bgp
,
1987 struct bgpevpn
*vpn
,
1988 struct bgp_dest
*dest
)
1990 struct bgp_path_info
*tmp_ri
;
1991 struct bgp_path_info
*curr_select
= NULL
;
1993 for (tmp_ri
= bgp_dest_get_bgp_path_info(dest
); tmp_ri
;
1994 tmp_ri
= tmp_ri
->next
) {
1995 if (CHECK_FLAG(tmp_ri
->flags
, BGP_PATH_SELECTED
)) {
1996 curr_select
= tmp_ri
;
2001 if (curr_select
&& curr_select
->type
== ZEBRA_ROUTE_BGP
2002 && (curr_select
->sub_type
== BGP_ROUTE_IMPORTED
||
2003 bgp_evpn_attr_is_sync(curr_select
->attr
)))
2004 evpn_zebra_install(bgp
, vpn
,
2005 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
2010 * If the local route was not selected evict it and tell zebra to re-add
2011 * the best remote dest.
2013 * Typically a local path added by zebra is expected to be selected as
2014 * best. In which case when a remote path wins as best (later)
2015 * evpn_route_select_install itself evicts the older-local-best path.
2017 * However if bgp's add and zebra's add cross paths (race condition) it
2018 * is possible that the local path is no longer the "older" best path.
2019 * It is a path that was never designated as best and hence requires
2020 * additional handling to prevent bgp from injecting and holding on to a
2021 * non-best local path.
2023 static void evpn_cleanup_local_non_best_route(struct bgp
*bgp
,
2024 struct bgpevpn
*vpn
,
2025 struct bgp_dest
*dest
,
2026 struct bgp_path_info
*local_pi
)
2028 /* local path was not picked as the winner; kick it out */
2029 if (bgp_debug_zebra(NULL
))
2030 zlog_debug("evicting local evpn prefix %pBD as remote won",
2033 evpn_delete_old_local_route(bgp
, vpn
, dest
, local_pi
, NULL
);
2034 bgp_path_info_reap(dest
, local_pi
);
2036 /* tell zebra to re-add the best remote path */
2037 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
2040 static inline bool bgp_evpn_route_add_l3_ecomm_ok(struct bgpevpn
*vpn
,
2041 const struct prefix_evpn
*p
,
2044 return p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
2045 && (is_evpn_prefix_ipaddr_v4(p
)
2046 || (is_evpn_prefix_ipaddr_v6(p
)
2047 && !IN6_IS_ADDR_LINKLOCAL(
2048 &p
->prefix
.macip_addr
.ip
.ipaddr_v6
)))
2049 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)
2050 && bgpevpn_get_l3vni(vpn
) && bgp_evpn_es_add_l3_ecomm_ok(esi
);
2054 * Create or update EVPN route (of type based on prefix) for specified VNI
2055 * and schedule for processing.
2057 static int update_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2058 struct prefix_evpn
*p
, uint8_t flags
,
2059 uint32_t seq
, esi_t
*esi
)
2061 struct bgp_dest
*dest
;
2063 struct attr
*attr_new
;
2064 int add_l3_ecomm
= 0;
2065 struct bgp_path_info
*pi
;
2066 afi_t afi
= AFI_L2VPN
;
2067 safi_t safi
= SAFI_EVPN
;
2069 bool old_is_sync
= false;
2070 bool mac_only
= false;
2072 memset(&attr
, 0, sizeof(attr
));
2074 /* Build path-attribute for this route. */
2075 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2076 attr
.nexthop
= vpn
->originator_ip
;
2077 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2078 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2079 attr
.sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
) ? 1 : 0;
2080 attr
.default_gw
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
) ? 1 : 0;
2081 attr
.router_flag
= CHECK_FLAG(flags
,
2082 ZEBRA_MACIP_TYPE_ROUTER_FLAG
) ? 1 : 0;
2083 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
2084 attr
.es_flags
|= ATTR_ES_PROXY_ADVERT
;
2086 if (esi
&& bgp_evpn_is_esi_valid(esi
)) {
2087 memcpy(&attr
.esi
, esi
, sizeof(esi_t
));
2088 attr
.es_flags
|= ATTR_ES_IS_LOCAL
;
2091 /* PMSI is only needed for type-3 routes */
2092 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
) {
2093 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
);
2094 bgp_attr_set_pmsi_tnl_type(&attr
, PMSI_TNLTYPE_INGR_REPL
);
2097 /* router mac is only needed for type-2 routes here. */
2098 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
2099 uint8_t af_flags
= 0;
2101 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
2102 SET_FLAG(af_flags
, BGP_EVPN_MACIP_TYPE_SVI_IP
);
2104 bgp_evpn_get_rmac_nexthop(vpn
, p
, &attr
, af_flags
);
2107 if (bgp_debug_zebra(NULL
)) {
2108 char buf3
[ESI_STR_LEN
];
2111 "VRF %s vni %u type-%u route evp %pFX RMAC %pEA nexthop %pI4 esi %s",
2112 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2114 vpn
->vni
, p
->prefix
.route_type
, p
, &attr
.rmac
,
2115 &attr
.mp_nexthop_global_in
,
2116 esi_to_str(esi
, buf3
, sizeof(buf3
)));
2119 vni2label(vpn
->vni
, &(attr
.label
));
2121 /* Include L3 VNI related RTs and RMAC for type-2 routes, if they're
2122 * IPv4 or IPv6 global addresses and we're advertising L3VNI with
2125 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2126 vpn
, p
, (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2128 /* Set up extended community. */
2129 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2131 /* First, create (or fetch) route node within the VNI.
2132 * NOTE: There is no RD here.
2134 dest
= bgp_evpn_vni_node_get(vpn
, p
, NULL
);
2136 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
2137 (is_evpn_prefix_ipaddr_none(p
) == true))
2140 /* Create or update route entry. */
2141 route_change
= update_evpn_route_entry(
2142 bgp
, vpn
, afi
, safi
, dest
, &attr
,
2143 (mac_only
? NULL
: &p
->prefix
.macip_addr
.mac
), NULL
/* ip */, 1,
2144 &pi
, flags
, seq
, true /* setup_sync */, &old_is_sync
);
2146 attr_new
= pi
->attr
;
2148 /* lock ri to prevent freeing in evpn_route_select_install */
2149 bgp_path_info_lock(pi
);
2151 /* Perform route selection. Normally, the local route in the
2152 * VNI is expected to win and be the best route. However, if
2153 * there is a race condition where a host moved from local to
2154 * remote and the remote route was received in BGP just prior
2155 * to the local MACIP notification from zebra, the remote
2156 * route would win, and we should evict the defunct local route
2157 * and (re)install the remote route into zebra.
2159 evpn_route_select_install(bgp
, vpn
, dest
);
2161 * If the new local route was not selected evict it and tell zebra
2162 * to re-add the best remote dest. BGP doesn't retain non-best local
2165 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2168 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2170 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2174 /* If the local path already existed and is still the
2175 * best path we need to also check if it transitioned
2176 * from being a sync path to a non-sync path. If it
2177 * it did we need to notify zebra that the sync-path
2180 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2181 if (!new_is_sync
&& old_is_sync
)
2182 evpn_zebra_uninstall(bgp
, vpn
, p
, pi
, true);
2185 bgp_path_info_unlock(pi
);
2187 bgp_dest_unlock_node(dest
);
2189 /* If this is a new route or some attribute has changed, export the
2190 * route to the global table. The route will be advertised to peers
2191 * from there. Note that this table is a 2-level tree (RD-level +
2192 * Prefix-level) similar to L3VPN routes.
2195 struct bgp_path_info
*global_pi
;
2197 dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
2198 p
, &vpn
->prd
, NULL
);
2199 update_evpn_route_entry(
2200 bgp
, vpn
, afi
, safi
, dest
, attr_new
, NULL
/* mac */,
2201 NULL
/* ip */, 1, &global_pi
, flags
, seq
,
2202 false /* setup_sync */, NULL
/* old_is_sync */);
2204 /* Schedule for processing and unlock node. */
2205 bgp_process(bgp
, dest
, afi
, safi
);
2206 bgp_dest_unlock_node(dest
);
2209 /* Unintern temporary. */
2210 aspath_unintern(&attr
.aspath
);
2216 * Delete EVPN route entry.
2217 * The entry can be in ESI/VNI table or the global table.
2219 void delete_evpn_route_entry(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
2220 struct bgp_dest
*dest
,
2221 struct bgp_path_info
**pi
)
2223 struct bgp_path_info
*tmp_pi
;
2227 /* Now, find matching route. */
2228 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2229 tmp_pi
= tmp_pi
->next
)
2230 if (tmp_pi
->peer
== bgp
->peer_self
2231 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
2232 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2237 /* Mark route for delete. */
2239 bgp_path_info_delete(dest
, tmp_pi
);
2242 /* Delete EVPN type5 route */
2243 static int delete_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
)
2245 afi_t afi
= AFI_L2VPN
;
2246 safi_t safi
= SAFI_EVPN
;
2247 struct bgp_dest
*dest
= NULL
;
2248 struct bgp_path_info
*pi
= NULL
;
2249 struct bgp
*bgp_evpn
= NULL
; /* evpn bgp instance */
2251 bgp_evpn
= bgp_get_evpn();
2255 /* locate the global route entry for this type-5 prefix */
2256 dest
= bgp_evpn_global_node_lookup(bgp_evpn
->rib
[afi
][safi
], safi
, evp
,
2257 &bgp_vrf
->vrf_prd
, NULL
);
2261 delete_evpn_route_entry(bgp_evpn
, afi
, safi
, dest
, &pi
);
2263 bgp_process(bgp_evpn
, dest
, afi
, safi
);
2264 bgp_dest_unlock_node(dest
);
2269 * Delete EVPN route (of type based on prefix) for specified VNI and
2270 * schedule for processing.
2272 static int delete_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2273 struct prefix_evpn
*p
)
2275 struct bgp_dest
*dest
, *global_dest
;
2276 struct bgp_path_info
*pi
;
2277 afi_t afi
= AFI_L2VPN
;
2278 safi_t safi
= SAFI_EVPN
;
2280 /* First, locate the route node within the VNI. If it doesn't exist,
2282 * is nothing further to do.
2283 * NOTE: There is no RD here.
2285 dest
= bgp_evpn_vni_node_lookup(vpn
, p
, NULL
);
2289 /* Next, locate route node in the global EVPN routing table. Note that
2290 * this table is a 2-level tree (RD-level + Prefix-level) similar to
2293 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], safi
, p
,
2296 /* Delete route entry in the global EVPN table. */
2297 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
2299 /* Schedule for processing - withdraws to peers happen from
2303 bgp_process(bgp
, global_dest
, afi
, safi
);
2304 bgp_dest_unlock_node(global_dest
);
2307 /* Delete route entry in the VNI route table. This can just be removed.
2309 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2311 bgp_path_info_reap(dest
, pi
);
2312 evpn_route_select_install(bgp
, vpn
, dest
);
2314 bgp_dest_unlock_node(dest
);
2319 void bgp_evpn_update_type2_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2320 struct bgp_dest
*dest
,
2321 struct bgp_path_info
*local_pi
,
2324 afi_t afi
= AFI_L2VPN
;
2325 safi_t safi
= SAFI_EVPN
;
2326 struct bgp_path_info
*pi
;
2328 struct attr
*attr_new
;
2330 int add_l3_ecomm
= 0;
2331 struct bgp_dest
*global_dest
;
2332 struct bgp_path_info
*global_pi
;
2333 struct prefix_evpn evp
;
2335 bool old_is_sync
= false;
2337 if (CHECK_FLAG(local_pi
->flags
, BGP_PATH_REMOVED
))
2341 * VNI table MAC-IP prefixes don't have MAC so make sure it's set from
2344 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)&dest
->p
)) {
2345 /* VNI MAC -> Global */
2346 evpn_type2_prefix_global_copy(
2347 &evp
, (struct prefix_evpn
*)&dest
->p
, NULL
/* mac */,
2348 evpn_type2_path_info_get_ip(local_pi
));
2350 /* VNI IP -> Global */
2351 evpn_type2_prefix_global_copy(
2352 &evp
, (struct prefix_evpn
*)&dest
->p
,
2353 evpn_type2_path_info_get_mac(local_pi
), NULL
/* ip */);
2357 * Build attribute per local route as the MAC mobility and
2358 * some other values could differ for different routes. The
2359 * attributes will be shared in the hash table.
2361 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2362 attr
.nexthop
= vpn
->originator_ip
;
2363 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2364 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2365 attr
.sticky
= (local_pi
->attr
->sticky
) ? 1 : 0;
2366 attr
.router_flag
= (local_pi
->attr
->router_flag
) ? 1 : 0;
2367 attr
.es_flags
= local_pi
->attr
->es_flags
;
2368 if (local_pi
->attr
->default_gw
) {
2369 attr
.default_gw
= 1;
2370 if (is_evpn_prefix_ipaddr_v6(&evp
))
2371 attr
.router_flag
= 1;
2373 memcpy(&attr
.esi
, &local_pi
->attr
->esi
, sizeof(esi_t
));
2374 bgp_evpn_get_rmac_nexthop(vpn
, &evp
, &attr
, local_pi
->extra
->af_flags
);
2375 vni2label(vpn
->vni
, &(attr
.label
));
2376 /* Add L3 VNI RTs and RMAC for non IPv6 link-local if
2377 * using L3 VNI for type-2 routes also.
2379 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2381 (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2383 /* Set up extended community. */
2384 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2385 seq
= mac_mobility_seqnum(local_pi
->attr
);
2387 if (bgp_debug_zebra(NULL
)) {
2388 char buf3
[ESI_STR_LEN
];
2391 "VRF %s vni %u evp %pFX RMAC %pEA nexthop %pI4 esi %s esf 0x%x from %s",
2392 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2394 vpn
->vni
, &evp
, &attr
.rmac
, &attr
.mp_nexthop_global_in
,
2395 esi_to_str(&attr
.esi
, buf3
, sizeof(buf3
)),
2396 attr
.es_flags
, caller
);
2399 /* Update the route entry. */
2400 route_change
= update_evpn_route_entry(
2401 bgp
, vpn
, afi
, safi
, dest
, &attr
, NULL
/* mac */, NULL
/* ip */,
2402 0, &pi
, 0, seq
, true /* setup_sync */, &old_is_sync
);
2405 attr_new
= pi
->attr
;
2406 /* lock ri to prevent freeing in evpn_route_select_install */
2407 bgp_path_info_lock(pi
);
2409 /* Perform route selection. Normally, the local route in the
2410 * VNI is expected to win and be the best route. However,
2411 * under peculiar situations (e.g., tunnel (next hop) IP change
2412 * that causes best selection to be based on next hop), a
2413 * remote route could win. If the local route is the best,
2414 * ensure it is updated in the global EVPN route table and
2415 * advertised to peers; otherwise, ensure it is evicted and
2416 * (re)install the remote route into zebra.
2418 evpn_route_select_install(bgp
, vpn
, dest
);
2420 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2423 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2425 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2429 /* If the local path already existed and is still the
2430 * best path we need to also check if it transitioned
2431 * from being a sync path to a non-sync path. If it
2432 * it did we need to notify zebra that the sync-path
2435 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2436 if (!new_is_sync
&& old_is_sync
)
2437 evpn_zebra_uninstall(bgp
, vpn
, &evp
, pi
, true);
2443 bgp_path_info_unlock(pi
);
2446 /* Update route in global routing table. */
2447 global_dest
= bgp_evpn_global_node_get(
2448 bgp
->rib
[afi
][safi
], afi
, safi
, &evp
, &vpn
->prd
, NULL
);
2449 assert(global_dest
);
2450 update_evpn_route_entry(
2451 bgp
, vpn
, afi
, safi
, global_dest
, attr_new
,
2452 NULL
/* mac */, NULL
/* ip */, 0, &global_pi
, 0,
2453 mac_mobility_seqnum(attr_new
), false /* setup_sync */,
2454 NULL
/* old_is_sync */);
2456 /* Schedule for processing and unlock node. */
2457 bgp_process(bgp
, global_dest
, afi
, safi
);
2458 bgp_dest_unlock_node(global_dest
);
2461 /* Unintern temporary. */
2462 aspath_unintern(&attr
.aspath
);
2465 static void update_type2_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2466 struct bgp_dest
*dest
)
2468 struct bgp_path_info
*tmp_pi
;
2470 const struct prefix_evpn
*evp
=
2471 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2473 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2476 /* Identify local route. */
2477 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2478 tmp_pi
= tmp_pi
->next
) {
2479 if (tmp_pi
->peer
== bgp
->peer_self
&&
2480 tmp_pi
->type
== ZEBRA_ROUTE_BGP
&&
2481 tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2488 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, tmp_pi
, __func__
);
2492 * Update all type-2 (MACIP) local routes for this VNI - these should also
2493 * be scheduled for advertise to peers.
2495 static void update_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2497 struct bgp_dest
*dest
;
2499 /* Walk this VNI's route MAC & IP table and update local type-2
2500 * routes. For any routes updated, update corresponding entry in the
2503 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2504 dest
= bgp_route_next(dest
))
2505 update_type2_route(bgp
, vpn
, dest
);
2507 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2508 dest
= bgp_route_next(dest
))
2509 update_type2_route(bgp
, vpn
, dest
);
2513 * Delete all type-2 (MACIP) local routes for this VNI - only from the
2514 * global routing table. These are also scheduled for withdraw from peers.
2516 static void delete_global_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2520 struct bgp_dest
*rddest
, *dest
;
2521 struct bgp_table
*table
;
2522 struct bgp_path_info
*pi
;
2527 rddest
= bgp_node_lookup(bgp
->rib
[afi
][safi
],
2528 (struct prefix
*)&vpn
->prd
);
2530 table
= bgp_dest_get_bgp_table_info(rddest
);
2531 for (dest
= bgp_table_top(table
); dest
;
2532 dest
= bgp_route_next(dest
)) {
2533 const struct prefix_evpn
*evp
=
2534 (const struct prefix_evpn
*)bgp_dest_get_prefix(
2537 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2540 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2542 bgp_process(bgp
, dest
, afi
, safi
);
2545 /* Unlock RD node. */
2546 bgp_dest_unlock_node(rddest
);
2550 static void delete_vni_type2_route(struct bgp
*bgp
, struct bgp_dest
*dest
)
2552 struct bgp_path_info
*pi
;
2553 afi_t afi
= AFI_L2VPN
;
2554 safi_t safi
= SAFI_EVPN
;
2556 const struct prefix_evpn
*evp
=
2557 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2559 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2562 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2564 /* Route entry in local table gets deleted immediately. */
2566 bgp_path_info_reap(dest
, pi
);
2569 static void delete_vni_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2571 struct bgp_dest
*dest
;
2573 /* Next, walk this VNI's MAC & IP route table and delete local type-2
2576 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2577 dest
= bgp_route_next(dest
))
2578 delete_vni_type2_route(bgp
, dest
);
2580 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2581 dest
= bgp_route_next(dest
))
2582 delete_vni_type2_route(bgp
, dest
);
2586 * Delete all type-2 (MACIP) local routes for this VNI - from the global
2587 * table as well as the per-VNI route table.
2589 static void delete_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2591 /* First, walk the global route table for this VNI's type-2 local
2593 * EVPN routes are a 2-level table, first get the RD table.
2595 delete_global_type2_routes(bgp
, vpn
);
2596 delete_vni_type2_routes(bgp
, vpn
);
2600 * Delete all routes in the per-VNI route table.
2602 static void delete_all_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2604 struct bgp_dest
*dest
;
2605 struct bgp_path_info
*pi
, *nextpi
;
2607 /* Walk this VNI's MAC & IP route table and delete all routes. */
2608 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2609 dest
= bgp_route_next(dest
)) {
2610 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2611 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2612 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
2613 bgp_path_info_delete(dest
, pi
);
2614 bgp_path_info_reap(dest
, pi
);
2618 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2619 dest
= bgp_route_next(dest
)) {
2620 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2621 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2622 bgp_path_info_delete(dest
, pi
);
2623 bgp_path_info_reap(dest
, pi
);
2628 /* BUM traffic flood mode per-l2-vni */
2629 static int bgp_evpn_vni_flood_mode_get(struct bgp
*bgp
,
2630 struct bgpevpn
*vpn
)
2632 /* if flooding has been globally disabled per-vni mode is
2635 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
2636 return VXLAN_FLOOD_DISABLED
;
2638 /* if mcast group ip has been specified we use a PIM-SM MDT */
2639 if (vpn
->mcast_grp
.s_addr
!= INADDR_ANY
)
2640 return VXLAN_FLOOD_PIM_SM
;
2642 /* default is ingress replication */
2643 return VXLAN_FLOOD_HEAD_END_REPL
;
2647 * Update (and advertise) local routes for a VNI. Invoked upon the VNI
2648 * export RT getting modified or change to tunnel IP. Note that these
2649 * situations need the route in the per-VNI table as well as the global
2650 * table to be updated (as attributes change).
2652 int update_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2655 struct prefix_evpn p
;
2657 update_type1_routes_for_evi(bgp
, vpn
);
2659 /* Update and advertise the type-3 route (only one) followed by the
2660 * locally learnt type-2 routes (MACIP) - for this VNI.
2662 * RT-3 only if doing head-end replication
2664 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
2665 == VXLAN_FLOOD_HEAD_END_REPL
) {
2666 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2667 ret
= update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
);
2672 update_all_type2_routes(bgp
, vpn
);
2677 * Delete (and withdraw) local routes for specified VNI from the global
2678 * table and per-VNI table. After this, remove all other routes from
2679 * the per-VNI table. Invoked upon the VNI being deleted or EVPN
2680 * (advertise-all-vni) being disabled.
2682 static int delete_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2685 struct prefix_evpn p
;
2687 /* Delete and withdraw locally learnt type-2 routes (MACIP)
2688 * followed by type-3 routes (only one) - for this VNI.
2690 delete_all_type2_routes(bgp
, vpn
);
2692 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2693 ret
= delete_evpn_route(bgp
, vpn
, &p
);
2697 /* Delete all routes from the per-VNI table. */
2698 delete_all_vni_routes(bgp
, vpn
);
2703 * There is a flood mcast IP address change. Update the mcast-grp and
2704 * remove the type-3 route if any. A new type-3 route will be generated
2705 * post tunnel_ip update if the new flood mode is head-end-replication.
2707 static int bgp_evpn_mcast_grp_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2708 struct in_addr mcast_grp
)
2710 struct prefix_evpn p
;
2712 vpn
->mcast_grp
= mcast_grp
;
2714 if (is_vni_live(vpn
)) {
2715 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2716 delete_evpn_route(bgp
, vpn
, &p
);
2723 * There is a tunnel endpoint IP address change for this VNI, delete
2724 * prior type-3 route (if needed) and update.
2725 * Note: Route re-advertisement happens elsewhere after other processing
2728 static void handle_tunnel_ip_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2729 struct in_addr originator_ip
)
2731 struct prefix_evpn p
;
2733 if (IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
))
2736 /* If VNI is not live, we only need to update the originator ip */
2737 if (!is_vni_live(vpn
)) {
2738 vpn
->originator_ip
= originator_ip
;
2742 /* Update the tunnel-ip hash */
2743 bgp_tip_del(bgp
, &vpn
->originator_ip
);
2744 if (bgp_tip_add(bgp
, &originator_ip
))
2745 /* The originator_ip was not already present in the
2746 * bgp martian next-hop table as a tunnel-ip, so we
2747 * need to go back and filter routes matching the new
2750 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
2752 /* Need to withdraw type-3 route as the originator IP is part
2755 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2756 delete_evpn_route(bgp
, vpn
, &p
);
2758 /* Update the tunnel IP and re-advertise all routes for this VNI. */
2759 vpn
->originator_ip
= originator_ip
;
2763 static struct bgp_path_info
*
2764 bgp_create_evpn_bgp_path_info(struct bgp_path_info
*parent_pi
,
2765 struct bgp_dest
*dest
, struct attr
*attr
)
2767 struct attr
*attr_new
;
2768 struct bgp_path_info
*pi
;
2770 /* Add (or update) attribute to hash. */
2771 attr_new
= bgp_attr_intern(attr
);
2773 /* Create new route with its attribute. */
2774 pi
= info_make(parent_pi
->type
, BGP_ROUTE_IMPORTED
, 0, parent_pi
->peer
,
2776 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
2777 bgp_path_info_extra_get(pi
);
2778 pi
->extra
->parent
= bgp_path_info_lock(parent_pi
);
2779 bgp_dest_lock_node((struct bgp_dest
*)parent_pi
->net
);
2780 if (parent_pi
->extra
) {
2781 memcpy(&pi
->extra
->label
, &parent_pi
->extra
->label
,
2782 sizeof(pi
->extra
->label
));
2783 pi
->extra
->num_labels
= parent_pi
->extra
->num_labels
;
2784 pi
->extra
->igpmetric
= parent_pi
->extra
->igpmetric
;
2787 bgp_path_info_add(dest
, pi
);
2793 * Install route entry into the VRF routing table and invoke route selection.
2795 static int install_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
2796 const struct prefix_evpn
*evp
,
2797 struct bgp_path_info
*parent_pi
)
2799 struct bgp_dest
*dest
;
2800 struct bgp_path_info
*pi
;
2802 struct attr
*attr_new
;
2805 struct prefix
*pp
= &p
;
2808 bool new_pi
= false;
2809 bool use_l3nhg
= false;
2810 bool is_l3nhg_active
= false;
2811 char buf1
[INET6_ADDRSTRLEN
];
2813 memset(pp
, 0, sizeof(struct prefix
));
2814 ip_prefix_from_evpn_prefix(evp
, pp
);
2816 if (bgp_debug_zebra(NULL
))
2818 "vrf %s: import evpn prefix %pFX parent %p flags 0x%x",
2819 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
2822 /* Create (or fetch) route within the VRF. */
2823 /* NOTE: There is no RD here. */
2824 if (is_evpn_prefix_ipaddr_v4(evp
)) {
2826 safi
= SAFI_UNICAST
;
2827 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2828 } else if (is_evpn_prefix_ipaddr_v6(evp
)) {
2830 safi
= SAFI_UNICAST
;
2831 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2835 /* EVPN routes currently only support a IPv4 next hop which corresponds
2836 * to the remote VTEP. When importing into a VRF, if it is IPv6 host
2837 * or prefix route, we have to convert the next hop to an IPv4-mapped
2838 * address for the rest of the code to flow through. In the case of IPv4,
2839 * make sure to set the flag for next hop attribute.
2841 attr
= *parent_pi
->attr
;
2842 if (attr
.evpn_overlay
.type
!= OVERLAY_INDEX_GATEWAY_IP
) {
2844 evpn_convert_nexthop_to_ipv6(&attr
);
2846 attr
.nexthop
= attr
.mp_nexthop_global_in
;
2847 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2852 * If gateway IP overlay index is specified in the NLRI of
2853 * EVPN RT-5, this gateway IP should be used as the nexthop
2854 * for the prefix in the VRF
2856 if (bgp_debug_zebra(NULL
)) {
2858 "Install gateway IP %s as nexthop for prefix %pFX in vrf %s",
2859 inet_ntop(pp
->family
, &attr
.evpn_overlay
.gw_ip
,
2860 buf1
, sizeof(buf1
)), pp
,
2861 vrf_id_to_name(bgp_vrf
->vrf_id
));
2864 if (afi
== AFI_IP6
) {
2865 memcpy(&attr
.mp_nexthop_global
,
2866 &attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
2867 sizeof(struct in6_addr
));
2868 attr
.mp_nexthop_len
= IPV6_MAX_BYTELEN
;
2870 attr
.nexthop
= attr
.evpn_overlay
.gw_ip
.ipaddr_v4
;
2871 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2875 bgp_evpn_es_vrf_use_nhg(bgp_vrf
, &parent_pi
->attr
->esi
, &use_l3nhg
,
2876 &is_l3nhg_active
, NULL
);
2878 attr
.es_flags
|= ATTR_ES_L3_NHG_USE
;
2879 if (is_l3nhg_active
)
2880 attr
.es_flags
|= ATTR_ES_L3_NHG_ACTIVE
;
2882 /* Check if route entry is already present. */
2883 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2885 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
2889 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
, &attr
);
2892 if (attrhash_cmp(pi
->attr
, &attr
)
2893 && !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2894 bgp_dest_unlock_node(dest
);
2897 /* The attribute has changed. */
2898 /* Add (or update) attribute to hash. */
2899 attr_new
= bgp_attr_intern(&attr
);
2901 /* Restore route, if needed. */
2902 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
2903 bgp_path_info_restore(dest
, pi
);
2905 /* Mark if nexthop has changed. */
2907 && !IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
2909 && !IPV6_ADDR_SAME(&pi
->attr
->mp_nexthop_global
,
2910 &attr_new
->mp_nexthop_global
)))
2911 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
2913 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
2914 /* Unintern existing, set to new. */
2915 bgp_attr_unintern(&pi
->attr
);
2916 pi
->attr
= attr_new
;
2917 pi
->uptime
= monotime(NULL
);
2920 /* Gateway IP nexthop should be resolved */
2921 if (attr
.evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
2922 if (bgp_find_or_add_nexthop(bgp_vrf
, bgp_vrf
, afi
, safi
, pi
,
2924 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_VALID
);
2926 if (BGP_DEBUG(nht
, NHT
)) {
2927 inet_ntop(pp
->family
,
2928 &attr
.evpn_overlay
.gw_ip
,
2929 buf1
, sizeof(buf1
));
2930 zlog_debug("%s: gateway IP NH unresolved",
2933 bgp_path_info_unset_flag(dest
, pi
, BGP_PATH_VALID
);
2937 /* as it is an importation, change nexthop */
2938 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ANNC_NH_SELF
);
2941 /* Link path to evpn nexthop */
2942 bgp_evpn_path_nh_add(bgp_vrf
, pi
);
2944 bgp_aggregate_increment(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
2947 /* Perform route selection and update zebra, if required. */
2948 bgp_process(bgp_vrf
, dest
, afi
, safi
);
2950 /* Process for route leaking. */
2951 vpn_leak_from_vrf_update(bgp_get_default(), bgp_vrf
, pi
);
2953 bgp_dest_unlock_node(dest
);
2955 if (bgp_debug_zebra(NULL
))
2956 zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)",
2957 new_pi
? "new" : "update", dest
,
2958 bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
2965 * Common handling for vni route tables install/selection.
2967 static int install_evpn_route_entry_in_vni_common(
2968 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
2969 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
2971 struct bgp_path_info
*pi
;
2972 struct bgp_path_info
*local_pi
;
2973 struct attr
*attr_new
;
2975 bool old_local_es
= false;
2978 /* Check if route entry is already present. */
2979 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2981 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
2985 /* Create an info */
2986 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
,
2989 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
2990 if (is_evpn_type2_dest_ipaddr_none(dest
))
2991 evpn_type2_path_info_set_ip(
2992 pi
, p
->prefix
.macip_addr
.ip
);
2994 evpn_type2_path_info_set_mac(
2995 pi
, p
->prefix
.macip_addr
.mac
);
2998 new_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3000 /* Return early if attributes haven't changed
3001 * and dest isn't flagged for removal.
3002 * dest will be unlocked by either
3003 * install_evpn_route_entry_in_vni_mac() or
3004 * install_evpn_route_entry_in_vni_ip()
3006 if (attrhash_cmp(pi
->attr
, parent_pi
->attr
) &&
3007 !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3009 /* The attribute has changed. */
3010 /* Add (or update) attribute to hash. */
3011 attr_new
= bgp_attr_intern(parent_pi
->attr
);
3013 /* Restore route, if needed. */
3014 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3015 bgp_path_info_restore(dest
, pi
);
3017 /* Mark if nexthop has changed. */
3018 if (!IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
3019 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
3021 old_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3022 new_local_es
= bgp_evpn_attr_is_local_es(attr_new
);
3023 /* If ESI is different or if its type has changed we
3024 * need to reinstall the path in zebra
3026 if ((old_local_es
!= new_local_es
)
3027 || memcmp(&pi
->attr
->esi
, &attr_new
->esi
,
3028 sizeof(attr_new
->esi
))) {
3030 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
3031 zlog_debug("VNI %d path %pFX chg to %s es",
3032 vpn
->vni
, &pi
->net
->p
,
3033 new_local_es
? "local"
3035 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
3038 /* Unintern existing, set to new. */
3039 bgp_attr_unintern(&pi
->attr
);
3040 pi
->attr
= attr_new
;
3041 pi
->uptime
= monotime(NULL
);
3044 /* Add this route to remote IP hashtable */
3045 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
3047 /* Perform route selection and update zebra, if required. */
3048 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3050 /* if the best path is a local path with a non-zero ES
3051 * sync info against the local path may need to be updated
3052 * when a remote path is added/updated (including changes
3053 * from sync-path to remote-path)
3055 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3056 if (local_pi
&& (old_local_es
|| new_local_es
))
3057 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3064 * Common handling for vni route tables uninstall/selection.
3066 static int uninstall_evpn_route_entry_in_vni_common(
3067 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
3068 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
3070 struct bgp_path_info
*pi
;
3071 struct bgp_path_info
*local_pi
;
3074 /* Find matching route entry. */
3075 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3077 (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3083 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
3085 /* Mark entry for deletion */
3086 bgp_path_info_delete(dest
, pi
);
3088 /* Perform route selection and update zebra, if required. */
3089 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3091 /* if the best path is a local path with a non-zero ES
3092 * sync info against the local path may need to be updated
3093 * when a remote path is deleted
3095 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3096 if (local_pi
&& bgp_evpn_attr_is_local_es(local_pi
->attr
))
3097 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3104 * Install route entry into VNI IP table and invoke route selection.
3106 static int install_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3107 struct bgpevpn
*vpn
,
3108 const struct prefix_evpn
*p
,
3109 struct bgp_path_info
*parent_pi
)
3112 struct bgp_dest
*dest
;
3114 /* Ignore MAC Only Type-2 */
3115 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3116 (is_evpn_prefix_ipaddr_none(p
) == true))
3119 /* Create (or fetch) route within the VNI IP table. */
3120 dest
= bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
3122 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3125 bgp_dest_unlock_node(dest
);
3131 * Install route entry into VNI MAC table and invoke route selection.
3133 static int install_evpn_route_entry_in_vni_mac(struct bgp
*bgp
,
3134 struct bgpevpn
*vpn
,
3135 const struct prefix_evpn
*p
,
3136 struct bgp_path_info
*parent_pi
)
3139 struct bgp_dest
*dest
;
3141 /* Only type-2 routes go into this table */
3142 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3145 /* Create (or fetch) route within the VNI MAC table. */
3146 dest
= bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
3148 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3151 bgp_dest_unlock_node(dest
);
3157 * Uninstall route entry from VNI IP table and invoke route selection.
3159 static int uninstall_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3160 struct bgpevpn
*vpn
,
3161 const struct prefix_evpn
*p
,
3162 struct bgp_path_info
*parent_pi
)
3165 struct bgp_dest
*dest
;
3167 /* Ignore MAC Only Type-2 */
3168 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3169 (is_evpn_prefix_ipaddr_none(p
) == true))
3172 /* Locate route within the VNI IP table. */
3173 dest
= bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
3177 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3180 bgp_dest_unlock_node(dest
);
3186 * Uninstall route entry from VNI IP table and invoke route selection.
3189 uninstall_evpn_route_entry_in_vni_mac(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3190 const struct prefix_evpn
*p
,
3191 struct bgp_path_info
*parent_pi
)
3194 struct bgp_dest
*dest
;
3196 /* Only type-2 routes go into this table */
3197 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3200 /* Locate route within the VNI MAC table. */
3201 dest
= bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
, parent_pi
);
3205 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3208 bgp_dest_unlock_node(dest
);
3213 * Uninstall route entry from the VRF routing table and send message
3214 * to zebra, if appropriate.
3216 static int uninstall_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
3217 const struct prefix_evpn
*evp
,
3218 struct bgp_path_info
*parent_pi
)
3220 struct bgp_dest
*dest
;
3221 struct bgp_path_info
*pi
;
3224 struct prefix
*pp
= &p
;
3228 memset(pp
, 0, sizeof(struct prefix
));
3229 ip_prefix_from_evpn_prefix(evp
, pp
);
3231 if (bgp_debug_zebra(NULL
))
3233 "vrf %s: unimport evpn prefix %pFX parent %p flags 0x%x",
3234 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
3237 /* Locate route within the VRF. */
3238 /* NOTE: There is no RD here. */
3239 if (is_evpn_prefix_ipaddr_v4(evp
)) {
3241 safi
= SAFI_UNICAST
;
3242 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3245 safi
= SAFI_UNICAST
;
3246 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3252 /* Find matching route entry. */
3253 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3255 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3259 bgp_dest_unlock_node(dest
);
3263 if (bgp_debug_zebra(NULL
))
3264 zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)",
3265 dest
, bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
3268 /* Process for route leaking. */
3269 vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf
, pi
);
3271 bgp_aggregate_decrement(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
3274 /* Mark entry for deletion */
3275 bgp_path_info_delete(dest
, pi
);
3277 /* Unlink path to evpn nexthop */
3278 bgp_evpn_path_nh_del(bgp_vrf
, pi
);
3280 /* Perform route selection and update zebra, if required. */
3281 bgp_process(bgp_vrf
, dest
, afi
, safi
);
3283 /* Unlock route node. */
3284 bgp_dest_unlock_node(dest
);
3290 * Install route entry into the VNI routing tables.
3292 static int install_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3293 const struct prefix_evpn
*p
,
3294 struct bgp_path_info
*parent_pi
)
3298 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3300 "%s (%u): Installing EVPN %pFX route in VNI %u IP/MAC table",
3301 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3303 ret
= install_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3308 "%s (%u): Failed to install EVPN %pFX route in VNI %u MAC table",
3309 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3314 ret
= install_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3319 "%s (%u): Failed to install EVPN %pFX route in VNI %u IP table",
3320 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3329 * Uninstall route entry from the VNI routing tables.
3331 static int uninstall_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3332 const struct prefix_evpn
*p
,
3333 struct bgp_path_info
*parent_pi
)
3337 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3339 "%s (%u): Uninstalling EVPN %pFX route from VNI %u IP/MAC table",
3340 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3342 ret
= uninstall_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3347 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u IP table",
3348 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3353 ret
= uninstall_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3358 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u MAC table",
3359 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3368 * Given a route entry and a VRF, see if this route entry should be
3369 * imported into the VRF i.e., RTs match.
3371 static int is_route_matching_for_vrf(struct bgp
*bgp_vrf
,
3372 struct bgp_path_info
*pi
)
3374 struct attr
*attr
= pi
->attr
;
3375 struct ecommunity
*ecom
;
3379 /* Route should have valid RT to be even considered. */
3380 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3383 ecom
= bgp_attr_get_ecommunity(attr
);
3384 if (!ecom
|| !ecom
->size
)
3387 /* For each extended community RT, see if it matches this VNI. If any RT
3388 * matches, we're done.
3390 for (i
= 0; i
< ecom
->size
; i
++) {
3392 uint8_t type
, sub_type
;
3393 struct ecommunity_val
*eval
;
3394 struct ecommunity_val eval_tmp
;
3395 struct vrf_irt_node
*irt
;
3397 /* Only deal with RTs */
3398 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3399 eval
= (struct ecommunity_val
*)(ecom
->val
3400 + (i
* ecom
->unit_size
));
3403 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3406 /* See if this RT matches specified VNIs import RTs */
3407 irt
= lookup_vrf_import_rt(eval
);
3409 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3412 /* Also check for non-exact match. In this, we mask out the AS
3414 * only check on the local-admin sub-field. This is to
3416 * VNI as the RT for EBGP peering too.
3419 if (type
== ECOMMUNITY_ENCODE_AS
3420 || type
== ECOMMUNITY_ENCODE_AS4
3421 || type
== ECOMMUNITY_ENCODE_IP
) {
3422 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3423 mask_ecom_global_admin(&eval_tmp
, eval
);
3424 irt
= lookup_vrf_import_rt(&eval_tmp
);
3427 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3435 * Given a route entry and a VNI, see if this route entry should be
3436 * imported into the VNI i.e., RTs match.
3438 static int is_route_matching_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3439 struct bgp_path_info
*pi
)
3441 struct attr
*attr
= pi
->attr
;
3442 struct ecommunity
*ecom
;
3446 /* Route should have valid RT to be even considered. */
3447 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3450 ecom
= bgp_attr_get_ecommunity(attr
);
3451 if (!ecom
|| !ecom
->size
)
3454 /* For each extended community RT, see if it matches this VNI. If any RT
3455 * matches, we're done.
3457 for (i
= 0; i
< ecom
->size
; i
++) {
3459 uint8_t type
, sub_type
;
3460 struct ecommunity_val
*eval
;
3461 struct ecommunity_val eval_tmp
;
3462 struct irt_node
*irt
;
3464 /* Only deal with RTs */
3465 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3466 eval
= (struct ecommunity_val
*)(ecom
->val
3467 + (i
* ecom
->unit_size
));
3470 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3473 /* See if this RT matches specified VNIs import RTs */
3474 irt
= lookup_import_rt(bgp
, eval
);
3476 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3479 /* Also check for non-exact match. In this, we mask out the AS
3481 * only check on the local-admin sub-field. This is to
3483 * VNI as the RT for EBGP peering too.
3486 if (type
== ECOMMUNITY_ENCODE_AS
3487 || type
== ECOMMUNITY_ENCODE_AS4
3488 || type
== ECOMMUNITY_ENCODE_IP
) {
3489 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3490 mask_ecom_global_admin(&eval_tmp
, eval
);
3491 irt
= lookup_import_rt(bgp
, &eval_tmp
);
3494 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3501 /* This API will scan evpn routes for checking attribute's rmac
3502 * macthes with bgp instance router mac. It avoid installing
3503 * route into bgp vrf table and remote rmac in bridge table.
3505 static int bgp_evpn_route_rmac_self_check(struct bgp
*bgp_vrf
,
3506 const struct prefix_evpn
*evp
,
3507 struct bgp_path_info
*pi
)
3509 /* evpn route could have learnt prior to L3vni has come up,
3510 * perform rmac check before installing route and
3511 * remote router mac.
3512 * The route will be removed from global bgp table once
3513 * SVI comes up with MAC and stored in hash, triggers
3514 * bgp_mac_rescan_all_evpn_tables.
3516 if (memcmp(&bgp_vrf
->rmac
, &pi
->attr
->rmac
, ETH_ALEN
) == 0) {
3517 if (bgp_debug_update(pi
->peer
, NULL
, NULL
, 1)) {
3518 char attr_str
[BUFSIZ
] = {0};
3520 bgp_dump_attr(pi
->attr
, attr_str
, sizeof(attr_str
));
3523 "%s: bgp %u prefix %pFX with attr %s - DENIED due to self mac",
3524 __func__
, bgp_vrf
->vrf_id
, evp
, attr_str
);
3533 /* don't import hosts that are locally attached */
3535 bgp_evpn_skip_vrf_import_of_local_es(struct bgp
*bgp_vrf
,
3536 const struct prefix_evpn
*evp
,
3537 struct bgp_path_info
*pi
, int install
)
3541 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
3542 esi
= bgp_evpn_attr_get_esi(pi
->attr
);
3544 /* Don't import routes that point to a local destination */
3545 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
3546 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
3547 char esi_buf
[ESI_STR_LEN
];
3550 "vrf %s of evpn prefix %pFX skipped, local es %s",
3551 install
? "import" : "unimport", evp
,
3552 esi_to_str(esi
, esi_buf
,
3562 * Install or uninstall a mac-ip route in the provided vrf if
3563 * there is a rt match
3565 int bgp_evpn_route_entry_install_if_vrf_match(struct bgp
*bgp_vrf
,
3566 struct bgp_path_info
*pi
,
3570 const struct prefix_evpn
*evp
=
3571 (const struct prefix_evpn
*)bgp_dest_get_prefix(pi
->net
);
3573 /* Consider "valid" remote routes applicable for
3576 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3577 && pi
->type
== ZEBRA_ROUTE_BGP
3578 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3581 if (is_route_matching_for_vrf(bgp_vrf
, pi
)) {
3582 if (bgp_evpn_route_rmac_self_check(bgp_vrf
, evp
, pi
))
3585 /* don't import hosts that are locally attached */
3586 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3587 bgp_vrf
, evp
, pi
, install
))
3591 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3593 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3597 flog_err(EC_BGP_EVPN_FAIL
,
3598 "Failed to %s EVPN %pFX route in VRF %s",
3599 install
? "install" : "uninstall", evp
,
3600 vrf_id_to_name(bgp_vrf
->vrf_id
));
3607 * Install or uninstall mac-ip routes are appropriate for this
3610 static int install_uninstall_routes_for_vrf(struct bgp
*bgp_vrf
, int install
)
3614 struct bgp_dest
*rd_dest
, *dest
;
3615 struct bgp_table
*table
;
3616 struct bgp_path_info
*pi
;
3618 struct bgp
*bgp_evpn
= NULL
;
3622 bgp_evpn
= bgp_get_evpn();
3626 /* Walk entire global routing table and evaluate routes which could be
3627 * imported into this VRF. Note that we need to loop through all global
3628 * routes to determine which route matches the import rt on vrf
3630 for (rd_dest
= bgp_table_top(bgp_evpn
->rib
[afi
][safi
]); rd_dest
;
3631 rd_dest
= bgp_route_next(rd_dest
)) {
3632 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3636 for (dest
= bgp_table_top(table
); dest
;
3637 dest
= bgp_route_next(dest
)) {
3638 const struct prefix_evpn
*evp
=
3639 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3642 /* if not mac-ip route skip this route */
3643 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3644 || evp
->prefix
.route_type
3645 == BGP_EVPN_IP_PREFIX_ROUTE
))
3648 /* if not a mac+ip route skip this route */
3649 if (!(is_evpn_prefix_ipaddr_v4(evp
)
3650 || is_evpn_prefix_ipaddr_v6(evp
)))
3653 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3655 ret
= bgp_evpn_route_entry_install_if_vrf_match(
3656 bgp_vrf
, pi
, install
);
3667 * Install or uninstall routes of specified type that are appropriate for this
3670 static int install_uninstall_routes_for_vni(struct bgp
*bgp
,
3671 struct bgpevpn
*vpn
,
3672 bgp_evpn_route_type rtype
,
3677 struct bgp_dest
*rd_dest
, *dest
;
3678 struct bgp_table
*table
;
3679 struct bgp_path_info
*pi
;
3685 /* Walk entire global routing table and evaluate routes which could be
3686 * imported into this VPN. Note that we cannot just look at the routes
3688 * the VNI's RD - remote routes applicable for this VNI could have any
3691 /* EVPN routes are a 2-level table. */
3692 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
3693 rd_dest
= bgp_route_next(rd_dest
)) {
3694 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3698 for (dest
= bgp_table_top(table
); dest
;
3699 dest
= bgp_route_next(dest
)) {
3700 const struct prefix_evpn
*evp
=
3701 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3704 if (evp
->prefix
.route_type
!= rtype
)
3707 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3709 /* Consider "valid" remote routes applicable for
3711 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3712 && pi
->type
== ZEBRA_ROUTE_BGP
3713 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3716 if (is_route_matching_for_vni(bgp
, vpn
, pi
)) {
3718 ret
= install_evpn_route_entry(
3721 ret
= uninstall_evpn_route_entry(
3727 "%u: Failed to %s EVPN %s route in VNI %u",
3731 rtype
== BGP_EVPN_MAC_IP_ROUTE
3736 bgp_dest_unlock_node(rd_dest
);
3737 bgp_dest_unlock_node(dest
);
3748 /* Install any existing remote routes applicable for this VRF into VRF RIB. This
3749 * is invoked upon l3vni-add or l3vni import rt change
3751 static int install_routes_for_vrf(struct bgp
*bgp_vrf
)
3753 install_uninstall_routes_for_vrf(bgp_vrf
, 1);
3758 * Install any existing remote routes applicable for this VNI into its
3759 * routing table. This is invoked when a VNI becomes "live" or its Import
3762 static int install_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3766 /* Install type-3 routes followed by type-2 routes - the ones applicable
3769 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3774 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3779 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3783 /* uninstall routes from l3vni vrf. */
3784 static int uninstall_routes_for_vrf(struct bgp
*bgp_vrf
)
3786 install_uninstall_routes_for_vrf(bgp_vrf
, 0);
3791 * Uninstall any existing remote routes for this VNI. One scenario in which
3792 * this is invoked is upon an import RT change.
3794 static int uninstall_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3798 /* Uninstall type-2 routes followed by type-3 routes - the ones
3802 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3807 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3813 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3818 * Install or uninstall route in matching VRFs (list).
3820 static int install_uninstall_route_in_vrfs(struct bgp
*bgp_def
, afi_t afi
,
3821 safi_t safi
, struct prefix_evpn
*evp
,
3822 struct bgp_path_info
*pi
,
3823 struct list
*vrfs
, int install
)
3825 struct bgp
*bgp_vrf
;
3826 struct listnode
*node
, *nnode
;
3828 /* Only type-2/type-5 routes go into a VRF */
3829 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3830 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3833 /* if it is type-2 route and not a mac+ip route skip this route */
3834 if ((evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3835 && !(is_evpn_prefix_ipaddr_v4(evp
)
3836 || is_evpn_prefix_ipaddr_v6(evp
)))
3839 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, bgp_vrf
)) {
3842 /* don't import hosts that are locally attached */
3843 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3844 bgp_vrf
, evp
, pi
, install
))
3848 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3850 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3854 flog_err(EC_BGP_EVPN_FAIL
,
3855 "%u: Failed to %s prefix %pFX in VRF %s",
3857 install
? "install" : "uninstall", evp
,
3858 vrf_id_to_name(bgp_vrf
->vrf_id
));
3867 * Install or uninstall route in matching VNIs (list).
3869 static int install_uninstall_route_in_vnis(struct bgp
*bgp
, afi_t afi
,
3870 safi_t safi
, struct prefix_evpn
*evp
,
3871 struct bgp_path_info
*pi
,
3872 struct list
*vnis
, int install
)
3874 struct bgpevpn
*vpn
;
3875 struct listnode
*node
, *nnode
;
3877 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, vpn
)) {
3880 if (!is_vni_live(vpn
))
3884 ret
= install_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3886 ret
= uninstall_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3889 flog_err(EC_BGP_EVPN_FAIL
,
3890 "%u: Failed to %s EVPN %s route in VNI %u",
3891 bgp
->vrf_id
, install
? "install" : "uninstall",
3892 evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3904 * Install or uninstall route for appropriate VNIs/ESIs.
3906 static int bgp_evpn_install_uninstall_table(struct bgp
*bgp
, afi_t afi
,
3907 safi_t safi
, const struct prefix
*p
,
3908 struct bgp_path_info
*pi
,
3909 int import
, bool in_vni_rt
,
3912 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
3913 struct attr
*attr
= pi
->attr
;
3914 struct ecommunity
*ecom
;
3916 struct prefix_evpn ad_evp
;
3920 /* Only type-1, type-2, type-3, type-4 and type-5
3921 * are supported currently
3923 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3924 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
3925 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
3926 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
3927 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3930 /* If we don't have Route Target, nothing much to do. */
3931 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3934 /* EAD prefix in the global table doesn't include the VTEP-IP so
3935 * we need to create a different copy for the VNI
3937 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
3938 evp
= evpn_type1_prefix_vni_ip_copy(&ad_evp
, evp
,
3941 ecom
= bgp_attr_get_ecommunity(attr
);
3942 if (!ecom
|| !ecom
->size
)
3945 /* An EVPN route belongs to a VNI or a VRF or an ESI based on the RTs
3946 * attached to the route */
3947 for (i
= 0; i
< ecom
->size
; i
++) {
3949 uint8_t type
, sub_type
;
3950 struct ecommunity_val
*eval
;
3951 struct ecommunity_val eval_tmp
;
3952 struct irt_node
*irt
; /* import rt for l2vni */
3953 struct vrf_irt_node
*vrf_irt
; /* import rt for l3vni */
3954 struct bgp_evpn_es
*es
;
3956 /* Only deal with RTs */
3957 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3958 eval
= (struct ecommunity_val
*)(ecom
->val
3959 + (i
* ecom
->unit_size
));
3962 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3965 /* non-local MAC-IP routes in the global route table are linked
3966 * to the destination ES
3968 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3969 bgp_evpn_path_es_link(pi
, 0,
3970 bgp_evpn_attr_get_esi(pi
->attr
));
3973 * macip routes (type-2) are imported into VNI and VRF tables.
3974 * IMET route is imported into VNI table.
3975 * prefix routes are imported into VRF table.
3977 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
||
3978 evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
||
3979 evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
||
3980 evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
3982 irt
= in_vni_rt
? lookup_import_rt(bgp
, eval
) : NULL
;
3984 install_uninstall_route_in_vnis(
3985 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
3988 vrf_irt
= in_vrf_rt
? lookup_vrf_import_rt(eval
) : NULL
;
3990 install_uninstall_route_in_vrfs(
3991 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
3994 /* Also check for non-exact match.
3995 * In this, we mask out the AS and
3996 * only check on the local-admin sub-field.
3997 * This is to facilitate using
3998 * VNI as the RT for EBGP peering too.
4002 if (type
== ECOMMUNITY_ENCODE_AS
4003 || type
== ECOMMUNITY_ENCODE_AS4
4004 || type
== ECOMMUNITY_ENCODE_IP
) {
4005 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
4006 mask_ecom_global_admin(&eval_tmp
, eval
);
4008 irt
= lookup_import_rt(bgp
, &eval_tmp
);
4011 lookup_vrf_import_rt(&eval_tmp
);
4015 install_uninstall_route_in_vnis(
4016 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
4019 install_uninstall_route_in_vrfs(
4020 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
4024 /* es route is imported into the es table */
4025 if (evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) {
4027 /* we will match based on the entire esi to avoid
4028 * import of an es route for esi2 into esi1
4030 es
= bgp_evpn_es_find(&evp
->prefix
.es_addr
.esi
);
4031 if (es
&& bgp_evpn_is_es_local(es
))
4032 bgp_evpn_es_route_install_uninstall(
4033 bgp
, es
, afi
, safi
, evp
, pi
, import
);
4041 * Install or uninstall route for appropriate VNIs/ESIs.
4043 static int install_uninstall_evpn_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
4044 const struct prefix
*p
,
4045 struct bgp_path_info
*pi
, int import
)
4047 return bgp_evpn_install_uninstall_table(bgp
, afi
, safi
, p
, pi
, import
,
4051 void bgp_evpn_import_type2_route(struct bgp_path_info
*pi
, int import
)
4053 struct bgp
*bgp_evpn
;
4055 bgp_evpn
= bgp_get_evpn();
4059 install_uninstall_evpn_route(bgp_evpn
, AFI_L2VPN
, SAFI_EVPN
,
4060 &pi
->net
->p
, pi
, import
);
4064 * delete and withdraw all ipv4 and ipv6 routes in the vrf table as type-5
4067 static void delete_withdraw_vrf_routes(struct bgp
*bgp_vrf
)
4069 /* Delete ipv4 default route and withdraw from peers */
4070 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4071 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4072 SAFI_UNICAST
, false);
4074 /* delete all ipv4 routes and withdraw from peers */
4075 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4076 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4078 /* Delete ipv6 default route and withdraw from peers */
4079 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4080 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4081 SAFI_UNICAST
, false);
4083 /* delete all ipv6 routes and withdraw from peers */
4084 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4085 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4089 * update and advertise all ipv4 and ipv6 routes in thr vrf table as type-5
4092 void update_advertise_vrf_routes(struct bgp
*bgp_vrf
)
4094 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
4096 bgp_evpn
= bgp_get_evpn();
4100 /* update all ipv4 routes */
4101 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4102 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4104 /* update ipv4 default route and withdraw from peers */
4105 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4106 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4107 SAFI_UNICAST
, true);
4109 /* update all ipv6 routes */
4110 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4111 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4113 /* update ipv6 default route and withdraw from peers */
4114 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4115 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4116 SAFI_UNICAST
, true);
4121 * update and advertise local routes for a VRF as type-5 routes.
4122 * This is invoked upon RD change for a VRF. Note taht the processing is only
4123 * done in the global route table using the routes which already exist in the
4126 static void update_router_id_vrf(struct bgp
*bgp_vrf
)
4128 /* skip if the RD is configured */
4129 if (is_vrf_rd_configured(bgp_vrf
))
4132 /* derive the RD for the VRF based on new router-id */
4133 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
4135 /* update advertise ipv4|ipv6 routes as type-5 routes */
4136 update_advertise_vrf_routes(bgp_vrf
);
4140 * Delete and withdraw all type-5 routes for the RD corresponding to VRF.
4141 * This is invoked upon VRF RD change. The processing is done only from global
4144 static void withdraw_router_id_vrf(struct bgp
*bgp_vrf
)
4146 /* skip if the RD is configured */
4147 if (is_vrf_rd_configured(bgp_vrf
))
4150 /* delete/withdraw ipv4|ipv6 routes as type-5 routes */
4151 delete_withdraw_vrf_routes(bgp_vrf
);
4154 static void update_advertise_vni_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
4155 struct bgp_dest
*dest
)
4157 struct bgp_dest
*global_dest
;
4158 struct bgp_path_info
*pi
, *global_pi
;
4160 afi_t afi
= AFI_L2VPN
;
4161 safi_t safi
= SAFI_EVPN
;
4163 struct prefix_evpn tmp_evp
;
4164 const struct prefix_evpn
*evp
=
4165 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
4168 * We have already processed type-3 routes.
4169 * Process only type-1 and type-2 routes here.
4171 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
4172 evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
)
4175 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4176 if (pi
->peer
== bgp
->peer_self
&& pi
->type
== ZEBRA_ROUTE_BGP
&&
4177 pi
->sub_type
== BGP_ROUTE_STATIC
)
4183 * VNI table MAC-IP prefixes don't have MAC so make sure it's
4184 * set from path info here.
4186 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4187 if (is_evpn_prefix_ipaddr_none(evp
)) {
4188 /* VNI MAC -> Global */
4189 evpn_type2_prefix_global_copy(
4190 &tmp_evp
, evp
, NULL
/* mac */,
4191 evpn_type2_path_info_get_ip(pi
));
4193 /* VNI IP -> Global */
4194 evpn_type2_prefix_global_copy(
4195 &tmp_evp
, evp
, evpn_type2_path_info_get_mac(pi
),
4199 memcpy(&tmp_evp
, evp
, sizeof(tmp_evp
));
4202 /* Create route in global routing table using this route entry's
4206 global_dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
4207 &tmp_evp
, &vpn
->prd
, NULL
);
4208 assert(global_dest
);
4210 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4212 update_evpn_route_entry(
4213 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4214 NULL
/* ip */, 1, &global_pi
, 0,
4215 mac_mobility_seqnum(attr
), false /* setup_sync */,
4216 NULL
/* old_is_sync */);
4219 struct bgp_evpn_es
*es
;
4220 int route_changed
= 0;
4222 es
= bgp_evpn_es_find(&evp
->prefix
.ead_addr
.esi
);
4223 bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, global_dest
,
4224 attr
, &global_pi
, &route_changed
);
4227 /* Schedule for processing and unlock node. */
4228 bgp_process(bgp
, global_dest
, afi
, safi
);
4229 bgp_dest_unlock_node(global_dest
);
4233 * Update and advertise local routes for a VNI. Invoked upon router-id
4234 * change. Note that the processing is done only on the global route table
4235 * using routes that already exist in the per-VNI table.
4237 static void update_advertise_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4239 struct prefix_evpn p
;
4240 struct bgp_dest
*dest
, *global_dest
;
4241 struct bgp_path_info
*pi
;
4243 afi_t afi
= AFI_L2VPN
;
4244 safi_t safi
= SAFI_EVPN
;
4246 /* Locate type-3 route for VNI in the per-VNI table and use its
4247 * attributes to create and advertise the type-3 route for this VNI
4248 * in the global table.
4250 * RT-3 only if doing head-end replication
4252 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4253 == VXLAN_FLOOD_HEAD_END_REPL
) {
4254 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4255 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
4256 if (!dest
) /* unexpected */
4258 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4259 if (pi
->peer
== bgp
->peer_self
&&
4260 pi
->type
== ZEBRA_ROUTE_BGP
4261 && pi
->sub_type
== BGP_ROUTE_STATIC
)
4264 bgp_dest_unlock_node(dest
);
4270 global_dest
= bgp_evpn_global_node_get(
4271 bgp
->rib
[afi
][safi
], afi
, safi
, &p
, &vpn
->prd
, NULL
);
4272 update_evpn_route_entry(
4273 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4274 NULL
/* ip */, 1, &pi
, 0, mac_mobility_seqnum(attr
),
4275 false /* setup_sync */, NULL
/* old_is_sync */);
4277 /* Schedule for processing and unlock node. */
4278 bgp_process(bgp
, global_dest
, afi
, safi
);
4279 bgp_dest_unlock_node(global_dest
);
4282 /* Now, walk this VNI's MAC & IP route table and use the route and its
4283 * attribute to create and schedule route in global table.
4285 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
4286 dest
= bgp_route_next(dest
))
4287 update_advertise_vni_route(bgp
, vpn
, dest
);
4289 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
4290 dest
= bgp_route_next(dest
))
4291 update_advertise_vni_route(bgp
, vpn
, dest
);
4295 * Delete (and withdraw) local routes for a VNI - only from the global
4296 * table. Invoked upon router-id change.
4298 static int delete_withdraw_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4300 struct prefix_evpn p
;
4301 struct bgp_dest
*global_dest
;
4302 struct bgp_path_info
*pi
;
4303 afi_t afi
= AFI_L2VPN
;
4304 safi_t safi
= SAFI_EVPN
;
4306 /* Delete and withdraw locally learnt type-2 routes (MACIP)
4307 * for this VNI - from the global table.
4309 delete_global_type2_routes(bgp
, vpn
);
4311 /* Remove type-3 route for this VNI from global table. */
4312 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4313 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], safi
, &p
,
4316 /* Delete route entry in the global EVPN table. */
4317 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
4319 /* Schedule for processing - withdraws to peers happen from
4323 bgp_process(bgp
, global_dest
, afi
, safi
);
4324 bgp_dest_unlock_node(global_dest
);
4328 delete_global_ead_evi_routes(bgp
, vpn
);
4333 * Handle router-id change. Update and advertise local routes corresponding
4334 * to this VNI from peers. Note that this is invoked after updating the
4335 * router-id. The routes in the per-VNI table are used to create routes in
4336 * the global table and schedule them.
4338 static void update_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4340 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4342 /* Skip VNIs with configured RD. */
4343 if (is_rd_configured(vpn
))
4346 bgp_evpn_derive_auto_rd(bgp
, vpn
);
4347 update_advertise_vni_routes(bgp
, vpn
);
4351 * Handle router-id change. Delete and withdraw local routes corresponding
4352 * to this VNI from peers. Note that this is invoked prior to updating
4353 * the router-id and is done only on the global route table, the routes
4354 * are needed in the per-VNI table to re-advertise with new router id.
4356 static void withdraw_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4358 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4360 /* Skip VNIs with configured RD. */
4361 if (is_rd_configured(vpn
))
4364 delete_withdraw_vni_routes(bgp
, vpn
);
4368 * Create RT-3 for a VNI and schedule for processing and advertisement.
4369 * This is invoked upon flooding mode changing to head-end replication.
4371 static void create_advertise_type3(struct hash_bucket
*bucket
, void *data
)
4373 struct bgpevpn
*vpn
= bucket
->data
;
4374 struct bgp
*bgp
= data
;
4375 struct prefix_evpn p
;
4377 if (!vpn
|| !is_vni_live(vpn
) ||
4378 bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4379 != VXLAN_FLOOD_HEAD_END_REPL
)
4382 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4383 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
))
4384 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
4385 "Type3 route creation failure for VNI %u", vpn
->vni
);
4389 * Delete RT-3 for a VNI and schedule for processing and withdrawal.
4390 * This is invoked upon flooding mode changing to drop BUM packets.
4392 static void delete_withdraw_type3(struct hash_bucket
*bucket
, void *data
)
4394 struct bgpevpn
*vpn
= bucket
->data
;
4395 struct bgp
*bgp
= data
;
4396 struct prefix_evpn p
;
4398 if (!vpn
|| !is_vni_live(vpn
))
4401 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4402 delete_evpn_route(bgp
, vpn
, &p
);
4406 * Process received EVPN type-2 route (advertise or withdraw).
4408 static int process_type2_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4409 struct attr
*attr
, uint8_t *pfx
, int psize
,
4410 uint32_t addpath_id
)
4412 struct prefix_rd prd
;
4413 struct prefix_evpn p
= {};
4414 struct bgp_route_evpn evpn
= {};
4416 uint8_t macaddr_len
;
4417 /* holds the VNI(s) as in packet */
4418 mpls_label_t label
[BGP_MAX_LABELS
] = {};
4419 uint32_t num_labels
= 0;
4423 /* Type-2 route should be either 33, 37 or 49 bytes or an
4424 * additional 3 bytes if there is a second label (VNI):
4425 * RD (8), ESI (10), Eth Tag (4), MAC Addr Len (1),
4426 * MAC Addr (6), IP len (1), IP (0, 4 or 16),
4427 * MPLS Lbl1 (3), MPLS Lbl2 (0 or 3)
4429 if (psize
!= 33 && psize
!= 37 && psize
!= 49 && psize
!= 36
4430 && psize
!= 40 && psize
!= 52) {
4431 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4432 "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
4433 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4437 struct stream
*pkt
= stream_new(psize
);
4438 stream_put(pkt
, pfx
, psize
);
4440 /* Make prefix_rd */
4441 prd
.family
= AF_UNSPEC
;
4444 STREAM_GET(&prd
.val
, pkt
, 8);
4446 /* Make EVPN prefix. */
4448 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4449 p
.prefix
.route_type
= BGP_EVPN_MAC_IP_ROUTE
;
4451 /* Copy Ethernet Seg Identifier */
4453 STREAM_GET(&attr
->esi
, pkt
, sizeof(esi_t
));
4455 if (bgp_evpn_is_esi_local_and_non_bypass(&attr
->esi
))
4456 attr
->es_flags
|= ATTR_ES_IS_LOCAL
;
4458 attr
->es_flags
&= ~ATTR_ES_IS_LOCAL
;
4460 STREAM_FORWARD_GETP(pkt
, sizeof(esi_t
));
4463 /* Copy Ethernet Tag */
4464 STREAM_GET(ð_tag
, pkt
, 4);
4465 p
.prefix
.macip_addr
.eth_tag
= ntohl(eth_tag
);
4467 /* Get the MAC Addr len */
4468 STREAM_GETC(pkt
, macaddr_len
);
4470 /* Get the MAC Addr */
4471 if (macaddr_len
== (ETH_ALEN
* 8)) {
4472 STREAM_GET(&p
.prefix
.macip_addr
.mac
.octet
, pkt
, ETH_ALEN
);
4475 EC_BGP_EVPN_ROUTE_INVALID
,
4476 "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
4477 peer
->bgp
->vrf_id
, peer
->host
, macaddr_len
);
4483 STREAM_GETC(pkt
, ipaddr_len
);
4485 if (ipaddr_len
!= 0 && ipaddr_len
!= IPV4_MAX_BITLEN
4486 && ipaddr_len
!= IPV6_MAX_BITLEN
) {
4488 EC_BGP_EVPN_ROUTE_INVALID
,
4489 "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
4490 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4495 ipaddr_len
/= 8; /* Convert to bytes. */
4496 p
.prefix
.macip_addr
.ip
.ipa_type
= (ipaddr_len
== IPV4_MAX_BYTELEN
)
4499 STREAM_GET(&p
.prefix
.macip_addr
.ip
.ip
.addr
, pkt
, ipaddr_len
);
4502 /* Get the VNI(s). Stored as bytes here. */
4503 STREAM_GET(&label
[0], pkt
, BGP_LABEL_BYTES
);
4506 /* Do we have a second VNI? */
4507 if (STREAM_READABLE(pkt
)) {
4509 STREAM_GET(&label
[1], pkt
, BGP_LABEL_BYTES
);
4512 /* Process the route. */
4514 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4515 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4516 &label
[0], num_labels
, 0, &evpn
);
4518 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4519 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
[0],
4525 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4526 "%u:%s - Rx EVPN Type-2 NLRI - corrupt, discarding",
4527 peer
->bgp
->vrf_id
, peer
->host
);
4535 * Process received EVPN type-3 route (advertise or withdraw).
4537 static int process_type3_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4538 struct attr
*attr
, uint8_t *pfx
, int psize
,
4539 uint32_t addpath_id
)
4541 struct prefix_rd prd
;
4542 struct prefix_evpn p
;
4546 /* Type-3 route should be either 17 or 29 bytes: RD (8), Eth Tag (4),
4547 * IP len (1) and IP (4 or 16).
4549 if (psize
!= 17 && psize
!= 29) {
4550 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4551 "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
4552 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4556 /* If PMSI is present, log if it is anything other than IR.
4557 * Note: We just simply ignore the values as it is not clear if
4558 * doing anything else is better.
4561 (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
))) {
4562 enum pta_type pmsi_tnl_type
= bgp_attr_get_pmsi_tnl_type(attr
);
4564 if (pmsi_tnl_type
!= PMSI_TNLTYPE_INGR_REPL
4565 && pmsi_tnl_type
!= PMSI_TNLTYPE_PIM_SM
) {
4567 EC_BGP_EVPN_PMSI_PRESENT
,
4568 "%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d",
4569 peer
->bgp
->vrf_id
, peer
->host
, pmsi_tnl_type
);
4573 /* Make prefix_rd */
4574 prd
.family
= AF_UNSPEC
;
4576 memcpy(&prd
.val
, pfx
, 8);
4579 /* Make EVPN prefix. */
4580 memset(&p
, 0, sizeof(p
));
4582 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4583 p
.prefix
.route_type
= BGP_EVPN_IMET_ROUTE
;
4585 /* Copy Ethernet Tag */
4586 memcpy(ð_tag
, pfx
, 4);
4587 p
.prefix
.imet_addr
.eth_tag
= ntohl(eth_tag
);
4591 ipaddr_len
= *pfx
++;
4592 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
4593 p
.prefix
.imet_addr
.ip
.ipa_type
= IPADDR_V4
;
4594 memcpy(&p
.prefix
.imet_addr
.ip
.ip
.addr
, pfx
, IPV4_MAX_BYTELEN
);
4597 EC_BGP_EVPN_ROUTE_INVALID
,
4598 "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
4599 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4603 /* Process the route. */
4605 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4606 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
,
4609 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4610 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
, 0,
4616 * Process received EVPN type-5 route (advertise or withdraw).
4618 static int process_type5_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4619 struct attr
*attr
, uint8_t *pfx
, int psize
,
4620 uint32_t addpath_id
)
4622 struct prefix_rd prd
;
4623 struct prefix_evpn p
;
4624 struct bgp_route_evpn evpn
;
4627 mpls_label_t label
; /* holds the VNI as in the packet */
4628 bool is_valid_update
= true;
4630 /* Type-5 route should be 34 or 58 bytes:
4631 * RD (8), ESI (10), Eth Tag (4), IP len (1), IP (4 or 16),
4632 * GW (4 or 16) and VNI (3).
4633 * Note that the IP and GW should both be IPv4 or both IPv6.
4635 if (psize
!= 34 && psize
!= 58) {
4636 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4637 "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
4638 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4642 /* Make prefix_rd */
4643 prd
.family
= AF_UNSPEC
;
4645 memcpy(&prd
.val
, pfx
, 8);
4648 /* Make EVPN prefix. */
4649 memset(&p
, 0, sizeof(p
));
4651 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4652 p
.prefix
.route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
4654 /* Additional information outside of prefix - ESI and GW IP */
4655 memset(&evpn
, 0, sizeof(evpn
));
4657 /* Fetch ESI overlay index */
4659 memcpy(&evpn
.eth_s_id
, pfx
, sizeof(esi_t
));
4662 /* Fetch Ethernet Tag. */
4663 memcpy(ð_tag
, pfx
, 4);
4664 p
.prefix
.prefix_addr
.eth_tag
= ntohl(eth_tag
);
4667 /* Fetch IP prefix length. */
4669 if (ippfx_len
> IPV6_MAX_BITLEN
) {
4671 EC_BGP_EVPN_ROUTE_INVALID
,
4672 "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
4673 peer
->bgp
->vrf_id
, peer
->host
, ippfx_len
);
4676 p
.prefix
.prefix_addr
.ip_prefix_length
= ippfx_len
;
4678 /* Determine IPv4 or IPv6 prefix */
4679 /* Since the address and GW are from the same family, this just becomes
4680 * a simple check on the total size.
4683 SET_IPADDR_V4(&p
.prefix
.prefix_addr
.ip
);
4684 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v4
, pfx
, 4);
4686 SET_IPADDR_V4(&evpn
.gw_ip
);
4687 memcpy(&evpn
.gw_ip
.ipaddr_v4
, pfx
, 4);
4690 SET_IPADDR_V6(&p
.prefix
.prefix_addr
.ip
);
4691 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v6
, pfx
,
4693 pfx
+= IPV6_MAX_BYTELEN
;
4694 SET_IPADDR_V6(&evpn
.gw_ip
);
4695 memcpy(&evpn
.gw_ip
.ipaddr_v6
, pfx
, IPV6_MAX_BYTELEN
);
4696 pfx
+= IPV6_MAX_BYTELEN
;
4699 /* Get the VNI (in MPLS label field). Stored as bytes here. */
4700 memset(&label
, 0, sizeof(label
));
4701 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
4704 * If in future, we are required to access additional fields,
4705 * we MUST increment pfx by BGP_LABEL_BYTES in before reading the next
4710 * An update containing a non-zero gateway IP and a non-zero ESI
4711 * at the same time is should be treated as withdraw
4713 if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4714 !ipaddr_is_zero(&evpn
.gw_ip
)) {
4715 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4716 "%s - Rx EVPN Type-5 ESI and gateway-IP both non-zero.",
4718 is_valid_update
= false;
4719 } else if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
))
4720 evpn
.type
= OVERLAY_INDEX_ESI
;
4721 else if (!ipaddr_is_zero(&evpn
.gw_ip
))
4722 evpn
.type
= OVERLAY_INDEX_GATEWAY_IP
;
4724 if (is_zero_mac(&attr
->rmac
) &&
4725 !bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4726 ipaddr_is_zero(&evpn
.gw_ip
) && label
== 0) {
4727 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4728 "%s - Rx EVPN Type-5 ESI, gateway-IP, RMAC and label all zero",
4730 is_valid_update
= false;
4733 if (is_mcast_mac(&attr
->rmac
) || is_bcast_mac(&attr
->rmac
))
4734 is_valid_update
= false;
4737 /* Process the route. */
4738 if (attr
&& is_valid_update
)
4739 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4740 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4741 &label
, 1, 0, &evpn
);
4743 if (!is_valid_update
) {
4744 char attr_str
[BUFSIZ
] = {0};
4746 bgp_dump_attr(attr
, attr_str
, BUFSIZ
);
4748 "Invalid update from peer %s vrf %u prefix %pFX attr %s - treat as withdraw",
4749 peer
->hostname
, peer
->bgp
->vrf_id
, &p
,
4752 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4753 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
, 1,
4760 static void evpn_mpattr_encode_type5(struct stream
*s
, const struct prefix
*p
,
4761 const struct prefix_rd
*prd
,
4762 mpls_label_t
*label
, uint32_t num_labels
,
4767 const struct evpn_addr
*p_evpn_p
;
4769 memset(&temp
, 0, sizeof(temp
));
4770 if (p
->family
!= AF_EVPN
)
4772 p_evpn_p
= &(p
->u
.prefix_evpn
);
4774 /* len denites the total len of IP and GW-IP in the route
4775 IP and GW-IP have to be both ipv4 or ipv6
4777 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4778 len
= 8; /* IP and GWIP are both ipv4 */
4780 len
= 32; /* IP and GWIP are both ipv6 */
4781 /* Prefix contains RD, ESI, EthTag, IP length, IP, GWIP and VNI */
4782 stream_putc(s
, 8 + 10 + 4 + 1 + len
+ 3);
4783 stream_put(s
, prd
->val
, 8);
4784 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_ESI
)
4785 stream_put(s
, &attr
->esi
, sizeof(esi_t
));
4787 stream_put(s
, 0, sizeof(esi_t
));
4788 stream_putl(s
, p_evpn_p
->prefix_addr
.eth_tag
);
4789 stream_putc(s
, p_evpn_p
->prefix_addr
.ip_prefix_length
);
4790 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4791 stream_put_ipv4(s
, p_evpn_p
->prefix_addr
.ip
.ipaddr_v4
.s_addr
);
4793 stream_put(s
, &p_evpn_p
->prefix_addr
.ip
.ipaddr_v6
, 16);
4794 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
4795 const struct bgp_route_evpn
*evpn_overlay
=
4796 bgp_attr_get_evpn_overlay(attr
);
4798 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4800 evpn_overlay
->gw_ip
.ipaddr_v4
.s_addr
);
4802 stream_put(s
, &(evpn_overlay
->gw_ip
.ipaddr_v6
), 16);
4804 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4805 stream_put_ipv4(s
, 0);
4807 stream_put(s
, &temp
, 16);
4811 stream_put(s
, label
, 3);
4817 * Cleanup specific VNI upon EVPN (advertise-all-vni) being disabled.
4819 static void cleanup_vni_on_disable(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4821 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4823 /* Remove EVPN routes and schedule for processing. */
4824 delete_routes_for_vni(bgp
, vpn
);
4826 /* Clear "live" flag and see if hash needs to be freed. */
4827 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
4828 if (!is_vni_configured(vpn
))
4829 bgp_evpn_free(bgp
, vpn
);
4833 * Free a VNI entry; iterator function called during cleanup.
4835 static void free_vni_entry(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4837 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4839 delete_all_vni_routes(bgp
, vpn
);
4840 bgp_evpn_free(bgp
, vpn
);
4844 * Derive AUTO import RT for BGP VRF - L3VNI
4846 static void evpn_auto_rt_import_add_for_vrf(struct bgp
*bgp_vrf
)
4848 struct bgp
*bgp_evpn
= NULL
;
4850 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
, true);
4853 bgp_evpn
= bgp_get_evpn();
4858 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
4862 * Delete AUTO import RT from BGP VRF - L3VNI
4864 static void evpn_auto_rt_import_delete_for_vrf(struct bgp
*bgp_vrf
)
4866 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
,
4871 * Derive AUTO export RT for BGP VRF - L3VNI
4873 static void evpn_auto_rt_export_add_for_vrf(struct bgp
*bgp_vrf
)
4875 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
, true);
4879 * Delete AUTO export RT from BGP VRF - L3VNI
4881 static void evpn_auto_rt_export_delete_for_vrf(struct bgp
*bgp_vrf
)
4883 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
,
4887 static void bgp_evpn_handle_export_rt_change_for_vrf(struct bgp
*bgp_vrf
)
4889 struct bgp
*bgp_evpn
= NULL
;
4890 struct listnode
*node
= NULL
;
4891 struct bgpevpn
*vpn
= NULL
;
4893 bgp_evpn
= bgp_get_evpn();
4897 /* update all type-5 routes */
4898 update_advertise_vrf_routes(bgp_vrf
);
4900 /* update all type-2 routes */
4901 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
4902 update_routes_for_vni(bgp_evpn
, vpn
);
4906 * Handle autort change for a given VNI.
4908 static void update_autort_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4910 struct bgpevpn
*vpn
= bucket
->data
;
4912 if (!is_import_rt_configured(vpn
)) {
4913 if (is_vni_live(vpn
))
4914 bgp_evpn_uninstall_routes(bgp
, vpn
);
4915 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
4916 list_delete_all_node(vpn
->import_rtl
);
4917 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
4918 if (is_vni_live(vpn
))
4919 bgp_evpn_install_routes(bgp
, vpn
);
4921 if (!is_export_rt_configured(vpn
)) {
4922 list_delete_all_node(vpn
->export_rtl
);
4923 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
4924 if (is_vni_live(vpn
))
4925 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
4930 * Handle autort change for L3VNI.
4932 static void update_autort_l3vni(struct bgp
*bgp
)
4934 if ((CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
4935 && (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)))
4938 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
4939 if (is_l3vni_live(bgp
))
4940 uninstall_routes_for_vrf(bgp
);
4942 /* Cleanup the RT to VRF mapping */
4943 bgp_evpn_unmap_vrf_from_its_rts(bgp
);
4945 /* Remove auto generated RT */
4946 evpn_auto_rt_import_delete_for_vrf(bgp
);
4948 list_delete_all_node(bgp
->vrf_import_rtl
);
4950 /* Map auto derive or configured RTs */
4951 evpn_auto_rt_import_add_for_vrf(bgp
);
4954 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4955 list_delete_all_node(bgp
->vrf_export_rtl
);
4957 evpn_auto_rt_export_delete_for_vrf(bgp
);
4959 evpn_auto_rt_export_add_for_vrf(bgp
);
4961 if (is_l3vni_live(bgp
))
4962 bgp_evpn_map_vrf_to_its_rts(bgp
);
4965 if (!is_l3vni_live(bgp
))
4968 /* advertise type-5 routes if needed */
4969 update_advertise_vrf_routes(bgp
);
4971 /* install all remote routes belonging to this l3vni
4972 * into corresponding vrf
4974 install_routes_for_vrf(bgp
);
4981 /* withdraw type-5 route corresponding to ip prefix */
4982 void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
4983 afi_t afi
, safi_t safi
)
4986 struct prefix_evpn evp
;
4988 build_type5_prefix_from_ip_prefix(&evp
, p
);
4989 ret
= delete_evpn_type5_route(bgp_vrf
, &evp
);
4992 EC_BGP_EVPN_ROUTE_DELETE
,
4993 "%u failed to delete type-5 route for prefix %pFX in vrf %s",
4994 bgp_vrf
->vrf_id
, p
, vrf_id_to_name(bgp_vrf
->vrf_id
));
4997 /* withdraw all type-5 routes for an address family */
4998 void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
, safi_t safi
)
5000 struct bgp_table
*table
= NULL
;
5001 struct bgp_dest
*dest
= NULL
;
5002 struct bgp_path_info
*pi
;
5004 table
= bgp_vrf
->rib
[afi
][safi
];
5005 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5006 /* Only care about "selected" routes. Also ensure that
5007 * these are routes that are injectable into EVPN.
5009 /* TODO: Support for AddPath for EVPN. */
5010 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5011 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5012 && is_route_injectable_into_evpn(pi
)) {
5013 bgp_evpn_withdraw_type5_route(
5014 bgp_vrf
, bgp_dest_get_prefix(dest
), afi
,
5023 * evpn - enable advertisement of default g/w
5025 void bgp_evpn_install_uninstall_default_route(struct bgp
*bgp_vrf
, afi_t afi
,
5026 safi_t safi
, bool add
)
5028 struct prefix ip_prefix
;
5030 /* form the default prefix 0.0.0.0/0 */
5031 memset(&ip_prefix
, 0, sizeof(ip_prefix
));
5032 ip_prefix
.family
= afi2family(afi
);
5035 bgp_evpn_advertise_type5_route(bgp_vrf
, &ip_prefix
,
5038 bgp_evpn_withdraw_type5_route(bgp_vrf
, &ip_prefix
,
5045 * Advertise IP prefix as type-5 route. The afi/safi and src_attr passed
5046 * to this function correspond to those of the source IP prefix (best
5047 * path in the case of the attr. In the case of a local prefix (when we
5048 * are advertising local subnets), the src_attr will be NULL.
5050 void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
5051 struct attr
*src_attr
, afi_t afi
,
5055 struct prefix_evpn evp
;
5057 build_type5_prefix_from_ip_prefix(&evp
, p
);
5058 ret
= update_evpn_type5_route(bgp_vrf
, &evp
, src_attr
, afi
, safi
);
5060 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
5061 "%u: Failed to create type-5 route for prefix %pFX",
5062 bgp_vrf
->vrf_id
, p
);
5065 /* Inject all prefixes of a particular address-family (currently, IPv4 or
5066 * IPv6 unicast) into EVPN as type-5 routes. This is invoked when the
5067 * advertisement is enabled.
5069 void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
5072 struct bgp_table
*table
= NULL
;
5073 struct bgp_dest
*dest
= NULL
;
5074 struct bgp_path_info
*pi
;
5076 table
= bgp_vrf
->rib
[afi
][safi
];
5077 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5078 /* Need to identify the "selected" route entry to use its
5079 * attribute. Also, ensure that the route is injectable
5081 * TODO: Support for AddPath for EVPN.
5083 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5084 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5085 && is_route_injectable_into_evpn(pi
)) {
5087 /* apply the route-map */
5088 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
) {
5089 route_map_result_t ret
;
5090 struct bgp_path_info tmp_pi
;
5091 struct bgp_path_info_extra tmp_pie
;
5092 struct attr tmp_attr
;
5094 tmp_attr
= *pi
->attr
;
5096 /* Fill temp path_info */
5097 prep_for_rmap_apply(&tmp_pi
, &tmp_pie
,
5101 RESET_FLAG(tmp_attr
.rmap_change_flags
);
5103 ret
= route_map_apply(
5104 bgp_vrf
->adv_cmd_rmap
[afi
][safi
]
5106 bgp_dest_get_prefix(dest
),
5108 if (ret
== RMAP_DENYMATCH
) {
5109 bgp_attr_flush(&tmp_attr
);
5112 bgp_evpn_advertise_type5_route(
5114 bgp_dest_get_prefix(dest
),
5115 &tmp_attr
, afi
, safi
);
5117 bgp_evpn_advertise_type5_route(
5119 bgp_dest_get_prefix(dest
),
5120 pi
->attr
, afi
, safi
);
5127 static void rt_list_remove_node(struct list
*rt_list
,
5128 struct ecommunity
*ecomdel
, bool is_l3
)
5130 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
5131 struct vrf_route_target
*l3rt
= NULL
;
5132 struct ecommunity
*ecom
= NULL
;
5135 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5136 if (ecommunity_match(l3rt
->ecom
, ecomdel
)) {
5137 evpn_vrf_rt_del(l3rt
);
5143 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, ecom
)) {
5144 if (ecommunity_match(ecom
, ecomdel
)) {
5145 ecommunity_free(&ecom
);
5154 list_delete_node(rt_list
, node_to_del
);
5157 void evpn_rt_delete_auto(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
,
5160 struct ecommunity
*ecom_auto
;
5161 struct ecommunity_val eval
;
5163 if (bgp
->advertise_autort_rfc8365
)
5164 vni
|= EVPN_AUTORT_VXLAN
;
5166 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
, true);
5168 ecom_auto
= ecommunity_new();
5169 ecommunity_add_val(ecom_auto
, &eval
, false, false);
5171 rt_list_remove_node(rtl
, ecom_auto
, is_l3
);
5173 ecommunity_free(&ecom_auto
);
5176 static void evpn_vrf_rt_routes_map(struct bgp
*bgp_vrf
)
5178 /* map VRFs to its RTs and install routes matching this new RT */
5179 if (is_l3vni_live(bgp_vrf
)) {
5180 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
5181 install_routes_for_vrf(bgp_vrf
);
5185 static void evpn_vrf_rt_routes_unmap(struct bgp
*bgp_vrf
)
5187 /* uninstall routes from vrf */
5188 if (is_l3vni_live(bgp_vrf
))
5189 uninstall_routes_for_vrf(bgp_vrf
);
5191 /* Cleanup the RT to VRF mapping */
5192 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
5195 static bool rt_list_has_cfgd_rt(struct list
*rt_list
)
5197 struct listnode
*node
= NULL
, *nnode
= NULL
;
5198 struct vrf_route_target
*l3rt
= NULL
;
5200 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5201 if (!CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
))
5208 static void unconfigure_import_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5210 if (!bgp_vrf
->vrf_import_rtl
)
5211 return; /* this should never fail */
5213 if (!is_l3vni_live(bgp_vrf
))
5214 return; /* Nothing to do if no vni */
5216 /* fall back to auto-generated RT if this was the last RT */
5217 if (list_isempty(bgp_vrf
->vrf_import_rtl
))
5218 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5221 static void unconfigure_export_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5224 if (!bgp_vrf
->vrf_export_rtl
)
5225 return; /* this should never fail */
5227 if (!is_l3vni_live(bgp_vrf
))
5228 return; /* Nothing to do if no vni */
5230 /* fall back to auto-generated RT if this was the last RT */
5231 if (list_isempty(bgp_vrf
->vrf_export_rtl
))
5232 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5234 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5237 void bgp_evpn_configure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5238 struct ecommunity
*ecomadd
,
5241 struct vrf_route_target
*newrt
;
5243 newrt
= evpn_vrf_rt_new(ecomadd
);
5246 SET_FLAG(newrt
->flags
, BGP_VRF_RT_WILD
);
5248 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5250 /* Remove auto generated RT if not configured */
5251 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5252 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5254 /* Add the newly configured RT to RT list */
5255 listnode_add_sort(bgp_vrf
->vrf_import_rtl
, newrt
);
5257 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5259 evpn_vrf_rt_routes_map(bgp_vrf
);
5262 void bgp_evpn_configure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5264 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5265 return; /* Already configured */
5267 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5269 if (!is_l3vni_live(bgp_vrf
))
5270 return; /* Wait for VNI before adding rts */
5272 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5274 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5276 evpn_vrf_rt_routes_map(bgp_vrf
);
5279 void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5280 struct ecommunity
*ecomdel
)
5282 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
5283 return; /* Already un-configured */
5285 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5288 rt_list_remove_node(bgp_vrf
->vrf_import_rtl
, ecomdel
, true);
5290 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_import_rtl
))
5291 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5293 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5295 evpn_vrf_rt_routes_map(bgp_vrf
);
5298 void bgp_evpn_unconfigure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5300 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5301 return; /* Already un-configured */
5303 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5305 /* remove auto-generated RT */
5306 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5308 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5310 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5312 evpn_vrf_rt_routes_map(bgp_vrf
);
5315 void bgp_evpn_configure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5316 struct ecommunity
*ecomadd
)
5318 struct vrf_route_target
*newrt
;
5320 newrt
= evpn_vrf_rt_new(ecomadd
);
5322 /* Remove auto generated RT if not configured */
5323 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5324 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5326 /* Add the new RT to the RT list */
5327 listnode_add_sort(bgp_vrf
->vrf_export_rtl
, newrt
);
5329 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5331 if (is_l3vni_live(bgp_vrf
))
5332 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5335 void bgp_evpn_configure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5337 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5338 return; /* Already configured */
5340 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5342 if (!is_l3vni_live(bgp_vrf
))
5343 return; /* Wait for VNI before adding rts */
5345 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5347 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5350 void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5351 struct ecommunity
*ecomdel
)
5353 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
))
5354 return; /* Already un-configured */
5357 rt_list_remove_node(bgp_vrf
->vrf_export_rtl
, ecomdel
, true);
5359 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_export_rtl
))
5360 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5362 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5365 void bgp_evpn_unconfigure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5367 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5368 return; /* Already un-configured */
5370 /* remove auto-generated RT */
5371 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5373 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5375 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5379 * Handle change to BGP router id. This is invoked twice by the change
5380 * handler, first before the router id has been changed and then after
5381 * the router id has been changed. The first invocation will result in
5382 * local routes for all VNIs/VRF being deleted and withdrawn and the next
5383 * will result in the routes being re-advertised.
5385 void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
)
5387 struct listnode
*node
;
5388 struct bgp
*bgp_vrf
;
5392 /* delete and withdraw all the type-5 routes
5393 stored in the global table for this vrf
5395 withdraw_router_id_vrf(bgp
);
5397 /* delete all the VNI routes (type-2/type-3) routes for all the
5400 hash_iterate(bgp
->vnihash
,
5401 (void (*)(struct hash_bucket
*,
5402 void *))withdraw_router_id_vni
,
5405 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5406 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5407 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5408 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5410 bgp_vrf
->evpn_info
->pip_ip
.s_addr
5416 /* Assign new default instance router-id */
5417 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5418 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5419 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5420 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5422 bgp_vrf
->evpn_info
->pip_ip
=
5424 /* advertise type-5 routes with
5427 update_advertise_vrf_routes(bgp_vrf
);
5432 /* advertise all routes in the vrf as type-5 routes with the new
5435 update_router_id_vrf(bgp
);
5437 /* advertise all the VNI routes (type-2/type-3) routes with the
5440 hash_iterate(bgp
->vnihash
,
5441 (void (*)(struct hash_bucket
*,
5442 void *))update_router_id_vni
,
5448 * Handle change to auto-RT algorithm - update and advertise local routes.
5450 void bgp_evpn_handle_autort_change(struct bgp
*bgp
)
5452 hash_iterate(bgp
->vnihash
,
5453 (void (*)(struct hash_bucket
*,
5454 void*))update_autort_vni
,
5457 update_autort_l3vni(bgp
);
5461 * Handle change to export RT - update and advertise local routes.
5463 int bgp_evpn_handle_export_rt_change(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5465 return update_routes_for_vni(bgp
, vpn
);
5468 void bgp_evpn_handle_vrf_rd_change(struct bgp
*bgp_vrf
, int withdraw
)
5471 delete_withdraw_vrf_routes(bgp_vrf
);
5473 update_advertise_vrf_routes(bgp_vrf
);
5477 * Handle change to RD. This is invoked twice by the change handler,
5478 * first before the RD has been changed and then after the RD has
5479 * been changed. The first invocation will result in local routes
5480 * of this VNI being deleted and withdrawn and the next will result
5481 * in the routes being re-advertised.
5483 void bgp_evpn_handle_rd_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
5487 delete_withdraw_vni_routes(bgp
, vpn
);
5489 update_advertise_vni_routes(bgp
, vpn
);
5493 * Install routes for this VNI. Invoked upon change to Import RT.
5495 int bgp_evpn_install_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5497 return install_routes_for_vni(bgp
, vpn
);
5501 * Uninstall all routes installed for this VNI. Invoked upon change
5504 int bgp_evpn_uninstall_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5506 return uninstall_routes_for_vni(bgp
, vpn
);
5510 * TODO: Hardcoded for a maximum of 2 VNIs right now
5512 char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
, char *buf
,
5517 vni1
= label2vni(label
);
5518 if (num_labels
== 2) {
5519 vni2
= label2vni(label
+ 1);
5520 snprintf(buf
, len
, "%u/%u", vni1
, vni2
);
5522 snprintf(buf
, len
, "%u", vni1
);
5527 * Function to convert evpn route to json format.
5528 * NOTE: We don't use prefix2str as the output here is a bit different.
5530 void bgp_evpn_route2json(const struct prefix_evpn
*p
, json_object
*json
)
5532 char buf1
[ETHER_ADDR_STRLEN
];
5533 char buf2
[PREFIX2STR_BUFFER
];
5540 json_object_int_add(json
, "routeType", p
->prefix
.route_type
);
5542 switch (p
->prefix
.route_type
) {
5543 case BGP_EVPN_MAC_IP_ROUTE
:
5544 json_object_int_add(json
, "ethTag",
5545 p
->prefix
.macip_addr
.eth_tag
);
5546 json_object_int_add(json
, "macLen", 8 * ETH_ALEN
);
5547 json_object_string_add(json
, "mac",
5548 prefix_mac2str(&p
->prefix
.macip_addr
.mac
, buf1
,
5551 if (!is_evpn_prefix_ipaddr_none(p
)) {
5552 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
:
5554 prefixlen
= (family
== AF_INET
) ?
5555 IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN
;
5556 inet_ntop(family
, &p
->prefix
.macip_addr
.ip
.ip
.addr
,
5557 buf2
, PREFIX2STR_BUFFER
);
5558 json_object_int_add(json
, "ipLen", prefixlen
);
5559 json_object_string_add(json
, "ip", buf2
);
5563 case BGP_EVPN_IMET_ROUTE
:
5564 json_object_int_add(json
, "ethTag",
5565 p
->prefix
.imet_addr
.eth_tag
);
5566 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5567 prefixlen
= (family
== AF_INET
) ? IPV4_MAX_BITLEN
:
5569 inet_ntop(family
, &p
->prefix
.imet_addr
.ip
.ip
.addr
, buf2
,
5571 json_object_int_add(json
, "ipLen", prefixlen
);
5572 json_object_string_add(json
, "ip", buf2
);
5575 case BGP_EVPN_IP_PREFIX_ROUTE
:
5576 json_object_int_add(json
, "ethTag",
5577 p
->prefix
.prefix_addr
.eth_tag
);
5578 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5579 inet_ntop(family
, &p
->prefix
.prefix_addr
.ip
.ip
.addr
,
5580 buf2
, sizeof(buf2
));
5581 json_object_int_add(json
, "ipLen",
5582 p
->prefix
.prefix_addr
.ip_prefix_length
);
5583 json_object_string_add(json
, "ip", buf2
);
5592 * Encode EVPN prefix in Update (MP_REACH)
5594 void bgp_evpn_encode_prefix(struct stream
*s
, const struct prefix
*p
,
5595 const struct prefix_rd
*prd
, mpls_label_t
*label
,
5596 uint32_t num_labels
, struct attr
*attr
,
5597 bool addpath_capable
, uint32_t addpath_tx_id
)
5599 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
5600 int len
, ipa_len
= 0;
5602 if (addpath_capable
)
5603 stream_putl(s
, addpath_tx_id
);
5606 stream_putc(s
, evp
->prefix
.route_type
);
5608 switch (evp
->prefix
.route_type
) {
5609 case BGP_EVPN_MAC_IP_ROUTE
:
5610 if (is_evpn_prefix_ipaddr_v4(evp
))
5611 ipa_len
= IPV4_MAX_BYTELEN
;
5612 else if (is_evpn_prefix_ipaddr_v6(evp
))
5613 ipa_len
= IPV6_MAX_BYTELEN
;
5614 /* RD, ESI, EthTag, MAC+len, IP len, [IP], 1 VNI */
5615 len
= 8 + 10 + 4 + 1 + 6 + 1 + ipa_len
+ 3;
5616 if (ipa_len
&& num_labels
> 1) /* There are 2 VNIs */
5618 stream_putc(s
, len
);
5619 stream_put(s
, prd
->val
, 8); /* RD */
5621 stream_put(s
, &attr
->esi
, ESI_BYTES
);
5623 stream_put(s
, 0, 10);
5624 stream_putl(s
, evp
->prefix
.macip_addr
.eth_tag
); /* Ethernet Tag ID */
5625 stream_putc(s
, 8 * ETH_ALEN
); /* Mac Addr Len - bits */
5626 stream_put(s
, evp
->prefix
.macip_addr
.mac
.octet
, 6); /* Mac Addr */
5627 stream_putc(s
, 8 * ipa_len
); /* IP address Length */
5628 if (ipa_len
) /* IP */
5629 stream_put(s
, &evp
->prefix
.macip_addr
.ip
.ip
.addr
,
5631 /* 1st label is the L2 VNI */
5632 stream_put(s
, label
, BGP_LABEL_BYTES
);
5633 /* Include 2nd label (L3 VNI) if advertising MAC+IP */
5634 if (ipa_len
&& num_labels
> 1)
5635 stream_put(s
, label
+ 1, BGP_LABEL_BYTES
);
5638 case BGP_EVPN_IMET_ROUTE
:
5639 stream_putc(s
, 17); // TODO: length - assumes IPv4 address
5640 stream_put(s
, prd
->val
, 8); /* RD */
5641 stream_putl(s
, evp
->prefix
.imet_addr
.eth_tag
); /* Ethernet Tag ID */
5642 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5643 /* Originating Router's IP Addr */
5644 stream_put_in_addr(s
, &evp
->prefix
.imet_addr
.ip
.ipaddr_v4
);
5647 case BGP_EVPN_ES_ROUTE
:
5648 stream_putc(s
, 23); /* TODO: length: assumes ipv4 VTEP */
5649 stream_put(s
, prd
->val
, 8); /* RD */
5650 stream_put(s
, evp
->prefix
.es_addr
.esi
.val
, 10); /* ESI */
5651 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5653 stream_put_in_addr(s
, &evp
->prefix
.es_addr
.ip
.ipaddr_v4
);
5656 case BGP_EVPN_AD_ROUTE
:
5657 /* RD, ESI, EthTag, 1 VNI */
5658 len
= RD_BYTES
+ ESI_BYTES
+ EVPN_ETH_TAG_BYTES
+ BGP_LABEL_BYTES
;
5659 stream_putc(s
, len
);
5660 stream_put(s
, prd
->val
, RD_BYTES
); /* RD */
5661 stream_put(s
, evp
->prefix
.ead_addr
.esi
.val
, ESI_BYTES
); /* ESI */
5662 stream_putl(s
, evp
->prefix
.ead_addr
.eth_tag
); /* Ethernet Tag */
5663 stream_put(s
, label
, BGP_LABEL_BYTES
);
5666 case BGP_EVPN_IP_PREFIX_ROUTE
:
5667 /* TODO: AddPath support. */
5668 evpn_mpattr_encode_type5(s
, p
, prd
, label
, num_labels
, attr
);
5676 int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
5677 struct bgp_nlri
*packet
, bool withdraw
)
5683 uint32_t addpath_id
;
5684 bool addpath_capable
;
5689 /* Start processing the NLRI - there may be multiple in the MP_REACH */
5691 lim
= pnt
+ packet
->length
;
5693 safi
= packet
->safi
;
5696 addpath_capable
= bgp_addpath_encode_rx(peer
, afi
, safi
);
5698 for (; pnt
< lim
; pnt
+= psize
) {
5699 /* Clear prefix structure. */
5700 memset(&p
, 0, sizeof(p
));
5702 /* Deal with path-id if AddPath is supported. */
5703 if (addpath_capable
) {
5704 /* When packet overflow occurs return immediately. */
5705 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
5706 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5708 memcpy(&addpath_id
, pnt
, BGP_ADDPATH_ID_LEN
);
5709 addpath_id
= ntohl(addpath_id
);
5710 pnt
+= BGP_ADDPATH_ID_LEN
;
5713 /* All EVPN NLRI types start with type and length. */
5715 return BGP_NLRI_PARSE_ERROR_EVPN_MISSING_TYPE
;
5720 /* When packet overflow occur return immediately. */
5721 if (pnt
+ psize
> lim
)
5722 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5725 case BGP_EVPN_MAC_IP_ROUTE
:
5726 if (process_type2_route(peer
, afi
, safi
,
5727 withdraw
? NULL
: attr
, pnt
,
5728 psize
, addpath_id
)) {
5731 "%u:%s - Error in processing EVPN type-2 NLRI size %d",
5732 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5733 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE2_SIZE
;
5737 case BGP_EVPN_IMET_ROUTE
:
5738 if (process_type3_route(peer
, afi
, safi
,
5739 withdraw
? NULL
: attr
, pnt
,
5740 psize
, addpath_id
)) {
5743 "%u:%s - Error in processing EVPN type-3 NLRI size %d",
5744 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5745 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE3_SIZE
;
5749 case BGP_EVPN_ES_ROUTE
:
5750 if (bgp_evpn_type4_route_process(peer
, afi
, safi
,
5751 withdraw
? NULL
: attr
, pnt
,
5752 psize
, addpath_id
)) {
5755 "%u:%s - Error in processing EVPN type-4 NLRI size %d",
5756 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5757 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE4_SIZE
;
5761 case BGP_EVPN_AD_ROUTE
:
5762 if (bgp_evpn_type1_route_process(peer
, afi
, safi
,
5763 withdraw
? NULL
: attr
, pnt
,
5764 psize
, addpath_id
)) {
5767 "%u:%s - Error in processing EVPN type-1 NLRI size %d",
5768 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5769 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE
;
5773 case BGP_EVPN_IP_PREFIX_ROUTE
:
5774 if (process_type5_route(peer
, afi
, safi
,
5775 withdraw
? NULL
: attr
, pnt
,
5776 psize
, addpath_id
)) {
5779 "%u:%s - Error in processing EVPN type-5 NLRI size %d",
5780 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5781 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE5_SIZE
;
5790 /* Packet length consistency check. */
5792 return BGP_NLRI_PARSE_ERROR_PACKET_LENGTH
;
5794 return BGP_NLRI_PARSE_OK
;
5798 * Map the RTs (configured or automatically derived) of a VRF to the VRF.
5799 * The mapping will be used during route processing.
5800 * bgp_vrf: specific bgp vrf instance on which RT is configured
5802 void bgp_evpn_map_vrf_to_its_rts(struct bgp
*bgp_vrf
)
5804 struct listnode
*node
, *nnode
;
5805 struct vrf_route_target
*l3rt
;
5807 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5808 map_vrf_to_rt(bgp_vrf
, l3rt
);
5812 * Unmap the RTs (configured or automatically derived) of a VRF from the VRF.
5814 void bgp_evpn_unmap_vrf_from_its_rts(struct bgp
*bgp_vrf
)
5816 struct listnode
*node
, *nnode
;
5817 struct vrf_route_target
*l3rt
;
5819 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5820 unmap_vrf_from_rt(bgp_vrf
, l3rt
);
5824 * Map the RTs (configured or automatically derived) of a VNI to the VNI.
5825 * The mapping will be used during route processing.
5827 void bgp_evpn_map_vni_to_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5830 struct ecommunity_val
*eval
;
5831 struct listnode
*node
, *nnode
;
5832 struct ecommunity
*ecom
;
5834 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5835 for (i
= 0; i
< ecom
->size
; i
++) {
5836 eval
= (struct ecommunity_val
*)(ecom
->val
5838 * ECOMMUNITY_SIZE
));
5839 map_vni_to_rt(bgp
, vpn
, eval
);
5845 * Unmap the RTs (configured or automatically derived) of a VNI from the VNI.
5847 void bgp_evpn_unmap_vni_from_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5850 struct ecommunity_val
*eval
;
5851 struct listnode
*node
, *nnode
;
5852 struct ecommunity
*ecom
;
5854 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5855 for (i
= 0; i
< ecom
->size
; i
++) {
5856 struct irt_node
*irt
;
5857 struct ecommunity_val eval_tmp
;
5859 eval
= (struct ecommunity_val
*)(ecom
->val
5861 * ECOMMUNITY_SIZE
));
5862 /* If using "automatic" RT, we only care about the
5863 * local-admin sub-field.
5864 * This is to facilitate using VNI as the RT for EBGP
5867 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
5868 if (!is_import_rt_configured(vpn
))
5869 mask_ecom_global_admin(&eval_tmp
, eval
);
5871 irt
= lookup_import_rt(bgp
, &eval_tmp
);
5873 unmap_vni_from_rt(bgp
, vpn
, irt
);
5879 * Derive Import RT automatically for VNI and map VNI to RT.
5880 * The mapping will be used during route processing.
5882 void bgp_evpn_derive_auto_rt_import(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5884 form_auto_rt(bgp
, vpn
->vni
, vpn
->import_rtl
, false);
5885 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
5888 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
5892 * Derive Export RT automatically for VNI.
5894 void bgp_evpn_derive_auto_rt_export(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5896 form_auto_rt(bgp
, vpn
->vni
, vpn
->export_rtl
, false);
5897 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
5901 * Derive RD automatically for VNI using passed information - it
5902 * is of the form RouterId:unique-id-for-vni.
5904 void bgp_evpn_derive_auto_rd_for_vrf(struct bgp
*bgp
)
5906 if (is_vrf_rd_configured(bgp
))
5909 form_auto_rd(bgp
->router_id
, bgp
->vrf_rd_id
, &bgp
->vrf_prd
);
5913 * Derive RD automatically for VNI using passed information - it
5914 * is of the form RouterId:unique-id-for-vni.
5916 void bgp_evpn_derive_auto_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5918 char buf
[BGP_EVPN_PREFIX_RD_LEN
];
5920 vpn
->prd
.family
= AF_UNSPEC
;
5921 vpn
->prd
.prefixlen
= 64;
5922 snprintfrr(buf
, sizeof(buf
), "%pI4:%hu", &bgp
->router_id
, vpn
->rd_id
);
5923 (void)str2prefix_rd(buf
, &vpn
->prd
);
5924 if (vpn
->prd_pretty
)
5925 XFREE(MTYPE_BGP
, vpn
->prd_pretty
);
5926 UNSET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
5932 bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni
)
5934 struct list
*inst
= bm
->bgp
;
5935 struct listnode
*node
;
5936 struct bgp
*bgp_vrf
;
5938 for (ALL_LIST_ELEMENTS_RO(inst
, node
, bgp_vrf
)) {
5939 if (bgp_vrf
->l3vni
== vni
)
5949 struct bgpevpn
*bgp_evpn_lookup_vni(struct bgp
*bgp
, vni_t vni
)
5951 struct bgpevpn
*vpn
;
5954 memset(&tmp
, 0, sizeof(tmp
));
5956 vpn
= hash_lookup(bgp
->vnihash
, &tmp
);
5961 * Create a new vpn - invoked upon configuration or zebra notification.
5963 struct bgpevpn
*bgp_evpn_new(struct bgp
*bgp
, vni_t vni
,
5964 struct in_addr originator_ip
,
5965 vrf_id_t tenant_vrf_id
,
5966 struct in_addr mcast_grp
,
5967 ifindex_t svi_ifindex
)
5969 struct bgpevpn
*vpn
;
5971 vpn
= XCALLOC(MTYPE_BGP_EVPN
, sizeof(struct bgpevpn
));
5973 /* Set values - RD and RT set to defaults. */
5975 vpn
->originator_ip
= originator_ip
;
5976 vpn
->tenant_vrf_id
= tenant_vrf_id
;
5977 vpn
->mcast_grp
= mcast_grp
;
5978 vpn
->svi_ifindex
= svi_ifindex
;
5980 /* Initialize route-target import and export lists */
5981 vpn
->import_rtl
= list_new();
5982 vpn
->import_rtl
->cmp
=
5983 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
5984 vpn
->import_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
5985 vpn
->export_rtl
= list_new();
5986 vpn
->export_rtl
->cmp
=
5987 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
5988 vpn
->export_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
5989 bf_assign_index(bm
->rd_idspace
, vpn
->rd_id
);
5990 derive_rd_rt_for_vni(bgp
, vpn
);
5992 /* Initialize EVPN route tables. */
5993 vpn
->ip_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
5994 vpn
->mac_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
5997 (void)hash_get(bgp
->vnihash
, vpn
, hash_alloc_intern
);
5999 bgp_evpn_remote_ip_hash_init(vpn
);
6000 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6002 /* add to l2vni list on corresponding vrf */
6003 bgpevpn_link_to_l3vni(vpn
);
6005 bgp_evpn_vni_es_init(vpn
);
6007 QOBJ_REG(vpn
, bgpevpn
);
6012 * Free a given VPN - called in multiple scenarios such as zebra
6013 * notification, configuration being deleted, advertise-all-vni disabled etc.
6014 * This just frees appropriate memory, caller should have taken other
6017 void bgp_evpn_free(struct bgp
*bgp
, struct bgpevpn
*vpn
)
6019 bgp_evpn_remote_ip_hash_destroy(vpn
);
6020 bgp_evpn_vni_es_cleanup(vpn
);
6021 bgpevpn_unlink_from_l3vni(vpn
);
6022 bgp_table_unlock(vpn
->ip_table
);
6023 bgp_table_unlock(vpn
->mac_table
);
6024 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
6025 list_delete(&vpn
->import_rtl
);
6026 list_delete(&vpn
->export_rtl
);
6027 bf_release_index(bm
->rd_idspace
, vpn
->rd_id
);
6028 hash_release(bgp
->vni_svi_hash
, vpn
);
6029 hash_release(bgp
->vnihash
, vpn
);
6030 if (vpn
->prd_pretty
)
6031 XFREE(MTYPE_BGP
, vpn
->prd_pretty
);
6033 XFREE(MTYPE_BGP_EVPN
, vpn
);
6036 static void hash_evpn_free(struct bgpevpn
*vpn
)
6038 XFREE(MTYPE_BGP_EVPN
, vpn
);
6042 * Import evpn route from global table to VNI/VRF/ESI.
6044 int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6045 const struct prefix
*p
, struct bgp_path_info
*pi
)
6047 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 1);
6051 * Unimport evpn route from VNI/VRF/ESI.
6053 int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6054 const struct prefix
*p
, struct bgp_path_info
*pi
)
6056 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 0);
6059 /* filter routes which have martian next hops */
6060 int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
)
6064 struct bgp_dest
*rd_dest
, *dest
;
6065 struct bgp_table
*table
;
6066 struct bgp_path_info
*pi
;
6071 /* Walk entire global routing table and evaluate routes which could be
6072 * imported into this VPN. Note that we cannot just look at the routes
6073 * for the VNI's RD -
6074 * remote routes applicable for this VNI could have any RD.
6076 /* EVPN routes are a 2-level table. */
6077 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
6078 rd_dest
= bgp_route_next(rd_dest
)) {
6079 table
= bgp_dest_get_bgp_table_info(rd_dest
);
6083 for (dest
= bgp_table_top(table
); dest
;
6084 dest
= bgp_route_next(dest
)) {
6086 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
6089 /* Consider "valid" remote routes applicable for
6091 if (!(pi
->type
== ZEBRA_ROUTE_BGP
6092 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
6094 if (bgp_nexthop_self(bgp
, afi
, pi
->type
,
6095 pi
->sub_type
, pi
->attr
,
6097 const struct prefix
*p
=
6098 bgp_dest_get_prefix(dest
);
6100 if (bgp_debug_update(pi
->peer
, p
, NULL
,
6102 char attr_str
[BUFSIZ
] = {0};
6104 bgp_dump_attr(pi
->attr
,
6109 "%u: prefix %pBD with attr %s - DENIED due to martian or self nexthop",
6113 bgp_evpn_unimport_route(bgp
, afi
, safi
,
6116 bgp_rib_remove(dest
, pi
, pi
->peer
, afi
,
6127 * Handle del of a local MACIP.
6129 int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6130 struct ipaddr
*ip
, int state
)
6132 struct bgpevpn
*vpn
;
6133 struct prefix_evpn p
;
6134 struct bgp_dest
*dest
;
6136 /* Lookup VNI hash - should exist. */
6137 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6138 if (!vpn
|| !is_vni_live(vpn
)) {
6139 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6140 "%u: VNI hash entry for VNI %u %s at MACIP DEL",
6141 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6145 build_evpn_type2_prefix(&p
, mac
, ip
);
6146 if (state
== ZEBRA_NEIGH_ACTIVE
) {
6147 /* Remove EVPN type-2 route and schedule for processing. */
6148 delete_evpn_route(bgp
, vpn
, &p
);
6150 /* Re-instate the current remote best path if any */
6151 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
6153 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
6154 bgp_dest_unlock_node(dest
);
6162 * Handle add of a local MACIP.
6164 int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6165 struct ipaddr
*ip
, uint8_t flags
, uint32_t seq
, esi_t
*esi
)
6167 struct bgpevpn
*vpn
;
6168 struct prefix_evpn p
;
6170 /* Lookup VNI hash - should exist. */
6171 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6172 if (!vpn
|| !is_vni_live(vpn
)) {
6173 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6174 "%u: VNI hash entry for VNI %u %s at MACIP ADD",
6175 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6179 /* Create EVPN type-2 route and schedule for processing. */
6180 build_evpn_type2_prefix(&p
, mac
, ip
);
6181 if (update_evpn_route(bgp
, vpn
, &p
, flags
, seq
, esi
)) {
6183 EC_BGP_EVPN_ROUTE_CREATE
,
6184 "%u:Failed to create Type-2 route, VNI %u %s MAC %pEA IP %pIA (flags: 0x%x)",
6185 bgp
->vrf_id
, vpn
->vni
,
6186 CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
)
6196 static void link_l2vni_hash_to_l3vni(struct hash_bucket
*bucket
,
6197 struct bgp
*bgp_vrf
)
6199 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6200 struct bgp
*bgp_evpn
= NULL
;
6202 bgp_evpn
= bgp_get_evpn();
6205 if (vpn
->tenant_vrf_id
== bgp_vrf
->vrf_id
)
6206 bgpevpn_link_to_l3vni(vpn
);
6209 int bgp_evpn_local_l3vni_add(vni_t l3vni
, vrf_id_t vrf_id
,
6210 struct ethaddr
*svi_rmac
,
6211 struct ethaddr
*vrr_rmac
,
6212 struct in_addr originator_ip
, int filter
,
6213 ifindex_t svi_ifindex
,
6214 bool is_anycast_mac
)
6216 struct bgp
*bgp_vrf
= NULL
; /* bgp VRF instance */
6217 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6218 struct listnode
*node
= NULL
;
6219 struct bgpevpn
*vpn
= NULL
;
6222 /* get the EVPN instance - required to get the AS number for VRF
6225 bgp_evpn
= bgp_get_evpn();
6229 "Cannot process L3VNI %u ADD - EVPN BGP instance not yet created",
6234 if (CHECK_FLAG(bgp_evpn
->flags
, BGP_FLAG_DELETE_IN_PROGRESS
)) {
6235 flog_err(EC_BGP_NO_DFLT
,
6236 "Cannot process L3VNI %u ADD - EVPN BGP instance is shutting down",
6243 /* if the BGP vrf instance doesn't exist - create one */
6244 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6249 ret
= bgp_get_vty(&bgp_vrf
, &as
, vrf_id_to_name(vrf_id
),
6250 vrf_id
== VRF_DEFAULT
6251 ? BGP_INSTANCE_TYPE_DEFAULT
6252 : BGP_INSTANCE_TYPE_VRF
,
6253 NULL
, ASNOTATION_UNDEFINED
);
6255 case BGP_ERR_AS_MISMATCH
:
6256 flog_err(EC_BGP_EVPN_AS_MISMATCH
,
6257 "BGP instance is already running; AS is %s",
6258 bgp_vrf
->as_pretty
);
6260 case BGP_ERR_INSTANCE_MISMATCH
:
6261 flog_err(EC_BGP_EVPN_INSTANCE_MISMATCH
,
6262 "BGP instance type mismatch");
6266 /* mark as auto created */
6267 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
);
6270 /* associate the vrf with l3vni and related parameters */
6271 bgp_vrf
->l3vni
= l3vni
;
6272 bgp_vrf
->originator_ip
= originator_ip
;
6273 bgp_vrf
->l3vni_svi_ifindex
= svi_ifindex
;
6274 bgp_vrf
->evpn_info
->is_anycast_mac
= is_anycast_mac
;
6276 /* copy anycast MAC from VRR MAC */
6277 memcpy(&bgp_vrf
->rmac
, vrr_rmac
, ETH_ALEN
);
6278 /* copy sys RMAC from SVI MAC */
6279 memcpy(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, svi_rmac
, ETH_ALEN
);
6280 /* PIP user configured mac is not present use svi mac as sys mac */
6281 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
))
6282 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
, svi_rmac
, ETH_ALEN
);
6284 if (bgp_debug_zebra(NULL
))
6286 "VRF %s vni %u pip %s RMAC %pEA sys RMAC %pEA static RMAC %pEA is_anycast_mac %s",
6287 vrf_id_to_name(bgp_vrf
->vrf_id
), bgp_vrf
->l3vni
,
6288 bgp_vrf
->evpn_info
->advertise_pip
? "enable"
6290 &bgp_vrf
->rmac
, &bgp_vrf
->evpn_info
->pip_rmac
,
6291 &bgp_vrf
->evpn_info
->pip_rmac_static
,
6292 is_anycast_mac
? "Enable" : "Disable");
6294 /* set the right filter - are we using l3vni only for prefix routes? */
6296 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6299 * VNI_FLAG_USE_TWO_LABELS flag for linked L2VNIs should not be
6300 * set before linking vrf to L3VNI. Thus, no need to clear
6304 UNSET_FLAG(bgp_vrf
->vrf_flags
,
6305 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6307 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6308 if (!CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
6311 * If we are flapping VNI_FLAG_USE_TWO_LABELS
6312 * flag, update all MACIP routes in this VNI
6314 SET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6315 update_all_type2_routes(bgp_evpn
, vpn
);
6320 /* Map auto derive or configured RTs */
6321 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
) ||
6322 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
6323 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
6325 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
6327 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
) ||
6328 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
6329 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
6331 /* auto derive RD */
6332 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
6334 /* link all corresponding l2vnis */
6335 hash_iterate(bgp_evpn
->vnihash
,
6336 (void (*)(struct hash_bucket
*,
6337 void *))link_l2vni_hash_to_l3vni
,
6340 /* Only update all corresponding type-2 routes if we are advertising two
6341 * labels along with type-2 routes
6344 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
6345 update_routes_for_vni(bgp_evpn
, vpn
);
6347 /* advertise type-5 routes if needed */
6348 update_advertise_vrf_routes(bgp_vrf
);
6350 /* install all remote routes belonging to this l3vni into correspondng
6352 install_routes_for_vrf(bgp_vrf
);
6357 int bgp_evpn_local_l3vni_del(vni_t l3vni
, vrf_id_t vrf_id
)
6359 struct bgp
*bgp_vrf
= NULL
; /* bgp vrf instance */
6360 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6361 struct listnode
*node
= NULL
;
6362 struct listnode
*next
= NULL
;
6363 struct bgpevpn
*vpn
= NULL
;
6365 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6369 "Cannot process L3VNI %u Del - Could not find BGP instance",
6374 bgp_evpn
= bgp_get_evpn();
6378 "Cannot process L3VNI %u Del - Could not find EVPN BGP instance",
6383 if (CHECK_FLAG(bgp_evpn
->flags
, BGP_FLAG_DELETE_IN_PROGRESS
)) {
6384 flog_err(EC_BGP_NO_DFLT
,
6385 "Cannot process L3VNI %u ADD - EVPN BGP instance is shutting down",
6390 /* Remove remote routes from BGT VRF even if BGP_VRF_AUTO is configured,
6391 * bgp_delete would not remove/decrement bgp_path_info of the ip_prefix
6392 * routes. This will uninstalling the routes from zebra and decremnt the
6395 uninstall_routes_for_vrf(bgp_vrf
);
6397 /* delete/withdraw all type-5 routes */
6398 delete_withdraw_vrf_routes(bgp_vrf
);
6400 /* remove the l3vni from vrf instance */
6403 /* remove the Rmac from the BGP vrf */
6404 memset(&bgp_vrf
->rmac
, 0, sizeof(struct ethaddr
));
6405 memset(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, 0, ETH_ALEN
);
6406 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
) &&
6407 !is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac
))
6408 memset(&bgp_vrf
->evpn_info
->pip_rmac
, 0, ETH_ALEN
);
6410 /* remove default import RT or Unmap non-default import RT */
6411 if (!list_isempty(bgp_vrf
->vrf_import_rtl
)) {
6412 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6413 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
6414 list_delete_all_node(bgp_vrf
->vrf_import_rtl
);
6417 /* remove default export RT */
6418 if (!list_isempty(bgp_vrf
->vrf_export_rtl
) &&
6419 !CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
6420 list_delete_all_node(bgp_vrf
->vrf_export_rtl
);
6423 /* update all corresponding local mac-ip routes */
6424 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)) {
6425 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6426 UNSET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6427 update_routes_for_vni(bgp_evpn
, vpn
);
6431 /* If any L2VNIs point to this instance, unlink them. */
6432 for (ALL_LIST_ELEMENTS(bgp_vrf
->l2vnis
, node
, next
, vpn
))
6433 bgpevpn_unlink_from_l3vni(vpn
);
6435 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6437 /* Delete the instance if it was autocreated */
6438 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
))
6439 bgp_delete(bgp_vrf
);
6445 * Handle del of a local VNI.
6447 int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
)
6449 struct bgpevpn
*vpn
;
6451 /* Locate VNI hash */
6452 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6456 /* Remove all local EVPN routes and schedule for processing (to
6457 * withdraw from peers).
6459 delete_routes_for_vni(bgp
, vpn
);
6461 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6463 vpn
->svi_ifindex
= 0;
6465 * tunnel is no longer active, del tunnel ip address from tip_hash
6467 bgp_tip_del(bgp
, &vpn
->originator_ip
);
6469 /* Clear "live" flag and see if hash needs to be freed. */
6470 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6471 if (!is_vni_configured(vpn
))
6472 bgp_evpn_free(bgp
, vpn
);
6478 * Handle add (or update) of a local VNI. The VNI changes we care
6479 * about are for the local-tunnel-ip and the (tenant) VRF.
6481 int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
6482 struct in_addr originator_ip
,
6483 vrf_id_t tenant_vrf_id
,
6484 struct in_addr mcast_grp
,
6485 ifindex_t svi_ifindex
)
6487 struct bgpevpn
*vpn
;
6488 struct prefix_evpn p
;
6490 /* Lookup VNI. If present and no change, exit. */
6491 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6494 if (is_vni_live(vpn
)
6495 && IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
)
6496 && IPV4_ADDR_SAME(&vpn
->mcast_grp
, &mcast_grp
)
6497 && vpn
->tenant_vrf_id
== tenant_vrf_id
6498 && vpn
->svi_ifindex
== svi_ifindex
)
6499 /* Probably some other param has changed that we don't
6503 bgp_evpn_mcast_grp_change(bgp
, vpn
, mcast_grp
);
6505 if (vpn
->svi_ifindex
!= svi_ifindex
) {
6508 * Unresolve all the gateway IP nexthops for this VNI
6511 bgp_evpn_remote_ip_hash_iterate(
6513 (void (*)(struct hash_bucket
*, void *))
6514 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6516 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6517 vpn
->svi_ifindex
= svi_ifindex
;
6518 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6521 * Resolve all the gateway IP nexthops for this VNI
6524 bgp_evpn_remote_ip_hash_iterate(
6526 (void (*)(struct hash_bucket
*, void *))
6527 bgp_evpn_remote_ip_hash_link_nexthop
,
6531 /* Update tenant_vrf_id if it has changed. */
6532 if (vpn
->tenant_vrf_id
!= tenant_vrf_id
) {
6535 * Unresolve all the gateway IP nexthops for this VNI
6538 bgp_evpn_remote_ip_hash_iterate(
6540 (void (*)(struct hash_bucket
*, void *))
6541 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6543 bgpevpn_unlink_from_l3vni(vpn
);
6544 vpn
->tenant_vrf_id
= tenant_vrf_id
;
6545 bgpevpn_link_to_l3vni(vpn
);
6548 * Resolve all the gateway IP nexthops for this VNI
6551 bgp_evpn_remote_ip_hash_iterate(
6553 (void (*)(struct hash_bucket
*, void *))
6554 bgp_evpn_remote_ip_hash_link_nexthop
,
6558 /* If tunnel endpoint IP has changed, update (and delete prior
6559 * type-3 route, if needed.)
6561 handle_tunnel_ip_change(bgp
, vpn
, originator_ip
);
6563 /* Update all routes with new endpoint IP and/or export RT
6566 if (is_vni_live(vpn
))
6567 update_routes_for_vni(bgp
, vpn
);
6569 /* Create or update as appropriate. */
6570 vpn
= bgp_evpn_new(bgp
, vni
, originator_ip
, tenant_vrf_id
,
6571 mcast_grp
, svi_ifindex
);
6574 /* if the VNI is live already, there is nothing more to do */
6575 if (is_vni_live(vpn
))
6578 /* Mark as "live" */
6579 SET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6581 /* tunnel is now active, add tunnel-ip to db */
6582 if (bgp_tip_add(bgp
, &originator_ip
))
6583 /* The originator_ip was not already present in the
6584 * bgp martian next-hop table as a tunnel-ip, so we
6585 * need to go back and filter routes matching the new
6588 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
6591 * Create EVPN type-3 route and schedule for processing.
6593 * RT-3 only if doing head-end replication
6595 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
6596 == VXLAN_FLOOD_HEAD_END_REPL
) {
6597 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
6598 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
)) {
6599 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
6600 "%u: Type3 route creation failure for VNI %u",
6606 /* If we have learnt and retained remote routes (VTEPs, MACs) for this
6610 install_routes_for_vni(bgp
, vpn
);
6612 /* If we are advertising gateway mac-ip
6613 It needs to be conveyed again to zebra */
6614 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
, vpn
->vni
);
6616 /* advertise svi mac-ip knob to zebra */
6617 bgp_zebra_advertise_svi_macip(bgp
, vpn
->advertise_svi_macip
, vpn
->vni
);
6623 * Handle change in setting for BUM handling. The supported values
6624 * are head-end replication and dropping all BUM packets. Any change
6625 * should be registered with zebra. Also, if doing head-end replication,
6626 * need to advertise local VNIs as EVPN RT-3 wheras, if BUM packets are
6627 * to be dropped, the RT-3s must be withdrawn.
6629 void bgp_evpn_flood_control_change(struct bgp
*bgp
)
6631 zlog_info("L2VPN EVPN BUM handling is %s",
6632 bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
?
6633 "Flooding" : "Flooding Disabled");
6635 bgp_zebra_vxlan_flood_control(bgp
, bgp
->vxlan_flood_ctrl
);
6636 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
)
6637 hash_iterate(bgp
->vnihash
, create_advertise_type3
, bgp
);
6638 else if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
6639 hash_iterate(bgp
->vnihash
, delete_withdraw_type3
, bgp
);
6643 * Cleanup EVPN information on disable - Need to delete and withdraw
6644 * EVPN routes from peers.
6646 void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
)
6648 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_bucket
*,
6649 void *))cleanup_vni_on_disable
,
6654 * Cleanup EVPN information - invoked at the time of bgpd exit or when the
6655 * BGP instance (default) is being freed.
6657 void bgp_evpn_cleanup(struct bgp
*bgp
)
6659 hash_iterate(bgp
->vnihash
,
6660 (void (*)(struct hash_bucket
*, void *))free_vni_entry
,
6663 hash_clean_and_free(&bgp
->import_rt_hash
,
6664 (void (*)(void *))hash_import_rt_free
);
6666 hash_clean_and_free(&bgp
->vrf_import_rt_hash
,
6667 (void (*)(void *))hash_vrf_import_rt_free
);
6669 hash_clean_and_free(&bgp
->vni_svi_hash
,
6670 (void (*)(void *))hash_evpn_free
);
6673 * Why is the vnihash freed at the top of this function and
6674 * then deleted here?
6676 hash_clean_and_free(&bgp
->vnihash
, NULL
);
6678 list_delete(&bgp
->vrf_import_rtl
);
6679 list_delete(&bgp
->vrf_export_rtl
);
6680 list_delete(&bgp
->l2vnis
);
6682 if (bgp
->vrf_prd_pretty
)
6683 XFREE(MTYPE_BGP
, bgp
->vrf_prd_pretty
);
6687 * Initialization for EVPN
6690 * hash for RT to VNI
6692 void bgp_evpn_init(struct bgp
*bgp
)
6695 hash_create(vni_hash_key_make
, vni_hash_cmp
, "BGP VNI Hash");
6697 hash_create(vni_svi_hash_key_make
, vni_svi_hash_cmp
,
6698 "BGP VNI hash based on SVI ifindex");
6699 bgp
->import_rt_hash
=
6700 hash_create(import_rt_hash_key_make
, import_rt_hash_cmp
,
6701 "BGP Import RT Hash");
6702 bgp
->vrf_import_rt_hash
=
6703 hash_create(vrf_import_rt_hash_key_make
, vrf_import_rt_hash_cmp
,
6704 "BGP VRF Import RT Hash");
6705 bgp
->vrf_import_rtl
= list_new();
6706 bgp
->vrf_import_rtl
->cmp
=
6707 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6708 bgp
->vrf_import_rtl
->del
= evpn_vrf_rt_del
;
6709 bgp
->vrf_export_rtl
= list_new();
6710 bgp
->vrf_export_rtl
->cmp
=
6711 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6712 bgp
->vrf_export_rtl
->del
= evpn_vrf_rt_del
;
6713 bgp
->l2vnis
= list_new();
6714 bgp
->l2vnis
->cmp
= vni_list_cmp
;
6715 /* By default Duplicate Address Dection is enabled.
6716 * Max-moves (N) 5, detection time (M) 180
6717 * default action is warning-only
6718 * freeze action permanently freezes address,
6719 * and freeze time (auto-recovery) is disabled.
6721 if (bgp
->evpn_info
) {
6722 bgp
->evpn_info
->dup_addr_detect
= true;
6723 bgp
->evpn_info
->dad_time
= EVPN_DAD_DEFAULT_TIME
;
6724 bgp
->evpn_info
->dad_max_moves
= EVPN_DAD_DEFAULT_MAX_MOVES
;
6725 bgp
->evpn_info
->dad_freeze
= false;
6726 bgp
->evpn_info
->dad_freeze_time
= 0;
6727 /* Initialize zebra vxlan */
6728 bgp_zebra_dup_addr_detection(bgp
);
6729 /* Enable PIP feature by default for bgp vrf instance */
6730 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
6731 struct bgp
*bgp_default
;
6733 bgp
->evpn_info
->advertise_pip
= true;
6734 bgp_default
= bgp_get_default();
6736 bgp
->evpn_info
->pip_ip
= bgp_default
->router_id
;
6740 /* Default BUM handling is to do head-end replication. */
6741 bgp
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6743 bgp_evpn_nh_init(bgp
);
6746 void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
)
6748 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6749 bgp_evpn_nh_finish(bgp_vrf
);
6753 * Get the prefixlen of the ip prefix carried within the type5 evpn route.
6755 int bgp_evpn_get_type5_prefixlen(const struct prefix
*pfx
)
6757 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6759 if (!pfx
|| pfx
->family
!= AF_EVPN
)
6762 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
6765 return evp
->prefix
.prefix_addr
.ip_prefix_length
;
6769 * Should we register nexthop for this EVPN prefix for nexthop tracking?
6771 bool bgp_evpn_is_prefix_nht_supported(const struct prefix
*pfx
)
6773 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6776 * EVPN routes should be marked as valid only if the nexthop is
6777 * reachable. Only if this happens, the route should be imported
6778 * (into VNI or VRF routing tables) and/or advertised.
6779 * Note: This is currently applied for EVPN type-1, type-2,
6780 * type-3, type-4 and type-5 routes.
6781 * It may be tweaked later on for other routes, or
6782 * even removed completely when all routes are handled.
6784 if (pfx
&& pfx
->family
== AF_EVPN
6785 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
6786 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
6787 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
6788 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
6789 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
6795 static void *bgp_evpn_remote_ip_hash_alloc(void *p
)
6797 const struct evpn_remote_ip
*key
= (const struct evpn_remote_ip
*)p
;
6798 struct evpn_remote_ip
*ip
;
6800 ip
= XMALLOC(MTYPE_EVPN_REMOTE_IP
, sizeof(struct evpn_remote_ip
));
6802 ip
->macip_path_list
= list_new();
6807 static unsigned int bgp_evpn_remote_ip_hash_key_make(const void *p
)
6809 const struct evpn_remote_ip
*ip
= p
;
6810 const struct ipaddr
*addr
= &ip
->addr
;
6812 if (IS_IPADDR_V4(addr
))
6813 return jhash_1word(addr
->ipaddr_v4
.s_addr
, 0);
6815 return jhash2(addr
->ipaddr_v6
.s6_addr32
,
6816 array_size(addr
->ipaddr_v6
.s6_addr32
), 0);
6819 static bool bgp_evpn_remote_ip_hash_cmp(const void *p1
, const void *p2
)
6821 const struct evpn_remote_ip
*ip1
= p1
;
6822 const struct evpn_remote_ip
*ip2
= p2
;
6824 return !ipaddr_cmp(&ip1
->addr
, &ip2
->addr
);
6827 static void bgp_evpn_remote_ip_hash_init(struct bgpevpn
*vpn
)
6829 if (!evpn_resolve_overlay_index())
6832 vpn
->remote_ip_hash
= hash_create(bgp_evpn_remote_ip_hash_key_make
,
6833 bgp_evpn_remote_ip_hash_cmp
,
6834 "BGP EVPN remote IP hash");
6837 static void bgp_evpn_remote_ip_hash_free(struct hash_bucket
*bucket
, void *args
)
6839 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6840 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6842 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6844 list_delete(&ip
->macip_path_list
);
6846 hash_release(vpn
->remote_ip_hash
, ip
);
6847 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6850 static void bgp_evpn_remote_ip_hash_destroy(struct bgpevpn
*vpn
)
6852 if (!evpn_resolve_overlay_index() || vpn
->remote_ip_hash
== NULL
)
6855 hash_iterate(vpn
->remote_ip_hash
,
6856 (void (*)(struct hash_bucket
*, void *))bgp_evpn_remote_ip_hash_free
,
6859 hash_free(vpn
->remote_ip_hash
);
6860 vpn
->remote_ip_hash
= NULL
;
6863 /* Add a remote MAC/IP route to hash table */
6864 static void bgp_evpn_remote_ip_hash_add(struct bgpevpn
*vpn
,
6865 struct bgp_path_info
*pi
)
6867 struct evpn_remote_ip tmp
;
6868 struct evpn_remote_ip
*ip
;
6869 struct prefix_evpn
*evp
;
6871 if (!evpn_resolve_overlay_index())
6874 if (pi
->type
!= ZEBRA_ROUTE_BGP
|| pi
->sub_type
!= BGP_ROUTE_IMPORTED
6875 || !CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
))
6878 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6880 if (evp
->family
!= AF_EVPN
6881 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6882 || is_evpn_prefix_ipaddr_none(evp
))
6885 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6886 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6888 if (listnode_lookup(ip
->macip_path_list
, pi
) != NULL
)
6890 (void)listnode_add(ip
->macip_path_list
, pi
);
6894 ip
= hash_get(vpn
->remote_ip_hash
, &tmp
, bgp_evpn_remote_ip_hash_alloc
);
6895 (void)listnode_add(ip
->macip_path_list
, pi
);
6897 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6900 /* Delete a remote MAC/IP route from hash table */
6901 static void bgp_evpn_remote_ip_hash_del(struct bgpevpn
*vpn
,
6902 struct bgp_path_info
*pi
)
6904 struct evpn_remote_ip tmp
;
6905 struct evpn_remote_ip
*ip
;
6906 struct prefix_evpn
*evp
;
6908 if (!evpn_resolve_overlay_index())
6911 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6913 if (evp
->family
!= AF_EVPN
6914 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6915 || is_evpn_prefix_ipaddr_none(evp
))
6918 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6919 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6923 listnode_delete(ip
->macip_path_list
, pi
);
6925 if (ip
->macip_path_list
->count
== 0) {
6926 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6927 hash_release(vpn
->remote_ip_hash
, ip
);
6928 list_delete(&ip
->macip_path_list
);
6929 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6933 static void bgp_evpn_remote_ip_hash_iterate(struct bgpevpn
*vpn
,
6934 void (*func
)(struct hash_bucket
*,
6938 if (!evpn_resolve_overlay_index())
6941 hash_iterate(vpn
->remote_ip_hash
, func
, arg
);
6944 static void show_remote_ip_entry(struct hash_bucket
*bucket
, void *args
)
6946 char buf
[INET6_ADDRSTRLEN
];
6947 struct listnode
*node
= NULL
;
6948 struct bgp_path_info
*pi
= NULL
;
6949 struct vty
*vty
= (struct vty
*)args
;
6950 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6952 vty_out(vty
, " Remote IP: %s\n",
6953 ipaddr2str(&ip
->addr
, buf
, sizeof(buf
)));
6954 vty_out(vty
, " Linked MAC/IP routes:\n");
6955 for (ALL_LIST_ELEMENTS_RO(ip
->macip_path_list
, node
, pi
))
6956 vty_out(vty
, " %pFX\n", &pi
->net
->p
);
6959 void bgp_evpn_show_remote_ip_hash(struct hash_bucket
*bucket
, void *args
)
6961 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6962 struct vty
*vty
= (struct vty
*)args
;
6964 vty_out(vty
, "VNI: %u\n", vpn
->vni
);
6965 bgp_evpn_remote_ip_hash_iterate(
6967 (void (*)(struct hash_bucket
*, void *))show_remote_ip_entry
,
6972 static void bgp_evpn_remote_ip_hash_link_nexthop(struct hash_bucket
*bucket
,
6975 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6976 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6978 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6981 static void bgp_evpn_remote_ip_hash_unlink_nexthop(struct hash_bucket
*bucket
,
6984 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6985 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6987 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6990 static unsigned int vni_svi_hash_key_make(const void *p
)
6992 const struct bgpevpn
*vpn
= p
;
6994 return jhash_1word(vpn
->svi_ifindex
, 0);
6997 static bool vni_svi_hash_cmp(const void *p1
, const void *p2
)
6999 const struct bgpevpn
*vpn1
= p1
;
7000 const struct bgpevpn
*vpn2
= p2
;
7002 return (vpn1
->svi_ifindex
== vpn2
->svi_ifindex
);
7005 static struct bgpevpn
*bgp_evpn_vni_svi_hash_lookup(struct bgp
*bgp
,
7008 struct bgpevpn
*vpn
;
7011 memset(&tmp
, 0, sizeof(tmp
));
7012 tmp
.svi_ifindex
= svi
;
7013 vpn
= hash_lookup(bgp
->vni_svi_hash
, &tmp
);
7017 static void bgp_evpn_link_to_vni_svi_hash(struct bgp
*bgp
, struct bgpevpn
*vpn
)
7019 if (vpn
->svi_ifindex
== 0)
7022 (void)hash_get(bgp
->vni_svi_hash
, vpn
, hash_alloc_intern
);
7025 static void bgp_evpn_unlink_from_vni_svi_hash(struct bgp
*bgp
,
7026 struct bgpevpn
*vpn
)
7028 if (vpn
->svi_ifindex
== 0)
7031 hash_release(bgp
->vni_svi_hash
, vpn
);
7034 void bgp_evpn_show_vni_svi_hash(struct hash_bucket
*bucket
, void *args
)
7036 struct bgpevpn
*evpn
= (struct bgpevpn
*)bucket
->data
;
7037 struct vty
*vty
= (struct vty
*)args
;
7039 vty_out(vty
, "SVI: %u VNI: %u\n", evpn
->svi_ifindex
, evpn
->vni
);
7043 * This function is called for a bgp_nexthop_cache entry when the nexthop is
7044 * gateway IP overlay index.
7045 * This function returns true if there is a remote MAC/IP route for the gateway
7046 * IP in the EVI of the nexthop SVI.
7048 bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache
*bnc
)
7050 struct bgp
*bgp_evpn
= NULL
;
7051 struct bgpevpn
*vpn
= NULL
;
7052 struct evpn_remote_ip tmp
;
7055 if (!evpn_resolve_overlay_index())
7058 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
== 0)
7061 bgp_evpn
= bgp_get_evpn();
7066 * Gateway IP is resolved by nht over SVI interface.
7067 * Use this SVI to find corresponding EVI(L2 context)
7069 vpn
= bgp_evpn_vni_svi_hash_lookup(bgp_evpn
, bnc
->nexthop
->ifindex
);
7073 if (vpn
->bgp_vrf
!= bnc
->bgp
)
7077 * Check if the gateway IP is present in the EVI remote_ip_hash table
7078 * which stores all the remote IP addresses received via MAC/IP routes
7081 memset(&tmp
, 0, sizeof(tmp
));
7084 if (p
->family
== AF_INET
) {
7085 tmp
.addr
.ipa_type
= IPADDR_V4
;
7086 memcpy(&(tmp
.addr
.ipaddr_v4
), &(p
->u
.prefix4
),
7087 sizeof(struct in_addr
));
7088 } else if (p
->family
== AF_INET6
) {
7089 tmp
.addr
.ipa_type
= IPADDR_V6
;
7090 memcpy(&(tmp
.addr
.ipaddr_v6
), &(p
->u
.prefix6
),
7091 sizeof(struct in6_addr
));
7095 if (hash_lookup(vpn
->remote_ip_hash
, &tmp
) == NULL
)
7101 /* Resolve/Unresolve nexthops when a MAC/IP route is added/deleted */
7102 static void bgp_evpn_remote_ip_process_nexthops(struct bgpevpn
*vpn
,
7103 struct ipaddr
*addr
,
7108 struct bgp_nexthop_cache
*bnc
;
7109 struct bgp_nexthop_cache_head
*tree
= NULL
;
7111 if (!vpn
->bgp_vrf
|| vpn
->svi_ifindex
== 0)
7114 memset(&p
, 0, sizeof(p
));
7116 if (addr
->ipa_type
== IPADDR_V4
) {
7119 memcpy(&(p
.u
.prefix4
), &(addr
->ipaddr_v4
),
7120 sizeof(struct in_addr
));
7121 p
.prefixlen
= IPV4_MAX_BITLEN
;
7122 } else if (addr
->ipa_type
== IPADDR_V6
) {
7124 p
.family
= AF_INET6
;
7125 memcpy(&(p
.u
.prefix6
), &(addr
->ipaddr_v6
),
7126 sizeof(struct in6_addr
));
7127 p
.prefixlen
= IPV6_MAX_BITLEN
;
7131 tree
= &vpn
->bgp_vrf
->nexthop_cache_table
[afi
];
7132 bnc
= bnc_find(tree
, &p
, 0, 0);
7134 if (!bnc
|| !bnc
->is_evpn_gwip_nexthop
)
7137 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
!= vpn
->svi_ifindex
)
7140 if (BGP_DEBUG(nht
, NHT
))
7141 zlog_debug("%s(%u): vni %u mac/ip %s for NH %pFX",
7142 vpn
->bgp_vrf
->name_pretty
, vpn
->tenant_vrf_id
,
7143 vpn
->vni
, (resolve
? "add" : "delete"),
7147 * MAC/IP route or SVI or tenant vrf being added to EVI.
7148 * Set nexthop as valid only if it is already L3 reachable
7150 if (resolve
&& bnc
->flags
& BGP_NEXTHOP_EVPN_INCOMPLETE
) {
7151 bnc
->flags
&= ~BGP_NEXTHOP_EVPN_INCOMPLETE
;
7152 bnc
->flags
|= BGP_NEXTHOP_VALID
;
7153 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7154 evaluate_paths(bnc
);
7157 /* MAC/IP route or SVI or tenant vrf being deleted from EVI */
7158 if (!resolve
&& bnc
->flags
& BGP_NEXTHOP_VALID
) {
7159 bnc
->flags
&= ~BGP_NEXTHOP_VALID
;
7160 bnc
->flags
|= BGP_NEXTHOP_EVPN_INCOMPLETE
;
7161 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7162 evaluate_paths(bnc
);
7166 void bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket
*bucket
,
7169 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7170 struct bgp_dest
*dest
;
7171 struct bgp_path_info
*pi
;
7173 bgp_evpn_remote_ip_hash_init(vpn
);
7175 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
7176 dest
= bgp_route_next(dest
))
7177 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
7178 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
7181 void bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket
*bucket
,
7184 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7186 bgp_evpn_remote_ip_hash_destroy(vpn
);
7190 * Helper function for getting the correct label index for l3vni.
7192 * Returns the label with the l3vni of the path's label stack.
7194 * L3vni is always last label. Type5 will only
7195 * have one label, Type2 will have two.
7198 mpls_label_t
*bgp_evpn_path_info_labels_get_l3vni(mpls_label_t
*labels
,
7199 uint32_t num_labels
)
7207 return &labels
[num_labels
- 1];
7211 * Returns the l3vni of the path converted from the label stack.
7213 vni_t
bgp_evpn_path_info_get_l3vni(const struct bgp_path_info
*pi
)
7218 return label2vni(bgp_evpn_path_info_labels_get_l3vni(
7219 pi
->extra
->label
, pi
->extra
->num_labels
));
7223 * Returns true if the l3vni of any of this path doesn't match vrf's l3vni.
7225 static bool bgp_evpn_path_is_dvni(const struct bgp
*bgp_vrf
,
7226 const struct bgp_path_info
*pi
)
7230 vni
= bgp_evpn_path_info_get_l3vni(pi
);
7232 if ((vni
> 0) && (vni
!= bgp_vrf
->l3vni
))
7239 * Returns true if the l3vni of any of the mpath's doesn't match vrf's l3vni.
7241 bool bgp_evpn_mpath_has_dvni(const struct bgp
*bgp_vrf
,
7242 struct bgp_path_info
*mpinfo
)
7244 for (; mpinfo
; mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
7245 if (bgp_evpn_path_is_dvni(bgp_vrf
, mpinfo
))