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
);
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.
678 bgp_evpn_global_node_lookup(struct bgp_table
*table
, afi_t afi
, safi_t safi
,
679 const struct prefix_evpn
*evp
,
680 struct prefix_rd
*prd
,
681 const struct bgp_path_info
*local_pi
)
683 struct prefix_evpn global_p
;
685 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
686 /* prefix in the global table doesn't include the VTEP-IP so
687 * we need to create a different copy of the prefix
689 evpn_type1_prefix_global_copy(&global_p
, evp
);
691 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
694 * prefix in the global table needs MAC/IP, ensure they are
695 * present, using one's from local table's path_info.
697 if (is_evpn_prefix_ipaddr_none(evp
)) {
698 /* VNI MAC -> Global */
699 evpn_type2_prefix_global_copy(
700 &global_p
, evp
, NULL
/* mac */,
701 evpn_type2_path_info_get_ip(local_pi
));
703 /* VNI IP -> Global */
704 evpn_type2_prefix_global_copy(
706 evpn_type2_path_info_get_mac(local_pi
),
712 return bgp_afi_node_lookup(table
, afi
, safi
, (struct prefix
*)evp
, prd
);
716 * Wrapper for node get in VNI IP table.
718 struct bgp_dest
*bgp_evpn_vni_ip_node_get(struct bgp_table
*const table
,
719 const struct prefix_evpn
*evp
,
720 const struct bgp_path_info
*parent_pi
)
722 struct prefix_evpn vni_p
;
724 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
725 /* prefix in the global table doesn't include the VTEP-IP so
726 * we need to create a different copy for the VNI
728 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
729 parent_pi
->attr
->nexthop
);
731 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
732 /* Only MAC-IP should go into this table, not mac-only */
733 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
736 * prefix in the vni IP table doesn't include MAC so
737 * we need to create a different copy of the prefix.
739 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
742 return bgp_node_get(table
, (struct prefix
*)evp
);
746 * Wrapper for node lookup in VNI IP table.
749 bgp_evpn_vni_ip_node_lookup(const struct bgp_table
*const table
,
750 const struct prefix_evpn
*evp
,
751 const struct bgp_path_info
*parent_pi
)
753 struct prefix_evpn vni_p
;
755 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
756 /* prefix in the global table doesn't include the VTEP-IP so
757 * we need to create a different copy for the VNI
759 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
760 parent_pi
->attr
->nexthop
);
762 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
763 /* Only MAC-IP should go into this table, not mac-only */
764 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
767 * prefix in the vni IP table doesn't include MAC so
768 * we need to create a different copy of the prefix.
770 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
773 return bgp_node_lookup(table
, (struct prefix
*)evp
);
777 * Wrapper for node get in VNI MAC table.
780 bgp_evpn_vni_mac_node_get(struct bgp_table
*const table
,
781 const struct prefix_evpn
*evp
,
782 const struct bgp_path_info
*parent_pi
)
784 struct prefix_evpn vni_p
;
786 /* Only type-2 should ever go into this table */
787 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
790 * prefix in the vni MAC table doesn't include IP so
791 * we need to create a different copy of the prefix.
793 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
795 return bgp_node_get(table
, (struct prefix
*)evp
);
799 * Wrapper for node lookup in VNI MAC table.
802 bgp_evpn_vni_mac_node_lookup(const struct bgp_table
*const table
,
803 const struct prefix_evpn
*evp
,
804 const struct bgp_path_info
*parent_pi
)
806 struct prefix_evpn vni_p
;
808 /* Only type-2 should ever go into this table */
809 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
812 * prefix in the vni MAC table doesn't include IP so
813 * we need to create a different copy of the prefix.
815 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
817 return bgp_node_lookup(table
, (struct prefix
*)evp
);
821 * Wrapper for node get in both VNI tables.
823 struct bgp_dest
*bgp_evpn_vni_node_get(struct bgpevpn
*vpn
,
824 const struct prefix_evpn
*p
,
825 const struct bgp_path_info
*parent_pi
)
827 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
828 (is_evpn_prefix_ipaddr_none(p
) == true))
829 return bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
831 return bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
835 * Wrapper for node lookup in both VNI tables.
837 struct bgp_dest
*bgp_evpn_vni_node_lookup(const struct bgpevpn
*vpn
,
838 const struct prefix_evpn
*p
,
839 const struct bgp_path_info
*parent_pi
)
841 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
842 (is_evpn_prefix_ipaddr_none(p
) == true))
843 return bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
,
846 return bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
850 * Add (update) or delete MACIP from zebra.
852 static int bgp_zebra_send_remote_macip(struct bgp
*bgp
, struct bgpevpn
*vpn
,
853 const struct prefix_evpn
*p
,
854 const struct ethaddr
*mac
,
855 struct in_addr remote_vtep_ip
, int add
,
856 uint8_t flags
, uint32_t seq
, esi_t
*esi
)
860 static struct in_addr zero_remote_vtep_ip
;
864 if (!zclient
|| zclient
->sock
< 0)
867 /* Don't try to register if Zebra doesn't know of this instance. */
868 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
869 if (BGP_DEBUG(zebra
, ZEBRA
))
871 "%s: No zebra instance to talk to, not installing remote macip",
881 zclient_create_header(
882 s
, add
? ZEBRA_REMOTE_MACIP_ADD
: ZEBRA_REMOTE_MACIP_DEL
,
884 stream_putl(s
, vpn
->vni
);
886 if (mac
) /* Mac Addr */
887 stream_put(s
, &mac
->octet
, ETH_ALEN
);
889 stream_put(s
, &p
->prefix
.macip_addr
.mac
.octet
, ETH_ALEN
);
891 /* IP address length and IP address, if any. */
892 if (is_evpn_prefix_ipaddr_none(p
))
895 ipa_len
= is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BYTELEN
897 stream_putw(s
, ipa_len
);
898 stream_put(s
, &p
->prefix
.macip_addr
.ip
.ip
.addr
, ipa_len
);
900 /* If the ESI is valid that becomes the nexthop; tape out the
901 * VTEP-IP for that case
903 if (bgp_evpn_is_esi_valid(esi
)) {
905 stream_put_in_addr(s
, &zero_remote_vtep_ip
);
908 stream_put_in_addr(s
, &remote_vtep_ip
);
911 /* TX flags - MAC sticky status and/or gateway mac */
912 /* Also TX the sequence number of the best route. */
914 stream_putc(s
, flags
);
916 stream_put(s
, esi
, sizeof(esi_t
));
919 stream_putw_at(s
, 0, stream_get_endp(s
));
921 if (bgp_debug_zebra(NULL
)) {
922 char esi_buf
[ESI_STR_LEN
];
925 esi_to_str(esi
, esi_buf
, sizeof(esi_buf
));
927 snprintf(esi_buf
, sizeof(esi_buf
), "-");
929 "Tx %s MACIP, VNI %u MAC %pEA IP %pIA flags 0x%x seq %u remote VTEP %pI4 esi %s",
930 add
? "ADD" : "DEL", vpn
->vni
,
931 (mac
? mac
: &p
->prefix
.macip_addr
.mac
),
932 &p
->prefix
.macip_addr
.ip
, flags
, seq
, &remote_vtep_ip
,
936 frrtrace(5, frr_bgp
, evpn_mac_ip_zsend
, add
, vpn
, p
, remote_vtep_ip
,
939 return zclient_send_message(zclient
);
943 * Add (update) or delete remote VTEP from zebra.
945 static int bgp_zebra_send_remote_vtep(struct bgp
*bgp
, struct bgpevpn
*vpn
,
946 const struct prefix_evpn
*p
,
947 int flood_control
, int add
)
952 if (!zclient
|| zclient
->sock
< 0)
955 /* Don't try to register if Zebra doesn't know of this instance. */
956 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
957 if (BGP_DEBUG(zebra
, ZEBRA
))
959 "%s: No zebra instance to talk to, not installing remote vtep",
967 zclient_create_header(
968 s
, add
? ZEBRA_REMOTE_VTEP_ADD
: ZEBRA_REMOTE_VTEP_DEL
,
970 stream_putl(s
, vpn
->vni
);
971 if (is_evpn_prefix_ipaddr_v4(p
))
972 stream_put_in_addr(s
, &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
973 else if (is_evpn_prefix_ipaddr_v6(p
)) {
976 "Bad remote IP when trying to %s remote VTEP for VNI %u",
977 add
? "ADD" : "DEL", vpn
->vni
);
980 stream_putl(s
, flood_control
);
982 stream_putw_at(s
, 0, stream_get_endp(s
));
984 if (bgp_debug_zebra(NULL
))
985 zlog_debug("Tx %s Remote VTEP, VNI %u remote VTEP %pI4",
986 add
? "ADD" : "DEL", vpn
->vni
,
987 &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
989 frrtrace(3, frr_bgp
, evpn_bum_vtep_zsend
, add
, vpn
, p
);
991 return zclient_send_message(zclient
);
995 * Build extended communities for EVPN prefix route.
997 static void build_evpn_type5_route_extcomm(struct bgp
*bgp_vrf
,
1000 struct ecommunity ecom_encap
;
1001 struct ecommunity_val eval
;
1002 struct ecommunity_val eval_rmac
;
1003 bgp_encap_types tnl_type
;
1004 struct listnode
*node
, *nnode
;
1005 struct vrf_route_target
*l3rt
;
1006 struct ecommunity
*old_ecom
;
1007 struct ecommunity
*ecom
;
1008 struct list
*vrf_export_rtl
= NULL
;
1011 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1012 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1013 encode_encap_extcomm(tnl_type
, &eval
);
1014 ecom_encap
.size
= 1;
1015 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1016 ecom_encap
.val
= (uint8_t *)eval
.val
;
1019 if (bgp_attr_get_ecommunity(attr
)) {
1020 old_ecom
= bgp_attr_get_ecommunity(attr
);
1021 ecom
= ecommunity_merge(ecommunity_dup(old_ecom
), &ecom_encap
);
1022 if (!old_ecom
->refcnt
)
1023 ecommunity_free(&old_ecom
);
1025 ecom
= ecommunity_dup(&ecom_encap
);
1026 bgp_attr_set_ecommunity(attr
, ecom
);
1027 attr
->encap_tunneltype
= tnl_type
;
1029 /* Add the export RTs for L3VNI/VRF */
1030 vrf_export_rtl
= bgp_vrf
->vrf_export_rtl
;
1031 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
, l3rt
))
1032 bgp_attr_set_ecommunity(
1033 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1036 /* add the router mac extended community */
1037 if (!is_zero_mac(&attr
->rmac
)) {
1038 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1039 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1045 * Build extended communities for EVPN route.
1046 * This function is applicable for type-2 and type-3 routes. The layer-2 RT
1047 * and ENCAP extended communities are applicable for all routes.
1048 * The default gateway extended community and MAC mobility (sticky) extended
1049 * community are added as needed based on passed settings - only for type-2
1050 * routes. Likewise, the layer-3 RT and Router MAC extended communities are
1051 * added, if present, based on passed settings - only for non-link-local
1054 static void build_evpn_route_extcomm(struct bgpevpn
*vpn
, struct attr
*attr
,
1057 struct ecommunity ecom_encap
;
1058 struct ecommunity ecom_sticky
;
1059 struct ecommunity ecom_default_gw
;
1060 struct ecommunity ecom_na
;
1061 struct ecommunity_val eval
;
1062 struct ecommunity_val eval_sticky
;
1063 struct ecommunity_val eval_default_gw
;
1064 struct ecommunity_val eval_rmac
;
1065 struct ecommunity_val eval_na
;
1068 bgp_encap_types tnl_type
;
1069 struct listnode
*node
, *nnode
;
1070 struct ecommunity
*ecom
;
1071 struct vrf_route_target
*l3rt
;
1073 struct list
*vrf_export_rtl
= NULL
;
1076 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1077 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1078 encode_encap_extcomm(tnl_type
, &eval
);
1079 ecom_encap
.size
= 1;
1080 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1081 ecom_encap
.val
= (uint8_t *)eval
.val
;
1084 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
1085 attr
->encap_tunneltype
= tnl_type
;
1087 /* Add the export RTs for L2VNI */
1088 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
))
1089 bgp_attr_set_ecommunity(
1091 ecommunity_merge(bgp_attr_get_ecommunity(attr
), ecom
));
1093 /* Add the export RTs for L3VNI if told to - caller determines
1094 * when this should be done.
1097 vrf_export_rtl
= bgpevpn_get_vrf_export_rtl(vpn
);
1098 if (vrf_export_rtl
&& !list_isempty(vrf_export_rtl
)) {
1099 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
,
1101 bgp_attr_set_ecommunity(
1104 bgp_attr_get_ecommunity(attr
),
1109 /* Add MAC mobility (sticky) if needed. */
1112 memset(&ecom_sticky
, 0, sizeof(ecom_sticky
));
1113 encode_mac_mobility_extcomm(1, seqnum
, &eval_sticky
);
1114 ecom_sticky
.size
= 1;
1115 ecom_sticky
.unit_size
= ECOMMUNITY_SIZE
;
1116 ecom_sticky
.val
= (uint8_t *)eval_sticky
.val
;
1117 bgp_attr_set_ecommunity(
1118 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1122 /* Add RMAC, if told to. */
1124 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1125 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1129 /* Add default gateway, if needed. */
1130 if (attr
->default_gw
) {
1131 memset(&ecom_default_gw
, 0, sizeof(ecom_default_gw
));
1132 encode_default_gw_extcomm(&eval_default_gw
);
1133 ecom_default_gw
.size
= 1;
1134 ecom_default_gw
.unit_size
= ECOMMUNITY_SIZE
;
1135 ecom_default_gw
.val
= (uint8_t *)eval_default_gw
.val
;
1136 bgp_attr_set_ecommunity(
1137 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1141 proxy
= !!(attr
->es_flags
& ATTR_ES_PROXY_ADVERT
);
1142 if (attr
->router_flag
|| proxy
) {
1143 memset(&ecom_na
, 0, sizeof(ecom_na
));
1144 encode_na_flag_extcomm(&eval_na
, attr
->router_flag
, proxy
);
1146 ecom_na
.unit_size
= ECOMMUNITY_SIZE
;
1147 ecom_na
.val
= (uint8_t *)eval_na
.val
;
1148 bgp_attr_set_ecommunity(
1149 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1155 * Add MAC mobility extended community to attribute.
1157 static void add_mac_mobility_to_attr(uint32_t seq_num
, struct attr
*attr
)
1159 struct ecommunity ecom_tmp
;
1160 struct ecommunity_val eval
;
1161 uint8_t *ecom_val_ptr
;
1166 struct ecommunity
*ecomm
= bgp_attr_get_ecommunity(attr
);
1169 encode_mac_mobility_extcomm(0, seq_num
, &eval
);
1171 /* Find current MM ecommunity */
1172 ecom_val_ptr
= NULL
;
1175 for (i
= 0; i
< ecomm
->size
; i
++) {
1176 pnt
= ecomm
->val
+ (i
* ecomm
->unit_size
);
1180 if (type
== ECOMMUNITY_ENCODE_EVPN
1182 == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY
) {
1184 (ecomm
->val
+ (i
* ecomm
->unit_size
));
1190 /* Update the existing MM ecommunity */
1192 memcpy(ecom_val_ptr
, eval
.val
, sizeof(char) * ecomm
->unit_size
);
1194 /* Add MM to existing */
1196 memset(&ecom_tmp
, 0, sizeof(ecom_tmp
));
1198 ecom_tmp
.unit_size
= ECOMMUNITY_SIZE
;
1199 ecom_tmp
.val
= (uint8_t *)eval
.val
;
1202 bgp_attr_set_ecommunity(
1203 attr
, ecommunity_merge(ecomm
, &ecom_tmp
));
1205 bgp_attr_set_ecommunity(attr
,
1206 ecommunity_dup(&ecom_tmp
));
1210 /* Install EVPN route into zebra. */
1211 static int evpn_zebra_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1212 const struct prefix_evpn
*p
,
1213 struct bgp_path_info
*pi
)
1217 int flood_control
= VXLAN_FLOOD_DISABLED
;
1220 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1223 if (pi
->sub_type
== BGP_ROUTE_IMPORTED
) {
1224 if (pi
->attr
->sticky
)
1225 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1226 if (pi
->attr
->default_gw
)
1227 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1228 if (is_evpn_prefix_ipaddr_v6(p
) &&
1229 pi
->attr
->router_flag
)
1230 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1232 seq
= mac_mobility_seqnum(pi
->attr
);
1233 /* if local ES notify zebra that this is a sync path */
1234 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
1235 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1236 if (bgp_evpn_attr_is_proxy(pi
->attr
))
1238 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1241 if (!bgp_evpn_attr_is_sync(pi
->attr
))
1244 /* if a local path is being turned around and sent
1245 * to zebra it is because it is a sync path on
1248 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1249 /* supply the highest peer seq number to zebra
1250 * for MM seq syncing
1252 seq
= bgp_evpn_attr_get_sync_seq(pi
->attr
);
1253 /* if any of the paths from the peer have the ROUTER
1254 * flag set install the local entry as a router entry
1256 if (is_evpn_prefix_ipaddr_v6(p
) &&
1257 (pi
->attr
->es_flags
&
1258 ATTR_ES_PEER_ROUTER
))
1260 ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1262 if (!(pi
->attr
->es_flags
& ATTR_ES_PEER_ACTIVE
))
1264 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1267 ret
= bgp_zebra_send_remote_macip(
1269 (is_evpn_prefix_ipaddr_none(p
)
1270 ? NULL
/* MAC update */
1271 : evpn_type2_path_info_get_mac(
1272 pi
) /* MAC-IP update */),
1273 pi
->attr
->nexthop
, 1, flags
, seq
,
1274 bgp_evpn_attr_get_esi(pi
->attr
));
1275 } else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
1276 ret
= bgp_evpn_remote_es_evi_add(bgp
, vpn
, p
);
1278 switch (bgp_attr_get_pmsi_tnl_type(pi
->attr
)) {
1279 case PMSI_TNLTYPE_INGR_REPL
:
1280 flood_control
= VXLAN_FLOOD_HEAD_END_REPL
;
1283 case PMSI_TNLTYPE_PIM_SM
:
1284 flood_control
= VXLAN_FLOOD_PIM_SM
;
1287 case PMSI_TNLTYPE_NO_INFO
:
1288 case PMSI_TNLTYPE_RSVP_TE_P2MP
:
1289 case PMSI_TNLTYPE_MLDP_P2MP
:
1290 case PMSI_TNLTYPE_PIM_SSM
:
1291 case PMSI_TNLTYPE_PIM_BIDIR
:
1292 case PMSI_TNLTYPE_MLDP_MP2MP
:
1293 flood_control
= VXLAN_FLOOD_DISABLED
;
1296 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
, flood_control
, 1);
1302 /* Uninstall EVPN route from zebra. */
1303 static int evpn_zebra_uninstall(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1304 const struct prefix_evpn
*p
,
1305 struct bgp_path_info
*pi
, bool is_sync
)
1309 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
1310 ret
= bgp_zebra_send_remote_macip(
1312 (is_evpn_prefix_ipaddr_none(p
)
1313 ? NULL
/* MAC update */
1314 : evpn_type2_path_info_get_mac(
1315 pi
) /* MAC-IP update */),
1316 (is_sync
? zero_vtep_ip
: pi
->attr
->nexthop
), 0, 0, 0,
1318 else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
1319 ret
= bgp_evpn_remote_es_evi_del(bgp
, vpn
, p
);
1321 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
,
1322 VXLAN_FLOOD_DISABLED
, 0);
1328 * Due to MAC mobility, the prior "local" best route has been supplanted
1329 * by a "remote" best route. The prior route has to be deleted and withdrawn
1332 static void evpn_delete_old_local_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1333 struct bgp_dest
*dest
,
1334 struct bgp_path_info
*old_local
,
1335 struct bgp_path_info
*new_select
)
1337 struct bgp_dest
*global_dest
;
1338 struct bgp_path_info
*pi
;
1339 afi_t afi
= AFI_L2VPN
;
1340 safi_t safi
= SAFI_EVPN
;
1342 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1343 char esi_buf
[ESI_STR_LEN
];
1344 char esi_buf2
[ESI_STR_LEN
];
1345 struct prefix_evpn
*evp
=
1346 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1348 zlog_debug("local path deleted %pFX es %s; new-path-es %s", evp
,
1349 esi_to_str(&old_local
->attr
->esi
, esi_buf
,
1351 new_select
? esi_to_str(&new_select
->attr
->esi
,
1352 esi_buf2
, sizeof(esi_buf2
))
1356 /* Locate route node in the global EVPN routing table. Note that
1357 * this table is a 2-level tree (RD-level + Prefix-level) similar to
1360 global_dest
= bgp_evpn_global_node_lookup(
1361 bgp
->rib
[afi
][safi
], afi
, safi
,
1362 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1363 &vpn
->prd
, old_local
);
1365 /* Delete route entry in the global EVPN table. */
1366 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
1368 /* Schedule for processing - withdraws to peers happen from
1372 bgp_process(bgp
, global_dest
, afi
, safi
);
1373 bgp_dest_unlock_node(global_dest
);
1376 /* Delete route entry in the VNI route table, caller to remove. */
1377 bgp_path_info_delete(dest
, old_local
);
1381 * Calculate the best path for an EVPN route. Install/update best path in zebra,
1383 * Note: vpn is NULL for local EAD-ES routes.
1385 int evpn_route_select_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1386 struct bgp_dest
*dest
)
1388 struct bgp_path_info
*old_select
, *new_select
;
1389 struct bgp_path_info_pair old_and_new
;
1390 afi_t afi
= AFI_L2VPN
;
1391 safi_t safi
= SAFI_EVPN
;
1394 /* Compute the best path. */
1395 bgp_best_selection(bgp
, dest
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
1397 old_select
= old_and_new
.old
;
1398 new_select
= old_and_new
.new;
1400 /* If the best path hasn't changed - see if there is still something to
1401 * update to zebra RIB.
1402 * Remote routes and SYNC route (i.e. local routes with
1403 * SYNCED_FROM_PEER flag) need to updated to zebra on any attr
1406 if (old_select
&& old_select
== new_select
1407 && old_select
->type
== ZEBRA_ROUTE_BGP
1408 && (old_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1409 bgp_evpn_attr_is_sync(old_select
->attr
))
1410 && !CHECK_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
)
1411 && !CHECK_FLAG(old_select
->flags
, BGP_PATH_ATTR_CHANGED
)
1412 && !bgp_addpath_is_addpath_used(&bgp
->tx_addpath
, afi
, safi
)) {
1413 if (bgp_zebra_has_route_changed(old_select
))
1414 ret
= evpn_zebra_install(
1416 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1419 UNSET_FLAG(old_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1420 UNSET_FLAG(old_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1421 bgp_zebra_clear_route_change_flags(dest
);
1425 /* If the user did a "clear" this flag will be set */
1426 UNSET_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
);
1428 /* bestpath has changed; update relevant fields and install or uninstall
1429 * into the zebra RIB.
1431 if (old_select
|| new_select
)
1432 bgp_bump_version(dest
);
1435 bgp_path_info_unset_flag(dest
, old_select
, BGP_PATH_SELECTED
);
1437 bgp_path_info_set_flag(dest
, new_select
, BGP_PATH_SELECTED
);
1438 bgp_path_info_unset_flag(dest
, new_select
,
1439 BGP_PATH_ATTR_CHANGED
);
1440 UNSET_FLAG(new_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1441 UNSET_FLAG(new_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1444 /* a local entry with the SYNC flag also results in a MAC-IP update
1447 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
1448 && (new_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1449 bgp_evpn_attr_is_sync(new_select
->attr
))) {
1450 ret
= evpn_zebra_install(
1452 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1455 /* If an old best existed and it was a "local" route, the only
1457 * it would be supplanted is due to MAC mobility procedures. So,
1459 * need to do an implicit delete and withdraw that route from
1462 if (new_select
->sub_type
== BGP_ROUTE_IMPORTED
&&
1463 old_select
&& old_select
->peer
== bgp
->peer_self
1464 && old_select
->type
== ZEBRA_ROUTE_BGP
1465 && old_select
->sub_type
== BGP_ROUTE_STATIC
1467 evpn_delete_old_local_route(bgp
, vpn
, dest
,
1468 old_select
, new_select
);
1470 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
1471 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
1472 ret
= evpn_zebra_uninstall(
1474 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1479 /* Clear any route change flags. */
1480 bgp_zebra_clear_route_change_flags(dest
);
1482 /* Reap old select bgp_path_info, if it has been removed */
1483 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_PATH_REMOVED
))
1484 bgp_path_info_reap(dest
, old_select
);
1489 static struct bgp_path_info
*bgp_evpn_route_get_local_path(
1490 struct bgp
*bgp
, struct bgp_dest
*dest
)
1492 struct bgp_path_info
*tmp_pi
;
1493 struct bgp_path_info
*local_pi
= NULL
;
1495 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1496 tmp_pi
= tmp_pi
->next
) {
1497 if (bgp_evpn_is_path_local(bgp
, tmp_pi
)) {
1506 static int update_evpn_type5_route_entry(struct bgp
*bgp_evpn
,
1507 struct bgp
*bgp_vrf
, afi_t afi
,
1508 safi_t safi
, struct bgp_dest
*dest
,
1509 struct attr
*attr
, int *route_changed
)
1511 struct attr
*attr_new
= NULL
;
1512 struct bgp_path_info
*pi
= NULL
;
1513 mpls_label_t label
= MPLS_INVALID_LABEL
;
1514 struct bgp_path_info
*local_pi
= NULL
;
1515 struct bgp_path_info
*tmp_pi
= NULL
;
1518 /* locate the local route entry if any */
1519 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1520 tmp_pi
= tmp_pi
->next
) {
1521 if (tmp_pi
->peer
== bgp_evpn
->peer_self
1522 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
1523 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
1528 * create a new route entry if one doesn't exist.
1529 * Otherwise see if route attr has changed
1533 /* route has changed as this is the first entry */
1536 /* Add (or update) attribute to hash. */
1537 attr_new
= bgp_attr_intern(attr
);
1539 /* create the route info from attribute */
1540 pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1541 bgp_evpn
->peer_self
, attr_new
, dest
);
1542 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
1544 /* Type-5 routes advertise the L3-VNI */
1545 bgp_path_info_extra_get(pi
);
1546 vni2label(bgp_vrf
->l3vni
, &label
);
1547 memcpy(&pi
->extra
->label
, &label
, sizeof(label
));
1548 pi
->extra
->num_labels
= 1;
1550 /* add the route entry to route node*/
1551 bgp_path_info_add(dest
, pi
);
1555 if (!attrhash_cmp(tmp_pi
->attr
, attr
)) {
1557 /* attribute changed */
1560 /* The attribute has changed. */
1561 /* Add (or update) attribute to hash. */
1562 attr_new
= bgp_attr_intern(attr
);
1563 bgp_path_info_set_flag(dest
, tmp_pi
,
1564 BGP_PATH_ATTR_CHANGED
);
1566 /* Restore route, if needed. */
1567 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1568 bgp_path_info_restore(dest
, tmp_pi
);
1570 /* Unintern existing, set to new. */
1571 bgp_attr_unintern(&tmp_pi
->attr
);
1572 tmp_pi
->attr
= attr_new
;
1573 tmp_pi
->uptime
= monotime(NULL
);
1579 /* update evpn type-5 route entry */
1580 static int update_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
,
1581 struct attr
*src_attr
, afi_t src_afi
,
1584 afi_t afi
= AFI_L2VPN
;
1585 safi_t safi
= SAFI_EVPN
;
1587 struct bgp_dest
*dest
= NULL
;
1588 struct bgp
*bgp_evpn
= NULL
;
1589 int route_changed
= 0;
1591 bgp_evpn
= bgp_get_evpn();
1595 /* Build path attribute for this route - use the source attr, if
1596 * present, else treat as locally originated.
1601 memset(&attr
, 0, sizeof(attr
));
1602 bgp_attr_default_set(&attr
, bgp_vrf
, BGP_ORIGIN_IGP
);
1605 /* Advertise Primary IP (PIP) is enabled, send individual
1606 * IP (default instance router-id) as nexthop.
1607 * PIP is disabled or vrr interface is not present
1608 * use anycast-IP as nexthop and anycast RMAC.
1610 if (!bgp_vrf
->evpn_info
->advertise_pip
||
1611 (!bgp_vrf
->evpn_info
->is_anycast_mac
)) {
1612 attr
.nexthop
= bgp_vrf
->originator_ip
;
1613 attr
.mp_nexthop_global_in
= bgp_vrf
->originator_ip
;
1614 memcpy(&attr
.rmac
, &bgp_vrf
->rmac
, ETH_ALEN
);
1617 memcpy(&attr
.rmac
, &bgp_vrf
->evpn_info
->pip_rmac
, ETH_ALEN
);
1618 if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
!= INADDR_ANY
) {
1619 attr
.nexthop
= bgp_vrf
->evpn_info
->pip_ip
;
1620 attr
.mp_nexthop_global_in
= bgp_vrf
->evpn_info
->pip_ip
;
1621 } else if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
== INADDR_ANY
)
1622 if (bgp_debug_zebra(NULL
))
1624 "VRF %s evp %pFX advertise-pip primary ip is not configured",
1625 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
);
1628 if (bgp_debug_zebra(NULL
))
1630 "VRF %s type-5 route evp %pFX RMAC %pEA nexthop %pI4",
1631 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, &attr
.rmac
,
1634 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1636 if (src_afi
== AFI_IP6
&&
1637 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1638 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
)) {
1640 !IN6_IS_ADDR_UNSPECIFIED(&src_attr
->mp_nexthop_global
)) {
1641 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1642 SET_IPADDR_V6(&attr
.evpn_overlay
.gw_ip
);
1643 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
1644 &src_attr
->mp_nexthop_global
,
1645 sizeof(struct in6_addr
));
1647 } else if (src_afi
== AFI_IP
&&
1648 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1649 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
)) {
1650 if (src_attr
&& src_attr
->nexthop
.s_addr
!= 0) {
1651 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1652 SET_IPADDR_V4(&attr
.evpn_overlay
.gw_ip
);
1653 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v4
,
1654 &src_attr
->nexthop
, sizeof(struct in_addr
));
1658 /* Setup RT and encap extended community */
1659 build_evpn_type5_route_extcomm(bgp_vrf
, &attr
);
1661 /* get the route node in global table */
1662 dest
= bgp_evpn_global_node_get(bgp_evpn
->rib
[afi
][safi
], afi
, safi
,
1663 evp
, &bgp_vrf
->vrf_prd
, NULL
);
1666 /* create or update the route entry within the route node */
1667 update_evpn_type5_route_entry(bgp_evpn
, bgp_vrf
, afi
, safi
, dest
, &attr
,
1670 /* schedule for processing and unlock node */
1671 if (route_changed
) {
1672 bgp_process(bgp_evpn
, dest
, afi
, safi
);
1673 bgp_dest_unlock_node(dest
);
1676 /* uninten temporary */
1678 aspath_unintern(&attr
.aspath
);
1682 static void bgp_evpn_get_sync_info(struct bgp
*bgp
, esi_t
*esi
,
1683 struct bgp_dest
*dest
, uint32_t loc_seq
,
1684 uint32_t *max_sync_seq
, bool *active_on_peer
,
1685 bool *peer_router
, bool *proxy_from_peer
,
1686 const struct ethaddr
*mac
)
1688 struct bgp_path_info
*tmp_pi
;
1689 struct bgp_path_info
*second_best_path
= NULL
;
1690 uint32_t tmp_mm_seq
= 0;
1693 struct ethaddr
*tmp_mac
;
1694 bool mac_cmp
= false;
1695 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&dest
->p
;
1698 /* mac comparison is not needed for MAC-only routes */
1699 if (mac
&& !is_evpn_prefix_ipaddr_none(evp
))
1702 /* find the best non-local path. a local path can only be present
1705 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1706 tmp_pi
= tmp_pi
->next
) {
1707 if (tmp_pi
->sub_type
!= BGP_ROUTE_IMPORTED
||
1708 !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
))
1711 /* ignore paths that have a different mac */
1713 tmp_mac
= evpn_type2_path_info_get_mac(tmp_pi
);
1714 if (memcmp(mac
, tmp_mac
, sizeof(*mac
)))
1718 if (bgp_evpn_path_info_cmp(bgp
, tmp_pi
,
1719 second_best_path
, &paths_eq
))
1720 second_best_path
= tmp_pi
;
1723 if (!second_best_path
)
1726 tmp_esi
= bgp_evpn_attr_get_esi(second_best_path
->attr
);
1727 /* if this has the same ES desination as the local path
1730 if (!memcmp(esi
, tmp_esi
, sizeof(esi_t
))) {
1731 tmp_mm_seq
= mac_mobility_seqnum(second_best_path
->attr
);
1732 if (tmp_mm_seq
< loc_seq
)
1735 /* we have a non-proxy path from the ES peer. */
1736 if (second_best_path
->attr
->es_flags
&
1737 ATTR_ES_PROXY_ADVERT
) {
1738 *proxy_from_peer
= true;
1740 *active_on_peer
= true;
1743 if (second_best_path
->attr
->router_flag
)
1744 *peer_router
= true;
1746 /* we use both proxy and non-proxy imports to
1747 * determine the max sync sequence
1749 if (tmp_mm_seq
> *max_sync_seq
)
1750 *max_sync_seq
= tmp_mm_seq
;
1754 /* Bubble up sync-info from all paths (non-best) to the local-path.
1755 * This is need for MM sequence number syncing and proxy advertisement.
1756 * Note: The local path can only exist as a best path in the
1757 * VPN route table. It will take precedence over all sync paths.
1759 static void update_evpn_route_entry_sync_info(struct bgp
*bgp
,
1760 struct bgp_dest
*dest
,
1762 uint32_t loc_seq
, bool setup_sync
,
1763 const struct ethaddr
*mac
)
1766 struct prefix_evpn
*evp
=
1767 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1769 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
1772 esi
= bgp_evpn_attr_get_esi(attr
);
1773 if (bgp_evpn_is_esi_valid(esi
)) {
1775 uint32_t max_sync_seq
= 0;
1776 bool active_on_peer
= false;
1777 bool peer_router
= false;
1778 bool proxy_from_peer
= false;
1780 bgp_evpn_get_sync_info(bgp
, esi
, dest
, loc_seq
,
1781 &max_sync_seq
, &active_on_peer
,
1782 &peer_router
, &proxy_from_peer
,
1784 attr
->mm_sync_seqnum
= max_sync_seq
;
1786 attr
->es_flags
|= ATTR_ES_PEER_ACTIVE
;
1788 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1789 if (proxy_from_peer
)
1790 attr
->es_flags
|= ATTR_ES_PEER_PROXY
;
1792 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1794 attr
->es_flags
|= ATTR_ES_PEER_ROUTER
;
1796 attr
->es_flags
&= ~ATTR_ES_PEER_ROUTER
;
1798 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1799 char esi_buf
[ESI_STR_LEN
];
1802 "setup sync info for %pFX es %s max_seq %d %s%s%s",
1804 esi_to_str(esi
, esi_buf
,
1807 (attr
->es_flags
& ATTR_ES_PEER_ACTIVE
)
1810 (attr
->es_flags
& ATTR_ES_PEER_PROXY
)
1813 (attr
->es_flags
& ATTR_ES_PEER_ROUTER
)
1819 attr
->mm_sync_seqnum
= 0;
1820 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1821 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1826 * Create or update EVPN route entry. This could be in the VNI route tables
1827 * or the global route table.
1829 static int update_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1830 afi_t afi
, safi_t safi
,
1831 struct bgp_dest
*dest
, struct attr
*attr
,
1832 const struct ethaddr
*mac
,
1833 const struct ipaddr
*ip
, int add
,
1834 struct bgp_path_info
**pi
, uint8_t flags
,
1835 uint32_t seq
, bool vpn_rt
, bool *old_is_sync
)
1837 struct bgp_path_info
*tmp_pi
;
1838 struct bgp_path_info
*local_pi
;
1839 struct attr
*attr_new
;
1840 mpls_label_t label
[BGP_MAX_LABELS
];
1841 uint32_t num_labels
= 1;
1842 int route_change
= 1;
1844 const struct prefix_evpn
*evp
;
1847 evp
= (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1848 memset(&label
, 0, sizeof(label
));
1850 /* See if this is an update of an existing route, or a new add. */
1851 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
1853 /* If route doesn't exist already, create a new one, if told to.
1854 * Otherwise act based on whether the attributes of the route have
1857 if (!local_pi
&& !add
)
1860 if (old_is_sync
&& local_pi
)
1861 *old_is_sync
= bgp_evpn_attr_is_sync(local_pi
->attr
);
1863 /* if a local path is being added with a non-zero esi look
1864 * for SYNC paths from ES peers and bubble up the sync-info
1866 update_evpn_route_entry_sync_info(bgp
, dest
, attr
, seq
, vpn_rt
, mac
);
1868 /* For non-GW MACs, update MAC mobility seq number, if needed. */
1869 if (seq
&& !CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
))
1870 add_mac_mobility_to_attr(seq
, attr
);
1873 /* Add (or update) attribute to hash. */
1874 attr_new
= bgp_attr_intern(attr
);
1876 /* Extract MAC mobility sequence number, if any. */
1877 attr_new
->mm_seqnum
=
1878 bgp_attr_mac_mobility_seqnum(attr_new
, &sticky
);
1879 attr_new
->sticky
= sticky
;
1881 /* Create new route with its attribute. */
1882 tmp_pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1883 bgp
->peer_self
, attr_new
, dest
);
1884 SET_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
);
1885 bgp_path_info_extra_get(tmp_pi
);
1887 /* The VNI goes into the 'label' field of the route */
1888 vni2label(vpn
->vni
, &label
[0]);
1890 /* Type-2 routes may carry a second VNI - the L3-VNI.
1891 * Only attach second label if we are advertising two labels for
1894 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1895 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
1898 l3vni
= bgpevpn_get_l3vni(vpn
);
1900 vni2label(l3vni
, &label
[1]);
1905 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1906 tmp_pi
->extra
->num_labels
= num_labels
;
1908 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1910 evpn_type2_path_info_set_mac(tmp_pi
, *mac
);
1912 evpn_type2_path_info_set_ip(tmp_pi
, *ip
);
1915 /* Mark route as self type-2 route */
1916 if (flags
&& CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
1917 tmp_pi
->extra
->af_flags
= BGP_EVPN_MACIP_TYPE_SVI_IP
;
1918 bgp_path_info_add(dest
, tmp_pi
);
1921 if (attrhash_cmp(tmp_pi
->attr
, attr
)
1922 && !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1926 * The attributes have changed, type-2 routes needs to
1927 * be advertised with right labels.
1929 vni2label(vpn
->vni
, &label
[0]);
1930 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1931 && CHECK_FLAG(vpn
->flags
,
1932 VNI_FLAG_USE_TWO_LABELS
)) {
1935 l3vni
= bgpevpn_get_l3vni(vpn
);
1937 vni2label(l3vni
, &label
[1]);
1941 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1942 tmp_pi
->extra
->num_labels
= num_labels
;
1944 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1946 evpn_type2_path_info_set_mac(tmp_pi
,
1949 evpn_type2_path_info_set_ip(tmp_pi
,
1953 /* The attribute has changed. */
1954 /* Add (or update) attribute to hash. */
1955 attr_new
= bgp_attr_intern(attr
);
1956 bgp_path_info_set_flag(dest
, tmp_pi
,
1957 BGP_PATH_ATTR_CHANGED
);
1959 /* Extract MAC mobility sequence number, if any. */
1960 attr_new
->mm_seqnum
=
1961 bgp_attr_mac_mobility_seqnum(attr_new
, &sticky
);
1962 attr_new
->sticky
= sticky
;
1964 /* Restore route, if needed. */
1965 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1966 bgp_path_info_restore(dest
, tmp_pi
);
1968 /* Unintern existing, set to new. */
1969 bgp_attr_unintern(&tmp_pi
->attr
);
1970 tmp_pi
->attr
= attr_new
;
1971 tmp_pi
->uptime
= monotime(NULL
);
1975 /* local MAC-IP routes in the VNI table are linked to
1976 * the destination ES
1978 if (route_change
&& vpn_rt
1979 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
))
1980 bgp_evpn_path_es_link(tmp_pi
, vpn
->vni
,
1981 bgp_evpn_attr_get_esi(tmp_pi
->attr
));
1983 /* Return back the route entry. */
1985 return route_change
;
1988 static void evpn_zebra_reinstall_best_route(struct bgp
*bgp
,
1989 struct bgpevpn
*vpn
,
1990 struct bgp_dest
*dest
)
1992 struct bgp_path_info
*tmp_ri
;
1993 struct bgp_path_info
*curr_select
= NULL
;
1995 for (tmp_ri
= bgp_dest_get_bgp_path_info(dest
); tmp_ri
;
1996 tmp_ri
= tmp_ri
->next
) {
1997 if (CHECK_FLAG(tmp_ri
->flags
, BGP_PATH_SELECTED
)) {
1998 curr_select
= tmp_ri
;
2003 if (curr_select
&& curr_select
->type
== ZEBRA_ROUTE_BGP
2004 && (curr_select
->sub_type
== BGP_ROUTE_IMPORTED
||
2005 bgp_evpn_attr_is_sync(curr_select
->attr
)))
2006 evpn_zebra_install(bgp
, vpn
,
2007 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
2012 * If the local route was not selected evict it and tell zebra to re-add
2013 * the best remote dest.
2015 * Typically a local path added by zebra is expected to be selected as
2016 * best. In which case when a remote path wins as best (later)
2017 * evpn_route_select_install itself evicts the older-local-best path.
2019 * However if bgp's add and zebra's add cross paths (race condition) it
2020 * is possible that the local path is no longer the "older" best path.
2021 * It is a path that was never designated as best and hence requires
2022 * additional handling to prevent bgp from injecting and holding on to a
2023 * non-best local path.
2025 static void evpn_cleanup_local_non_best_route(struct bgp
*bgp
,
2026 struct bgpevpn
*vpn
,
2027 struct bgp_dest
*dest
,
2028 struct bgp_path_info
*local_pi
)
2030 /* local path was not picked as the winner; kick it out */
2031 if (bgp_debug_zebra(NULL
))
2032 zlog_debug("evicting local evpn prefix %pBD as remote won",
2035 evpn_delete_old_local_route(bgp
, vpn
, dest
, local_pi
, NULL
);
2036 bgp_path_info_reap(dest
, local_pi
);
2038 /* tell zebra to re-add the best remote path */
2039 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
2042 static inline bool bgp_evpn_route_add_l3_ecomm_ok(struct bgpevpn
*vpn
,
2043 const struct prefix_evpn
*p
,
2046 return p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
2047 && (is_evpn_prefix_ipaddr_v4(p
)
2048 || (is_evpn_prefix_ipaddr_v6(p
)
2049 && !IN6_IS_ADDR_LINKLOCAL(
2050 &p
->prefix
.macip_addr
.ip
.ipaddr_v6
)))
2051 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)
2052 && bgpevpn_get_l3vni(vpn
) && bgp_evpn_es_add_l3_ecomm_ok(esi
);
2056 * Create or update EVPN route (of type based on prefix) for specified VNI
2057 * and schedule for processing.
2059 static int update_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2060 struct prefix_evpn
*p
, uint8_t flags
,
2061 uint32_t seq
, esi_t
*esi
)
2063 struct bgp_dest
*dest
;
2065 struct attr
*attr_new
;
2066 int add_l3_ecomm
= 0;
2067 struct bgp_path_info
*pi
;
2068 afi_t afi
= AFI_L2VPN
;
2069 safi_t safi
= SAFI_EVPN
;
2071 bool old_is_sync
= false;
2072 bool mac_only
= false;
2074 memset(&attr
, 0, sizeof(attr
));
2076 /* Build path-attribute for this route. */
2077 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2078 attr
.nexthop
= vpn
->originator_ip
;
2079 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2080 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2081 attr
.sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
) ? 1 : 0;
2082 attr
.default_gw
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
) ? 1 : 0;
2083 attr
.router_flag
= CHECK_FLAG(flags
,
2084 ZEBRA_MACIP_TYPE_ROUTER_FLAG
) ? 1 : 0;
2085 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
2086 attr
.es_flags
|= ATTR_ES_PROXY_ADVERT
;
2088 if (esi
&& bgp_evpn_is_esi_valid(esi
)) {
2089 memcpy(&attr
.esi
, esi
, sizeof(esi_t
));
2090 attr
.es_flags
|= ATTR_ES_IS_LOCAL
;
2093 /* PMSI is only needed for type-3 routes */
2094 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
) {
2095 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
);
2096 bgp_attr_set_pmsi_tnl_type(&attr
, PMSI_TNLTYPE_INGR_REPL
);
2099 /* router mac is only needed for type-2 routes here. */
2100 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
2101 uint8_t af_flags
= 0;
2103 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
2104 SET_FLAG(af_flags
, BGP_EVPN_MACIP_TYPE_SVI_IP
);
2106 bgp_evpn_get_rmac_nexthop(vpn
, p
, &attr
, af_flags
);
2109 if (bgp_debug_zebra(NULL
)) {
2110 char buf3
[ESI_STR_LEN
];
2113 "VRF %s vni %u type-%u route evp %pFX RMAC %pEA nexthop %pI4 esi %s",
2114 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2116 vpn
->vni
, p
->prefix
.route_type
, p
, &attr
.rmac
,
2117 &attr
.mp_nexthop_global_in
,
2118 esi_to_str(esi
, buf3
, sizeof(buf3
)));
2121 vni2label(vpn
->vni
, &(attr
.label
));
2123 /* Include L3 VNI related RTs and RMAC for type-2 routes, if they're
2124 * IPv4 or IPv6 global addresses and we're advertising L3VNI with
2127 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2128 vpn
, p
, (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2130 /* Set up extended community. */
2131 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2133 /* First, create (or fetch) route node within the VNI.
2134 * NOTE: There is no RD here.
2136 dest
= bgp_evpn_vni_node_get(vpn
, p
, NULL
);
2138 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
2139 (is_evpn_prefix_ipaddr_none(p
) == true))
2142 /* Create or update route entry. */
2143 route_change
= update_evpn_route_entry(
2144 bgp
, vpn
, afi
, safi
, dest
, &attr
,
2145 (mac_only
? NULL
: &p
->prefix
.macip_addr
.mac
), NULL
/* ip */, 1,
2146 &pi
, flags
, seq
, true /* setup_sync */, &old_is_sync
);
2148 attr_new
= pi
->attr
;
2150 /* lock ri to prevent freeing in evpn_route_select_install */
2151 bgp_path_info_lock(pi
);
2153 /* Perform route selection. Normally, the local route in the
2154 * VNI is expected to win and be the best route. However, if
2155 * there is a race condition where a host moved from local to
2156 * remote and the remote route was received in BGP just prior
2157 * to the local MACIP notification from zebra, the remote
2158 * route would win, and we should evict the defunct local route
2159 * and (re)install the remote route into zebra.
2161 evpn_route_select_install(bgp
, vpn
, dest
);
2163 * If the new local route was not selected evict it and tell zebra
2164 * to re-add the best remote dest. BGP doesn't retain non-best local
2167 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2170 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2172 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2176 /* If the local path already existed and is still the
2177 * best path we need to also check if it transitioned
2178 * from being a sync path to a non-sync path. If it
2179 * it did we need to notify zebra that the sync-path
2182 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2183 if (!new_is_sync
&& old_is_sync
)
2184 evpn_zebra_uninstall(bgp
, vpn
, p
, pi
, true);
2187 bgp_path_info_unlock(pi
);
2189 bgp_dest_unlock_node(dest
);
2191 /* If this is a new route or some attribute has changed, export the
2192 * route to the global table. The route will be advertised to peers
2193 * from there. Note that this table is a 2-level tree (RD-level +
2194 * Prefix-level) similar to L3VPN routes.
2197 struct bgp_path_info
*global_pi
;
2199 dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
2200 p
, &vpn
->prd
, NULL
);
2201 update_evpn_route_entry(
2202 bgp
, vpn
, afi
, safi
, dest
, attr_new
, NULL
/* mac */,
2203 NULL
/* ip */, 1, &global_pi
, flags
, seq
,
2204 false /* setup_sync */, NULL
/* old_is_sync */);
2206 /* Schedule for processing and unlock node. */
2207 bgp_process(bgp
, dest
, afi
, safi
);
2208 bgp_dest_unlock_node(dest
);
2211 /* Unintern temporary. */
2212 aspath_unintern(&attr
.aspath
);
2218 * Delete EVPN route entry.
2219 * The entry can be in ESI/VNI table or the global table.
2221 void delete_evpn_route_entry(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
2222 struct bgp_dest
*dest
,
2223 struct bgp_path_info
**pi
)
2225 struct bgp_path_info
*tmp_pi
;
2229 /* Now, find matching route. */
2230 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2231 tmp_pi
= tmp_pi
->next
)
2232 if (tmp_pi
->peer
== bgp
->peer_self
2233 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
2234 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2239 /* Mark route for delete. */
2241 bgp_path_info_delete(dest
, tmp_pi
);
2244 /* Delete EVPN type5 route */
2245 static int delete_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
)
2247 afi_t afi
= AFI_L2VPN
;
2248 safi_t safi
= SAFI_EVPN
;
2249 struct bgp_dest
*dest
= NULL
;
2250 struct bgp_path_info
*pi
= NULL
;
2251 struct bgp
*bgp_evpn
= NULL
; /* evpn bgp instance */
2253 bgp_evpn
= bgp_get_evpn();
2257 /* locate the global route entry for this type-5 prefix */
2258 dest
= bgp_evpn_global_node_lookup(bgp_evpn
->rib
[afi
][safi
], afi
, safi
,
2259 evp
, &bgp_vrf
->vrf_prd
, NULL
);
2263 delete_evpn_route_entry(bgp_evpn
, afi
, safi
, dest
, &pi
);
2265 bgp_process(bgp_evpn
, dest
, afi
, safi
);
2266 bgp_dest_unlock_node(dest
);
2271 * Delete EVPN route (of type based on prefix) for specified VNI and
2272 * schedule for processing.
2274 static int delete_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2275 struct prefix_evpn
*p
)
2277 struct bgp_dest
*dest
, *global_dest
;
2278 struct bgp_path_info
*pi
;
2279 afi_t afi
= AFI_L2VPN
;
2280 safi_t safi
= SAFI_EVPN
;
2282 /* First, locate the route node within the VNI. If it doesn't exist,
2284 * is nothing further to do.
2285 * NOTE: There is no RD here.
2287 dest
= bgp_evpn_vni_node_lookup(vpn
, p
, NULL
);
2291 /* Next, locate route node in the global EVPN routing table. Note that
2292 * this table is a 2-level tree (RD-level + Prefix-level) similar to
2295 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], afi
,
2296 safi
, p
, &vpn
->prd
, NULL
);
2298 /* Delete route entry in the global EVPN table. */
2299 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
2301 /* Schedule for processing - withdraws to peers happen from
2305 bgp_process(bgp
, global_dest
, afi
, safi
);
2306 bgp_dest_unlock_node(global_dest
);
2309 /* Delete route entry in the VNI route table. This can just be removed.
2311 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2313 bgp_path_info_reap(dest
, pi
);
2314 evpn_route_select_install(bgp
, vpn
, dest
);
2316 bgp_dest_unlock_node(dest
);
2321 void bgp_evpn_update_type2_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2322 struct bgp_dest
*dest
,
2323 struct bgp_path_info
*local_pi
,
2326 afi_t afi
= AFI_L2VPN
;
2327 safi_t safi
= SAFI_EVPN
;
2328 struct bgp_path_info
*pi
;
2330 struct attr
*attr_new
;
2332 int add_l3_ecomm
= 0;
2333 struct bgp_dest
*global_dest
;
2334 struct bgp_path_info
*global_pi
;
2335 struct prefix_evpn evp
;
2337 bool old_is_sync
= false;
2339 if (CHECK_FLAG(local_pi
->flags
, BGP_PATH_REMOVED
))
2343 * VNI table MAC-IP prefixes don't have MAC so make sure it's set from
2346 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)&dest
->p
)) {
2347 /* VNI MAC -> Global */
2348 evpn_type2_prefix_global_copy(
2349 &evp
, (struct prefix_evpn
*)&dest
->p
, NULL
/* mac */,
2350 evpn_type2_path_info_get_ip(local_pi
));
2352 /* VNI IP -> Global */
2353 evpn_type2_prefix_global_copy(
2354 &evp
, (struct prefix_evpn
*)&dest
->p
,
2355 evpn_type2_path_info_get_mac(local_pi
), NULL
/* ip */);
2359 * Build attribute per local route as the MAC mobility and
2360 * some other values could differ for different routes. The
2361 * attributes will be shared in the hash table.
2363 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2364 attr
.nexthop
= vpn
->originator_ip
;
2365 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2366 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2367 attr
.sticky
= (local_pi
->attr
->sticky
) ? 1 : 0;
2368 attr
.router_flag
= (local_pi
->attr
->router_flag
) ? 1 : 0;
2369 attr
.es_flags
= local_pi
->attr
->es_flags
;
2370 if (local_pi
->attr
->default_gw
) {
2371 attr
.default_gw
= 1;
2372 if (is_evpn_prefix_ipaddr_v6(&evp
))
2373 attr
.router_flag
= 1;
2375 memcpy(&attr
.esi
, &local_pi
->attr
->esi
, sizeof(esi_t
));
2376 bgp_evpn_get_rmac_nexthop(vpn
, &evp
, &attr
, local_pi
->extra
->af_flags
);
2377 vni2label(vpn
->vni
, &(attr
.label
));
2378 /* Add L3 VNI RTs and RMAC for non IPv6 link-local if
2379 * using L3 VNI for type-2 routes also.
2381 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2383 (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2385 /* Set up extended community. */
2386 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2387 seq
= mac_mobility_seqnum(local_pi
->attr
);
2389 if (bgp_debug_zebra(NULL
)) {
2390 char buf3
[ESI_STR_LEN
];
2393 "VRF %s vni %u evp %pFX RMAC %pEA nexthop %pI4 esi %s esf 0x%x from %s",
2394 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2396 vpn
->vni
, &evp
, &attr
.rmac
, &attr
.mp_nexthop_global_in
,
2397 esi_to_str(&attr
.esi
, buf3
, sizeof(buf3
)),
2398 attr
.es_flags
, caller
);
2401 /* Update the route entry. */
2402 route_change
= update_evpn_route_entry(
2403 bgp
, vpn
, afi
, safi
, dest
, &attr
, NULL
/* mac */, NULL
/* ip */,
2404 0, &pi
, 0, seq
, true /* setup_sync */, &old_is_sync
);
2407 attr_new
= pi
->attr
;
2408 /* lock ri to prevent freeing in evpn_route_select_install */
2409 bgp_path_info_lock(pi
);
2411 /* Perform route selection. Normally, the local route in the
2412 * VNI is expected to win and be the best route. However,
2413 * under peculiar situations (e.g., tunnel (next hop) IP change
2414 * that causes best selection to be based on next hop), a
2415 * remote route could win. If the local route is the best,
2416 * ensure it is updated in the global EVPN route table and
2417 * advertised to peers; otherwise, ensure it is evicted and
2418 * (re)install the remote route into zebra.
2420 evpn_route_select_install(bgp
, vpn
, dest
);
2422 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2425 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2427 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2431 /* If the local path already existed and is still the
2432 * best path we need to also check if it transitioned
2433 * from being a sync path to a non-sync path. If it
2434 * it did we need to notify zebra that the sync-path
2437 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2438 if (!new_is_sync
&& old_is_sync
)
2439 evpn_zebra_uninstall(bgp
, vpn
, &evp
, pi
, true);
2445 bgp_path_info_unlock(pi
);
2448 /* Update route in global routing table. */
2449 global_dest
= bgp_evpn_global_node_get(
2450 bgp
->rib
[afi
][safi
], afi
, safi
, &evp
, &vpn
->prd
, NULL
);
2451 assert(global_dest
);
2452 update_evpn_route_entry(
2453 bgp
, vpn
, afi
, safi
, global_dest
, attr_new
,
2454 NULL
/* mac */, NULL
/* ip */, 0, &global_pi
, 0,
2455 mac_mobility_seqnum(attr_new
), false /* setup_sync */,
2456 NULL
/* old_is_sync */);
2458 /* Schedule for processing and unlock node. */
2459 bgp_process(bgp
, global_dest
, afi
, safi
);
2460 bgp_dest_unlock_node(global_dest
);
2463 /* Unintern temporary. */
2464 aspath_unintern(&attr
.aspath
);
2467 static void update_type2_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2468 struct bgp_dest
*dest
)
2470 struct bgp_path_info
*tmp_pi
;
2472 const struct prefix_evpn
*evp
=
2473 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2475 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2478 /* Identify local route. */
2479 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2480 tmp_pi
= tmp_pi
->next
) {
2481 if (tmp_pi
->peer
== bgp
->peer_self
&&
2482 tmp_pi
->type
== ZEBRA_ROUTE_BGP
&&
2483 tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2490 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, tmp_pi
, __func__
);
2494 * Update all type-2 (MACIP) local routes for this VNI - these should also
2495 * be scheduled for advertise to peers.
2497 static void update_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2499 struct bgp_dest
*dest
;
2501 /* Walk this VNI's route MAC & IP table and update local type-2
2502 * routes. For any routes updated, update corresponding entry in the
2505 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2506 dest
= bgp_route_next(dest
))
2507 update_type2_route(bgp
, vpn
, dest
);
2509 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2510 dest
= bgp_route_next(dest
))
2511 update_type2_route(bgp
, vpn
, dest
);
2515 * Delete all type-2 (MACIP) local routes for this VNI - only from the
2516 * global routing table. These are also scheduled for withdraw from peers.
2518 static void delete_global_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2522 struct bgp_dest
*rddest
, *dest
;
2523 struct bgp_table
*table
;
2524 struct bgp_path_info
*pi
;
2529 rddest
= bgp_node_lookup(bgp
->rib
[afi
][safi
],
2530 (struct prefix
*)&vpn
->prd
);
2532 table
= bgp_dest_get_bgp_table_info(rddest
);
2533 for (dest
= bgp_table_top(table
); dest
;
2534 dest
= bgp_route_next(dest
)) {
2535 const struct prefix_evpn
*evp
=
2536 (const struct prefix_evpn
*)bgp_dest_get_prefix(
2539 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2542 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2544 bgp_process(bgp
, dest
, afi
, safi
);
2547 /* Unlock RD node. */
2548 bgp_dest_unlock_node(rddest
);
2552 static void delete_vni_type2_route(struct bgp
*bgp
, struct bgp_dest
*dest
)
2554 struct bgp_path_info
*pi
;
2555 afi_t afi
= AFI_L2VPN
;
2556 safi_t safi
= SAFI_EVPN
;
2558 const struct prefix_evpn
*evp
=
2559 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2561 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2564 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2566 /* Route entry in local table gets deleted immediately. */
2568 bgp_path_info_reap(dest
, pi
);
2571 static void delete_vni_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2573 struct bgp_dest
*dest
;
2575 /* Next, walk this VNI's MAC & IP route table and delete local type-2
2578 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2579 dest
= bgp_route_next(dest
))
2580 delete_vni_type2_route(bgp
, dest
);
2582 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2583 dest
= bgp_route_next(dest
))
2584 delete_vni_type2_route(bgp
, dest
);
2588 * Delete all type-2 (MACIP) local routes for this VNI - from the global
2589 * table as well as the per-VNI route table.
2591 static void delete_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2593 /* First, walk the global route table for this VNI's type-2 local
2595 * EVPN routes are a 2-level table, first get the RD table.
2597 delete_global_type2_routes(bgp
, vpn
);
2598 delete_vni_type2_routes(bgp
, vpn
);
2602 * Delete all routes in the per-VNI route table.
2604 static void delete_all_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2606 struct bgp_dest
*dest
;
2607 struct bgp_path_info
*pi
, *nextpi
;
2609 /* Walk this VNI's MAC & IP route table and delete all routes. */
2610 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2611 dest
= bgp_route_next(dest
)) {
2612 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2613 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2614 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
2615 bgp_path_info_delete(dest
, pi
);
2616 bgp_path_info_reap(dest
, pi
);
2620 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2621 dest
= bgp_route_next(dest
)) {
2622 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2623 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2624 bgp_path_info_delete(dest
, pi
);
2625 bgp_path_info_reap(dest
, pi
);
2630 /* BUM traffic flood mode per-l2-vni */
2631 static int bgp_evpn_vni_flood_mode_get(struct bgp
*bgp
,
2632 struct bgpevpn
*vpn
)
2634 /* if flooding has been globally disabled per-vni mode is
2637 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
2638 return VXLAN_FLOOD_DISABLED
;
2640 /* if mcast group ip has been specified we use a PIM-SM MDT */
2641 if (vpn
->mcast_grp
.s_addr
!= INADDR_ANY
)
2642 return VXLAN_FLOOD_PIM_SM
;
2644 /* default is ingress replication */
2645 return VXLAN_FLOOD_HEAD_END_REPL
;
2649 * Update (and advertise) local routes for a VNI. Invoked upon the VNI
2650 * export RT getting modified or change to tunnel IP. Note that these
2651 * situations need the route in the per-VNI table as well as the global
2652 * table to be updated (as attributes change).
2654 int update_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2657 struct prefix_evpn p
;
2659 update_type1_routes_for_evi(bgp
, vpn
);
2661 /* Update and advertise the type-3 route (only one) followed by the
2662 * locally learnt type-2 routes (MACIP) - for this VNI.
2664 * RT-3 only if doing head-end replication
2666 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
2667 == VXLAN_FLOOD_HEAD_END_REPL
) {
2668 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2669 ret
= update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
);
2674 update_all_type2_routes(bgp
, vpn
);
2679 * Delete (and withdraw) local routes for specified VNI from the global
2680 * table and per-VNI table. After this, remove all other routes from
2681 * the per-VNI table. Invoked upon the VNI being deleted or EVPN
2682 * (advertise-all-vni) being disabled.
2684 static int delete_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2687 struct prefix_evpn p
;
2689 /* Delete and withdraw locally learnt type-2 routes (MACIP)
2690 * followed by type-3 routes (only one) - for this VNI.
2692 delete_all_type2_routes(bgp
, vpn
);
2694 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2695 ret
= delete_evpn_route(bgp
, vpn
, &p
);
2699 /* Delete all routes from the per-VNI table. */
2700 delete_all_vni_routes(bgp
, vpn
);
2705 * There is a flood mcast IP address change. Update the mcast-grp and
2706 * remove the type-3 route if any. A new type-3 route will be generated
2707 * post tunnel_ip update if the new flood mode is head-end-replication.
2709 static int bgp_evpn_mcast_grp_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2710 struct in_addr mcast_grp
)
2712 struct prefix_evpn p
;
2714 vpn
->mcast_grp
= mcast_grp
;
2716 if (is_vni_live(vpn
)) {
2717 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2718 delete_evpn_route(bgp
, vpn
, &p
);
2725 * There is a tunnel endpoint IP address change for this VNI, delete
2726 * prior type-3 route (if needed) and update.
2727 * Note: Route re-advertisement happens elsewhere after other processing
2730 static void handle_tunnel_ip_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2731 struct in_addr originator_ip
)
2733 struct prefix_evpn p
;
2735 if (IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
))
2738 /* If VNI is not live, we only need to update the originator ip */
2739 if (!is_vni_live(vpn
)) {
2740 vpn
->originator_ip
= originator_ip
;
2744 /* Update the tunnel-ip hash */
2745 bgp_tip_del(bgp
, &vpn
->originator_ip
);
2746 if (bgp_tip_add(bgp
, &originator_ip
))
2747 /* The originator_ip was not already present in the
2748 * bgp martian next-hop table as a tunnel-ip, so we
2749 * need to go back and filter routes matching the new
2752 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
2754 /* Need to withdraw type-3 route as the originator IP is part
2757 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2758 delete_evpn_route(bgp
, vpn
, &p
);
2760 /* Update the tunnel IP and re-advertise all routes for this VNI. */
2761 vpn
->originator_ip
= originator_ip
;
2765 static struct bgp_path_info
*
2766 bgp_create_evpn_bgp_path_info(struct bgp_path_info
*parent_pi
,
2767 struct bgp_dest
*dest
, struct attr
*attr
)
2769 struct attr
*attr_new
;
2770 struct bgp_path_info
*pi
;
2772 /* Add (or update) attribute to hash. */
2773 attr_new
= bgp_attr_intern(attr
);
2775 /* Create new route with its attribute. */
2776 pi
= info_make(parent_pi
->type
, BGP_ROUTE_IMPORTED
, 0, parent_pi
->peer
,
2778 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
2779 bgp_path_info_extra_get(pi
);
2780 pi
->extra
->parent
= bgp_path_info_lock(parent_pi
);
2781 bgp_dest_lock_node((struct bgp_dest
*)parent_pi
->net
);
2782 if (parent_pi
->extra
) {
2783 memcpy(&pi
->extra
->label
, &parent_pi
->extra
->label
,
2784 sizeof(pi
->extra
->label
));
2785 pi
->extra
->num_labels
= parent_pi
->extra
->num_labels
;
2786 pi
->extra
->igpmetric
= parent_pi
->extra
->igpmetric
;
2789 bgp_path_info_add(dest
, pi
);
2795 * Install route entry into the VRF routing table and invoke route selection.
2797 static int install_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
2798 const struct prefix_evpn
*evp
,
2799 struct bgp_path_info
*parent_pi
)
2801 struct bgp_dest
*dest
;
2802 struct bgp_path_info
*pi
;
2804 struct attr
*attr_new
;
2807 struct prefix
*pp
= &p
;
2810 bool new_pi
= false;
2811 bool use_l3nhg
= false;
2812 bool is_l3nhg_active
= false;
2813 char buf1
[INET6_ADDRSTRLEN
];
2815 memset(pp
, 0, sizeof(struct prefix
));
2816 ip_prefix_from_evpn_prefix(evp
, pp
);
2818 if (bgp_debug_zebra(NULL
))
2820 "vrf %s: import evpn prefix %pFX parent %p flags 0x%x",
2821 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
2824 /* Create (or fetch) route within the VRF. */
2825 /* NOTE: There is no RD here. */
2826 if (is_evpn_prefix_ipaddr_v4(evp
)) {
2828 safi
= SAFI_UNICAST
;
2829 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2830 } else if (is_evpn_prefix_ipaddr_v6(evp
)) {
2832 safi
= SAFI_UNICAST
;
2833 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2837 /* EVPN routes currently only support a IPv4 next hop which corresponds
2838 * to the remote VTEP. When importing into a VRF, if it is IPv6 host
2839 * or prefix route, we have to convert the next hop to an IPv4-mapped
2840 * address for the rest of the code to flow through. In the case of IPv4,
2841 * make sure to set the flag for next hop attribute.
2843 attr
= *parent_pi
->attr
;
2844 if (attr
.evpn_overlay
.type
!= OVERLAY_INDEX_GATEWAY_IP
) {
2846 evpn_convert_nexthop_to_ipv6(&attr
);
2848 attr
.nexthop
= attr
.mp_nexthop_global_in
;
2849 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2854 * If gateway IP overlay index is specified in the NLRI of
2855 * EVPN RT-5, this gateway IP should be used as the nexthop
2856 * for the prefix in the VRF
2858 if (bgp_debug_zebra(NULL
)) {
2860 "Install gateway IP %s as nexthop for prefix %pFX in vrf %s",
2861 inet_ntop(pp
->family
, &attr
.evpn_overlay
.gw_ip
,
2862 buf1
, sizeof(buf1
)), pp
,
2863 vrf_id_to_name(bgp_vrf
->vrf_id
));
2866 if (afi
== AFI_IP6
) {
2867 memcpy(&attr
.mp_nexthop_global
,
2868 &attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
2869 sizeof(struct in6_addr
));
2870 attr
.mp_nexthop_len
= IPV6_MAX_BYTELEN
;
2872 attr
.nexthop
= attr
.evpn_overlay
.gw_ip
.ipaddr_v4
;
2873 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2877 bgp_evpn_es_vrf_use_nhg(bgp_vrf
, &parent_pi
->attr
->esi
, &use_l3nhg
,
2878 &is_l3nhg_active
, NULL
);
2880 attr
.es_flags
|= ATTR_ES_L3_NHG_USE
;
2881 if (is_l3nhg_active
)
2882 attr
.es_flags
|= ATTR_ES_L3_NHG_ACTIVE
;
2884 /* Check if route entry is already present. */
2885 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2887 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
2891 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
, &attr
);
2894 if (attrhash_cmp(pi
->attr
, &attr
)
2895 && !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2896 bgp_dest_unlock_node(dest
);
2899 /* The attribute has changed. */
2900 /* Add (or update) attribute to hash. */
2901 attr_new
= bgp_attr_intern(&attr
);
2903 /* Restore route, if needed. */
2904 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
2905 bgp_path_info_restore(dest
, pi
);
2907 /* Mark if nexthop has changed. */
2909 && !IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
2911 && !IPV6_ADDR_SAME(&pi
->attr
->mp_nexthop_global
,
2912 &attr_new
->mp_nexthop_global
)))
2913 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
2915 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
2916 /* Unintern existing, set to new. */
2917 bgp_attr_unintern(&pi
->attr
);
2918 pi
->attr
= attr_new
;
2919 pi
->uptime
= monotime(NULL
);
2922 /* Gateway IP nexthop should be resolved */
2923 if (attr
.evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
2924 if (bgp_find_or_add_nexthop(bgp_vrf
, bgp_vrf
, afi
, safi
, pi
,
2926 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_VALID
);
2928 if (BGP_DEBUG(nht
, NHT
)) {
2929 inet_ntop(pp
->family
,
2930 &attr
.evpn_overlay
.gw_ip
,
2931 buf1
, sizeof(buf1
));
2932 zlog_debug("%s: gateway IP NH unresolved",
2935 bgp_path_info_unset_flag(dest
, pi
, BGP_PATH_VALID
);
2939 /* as it is an importation, change nexthop */
2940 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ANNC_NH_SELF
);
2943 /* Link path to evpn nexthop */
2944 bgp_evpn_path_nh_add(bgp_vrf
, pi
);
2946 bgp_aggregate_increment(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
2949 /* Perform route selection and update zebra, if required. */
2950 bgp_process(bgp_vrf
, dest
, afi
, safi
);
2952 /* Process for route leaking. */
2953 vpn_leak_from_vrf_update(bgp_get_default(), bgp_vrf
, pi
);
2955 bgp_dest_unlock_node(dest
);
2957 if (bgp_debug_zebra(NULL
))
2958 zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)",
2959 new_pi
? "new" : "update", dest
,
2960 bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
2967 * Common handling for vni route tables install/selection.
2969 static int install_evpn_route_entry_in_vni_common(
2970 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
2971 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
2973 struct bgp_path_info
*pi
;
2974 struct bgp_path_info
*local_pi
;
2975 struct attr
*attr_new
;
2977 bool old_local_es
= false;
2980 /* Check if route entry is already present. */
2981 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2983 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
2987 /* Create an info */
2988 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
,
2991 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
2992 if (is_evpn_type2_dest_ipaddr_none(dest
))
2993 evpn_type2_path_info_set_ip(
2994 pi
, p
->prefix
.macip_addr
.ip
);
2996 evpn_type2_path_info_set_mac(
2997 pi
, p
->prefix
.macip_addr
.mac
);
3000 new_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3002 /* Return early if attributes haven't changed
3003 * and dest isn't flagged for removal.
3004 * dest will be unlocked by either
3005 * install_evpn_route_entry_in_vni_mac() or
3006 * install_evpn_route_entry_in_vni_ip()
3008 if (attrhash_cmp(pi
->attr
, parent_pi
->attr
) &&
3009 !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3011 /* The attribute has changed. */
3012 /* Add (or update) attribute to hash. */
3013 attr_new
= bgp_attr_intern(parent_pi
->attr
);
3015 /* Restore route, if needed. */
3016 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3017 bgp_path_info_restore(dest
, pi
);
3019 /* Mark if nexthop has changed. */
3020 if (!IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
3021 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
3023 old_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3024 new_local_es
= bgp_evpn_attr_is_local_es(attr_new
);
3025 /* If ESI is different or if its type has changed we
3026 * need to reinstall the path in zebra
3028 if ((old_local_es
!= new_local_es
)
3029 || memcmp(&pi
->attr
->esi
, &attr_new
->esi
,
3030 sizeof(attr_new
->esi
))) {
3032 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
3033 zlog_debug("VNI %d path %pFX chg to %s es",
3034 vpn
->vni
, &pi
->net
->p
,
3035 new_local_es
? "local"
3037 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
3040 /* Unintern existing, set to new. */
3041 bgp_attr_unintern(&pi
->attr
);
3042 pi
->attr
= attr_new
;
3043 pi
->uptime
= monotime(NULL
);
3046 /* Add this route to remote IP hashtable */
3047 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
3049 /* Perform route selection and update zebra, if required. */
3050 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3052 /* if the best path is a local path with a non-zero ES
3053 * sync info against the local path may need to be updated
3054 * when a remote path is added/updated (including changes
3055 * from sync-path to remote-path)
3057 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3058 if (local_pi
&& (old_local_es
|| new_local_es
))
3059 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3066 * Common handling for vni route tables uninstall/selection.
3068 static int uninstall_evpn_route_entry_in_vni_common(
3069 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
3070 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
3072 struct bgp_path_info
*pi
;
3073 struct bgp_path_info
*local_pi
;
3076 /* Find matching route entry. */
3077 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3079 (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3085 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
3087 /* Mark entry for deletion */
3088 bgp_path_info_delete(dest
, pi
);
3090 /* Perform route selection and update zebra, if required. */
3091 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3093 /* if the best path is a local path with a non-zero ES
3094 * sync info against the local path may need to be updated
3095 * when a remote path is deleted
3097 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3098 if (local_pi
&& bgp_evpn_attr_is_local_es(local_pi
->attr
))
3099 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3106 * Install route entry into VNI IP table and invoke route selection.
3108 static int install_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3109 struct bgpevpn
*vpn
,
3110 const struct prefix_evpn
*p
,
3111 struct bgp_path_info
*parent_pi
)
3114 struct bgp_dest
*dest
;
3116 /* Ignore MAC Only Type-2 */
3117 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3118 (is_evpn_prefix_ipaddr_none(p
) == true))
3121 /* Create (or fetch) route within the VNI IP table. */
3122 dest
= bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
3124 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3127 bgp_dest_unlock_node(dest
);
3133 * Install route entry into VNI MAC table and invoke route selection.
3135 static int install_evpn_route_entry_in_vni_mac(struct bgp
*bgp
,
3136 struct bgpevpn
*vpn
,
3137 const struct prefix_evpn
*p
,
3138 struct bgp_path_info
*parent_pi
)
3141 struct bgp_dest
*dest
;
3143 /* Only type-2 routes go into this table */
3144 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3147 /* Create (or fetch) route within the VNI MAC table. */
3148 dest
= bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
3150 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3153 bgp_dest_unlock_node(dest
);
3159 * Uninstall route entry from VNI IP table and invoke route selection.
3161 static int uninstall_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3162 struct bgpevpn
*vpn
,
3163 const struct prefix_evpn
*p
,
3164 struct bgp_path_info
*parent_pi
)
3167 struct bgp_dest
*dest
;
3169 /* Ignore MAC Only Type-2 */
3170 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3171 (is_evpn_prefix_ipaddr_none(p
) == true))
3174 /* Locate route within the VNI IP table. */
3175 dest
= bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
3179 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3182 bgp_dest_unlock_node(dest
);
3188 * Uninstall route entry from VNI IP table and invoke route selection.
3191 uninstall_evpn_route_entry_in_vni_mac(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3192 const struct prefix_evpn
*p
,
3193 struct bgp_path_info
*parent_pi
)
3196 struct bgp_dest
*dest
;
3198 /* Only type-2 routes go into this table */
3199 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3202 /* Locate route within the VNI MAC table. */
3203 dest
= bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
, parent_pi
);
3207 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3210 bgp_dest_unlock_node(dest
);
3215 * Uninstall route entry from the VRF routing table and send message
3216 * to zebra, if appropriate.
3218 static int uninstall_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
3219 const struct prefix_evpn
*evp
,
3220 struct bgp_path_info
*parent_pi
)
3222 struct bgp_dest
*dest
;
3223 struct bgp_path_info
*pi
;
3226 struct prefix
*pp
= &p
;
3230 memset(pp
, 0, sizeof(struct prefix
));
3231 ip_prefix_from_evpn_prefix(evp
, pp
);
3233 if (bgp_debug_zebra(NULL
))
3235 "vrf %s: unimport evpn prefix %pFX parent %p flags 0x%x",
3236 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
3239 /* Locate route within the VRF. */
3240 /* NOTE: There is no RD here. */
3241 if (is_evpn_prefix_ipaddr_v4(evp
)) {
3243 safi
= SAFI_UNICAST
;
3244 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3247 safi
= SAFI_UNICAST
;
3248 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3254 /* Find matching route entry. */
3255 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3257 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3261 bgp_dest_unlock_node(dest
);
3265 if (bgp_debug_zebra(NULL
))
3266 zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)",
3267 dest
, bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
3270 /* Process for route leaking. */
3271 vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf
, pi
);
3273 bgp_aggregate_decrement(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
3276 /* Mark entry for deletion */
3277 bgp_path_info_delete(dest
, pi
);
3279 /* Unlink path to evpn nexthop */
3280 bgp_evpn_path_nh_del(bgp_vrf
, pi
);
3282 /* Perform route selection and update zebra, if required. */
3283 bgp_process(bgp_vrf
, dest
, afi
, safi
);
3285 /* Unlock route node. */
3286 bgp_dest_unlock_node(dest
);
3292 * Install route entry into the VNI routing tables.
3294 static int install_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3295 const struct prefix_evpn
*p
,
3296 struct bgp_path_info
*parent_pi
)
3300 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3302 "%s (%u): Installing EVPN %pFX route in VNI %u IP/MAC table",
3303 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3305 ret
= install_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3310 "%s (%u): Failed to install EVPN %pFX route in VNI %u MAC table",
3311 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3316 ret
= install_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3321 "%s (%u): Failed to install EVPN %pFX route in VNI %u IP table",
3322 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3331 * Uninstall route entry from the VNI routing tables.
3333 static int uninstall_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3334 const struct prefix_evpn
*p
,
3335 struct bgp_path_info
*parent_pi
)
3339 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3341 "%s (%u): Uninstalling EVPN %pFX route from VNI %u IP/MAC table",
3342 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3344 ret
= uninstall_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3349 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u IP table",
3350 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3355 ret
= uninstall_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3360 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u MAC table",
3361 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3370 * Given a route entry and a VRF, see if this route entry should be
3371 * imported into the VRF i.e., RTs match.
3373 static int is_route_matching_for_vrf(struct bgp
*bgp_vrf
,
3374 struct bgp_path_info
*pi
)
3376 struct attr
*attr
= pi
->attr
;
3377 struct ecommunity
*ecom
;
3381 /* Route should have valid RT to be even considered. */
3382 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3385 ecom
= bgp_attr_get_ecommunity(attr
);
3386 if (!ecom
|| !ecom
->size
)
3389 /* For each extended community RT, see if it matches this VNI. If any RT
3390 * matches, we're done.
3392 for (i
= 0; i
< ecom
->size
; i
++) {
3394 uint8_t type
, sub_type
;
3395 struct ecommunity_val
*eval
;
3396 struct ecommunity_val eval_tmp
;
3397 struct vrf_irt_node
*irt
;
3399 /* Only deal with RTs */
3400 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3401 eval
= (struct ecommunity_val
*)(ecom
->val
3402 + (i
* ecom
->unit_size
));
3405 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3408 /* See if this RT matches specified VNIs import RTs */
3409 irt
= lookup_vrf_import_rt(eval
);
3411 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3414 /* Also check for non-exact match. In this, we mask out the AS
3416 * only check on the local-admin sub-field. This is to
3418 * VNI as the RT for EBGP peering too.
3421 if (type
== ECOMMUNITY_ENCODE_AS
3422 || type
== ECOMMUNITY_ENCODE_AS4
3423 || type
== ECOMMUNITY_ENCODE_IP
) {
3424 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3425 mask_ecom_global_admin(&eval_tmp
, eval
);
3426 irt
= lookup_vrf_import_rt(&eval_tmp
);
3429 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3437 * Given a route entry and a VNI, see if this route entry should be
3438 * imported into the VNI i.e., RTs match.
3440 static int is_route_matching_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3441 struct bgp_path_info
*pi
)
3443 struct attr
*attr
= pi
->attr
;
3444 struct ecommunity
*ecom
;
3448 /* Route should have valid RT to be even considered. */
3449 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3452 ecom
= bgp_attr_get_ecommunity(attr
);
3453 if (!ecom
|| !ecom
->size
)
3456 /* For each extended community RT, see if it matches this VNI. If any RT
3457 * matches, we're done.
3459 for (i
= 0; i
< ecom
->size
; i
++) {
3461 uint8_t type
, sub_type
;
3462 struct ecommunity_val
*eval
;
3463 struct ecommunity_val eval_tmp
;
3464 struct irt_node
*irt
;
3466 /* Only deal with RTs */
3467 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3468 eval
= (struct ecommunity_val
*)(ecom
->val
3469 + (i
* ecom
->unit_size
));
3472 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3475 /* See if this RT matches specified VNIs import RTs */
3476 irt
= lookup_import_rt(bgp
, eval
);
3478 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3481 /* Also check for non-exact match. In this, we mask out the AS
3483 * only check on the local-admin sub-field. This is to
3485 * VNI as the RT for EBGP peering too.
3488 if (type
== ECOMMUNITY_ENCODE_AS
3489 || type
== ECOMMUNITY_ENCODE_AS4
3490 || type
== ECOMMUNITY_ENCODE_IP
) {
3491 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3492 mask_ecom_global_admin(&eval_tmp
, eval
);
3493 irt
= lookup_import_rt(bgp
, &eval_tmp
);
3496 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3503 /* This API will scan evpn routes for checking attribute's rmac
3504 * macthes with bgp instance router mac. It avoid installing
3505 * route into bgp vrf table and remote rmac in bridge table.
3507 static int bgp_evpn_route_rmac_self_check(struct bgp
*bgp_vrf
,
3508 const struct prefix_evpn
*evp
,
3509 struct bgp_path_info
*pi
)
3511 /* evpn route could have learnt prior to L3vni has come up,
3512 * perform rmac check before installing route and
3513 * remote router mac.
3514 * The route will be removed from global bgp table once
3515 * SVI comes up with MAC and stored in hash, triggers
3516 * bgp_mac_rescan_all_evpn_tables.
3518 if (memcmp(&bgp_vrf
->rmac
, &pi
->attr
->rmac
, ETH_ALEN
) == 0) {
3519 if (bgp_debug_update(pi
->peer
, NULL
, NULL
, 1)) {
3520 char attr_str
[BUFSIZ
] = {0};
3522 bgp_dump_attr(pi
->attr
, attr_str
, sizeof(attr_str
));
3525 "%s: bgp %u prefix %pFX with attr %s - DENIED due to self mac",
3526 __func__
, bgp_vrf
->vrf_id
, evp
, attr_str
);
3535 /* don't import hosts that are locally attached */
3537 bgp_evpn_skip_vrf_import_of_local_es(struct bgp
*bgp_vrf
,
3538 const struct prefix_evpn
*evp
,
3539 struct bgp_path_info
*pi
, int install
)
3543 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
3544 esi
= bgp_evpn_attr_get_esi(pi
->attr
);
3546 /* Don't import routes that point to a local destination */
3547 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
3548 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
3549 char esi_buf
[ESI_STR_LEN
];
3552 "vrf %s of evpn prefix %pFX skipped, local es %s",
3553 install
? "import" : "unimport", evp
,
3554 esi_to_str(esi
, esi_buf
,
3564 * Install or uninstall a mac-ip route in the provided vrf if
3565 * there is a rt match
3567 int bgp_evpn_route_entry_install_if_vrf_match(struct bgp
*bgp_vrf
,
3568 struct bgp_path_info
*pi
,
3572 const struct prefix_evpn
*evp
=
3573 (const struct prefix_evpn
*)bgp_dest_get_prefix(pi
->net
);
3575 /* Consider "valid" remote routes applicable for
3578 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3579 && pi
->type
== ZEBRA_ROUTE_BGP
3580 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3583 if (is_route_matching_for_vrf(bgp_vrf
, pi
)) {
3584 if (bgp_evpn_route_rmac_self_check(bgp_vrf
, evp
, pi
))
3587 /* don't import hosts that are locally attached */
3588 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3589 bgp_vrf
, evp
, pi
, install
))
3593 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3595 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3599 flog_err(EC_BGP_EVPN_FAIL
,
3600 "Failed to %s EVPN %pFX route in VRF %s",
3601 install
? "install" : "uninstall", evp
,
3602 vrf_id_to_name(bgp_vrf
->vrf_id
));
3609 * Install or uninstall mac-ip routes are appropriate for this
3612 static int install_uninstall_routes_for_vrf(struct bgp
*bgp_vrf
, int install
)
3616 struct bgp_dest
*rd_dest
, *dest
;
3617 struct bgp_table
*table
;
3618 struct bgp_path_info
*pi
;
3620 struct bgp
*bgp_evpn
= NULL
;
3624 bgp_evpn
= bgp_get_evpn();
3628 /* Walk entire global routing table and evaluate routes which could be
3629 * imported into this VRF. Note that we need to loop through all global
3630 * routes to determine which route matches the import rt on vrf
3632 for (rd_dest
= bgp_table_top(bgp_evpn
->rib
[afi
][safi
]); rd_dest
;
3633 rd_dest
= bgp_route_next(rd_dest
)) {
3634 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3638 for (dest
= bgp_table_top(table
); dest
;
3639 dest
= bgp_route_next(dest
)) {
3640 const struct prefix_evpn
*evp
=
3641 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3644 /* if not mac-ip route skip this route */
3645 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3646 || evp
->prefix
.route_type
3647 == BGP_EVPN_IP_PREFIX_ROUTE
))
3650 /* if not a mac+ip route skip this route */
3651 if (!(is_evpn_prefix_ipaddr_v4(evp
)
3652 || is_evpn_prefix_ipaddr_v6(evp
)))
3655 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3657 ret
= bgp_evpn_route_entry_install_if_vrf_match(
3658 bgp_vrf
, pi
, install
);
3669 * Install or uninstall routes of specified type that are appropriate for this
3672 static int install_uninstall_routes_for_vni(struct bgp
*bgp
,
3673 struct bgpevpn
*vpn
,
3674 bgp_evpn_route_type rtype
,
3679 struct bgp_dest
*rd_dest
, *dest
;
3680 struct bgp_table
*table
;
3681 struct bgp_path_info
*pi
;
3687 /* Walk entire global routing table and evaluate routes which could be
3688 * imported into this VPN. Note that we cannot just look at the routes
3690 * the VNI's RD - remote routes applicable for this VNI could have any
3693 /* EVPN routes are a 2-level table. */
3694 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
3695 rd_dest
= bgp_route_next(rd_dest
)) {
3696 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3700 for (dest
= bgp_table_top(table
); dest
;
3701 dest
= bgp_route_next(dest
)) {
3702 const struct prefix_evpn
*evp
=
3703 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3706 if (evp
->prefix
.route_type
!= rtype
)
3709 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3711 /* Consider "valid" remote routes applicable for
3713 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3714 && pi
->type
== ZEBRA_ROUTE_BGP
3715 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3718 if (is_route_matching_for_vni(bgp
, vpn
, pi
)) {
3720 ret
= install_evpn_route_entry(
3723 ret
= uninstall_evpn_route_entry(
3729 "%u: Failed to %s EVPN %s route in VNI %u",
3733 rtype
== BGP_EVPN_MAC_IP_ROUTE
3738 bgp_dest_unlock_node(rd_dest
);
3739 bgp_dest_unlock_node(dest
);
3750 /* Install any existing remote routes applicable for this VRF into VRF RIB. This
3751 * is invoked upon l3vni-add or l3vni import rt change
3753 static int install_routes_for_vrf(struct bgp
*bgp_vrf
)
3755 install_uninstall_routes_for_vrf(bgp_vrf
, 1);
3760 * Install any existing remote routes applicable for this VNI into its
3761 * routing table. This is invoked when a VNI becomes "live" or its Import
3764 static int install_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3768 /* Install type-3 routes followed by type-2 routes - the ones applicable
3771 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3776 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3781 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3785 /* uninstall routes from l3vni vrf. */
3786 static int uninstall_routes_for_vrf(struct bgp
*bgp_vrf
)
3788 install_uninstall_routes_for_vrf(bgp_vrf
, 0);
3793 * Uninstall any existing remote routes for this VNI. One scenario in which
3794 * this is invoked is upon an import RT change.
3796 static int uninstall_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3800 /* Uninstall type-2 routes followed by type-3 routes - the ones
3804 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3809 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3815 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3820 * Install or uninstall route in matching VRFs (list).
3822 static int install_uninstall_route_in_vrfs(struct bgp
*bgp_def
, afi_t afi
,
3823 safi_t safi
, struct prefix_evpn
*evp
,
3824 struct bgp_path_info
*pi
,
3825 struct list
*vrfs
, int install
)
3827 struct bgp
*bgp_vrf
;
3828 struct listnode
*node
, *nnode
;
3830 /* Only type-2/type-5 routes go into a VRF */
3831 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3832 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3835 /* if it is type-2 route and not a mac+ip route skip this route */
3836 if ((evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3837 && !(is_evpn_prefix_ipaddr_v4(evp
)
3838 || is_evpn_prefix_ipaddr_v6(evp
)))
3841 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, bgp_vrf
)) {
3844 /* don't import hosts that are locally attached */
3845 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3846 bgp_vrf
, evp
, pi
, install
))
3850 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3852 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3856 flog_err(EC_BGP_EVPN_FAIL
,
3857 "%u: Failed to %s prefix %pFX in VRF %s",
3859 install
? "install" : "uninstall", evp
,
3860 vrf_id_to_name(bgp_vrf
->vrf_id
));
3869 * Install or uninstall route in matching VNIs (list).
3871 static int install_uninstall_route_in_vnis(struct bgp
*bgp
, afi_t afi
,
3872 safi_t safi
, struct prefix_evpn
*evp
,
3873 struct bgp_path_info
*pi
,
3874 struct list
*vnis
, int install
)
3876 struct bgpevpn
*vpn
;
3877 struct listnode
*node
, *nnode
;
3879 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, vpn
)) {
3882 if (!is_vni_live(vpn
))
3886 ret
= install_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3888 ret
= uninstall_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3891 flog_err(EC_BGP_EVPN_FAIL
,
3892 "%u: Failed to %s EVPN %s route in VNI %u",
3893 bgp
->vrf_id
, install
? "install" : "uninstall",
3894 evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3906 * Install or uninstall route for appropriate VNIs/ESIs.
3908 static int bgp_evpn_install_uninstall_table(struct bgp
*bgp
, afi_t afi
,
3909 safi_t safi
, const struct prefix
*p
,
3910 struct bgp_path_info
*pi
,
3911 int import
, bool in_vni_rt
,
3914 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
3915 struct attr
*attr
= pi
->attr
;
3916 struct ecommunity
*ecom
;
3918 struct prefix_evpn ad_evp
;
3922 /* Only type-1, type-2, type-3, type-4 and type-5
3923 * are supported currently
3925 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3926 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
3927 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
3928 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
3929 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3932 /* If we don't have Route Target, nothing much to do. */
3933 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3936 /* EAD prefix in the global table doesn't include the VTEP-IP so
3937 * we need to create a different copy for the VNI
3939 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
3940 evp
= evpn_type1_prefix_vni_ip_copy(&ad_evp
, evp
,
3943 ecom
= bgp_attr_get_ecommunity(attr
);
3944 if (!ecom
|| !ecom
->size
)
3947 /* An EVPN route belongs to a VNI or a VRF or an ESI based on the RTs
3948 * attached to the route */
3949 for (i
= 0; i
< ecom
->size
; i
++) {
3951 uint8_t type
, sub_type
;
3952 struct ecommunity_val
*eval
;
3953 struct ecommunity_val eval_tmp
;
3954 struct irt_node
*irt
; /* import rt for l2vni */
3955 struct vrf_irt_node
*vrf_irt
; /* import rt for l3vni */
3956 struct bgp_evpn_es
*es
;
3958 /* Only deal with RTs */
3959 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3960 eval
= (struct ecommunity_val
*)(ecom
->val
3961 + (i
* ecom
->unit_size
));
3964 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3967 /* non-local MAC-IP routes in the global route table are linked
3968 * to the destination ES
3970 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3971 bgp_evpn_path_es_link(pi
, 0,
3972 bgp_evpn_attr_get_esi(pi
->attr
));
3975 * macip routes (type-2) are imported into VNI and VRF tables.
3976 * IMET route is imported into VNI table.
3977 * prefix routes are imported into VRF table.
3979 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
||
3980 evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
||
3981 evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
||
3982 evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
3984 irt
= in_vni_rt
? lookup_import_rt(bgp
, eval
) : NULL
;
3986 install_uninstall_route_in_vnis(
3987 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
3990 vrf_irt
= in_vrf_rt
? lookup_vrf_import_rt(eval
) : NULL
;
3992 install_uninstall_route_in_vrfs(
3993 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
3996 /* Also check for non-exact match.
3997 * In this, we mask out the AS and
3998 * only check on the local-admin sub-field.
3999 * This is to facilitate using
4000 * VNI as the RT for EBGP peering too.
4004 if (type
== ECOMMUNITY_ENCODE_AS
4005 || type
== ECOMMUNITY_ENCODE_AS4
4006 || type
== ECOMMUNITY_ENCODE_IP
) {
4007 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
4008 mask_ecom_global_admin(&eval_tmp
, eval
);
4010 irt
= lookup_import_rt(bgp
, &eval_tmp
);
4013 lookup_vrf_import_rt(&eval_tmp
);
4017 install_uninstall_route_in_vnis(
4018 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
4021 install_uninstall_route_in_vrfs(
4022 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
4026 /* es route is imported into the es table */
4027 if (evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) {
4029 /* we will match based on the entire esi to avoid
4030 * import of an es route for esi2 into esi1
4032 es
= bgp_evpn_es_find(&evp
->prefix
.es_addr
.esi
);
4033 if (es
&& bgp_evpn_is_es_local(es
))
4034 bgp_evpn_es_route_install_uninstall(
4035 bgp
, es
, afi
, safi
, evp
, pi
, import
);
4043 * Install or uninstall route for appropriate VNIs/ESIs.
4045 static int install_uninstall_evpn_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
4046 const struct prefix
*p
,
4047 struct bgp_path_info
*pi
, int import
)
4049 return bgp_evpn_install_uninstall_table(bgp
, afi
, safi
, p
, pi
, import
,
4053 void bgp_evpn_import_type2_route(struct bgp_path_info
*pi
, int import
)
4055 struct bgp
*bgp_evpn
;
4057 bgp_evpn
= bgp_get_evpn();
4061 install_uninstall_evpn_route(bgp_evpn
, AFI_L2VPN
, SAFI_EVPN
,
4062 &pi
->net
->p
, pi
, import
);
4066 * delete and withdraw all ipv4 and ipv6 routes in the vrf table as type-5
4069 static void delete_withdraw_vrf_routes(struct bgp
*bgp_vrf
)
4071 /* Delete ipv4 default route and withdraw from peers */
4072 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4073 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4074 SAFI_UNICAST
, false);
4076 /* delete all ipv4 routes and withdraw from peers */
4077 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4078 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4080 /* Delete ipv6 default route and withdraw from peers */
4081 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4082 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4083 SAFI_UNICAST
, false);
4085 /* delete all ipv6 routes and withdraw from peers */
4086 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4087 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4091 * update and advertise all ipv4 and ipv6 routes in thr vrf table as type-5
4094 void update_advertise_vrf_routes(struct bgp
*bgp_vrf
)
4096 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
4098 bgp_evpn
= bgp_get_evpn();
4102 /* update all ipv4 routes */
4103 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4104 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4106 /* update ipv4 default route and withdraw from peers */
4107 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4108 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4109 SAFI_UNICAST
, true);
4111 /* update all ipv6 routes */
4112 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4113 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4115 /* update ipv6 default route and withdraw from peers */
4116 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4117 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4118 SAFI_UNICAST
, true);
4123 * update and advertise local routes for a VRF as type-5 routes.
4124 * This is invoked upon RD change for a VRF. Note taht the processing is only
4125 * done in the global route table using the routes which already exist in the
4128 static void update_router_id_vrf(struct bgp
*bgp_vrf
)
4130 /* skip if the RD is configured */
4131 if (is_vrf_rd_configured(bgp_vrf
))
4134 /* derive the RD for the VRF based on new router-id */
4135 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
4137 /* update advertise ipv4|ipv6 routes as type-5 routes */
4138 update_advertise_vrf_routes(bgp_vrf
);
4142 * Delete and withdraw all type-5 routes for the RD corresponding to VRF.
4143 * This is invoked upon VRF RD change. The processing is done only from global
4146 static void withdraw_router_id_vrf(struct bgp
*bgp_vrf
)
4148 /* skip if the RD is configured */
4149 if (is_vrf_rd_configured(bgp_vrf
))
4152 /* delete/withdraw ipv4|ipv6 routes as type-5 routes */
4153 delete_withdraw_vrf_routes(bgp_vrf
);
4156 static void update_advertise_vni_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
4157 struct bgp_dest
*dest
)
4159 struct bgp_dest
*global_dest
;
4160 struct bgp_path_info
*pi
, *global_pi
;
4162 afi_t afi
= AFI_L2VPN
;
4163 safi_t safi
= SAFI_EVPN
;
4165 struct prefix_evpn tmp_evp
;
4166 const struct prefix_evpn
*evp
=
4167 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
4170 * We have already processed type-3 routes.
4171 * Process only type-1 and type-2 routes here.
4173 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
4174 evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
)
4177 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4178 if (pi
->peer
== bgp
->peer_self
&& pi
->type
== ZEBRA_ROUTE_BGP
&&
4179 pi
->sub_type
== BGP_ROUTE_STATIC
)
4185 * VNI table MAC-IP prefixes don't have MAC so make sure it's
4186 * set from path info here.
4188 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4189 if (is_evpn_prefix_ipaddr_none(evp
)) {
4190 /* VNI MAC -> Global */
4191 evpn_type2_prefix_global_copy(
4192 &tmp_evp
, evp
, NULL
/* mac */,
4193 evpn_type2_path_info_get_ip(pi
));
4195 /* VNI IP -> Global */
4196 evpn_type2_prefix_global_copy(
4197 &tmp_evp
, evp
, evpn_type2_path_info_get_mac(pi
),
4201 memcpy(&tmp_evp
, evp
, sizeof(tmp_evp
));
4204 /* Create route in global routing table using this route entry's
4208 global_dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
4209 &tmp_evp
, &vpn
->prd
, NULL
);
4210 assert(global_dest
);
4212 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4214 update_evpn_route_entry(
4215 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4216 NULL
/* ip */, 1, &global_pi
, 0,
4217 mac_mobility_seqnum(attr
), false /* setup_sync */,
4218 NULL
/* old_is_sync */);
4221 struct bgp_evpn_es
*es
;
4222 int route_changed
= 0;
4224 es
= bgp_evpn_es_find(&evp
->prefix
.ead_addr
.esi
);
4225 bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, global_dest
,
4226 attr
, &global_pi
, &route_changed
);
4229 /* Schedule for processing and unlock node. */
4230 bgp_process(bgp
, global_dest
, afi
, safi
);
4231 bgp_dest_unlock_node(global_dest
);
4235 * Update and advertise local routes for a VNI. Invoked upon router-id
4236 * change. Note that the processing is done only on the global route table
4237 * using routes that already exist in the per-VNI table.
4239 static void update_advertise_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4241 struct prefix_evpn p
;
4242 struct bgp_dest
*dest
, *global_dest
;
4243 struct bgp_path_info
*pi
;
4245 afi_t afi
= AFI_L2VPN
;
4246 safi_t safi
= SAFI_EVPN
;
4248 /* Locate type-3 route for VNI in the per-VNI table and use its
4249 * attributes to create and advertise the type-3 route for this VNI
4250 * in the global table.
4252 * RT-3 only if doing head-end replication
4254 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4255 == VXLAN_FLOOD_HEAD_END_REPL
) {
4256 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4257 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
4258 if (!dest
) /* unexpected */
4260 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4261 if (pi
->peer
== bgp
->peer_self
&&
4262 pi
->type
== ZEBRA_ROUTE_BGP
4263 && pi
->sub_type
== BGP_ROUTE_STATIC
)
4266 bgp_dest_unlock_node(dest
);
4272 global_dest
= bgp_evpn_global_node_get(
4273 bgp
->rib
[afi
][safi
], afi
, safi
, &p
, &vpn
->prd
, NULL
);
4274 update_evpn_route_entry(
4275 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4276 NULL
/* ip */, 1, &pi
, 0, mac_mobility_seqnum(attr
),
4277 false /* setup_sync */, NULL
/* old_is_sync */);
4279 /* Schedule for processing and unlock node. */
4280 bgp_process(bgp
, global_dest
, afi
, safi
);
4281 bgp_dest_unlock_node(global_dest
);
4284 /* Now, walk this VNI's MAC & IP route table and use the route and its
4285 * attribute to create and schedule route in global table.
4287 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
4288 dest
= bgp_route_next(dest
))
4289 update_advertise_vni_route(bgp
, vpn
, dest
);
4291 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
4292 dest
= bgp_route_next(dest
))
4293 update_advertise_vni_route(bgp
, vpn
, dest
);
4297 * Delete (and withdraw) local routes for a VNI - only from the global
4298 * table. Invoked upon router-id change.
4300 static int delete_withdraw_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4302 struct prefix_evpn p
;
4303 struct bgp_dest
*global_dest
;
4304 struct bgp_path_info
*pi
;
4305 afi_t afi
= AFI_L2VPN
;
4306 safi_t safi
= SAFI_EVPN
;
4308 /* Delete and withdraw locally learnt type-2 routes (MACIP)
4309 * for this VNI - from the global table.
4311 delete_global_type2_routes(bgp
, vpn
);
4313 /* Remove type-3 route for this VNI from global table. */
4314 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4315 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], afi
,
4316 safi
, &p
, &vpn
->prd
, NULL
);
4318 /* Delete route entry in the global EVPN table. */
4319 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
4321 /* Schedule for processing - withdraws to peers happen from
4325 bgp_process(bgp
, global_dest
, afi
, safi
);
4326 bgp_dest_unlock_node(global_dest
);
4330 delete_global_ead_evi_routes(bgp
, vpn
);
4335 * Handle router-id change. Update and advertise local routes corresponding
4336 * to this VNI from peers. Note that this is invoked after updating the
4337 * router-id. The routes in the per-VNI table are used to create routes in
4338 * the global table and schedule them.
4340 static void update_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4342 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4344 /* Skip VNIs with configured RD. */
4345 if (is_rd_configured(vpn
))
4348 bgp_evpn_derive_auto_rd(bgp
, vpn
);
4349 update_advertise_vni_routes(bgp
, vpn
);
4353 * Handle router-id change. Delete and withdraw local routes corresponding
4354 * to this VNI from peers. Note that this is invoked prior to updating
4355 * the router-id and is done only on the global route table, the routes
4356 * are needed in the per-VNI table to re-advertise with new router id.
4358 static void withdraw_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4360 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4362 /* Skip VNIs with configured RD. */
4363 if (is_rd_configured(vpn
))
4366 delete_withdraw_vni_routes(bgp
, vpn
);
4370 * Create RT-3 for a VNI and schedule for processing and advertisement.
4371 * This is invoked upon flooding mode changing to head-end replication.
4373 static void create_advertise_type3(struct hash_bucket
*bucket
, void *data
)
4375 struct bgpevpn
*vpn
= bucket
->data
;
4376 struct bgp
*bgp
= data
;
4377 struct prefix_evpn p
;
4379 if (!vpn
|| !is_vni_live(vpn
) ||
4380 bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4381 != VXLAN_FLOOD_HEAD_END_REPL
)
4384 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4385 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
))
4386 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
4387 "Type3 route creation failure for VNI %u", vpn
->vni
);
4391 * Delete RT-3 for a VNI and schedule for processing and withdrawal.
4392 * This is invoked upon flooding mode changing to drop BUM packets.
4394 static void delete_withdraw_type3(struct hash_bucket
*bucket
, void *data
)
4396 struct bgpevpn
*vpn
= bucket
->data
;
4397 struct bgp
*bgp
= data
;
4398 struct prefix_evpn p
;
4400 if (!vpn
|| !is_vni_live(vpn
))
4403 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4404 delete_evpn_route(bgp
, vpn
, &p
);
4408 * Process received EVPN type-2 route (advertise or withdraw).
4410 static int process_type2_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4411 struct attr
*attr
, uint8_t *pfx
, int psize
,
4412 uint32_t addpath_id
)
4414 struct prefix_rd prd
;
4415 struct prefix_evpn p
= {};
4416 struct bgp_route_evpn evpn
= {};
4418 uint8_t macaddr_len
;
4419 /* holds the VNI(s) as in packet */
4420 mpls_label_t label
[BGP_MAX_LABELS
] = {};
4421 uint32_t num_labels
= 0;
4425 /* Type-2 route should be either 33, 37 or 49 bytes or an
4426 * additional 3 bytes if there is a second label (VNI):
4427 * RD (8), ESI (10), Eth Tag (4), MAC Addr Len (1),
4428 * MAC Addr (6), IP len (1), IP (0, 4 or 16),
4429 * MPLS Lbl1 (3), MPLS Lbl2 (0 or 3)
4431 if (psize
!= 33 && psize
!= 37 && psize
!= 49 && psize
!= 36
4432 && psize
!= 40 && psize
!= 52) {
4433 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4434 "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
4435 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4439 struct stream
*pkt
= stream_new(psize
);
4440 stream_put(pkt
, pfx
, psize
);
4442 /* Make prefix_rd */
4443 prd
.family
= AF_UNSPEC
;
4446 STREAM_GET(&prd
.val
, pkt
, 8);
4448 /* Make EVPN prefix. */
4450 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4451 p
.prefix
.route_type
= BGP_EVPN_MAC_IP_ROUTE
;
4453 /* Copy Ethernet Seg Identifier */
4455 STREAM_GET(&attr
->esi
, pkt
, sizeof(esi_t
));
4457 if (bgp_evpn_is_esi_local_and_non_bypass(&attr
->esi
))
4458 attr
->es_flags
|= ATTR_ES_IS_LOCAL
;
4460 attr
->es_flags
&= ~ATTR_ES_IS_LOCAL
;
4462 STREAM_FORWARD_GETP(pkt
, sizeof(esi_t
));
4465 /* Copy Ethernet Tag */
4466 STREAM_GET(ð_tag
, pkt
, 4);
4467 p
.prefix
.macip_addr
.eth_tag
= ntohl(eth_tag
);
4469 /* Get the MAC Addr len */
4470 STREAM_GETC(pkt
, macaddr_len
);
4472 /* Get the MAC Addr */
4473 if (macaddr_len
== (ETH_ALEN
* 8)) {
4474 STREAM_GET(&p
.prefix
.macip_addr
.mac
.octet
, pkt
, ETH_ALEN
);
4477 EC_BGP_EVPN_ROUTE_INVALID
,
4478 "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
4479 peer
->bgp
->vrf_id
, peer
->host
, macaddr_len
);
4485 STREAM_GETC(pkt
, ipaddr_len
);
4487 if (ipaddr_len
!= 0 && ipaddr_len
!= IPV4_MAX_BITLEN
4488 && ipaddr_len
!= IPV6_MAX_BITLEN
) {
4490 EC_BGP_EVPN_ROUTE_INVALID
,
4491 "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
4492 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4497 ipaddr_len
/= 8; /* Convert to bytes. */
4498 p
.prefix
.macip_addr
.ip
.ipa_type
= (ipaddr_len
== IPV4_MAX_BYTELEN
)
4501 STREAM_GET(&p
.prefix
.macip_addr
.ip
.ip
.addr
, pkt
, ipaddr_len
);
4504 /* Get the VNI(s). Stored as bytes here. */
4505 STREAM_GET(&label
[0], pkt
, BGP_LABEL_BYTES
);
4508 /* Do we have a second VNI? */
4509 if (STREAM_READABLE(pkt
)) {
4511 STREAM_GET(&label
[1], pkt
, BGP_LABEL_BYTES
);
4514 /* Process the route. */
4516 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4517 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4518 &label
[0], num_labels
, 0, &evpn
);
4520 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4521 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
[0],
4527 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4528 "%u:%s - Rx EVPN Type-2 NLRI - corrupt, discarding",
4529 peer
->bgp
->vrf_id
, peer
->host
);
4537 * Process received EVPN type-3 route (advertise or withdraw).
4539 static int process_type3_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4540 struct attr
*attr
, uint8_t *pfx
, int psize
,
4541 uint32_t addpath_id
)
4543 struct prefix_rd prd
;
4544 struct prefix_evpn p
;
4548 /* Type-3 route should be either 17 or 29 bytes: RD (8), Eth Tag (4),
4549 * IP len (1) and IP (4 or 16).
4551 if (psize
!= 17 && psize
!= 29) {
4552 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4553 "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
4554 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4558 /* If PMSI is present, log if it is anything other than IR.
4559 * Note: We just simply ignore the values as it is not clear if
4560 * doing anything else is better.
4563 (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
))) {
4564 enum pta_type pmsi_tnl_type
= bgp_attr_get_pmsi_tnl_type(attr
);
4566 if (pmsi_tnl_type
!= PMSI_TNLTYPE_INGR_REPL
4567 && pmsi_tnl_type
!= PMSI_TNLTYPE_PIM_SM
) {
4569 EC_BGP_EVPN_PMSI_PRESENT
,
4570 "%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d",
4571 peer
->bgp
->vrf_id
, peer
->host
, pmsi_tnl_type
);
4575 /* Make prefix_rd */
4576 prd
.family
= AF_UNSPEC
;
4578 memcpy(&prd
.val
, pfx
, 8);
4581 /* Make EVPN prefix. */
4582 memset(&p
, 0, sizeof(p
));
4584 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4585 p
.prefix
.route_type
= BGP_EVPN_IMET_ROUTE
;
4587 /* Copy Ethernet Tag */
4588 memcpy(ð_tag
, pfx
, 4);
4589 p
.prefix
.imet_addr
.eth_tag
= ntohl(eth_tag
);
4593 ipaddr_len
= *pfx
++;
4594 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
4595 p
.prefix
.imet_addr
.ip
.ipa_type
= IPADDR_V4
;
4596 memcpy(&p
.prefix
.imet_addr
.ip
.ip
.addr
, pfx
, IPV4_MAX_BYTELEN
);
4599 EC_BGP_EVPN_ROUTE_INVALID
,
4600 "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
4601 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4605 /* Process the route. */
4607 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4608 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
,
4611 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4612 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
, 0,
4618 * Process received EVPN type-5 route (advertise or withdraw).
4620 static int process_type5_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4621 struct attr
*attr
, uint8_t *pfx
, int psize
,
4622 uint32_t addpath_id
)
4624 struct prefix_rd prd
;
4625 struct prefix_evpn p
;
4626 struct bgp_route_evpn evpn
;
4629 mpls_label_t label
; /* holds the VNI as in the packet */
4630 bool is_valid_update
= true;
4632 /* Type-5 route should be 34 or 58 bytes:
4633 * RD (8), ESI (10), Eth Tag (4), IP len (1), IP (4 or 16),
4634 * GW (4 or 16) and VNI (3).
4635 * Note that the IP and GW should both be IPv4 or both IPv6.
4637 if (psize
!= 34 && psize
!= 58) {
4638 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4639 "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
4640 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4644 /* Make prefix_rd */
4645 prd
.family
= AF_UNSPEC
;
4647 memcpy(&prd
.val
, pfx
, 8);
4650 /* Make EVPN prefix. */
4651 memset(&p
, 0, sizeof(p
));
4653 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4654 p
.prefix
.route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
4656 /* Additional information outside of prefix - ESI and GW IP */
4657 memset(&evpn
, 0, sizeof(evpn
));
4659 /* Fetch ESI overlay index */
4661 memcpy(&evpn
.eth_s_id
, pfx
, sizeof(esi_t
));
4664 /* Fetch Ethernet Tag. */
4665 memcpy(ð_tag
, pfx
, 4);
4666 p
.prefix
.prefix_addr
.eth_tag
= ntohl(eth_tag
);
4669 /* Fetch IP prefix length. */
4671 if (ippfx_len
> IPV6_MAX_BITLEN
) {
4673 EC_BGP_EVPN_ROUTE_INVALID
,
4674 "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
4675 peer
->bgp
->vrf_id
, peer
->host
, ippfx_len
);
4678 p
.prefix
.prefix_addr
.ip_prefix_length
= ippfx_len
;
4680 /* Determine IPv4 or IPv6 prefix */
4681 /* Since the address and GW are from the same family, this just becomes
4682 * a simple check on the total size.
4685 SET_IPADDR_V4(&p
.prefix
.prefix_addr
.ip
);
4686 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v4
, pfx
, 4);
4688 SET_IPADDR_V4(&evpn
.gw_ip
);
4689 memcpy(&evpn
.gw_ip
.ipaddr_v4
, pfx
, 4);
4692 SET_IPADDR_V6(&p
.prefix
.prefix_addr
.ip
);
4693 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v6
, pfx
,
4695 pfx
+= IPV6_MAX_BYTELEN
;
4696 SET_IPADDR_V6(&evpn
.gw_ip
);
4697 memcpy(&evpn
.gw_ip
.ipaddr_v6
, pfx
, IPV6_MAX_BYTELEN
);
4698 pfx
+= IPV6_MAX_BYTELEN
;
4701 /* Get the VNI (in MPLS label field). Stored as bytes here. */
4702 memset(&label
, 0, sizeof(label
));
4703 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
4706 * If in future, we are required to access additional fields,
4707 * we MUST increment pfx by BGP_LABEL_BYTES in before reading the next
4712 * An update containing a non-zero gateway IP and a non-zero ESI
4713 * at the same time is should be treated as withdraw
4715 if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4716 !ipaddr_is_zero(&evpn
.gw_ip
)) {
4717 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4718 "%s - Rx EVPN Type-5 ESI and gateway-IP both non-zero.",
4720 is_valid_update
= false;
4721 } else if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
))
4722 evpn
.type
= OVERLAY_INDEX_ESI
;
4723 else if (!ipaddr_is_zero(&evpn
.gw_ip
))
4724 evpn
.type
= OVERLAY_INDEX_GATEWAY_IP
;
4726 if (is_zero_mac(&attr
->rmac
) &&
4727 !bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4728 ipaddr_is_zero(&evpn
.gw_ip
) && label
== 0) {
4729 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4730 "%s - Rx EVPN Type-5 ESI, gateway-IP, RMAC and label all zero",
4732 is_valid_update
= false;
4735 if (is_mcast_mac(&attr
->rmac
) || is_bcast_mac(&attr
->rmac
))
4736 is_valid_update
= false;
4739 /* Process the route. */
4740 if (attr
&& is_valid_update
)
4741 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4742 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4743 &label
, 1, 0, &evpn
);
4745 if (!is_valid_update
) {
4746 char attr_str
[BUFSIZ
] = {0};
4748 bgp_dump_attr(attr
, attr_str
, BUFSIZ
);
4750 "Invalid update from peer %s vrf %u prefix %pFX attr %s - treat as withdraw",
4751 peer
->hostname
, peer
->bgp
->vrf_id
, &p
,
4754 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, afi
, safi
,
4755 ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, &label
, 1,
4762 static void evpn_mpattr_encode_type5(struct stream
*s
, const struct prefix
*p
,
4763 const struct prefix_rd
*prd
,
4764 mpls_label_t
*label
, uint32_t num_labels
,
4769 const struct evpn_addr
*p_evpn_p
;
4771 memset(&temp
, 0, sizeof(temp
));
4772 if (p
->family
!= AF_EVPN
)
4774 p_evpn_p
= &(p
->u
.prefix_evpn
);
4776 /* len denites the total len of IP and GW-IP in the route
4777 IP and GW-IP have to be both ipv4 or ipv6
4779 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4780 len
= 8; /* IP and GWIP are both ipv4 */
4782 len
= 32; /* IP and GWIP are both ipv6 */
4783 /* Prefix contains RD, ESI, EthTag, IP length, IP, GWIP and VNI */
4784 stream_putc(s
, 8 + 10 + 4 + 1 + len
+ 3);
4785 stream_put(s
, prd
->val
, 8);
4786 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_ESI
)
4787 stream_put(s
, &attr
->esi
, sizeof(esi_t
));
4789 stream_put(s
, 0, sizeof(esi_t
));
4790 stream_putl(s
, p_evpn_p
->prefix_addr
.eth_tag
);
4791 stream_putc(s
, p_evpn_p
->prefix_addr
.ip_prefix_length
);
4792 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4793 stream_put_ipv4(s
, p_evpn_p
->prefix_addr
.ip
.ipaddr_v4
.s_addr
);
4795 stream_put(s
, &p_evpn_p
->prefix_addr
.ip
.ipaddr_v6
, 16);
4796 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
4797 const struct bgp_route_evpn
*evpn_overlay
=
4798 bgp_attr_get_evpn_overlay(attr
);
4800 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4802 evpn_overlay
->gw_ip
.ipaddr_v4
.s_addr
);
4804 stream_put(s
, &(evpn_overlay
->gw_ip
.ipaddr_v6
), 16);
4806 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4807 stream_put_ipv4(s
, 0);
4809 stream_put(s
, &temp
, 16);
4813 stream_put(s
, label
, 3);
4819 * Cleanup specific VNI upon EVPN (advertise-all-vni) being disabled.
4821 static void cleanup_vni_on_disable(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4823 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4825 /* Remove EVPN routes and schedule for processing. */
4826 delete_routes_for_vni(bgp
, vpn
);
4828 /* Clear "live" flag and see if hash needs to be freed. */
4829 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
4830 if (!is_vni_configured(vpn
))
4831 bgp_evpn_free(bgp
, vpn
);
4835 * Free a VNI entry; iterator function called during cleanup.
4837 static void free_vni_entry(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4839 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4841 delete_all_vni_routes(bgp
, vpn
);
4842 bgp_evpn_free(bgp
, vpn
);
4846 * Derive AUTO import RT for BGP VRF - L3VNI
4848 static void evpn_auto_rt_import_add_for_vrf(struct bgp
*bgp_vrf
)
4850 struct bgp
*bgp_evpn
= NULL
;
4852 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
, true);
4855 bgp_evpn
= bgp_get_evpn();
4860 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
4864 * Delete AUTO import RT from BGP VRF - L3VNI
4866 static void evpn_auto_rt_import_delete_for_vrf(struct bgp
*bgp_vrf
)
4868 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
,
4873 * Derive AUTO export RT for BGP VRF - L3VNI
4875 static void evpn_auto_rt_export_add_for_vrf(struct bgp
*bgp_vrf
)
4877 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
, true);
4881 * Delete AUTO export RT from BGP VRF - L3VNI
4883 static void evpn_auto_rt_export_delete_for_vrf(struct bgp
*bgp_vrf
)
4885 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
,
4889 static void bgp_evpn_handle_export_rt_change_for_vrf(struct bgp
*bgp_vrf
)
4891 struct bgp
*bgp_evpn
= NULL
;
4892 struct listnode
*node
= NULL
;
4893 struct bgpevpn
*vpn
= NULL
;
4895 bgp_evpn
= bgp_get_evpn();
4899 /* update all type-5 routes */
4900 update_advertise_vrf_routes(bgp_vrf
);
4902 /* update all type-2 routes */
4903 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
4904 update_routes_for_vni(bgp_evpn
, vpn
);
4908 * Handle autort change for a given VNI.
4910 static void update_autort_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4912 struct bgpevpn
*vpn
= bucket
->data
;
4914 if (!is_import_rt_configured(vpn
)) {
4915 if (is_vni_live(vpn
))
4916 bgp_evpn_uninstall_routes(bgp
, vpn
);
4917 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
4918 list_delete_all_node(vpn
->import_rtl
);
4919 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
4920 if (is_vni_live(vpn
))
4921 bgp_evpn_install_routes(bgp
, vpn
);
4923 if (!is_export_rt_configured(vpn
)) {
4924 list_delete_all_node(vpn
->export_rtl
);
4925 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
4926 if (is_vni_live(vpn
))
4927 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
4932 * Handle autort change for L3VNI.
4934 static void update_autort_l3vni(struct bgp
*bgp
)
4936 if ((CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
4937 && (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)))
4940 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
4941 if (is_l3vni_live(bgp
))
4942 uninstall_routes_for_vrf(bgp
);
4944 /* Cleanup the RT to VRF mapping */
4945 bgp_evpn_unmap_vrf_from_its_rts(bgp
);
4947 /* Remove auto generated RT */
4948 evpn_auto_rt_import_delete_for_vrf(bgp
);
4950 list_delete_all_node(bgp
->vrf_import_rtl
);
4952 /* Map auto derive or configured RTs */
4953 evpn_auto_rt_import_add_for_vrf(bgp
);
4956 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4957 list_delete_all_node(bgp
->vrf_export_rtl
);
4959 evpn_auto_rt_export_delete_for_vrf(bgp
);
4961 evpn_auto_rt_export_add_for_vrf(bgp
);
4963 if (is_l3vni_live(bgp
))
4964 bgp_evpn_map_vrf_to_its_rts(bgp
);
4967 if (!is_l3vni_live(bgp
))
4970 /* advertise type-5 routes if needed */
4971 update_advertise_vrf_routes(bgp
);
4973 /* install all remote routes belonging to this l3vni
4974 * into corresponding vrf
4976 install_routes_for_vrf(bgp
);
4983 /* withdraw type-5 route corresponding to ip prefix */
4984 void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
4985 afi_t afi
, safi_t safi
)
4988 struct prefix_evpn evp
;
4990 build_type5_prefix_from_ip_prefix(&evp
, p
);
4991 ret
= delete_evpn_type5_route(bgp_vrf
, &evp
);
4994 EC_BGP_EVPN_ROUTE_DELETE
,
4995 "%u failed to delete type-5 route for prefix %pFX in vrf %s",
4996 bgp_vrf
->vrf_id
, p
, vrf_id_to_name(bgp_vrf
->vrf_id
));
4999 /* withdraw all type-5 routes for an address family */
5000 void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
, safi_t safi
)
5002 struct bgp_table
*table
= NULL
;
5003 struct bgp_dest
*dest
= NULL
;
5004 struct bgp_path_info
*pi
;
5006 table
= bgp_vrf
->rib
[afi
][safi
];
5007 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5008 /* Only care about "selected" routes. Also ensure that
5009 * these are routes that are injectable into EVPN.
5011 /* TODO: Support for AddPath for EVPN. */
5012 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5013 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5014 && is_route_injectable_into_evpn(pi
)) {
5015 bgp_evpn_withdraw_type5_route(
5016 bgp_vrf
, bgp_dest_get_prefix(dest
), afi
,
5025 * evpn - enable advertisement of default g/w
5027 void bgp_evpn_install_uninstall_default_route(struct bgp
*bgp_vrf
, afi_t afi
,
5028 safi_t safi
, bool add
)
5030 struct prefix ip_prefix
;
5032 /* form the default prefix 0.0.0.0/0 */
5033 memset(&ip_prefix
, 0, sizeof(ip_prefix
));
5034 ip_prefix
.family
= afi2family(afi
);
5037 bgp_evpn_advertise_type5_route(bgp_vrf
, &ip_prefix
,
5040 bgp_evpn_withdraw_type5_route(bgp_vrf
, &ip_prefix
,
5047 * Advertise IP prefix as type-5 route. The afi/safi and src_attr passed
5048 * to this function correspond to those of the source IP prefix (best
5049 * path in the case of the attr. In the case of a local prefix (when we
5050 * are advertising local subnets), the src_attr will be NULL.
5052 void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
5053 struct attr
*src_attr
, afi_t afi
,
5057 struct prefix_evpn evp
;
5059 build_type5_prefix_from_ip_prefix(&evp
, p
);
5060 ret
= update_evpn_type5_route(bgp_vrf
, &evp
, src_attr
, afi
, safi
);
5062 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
5063 "%u: Failed to create type-5 route for prefix %pFX",
5064 bgp_vrf
->vrf_id
, p
);
5067 /* Inject all prefixes of a particular address-family (currently, IPv4 or
5068 * IPv6 unicast) into EVPN as type-5 routes. This is invoked when the
5069 * advertisement is enabled.
5071 void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
5074 struct bgp_table
*table
= NULL
;
5075 struct bgp_dest
*dest
= NULL
;
5076 struct bgp_path_info
*pi
;
5078 table
= bgp_vrf
->rib
[afi
][safi
];
5079 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5080 /* Need to identify the "selected" route entry to use its
5081 * attribute. Also, ensure that the route is injectable
5083 * TODO: Support for AddPath for EVPN.
5085 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5086 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5087 && is_route_injectable_into_evpn(pi
)) {
5089 /* apply the route-map */
5090 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
) {
5091 route_map_result_t ret
;
5092 struct bgp_path_info tmp_pi
;
5093 struct bgp_path_info_extra tmp_pie
;
5094 struct attr tmp_attr
;
5096 tmp_attr
= *pi
->attr
;
5098 /* Fill temp path_info */
5099 prep_for_rmap_apply(&tmp_pi
, &tmp_pie
,
5103 RESET_FLAG(tmp_attr
.rmap_change_flags
);
5105 ret
= route_map_apply(
5106 bgp_vrf
->adv_cmd_rmap
[afi
][safi
]
5108 bgp_dest_get_prefix(dest
),
5110 if (ret
== RMAP_DENYMATCH
) {
5111 bgp_attr_flush(&tmp_attr
);
5114 bgp_evpn_advertise_type5_route(
5116 bgp_dest_get_prefix(dest
),
5117 &tmp_attr
, afi
, safi
);
5119 bgp_evpn_advertise_type5_route(
5121 bgp_dest_get_prefix(dest
),
5122 pi
->attr
, afi
, safi
);
5129 static void rt_list_remove_node(struct list
*rt_list
,
5130 struct ecommunity
*ecomdel
, bool is_l3
)
5132 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
5133 struct vrf_route_target
*l3rt
= NULL
;
5134 struct ecommunity
*ecom
= NULL
;
5137 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5138 if (ecommunity_match(l3rt
->ecom
, ecomdel
)) {
5139 evpn_vrf_rt_del(l3rt
);
5145 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, ecom
)) {
5146 if (ecommunity_match(ecom
, ecomdel
)) {
5147 ecommunity_free(&ecom
);
5156 list_delete_node(rt_list
, node_to_del
);
5159 void evpn_rt_delete_auto(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
,
5162 struct ecommunity
*ecom_auto
;
5163 struct ecommunity_val eval
;
5165 if (bgp
->advertise_autort_rfc8365
)
5166 vni
|= EVPN_AUTORT_VXLAN
;
5168 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
);
5170 ecom_auto
= ecommunity_new();
5171 ecommunity_add_val(ecom_auto
, &eval
, false, false);
5173 rt_list_remove_node(rtl
, ecom_auto
, is_l3
);
5175 ecommunity_free(&ecom_auto
);
5178 static void evpn_vrf_rt_routes_map(struct bgp
*bgp_vrf
)
5180 /* map VRFs to its RTs and install routes matching this new RT */
5181 if (is_l3vni_live(bgp_vrf
)) {
5182 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
5183 install_routes_for_vrf(bgp_vrf
);
5187 static void evpn_vrf_rt_routes_unmap(struct bgp
*bgp_vrf
)
5189 /* uninstall routes from vrf */
5190 if (is_l3vni_live(bgp_vrf
))
5191 uninstall_routes_for_vrf(bgp_vrf
);
5193 /* Cleanup the RT to VRF mapping */
5194 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
5197 static bool rt_list_has_cfgd_rt(struct list
*rt_list
)
5199 struct listnode
*node
= NULL
, *nnode
= NULL
;
5200 struct vrf_route_target
*l3rt
= NULL
;
5202 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5203 if (!CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
))
5210 static void unconfigure_import_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5212 if (!bgp_vrf
->vrf_import_rtl
)
5213 return; /* this should never fail */
5215 if (!is_l3vni_live(bgp_vrf
))
5216 return; /* Nothing to do if no vni */
5218 /* fall back to auto-generated RT if this was the last RT */
5219 if (list_isempty(bgp_vrf
->vrf_import_rtl
))
5220 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5223 static void unconfigure_export_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5226 if (!bgp_vrf
->vrf_export_rtl
)
5227 return; /* this should never fail */
5229 if (!is_l3vni_live(bgp_vrf
))
5230 return; /* Nothing to do if no vni */
5232 /* fall back to auto-generated RT if this was the last RT */
5233 if (list_isempty(bgp_vrf
->vrf_export_rtl
))
5234 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5236 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5239 void bgp_evpn_configure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5240 struct ecommunity
*ecomadd
,
5243 struct vrf_route_target
*newrt
;
5245 newrt
= evpn_vrf_rt_new(ecomadd
);
5248 SET_FLAG(newrt
->flags
, BGP_VRF_RT_WILD
);
5250 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5252 /* Remove auto generated RT if not configured */
5253 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5254 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5256 /* Add the newly configured RT to RT list */
5257 listnode_add_sort(bgp_vrf
->vrf_import_rtl
, newrt
);
5259 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5261 evpn_vrf_rt_routes_map(bgp_vrf
);
5264 void bgp_evpn_configure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5266 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5267 return; /* Already configured */
5269 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5271 if (!is_l3vni_live(bgp_vrf
))
5272 return; /* Wait for VNI before adding rts */
5274 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5276 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5278 evpn_vrf_rt_routes_map(bgp_vrf
);
5281 void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5282 struct ecommunity
*ecomdel
)
5284 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
5285 return; /* Already un-configured */
5287 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5290 rt_list_remove_node(bgp_vrf
->vrf_import_rtl
, ecomdel
, true);
5292 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_import_rtl
))
5293 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5295 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5297 evpn_vrf_rt_routes_map(bgp_vrf
);
5300 void bgp_evpn_unconfigure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5302 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5303 return; /* Already un-configured */
5305 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5307 /* remove auto-generated RT */
5308 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5310 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5312 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5314 evpn_vrf_rt_routes_map(bgp_vrf
);
5317 void bgp_evpn_configure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5318 struct ecommunity
*ecomadd
)
5320 struct vrf_route_target
*newrt
;
5322 newrt
= evpn_vrf_rt_new(ecomadd
);
5324 /* Remove auto generated RT if not configured */
5325 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5326 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5328 /* Add the new RT to the RT list */
5329 listnode_add_sort(bgp_vrf
->vrf_export_rtl
, newrt
);
5331 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5333 if (is_l3vni_live(bgp_vrf
))
5334 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5337 void bgp_evpn_configure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5339 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5340 return; /* Already configured */
5342 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5344 if (!is_l3vni_live(bgp_vrf
))
5345 return; /* Wait for VNI before adding rts */
5347 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5349 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5352 void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5353 struct ecommunity
*ecomdel
)
5355 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
))
5356 return; /* Already un-configured */
5359 rt_list_remove_node(bgp_vrf
->vrf_export_rtl
, ecomdel
, true);
5361 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_export_rtl
))
5362 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5364 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5367 void bgp_evpn_unconfigure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5369 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5370 return; /* Already un-configured */
5372 /* remove auto-generated RT */
5373 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5375 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5377 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5381 * Handle change to BGP router id. This is invoked twice by the change
5382 * handler, first before the router id has been changed and then after
5383 * the router id has been changed. The first invocation will result in
5384 * local routes for all VNIs/VRF being deleted and withdrawn and the next
5385 * will result in the routes being re-advertised.
5387 void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
)
5389 struct listnode
*node
;
5390 struct bgp
*bgp_vrf
;
5394 /* delete and withdraw all the type-5 routes
5395 stored in the global table for this vrf
5397 withdraw_router_id_vrf(bgp
);
5399 /* delete all the VNI routes (type-2/type-3) routes for all the
5402 hash_iterate(bgp
->vnihash
,
5403 (void (*)(struct hash_bucket
*,
5404 void *))withdraw_router_id_vni
,
5407 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5408 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5409 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5410 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5412 bgp_vrf
->evpn_info
->pip_ip
.s_addr
5418 /* Assign new default instance router-id */
5419 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5420 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5421 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5422 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5424 bgp_vrf
->evpn_info
->pip_ip
=
5426 /* advertise type-5 routes with
5429 update_advertise_vrf_routes(bgp_vrf
);
5434 /* advertise all routes in the vrf as type-5 routes with the new
5437 update_router_id_vrf(bgp
);
5439 /* advertise all the VNI routes (type-2/type-3) routes with the
5442 hash_iterate(bgp
->vnihash
,
5443 (void (*)(struct hash_bucket
*,
5444 void *))update_router_id_vni
,
5450 * Handle change to auto-RT algorithm - update and advertise local routes.
5452 void bgp_evpn_handle_autort_change(struct bgp
*bgp
)
5454 hash_iterate(bgp
->vnihash
,
5455 (void (*)(struct hash_bucket
*,
5456 void*))update_autort_vni
,
5459 update_autort_l3vni(bgp
);
5463 * Handle change to export RT - update and advertise local routes.
5465 int bgp_evpn_handle_export_rt_change(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5467 return update_routes_for_vni(bgp
, vpn
);
5470 void bgp_evpn_handle_vrf_rd_change(struct bgp
*bgp_vrf
, int withdraw
)
5473 delete_withdraw_vrf_routes(bgp_vrf
);
5475 update_advertise_vrf_routes(bgp_vrf
);
5479 * Handle change to RD. This is invoked twice by the change handler,
5480 * first before the RD has been changed and then after the RD has
5481 * been changed. The first invocation will result in local routes
5482 * of this VNI being deleted and withdrawn and the next will result
5483 * in the routes being re-advertised.
5485 void bgp_evpn_handle_rd_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
5489 delete_withdraw_vni_routes(bgp
, vpn
);
5491 update_advertise_vni_routes(bgp
, vpn
);
5495 * Install routes for this VNI. Invoked upon change to Import RT.
5497 int bgp_evpn_install_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5499 return install_routes_for_vni(bgp
, vpn
);
5503 * Uninstall all routes installed for this VNI. Invoked upon change
5506 int bgp_evpn_uninstall_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5508 return uninstall_routes_for_vni(bgp
, vpn
);
5512 * TODO: Hardcoded for a maximum of 2 VNIs right now
5514 char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
, char *buf
,
5519 vni1
= label2vni(label
);
5520 if (num_labels
== 2) {
5521 vni2
= label2vni(label
+ 1);
5522 snprintf(buf
, len
, "%u/%u", vni1
, vni2
);
5524 snprintf(buf
, len
, "%u", vni1
);
5529 * Function to convert evpn route to json format.
5530 * NOTE: We don't use prefix2str as the output here is a bit different.
5532 void bgp_evpn_route2json(const struct prefix_evpn
*p
, json_object
*json
)
5534 char buf1
[ETHER_ADDR_STRLEN
];
5535 char buf2
[PREFIX2STR_BUFFER
];
5542 json_object_int_add(json
, "routeType", p
->prefix
.route_type
);
5544 switch (p
->prefix
.route_type
) {
5545 case BGP_EVPN_MAC_IP_ROUTE
:
5546 json_object_int_add(json
, "ethTag",
5547 p
->prefix
.macip_addr
.eth_tag
);
5548 json_object_int_add(json
, "macLen", 8 * ETH_ALEN
);
5549 json_object_string_add(json
, "mac",
5550 prefix_mac2str(&p
->prefix
.macip_addr
.mac
, buf1
,
5553 if (!is_evpn_prefix_ipaddr_none(p
)) {
5554 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
:
5556 prefixlen
= (family
== AF_INET
) ?
5557 IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN
;
5558 inet_ntop(family
, &p
->prefix
.macip_addr
.ip
.ip
.addr
,
5559 buf2
, PREFIX2STR_BUFFER
);
5560 json_object_int_add(json
, "ipLen", prefixlen
);
5561 json_object_string_add(json
, "ip", buf2
);
5565 case BGP_EVPN_IMET_ROUTE
:
5566 json_object_int_add(json
, "ethTag",
5567 p
->prefix
.imet_addr
.eth_tag
);
5568 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5569 prefixlen
= (family
== AF_INET
) ? IPV4_MAX_BITLEN
:
5571 inet_ntop(family
, &p
->prefix
.imet_addr
.ip
.ip
.addr
, buf2
,
5573 json_object_int_add(json
, "ipLen", prefixlen
);
5574 json_object_string_add(json
, "ip", buf2
);
5577 case BGP_EVPN_IP_PREFIX_ROUTE
:
5578 json_object_int_add(json
, "ethTag",
5579 p
->prefix
.prefix_addr
.eth_tag
);
5580 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5581 inet_ntop(family
, &p
->prefix
.prefix_addr
.ip
.ip
.addr
,
5582 buf2
, sizeof(buf2
));
5583 json_object_int_add(json
, "ipLen",
5584 p
->prefix
.prefix_addr
.ip_prefix_length
);
5585 json_object_string_add(json
, "ip", buf2
);
5594 * Encode EVPN prefix in Update (MP_REACH)
5596 void bgp_evpn_encode_prefix(struct stream
*s
, const struct prefix
*p
,
5597 const struct prefix_rd
*prd
, mpls_label_t
*label
,
5598 uint32_t num_labels
, struct attr
*attr
,
5599 bool addpath_capable
, uint32_t addpath_tx_id
)
5601 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
5602 int len
, ipa_len
= 0;
5604 if (addpath_capable
)
5605 stream_putl(s
, addpath_tx_id
);
5608 stream_putc(s
, evp
->prefix
.route_type
);
5610 switch (evp
->prefix
.route_type
) {
5611 case BGP_EVPN_MAC_IP_ROUTE
:
5612 if (is_evpn_prefix_ipaddr_v4(evp
))
5613 ipa_len
= IPV4_MAX_BYTELEN
;
5614 else if (is_evpn_prefix_ipaddr_v6(evp
))
5615 ipa_len
= IPV6_MAX_BYTELEN
;
5616 /* RD, ESI, EthTag, MAC+len, IP len, [IP], 1 VNI */
5617 len
= 8 + 10 + 4 + 1 + 6 + 1 + ipa_len
+ 3;
5618 if (ipa_len
&& num_labels
> 1) /* There are 2 VNIs */
5620 stream_putc(s
, len
);
5621 stream_put(s
, prd
->val
, 8); /* RD */
5623 stream_put(s
, &attr
->esi
, ESI_BYTES
);
5625 stream_put(s
, 0, 10);
5626 stream_putl(s
, evp
->prefix
.macip_addr
.eth_tag
); /* Ethernet Tag ID */
5627 stream_putc(s
, 8 * ETH_ALEN
); /* Mac Addr Len - bits */
5628 stream_put(s
, evp
->prefix
.macip_addr
.mac
.octet
, 6); /* Mac Addr */
5629 stream_putc(s
, 8 * ipa_len
); /* IP address Length */
5630 if (ipa_len
) /* IP */
5631 stream_put(s
, &evp
->prefix
.macip_addr
.ip
.ip
.addr
,
5633 /* 1st label is the L2 VNI */
5634 stream_put(s
, label
, BGP_LABEL_BYTES
);
5635 /* Include 2nd label (L3 VNI) if advertising MAC+IP */
5636 if (ipa_len
&& num_labels
> 1)
5637 stream_put(s
, label
+ 1, BGP_LABEL_BYTES
);
5640 case BGP_EVPN_IMET_ROUTE
:
5641 stream_putc(s
, 17); // TODO: length - assumes IPv4 address
5642 stream_put(s
, prd
->val
, 8); /* RD */
5643 stream_putl(s
, evp
->prefix
.imet_addr
.eth_tag
); /* Ethernet Tag ID */
5644 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5645 /* Originating Router's IP Addr */
5646 stream_put_in_addr(s
, &evp
->prefix
.imet_addr
.ip
.ipaddr_v4
);
5649 case BGP_EVPN_ES_ROUTE
:
5650 stream_putc(s
, 23); /* TODO: length: assumes ipv4 VTEP */
5651 stream_put(s
, prd
->val
, 8); /* RD */
5652 stream_put(s
, evp
->prefix
.es_addr
.esi
.val
, 10); /* ESI */
5653 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5655 stream_put_in_addr(s
, &evp
->prefix
.es_addr
.ip
.ipaddr_v4
);
5658 case BGP_EVPN_AD_ROUTE
:
5659 /* RD, ESI, EthTag, 1 VNI */
5660 len
= RD_BYTES
+ ESI_BYTES
+ EVPN_ETH_TAG_BYTES
+ BGP_LABEL_BYTES
;
5661 stream_putc(s
, len
);
5662 stream_put(s
, prd
->val
, RD_BYTES
); /* RD */
5663 stream_put(s
, evp
->prefix
.ead_addr
.esi
.val
, ESI_BYTES
); /* ESI */
5664 stream_putl(s
, evp
->prefix
.ead_addr
.eth_tag
); /* Ethernet Tag */
5665 stream_put(s
, label
, BGP_LABEL_BYTES
);
5668 case BGP_EVPN_IP_PREFIX_ROUTE
:
5669 /* TODO: AddPath support. */
5670 evpn_mpattr_encode_type5(s
, p
, prd
, label
, num_labels
, attr
);
5678 int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
5679 struct bgp_nlri
*packet
, int withdraw
)
5685 uint32_t addpath_id
;
5686 bool addpath_capable
;
5691 /* Start processing the NLRI - there may be multiple in the MP_REACH */
5693 lim
= pnt
+ packet
->length
;
5695 safi
= packet
->safi
;
5698 addpath_capable
= bgp_addpath_encode_rx(peer
, afi
, safi
);
5700 for (; pnt
< lim
; pnt
+= psize
) {
5701 /* Clear prefix structure. */
5702 memset(&p
, 0, sizeof(p
));
5704 /* Deal with path-id if AddPath is supported. */
5705 if (addpath_capable
) {
5706 /* When packet overflow occurs return immediately. */
5707 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
5708 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5710 memcpy(&addpath_id
, pnt
, BGP_ADDPATH_ID_LEN
);
5711 addpath_id
= ntohl(addpath_id
);
5712 pnt
+= BGP_ADDPATH_ID_LEN
;
5715 /* All EVPN NLRI types start with type and length. */
5717 return BGP_NLRI_PARSE_ERROR_EVPN_MISSING_TYPE
;
5722 /* When packet overflow occur return immediately. */
5723 if (pnt
+ psize
> lim
)
5724 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5727 case BGP_EVPN_MAC_IP_ROUTE
:
5728 if (process_type2_route(peer
, afi
, safi
,
5729 withdraw
? NULL
: attr
, pnt
,
5730 psize
, addpath_id
)) {
5733 "%u:%s - Error in processing EVPN type-2 NLRI size %d",
5734 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5735 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE2_SIZE
;
5739 case BGP_EVPN_IMET_ROUTE
:
5740 if (process_type3_route(peer
, afi
, safi
,
5741 withdraw
? NULL
: attr
, pnt
,
5742 psize
, addpath_id
)) {
5745 "%u:%s - Error in processing EVPN type-3 NLRI size %d",
5746 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5747 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE3_SIZE
;
5751 case BGP_EVPN_ES_ROUTE
:
5752 if (bgp_evpn_type4_route_process(peer
, afi
, safi
,
5753 withdraw
? NULL
: attr
, pnt
,
5754 psize
, addpath_id
)) {
5757 "%u:%s - Error in processing EVPN type-4 NLRI size %d",
5758 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5759 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE4_SIZE
;
5763 case BGP_EVPN_AD_ROUTE
:
5764 if (bgp_evpn_type1_route_process(peer
, afi
, safi
,
5765 withdraw
? NULL
: attr
, pnt
,
5766 psize
, addpath_id
)) {
5769 "%u:%s - Error in processing EVPN type-1 NLRI size %d",
5770 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5771 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE
;
5775 case BGP_EVPN_IP_PREFIX_ROUTE
:
5776 if (process_type5_route(peer
, afi
, safi
,
5777 withdraw
? NULL
: attr
, pnt
,
5778 psize
, addpath_id
)) {
5781 "%u:%s - Error in processing EVPN type-5 NLRI size %d",
5782 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5783 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE5_SIZE
;
5792 /* Packet length consistency check. */
5794 return BGP_NLRI_PARSE_ERROR_PACKET_LENGTH
;
5796 return BGP_NLRI_PARSE_OK
;
5800 * Map the RTs (configured or automatically derived) of a VRF to the VRF.
5801 * The mapping will be used during route processing.
5802 * bgp_vrf: specific bgp vrf instance on which RT is configured
5804 void bgp_evpn_map_vrf_to_its_rts(struct bgp
*bgp_vrf
)
5806 struct listnode
*node
, *nnode
;
5807 struct vrf_route_target
*l3rt
;
5809 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5810 map_vrf_to_rt(bgp_vrf
, l3rt
);
5814 * Unmap the RTs (configured or automatically derived) of a VRF from the VRF.
5816 void bgp_evpn_unmap_vrf_from_its_rts(struct bgp
*bgp_vrf
)
5818 struct listnode
*node
, *nnode
;
5819 struct vrf_route_target
*l3rt
;
5821 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5822 unmap_vrf_from_rt(bgp_vrf
, l3rt
);
5826 * Map the RTs (configured or automatically derived) of a VNI to the VNI.
5827 * The mapping will be used during route processing.
5829 void bgp_evpn_map_vni_to_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5832 struct ecommunity_val
*eval
;
5833 struct listnode
*node
, *nnode
;
5834 struct ecommunity
*ecom
;
5836 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5837 for (i
= 0; i
< ecom
->size
; i
++) {
5838 eval
= (struct ecommunity_val
*)(ecom
->val
5840 * ECOMMUNITY_SIZE
));
5841 map_vni_to_rt(bgp
, vpn
, eval
);
5847 * Unmap the RTs (configured or automatically derived) of a VNI from the VNI.
5849 void bgp_evpn_unmap_vni_from_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5852 struct ecommunity_val
*eval
;
5853 struct listnode
*node
, *nnode
;
5854 struct ecommunity
*ecom
;
5856 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5857 for (i
= 0; i
< ecom
->size
; i
++) {
5858 struct irt_node
*irt
;
5859 struct ecommunity_val eval_tmp
;
5861 eval
= (struct ecommunity_val
*)(ecom
->val
5863 * ECOMMUNITY_SIZE
));
5864 /* If using "automatic" RT, we only care about the
5865 * local-admin sub-field.
5866 * This is to facilitate using VNI as the RT for EBGP
5869 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
5870 if (!is_import_rt_configured(vpn
))
5871 mask_ecom_global_admin(&eval_tmp
, eval
);
5873 irt
= lookup_import_rt(bgp
, &eval_tmp
);
5875 unmap_vni_from_rt(bgp
, vpn
, irt
);
5881 * Derive Import RT automatically for VNI and map VNI to RT.
5882 * The mapping will be used during route processing.
5884 void bgp_evpn_derive_auto_rt_import(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5886 form_auto_rt(bgp
, vpn
->vni
, vpn
->import_rtl
, false);
5887 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
5890 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
5894 * Derive Export RT automatically for VNI.
5896 void bgp_evpn_derive_auto_rt_export(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5898 form_auto_rt(bgp
, vpn
->vni
, vpn
->export_rtl
, false);
5899 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
5903 * Derive RD automatically for VNI using passed information - it
5904 * is of the form RouterId:unique-id-for-vni.
5906 void bgp_evpn_derive_auto_rd_for_vrf(struct bgp
*bgp
)
5908 if (is_vrf_rd_configured(bgp
))
5911 form_auto_rd(bgp
->router_id
, bgp
->vrf_rd_id
, &bgp
->vrf_prd
);
5915 * Derive RD automatically for VNI using passed information - it
5916 * is of the form RouterId:unique-id-for-vni.
5918 void bgp_evpn_derive_auto_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5920 char buf
[BGP_EVPN_PREFIX_RD_LEN
];
5922 vpn
->prd
.family
= AF_UNSPEC
;
5923 vpn
->prd
.prefixlen
= 64;
5924 snprintfrr(buf
, sizeof(buf
), "%pI4:%hu", &bgp
->router_id
, vpn
->rd_id
);
5925 (void)str2prefix_rd(buf
, &vpn
->prd
);
5926 if (vpn
->prd_pretty
)
5927 XFREE(MTYPE_BGP
, vpn
->prd_pretty
);
5928 UNSET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
5934 bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni
)
5936 struct list
*inst
= bm
->bgp
;
5937 struct listnode
*node
;
5938 struct bgp
*bgp_vrf
;
5940 for (ALL_LIST_ELEMENTS_RO(inst
, node
, bgp_vrf
)) {
5941 if (bgp_vrf
->l3vni
== vni
)
5951 struct bgpevpn
*bgp_evpn_lookup_vni(struct bgp
*bgp
, vni_t vni
)
5953 struct bgpevpn
*vpn
;
5956 memset(&tmp
, 0, sizeof(tmp
));
5958 vpn
= hash_lookup(bgp
->vnihash
, &tmp
);
5963 * Create a new vpn - invoked upon configuration or zebra notification.
5965 struct bgpevpn
*bgp_evpn_new(struct bgp
*bgp
, vni_t vni
,
5966 struct in_addr originator_ip
,
5967 vrf_id_t tenant_vrf_id
,
5968 struct in_addr mcast_grp
,
5969 ifindex_t svi_ifindex
)
5971 struct bgpevpn
*vpn
;
5973 vpn
= XCALLOC(MTYPE_BGP_EVPN
, sizeof(struct bgpevpn
));
5975 /* Set values - RD and RT set to defaults. */
5977 vpn
->originator_ip
= originator_ip
;
5978 vpn
->tenant_vrf_id
= tenant_vrf_id
;
5979 vpn
->mcast_grp
= mcast_grp
;
5980 vpn
->svi_ifindex
= svi_ifindex
;
5982 /* Initialize route-target import and export lists */
5983 vpn
->import_rtl
= list_new();
5984 vpn
->import_rtl
->cmp
=
5985 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
5986 vpn
->import_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
5987 vpn
->export_rtl
= list_new();
5988 vpn
->export_rtl
->cmp
=
5989 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
5990 vpn
->export_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
5991 bf_assign_index(bm
->rd_idspace
, vpn
->rd_id
);
5992 derive_rd_rt_for_vni(bgp
, vpn
);
5994 /* Initialize EVPN route tables. */
5995 vpn
->ip_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
5996 vpn
->mac_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
5999 (void)hash_get(bgp
->vnihash
, vpn
, hash_alloc_intern
);
6001 bgp_evpn_remote_ip_hash_init(vpn
);
6002 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6004 /* add to l2vni list on corresponding vrf */
6005 bgpevpn_link_to_l3vni(vpn
);
6007 bgp_evpn_vni_es_init(vpn
);
6009 QOBJ_REG(vpn
, bgpevpn
);
6014 * Free a given VPN - called in multiple scenarios such as zebra
6015 * notification, configuration being deleted, advertise-all-vni disabled etc.
6016 * This just frees appropriate memory, caller should have taken other
6019 void bgp_evpn_free(struct bgp
*bgp
, struct bgpevpn
*vpn
)
6021 bgp_evpn_remote_ip_hash_destroy(vpn
);
6022 bgp_evpn_vni_es_cleanup(vpn
);
6023 bgpevpn_unlink_from_l3vni(vpn
);
6024 bgp_table_unlock(vpn
->ip_table
);
6025 bgp_table_unlock(vpn
->mac_table
);
6026 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
6027 list_delete(&vpn
->import_rtl
);
6028 list_delete(&vpn
->export_rtl
);
6029 bf_release_index(bm
->rd_idspace
, vpn
->rd_id
);
6030 hash_release(bgp
->vni_svi_hash
, vpn
);
6031 hash_release(bgp
->vnihash
, vpn
);
6032 if (vpn
->prd_pretty
)
6033 XFREE(MTYPE_BGP
, vpn
->prd_pretty
);
6035 XFREE(MTYPE_BGP_EVPN
, vpn
);
6038 static void hash_evpn_free(struct bgpevpn
*vpn
)
6040 XFREE(MTYPE_BGP_EVPN
, vpn
);
6044 * Import evpn route from global table to VNI/VRF/ESI.
6046 int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6047 const struct prefix
*p
, struct bgp_path_info
*pi
)
6049 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 1);
6053 * Unimport evpn route from VNI/VRF/ESI.
6055 int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6056 const struct prefix
*p
, struct bgp_path_info
*pi
)
6058 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 0);
6061 /* filter routes which have martian next hops */
6062 int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
)
6066 struct bgp_dest
*rd_dest
, *dest
;
6067 struct bgp_table
*table
;
6068 struct bgp_path_info
*pi
;
6073 /* Walk entire global routing table and evaluate routes which could be
6074 * imported into this VPN. Note that we cannot just look at the routes
6075 * for the VNI's RD -
6076 * remote routes applicable for this VNI could have any RD.
6078 /* EVPN routes are a 2-level table. */
6079 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
6080 rd_dest
= bgp_route_next(rd_dest
)) {
6081 table
= bgp_dest_get_bgp_table_info(rd_dest
);
6085 for (dest
= bgp_table_top(table
); dest
;
6086 dest
= bgp_route_next(dest
)) {
6088 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
6091 /* Consider "valid" remote routes applicable for
6093 if (!(pi
->type
== ZEBRA_ROUTE_BGP
6094 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
6096 if (bgp_nexthop_self(bgp
, afi
, pi
->type
,
6097 pi
->sub_type
, pi
->attr
,
6099 const struct prefix
*p
=
6100 bgp_dest_get_prefix(dest
);
6102 if (bgp_debug_update(pi
->peer
, p
, NULL
,
6104 char attr_str
[BUFSIZ
] = {0};
6106 bgp_dump_attr(pi
->attr
,
6111 "%u: prefix %pBD with attr %s - DENIED due to martian or self nexthop",
6115 bgp_evpn_unimport_route(bgp
, afi
, safi
,
6118 bgp_rib_remove(dest
, pi
, pi
->peer
, afi
,
6129 * Handle del of a local MACIP.
6131 int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6132 struct ipaddr
*ip
, int state
)
6134 struct bgpevpn
*vpn
;
6135 struct prefix_evpn p
;
6136 struct bgp_dest
*dest
;
6138 /* Lookup VNI hash - should exist. */
6139 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6140 if (!vpn
|| !is_vni_live(vpn
)) {
6141 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6142 "%u: VNI hash entry for VNI %u %s at MACIP DEL",
6143 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6147 build_evpn_type2_prefix(&p
, mac
, ip
);
6148 if (state
== ZEBRA_NEIGH_ACTIVE
) {
6149 /* Remove EVPN type-2 route and schedule for processing. */
6150 delete_evpn_route(bgp
, vpn
, &p
);
6152 /* Re-instate the current remote best path if any */
6153 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
6155 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
6156 bgp_dest_unlock_node(dest
);
6164 * Handle add of a local MACIP.
6166 int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6167 struct ipaddr
*ip
, uint8_t flags
, uint32_t seq
, esi_t
*esi
)
6169 struct bgpevpn
*vpn
;
6170 struct prefix_evpn p
;
6172 /* Lookup VNI hash - should exist. */
6173 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6174 if (!vpn
|| !is_vni_live(vpn
)) {
6175 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6176 "%u: VNI hash entry for VNI %u %s at MACIP ADD",
6177 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6181 /* Create EVPN type-2 route and schedule for processing. */
6182 build_evpn_type2_prefix(&p
, mac
, ip
);
6183 if (update_evpn_route(bgp
, vpn
, &p
, flags
, seq
, esi
)) {
6185 EC_BGP_EVPN_ROUTE_CREATE
,
6186 "%u:Failed to create Type-2 route, VNI %u %s MAC %pEA IP %pIA (flags: 0x%x)",
6187 bgp
->vrf_id
, vpn
->vni
,
6188 CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
)
6198 static void link_l2vni_hash_to_l3vni(struct hash_bucket
*bucket
,
6199 struct bgp
*bgp_vrf
)
6201 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6202 struct bgp
*bgp_evpn
= NULL
;
6204 bgp_evpn
= bgp_get_evpn();
6207 if (vpn
->tenant_vrf_id
== bgp_vrf
->vrf_id
)
6208 bgpevpn_link_to_l3vni(vpn
);
6211 int bgp_evpn_local_l3vni_add(vni_t l3vni
, vrf_id_t vrf_id
,
6212 struct ethaddr
*svi_rmac
,
6213 struct ethaddr
*vrr_rmac
,
6214 struct in_addr originator_ip
, int filter
,
6215 ifindex_t svi_ifindex
,
6216 bool is_anycast_mac
)
6218 struct bgp
*bgp_vrf
= NULL
; /* bgp VRF instance */
6219 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6220 struct listnode
*node
= NULL
;
6221 struct bgpevpn
*vpn
= NULL
;
6224 /* get the EVPN instance - required to get the AS number for VRF
6227 bgp_evpn
= bgp_get_evpn();
6231 "Cannot process L3VNI %u ADD - EVPN BGP instance not yet created",
6237 /* if the BGP vrf instance doesn't exist - create one */
6238 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6243 ret
= bgp_get_vty(&bgp_vrf
, &as
, vrf_id_to_name(vrf_id
),
6244 vrf_id
== VRF_DEFAULT
6245 ? BGP_INSTANCE_TYPE_DEFAULT
6246 : BGP_INSTANCE_TYPE_VRF
,
6247 NULL
, ASNOTATION_UNDEFINED
);
6249 case BGP_ERR_AS_MISMATCH
:
6250 flog_err(EC_BGP_EVPN_AS_MISMATCH
,
6251 "BGP instance is already running; AS is %s",
6252 bgp_vrf
->as_pretty
);
6254 case BGP_ERR_INSTANCE_MISMATCH
:
6255 flog_err(EC_BGP_EVPN_INSTANCE_MISMATCH
,
6256 "BGP instance type mismatch");
6260 /* mark as auto created */
6261 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
);
6264 /* associate the vrf with l3vni and related parameters */
6265 bgp_vrf
->l3vni
= l3vni
;
6266 bgp_vrf
->originator_ip
= originator_ip
;
6267 bgp_vrf
->l3vni_svi_ifindex
= svi_ifindex
;
6268 bgp_vrf
->evpn_info
->is_anycast_mac
= is_anycast_mac
;
6270 /* copy anycast MAC from VRR MAC */
6271 memcpy(&bgp_vrf
->rmac
, vrr_rmac
, ETH_ALEN
);
6272 /* copy sys RMAC from SVI MAC */
6273 memcpy(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, svi_rmac
, ETH_ALEN
);
6274 /* PIP user configured mac is not present use svi mac as sys mac */
6275 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
))
6276 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
, svi_rmac
, ETH_ALEN
);
6278 if (bgp_debug_zebra(NULL
))
6280 "VRF %s vni %u pip %s RMAC %pEA sys RMAC %pEA static RMAC %pEA is_anycast_mac %s",
6281 vrf_id_to_name(bgp_vrf
->vrf_id
), bgp_vrf
->l3vni
,
6282 bgp_vrf
->evpn_info
->advertise_pip
? "enable"
6284 &bgp_vrf
->rmac
, &bgp_vrf
->evpn_info
->pip_rmac
,
6285 &bgp_vrf
->evpn_info
->pip_rmac_static
,
6286 is_anycast_mac
? "Enable" : "Disable");
6288 /* set the right filter - are we using l3vni only for prefix routes? */
6290 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6293 * VNI_FLAG_USE_TWO_LABELS flag for linked L2VNIs should not be
6294 * set before linking vrf to L3VNI. Thus, no need to clear
6298 UNSET_FLAG(bgp_vrf
->vrf_flags
,
6299 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6301 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6302 if (!CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
6305 * If we are flapping VNI_FLAG_USE_TWO_LABELS
6306 * flag, update all MACIP routes in this VNI
6308 SET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6309 update_all_type2_routes(bgp_evpn
, vpn
);
6314 /* Map auto derive or configured RTs */
6315 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
) ||
6316 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
6317 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
6319 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
6321 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
) ||
6322 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
6323 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
6325 /* auto derive RD */
6326 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
6328 /* link all corresponding l2vnis */
6329 hash_iterate(bgp_evpn
->vnihash
,
6330 (void (*)(struct hash_bucket
*,
6331 void *))link_l2vni_hash_to_l3vni
,
6334 /* Only update all corresponding type-2 routes if we are advertising two
6335 * labels along with type-2 routes
6338 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
6339 update_routes_for_vni(bgp_evpn
, vpn
);
6341 /* advertise type-5 routes if needed */
6342 update_advertise_vrf_routes(bgp_vrf
);
6344 /* install all remote routes belonging to this l3vni into correspondng
6346 install_routes_for_vrf(bgp_vrf
);
6351 int bgp_evpn_local_l3vni_del(vni_t l3vni
, vrf_id_t vrf_id
)
6353 struct bgp
*bgp_vrf
= NULL
; /* bgp vrf instance */
6354 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6355 struct listnode
*node
= NULL
;
6356 struct listnode
*next
= NULL
;
6357 struct bgpevpn
*vpn
= NULL
;
6359 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6363 "Cannot process L3VNI %u Del - Could not find BGP instance",
6368 bgp_evpn
= bgp_get_evpn();
6372 "Cannot process L3VNI %u Del - Could not find EVPN BGP instance",
6377 /* Remove remote routes from BGT VRF even if BGP_VRF_AUTO is configured,
6378 * bgp_delete would not remove/decrement bgp_path_info of the ip_prefix
6379 * routes. This will uninstalling the routes from zebra and decremnt the
6382 uninstall_routes_for_vrf(bgp_vrf
);
6384 /* delete/withdraw all type-5 routes */
6385 delete_withdraw_vrf_routes(bgp_vrf
);
6387 /* remove the l3vni from vrf instance */
6390 /* remove the Rmac from the BGP vrf */
6391 memset(&bgp_vrf
->rmac
, 0, sizeof(struct ethaddr
));
6392 memset(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, 0, ETH_ALEN
);
6393 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
) &&
6394 !is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac
))
6395 memset(&bgp_vrf
->evpn_info
->pip_rmac
, 0, ETH_ALEN
);
6397 /* remove default import RT or Unmap non-default import RT */
6398 if (!list_isempty(bgp_vrf
->vrf_import_rtl
)) {
6399 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6400 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
6401 list_delete_all_node(bgp_vrf
->vrf_import_rtl
);
6404 /* remove default export RT */
6405 if (!list_isempty(bgp_vrf
->vrf_export_rtl
) &&
6406 !CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
6407 list_delete_all_node(bgp_vrf
->vrf_export_rtl
);
6410 /* update all corresponding local mac-ip routes */
6411 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)) {
6412 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6413 UNSET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6414 update_routes_for_vni(bgp_evpn
, vpn
);
6418 /* If any L2VNIs point to this instance, unlink them. */
6419 for (ALL_LIST_ELEMENTS(bgp_vrf
->l2vnis
, node
, next
, vpn
))
6420 bgpevpn_unlink_from_l3vni(vpn
);
6422 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6424 /* Delete the instance if it was autocreated */
6425 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
))
6426 bgp_delete(bgp_vrf
);
6432 * Handle del of a local VNI.
6434 int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
)
6436 struct bgpevpn
*vpn
;
6438 /* Locate VNI hash */
6439 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6443 /* Remove all local EVPN routes and schedule for processing (to
6444 * withdraw from peers).
6446 delete_routes_for_vni(bgp
, vpn
);
6448 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6450 vpn
->svi_ifindex
= 0;
6452 * tunnel is no longer active, del tunnel ip address from tip_hash
6454 bgp_tip_del(bgp
, &vpn
->originator_ip
);
6456 /* Clear "live" flag and see if hash needs to be freed. */
6457 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6458 if (!is_vni_configured(vpn
))
6459 bgp_evpn_free(bgp
, vpn
);
6465 * Handle add (or update) of a local VNI. The VNI changes we care
6466 * about are for the local-tunnel-ip and the (tenant) VRF.
6468 int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
6469 struct in_addr originator_ip
,
6470 vrf_id_t tenant_vrf_id
,
6471 struct in_addr mcast_grp
,
6472 ifindex_t svi_ifindex
)
6474 struct bgpevpn
*vpn
;
6475 struct prefix_evpn p
;
6477 /* Lookup VNI. If present and no change, exit. */
6478 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6481 if (is_vni_live(vpn
)
6482 && IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
)
6483 && IPV4_ADDR_SAME(&vpn
->mcast_grp
, &mcast_grp
)
6484 && vpn
->tenant_vrf_id
== tenant_vrf_id
6485 && vpn
->svi_ifindex
== svi_ifindex
)
6486 /* Probably some other param has changed that we don't
6490 bgp_evpn_mcast_grp_change(bgp
, vpn
, mcast_grp
);
6492 if (vpn
->svi_ifindex
!= svi_ifindex
) {
6495 * Unresolve all the gateway IP nexthops for this VNI
6498 bgp_evpn_remote_ip_hash_iterate(
6500 (void (*)(struct hash_bucket
*, void *))
6501 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6503 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6504 vpn
->svi_ifindex
= svi_ifindex
;
6505 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6508 * Resolve 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_link_nexthop
,
6518 /* Update tenant_vrf_id if it has changed. */
6519 if (vpn
->tenant_vrf_id
!= tenant_vrf_id
) {
6522 * Unresolve all the gateway IP nexthops for this VNI
6525 bgp_evpn_remote_ip_hash_iterate(
6527 (void (*)(struct hash_bucket
*, void *))
6528 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6530 bgpevpn_unlink_from_l3vni(vpn
);
6531 vpn
->tenant_vrf_id
= tenant_vrf_id
;
6532 bgpevpn_link_to_l3vni(vpn
);
6535 * Resolve 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_link_nexthop
,
6545 /* If tunnel endpoint IP has changed, update (and delete prior
6546 * type-3 route, if needed.)
6548 handle_tunnel_ip_change(bgp
, vpn
, originator_ip
);
6550 /* Update all routes with new endpoint IP and/or export RT
6553 if (is_vni_live(vpn
))
6554 update_routes_for_vni(bgp
, vpn
);
6556 /* Create or update as appropriate. */
6557 vpn
= bgp_evpn_new(bgp
, vni
, originator_ip
, tenant_vrf_id
,
6558 mcast_grp
, svi_ifindex
);
6561 /* if the VNI is live already, there is nothing more to do */
6562 if (is_vni_live(vpn
))
6565 /* Mark as "live" */
6566 SET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6568 /* tunnel is now active, add tunnel-ip to db */
6569 if (bgp_tip_add(bgp
, &originator_ip
))
6570 /* The originator_ip was not already present in the
6571 * bgp martian next-hop table as a tunnel-ip, so we
6572 * need to go back and filter routes matching the new
6575 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
6578 * Create EVPN type-3 route and schedule for processing.
6580 * RT-3 only if doing head-end replication
6582 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
6583 == VXLAN_FLOOD_HEAD_END_REPL
) {
6584 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
6585 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
)) {
6586 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
6587 "%u: Type3 route creation failure for VNI %u",
6593 /* If we have learnt and retained remote routes (VTEPs, MACs) for this
6597 install_routes_for_vni(bgp
, vpn
);
6599 /* If we are advertising gateway mac-ip
6600 It needs to be conveyed again to zebra */
6601 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
, vpn
->vni
);
6603 /* advertise svi mac-ip knob to zebra */
6604 bgp_zebra_advertise_svi_macip(bgp
, vpn
->advertise_svi_macip
, vpn
->vni
);
6610 * Handle change in setting for BUM handling. The supported values
6611 * are head-end replication and dropping all BUM packets. Any change
6612 * should be registered with zebra. Also, if doing head-end replication,
6613 * need to advertise local VNIs as EVPN RT-3 wheras, if BUM packets are
6614 * to be dropped, the RT-3s must be withdrawn.
6616 void bgp_evpn_flood_control_change(struct bgp
*bgp
)
6618 zlog_info("L2VPN EVPN BUM handling is %s",
6619 bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
?
6620 "Flooding" : "Flooding Disabled");
6622 bgp_zebra_vxlan_flood_control(bgp
, bgp
->vxlan_flood_ctrl
);
6623 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
)
6624 hash_iterate(bgp
->vnihash
, create_advertise_type3
, bgp
);
6625 else if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
6626 hash_iterate(bgp
->vnihash
, delete_withdraw_type3
, bgp
);
6630 * Cleanup EVPN information on disable - Need to delete and withdraw
6631 * EVPN routes from peers.
6633 void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
)
6635 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_bucket
*,
6636 void *))cleanup_vni_on_disable
,
6641 * Cleanup EVPN information - invoked at the time of bgpd exit or when the
6642 * BGP instance (default) is being freed.
6644 void bgp_evpn_cleanup(struct bgp
*bgp
)
6646 hash_iterate(bgp
->vnihash
,
6647 (void (*)(struct hash_bucket
*, void *))free_vni_entry
,
6650 hash_clean(bgp
->import_rt_hash
, (void (*)(void *))hash_import_rt_free
);
6651 hash_free(bgp
->import_rt_hash
);
6652 bgp
->import_rt_hash
= NULL
;
6654 hash_clean(bgp
->vrf_import_rt_hash
,
6655 (void (*)(void *))hash_vrf_import_rt_free
);
6656 hash_free(bgp
->vrf_import_rt_hash
);
6657 bgp
->vrf_import_rt_hash
= NULL
;
6659 hash_clean(bgp
->vni_svi_hash
, (void (*)(void *))hash_evpn_free
);
6660 hash_free(bgp
->vni_svi_hash
);
6661 bgp
->vni_svi_hash
= NULL
;
6662 hash_free(bgp
->vnihash
);
6663 bgp
->vnihash
= NULL
;
6665 list_delete(&bgp
->vrf_import_rtl
);
6666 list_delete(&bgp
->vrf_export_rtl
);
6667 list_delete(&bgp
->l2vnis
);
6669 if (bgp
->vrf_prd_pretty
)
6670 XFREE(MTYPE_BGP
, bgp
->vrf_prd_pretty
);
6674 * Initialization for EVPN
6677 * hash for RT to VNI
6679 void bgp_evpn_init(struct bgp
*bgp
)
6682 hash_create(vni_hash_key_make
, vni_hash_cmp
, "BGP VNI Hash");
6684 hash_create(vni_svi_hash_key_make
, vni_svi_hash_cmp
,
6685 "BGP VNI hash based on SVI ifindex");
6686 bgp
->import_rt_hash
=
6687 hash_create(import_rt_hash_key_make
, import_rt_hash_cmp
,
6688 "BGP Import RT Hash");
6689 bgp
->vrf_import_rt_hash
=
6690 hash_create(vrf_import_rt_hash_key_make
, vrf_import_rt_hash_cmp
,
6691 "BGP VRF Import RT Hash");
6692 bgp
->vrf_import_rtl
= list_new();
6693 bgp
->vrf_import_rtl
->cmp
=
6694 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6695 bgp
->vrf_import_rtl
->del
= evpn_vrf_rt_del
;
6696 bgp
->vrf_export_rtl
= list_new();
6697 bgp
->vrf_export_rtl
->cmp
=
6698 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6699 bgp
->vrf_export_rtl
->del
= evpn_vrf_rt_del
;
6700 bgp
->l2vnis
= list_new();
6701 bgp
->l2vnis
->cmp
= vni_list_cmp
;
6702 /* By default Duplicate Address Dection is enabled.
6703 * Max-moves (N) 5, detection time (M) 180
6704 * default action is warning-only
6705 * freeze action permanently freezes address,
6706 * and freeze time (auto-recovery) is disabled.
6708 if (bgp
->evpn_info
) {
6709 bgp
->evpn_info
->dup_addr_detect
= true;
6710 bgp
->evpn_info
->dad_time
= EVPN_DAD_DEFAULT_TIME
;
6711 bgp
->evpn_info
->dad_max_moves
= EVPN_DAD_DEFAULT_MAX_MOVES
;
6712 bgp
->evpn_info
->dad_freeze
= false;
6713 bgp
->evpn_info
->dad_freeze_time
= 0;
6714 /* Initialize zebra vxlan */
6715 bgp_zebra_dup_addr_detection(bgp
);
6716 /* Enable PIP feature by default for bgp vrf instance */
6717 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
6718 struct bgp
*bgp_default
;
6720 bgp
->evpn_info
->advertise_pip
= true;
6721 bgp_default
= bgp_get_default();
6723 bgp
->evpn_info
->pip_ip
= bgp_default
->router_id
;
6727 /* Default BUM handling is to do head-end replication. */
6728 bgp
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6730 bgp_evpn_nh_init(bgp
);
6733 void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
)
6735 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6736 bgp_evpn_nh_finish(bgp_vrf
);
6740 * Get the prefixlen of the ip prefix carried within the type5 evpn route.
6742 int bgp_evpn_get_type5_prefixlen(const struct prefix
*pfx
)
6744 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6746 if (!pfx
|| pfx
->family
!= AF_EVPN
)
6749 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
6752 return evp
->prefix
.prefix_addr
.ip_prefix_length
;
6756 * Should we register nexthop for this EVPN prefix for nexthop tracking?
6758 bool bgp_evpn_is_prefix_nht_supported(const struct prefix
*pfx
)
6760 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6763 * EVPN routes should be marked as valid only if the nexthop is
6764 * reachable. Only if this happens, the route should be imported
6765 * (into VNI or VRF routing tables) and/or advertised.
6766 * Note: This is currently applied for EVPN type-1, type-2,
6767 * type-3, type-4 and type-5 routes.
6768 * It may be tweaked later on for other routes, or
6769 * even removed completely when all routes are handled.
6771 if (pfx
&& pfx
->family
== AF_EVPN
6772 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
6773 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
6774 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
6775 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
6776 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
6782 static void *bgp_evpn_remote_ip_hash_alloc(void *p
)
6784 const struct evpn_remote_ip
*key
= (const struct evpn_remote_ip
*)p
;
6785 struct evpn_remote_ip
*ip
;
6787 ip
= XMALLOC(MTYPE_EVPN_REMOTE_IP
, sizeof(struct evpn_remote_ip
));
6789 ip
->macip_path_list
= list_new();
6794 static unsigned int bgp_evpn_remote_ip_hash_key_make(const void *p
)
6796 const struct evpn_remote_ip
*ip
= p
;
6797 const struct ipaddr
*addr
= &ip
->addr
;
6799 if (IS_IPADDR_V4(addr
))
6800 return jhash_1word(addr
->ipaddr_v4
.s_addr
, 0);
6802 return jhash2(addr
->ipaddr_v6
.s6_addr32
,
6803 array_size(addr
->ipaddr_v6
.s6_addr32
), 0);
6806 static bool bgp_evpn_remote_ip_hash_cmp(const void *p1
, const void *p2
)
6808 const struct evpn_remote_ip
*ip1
= p1
;
6809 const struct evpn_remote_ip
*ip2
= p2
;
6811 return !ipaddr_cmp(&ip1
->addr
, &ip2
->addr
);
6814 static void bgp_evpn_remote_ip_hash_init(struct bgpevpn
*vpn
)
6816 if (!evpn_resolve_overlay_index())
6819 vpn
->remote_ip_hash
= hash_create(bgp_evpn_remote_ip_hash_key_make
,
6820 bgp_evpn_remote_ip_hash_cmp
,
6821 "BGP EVPN remote IP hash");
6824 static void bgp_evpn_remote_ip_hash_free(struct hash_bucket
*bucket
, void *args
)
6826 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6827 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6829 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6831 list_delete(&ip
->macip_path_list
);
6833 hash_release(vpn
->remote_ip_hash
, ip
);
6834 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6837 static void bgp_evpn_remote_ip_hash_destroy(struct bgpevpn
*vpn
)
6839 if (!evpn_resolve_overlay_index() || vpn
->remote_ip_hash
== NULL
)
6842 hash_iterate(vpn
->remote_ip_hash
,
6843 (void (*)(struct hash_bucket
*, void *))bgp_evpn_remote_ip_hash_free
,
6846 hash_free(vpn
->remote_ip_hash
);
6847 vpn
->remote_ip_hash
= NULL
;
6850 /* Add a remote MAC/IP route to hash table */
6851 static void bgp_evpn_remote_ip_hash_add(struct bgpevpn
*vpn
,
6852 struct bgp_path_info
*pi
)
6854 struct evpn_remote_ip tmp
;
6855 struct evpn_remote_ip
*ip
;
6856 struct prefix_evpn
*evp
;
6858 if (!evpn_resolve_overlay_index())
6861 if (pi
->type
!= ZEBRA_ROUTE_BGP
|| pi
->sub_type
!= BGP_ROUTE_IMPORTED
6862 || !CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
))
6865 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6867 if (evp
->family
!= AF_EVPN
6868 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6869 || is_evpn_prefix_ipaddr_none(evp
))
6872 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6873 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6875 if (listnode_lookup(ip
->macip_path_list
, pi
) != NULL
)
6877 (void)listnode_add(ip
->macip_path_list
, pi
);
6881 ip
= hash_get(vpn
->remote_ip_hash
, &tmp
, bgp_evpn_remote_ip_hash_alloc
);
6882 (void)listnode_add(ip
->macip_path_list
, pi
);
6884 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6887 /* Delete a remote MAC/IP route from hash table */
6888 static void bgp_evpn_remote_ip_hash_del(struct bgpevpn
*vpn
,
6889 struct bgp_path_info
*pi
)
6891 struct evpn_remote_ip tmp
;
6892 struct evpn_remote_ip
*ip
;
6893 struct prefix_evpn
*evp
;
6895 if (!evpn_resolve_overlay_index())
6898 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6900 if (evp
->family
!= AF_EVPN
6901 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6902 || is_evpn_prefix_ipaddr_none(evp
))
6905 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6906 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6910 listnode_delete(ip
->macip_path_list
, pi
);
6912 if (ip
->macip_path_list
->count
== 0) {
6913 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6914 hash_release(vpn
->remote_ip_hash
, ip
);
6915 list_delete(&ip
->macip_path_list
);
6916 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6920 static void bgp_evpn_remote_ip_hash_iterate(struct bgpevpn
*vpn
,
6921 void (*func
)(struct hash_bucket
*,
6925 if (!evpn_resolve_overlay_index())
6928 hash_iterate(vpn
->remote_ip_hash
, func
, arg
);
6931 static void show_remote_ip_entry(struct hash_bucket
*bucket
, void *args
)
6933 char buf
[INET6_ADDRSTRLEN
];
6934 struct listnode
*node
= NULL
;
6935 struct bgp_path_info
*pi
= NULL
;
6936 struct vty
*vty
= (struct vty
*)args
;
6937 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6939 vty_out(vty
, " Remote IP: %s\n",
6940 ipaddr2str(&ip
->addr
, buf
, sizeof(buf
)));
6941 vty_out(vty
, " Linked MAC/IP routes:\n");
6942 for (ALL_LIST_ELEMENTS_RO(ip
->macip_path_list
, node
, pi
))
6943 vty_out(vty
, " %pFX\n", &pi
->net
->p
);
6946 void bgp_evpn_show_remote_ip_hash(struct hash_bucket
*bucket
, void *args
)
6948 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6949 struct vty
*vty
= (struct vty
*)args
;
6951 vty_out(vty
, "VNI: %u\n", vpn
->vni
);
6952 bgp_evpn_remote_ip_hash_iterate(
6954 (void (*)(struct hash_bucket
*, void *))show_remote_ip_entry
,
6959 static void bgp_evpn_remote_ip_hash_link_nexthop(struct hash_bucket
*bucket
,
6962 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6963 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6965 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6968 static void bgp_evpn_remote_ip_hash_unlink_nexthop(struct hash_bucket
*bucket
,
6971 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6972 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6974 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6977 static unsigned int vni_svi_hash_key_make(const void *p
)
6979 const struct bgpevpn
*vpn
= p
;
6981 return jhash_1word(vpn
->svi_ifindex
, 0);
6984 static bool vni_svi_hash_cmp(const void *p1
, const void *p2
)
6986 const struct bgpevpn
*vpn1
= p1
;
6987 const struct bgpevpn
*vpn2
= p2
;
6989 return (vpn1
->svi_ifindex
== vpn2
->svi_ifindex
);
6992 static struct bgpevpn
*bgp_evpn_vni_svi_hash_lookup(struct bgp
*bgp
,
6995 struct bgpevpn
*vpn
;
6998 memset(&tmp
, 0, sizeof(tmp
));
6999 tmp
.svi_ifindex
= svi
;
7000 vpn
= hash_lookup(bgp
->vni_svi_hash
, &tmp
);
7004 static void bgp_evpn_link_to_vni_svi_hash(struct bgp
*bgp
, struct bgpevpn
*vpn
)
7006 if (vpn
->svi_ifindex
== 0)
7009 (void)hash_get(bgp
->vni_svi_hash
, vpn
, hash_alloc_intern
);
7012 static void bgp_evpn_unlink_from_vni_svi_hash(struct bgp
*bgp
,
7013 struct bgpevpn
*vpn
)
7015 if (vpn
->svi_ifindex
== 0)
7018 hash_release(bgp
->vni_svi_hash
, vpn
);
7021 void bgp_evpn_show_vni_svi_hash(struct hash_bucket
*bucket
, void *args
)
7023 struct bgpevpn
*evpn
= (struct bgpevpn
*)bucket
->data
;
7024 struct vty
*vty
= (struct vty
*)args
;
7026 vty_out(vty
, "SVI: %u VNI: %u\n", evpn
->svi_ifindex
, evpn
->vni
);
7030 * This function is called for a bgp_nexthop_cache entry when the nexthop is
7031 * gateway IP overlay index.
7032 * This function returns true if there is a remote MAC/IP route for the gateway
7033 * IP in the EVI of the nexthop SVI.
7035 bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache
*bnc
)
7037 struct bgp
*bgp_evpn
= NULL
;
7038 struct bgpevpn
*vpn
= NULL
;
7039 struct evpn_remote_ip tmp
;
7042 if (!evpn_resolve_overlay_index())
7045 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
== 0)
7048 bgp_evpn
= bgp_get_evpn();
7053 * Gateway IP is resolved by nht over SVI interface.
7054 * Use this SVI to find corresponding EVI(L2 context)
7056 vpn
= bgp_evpn_vni_svi_hash_lookup(bgp_evpn
, bnc
->nexthop
->ifindex
);
7060 if (vpn
->bgp_vrf
!= bnc
->bgp
)
7064 * Check if the gateway IP is present in the EVI remote_ip_hash table
7065 * which stores all the remote IP addresses received via MAC/IP routes
7068 memset(&tmp
, 0, sizeof(tmp
));
7071 if (p
->family
== AF_INET
) {
7072 tmp
.addr
.ipa_type
= IPADDR_V4
;
7073 memcpy(&(tmp
.addr
.ipaddr_v4
), &(p
->u
.prefix4
),
7074 sizeof(struct in_addr
));
7075 } else if (p
->family
== AF_INET6
) {
7076 tmp
.addr
.ipa_type
= IPADDR_V6
;
7077 memcpy(&(tmp
.addr
.ipaddr_v6
), &(p
->u
.prefix6
),
7078 sizeof(struct in6_addr
));
7082 if (hash_lookup(vpn
->remote_ip_hash
, &tmp
) == NULL
)
7088 /* Resolve/Unresolve nexthops when a MAC/IP route is added/deleted */
7089 static void bgp_evpn_remote_ip_process_nexthops(struct bgpevpn
*vpn
,
7090 struct ipaddr
*addr
,
7095 struct bgp_nexthop_cache
*bnc
;
7096 struct bgp_nexthop_cache_head
*tree
= NULL
;
7098 if (!vpn
->bgp_vrf
|| vpn
->svi_ifindex
== 0)
7101 memset(&p
, 0, sizeof(p
));
7103 if (addr
->ipa_type
== IPADDR_V4
) {
7106 memcpy(&(p
.u
.prefix4
), &(addr
->ipaddr_v4
),
7107 sizeof(struct in_addr
));
7108 p
.prefixlen
= IPV4_MAX_BITLEN
;
7109 } else if (addr
->ipa_type
== IPADDR_V6
) {
7111 p
.family
= AF_INET6
;
7112 memcpy(&(p
.u
.prefix6
), &(addr
->ipaddr_v6
),
7113 sizeof(struct in6_addr
));
7114 p
.prefixlen
= IPV6_MAX_BITLEN
;
7118 tree
= &vpn
->bgp_vrf
->nexthop_cache_table
[afi
];
7119 bnc
= bnc_find(tree
, &p
, 0, 0);
7121 if (!bnc
|| !bnc
->is_evpn_gwip_nexthop
)
7124 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
!= vpn
->svi_ifindex
)
7127 if (BGP_DEBUG(nht
, NHT
))
7128 zlog_debug("%s(%u): vni %u mac/ip %s for NH %pFX",
7129 vpn
->bgp_vrf
->name_pretty
, vpn
->tenant_vrf_id
,
7130 vpn
->vni
, (resolve
? "add" : "delete"),
7134 * MAC/IP route or SVI or tenant vrf being added to EVI.
7135 * Set nexthop as valid only if it is already L3 reachable
7137 if (resolve
&& bnc
->flags
& BGP_NEXTHOP_EVPN_INCOMPLETE
) {
7138 bnc
->flags
&= ~BGP_NEXTHOP_EVPN_INCOMPLETE
;
7139 bnc
->flags
|= BGP_NEXTHOP_VALID
;
7140 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7141 evaluate_paths(bnc
);
7144 /* MAC/IP route or SVI or tenant vrf being deleted from EVI */
7145 if (!resolve
&& bnc
->flags
& BGP_NEXTHOP_VALID
) {
7146 bnc
->flags
&= ~BGP_NEXTHOP_VALID
;
7147 bnc
->flags
|= BGP_NEXTHOP_EVPN_INCOMPLETE
;
7148 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7149 evaluate_paths(bnc
);
7153 void bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket
*bucket
,
7156 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7157 struct bgp_dest
*dest
;
7158 struct bgp_path_info
*pi
;
7160 bgp_evpn_remote_ip_hash_init(vpn
);
7162 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
7163 dest
= bgp_route_next(dest
))
7164 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
7165 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
7168 void bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket
*bucket
,
7171 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7173 bgp_evpn_remote_ip_hash_destroy(vpn
);
7177 * Helper function for getting the correct label index for l3vni.
7179 * Returns the label with the l3vni of the path's label stack.
7181 * L3vni is always last label. Type5 will only
7182 * have one label, Type2 will have two.
7185 mpls_label_t
*bgp_evpn_path_info_labels_get_l3vni(mpls_label_t
*labels
,
7186 uint32_t num_labels
)
7194 return &labels
[num_labels
- 1];
7198 * Returns the l3vni of the path converted from the label stack.
7200 vni_t
bgp_evpn_path_info_get_l3vni(const struct bgp_path_info
*pi
)
7205 return label2vni(bgp_evpn_path_info_labels_get_l3vni(
7206 pi
->extra
->label
, pi
->extra
->num_labels
));
7210 * Returns true if the l3vni of any of this path doesn't match vrf's l3vni.
7212 static bool bgp_evpn_path_is_dvni(const struct bgp
*bgp_vrf
,
7213 const struct bgp_path_info
*pi
)
7217 vni
= bgp_evpn_path_info_get_l3vni(pi
);
7219 if ((vni
> 0) && (vni
!= bgp_vrf
->l3vni
))
7226 * Returns true if the l3vni of any of the mpath's doesn't match vrf's l3vni.
7228 bool bgp_evpn_mpath_has_dvni(const struct bgp
*bgp_vrf
,
7229 struct bgp_path_info
*mpinfo
)
7231 for (; mpinfo
; mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
7232 if (bgp_evpn_path_is_dvni(bgp_vrf
, mpinfo
))