1 /* Ethernet-VPN Packet and vty Processing File
2 * Copyright (C) 2016 6WIND
3 * Copyright (C) 2017 Cumulus Networks, Inc.
5 * This file is part of FRR.
7 * FRRouting is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * FRRouting is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "lib/printfrr.h"
36 #include "bgpd/bgp_attr_evpn.h"
37 #include "bgpd/bgpd.h"
38 #include "bgpd/bgp_table.h"
39 #include "bgpd/bgp_route.h"
40 #include "bgpd/bgp_attr.h"
41 #include "bgpd/bgp_mplsvpn.h"
42 #include "bgpd/bgp_label.h"
43 #include "bgpd/bgp_evpn.h"
44 #include "bgpd/bgp_evpn_private.h"
45 #include "bgpd/bgp_evpn_mh.h"
46 #include "bgpd/bgp_ecommunity.h"
47 #include "bgpd/bgp_encap_types.h"
48 #include "bgpd/bgp_debug.h"
49 #include "bgpd/bgp_errors.h"
50 #include "bgpd/bgp_aspath.h"
51 #include "bgpd/bgp_zebra.h"
52 #include "bgpd/bgp_nexthop.h"
53 #include "bgpd/bgp_addpath.h"
54 #include "bgpd/bgp_mac.h"
55 #include "bgpd/bgp_vty.h"
56 #include "bgpd/bgp_nht.h"
57 #include "bgpd/bgp_trace.h"
58 #include "bgpd/bgp_mpath.h"
61 * Definitions and external declarations.
63 DEFINE_QOBJ_TYPE(bgpevpn
);
64 DEFINE_QOBJ_TYPE(bgp_evpn_es
);
66 DEFINE_MTYPE_STATIC(BGPD
, VRF_ROUTE_TARGET
, "L3 Route Target");
69 * Static function declarations
71 static void bgp_evpn_remote_ip_hash_init(struct bgpevpn
*evpn
);
72 static void bgp_evpn_remote_ip_hash_destroy(struct bgpevpn
*evpn
);
73 static void bgp_evpn_remote_ip_hash_add(struct bgpevpn
*vpn
,
74 struct bgp_path_info
*pi
);
75 static void bgp_evpn_remote_ip_hash_del(struct bgpevpn
*vpn
,
76 struct bgp_path_info
*pi
);
77 static void bgp_evpn_remote_ip_hash_iterate(struct bgpevpn
*vpn
,
78 void (*func
)(struct hash_bucket
*,
81 static void bgp_evpn_link_to_vni_svi_hash(struct bgp
*bgp
, struct bgpevpn
*vpn
);
82 static void bgp_evpn_unlink_from_vni_svi_hash(struct bgp
*bgp
,
84 static unsigned int vni_svi_hash_key_make(const void *p
);
85 static bool vni_svi_hash_cmp(const void *p1
, const void *p2
);
86 static void bgp_evpn_remote_ip_process_nexthops(struct bgpevpn
*vpn
,
89 static void bgp_evpn_remote_ip_hash_link_nexthop(struct hash_bucket
*bucket
,
91 static void bgp_evpn_remote_ip_hash_unlink_nexthop(struct hash_bucket
*bucket
,
93 static struct in_addr zero_vtep_ip
;
102 static unsigned int vni_hash_key_make(const void *p
)
104 const struct bgpevpn
*vpn
= p
;
105 return (jhash_1word(vpn
->vni
, 0));
109 * Comparison function for vni hash
111 static bool vni_hash_cmp(const void *p1
, const void *p2
)
113 const struct bgpevpn
*vpn1
= p1
;
114 const struct bgpevpn
*vpn2
= p2
;
116 return vpn1
->vni
== vpn2
->vni
;
119 int vni_list_cmp(void *p1
, void *p2
)
121 const struct bgpevpn
*vpn1
= p1
;
122 const struct bgpevpn
*vpn2
= p2
;
124 return vpn1
->vni
- vpn2
->vni
;
128 * Make vrf import route target hash key.
130 static unsigned int vrf_import_rt_hash_key_make(const void *p
)
132 const struct vrf_irt_node
*irt
= p
;
133 const char *pnt
= irt
->rt
.val
;
135 return jhash(pnt
, 8, 0x5abc1234);
139 * Comparison function for vrf import rt hash
141 static bool vrf_import_rt_hash_cmp(const void *p1
, const void *p2
)
143 const struct vrf_irt_node
*irt1
= p1
;
144 const struct vrf_irt_node
*irt2
= p2
;
146 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
150 * Create a new vrf import_rt in evpn instance
152 static struct vrf_irt_node
*vrf_import_rt_new(struct ecommunity_val
*rt
)
154 struct bgp
*bgp_evpn
= NULL
;
155 struct vrf_irt_node
*irt
;
157 bgp_evpn
= bgp_get_evpn();
159 flog_err(EC_BGP_NO_DFLT
,
160 "vrf import rt new - evpn instance not created yet");
164 irt
= XCALLOC(MTYPE_BGP_EVPN_VRF_IMPORT_RT
,
165 sizeof(struct vrf_irt_node
));
168 irt
->vrfs
= list_new();
171 (void)hash_get(bgp_evpn
->vrf_import_rt_hash
, irt
, hash_alloc_intern
);
177 * Free the vrf import rt node
179 static void vrf_import_rt_free(struct vrf_irt_node
*irt
)
181 struct bgp
*bgp_evpn
= NULL
;
183 bgp_evpn
= bgp_get_evpn();
185 flog_err(EC_BGP_NO_DFLT
,
186 "vrf import rt free - evpn instance not created yet");
190 hash_release(bgp_evpn
->vrf_import_rt_hash
, irt
);
191 list_delete(&irt
->vrfs
);
192 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
195 static void hash_vrf_import_rt_free(struct vrf_irt_node
*irt
)
197 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
201 * Function to lookup Import RT node - used to map a RT to set of
202 * VNIs importing routes with that RT.
204 static struct vrf_irt_node
*lookup_vrf_import_rt(struct ecommunity_val
*rt
)
206 struct bgp
*bgp_evpn
= NULL
;
207 struct vrf_irt_node
*irt
;
208 struct vrf_irt_node tmp
;
210 bgp_evpn
= bgp_get_evpn();
214 "vrf import rt lookup - evpn instance not created yet");
218 memset(&tmp
, 0, sizeof(tmp
));
219 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
220 irt
= hash_lookup(bgp_evpn
->vrf_import_rt_hash
, &tmp
);
225 * Is specified VRF present on the RT's list of "importing" VRFs?
227 static int is_vrf_present_in_irt_vrfs(struct list
*vrfs
, struct bgp
*bgp_vrf
)
229 struct listnode
*node
= NULL
, *nnode
= NULL
;
230 struct bgp
*tmp_bgp_vrf
= NULL
;
232 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, tmp_bgp_vrf
)) {
233 if (tmp_bgp_vrf
== bgp_vrf
)
240 * Make import route target hash key.
242 static unsigned int import_rt_hash_key_make(const void *p
)
244 const struct irt_node
*irt
= p
;
245 const char *pnt
= irt
->rt
.val
;
247 return jhash(pnt
, 8, 0xdeadbeef);
251 * Comparison function for import rt hash
253 static bool import_rt_hash_cmp(const void *p1
, const void *p2
)
255 const struct irt_node
*irt1
= p1
;
256 const struct irt_node
*irt2
= p2
;
258 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
262 * Create a new import_rt
264 static struct irt_node
*import_rt_new(struct bgp
*bgp
,
265 struct ecommunity_val
*rt
)
267 struct irt_node
*irt
;
269 irt
= XCALLOC(MTYPE_BGP_EVPN_IMPORT_RT
, sizeof(struct irt_node
));
272 irt
->vnis
= list_new();
275 (void)hash_get(bgp
->import_rt_hash
, irt
, hash_alloc_intern
);
281 * Free the import rt node
283 static void import_rt_free(struct bgp
*bgp
, struct irt_node
*irt
)
285 hash_release(bgp
->import_rt_hash
, irt
);
286 list_delete(&irt
->vnis
);
287 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
290 static void hash_import_rt_free(struct irt_node
*irt
)
292 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
296 * Function to lookup Import RT node - used to map a RT to set of
297 * VNIs importing routes with that RT.
299 static struct irt_node
*lookup_import_rt(struct bgp
*bgp
,
300 struct ecommunity_val
*rt
)
302 struct irt_node
*irt
;
305 memset(&tmp
, 0, sizeof(tmp
));
306 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
307 irt
= hash_lookup(bgp
->import_rt_hash
, &tmp
);
312 * Is specified VNI present on the RT's list of "importing" VNIs?
314 static int is_vni_present_in_irt_vnis(struct list
*vnis
, struct bgpevpn
*vpn
)
316 struct listnode
*node
, *nnode
;
317 struct bgpevpn
*tmp_vpn
;
319 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, tmp_vpn
)) {
328 * Compare Route Targets.
330 int bgp_evpn_route_target_cmp(struct ecommunity
*ecom1
,
331 struct ecommunity
*ecom2
)
339 if (!ecom1
&& !ecom2
)
342 if (ecom1
->str
&& !ecom2
->str
)
345 if (!ecom1
->str
&& ecom2
->str
)
348 if (!ecom1
->str
&& !ecom2
->str
)
351 return strcmp(ecom1
->str
, ecom2
->str
);
355 * Compare L3 Route Targets.
357 static int evpn_vrf_route_target_cmp(struct vrf_route_target
*rt1
,
358 struct vrf_route_target
*rt2
)
360 return bgp_evpn_route_target_cmp(rt1
->ecom
, rt2
->ecom
);
363 void bgp_evpn_xxport_delete_ecomm(void *val
)
365 struct ecommunity
*ecomm
= val
;
366 ecommunity_free(&ecomm
);
370 * Delete l3 Route Target.
372 static void evpn_vrf_rt_del(void *val
)
374 struct vrf_route_target
*l3rt
= val
;
376 ecommunity_free(&l3rt
->ecom
);
378 XFREE(MTYPE_VRF_ROUTE_TARGET
, l3rt
);
382 * Allocate a new l3 Route Target.
384 static struct vrf_route_target
*evpn_vrf_rt_new(struct ecommunity
*ecom
)
386 struct vrf_route_target
*l3rt
;
388 l3rt
= XCALLOC(MTYPE_VRF_ROUTE_TARGET
, sizeof(struct vrf_route_target
));
396 * Mask off global-admin field of specified extended community (RT),
397 * just retain the local-admin field.
399 static inline void mask_ecom_global_admin(struct ecommunity_val
*dst
,
400 const struct ecommunity_val
*src
)
406 if (type
== ECOMMUNITY_ENCODE_AS
) {
407 dst
->val
[2] = dst
->val
[3] = 0;
408 } else if (type
== ECOMMUNITY_ENCODE_AS4
409 || type
== ECOMMUNITY_ENCODE_IP
) {
410 dst
->val
[2] = dst
->val
[3] = 0;
411 dst
->val
[4] = dst
->val
[5] = 0;
416 * Converts the RT to Ecommunity Value and adjusts masking based
417 * on flags set for RT.
419 static void vrf_rt2ecom_val(struct ecommunity_val
*to_eval
,
420 const struct vrf_route_target
*l3rt
, int iter
)
422 const struct ecommunity_val
*eval
;
424 eval
= (const struct ecommunity_val
*)(l3rt
->ecom
->val
+
425 (iter
* ECOMMUNITY_SIZE
));
426 /* If using "automatic" or "wildcard *" RT,
427 * we only care about the local-admin sub-field.
428 * This is to facilitate using L3VNI(VRF-VNI)
429 * as the RT for EBGP peering too and simplify
430 * configurations by allowing any ASN via '*'.
432 memcpy(to_eval
, eval
, ECOMMUNITY_SIZE
);
434 if (CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
) ||
435 CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_WILD
))
436 mask_ecom_global_admin(to_eval
, eval
);
440 * Map one RT to specified VRF.
441 * bgp_vrf = BGP vrf instance
443 static void map_vrf_to_rt(struct bgp
*bgp_vrf
, struct vrf_route_target
*l3rt
)
447 for (i
= 0; i
< l3rt
->ecom
->size
; i
++) {
448 struct vrf_irt_node
*irt
= NULL
;
449 struct ecommunity_val eval_tmp
;
451 /* Adjust masking for value */
452 vrf_rt2ecom_val(&eval_tmp
, l3rt
, i
);
454 irt
= lookup_vrf_import_rt(&eval_tmp
);
456 if (irt
&& is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
457 return; /* Already mapped. */
460 irt
= vrf_import_rt_new(&eval_tmp
);
462 /* Add VRF to the list for this RT. */
463 listnode_add(irt
->vrfs
, bgp_vrf
);
468 * Unmap specified VRF from specified RT. If there are no other
469 * VRFs for this RT, then the RT hash is deleted.
470 * bgp_vrf: BGP VRF specific instance
472 static void unmap_vrf_from_rt(struct bgp
*bgp_vrf
,
473 struct vrf_route_target
*l3rt
)
477 for (i
= 0; i
< l3rt
->ecom
->size
; i
++) {
478 struct vrf_irt_node
*irt
;
479 struct ecommunity_val eval_tmp
;
481 /* Adjust masking for value */
482 vrf_rt2ecom_val(&eval_tmp
, l3rt
, i
);
484 irt
= lookup_vrf_import_rt(&eval_tmp
);
487 return; /* Not mapped */
489 /* Delete VRF from list for this RT. */
490 listnode_delete(irt
->vrfs
, bgp_vrf
);
492 if (!listnode_head(irt
->vrfs
))
493 vrf_import_rt_free(irt
);
498 * Map one RT to specified VNI.
500 static void map_vni_to_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
501 struct ecommunity_val
*eval
)
503 struct irt_node
*irt
;
504 struct ecommunity_val eval_tmp
;
506 /* If using "automatic" RT, we only care about the local-admin
508 * This is to facilitate using VNI as the RT for EBGP peering too.
510 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
511 if (!is_import_rt_configured(vpn
))
512 mask_ecom_global_admin(&eval_tmp
, eval
);
514 irt
= lookup_import_rt(bgp
, &eval_tmp
);
516 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
517 /* Already mapped. */
521 irt
= import_rt_new(bgp
, &eval_tmp
);
523 /* Add VNI to the hash list for this RT. */
524 listnode_add(irt
->vnis
, vpn
);
528 * Unmap specified VNI from specified RT. If there are no other
529 * VNIs for this RT, then the RT hash is deleted.
531 static void unmap_vni_from_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
532 struct irt_node
*irt
)
534 /* Delete VNI from hash list for this RT. */
535 listnode_delete(irt
->vnis
, vpn
);
536 if (!listnode_head(irt
->vnis
)) {
537 import_rt_free(bgp
, irt
);
541 static void bgp_evpn_get_rmac_nexthop(struct bgpevpn
*vpn
,
542 const struct prefix_evpn
*p
,
543 struct attr
*attr
, uint8_t flags
)
545 struct bgp
*bgp_vrf
= vpn
->bgp_vrf
;
547 memset(&attr
->rmac
, 0, sizeof(struct ethaddr
));
551 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
554 /* Copy sys (pip) RMAC and PIP IP as nexthop
555 * in case of route is self MAC-IP,
556 * advertise-pip and advertise-svi-ip features
558 * Otherwise, for all host MAC-IP route's
561 if (CHECK_FLAG(flags
, BGP_EVPN_MACIP_TYPE_SVI_IP
)
562 && bgp_vrf
->evpn_info
->advertise_pip
&&
563 bgp_vrf
->evpn_info
->is_anycast_mac
) {
565 memcpy(&attr
->rmac
, &bgp_vrf
->evpn_info
->pip_rmac
,
567 attr
->nexthop
= bgp_vrf
->evpn_info
->pip_ip
;
568 attr
->mp_nexthop_global_in
=
569 bgp_vrf
->evpn_info
->pip_ip
;
571 memcpy(&attr
->rmac
, &bgp_vrf
->rmac
, ETH_ALEN
);
575 * Create RT extended community automatically from passed information:
576 * of the form AS:VNI.
577 * NOTE: We use only the lower 16 bits of the AS. This is sufficient as
578 * the need is to get a RT value that will be unique across different
579 * VNIs but the same across routers (in the same AS) for a particular
582 static void form_auto_rt(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
,
585 struct ecommunity_val eval
;
586 struct ecommunity
*ecomadd
;
587 struct ecommunity
*ecom
;
588 struct vrf_route_target
*l3rt
;
589 struct vrf_route_target
*newrt
;
590 bool ecom_found
= false;
591 struct listnode
*node
;
593 if (bgp
->advertise_autort_rfc8365
)
594 vni
|= EVPN_AUTORT_VXLAN
;
595 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
);
597 ecomadd
= ecommunity_new();
598 ecommunity_add_val(ecomadd
, &eval
, false, false);
601 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, l3rt
))
602 if (ecommunity_cmp(ecomadd
, l3rt
->ecom
)) {
607 for (ALL_LIST_ELEMENTS_RO(rtl
, node
, ecom
))
608 if (ecommunity_cmp(ecomadd
, ecom
)) {
616 newrt
= evpn_vrf_rt_new(ecomadd
);
617 /* Label it as autoderived */
618 SET_FLAG(newrt
->flags
, BGP_VRF_RT_AUTO
);
619 listnode_add_sort(rtl
, newrt
);
621 listnode_add_sort(rtl
, ecomadd
);
623 ecommunity_free(&ecomadd
);
627 * Derive RD and RT for a VNI automatically. Invoked at the time of
630 static void derive_rd_rt_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
632 bgp_evpn_derive_auto_rd(bgp
, vpn
);
633 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
634 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
638 * Convert nexthop (remote VTEP IP) into an IPv6 address.
640 static void evpn_convert_nexthop_to_ipv6(struct attr
*attr
)
642 if (BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
644 ipv4_to_ipv4_mapped_ipv6(&attr
->mp_nexthop_global
, attr
->nexthop
);
645 attr
->mp_nexthop_len
= IPV6_MAX_BYTELEN
;
649 * Wrapper for node get in global table.
651 struct bgp_dest
*bgp_evpn_global_node_get(struct bgp_table
*table
, afi_t afi
,
653 const struct prefix_evpn
*evp
,
654 struct prefix_rd
*prd
,
655 const struct bgp_path_info
*local_pi
)
657 struct prefix_evpn global_p
;
659 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
660 /* prefix in the global table doesn't include the VTEP-IP so
661 * we need to create a different copy of the prefix
663 evpn_type1_prefix_global_copy(&global_p
, evp
);
665 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
668 * prefix in the global table needs MAC/IP, ensure they are
669 * present, using one's from local table's path_info.
671 if (is_evpn_prefix_ipaddr_none(evp
)) {
672 /* VNI MAC -> Global */
673 evpn_type2_prefix_global_copy(
674 &global_p
, evp
, NULL
/* mac */,
675 evpn_type2_path_info_get_ip(local_pi
));
677 /* VNI IP -> Global */
678 evpn_type2_prefix_global_copy(
680 evpn_type2_path_info_get_mac(local_pi
),
686 return bgp_afi_node_get(table
, afi
, safi
, (struct prefix
*)evp
, prd
);
690 * Wrapper for node lookup in global table.
693 bgp_evpn_global_node_lookup(struct bgp_table
*table
, afi_t afi
, safi_t safi
,
694 const struct prefix_evpn
*evp
,
695 struct prefix_rd
*prd
,
696 const struct bgp_path_info
*local_pi
)
698 struct prefix_evpn global_p
;
700 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
701 /* prefix in the global table doesn't include the VTEP-IP so
702 * we need to create a different copy of the prefix
704 evpn_type1_prefix_global_copy(&global_p
, evp
);
706 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
709 * prefix in the global table needs MAC/IP, ensure they are
710 * present, using one's from local table's path_info.
712 if (is_evpn_prefix_ipaddr_none(evp
)) {
713 /* VNI MAC -> Global */
714 evpn_type2_prefix_global_copy(
715 &global_p
, evp
, NULL
/* mac */,
716 evpn_type2_path_info_get_ip(local_pi
));
718 /* VNI IP -> Global */
719 evpn_type2_prefix_global_copy(
721 evpn_type2_path_info_get_mac(local_pi
),
727 return bgp_afi_node_lookup(table
, afi
, safi
, (struct prefix
*)evp
, prd
);
731 * Wrapper for node get in VNI IP table.
733 struct bgp_dest
*bgp_evpn_vni_ip_node_get(struct bgp_table
*const table
,
734 const struct prefix_evpn
*evp
,
735 const struct bgp_path_info
*parent_pi
)
737 struct prefix_evpn vni_p
;
739 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
740 /* prefix in the global table doesn't include the VTEP-IP so
741 * we need to create a different copy for the VNI
743 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
744 parent_pi
->attr
->nexthop
);
746 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
747 /* Only MAC-IP should go into this table, not mac-only */
748 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
751 * prefix in the vni IP table doesn't include MAC so
752 * we need to create a different copy of the prefix.
754 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
757 return bgp_node_get(table
, (struct prefix
*)evp
);
761 * Wrapper for node lookup in VNI IP table.
764 bgp_evpn_vni_ip_node_lookup(const struct bgp_table
*const table
,
765 const struct prefix_evpn
*evp
,
766 const struct bgp_path_info
*parent_pi
)
768 struct prefix_evpn vni_p
;
770 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
&& parent_pi
) {
771 /* prefix in the global table doesn't include the VTEP-IP so
772 * we need to create a different copy for the VNI
774 evpn_type1_prefix_vni_ip_copy(&vni_p
, evp
,
775 parent_pi
->attr
->nexthop
);
777 } else if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
778 /* Only MAC-IP should go into this table, not mac-only */
779 assert(is_evpn_prefix_ipaddr_none(evp
) == false);
782 * prefix in the vni IP table doesn't include MAC so
783 * we need to create a different copy of the prefix.
785 evpn_type2_prefix_vni_ip_copy(&vni_p
, evp
);
788 return bgp_node_lookup(table
, (struct prefix
*)evp
);
792 * Wrapper for node get in VNI MAC table.
795 bgp_evpn_vni_mac_node_get(struct bgp_table
*const table
,
796 const struct prefix_evpn
*evp
,
797 const struct bgp_path_info
*parent_pi
)
799 struct prefix_evpn vni_p
;
801 /* Only type-2 should ever go into this table */
802 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
805 * prefix in the vni MAC table doesn't include IP so
806 * we need to create a different copy of the prefix.
808 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
810 return bgp_node_get(table
, (struct prefix
*)evp
);
814 * Wrapper for node lookup in VNI MAC table.
817 bgp_evpn_vni_mac_node_lookup(const struct bgp_table
*const table
,
818 const struct prefix_evpn
*evp
,
819 const struct bgp_path_info
*parent_pi
)
821 struct prefix_evpn vni_p
;
823 /* Only type-2 should ever go into this table */
824 assert(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
);
827 * prefix in the vni MAC table doesn't include IP so
828 * we need to create a different copy of the prefix.
830 evpn_type2_prefix_vni_mac_copy(&vni_p
, evp
);
832 return bgp_node_lookup(table
, (struct prefix
*)evp
);
836 * Wrapper for node get in both VNI tables.
838 struct bgp_dest
*bgp_evpn_vni_node_get(struct bgpevpn
*vpn
,
839 const struct prefix_evpn
*p
,
840 const struct bgp_path_info
*parent_pi
)
842 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
843 (is_evpn_prefix_ipaddr_none(p
) == true))
844 return bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
846 return bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
850 * Wrapper for node lookup in both VNI tables.
852 struct bgp_dest
*bgp_evpn_vni_node_lookup(const struct bgpevpn
*vpn
,
853 const struct prefix_evpn
*p
,
854 const struct bgp_path_info
*parent_pi
)
856 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
857 (is_evpn_prefix_ipaddr_none(p
) == true))
858 return bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
,
861 return bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
865 * Add (update) or delete MACIP from zebra.
867 static int bgp_zebra_send_remote_macip(struct bgp
*bgp
, struct bgpevpn
*vpn
,
868 const struct prefix_evpn
*p
,
869 const struct ethaddr
*mac
,
870 struct in_addr remote_vtep_ip
, int add
,
871 uint8_t flags
, uint32_t seq
, esi_t
*esi
)
875 static struct in_addr zero_remote_vtep_ip
;
879 if (!zclient
|| zclient
->sock
< 0)
882 /* Don't try to register if Zebra doesn't know of this instance. */
883 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
884 if (BGP_DEBUG(zebra
, ZEBRA
))
886 "%s: No zebra instance to talk to, not installing remote macip",
896 zclient_create_header(
897 s
, add
? ZEBRA_REMOTE_MACIP_ADD
: ZEBRA_REMOTE_MACIP_DEL
,
899 stream_putl(s
, vpn
->vni
);
901 if (mac
) /* Mac Addr */
902 stream_put(s
, &mac
->octet
, ETH_ALEN
);
904 stream_put(s
, &p
->prefix
.macip_addr
.mac
.octet
, ETH_ALEN
);
906 /* IP address length and IP address, if any. */
907 if (is_evpn_prefix_ipaddr_none(p
))
910 ipa_len
= is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BYTELEN
912 stream_putw(s
, ipa_len
);
913 stream_put(s
, &p
->prefix
.macip_addr
.ip
.ip
.addr
, ipa_len
);
915 /* If the ESI is valid that becomes the nexthop; tape out the
916 * VTEP-IP for that case
918 if (bgp_evpn_is_esi_valid(esi
)) {
920 stream_put_in_addr(s
, &zero_remote_vtep_ip
);
923 stream_put_in_addr(s
, &remote_vtep_ip
);
926 /* TX flags - MAC sticky status and/or gateway mac */
927 /* Also TX the sequence number of the best route. */
929 stream_putc(s
, flags
);
931 stream_put(s
, esi
, sizeof(esi_t
));
934 stream_putw_at(s
, 0, stream_get_endp(s
));
936 if (bgp_debug_zebra(NULL
)) {
937 char esi_buf
[ESI_STR_LEN
];
940 esi_to_str(esi
, esi_buf
, sizeof(esi_buf
));
942 snprintf(esi_buf
, sizeof(esi_buf
), "-");
944 "Tx %s MACIP, VNI %u MAC %pEA IP %pIA flags 0x%x seq %u remote VTEP %pI4 esi %s",
945 add
? "ADD" : "DEL", vpn
->vni
,
946 (mac
? mac
: &p
->prefix
.macip_addr
.mac
),
947 &p
->prefix
.macip_addr
.ip
, flags
, seq
, &remote_vtep_ip
,
951 frrtrace(5, frr_bgp
, evpn_mac_ip_zsend
, add
, vpn
, p
, remote_vtep_ip
,
954 return zclient_send_message(zclient
);
958 * Add (update) or delete remote VTEP from zebra.
960 static int bgp_zebra_send_remote_vtep(struct bgp
*bgp
, struct bgpevpn
*vpn
,
961 const struct prefix_evpn
*p
,
962 int flood_control
, int add
)
967 if (!zclient
|| zclient
->sock
< 0)
970 /* Don't try to register if Zebra doesn't know of this instance. */
971 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
972 if (BGP_DEBUG(zebra
, ZEBRA
))
974 "%s: No zebra instance to talk to, not installing remote vtep",
982 zclient_create_header(
983 s
, add
? ZEBRA_REMOTE_VTEP_ADD
: ZEBRA_REMOTE_VTEP_DEL
,
985 stream_putl(s
, vpn
->vni
);
986 if (is_evpn_prefix_ipaddr_v4(p
))
987 stream_put_in_addr(s
, &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
988 else if (is_evpn_prefix_ipaddr_v6(p
)) {
991 "Bad remote IP when trying to %s remote VTEP for VNI %u",
992 add
? "ADD" : "DEL", vpn
->vni
);
995 stream_putl(s
, flood_control
);
997 stream_putw_at(s
, 0, stream_get_endp(s
));
999 if (bgp_debug_zebra(NULL
))
1000 zlog_debug("Tx %s Remote VTEP, VNI %u remote VTEP %pI4",
1001 add
? "ADD" : "DEL", vpn
->vni
,
1002 &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
1004 frrtrace(3, frr_bgp
, evpn_bum_vtep_zsend
, add
, vpn
, p
);
1006 return zclient_send_message(zclient
);
1010 * Build extended communities for EVPN prefix route.
1012 static void build_evpn_type5_route_extcomm(struct bgp
*bgp_vrf
,
1015 struct ecommunity ecom_encap
;
1016 struct ecommunity_val eval
;
1017 struct ecommunity_val eval_rmac
;
1018 bgp_encap_types tnl_type
;
1019 struct listnode
*node
, *nnode
;
1020 struct vrf_route_target
*l3rt
;
1021 struct ecommunity
*old_ecom
;
1022 struct ecommunity
*ecom
;
1023 struct list
*vrf_export_rtl
= NULL
;
1026 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1027 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1028 encode_encap_extcomm(tnl_type
, &eval
);
1029 ecom_encap
.size
= 1;
1030 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1031 ecom_encap
.val
= (uint8_t *)eval
.val
;
1034 if (bgp_attr_get_ecommunity(attr
)) {
1035 old_ecom
= bgp_attr_get_ecommunity(attr
);
1036 ecom
= ecommunity_merge(ecommunity_dup(old_ecom
), &ecom_encap
);
1037 if (!old_ecom
->refcnt
)
1038 ecommunity_free(&old_ecom
);
1040 ecom
= ecommunity_dup(&ecom_encap
);
1041 bgp_attr_set_ecommunity(attr
, ecom
);
1042 attr
->encap_tunneltype
= tnl_type
;
1044 /* Add the export RTs for L3VNI/VRF */
1045 vrf_export_rtl
= bgp_vrf
->vrf_export_rtl
;
1046 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
, l3rt
))
1047 bgp_attr_set_ecommunity(
1048 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1051 /* add the router mac extended community */
1052 if (!is_zero_mac(&attr
->rmac
)) {
1053 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1054 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1060 * Build extended communities for EVPN route.
1061 * This function is applicable for type-2 and type-3 routes. The layer-2 RT
1062 * and ENCAP extended communities are applicable for all routes.
1063 * The default gateway extended community and MAC mobility (sticky) extended
1064 * community are added as needed based on passed settings - only for type-2
1065 * routes. Likewise, the layer-3 RT and Router MAC extended communities are
1066 * added, if present, based on passed settings - only for non-link-local
1069 static void build_evpn_route_extcomm(struct bgpevpn
*vpn
, struct attr
*attr
,
1072 struct ecommunity ecom_encap
;
1073 struct ecommunity ecom_sticky
;
1074 struct ecommunity ecom_default_gw
;
1075 struct ecommunity ecom_na
;
1076 struct ecommunity_val eval
;
1077 struct ecommunity_val eval_sticky
;
1078 struct ecommunity_val eval_default_gw
;
1079 struct ecommunity_val eval_rmac
;
1080 struct ecommunity_val eval_na
;
1083 bgp_encap_types tnl_type
;
1084 struct listnode
*node
, *nnode
;
1085 struct ecommunity
*ecom
;
1086 struct vrf_route_target
*l3rt
;
1088 struct list
*vrf_export_rtl
= NULL
;
1091 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
1092 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
1093 encode_encap_extcomm(tnl_type
, &eval
);
1094 ecom_encap
.size
= 1;
1095 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
1096 ecom_encap
.val
= (uint8_t *)eval
.val
;
1099 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
1100 attr
->encap_tunneltype
= tnl_type
;
1102 /* Add the export RTs for L2VNI */
1103 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
))
1104 bgp_attr_set_ecommunity(
1106 ecommunity_merge(bgp_attr_get_ecommunity(attr
), ecom
));
1108 /* Add the export RTs for L3VNI if told to - caller determines
1109 * when this should be done.
1112 vrf_export_rtl
= bgpevpn_get_vrf_export_rtl(vpn
);
1113 if (vrf_export_rtl
&& !list_isempty(vrf_export_rtl
)) {
1114 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
,
1116 bgp_attr_set_ecommunity(
1119 bgp_attr_get_ecommunity(attr
),
1124 /* Add MAC mobility (sticky) if needed. */
1127 memset(&ecom_sticky
, 0, sizeof(ecom_sticky
));
1128 encode_mac_mobility_extcomm(1, seqnum
, &eval_sticky
);
1129 ecom_sticky
.size
= 1;
1130 ecom_sticky
.unit_size
= ECOMMUNITY_SIZE
;
1131 ecom_sticky
.val
= (uint8_t *)eval_sticky
.val
;
1132 bgp_attr_set_ecommunity(
1133 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1137 /* Add RMAC, if told to. */
1139 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
1140 ecommunity_add_val(bgp_attr_get_ecommunity(attr
), &eval_rmac
,
1144 /* Add default gateway, if needed. */
1145 if (attr
->default_gw
) {
1146 memset(&ecom_default_gw
, 0, sizeof(ecom_default_gw
));
1147 encode_default_gw_extcomm(&eval_default_gw
);
1148 ecom_default_gw
.size
= 1;
1149 ecom_default_gw
.unit_size
= ECOMMUNITY_SIZE
;
1150 ecom_default_gw
.val
= (uint8_t *)eval_default_gw
.val
;
1151 bgp_attr_set_ecommunity(
1152 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1156 proxy
= !!(attr
->es_flags
& ATTR_ES_PROXY_ADVERT
);
1157 if (attr
->router_flag
|| proxy
) {
1158 memset(&ecom_na
, 0, sizeof(ecom_na
));
1159 encode_na_flag_extcomm(&eval_na
, attr
->router_flag
, proxy
);
1161 ecom_na
.unit_size
= ECOMMUNITY_SIZE
;
1162 ecom_na
.val
= (uint8_t *)eval_na
.val
;
1163 bgp_attr_set_ecommunity(
1164 attr
, ecommunity_merge(bgp_attr_get_ecommunity(attr
),
1170 * Add MAC mobility extended community to attribute.
1172 static void add_mac_mobility_to_attr(uint32_t seq_num
, struct attr
*attr
)
1174 struct ecommunity ecom_tmp
;
1175 struct ecommunity_val eval
;
1176 uint8_t *ecom_val_ptr
;
1181 struct ecommunity
*ecomm
= bgp_attr_get_ecommunity(attr
);
1184 encode_mac_mobility_extcomm(0, seq_num
, &eval
);
1186 /* Find current MM ecommunity */
1187 ecom_val_ptr
= NULL
;
1190 for (i
= 0; i
< ecomm
->size
; i
++) {
1191 pnt
= ecomm
->val
+ (i
* ecomm
->unit_size
);
1195 if (type
== ECOMMUNITY_ENCODE_EVPN
1197 == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY
) {
1199 (ecomm
->val
+ (i
* ecomm
->unit_size
));
1205 /* Update the existing MM ecommunity */
1207 memcpy(ecom_val_ptr
, eval
.val
, sizeof(char) * ecomm
->unit_size
);
1209 /* Add MM to existing */
1211 memset(&ecom_tmp
, 0, sizeof(ecom_tmp
));
1213 ecom_tmp
.unit_size
= ECOMMUNITY_SIZE
;
1214 ecom_tmp
.val
= (uint8_t *)eval
.val
;
1217 bgp_attr_set_ecommunity(
1218 attr
, ecommunity_merge(ecomm
, &ecom_tmp
));
1220 bgp_attr_set_ecommunity(attr
,
1221 ecommunity_dup(&ecom_tmp
));
1225 /* Install EVPN route into zebra. */
1226 static int evpn_zebra_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1227 const struct prefix_evpn
*p
,
1228 struct bgp_path_info
*pi
)
1232 int flood_control
= VXLAN_FLOOD_DISABLED
;
1235 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1238 if (pi
->sub_type
== BGP_ROUTE_IMPORTED
) {
1239 if (pi
->attr
->sticky
)
1240 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1241 if (pi
->attr
->default_gw
)
1242 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1243 if (is_evpn_prefix_ipaddr_v6(p
) &&
1244 pi
->attr
->router_flag
)
1245 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1247 seq
= mac_mobility_seqnum(pi
->attr
);
1248 /* if local ES notify zebra that this is a sync path */
1249 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
1250 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1251 if (bgp_evpn_attr_is_proxy(pi
->attr
))
1253 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1256 if (!bgp_evpn_attr_is_sync(pi
->attr
))
1259 /* if a local path is being turned around and sent
1260 * to zebra it is because it is a sync path on
1263 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_SYNC_PATH
);
1264 /* supply the highest peer seq number to zebra
1265 * for MM seq syncing
1267 seq
= bgp_evpn_attr_get_sync_seq(pi
->attr
);
1268 /* if any of the paths from the peer have the ROUTER
1269 * flag set install the local entry as a router entry
1271 if (is_evpn_prefix_ipaddr_v6(p
) &&
1272 (pi
->attr
->es_flags
&
1273 ATTR_ES_PEER_ROUTER
))
1275 ZEBRA_MACIP_TYPE_ROUTER_FLAG
);
1277 if (!(pi
->attr
->es_flags
& ATTR_ES_PEER_ACTIVE
))
1279 ZEBRA_MACIP_TYPE_PROXY_ADVERT
);
1282 ret
= bgp_zebra_send_remote_macip(
1284 (is_evpn_prefix_ipaddr_none(p
)
1285 ? NULL
/* MAC update */
1286 : evpn_type2_path_info_get_mac(
1287 pi
) /* MAC-IP update */),
1288 pi
->attr
->nexthop
, 1, flags
, seq
,
1289 bgp_evpn_attr_get_esi(pi
->attr
));
1290 } else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
1291 ret
= bgp_evpn_remote_es_evi_add(bgp
, vpn
, p
);
1293 switch (bgp_attr_get_pmsi_tnl_type(pi
->attr
)) {
1294 case PMSI_TNLTYPE_INGR_REPL
:
1295 flood_control
= VXLAN_FLOOD_HEAD_END_REPL
;
1298 case PMSI_TNLTYPE_PIM_SM
:
1299 flood_control
= VXLAN_FLOOD_PIM_SM
;
1302 case PMSI_TNLTYPE_NO_INFO
:
1303 case PMSI_TNLTYPE_RSVP_TE_P2MP
:
1304 case PMSI_TNLTYPE_MLDP_P2MP
:
1305 case PMSI_TNLTYPE_PIM_SSM
:
1306 case PMSI_TNLTYPE_PIM_BIDIR
:
1307 case PMSI_TNLTYPE_MLDP_MP2MP
:
1308 flood_control
= VXLAN_FLOOD_DISABLED
;
1311 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
, flood_control
, 1);
1317 /* Uninstall EVPN route from zebra. */
1318 static int evpn_zebra_uninstall(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1319 const struct prefix_evpn
*p
,
1320 struct bgp_path_info
*pi
, bool is_sync
)
1324 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
1325 ret
= bgp_zebra_send_remote_macip(
1327 (is_evpn_prefix_ipaddr_none(p
)
1328 ? NULL
/* MAC update */
1329 : evpn_type2_path_info_get_mac(
1330 pi
) /* MAC-IP update */),
1331 (is_sync
? zero_vtep_ip
: pi
->attr
->nexthop
), 0, 0, 0,
1333 else if (p
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
1334 ret
= bgp_evpn_remote_es_evi_del(bgp
, vpn
, p
);
1336 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
,
1337 VXLAN_FLOOD_DISABLED
, 0);
1343 * Due to MAC mobility, the prior "local" best route has been supplanted
1344 * by a "remote" best route. The prior route has to be deleted and withdrawn
1347 static void evpn_delete_old_local_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1348 struct bgp_dest
*dest
,
1349 struct bgp_path_info
*old_local
,
1350 struct bgp_path_info
*new_select
)
1352 struct bgp_dest
*global_dest
;
1353 struct bgp_path_info
*pi
;
1354 afi_t afi
= AFI_L2VPN
;
1355 safi_t safi
= SAFI_EVPN
;
1357 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1358 char esi_buf
[ESI_STR_LEN
];
1359 char esi_buf2
[ESI_STR_LEN
];
1360 struct prefix_evpn
*evp
=
1361 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1363 zlog_debug("local path deleted %pFX es %s; new-path-es %s", evp
,
1364 esi_to_str(&old_local
->attr
->esi
, esi_buf
,
1366 new_select
? esi_to_str(&new_select
->attr
->esi
,
1367 esi_buf2
, sizeof(esi_buf2
))
1371 /* Locate route node in the global EVPN routing table. Note that
1372 * this table is a 2-level tree (RD-level + Prefix-level) similar to
1375 global_dest
= bgp_evpn_global_node_lookup(
1376 bgp
->rib
[afi
][safi
], afi
, safi
,
1377 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1378 &vpn
->prd
, old_local
);
1380 /* Delete route entry in the global EVPN table. */
1381 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
1383 /* Schedule for processing - withdraws to peers happen from
1387 bgp_process(bgp
, global_dest
, afi
, safi
);
1388 bgp_dest_unlock_node(global_dest
);
1391 /* Delete route entry in the VNI route table, caller to remove. */
1392 bgp_path_info_delete(dest
, old_local
);
1396 * Calculate the best path for an EVPN route. Install/update best path in zebra,
1398 * Note: vpn is NULL for local EAD-ES routes.
1400 int evpn_route_select_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1401 struct bgp_dest
*dest
)
1403 struct bgp_path_info
*old_select
, *new_select
;
1404 struct bgp_path_info_pair old_and_new
;
1405 afi_t afi
= AFI_L2VPN
;
1406 safi_t safi
= SAFI_EVPN
;
1409 /* Compute the best path. */
1410 bgp_best_selection(bgp
, dest
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
1412 old_select
= old_and_new
.old
;
1413 new_select
= old_and_new
.new;
1415 /* If the best path hasn't changed - see if there is still something to
1416 * update to zebra RIB.
1417 * Remote routes and SYNC route (i.e. local routes with
1418 * SYNCED_FROM_PEER flag) need to updated to zebra on any attr
1421 if (old_select
&& old_select
== new_select
1422 && old_select
->type
== ZEBRA_ROUTE_BGP
1423 && (old_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1424 bgp_evpn_attr_is_sync(old_select
->attr
))
1425 && !CHECK_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
)
1426 && !CHECK_FLAG(old_select
->flags
, BGP_PATH_ATTR_CHANGED
)
1427 && !bgp_addpath_is_addpath_used(&bgp
->tx_addpath
, afi
, safi
)) {
1428 if (bgp_zebra_has_route_changed(old_select
))
1429 ret
= evpn_zebra_install(
1431 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1434 UNSET_FLAG(old_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1435 UNSET_FLAG(old_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1436 bgp_zebra_clear_route_change_flags(dest
);
1440 /* If the user did a "clear" this flag will be set */
1441 UNSET_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
);
1443 /* bestpath has changed; update relevant fields and install or uninstall
1444 * into the zebra RIB.
1446 if (old_select
|| new_select
)
1447 bgp_bump_version(dest
);
1450 bgp_path_info_unset_flag(dest
, old_select
, BGP_PATH_SELECTED
);
1452 bgp_path_info_set_flag(dest
, new_select
, BGP_PATH_SELECTED
);
1453 bgp_path_info_unset_flag(dest
, new_select
,
1454 BGP_PATH_ATTR_CHANGED
);
1455 UNSET_FLAG(new_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
1456 UNSET_FLAG(new_select
->flags
, BGP_PATH_LINK_BW_CHG
);
1459 /* a local entry with the SYNC flag also results in a MAC-IP update
1462 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
1463 && (new_select
->sub_type
== BGP_ROUTE_IMPORTED
||
1464 bgp_evpn_attr_is_sync(new_select
->attr
))) {
1465 ret
= evpn_zebra_install(
1467 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
1470 /* If an old best existed and it was a "local" route, the only
1472 * it would be supplanted is due to MAC mobility procedures. So,
1474 * need to do an implicit delete and withdraw that route from
1477 if (new_select
->sub_type
== BGP_ROUTE_IMPORTED
&&
1478 old_select
&& old_select
->peer
== bgp
->peer_self
1479 && old_select
->type
== ZEBRA_ROUTE_BGP
1480 && old_select
->sub_type
== BGP_ROUTE_STATIC
1482 evpn_delete_old_local_route(bgp
, vpn
, dest
,
1483 old_select
, new_select
);
1485 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
1486 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
1487 ret
= evpn_zebra_uninstall(
1489 (const struct prefix_evpn
*)bgp_dest_get_prefix(
1494 /* Clear any route change flags. */
1495 bgp_zebra_clear_route_change_flags(dest
);
1497 /* Reap old select bgp_path_info, if it has been removed */
1498 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_PATH_REMOVED
))
1499 bgp_path_info_reap(dest
, old_select
);
1504 static struct bgp_path_info
*bgp_evpn_route_get_local_path(
1505 struct bgp
*bgp
, struct bgp_dest
*dest
)
1507 struct bgp_path_info
*tmp_pi
;
1508 struct bgp_path_info
*local_pi
= NULL
;
1510 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1511 tmp_pi
= tmp_pi
->next
) {
1512 if (bgp_evpn_is_path_local(bgp
, tmp_pi
)) {
1521 static int update_evpn_type5_route_entry(struct bgp
*bgp_evpn
,
1522 struct bgp
*bgp_vrf
, afi_t afi
,
1523 safi_t safi
, struct bgp_dest
*dest
,
1524 struct attr
*attr
, int *route_changed
)
1526 struct attr
*attr_new
= NULL
;
1527 struct bgp_path_info
*pi
= NULL
;
1528 mpls_label_t label
= MPLS_INVALID_LABEL
;
1529 struct bgp_path_info
*local_pi
= NULL
;
1530 struct bgp_path_info
*tmp_pi
= NULL
;
1533 /* locate the local route entry if any */
1534 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1535 tmp_pi
= tmp_pi
->next
) {
1536 if (tmp_pi
->peer
== bgp_evpn
->peer_self
1537 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
1538 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
1543 * create a new route entry if one doesn't exist.
1544 * Otherwise see if route attr has changed
1548 /* route has changed as this is the first entry */
1551 /* Add (or update) attribute to hash. */
1552 attr_new
= bgp_attr_intern(attr
);
1554 /* create the route info from attribute */
1555 pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1556 bgp_evpn
->peer_self
, attr_new
, dest
);
1557 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
1559 /* Type-5 routes advertise the L3-VNI */
1560 bgp_path_info_extra_get(pi
);
1561 vni2label(bgp_vrf
->l3vni
, &label
);
1562 memcpy(&pi
->extra
->label
, &label
, sizeof(label
));
1563 pi
->extra
->num_labels
= 1;
1565 /* add the route entry to route node*/
1566 bgp_path_info_add(dest
, pi
);
1570 if (!attrhash_cmp(tmp_pi
->attr
, attr
)) {
1572 /* attribute changed */
1575 /* The attribute has changed. */
1576 /* Add (or update) attribute to hash. */
1577 attr_new
= bgp_attr_intern(attr
);
1578 bgp_path_info_set_flag(dest
, tmp_pi
,
1579 BGP_PATH_ATTR_CHANGED
);
1581 /* Restore route, if needed. */
1582 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1583 bgp_path_info_restore(dest
, tmp_pi
);
1585 /* Unintern existing, set to new. */
1586 bgp_attr_unintern(&tmp_pi
->attr
);
1587 tmp_pi
->attr
= attr_new
;
1588 tmp_pi
->uptime
= monotime(NULL
);
1594 /* update evpn type-5 route entry */
1595 static int update_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
,
1596 struct attr
*src_attr
, afi_t src_afi
,
1599 afi_t afi
= AFI_L2VPN
;
1600 safi_t safi
= SAFI_EVPN
;
1602 struct bgp_dest
*dest
= NULL
;
1603 struct bgp
*bgp_evpn
= NULL
;
1604 int route_changed
= 0;
1606 bgp_evpn
= bgp_get_evpn();
1610 /* Build path attribute for this route - use the source attr, if
1611 * present, else treat as locally originated.
1616 memset(&attr
, 0, sizeof(attr
));
1617 bgp_attr_default_set(&attr
, bgp_vrf
, BGP_ORIGIN_IGP
);
1620 /* Advertise Primary IP (PIP) is enabled, send individual
1621 * IP (default instance router-id) as nexthop.
1622 * PIP is disabled or vrr interface is not present
1623 * use anycast-IP as nexthop and anycast RMAC.
1625 if (!bgp_vrf
->evpn_info
->advertise_pip
||
1626 (!bgp_vrf
->evpn_info
->is_anycast_mac
)) {
1627 attr
.nexthop
= bgp_vrf
->originator_ip
;
1628 attr
.mp_nexthop_global_in
= bgp_vrf
->originator_ip
;
1629 memcpy(&attr
.rmac
, &bgp_vrf
->rmac
, ETH_ALEN
);
1632 memcpy(&attr
.rmac
, &bgp_vrf
->evpn_info
->pip_rmac
, ETH_ALEN
);
1633 if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
!= INADDR_ANY
) {
1634 attr
.nexthop
= bgp_vrf
->evpn_info
->pip_ip
;
1635 attr
.mp_nexthop_global_in
= bgp_vrf
->evpn_info
->pip_ip
;
1636 } else if (bgp_vrf
->evpn_info
->pip_ip
.s_addr
== INADDR_ANY
)
1637 if (bgp_debug_zebra(NULL
))
1639 "VRF %s evp %pFX advertise-pip primary ip is not configured",
1640 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
);
1643 if (bgp_debug_zebra(NULL
))
1645 "VRF %s type-5 route evp %pFX RMAC %pEA nexthop %pI4",
1646 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, &attr
.rmac
,
1649 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1651 if (src_afi
== AFI_IP6
&&
1652 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1653 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
)) {
1655 !IN6_IS_ADDR_UNSPECIFIED(&src_attr
->mp_nexthop_global
)) {
1656 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1657 SET_IPADDR_V6(&attr
.evpn_overlay
.gw_ip
);
1658 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
1659 &src_attr
->mp_nexthop_global
,
1660 sizeof(struct in6_addr
));
1662 } else if (src_afi
== AFI_IP
&&
1663 CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
1664 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
)) {
1665 if (src_attr
&& src_attr
->nexthop
.s_addr
!= 0) {
1666 attr
.evpn_overlay
.type
= OVERLAY_INDEX_GATEWAY_IP
;
1667 SET_IPADDR_V4(&attr
.evpn_overlay
.gw_ip
);
1668 memcpy(&attr
.evpn_overlay
.gw_ip
.ipaddr_v4
,
1669 &src_attr
->nexthop
, sizeof(struct in_addr
));
1673 /* Setup RT and encap extended community */
1674 build_evpn_type5_route_extcomm(bgp_vrf
, &attr
);
1676 /* get the route node in global table */
1677 dest
= bgp_evpn_global_node_get(bgp_evpn
->rib
[afi
][safi
], afi
, safi
,
1678 evp
, &bgp_vrf
->vrf_prd
, NULL
);
1681 /* create or update the route entry within the route node */
1682 update_evpn_type5_route_entry(bgp_evpn
, bgp_vrf
, afi
, safi
, dest
, &attr
,
1685 /* schedule for processing and unlock node */
1686 if (route_changed
) {
1687 bgp_process(bgp_evpn
, dest
, afi
, safi
);
1688 bgp_dest_unlock_node(dest
);
1691 /* uninten temporary */
1693 aspath_unintern(&attr
.aspath
);
1697 static void bgp_evpn_get_sync_info(struct bgp
*bgp
, esi_t
*esi
,
1698 struct bgp_dest
*dest
, uint32_t loc_seq
,
1699 uint32_t *max_sync_seq
, bool *active_on_peer
,
1700 bool *peer_router
, bool *proxy_from_peer
,
1701 const struct ethaddr
*mac
)
1703 struct bgp_path_info
*tmp_pi
;
1704 struct bgp_path_info
*second_best_path
= NULL
;
1705 uint32_t tmp_mm_seq
= 0;
1708 struct ethaddr
*tmp_mac
;
1709 bool mac_cmp
= false;
1710 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&dest
->p
;
1713 /* mac comparison is not needed for MAC-only routes */
1714 if (mac
&& !is_evpn_prefix_ipaddr_none(evp
))
1717 /* find the best non-local path. a local path can only be present
1720 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
1721 tmp_pi
= tmp_pi
->next
) {
1722 if (tmp_pi
->sub_type
!= BGP_ROUTE_IMPORTED
||
1723 !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
))
1726 /* ignore paths that have a different mac */
1728 tmp_mac
= evpn_type2_path_info_get_mac(tmp_pi
);
1729 if (memcmp(mac
, tmp_mac
, sizeof(*mac
)))
1733 if (bgp_evpn_path_info_cmp(bgp
, tmp_pi
,
1734 second_best_path
, &paths_eq
))
1735 second_best_path
= tmp_pi
;
1738 if (!second_best_path
)
1741 tmp_esi
= bgp_evpn_attr_get_esi(second_best_path
->attr
);
1742 /* if this has the same ES desination as the local path
1745 if (!memcmp(esi
, tmp_esi
, sizeof(esi_t
))) {
1746 tmp_mm_seq
= mac_mobility_seqnum(second_best_path
->attr
);
1747 if (tmp_mm_seq
< loc_seq
)
1750 /* we have a non-proxy path from the ES peer. */
1751 if (second_best_path
->attr
->es_flags
&
1752 ATTR_ES_PROXY_ADVERT
) {
1753 *proxy_from_peer
= true;
1755 *active_on_peer
= true;
1758 if (second_best_path
->attr
->router_flag
)
1759 *peer_router
= true;
1761 /* we use both proxy and non-proxy imports to
1762 * determine the max sync sequence
1764 if (tmp_mm_seq
> *max_sync_seq
)
1765 *max_sync_seq
= tmp_mm_seq
;
1769 /* Bubble up sync-info from all paths (non-best) to the local-path.
1770 * This is need for MM sequence number syncing and proxy advertisement.
1771 * Note: The local path can only exist as a best path in the
1772 * VPN route table. It will take precedence over all sync paths.
1774 static void update_evpn_route_entry_sync_info(struct bgp
*bgp
,
1775 struct bgp_dest
*dest
,
1777 uint32_t loc_seq
, bool setup_sync
,
1778 const struct ethaddr
*mac
)
1781 struct prefix_evpn
*evp
=
1782 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1784 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
1787 esi
= bgp_evpn_attr_get_esi(attr
);
1788 if (bgp_evpn_is_esi_valid(esi
)) {
1790 uint32_t max_sync_seq
= 0;
1791 bool active_on_peer
= false;
1792 bool peer_router
= false;
1793 bool proxy_from_peer
= false;
1795 bgp_evpn_get_sync_info(bgp
, esi
, dest
, loc_seq
,
1796 &max_sync_seq
, &active_on_peer
,
1797 &peer_router
, &proxy_from_peer
,
1799 attr
->mm_sync_seqnum
= max_sync_seq
;
1801 attr
->es_flags
|= ATTR_ES_PEER_ACTIVE
;
1803 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1804 if (proxy_from_peer
)
1805 attr
->es_flags
|= ATTR_ES_PEER_PROXY
;
1807 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1809 attr
->es_flags
|= ATTR_ES_PEER_ROUTER
;
1811 attr
->es_flags
&= ~ATTR_ES_PEER_ROUTER
;
1813 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
1814 char esi_buf
[ESI_STR_LEN
];
1817 "setup sync info for %pFX es %s max_seq %d %s%s%s",
1819 esi_to_str(esi
, esi_buf
,
1822 (attr
->es_flags
& ATTR_ES_PEER_ACTIVE
)
1825 (attr
->es_flags
& ATTR_ES_PEER_PROXY
)
1828 (attr
->es_flags
& ATTR_ES_PEER_ROUTER
)
1834 attr
->mm_sync_seqnum
= 0;
1835 attr
->es_flags
&= ~ATTR_ES_PEER_ACTIVE
;
1836 attr
->es_flags
&= ~ATTR_ES_PEER_PROXY
;
1841 * Create or update EVPN route entry. This could be in the VNI route tables
1842 * or the global route table.
1844 static int update_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1845 afi_t afi
, safi_t safi
,
1846 struct bgp_dest
*dest
, struct attr
*attr
,
1847 const struct ethaddr
*mac
,
1848 const struct ipaddr
*ip
, int add
,
1849 struct bgp_path_info
**pi
, uint8_t flags
,
1850 uint32_t seq
, bool vpn_rt
, bool *old_is_sync
)
1852 struct bgp_path_info
*tmp_pi
;
1853 struct bgp_path_info
*local_pi
;
1854 struct attr
*attr_new
;
1855 mpls_label_t label
[BGP_MAX_LABELS
];
1856 uint32_t num_labels
= 1;
1857 int route_change
= 1;
1859 const struct prefix_evpn
*evp
;
1862 evp
= (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
1863 memset(&label
, 0, sizeof(label
));
1865 /* See if this is an update of an existing route, or a new add. */
1866 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
1868 /* If route doesn't exist already, create a new one, if told to.
1869 * Otherwise act based on whether the attributes of the route have
1872 if (!local_pi
&& !add
)
1875 if (old_is_sync
&& local_pi
)
1876 *old_is_sync
= bgp_evpn_attr_is_sync(local_pi
->attr
);
1878 /* if a local path is being added with a non-zero esi look
1879 * for SYNC paths from ES peers and bubble up the sync-info
1881 update_evpn_route_entry_sync_info(bgp
, dest
, attr
, seq
, vpn_rt
, mac
);
1883 /* For non-GW MACs, update MAC mobility seq number, if needed. */
1884 if (seq
&& !CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
))
1885 add_mac_mobility_to_attr(seq
, attr
);
1888 /* Add (or update) attribute to hash. */
1889 attr_new
= bgp_attr_intern(attr
);
1891 /* Extract MAC mobility sequence number, if any. */
1892 attr_new
->mm_seqnum
=
1893 bgp_attr_mac_mobility_seqnum(attr_new
, &sticky
);
1894 attr_new
->sticky
= sticky
;
1896 /* Create new route with its attribute. */
1897 tmp_pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1898 bgp
->peer_self
, attr_new
, dest
);
1899 SET_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
);
1900 bgp_path_info_extra_get(tmp_pi
);
1902 /* The VNI goes into the 'label' field of the route */
1903 vni2label(vpn
->vni
, &label
[0]);
1905 /* Type-2 routes may carry a second VNI - the L3-VNI.
1906 * Only attach second label if we are advertising two labels for
1909 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1910 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
1913 l3vni
= bgpevpn_get_l3vni(vpn
);
1915 vni2label(l3vni
, &label
[1]);
1920 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1921 tmp_pi
->extra
->num_labels
= num_labels
;
1923 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1925 evpn_type2_path_info_set_mac(tmp_pi
, *mac
);
1927 evpn_type2_path_info_set_ip(tmp_pi
, *ip
);
1930 /* Mark route as self type-2 route */
1931 if (flags
&& CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
1932 tmp_pi
->extra
->af_flags
= BGP_EVPN_MACIP_TYPE_SVI_IP
;
1933 bgp_path_info_add(dest
, tmp_pi
);
1936 if (attrhash_cmp(tmp_pi
->attr
, attr
)
1937 && !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1941 * The attributes have changed, type-2 routes needs to
1942 * be advertised with right labels.
1944 vni2label(vpn
->vni
, &label
[0]);
1945 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1946 && CHECK_FLAG(vpn
->flags
,
1947 VNI_FLAG_USE_TWO_LABELS
)) {
1950 l3vni
= bgpevpn_get_l3vni(vpn
);
1952 vni2label(l3vni
, &label
[1]);
1956 memcpy(&tmp_pi
->extra
->label
, label
, sizeof(label
));
1957 tmp_pi
->extra
->num_labels
= num_labels
;
1959 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
1961 evpn_type2_path_info_set_mac(tmp_pi
,
1964 evpn_type2_path_info_set_ip(tmp_pi
,
1968 /* The attribute has changed. */
1969 /* Add (or update) attribute to hash. */
1970 attr_new
= bgp_attr_intern(attr
);
1971 bgp_path_info_set_flag(dest
, tmp_pi
,
1972 BGP_PATH_ATTR_CHANGED
);
1974 /* Extract MAC mobility sequence number, if any. */
1975 attr_new
->mm_seqnum
=
1976 bgp_attr_mac_mobility_seqnum(attr_new
, &sticky
);
1977 attr_new
->sticky
= sticky
;
1979 /* Restore route, if needed. */
1980 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
1981 bgp_path_info_restore(dest
, tmp_pi
);
1983 /* Unintern existing, set to new. */
1984 bgp_attr_unintern(&tmp_pi
->attr
);
1985 tmp_pi
->attr
= attr_new
;
1986 tmp_pi
->uptime
= monotime(NULL
);
1990 /* local MAC-IP routes in the VNI table are linked to
1991 * the destination ES
1993 if (route_change
&& vpn_rt
1994 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
))
1995 bgp_evpn_path_es_link(tmp_pi
, vpn
->vni
,
1996 bgp_evpn_attr_get_esi(tmp_pi
->attr
));
1998 /* Return back the route entry. */
2000 return route_change
;
2003 static void evpn_zebra_reinstall_best_route(struct bgp
*bgp
,
2004 struct bgpevpn
*vpn
,
2005 struct bgp_dest
*dest
)
2007 struct bgp_path_info
*tmp_ri
;
2008 struct bgp_path_info
*curr_select
= NULL
;
2010 for (tmp_ri
= bgp_dest_get_bgp_path_info(dest
); tmp_ri
;
2011 tmp_ri
= tmp_ri
->next
) {
2012 if (CHECK_FLAG(tmp_ri
->flags
, BGP_PATH_SELECTED
)) {
2013 curr_select
= tmp_ri
;
2018 if (curr_select
&& curr_select
->type
== ZEBRA_ROUTE_BGP
2019 && (curr_select
->sub_type
== BGP_ROUTE_IMPORTED
||
2020 bgp_evpn_attr_is_sync(curr_select
->attr
)))
2021 evpn_zebra_install(bgp
, vpn
,
2022 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
),
2027 * If the local route was not selected evict it and tell zebra to re-add
2028 * the best remote dest.
2030 * Typically a local path added by zebra is expected to be selected as
2031 * best. In which case when a remote path wins as best (later)
2032 * evpn_route_select_install itself evicts the older-local-best path.
2034 * However if bgp's add and zebra's add cross paths (race condition) it
2035 * is possible that the local path is no longer the "older" best path.
2036 * It is a path that was never designated as best and hence requires
2037 * additional handling to prevent bgp from injecting and holding on to a
2038 * non-best local path.
2040 static void evpn_cleanup_local_non_best_route(struct bgp
*bgp
,
2041 struct bgpevpn
*vpn
,
2042 struct bgp_dest
*dest
,
2043 struct bgp_path_info
*local_pi
)
2045 /* local path was not picked as the winner; kick it out */
2046 if (bgp_debug_zebra(NULL
))
2047 zlog_debug("evicting local evpn prefix %pBD as remote won",
2050 evpn_delete_old_local_route(bgp
, vpn
, dest
, local_pi
, NULL
);
2051 bgp_path_info_reap(dest
, local_pi
);
2053 /* tell zebra to re-add the best remote path */
2054 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
2057 static inline bool bgp_evpn_route_add_l3_ecomm_ok(struct bgpevpn
*vpn
,
2058 const struct prefix_evpn
*p
,
2061 return p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
2062 && (is_evpn_prefix_ipaddr_v4(p
)
2063 || (is_evpn_prefix_ipaddr_v6(p
)
2064 && !IN6_IS_ADDR_LINKLOCAL(
2065 &p
->prefix
.macip_addr
.ip
.ipaddr_v6
)))
2066 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)
2067 && bgpevpn_get_l3vni(vpn
) && bgp_evpn_es_add_l3_ecomm_ok(esi
);
2071 * Create or update EVPN route (of type based on prefix) for specified VNI
2072 * and schedule for processing.
2074 static int update_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2075 struct prefix_evpn
*p
, uint8_t flags
,
2076 uint32_t seq
, esi_t
*esi
)
2078 struct bgp_dest
*dest
;
2080 struct attr
*attr_new
;
2081 int add_l3_ecomm
= 0;
2082 struct bgp_path_info
*pi
;
2083 afi_t afi
= AFI_L2VPN
;
2084 safi_t safi
= SAFI_EVPN
;
2086 bool old_is_sync
= false;
2087 bool mac_only
= false;
2089 memset(&attr
, 0, sizeof(attr
));
2091 /* Build path-attribute for this route. */
2092 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2093 attr
.nexthop
= vpn
->originator_ip
;
2094 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2095 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2096 attr
.sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
) ? 1 : 0;
2097 attr
.default_gw
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
) ? 1 : 0;
2098 attr
.router_flag
= CHECK_FLAG(flags
,
2099 ZEBRA_MACIP_TYPE_ROUTER_FLAG
) ? 1 : 0;
2100 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_PROXY_ADVERT
))
2101 attr
.es_flags
|= ATTR_ES_PROXY_ADVERT
;
2103 if (esi
&& bgp_evpn_is_esi_valid(esi
)) {
2104 memcpy(&attr
.esi
, esi
, sizeof(esi_t
));
2105 attr
.es_flags
|= ATTR_ES_IS_LOCAL
;
2108 /* PMSI is only needed for type-3 routes */
2109 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
) {
2110 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
);
2111 bgp_attr_set_pmsi_tnl_type(&attr
, PMSI_TNLTYPE_INGR_REPL
);
2114 /* router mac is only needed for type-2 routes here. */
2115 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
2116 uint8_t af_flags
= 0;
2118 if (CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_SVI_IP
))
2119 SET_FLAG(af_flags
, BGP_EVPN_MACIP_TYPE_SVI_IP
);
2121 bgp_evpn_get_rmac_nexthop(vpn
, p
, &attr
, af_flags
);
2124 if (bgp_debug_zebra(NULL
)) {
2125 char buf3
[ESI_STR_LEN
];
2128 "VRF %s vni %u type-%u route evp %pFX RMAC %pEA nexthop %pI4 esi %s",
2129 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2131 vpn
->vni
, p
->prefix
.route_type
, p
, &attr
.rmac
,
2132 &attr
.mp_nexthop_global_in
,
2133 esi_to_str(esi
, buf3
, sizeof(buf3
)));
2136 vni2label(vpn
->vni
, &(attr
.label
));
2138 /* Include L3 VNI related RTs and RMAC for type-2 routes, if they're
2139 * IPv4 or IPv6 global addresses and we're advertising L3VNI with
2142 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2143 vpn
, p
, (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2145 /* Set up extended community. */
2146 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2148 /* First, create (or fetch) route node within the VNI.
2149 * NOTE: There is no RD here.
2151 dest
= bgp_evpn_vni_node_get(vpn
, p
, NULL
);
2153 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
2154 (is_evpn_prefix_ipaddr_none(p
) == true))
2157 /* Create or update route entry. */
2158 route_change
= update_evpn_route_entry(
2159 bgp
, vpn
, afi
, safi
, dest
, &attr
,
2160 (mac_only
? NULL
: &p
->prefix
.macip_addr
.mac
), NULL
/* ip */, 1,
2161 &pi
, flags
, seq
, true /* setup_sync */, &old_is_sync
);
2163 attr_new
= pi
->attr
;
2165 /* lock ri to prevent freeing in evpn_route_select_install */
2166 bgp_path_info_lock(pi
);
2168 /* Perform route selection. Normally, the local route in the
2169 * VNI is expected to win and be the best route. However, if
2170 * there is a race condition where a host moved from local to
2171 * remote and the remote route was received in BGP just prior
2172 * to the local MACIP notification from zebra, the remote
2173 * route would win, and we should evict the defunct local route
2174 * and (re)install the remote route into zebra.
2176 evpn_route_select_install(bgp
, vpn
, dest
);
2178 * If the new local route was not selected evict it and tell zebra
2179 * to re-add the best remote dest. BGP doesn't retain non-best local
2182 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2185 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2187 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2191 /* If the local path already existed and is still the
2192 * best path we need to also check if it transitioned
2193 * from being a sync path to a non-sync path. If it
2194 * it did we need to notify zebra that the sync-path
2197 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2198 if (!new_is_sync
&& old_is_sync
)
2199 evpn_zebra_uninstall(bgp
, vpn
, p
, pi
, true);
2202 bgp_path_info_unlock(pi
);
2204 bgp_dest_unlock_node(dest
);
2206 /* If this is a new route or some attribute has changed, export the
2207 * route to the global table. The route will be advertised to peers
2208 * from there. Note that this table is a 2-level tree (RD-level +
2209 * Prefix-level) similar to L3VPN routes.
2212 struct bgp_path_info
*global_pi
;
2214 dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
2215 p
, &vpn
->prd
, NULL
);
2216 update_evpn_route_entry(
2217 bgp
, vpn
, afi
, safi
, dest
, attr_new
, NULL
/* mac */,
2218 NULL
/* ip */, 1, &global_pi
, flags
, seq
,
2219 false /* setup_sync */, NULL
/* old_is_sync */);
2221 /* Schedule for processing and unlock node. */
2222 bgp_process(bgp
, dest
, afi
, safi
);
2223 bgp_dest_unlock_node(dest
);
2226 /* Unintern temporary. */
2227 aspath_unintern(&attr
.aspath
);
2233 * Delete EVPN route entry.
2234 * The entry can be in ESI/VNI table or the global table.
2236 void delete_evpn_route_entry(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
2237 struct bgp_dest
*dest
,
2238 struct bgp_path_info
**pi
)
2240 struct bgp_path_info
*tmp_pi
;
2244 /* Now, find matching route. */
2245 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2246 tmp_pi
= tmp_pi
->next
)
2247 if (tmp_pi
->peer
== bgp
->peer_self
2248 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
2249 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2254 /* Mark route for delete. */
2256 bgp_path_info_delete(dest
, tmp_pi
);
2259 /* Delete EVPN type5 route */
2260 static int delete_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
)
2262 afi_t afi
= AFI_L2VPN
;
2263 safi_t safi
= SAFI_EVPN
;
2264 struct bgp_dest
*dest
= NULL
;
2265 struct bgp_path_info
*pi
= NULL
;
2266 struct bgp
*bgp_evpn
= NULL
; /* evpn bgp instance */
2268 bgp_evpn
= bgp_get_evpn();
2272 /* locate the global route entry for this type-5 prefix */
2273 dest
= bgp_evpn_global_node_lookup(bgp_evpn
->rib
[afi
][safi
], afi
, safi
,
2274 evp
, &bgp_vrf
->vrf_prd
, NULL
);
2278 delete_evpn_route_entry(bgp_evpn
, afi
, safi
, dest
, &pi
);
2280 bgp_process(bgp_evpn
, dest
, afi
, safi
);
2281 bgp_dest_unlock_node(dest
);
2286 * Delete EVPN route (of type based on prefix) for specified VNI and
2287 * schedule for processing.
2289 static int delete_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2290 struct prefix_evpn
*p
)
2292 struct bgp_dest
*dest
, *global_dest
;
2293 struct bgp_path_info
*pi
;
2294 afi_t afi
= AFI_L2VPN
;
2295 safi_t safi
= SAFI_EVPN
;
2297 /* First, locate the route node within the VNI. If it doesn't exist,
2299 * is nothing further to do.
2300 * NOTE: There is no RD here.
2302 dest
= bgp_evpn_vni_node_lookup(vpn
, p
, NULL
);
2306 /* Next, locate route node in the global EVPN routing table. Note that
2307 * this table is a 2-level tree (RD-level + Prefix-level) similar to
2310 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], afi
,
2311 safi
, p
, &vpn
->prd
, NULL
);
2313 /* Delete route entry in the global EVPN table. */
2314 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
2316 /* Schedule for processing - withdraws to peers happen from
2320 bgp_process(bgp
, global_dest
, afi
, safi
);
2321 bgp_dest_unlock_node(global_dest
);
2324 /* Delete route entry in the VNI route table. This can just be removed.
2326 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2328 bgp_path_info_reap(dest
, pi
);
2329 evpn_route_select_install(bgp
, vpn
, dest
);
2331 bgp_dest_unlock_node(dest
);
2336 void bgp_evpn_update_type2_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2337 struct bgp_dest
*dest
,
2338 struct bgp_path_info
*local_pi
,
2341 afi_t afi
= AFI_L2VPN
;
2342 safi_t safi
= SAFI_EVPN
;
2343 struct bgp_path_info
*pi
;
2345 struct attr
*attr_new
;
2347 int add_l3_ecomm
= 0;
2348 struct bgp_dest
*global_dest
;
2349 struct bgp_path_info
*global_pi
;
2350 struct prefix_evpn evp
;
2352 bool old_is_sync
= false;
2354 if (CHECK_FLAG(local_pi
->flags
, BGP_PATH_REMOVED
))
2358 * VNI table MAC-IP prefixes don't have MAC so make sure it's set from
2361 if (is_evpn_prefix_ipaddr_none((struct prefix_evpn
*)&dest
->p
)) {
2362 /* VNI MAC -> Global */
2363 evpn_type2_prefix_global_copy(
2364 &evp
, (struct prefix_evpn
*)&dest
->p
, NULL
/* mac */,
2365 evpn_type2_path_info_get_ip(local_pi
));
2367 /* VNI IP -> Global */
2368 evpn_type2_prefix_global_copy(
2369 &evp
, (struct prefix_evpn
*)&dest
->p
,
2370 evpn_type2_path_info_get_mac(local_pi
), NULL
/* ip */);
2374 * Build attribute per local route as the MAC mobility and
2375 * some other values could differ for different routes. The
2376 * attributes will be shared in the hash table.
2378 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
2379 attr
.nexthop
= vpn
->originator_ip
;
2380 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
2381 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
2382 attr
.sticky
= (local_pi
->attr
->sticky
) ? 1 : 0;
2383 attr
.router_flag
= (local_pi
->attr
->router_flag
) ? 1 : 0;
2384 attr
.es_flags
= local_pi
->attr
->es_flags
;
2385 if (local_pi
->attr
->default_gw
) {
2386 attr
.default_gw
= 1;
2387 if (is_evpn_prefix_ipaddr_v6(&evp
))
2388 attr
.router_flag
= 1;
2390 memcpy(&attr
.esi
, &local_pi
->attr
->esi
, sizeof(esi_t
));
2391 bgp_evpn_get_rmac_nexthop(vpn
, &evp
, &attr
, local_pi
->extra
->af_flags
);
2392 vni2label(vpn
->vni
, &(attr
.label
));
2393 /* Add L3 VNI RTs and RMAC for non IPv6 link-local if
2394 * using L3 VNI for type-2 routes also.
2396 add_l3_ecomm
= bgp_evpn_route_add_l3_ecomm_ok(
2398 (attr
.es_flags
& ATTR_ES_IS_LOCAL
) ? &attr
.esi
: NULL
);
2400 /* Set up extended community. */
2401 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
2402 seq
= mac_mobility_seqnum(local_pi
->attr
);
2404 if (bgp_debug_zebra(NULL
)) {
2405 char buf3
[ESI_STR_LEN
];
2408 "VRF %s vni %u evp %pFX RMAC %pEA nexthop %pI4 esi %s esf 0x%x from %s",
2409 vpn
->bgp_vrf
? vrf_id_to_name(vpn
->bgp_vrf
->vrf_id
)
2411 vpn
->vni
, &evp
, &attr
.rmac
, &attr
.mp_nexthop_global_in
,
2412 esi_to_str(&attr
.esi
, buf3
, sizeof(buf3
)),
2413 attr
.es_flags
, caller
);
2416 /* Update the route entry. */
2417 route_change
= update_evpn_route_entry(
2418 bgp
, vpn
, afi
, safi
, dest
, &attr
, NULL
/* mac */, NULL
/* ip */,
2419 0, &pi
, 0, seq
, true /* setup_sync */, &old_is_sync
);
2422 attr_new
= pi
->attr
;
2423 /* lock ri to prevent freeing in evpn_route_select_install */
2424 bgp_path_info_lock(pi
);
2426 /* Perform route selection. Normally, the local route in the
2427 * VNI is expected to win and be the best route. However,
2428 * under peculiar situations (e.g., tunnel (next hop) IP change
2429 * that causes best selection to be based on next hop), a
2430 * remote route could win. If the local route is the best,
2431 * ensure it is updated in the global EVPN route table and
2432 * advertised to peers; otherwise, ensure it is evicted and
2433 * (re)install the remote route into zebra.
2435 evpn_route_select_install(bgp
, vpn
, dest
);
2437 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2440 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)) {
2442 evpn_cleanup_local_non_best_route(bgp
, vpn
, dest
, pi
);
2446 /* If the local path already existed and is still the
2447 * best path we need to also check if it transitioned
2448 * from being a sync path to a non-sync path. If it
2449 * it did we need to notify zebra that the sync-path
2452 new_is_sync
= bgp_evpn_attr_is_sync(pi
->attr
);
2453 if (!new_is_sync
&& old_is_sync
)
2454 evpn_zebra_uninstall(bgp
, vpn
, &evp
, pi
, true);
2460 bgp_path_info_unlock(pi
);
2463 /* Update route in global routing table. */
2464 global_dest
= bgp_evpn_global_node_get(
2465 bgp
->rib
[afi
][safi
], afi
, safi
, &evp
, &vpn
->prd
, NULL
);
2466 assert(global_dest
);
2467 update_evpn_route_entry(
2468 bgp
, vpn
, afi
, safi
, global_dest
, attr_new
,
2469 NULL
/* mac */, NULL
/* ip */, 0, &global_pi
, 0,
2470 mac_mobility_seqnum(attr_new
), false /* setup_sync */,
2471 NULL
/* old_is_sync */);
2473 /* Schedule for processing and unlock node. */
2474 bgp_process(bgp
, global_dest
, afi
, safi
);
2475 bgp_dest_unlock_node(global_dest
);
2478 /* Unintern temporary. */
2479 aspath_unintern(&attr
.aspath
);
2482 static void update_type2_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2483 struct bgp_dest
*dest
)
2485 struct bgp_path_info
*tmp_pi
;
2487 const struct prefix_evpn
*evp
=
2488 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2490 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2493 /* Identify local route. */
2494 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
2495 tmp_pi
= tmp_pi
->next
) {
2496 if (tmp_pi
->peer
== bgp
->peer_self
&&
2497 tmp_pi
->type
== ZEBRA_ROUTE_BGP
&&
2498 tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
2505 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, tmp_pi
, __func__
);
2509 * Update all type-2 (MACIP) local routes for this VNI - these should also
2510 * be scheduled for advertise to peers.
2512 static void update_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2514 struct bgp_dest
*dest
;
2516 /* Walk this VNI's route MAC & IP table and update local type-2
2517 * routes. For any routes updated, update corresponding entry in the
2520 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2521 dest
= bgp_route_next(dest
))
2522 update_type2_route(bgp
, vpn
, dest
);
2524 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2525 dest
= bgp_route_next(dest
))
2526 update_type2_route(bgp
, vpn
, dest
);
2530 * Delete all type-2 (MACIP) local routes for this VNI - only from the
2531 * global routing table. These are also scheduled for withdraw from peers.
2533 static void delete_global_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2537 struct bgp_dest
*rddest
, *dest
;
2538 struct bgp_table
*table
;
2539 struct bgp_path_info
*pi
;
2544 rddest
= bgp_node_lookup(bgp
->rib
[afi
][safi
],
2545 (struct prefix
*)&vpn
->prd
);
2547 table
= bgp_dest_get_bgp_table_info(rddest
);
2548 for (dest
= bgp_table_top(table
); dest
;
2549 dest
= bgp_route_next(dest
)) {
2550 const struct prefix_evpn
*evp
=
2551 (const struct prefix_evpn
*)bgp_dest_get_prefix(
2554 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2557 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2559 bgp_process(bgp
, dest
, afi
, safi
);
2562 /* Unlock RD node. */
2563 bgp_dest_unlock_node(rddest
);
2567 static void delete_vni_type2_route(struct bgp
*bgp
, struct bgp_dest
*dest
)
2569 struct bgp_path_info
*pi
;
2570 afi_t afi
= AFI_L2VPN
;
2571 safi_t safi
= SAFI_EVPN
;
2573 const struct prefix_evpn
*evp
=
2574 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
2576 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2579 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
2581 /* Route entry in local table gets deleted immediately. */
2583 bgp_path_info_reap(dest
, pi
);
2586 static void delete_vni_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2588 struct bgp_dest
*dest
;
2590 /* Next, walk this VNI's MAC & IP route table and delete local type-2
2593 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2594 dest
= bgp_route_next(dest
))
2595 delete_vni_type2_route(bgp
, dest
);
2597 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2598 dest
= bgp_route_next(dest
))
2599 delete_vni_type2_route(bgp
, dest
);
2603 * Delete all type-2 (MACIP) local routes for this VNI - from the global
2604 * table as well as the per-VNI route table.
2606 static void delete_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2608 /* First, walk the global route table for this VNI's type-2 local
2610 * EVPN routes are a 2-level table, first get the RD table.
2612 delete_global_type2_routes(bgp
, vpn
);
2613 delete_vni_type2_routes(bgp
, vpn
);
2617 * Delete all routes in the per-VNI route table.
2619 static void delete_all_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2621 struct bgp_dest
*dest
;
2622 struct bgp_path_info
*pi
, *nextpi
;
2624 /* Walk this VNI's MAC & IP route table and delete all routes. */
2625 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
2626 dest
= bgp_route_next(dest
)) {
2627 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2628 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2629 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
2630 bgp_path_info_delete(dest
, pi
);
2631 bgp_path_info_reap(dest
, pi
);
2635 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
2636 dest
= bgp_route_next(dest
)) {
2637 for (pi
= bgp_dest_get_bgp_path_info(dest
);
2638 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
2639 bgp_path_info_delete(dest
, pi
);
2640 bgp_path_info_reap(dest
, pi
);
2645 /* BUM traffic flood mode per-l2-vni */
2646 static int bgp_evpn_vni_flood_mode_get(struct bgp
*bgp
,
2647 struct bgpevpn
*vpn
)
2649 /* if flooding has been globally disabled per-vni mode is
2652 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
2653 return VXLAN_FLOOD_DISABLED
;
2655 /* if mcast group ip has been specified we use a PIM-SM MDT */
2656 if (vpn
->mcast_grp
.s_addr
!= INADDR_ANY
)
2657 return VXLAN_FLOOD_PIM_SM
;
2659 /* default is ingress replication */
2660 return VXLAN_FLOOD_HEAD_END_REPL
;
2664 * Update (and advertise) local routes for a VNI. Invoked upon the VNI
2665 * export RT getting modified or change to tunnel IP. Note that these
2666 * situations need the route in the per-VNI table as well as the global
2667 * table to be updated (as attributes change).
2669 int update_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2672 struct prefix_evpn p
;
2674 update_type1_routes_for_evi(bgp
, vpn
);
2676 /* Update and advertise the type-3 route (only one) followed by the
2677 * locally learnt type-2 routes (MACIP) - for this VNI.
2679 * RT-3 only if doing head-end replication
2681 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
2682 == VXLAN_FLOOD_HEAD_END_REPL
) {
2683 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2684 ret
= update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
);
2689 update_all_type2_routes(bgp
, vpn
);
2694 * Delete (and withdraw) local routes for specified VNI from the global
2695 * table and per-VNI table. After this, remove all other routes from
2696 * the per-VNI table. Invoked upon the VNI being deleted or EVPN
2697 * (advertise-all-vni) being disabled.
2699 static int delete_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2702 struct prefix_evpn p
;
2704 /* Delete and withdraw locally learnt type-2 routes (MACIP)
2705 * followed by type-3 routes (only one) - for this VNI.
2707 delete_all_type2_routes(bgp
, vpn
);
2709 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2710 ret
= delete_evpn_route(bgp
, vpn
, &p
);
2714 /* Delete all routes from the per-VNI table. */
2715 delete_all_vni_routes(bgp
, vpn
);
2720 * There is a flood mcast IP address change. Update the mcast-grp and
2721 * remove the type-3 route if any. A new type-3 route will be generated
2722 * post tunnel_ip update if the new flood mode is head-end-replication.
2724 static int bgp_evpn_mcast_grp_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2725 struct in_addr mcast_grp
)
2727 struct prefix_evpn p
;
2729 vpn
->mcast_grp
= mcast_grp
;
2731 if (is_vni_live(vpn
)) {
2732 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2733 delete_evpn_route(bgp
, vpn
, &p
);
2740 * There is a tunnel endpoint IP address change for this VNI, delete
2741 * prior type-3 route (if needed) and update.
2742 * Note: Route re-advertisement happens elsewhere after other processing
2745 static void handle_tunnel_ip_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2746 struct in_addr originator_ip
)
2748 struct prefix_evpn p
;
2750 if (IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
))
2753 /* If VNI is not live, we only need to update the originator ip */
2754 if (!is_vni_live(vpn
)) {
2755 vpn
->originator_ip
= originator_ip
;
2759 /* Update the tunnel-ip hash */
2760 bgp_tip_del(bgp
, &vpn
->originator_ip
);
2761 if (bgp_tip_add(bgp
, &originator_ip
))
2762 /* The originator_ip was not already present in the
2763 * bgp martian next-hop table as a tunnel-ip, so we
2764 * need to go back and filter routes matching the new
2767 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
2769 /* Need to withdraw type-3 route as the originator IP is part
2772 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2773 delete_evpn_route(bgp
, vpn
, &p
);
2775 /* Update the tunnel IP and re-advertise all routes for this VNI. */
2776 vpn
->originator_ip
= originator_ip
;
2780 static struct bgp_path_info
*
2781 bgp_create_evpn_bgp_path_info(struct bgp_path_info
*parent_pi
,
2782 struct bgp_dest
*dest
, struct attr
*attr
)
2784 struct attr
*attr_new
;
2785 struct bgp_path_info
*pi
;
2787 /* Add (or update) attribute to hash. */
2788 attr_new
= bgp_attr_intern(attr
);
2790 /* Create new route with its attribute. */
2791 pi
= info_make(parent_pi
->type
, BGP_ROUTE_IMPORTED
, 0, parent_pi
->peer
,
2793 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
2794 bgp_path_info_extra_get(pi
);
2795 pi
->extra
->parent
= bgp_path_info_lock(parent_pi
);
2796 bgp_dest_lock_node((struct bgp_dest
*)parent_pi
->net
);
2797 if (parent_pi
->extra
) {
2798 memcpy(&pi
->extra
->label
, &parent_pi
->extra
->label
,
2799 sizeof(pi
->extra
->label
));
2800 pi
->extra
->num_labels
= parent_pi
->extra
->num_labels
;
2801 pi
->extra
->igpmetric
= parent_pi
->extra
->igpmetric
;
2804 bgp_path_info_add(dest
, pi
);
2810 * Install route entry into the VRF routing table and invoke route selection.
2812 static int install_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
2813 const struct prefix_evpn
*evp
,
2814 struct bgp_path_info
*parent_pi
)
2816 struct bgp_dest
*dest
;
2817 struct bgp_path_info
*pi
;
2819 struct attr
*attr_new
;
2822 struct prefix
*pp
= &p
;
2825 bool new_pi
= false;
2826 bool use_l3nhg
= false;
2827 bool is_l3nhg_active
= false;
2828 char buf1
[INET6_ADDRSTRLEN
];
2830 memset(pp
, 0, sizeof(struct prefix
));
2831 ip_prefix_from_evpn_prefix(evp
, pp
);
2833 if (bgp_debug_zebra(NULL
))
2835 "vrf %s: import evpn prefix %pFX parent %p flags 0x%x",
2836 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
2839 /* Create (or fetch) route within the VRF. */
2840 /* NOTE: There is no RD here. */
2841 if (is_evpn_prefix_ipaddr_v4(evp
)) {
2843 safi
= SAFI_UNICAST
;
2844 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2845 } else if (is_evpn_prefix_ipaddr_v6(evp
)) {
2847 safi
= SAFI_UNICAST
;
2848 dest
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2852 /* EVPN routes currently only support a IPv4 next hop which corresponds
2853 * to the remote VTEP. When importing into a VRF, if it is IPv6 host
2854 * or prefix route, we have to convert the next hop to an IPv4-mapped
2855 * address for the rest of the code to flow through. In the case of IPv4,
2856 * make sure to set the flag for next hop attribute.
2858 attr
= *parent_pi
->attr
;
2859 if (attr
.evpn_overlay
.type
!= OVERLAY_INDEX_GATEWAY_IP
) {
2861 evpn_convert_nexthop_to_ipv6(&attr
);
2863 attr
.nexthop
= attr
.mp_nexthop_global_in
;
2864 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2869 * If gateway IP overlay index is specified in the NLRI of
2870 * EVPN RT-5, this gateway IP should be used as the nexthop
2871 * for the prefix in the VRF
2873 if (bgp_debug_zebra(NULL
)) {
2875 "Install gateway IP %s as nexthop for prefix %pFX in vrf %s",
2876 inet_ntop(pp
->family
, &attr
.evpn_overlay
.gw_ip
,
2877 buf1
, sizeof(buf1
)), pp
,
2878 vrf_id_to_name(bgp_vrf
->vrf_id
));
2881 if (afi
== AFI_IP6
) {
2882 memcpy(&attr
.mp_nexthop_global
,
2883 &attr
.evpn_overlay
.gw_ip
.ipaddr_v6
,
2884 sizeof(struct in6_addr
));
2885 attr
.mp_nexthop_len
= IPV6_MAX_BYTELEN
;
2887 attr
.nexthop
= attr
.evpn_overlay
.gw_ip
.ipaddr_v4
;
2888 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2892 bgp_evpn_es_vrf_use_nhg(bgp_vrf
, &parent_pi
->attr
->esi
, &use_l3nhg
,
2893 &is_l3nhg_active
, NULL
);
2895 attr
.es_flags
|= ATTR_ES_L3_NHG_USE
;
2896 if (is_l3nhg_active
)
2897 attr
.es_flags
|= ATTR_ES_L3_NHG_ACTIVE
;
2899 /* Check if route entry is already present. */
2900 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2902 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
2906 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
, &attr
);
2909 if (attrhash_cmp(pi
->attr
, &attr
)
2910 && !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
2911 bgp_dest_unlock_node(dest
);
2914 /* The attribute has changed. */
2915 /* Add (or update) attribute to hash. */
2916 attr_new
= bgp_attr_intern(&attr
);
2918 /* Restore route, if needed. */
2919 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
2920 bgp_path_info_restore(dest
, pi
);
2922 /* Mark if nexthop has changed. */
2924 && !IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
2926 && !IPV6_ADDR_SAME(&pi
->attr
->mp_nexthop_global
,
2927 &attr_new
->mp_nexthop_global
)))
2928 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
2930 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
2931 /* Unintern existing, set to new. */
2932 bgp_attr_unintern(&pi
->attr
);
2933 pi
->attr
= attr_new
;
2934 pi
->uptime
= monotime(NULL
);
2937 /* Gateway IP nexthop should be resolved */
2938 if (attr
.evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
2939 if (bgp_find_or_add_nexthop(bgp_vrf
, bgp_vrf
, afi
, safi
, pi
,
2941 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_VALID
);
2943 if (BGP_DEBUG(nht
, NHT
)) {
2944 inet_ntop(pp
->family
,
2945 &attr
.evpn_overlay
.gw_ip
,
2946 buf1
, sizeof(buf1
));
2947 zlog_debug("%s: gateway IP NH unresolved",
2950 bgp_path_info_unset_flag(dest
, pi
, BGP_PATH_VALID
);
2954 /* as it is an importation, change nexthop */
2955 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ANNC_NH_SELF
);
2958 /* Link path to evpn nexthop */
2959 bgp_evpn_path_nh_add(bgp_vrf
, pi
);
2961 bgp_aggregate_increment(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
2964 /* Perform route selection and update zebra, if required. */
2965 bgp_process(bgp_vrf
, dest
, afi
, safi
);
2967 /* Process for route leaking. */
2968 vpn_leak_from_vrf_update(bgp_get_default(), bgp_vrf
, pi
);
2970 bgp_dest_unlock_node(dest
);
2972 if (bgp_debug_zebra(NULL
))
2973 zlog_debug("... %s pi dest %p (l %d) pi %p (l %d, f 0x%x)",
2974 new_pi
? "new" : "update", dest
,
2975 bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
2982 * Common handling for vni route tables install/selection.
2984 static int install_evpn_route_entry_in_vni_common(
2985 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
2986 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
2988 struct bgp_path_info
*pi
;
2989 struct bgp_path_info
*local_pi
;
2990 struct attr
*attr_new
;
2992 bool old_local_es
= false;
2995 /* Check if route entry is already present. */
2996 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
2998 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3002 /* Create an info */
3003 pi
= bgp_create_evpn_bgp_path_info(parent_pi
, dest
,
3006 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
3007 if (is_evpn_type2_dest_ipaddr_none(dest
))
3008 evpn_type2_path_info_set_ip(
3009 pi
, p
->prefix
.macip_addr
.ip
);
3011 evpn_type2_path_info_set_mac(
3012 pi
, p
->prefix
.macip_addr
.mac
);
3015 new_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3017 /* Return early if attributes haven't changed
3018 * and dest isn't flagged for removal.
3019 * dest will be unlocked by either
3020 * install_evpn_route_entry_in_vni_mac() or
3021 * install_evpn_route_entry_in_vni_ip()
3023 if (attrhash_cmp(pi
->attr
, parent_pi
->attr
) &&
3024 !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3026 /* The attribute has changed. */
3027 /* Add (or update) attribute to hash. */
3028 attr_new
= bgp_attr_intern(parent_pi
->attr
);
3030 /* Restore route, if needed. */
3031 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
3032 bgp_path_info_restore(dest
, pi
);
3034 /* Mark if nexthop has changed. */
3035 if (!IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
3036 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
3038 old_local_es
= bgp_evpn_attr_is_local_es(pi
->attr
);
3039 new_local_es
= bgp_evpn_attr_is_local_es(attr_new
);
3040 /* If ESI is different or if its type has changed we
3041 * need to reinstall the path in zebra
3043 if ((old_local_es
!= new_local_es
)
3044 || memcmp(&pi
->attr
->esi
, &attr_new
->esi
,
3045 sizeof(attr_new
->esi
))) {
3047 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
3048 zlog_debug("VNI %d path %pFX chg to %s es",
3049 vpn
->vni
, &pi
->net
->p
,
3050 new_local_es
? "local"
3052 bgp_path_info_set_flag(dest
, pi
, BGP_PATH_ATTR_CHANGED
);
3055 /* Unintern existing, set to new. */
3056 bgp_attr_unintern(&pi
->attr
);
3057 pi
->attr
= attr_new
;
3058 pi
->uptime
= monotime(NULL
);
3061 /* Add this route to remote IP hashtable */
3062 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
3064 /* Perform route selection and update zebra, if required. */
3065 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3067 /* if the best path is a local path with a non-zero ES
3068 * sync info against the local path may need to be updated
3069 * when a remote path is added/updated (including changes
3070 * from sync-path to remote-path)
3072 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3073 if (local_pi
&& (old_local_es
|| new_local_es
))
3074 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3081 * Common handling for vni route tables uninstall/selection.
3083 static int uninstall_evpn_route_entry_in_vni_common(
3084 struct bgp
*bgp
, struct bgpevpn
*vpn
, const struct prefix_evpn
*p
,
3085 struct bgp_dest
*dest
, struct bgp_path_info
*parent_pi
)
3087 struct bgp_path_info
*pi
;
3088 struct bgp_path_info
*local_pi
;
3091 /* Find matching route entry. */
3092 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3094 (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3100 bgp_evpn_remote_ip_hash_del(vpn
, pi
);
3102 /* Mark entry for deletion */
3103 bgp_path_info_delete(dest
, pi
);
3105 /* Perform route selection and update zebra, if required. */
3106 ret
= evpn_route_select_install(bgp
, vpn
, dest
);
3108 /* if the best path is a local path with a non-zero ES
3109 * sync info against the local path may need to be updated
3110 * when a remote path is deleted
3112 local_pi
= bgp_evpn_route_get_local_path(bgp
, dest
);
3113 if (local_pi
&& bgp_evpn_attr_is_local_es(local_pi
->attr
))
3114 bgp_evpn_update_type2_route_entry(bgp
, vpn
, dest
, local_pi
,
3121 * Install route entry into VNI IP table and invoke route selection.
3123 static int install_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3124 struct bgpevpn
*vpn
,
3125 const struct prefix_evpn
*p
,
3126 struct bgp_path_info
*parent_pi
)
3129 struct bgp_dest
*dest
;
3131 /* Ignore MAC Only Type-2 */
3132 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3133 (is_evpn_prefix_ipaddr_none(p
) == true))
3136 /* Create (or fetch) route within the VNI IP table. */
3137 dest
= bgp_evpn_vni_ip_node_get(vpn
->ip_table
, p
, parent_pi
);
3139 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3142 bgp_dest_unlock_node(dest
);
3148 * Install route entry into VNI MAC table and invoke route selection.
3150 static int install_evpn_route_entry_in_vni_mac(struct bgp
*bgp
,
3151 struct bgpevpn
*vpn
,
3152 const struct prefix_evpn
*p
,
3153 struct bgp_path_info
*parent_pi
)
3156 struct bgp_dest
*dest
;
3158 /* Only type-2 routes go into this table */
3159 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3162 /* Create (or fetch) route within the VNI MAC table. */
3163 dest
= bgp_evpn_vni_mac_node_get(vpn
->mac_table
, p
, parent_pi
);
3165 ret
= install_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3168 bgp_dest_unlock_node(dest
);
3174 * Uninstall route entry from VNI IP table and invoke route selection.
3176 static int uninstall_evpn_route_entry_in_vni_ip(struct bgp
*bgp
,
3177 struct bgpevpn
*vpn
,
3178 const struct prefix_evpn
*p
,
3179 struct bgp_path_info
*parent_pi
)
3182 struct bgp_dest
*dest
;
3184 /* Ignore MAC Only Type-2 */
3185 if ((p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) &&
3186 (is_evpn_prefix_ipaddr_none(p
) == true))
3189 /* Locate route within the VNI IP table. */
3190 dest
= bgp_evpn_vni_ip_node_lookup(vpn
->ip_table
, p
, parent_pi
);
3194 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3197 bgp_dest_unlock_node(dest
);
3203 * Uninstall route entry from VNI IP table and invoke route selection.
3206 uninstall_evpn_route_entry_in_vni_mac(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3207 const struct prefix_evpn
*p
,
3208 struct bgp_path_info
*parent_pi
)
3211 struct bgp_dest
*dest
;
3213 /* Only type-2 routes go into this table */
3214 if (p
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3217 /* Locate route within the VNI MAC table. */
3218 dest
= bgp_evpn_vni_mac_node_lookup(vpn
->mac_table
, p
, parent_pi
);
3222 ret
= uninstall_evpn_route_entry_in_vni_common(bgp
, vpn
, p
, dest
,
3225 bgp_dest_unlock_node(dest
);
3230 * Uninstall route entry from the VRF routing table and send message
3231 * to zebra, if appropriate.
3233 static int uninstall_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
3234 const struct prefix_evpn
*evp
,
3235 struct bgp_path_info
*parent_pi
)
3237 struct bgp_dest
*dest
;
3238 struct bgp_path_info
*pi
;
3241 struct prefix
*pp
= &p
;
3245 memset(pp
, 0, sizeof(struct prefix
));
3246 ip_prefix_from_evpn_prefix(evp
, pp
);
3248 if (bgp_debug_zebra(NULL
))
3250 "vrf %s: unimport evpn prefix %pFX parent %p flags 0x%x",
3251 vrf_id_to_name(bgp_vrf
->vrf_id
), evp
, parent_pi
,
3254 /* Locate route within the VRF. */
3255 /* NOTE: There is no RD here. */
3256 if (is_evpn_prefix_ipaddr_v4(evp
)) {
3258 safi
= SAFI_UNICAST
;
3259 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3262 safi
= SAFI_UNICAST
;
3263 dest
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
3269 /* Find matching route entry. */
3270 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
3272 && (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
3276 bgp_dest_unlock_node(dest
);
3280 if (bgp_debug_zebra(NULL
))
3281 zlog_debug("... delete dest %p (l %d) pi %p (l %d, f 0x%x)",
3282 dest
, bgp_dest_get_lock_count(dest
), pi
, pi
->lock
,
3285 /* Process for route leaking. */
3286 vpn_leak_from_vrf_withdraw(bgp_get_default(), bgp_vrf
, pi
);
3288 bgp_aggregate_decrement(bgp_vrf
, bgp_dest_get_prefix(dest
), pi
, afi
,
3291 /* Mark entry for deletion */
3292 bgp_path_info_delete(dest
, pi
);
3294 /* Unlink path to evpn nexthop */
3295 bgp_evpn_path_nh_del(bgp_vrf
, pi
);
3297 /* Perform route selection and update zebra, if required. */
3298 bgp_process(bgp_vrf
, dest
, afi
, safi
);
3300 /* Unlock route node. */
3301 bgp_dest_unlock_node(dest
);
3307 * Install route entry into the VNI routing tables.
3309 static int install_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3310 const struct prefix_evpn
*p
,
3311 struct bgp_path_info
*parent_pi
)
3315 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3317 "%s (%u): Installing EVPN %pFX route in VNI %u IP/MAC table",
3318 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3320 ret
= install_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3325 "%s (%u): Failed to install EVPN %pFX route in VNI %u MAC table",
3326 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3331 ret
= install_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3336 "%s (%u): Failed to install EVPN %pFX route in VNI %u IP table",
3337 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3346 * Uninstall route entry from the VNI routing tables.
3348 static int uninstall_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3349 const struct prefix_evpn
*p
,
3350 struct bgp_path_info
*parent_pi
)
3354 if (bgp_debug_update(parent_pi
->peer
, NULL
, NULL
, 1))
3356 "%s (%u): Uninstalling EVPN %pFX route from VNI %u IP/MAC table",
3357 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3359 ret
= uninstall_evpn_route_entry_in_vni_ip(bgp
, vpn
, p
, parent_pi
);
3364 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u IP table",
3365 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3370 ret
= uninstall_evpn_route_entry_in_vni_mac(bgp
, vpn
, p
, parent_pi
);
3375 "%s (%u): Failed to uninstall EVPN %pFX route from VNI %u MAC table",
3376 vrf_id_to_name(bgp
->vrf_id
), bgp
->vrf_id
, p
, vpn
->vni
);
3385 * Given a route entry and a VRF, see if this route entry should be
3386 * imported into the VRF i.e., RTs match.
3388 static int is_route_matching_for_vrf(struct bgp
*bgp_vrf
,
3389 struct bgp_path_info
*pi
)
3391 struct attr
*attr
= pi
->attr
;
3392 struct ecommunity
*ecom
;
3396 /* Route should have valid RT to be even considered. */
3397 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3400 ecom
= bgp_attr_get_ecommunity(attr
);
3401 if (!ecom
|| !ecom
->size
)
3404 /* For each extended community RT, see if it matches this VNI. If any RT
3405 * matches, we're done.
3407 for (i
= 0; i
< ecom
->size
; i
++) {
3409 uint8_t type
, sub_type
;
3410 struct ecommunity_val
*eval
;
3411 struct ecommunity_val eval_tmp
;
3412 struct vrf_irt_node
*irt
;
3414 /* Only deal with RTs */
3415 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3416 eval
= (struct ecommunity_val
*)(ecom
->val
3417 + (i
* ecom
->unit_size
));
3420 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3423 /* See if this RT matches specified VNIs import RTs */
3424 irt
= lookup_vrf_import_rt(eval
);
3426 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3429 /* Also check for non-exact match. In this, we mask out the AS
3431 * only check on the local-admin sub-field. This is to
3433 * VNI as the RT for EBGP peering too.
3436 if (type
== ECOMMUNITY_ENCODE_AS
3437 || type
== ECOMMUNITY_ENCODE_AS4
3438 || type
== ECOMMUNITY_ENCODE_IP
) {
3439 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3440 mask_ecom_global_admin(&eval_tmp
, eval
);
3441 irt
= lookup_vrf_import_rt(&eval_tmp
);
3444 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
3452 * Given a route entry and a VNI, see if this route entry should be
3453 * imported into the VNI i.e., RTs match.
3455 static int is_route_matching_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3456 struct bgp_path_info
*pi
)
3458 struct attr
*attr
= pi
->attr
;
3459 struct ecommunity
*ecom
;
3463 /* Route should have valid RT to be even considered. */
3464 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3467 ecom
= bgp_attr_get_ecommunity(attr
);
3468 if (!ecom
|| !ecom
->size
)
3471 /* For each extended community RT, see if it matches this VNI. If any RT
3472 * matches, we're done.
3474 for (i
= 0; i
< ecom
->size
; i
++) {
3476 uint8_t type
, sub_type
;
3477 struct ecommunity_val
*eval
;
3478 struct ecommunity_val eval_tmp
;
3479 struct irt_node
*irt
;
3481 /* Only deal with RTs */
3482 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3483 eval
= (struct ecommunity_val
*)(ecom
->val
3484 + (i
* ecom
->unit_size
));
3487 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3490 /* See if this RT matches specified VNIs import RTs */
3491 irt
= lookup_import_rt(bgp
, eval
);
3493 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3496 /* Also check for non-exact match. In this, we mask out the AS
3498 * only check on the local-admin sub-field. This is to
3500 * VNI as the RT for EBGP peering too.
3503 if (type
== ECOMMUNITY_ENCODE_AS
3504 || type
== ECOMMUNITY_ENCODE_AS4
3505 || type
== ECOMMUNITY_ENCODE_IP
) {
3506 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
3507 mask_ecom_global_admin(&eval_tmp
, eval
);
3508 irt
= lookup_import_rt(bgp
, &eval_tmp
);
3511 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
3518 /* This API will scan evpn routes for checking attribute's rmac
3519 * macthes with bgp instance router mac. It avoid installing
3520 * route into bgp vrf table and remote rmac in bridge table.
3522 static int bgp_evpn_route_rmac_self_check(struct bgp
*bgp_vrf
,
3523 const struct prefix_evpn
*evp
,
3524 struct bgp_path_info
*pi
)
3526 /* evpn route could have learnt prior to L3vni has come up,
3527 * perform rmac check before installing route and
3528 * remote router mac.
3529 * The route will be removed from global bgp table once
3530 * SVI comes up with MAC and stored in hash, triggers
3531 * bgp_mac_rescan_all_evpn_tables.
3533 if (memcmp(&bgp_vrf
->rmac
, &pi
->attr
->rmac
, ETH_ALEN
) == 0) {
3534 if (bgp_debug_update(pi
->peer
, NULL
, NULL
, 1)) {
3535 char attr_str
[BUFSIZ
] = {0};
3537 bgp_dump_attr(pi
->attr
, attr_str
, sizeof(attr_str
));
3540 "%s: bgp %u prefix %pFX with attr %s - DENIED due to self mac",
3541 __func__
, bgp_vrf
->vrf_id
, evp
, attr_str
);
3550 /* don't import hosts that are locally attached */
3552 bgp_evpn_skip_vrf_import_of_local_es(struct bgp
*bgp_vrf
,
3553 const struct prefix_evpn
*evp
,
3554 struct bgp_path_info
*pi
, int install
)
3558 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
3559 esi
= bgp_evpn_attr_get_esi(pi
->attr
);
3561 /* Don't import routes that point to a local destination */
3562 if (bgp_evpn_attr_is_local_es(pi
->attr
)) {
3563 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
)) {
3564 char esi_buf
[ESI_STR_LEN
];
3567 "vrf %s of evpn prefix %pFX skipped, local es %s",
3568 install
? "import" : "unimport", evp
,
3569 esi_to_str(esi
, esi_buf
,
3579 * Install or uninstall a mac-ip route in the provided vrf if
3580 * there is a rt match
3582 int bgp_evpn_route_entry_install_if_vrf_match(struct bgp
*bgp_vrf
,
3583 struct bgp_path_info
*pi
,
3587 const struct prefix_evpn
*evp
=
3588 (const struct prefix_evpn
*)bgp_dest_get_prefix(pi
->net
);
3590 /* Consider "valid" remote routes applicable for
3593 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3594 && pi
->type
== ZEBRA_ROUTE_BGP
3595 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3598 if (is_route_matching_for_vrf(bgp_vrf
, pi
)) {
3599 if (bgp_evpn_route_rmac_self_check(bgp_vrf
, evp
, pi
))
3602 /* don't import hosts that are locally attached */
3603 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3604 bgp_vrf
, evp
, pi
, install
))
3608 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3610 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3614 flog_err(EC_BGP_EVPN_FAIL
,
3615 "Failed to %s EVPN %pFX route in VRF %s",
3616 install
? "install" : "uninstall", evp
,
3617 vrf_id_to_name(bgp_vrf
->vrf_id
));
3624 * Install or uninstall mac-ip routes are appropriate for this
3627 static int install_uninstall_routes_for_vrf(struct bgp
*bgp_vrf
, int install
)
3631 struct bgp_dest
*rd_dest
, *dest
;
3632 struct bgp_table
*table
;
3633 struct bgp_path_info
*pi
;
3635 struct bgp
*bgp_evpn
= NULL
;
3639 bgp_evpn
= bgp_get_evpn();
3643 /* Walk entire global routing table and evaluate routes which could be
3644 * imported into this VRF. Note that we need to loop through all global
3645 * routes to determine which route matches the import rt on vrf
3647 for (rd_dest
= bgp_table_top(bgp_evpn
->rib
[afi
][safi
]); rd_dest
;
3648 rd_dest
= bgp_route_next(rd_dest
)) {
3649 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3653 for (dest
= bgp_table_top(table
); dest
;
3654 dest
= bgp_route_next(dest
)) {
3655 const struct prefix_evpn
*evp
=
3656 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3659 /* if not mac-ip route skip this route */
3660 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3661 || evp
->prefix
.route_type
3662 == BGP_EVPN_IP_PREFIX_ROUTE
))
3665 /* if not a mac+ip route skip this route */
3666 if (!(is_evpn_prefix_ipaddr_v4(evp
)
3667 || is_evpn_prefix_ipaddr_v6(evp
)))
3670 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3672 ret
= bgp_evpn_route_entry_install_if_vrf_match(
3673 bgp_vrf
, pi
, install
);
3684 * Install or uninstall routes of specified type that are appropriate for this
3687 static int install_uninstall_routes_for_vni(struct bgp
*bgp
,
3688 struct bgpevpn
*vpn
,
3689 bgp_evpn_route_type rtype
,
3694 struct bgp_dest
*rd_dest
, *dest
;
3695 struct bgp_table
*table
;
3696 struct bgp_path_info
*pi
;
3702 /* Walk entire global routing table and evaluate routes which could be
3703 * imported into this VPN. Note that we cannot just look at the routes
3705 * the VNI's RD - remote routes applicable for this VNI could have any
3708 /* EVPN routes are a 2-level table. */
3709 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
3710 rd_dest
= bgp_route_next(rd_dest
)) {
3711 table
= bgp_dest_get_bgp_table_info(rd_dest
);
3715 for (dest
= bgp_table_top(table
); dest
;
3716 dest
= bgp_route_next(dest
)) {
3717 const struct prefix_evpn
*evp
=
3718 (const struct prefix_evpn
*)bgp_dest_get_prefix(
3721 if (evp
->prefix
.route_type
!= rtype
)
3724 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
3726 /* Consider "valid" remote routes applicable for
3728 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
3729 && pi
->type
== ZEBRA_ROUTE_BGP
3730 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
3733 if (is_route_matching_for_vni(bgp
, vpn
, pi
)) {
3735 ret
= install_evpn_route_entry(
3738 ret
= uninstall_evpn_route_entry(
3744 "%u: Failed to %s EVPN %s route in VNI %u",
3748 rtype
== BGP_EVPN_MAC_IP_ROUTE
3753 bgp_dest_unlock_node(rd_dest
);
3754 bgp_dest_unlock_node(dest
);
3765 /* Install any existing remote routes applicable for this VRF into VRF RIB. This
3766 * is invoked upon l3vni-add or l3vni import rt change
3768 static int install_routes_for_vrf(struct bgp
*bgp_vrf
)
3770 install_uninstall_routes_for_vrf(bgp_vrf
, 1);
3775 * Install any existing remote routes applicable for this VNI into its
3776 * routing table. This is invoked when a VNI becomes "live" or its Import
3779 static int install_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3783 /* Install type-3 routes followed by type-2 routes - the ones applicable
3786 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3791 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3796 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3800 /* uninstall routes from l3vni vrf. */
3801 static int uninstall_routes_for_vrf(struct bgp
*bgp_vrf
)
3803 install_uninstall_routes_for_vrf(bgp_vrf
, 0);
3808 * Uninstall any existing remote routes for this VNI. One scenario in which
3809 * this is invoked is upon an import RT change.
3811 static int uninstall_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3815 /* Uninstall type-2 routes followed by type-3 routes - the ones
3819 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3824 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_AD_ROUTE
,
3830 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3835 * Install or uninstall route in matching VRFs (list).
3837 static int install_uninstall_route_in_vrfs(struct bgp
*bgp_def
, afi_t afi
,
3838 safi_t safi
, struct prefix_evpn
*evp
,
3839 struct bgp_path_info
*pi
,
3840 struct list
*vrfs
, int install
)
3842 struct bgp
*bgp_vrf
;
3843 struct listnode
*node
, *nnode
;
3845 /* Only type-2/type-5 routes go into a VRF */
3846 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3847 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3850 /* if it is type-2 route and not a mac+ip route skip this route */
3851 if ((evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3852 && !(is_evpn_prefix_ipaddr_v4(evp
)
3853 || is_evpn_prefix_ipaddr_v6(evp
)))
3856 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, bgp_vrf
)) {
3859 /* don't import hosts that are locally attached */
3860 if (install
&& bgp_evpn_skip_vrf_import_of_local_es(
3861 bgp_vrf
, evp
, pi
, install
))
3865 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, pi
);
3867 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3871 flog_err(EC_BGP_EVPN_FAIL
,
3872 "%u: Failed to %s prefix %pFX in VRF %s",
3874 install
? "install" : "uninstall", evp
,
3875 vrf_id_to_name(bgp_vrf
->vrf_id
));
3884 * Install or uninstall route in matching VNIs (list).
3886 static int install_uninstall_route_in_vnis(struct bgp
*bgp
, afi_t afi
,
3887 safi_t safi
, struct prefix_evpn
*evp
,
3888 struct bgp_path_info
*pi
,
3889 struct list
*vnis
, int install
)
3891 struct bgpevpn
*vpn
;
3892 struct listnode
*node
, *nnode
;
3894 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, vpn
)) {
3897 if (!is_vni_live(vpn
))
3901 ret
= install_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3903 ret
= uninstall_evpn_route_entry(bgp
, vpn
, evp
, pi
);
3906 flog_err(EC_BGP_EVPN_FAIL
,
3907 "%u: Failed to %s EVPN %s route in VNI %u",
3908 bgp
->vrf_id
, install
? "install" : "uninstall",
3909 evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3921 * Install or uninstall route for appropriate VNIs/ESIs.
3923 static int bgp_evpn_install_uninstall_table(struct bgp
*bgp
, afi_t afi
,
3924 safi_t safi
, const struct prefix
*p
,
3925 struct bgp_path_info
*pi
,
3926 int import
, bool in_vni_rt
,
3929 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
3930 struct attr
*attr
= pi
->attr
;
3931 struct ecommunity
*ecom
;
3933 struct prefix_evpn ad_evp
;
3937 /* Only type-1, type-2, type-3, type-4 and type-5
3938 * are supported currently
3940 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3941 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
3942 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
3943 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
3944 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3947 /* If we don't have Route Target, nothing much to do. */
3948 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3951 /* EAD prefix in the global table doesn't include the VTEP-IP so
3952 * we need to create a different copy for the VNI
3954 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
)
3955 evp
= evpn_type1_prefix_vni_ip_copy(&ad_evp
, evp
,
3958 ecom
= bgp_attr_get_ecommunity(attr
);
3959 if (!ecom
|| !ecom
->size
)
3962 /* An EVPN route belongs to a VNI or a VRF or an ESI based on the RTs
3963 * attached to the route */
3964 for (i
= 0; i
< ecom
->size
; i
++) {
3966 uint8_t type
, sub_type
;
3967 struct ecommunity_val
*eval
;
3968 struct ecommunity_val eval_tmp
;
3969 struct irt_node
*irt
; /* import rt for l2vni */
3970 struct vrf_irt_node
*vrf_irt
; /* import rt for l3vni */
3971 struct bgp_evpn_es
*es
;
3973 /* Only deal with RTs */
3974 pnt
= (ecom
->val
+ (i
* ecom
->unit_size
));
3975 eval
= (struct ecommunity_val
*)(ecom
->val
3976 + (i
* ecom
->unit_size
));
3979 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3982 /* non-local MAC-IP routes in the global route table are linked
3983 * to the destination ES
3985 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3986 bgp_evpn_path_es_link(pi
, 0,
3987 bgp_evpn_attr_get_esi(pi
->attr
));
3990 * macip routes (type-2) are imported into VNI and VRF tables.
3991 * IMET route is imported into VNI table.
3992 * prefix routes are imported into VRF table.
3994 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
||
3995 evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
||
3996 evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
||
3997 evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
3999 irt
= in_vni_rt
? lookup_import_rt(bgp
, eval
) : NULL
;
4001 install_uninstall_route_in_vnis(
4002 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
4005 vrf_irt
= in_vrf_rt
? lookup_vrf_import_rt(eval
) : NULL
;
4007 install_uninstall_route_in_vrfs(
4008 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
4011 /* Also check for non-exact match.
4012 * In this, we mask out the AS and
4013 * only check on the local-admin sub-field.
4014 * This is to facilitate using
4015 * VNI as the RT for EBGP peering too.
4019 if (type
== ECOMMUNITY_ENCODE_AS
4020 || type
== ECOMMUNITY_ENCODE_AS4
4021 || type
== ECOMMUNITY_ENCODE_IP
) {
4022 memcpy(&eval_tmp
, eval
, ecom
->unit_size
);
4023 mask_ecom_global_admin(&eval_tmp
, eval
);
4025 irt
= lookup_import_rt(bgp
, &eval_tmp
);
4028 lookup_vrf_import_rt(&eval_tmp
);
4032 install_uninstall_route_in_vnis(
4033 bgp
, afi
, safi
, evp
, pi
, irt
->vnis
,
4036 install_uninstall_route_in_vrfs(
4037 bgp
, afi
, safi
, evp
, pi
, vrf_irt
->vrfs
,
4041 /* es route is imported into the es table */
4042 if (evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) {
4044 /* we will match based on the entire esi to avoid
4045 * import of an es route for esi2 into esi1
4047 es
= bgp_evpn_es_find(&evp
->prefix
.es_addr
.esi
);
4048 if (es
&& bgp_evpn_is_es_local(es
))
4049 bgp_evpn_es_route_install_uninstall(
4050 bgp
, es
, afi
, safi
, evp
, pi
, import
);
4058 * Install or uninstall route for appropriate VNIs/ESIs.
4060 static int install_uninstall_evpn_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
4061 const struct prefix
*p
,
4062 struct bgp_path_info
*pi
, int import
)
4064 return bgp_evpn_install_uninstall_table(bgp
, afi
, safi
, p
, pi
, import
,
4068 void bgp_evpn_import_type2_route(struct bgp_path_info
*pi
, int import
)
4070 struct bgp
*bgp_evpn
;
4072 bgp_evpn
= bgp_get_evpn();
4076 install_uninstall_evpn_route(bgp_evpn
, AFI_L2VPN
, SAFI_EVPN
,
4077 &pi
->net
->p
, pi
, import
);
4081 * delete and withdraw all ipv4 and ipv6 routes in the vrf table as type-5
4084 static void delete_withdraw_vrf_routes(struct bgp
*bgp_vrf
)
4086 /* Delete ipv4 default route and withdraw from peers */
4087 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4088 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4089 SAFI_UNICAST
, false);
4091 /* delete all ipv4 routes and withdraw from peers */
4092 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4093 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4095 /* Delete ipv6 default route and withdraw from peers */
4096 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4097 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4098 SAFI_UNICAST
, false);
4100 /* delete all ipv6 routes and withdraw from peers */
4101 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4102 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4106 * update and advertise all ipv4 and ipv6 routes in thr vrf table as type-5
4109 void update_advertise_vrf_routes(struct bgp
*bgp_vrf
)
4111 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
4113 bgp_evpn
= bgp_get_evpn();
4117 /* update all ipv4 routes */
4118 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
4119 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
4121 /* update ipv4 default route and withdraw from peers */
4122 if (evpn_default_originate_set(bgp_vrf
, AFI_IP
, SAFI_UNICAST
))
4123 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP
,
4124 SAFI_UNICAST
, true);
4126 /* update all ipv6 routes */
4127 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
4128 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
4130 /* update ipv6 default route and withdraw from peers */
4131 if (evpn_default_originate_set(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
))
4132 bgp_evpn_install_uninstall_default_route(bgp_vrf
, AFI_IP6
,
4133 SAFI_UNICAST
, true);
4138 * update and advertise local routes for a VRF as type-5 routes.
4139 * This is invoked upon RD change for a VRF. Note taht the processing is only
4140 * done in the global route table using the routes which already exist in the
4143 static void update_router_id_vrf(struct bgp
*bgp_vrf
)
4145 /* skip if the RD is configured */
4146 if (is_vrf_rd_configured(bgp_vrf
))
4149 /* derive the RD for the VRF based on new router-id */
4150 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
4152 /* update advertise ipv4|ipv6 routes as type-5 routes */
4153 update_advertise_vrf_routes(bgp_vrf
);
4157 * Delete and withdraw all type-5 routes for the RD corresponding to VRF.
4158 * This is invoked upon VRF RD change. The processing is done only from global
4161 static void withdraw_router_id_vrf(struct bgp
*bgp_vrf
)
4163 /* skip if the RD is configured */
4164 if (is_vrf_rd_configured(bgp_vrf
))
4167 /* delete/withdraw ipv4|ipv6 routes as type-5 routes */
4168 delete_withdraw_vrf_routes(bgp_vrf
);
4171 static void update_advertise_vni_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
4172 struct bgp_dest
*dest
)
4174 struct bgp_dest
*global_dest
;
4175 struct bgp_path_info
*pi
, *global_pi
;
4177 afi_t afi
= AFI_L2VPN
;
4178 safi_t safi
= SAFI_EVPN
;
4180 struct prefix_evpn tmp_evp
;
4181 const struct prefix_evpn
*evp
=
4182 (const struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
4185 * We have already processed type-3 routes.
4186 * Process only type-1 and type-2 routes here.
4188 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
&&
4189 evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
)
4192 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4193 if (pi
->peer
== bgp
->peer_self
&& pi
->type
== ZEBRA_ROUTE_BGP
&&
4194 pi
->sub_type
== BGP_ROUTE_STATIC
)
4200 * VNI table MAC-IP prefixes don't have MAC so make sure it's
4201 * set from path info here.
4203 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4204 if (is_evpn_prefix_ipaddr_none(evp
)) {
4205 /* VNI MAC -> Global */
4206 evpn_type2_prefix_global_copy(
4207 &tmp_evp
, evp
, NULL
/* mac */,
4208 evpn_type2_path_info_get_ip(pi
));
4210 /* VNI IP -> Global */
4211 evpn_type2_prefix_global_copy(
4212 &tmp_evp
, evp
, evpn_type2_path_info_get_mac(pi
),
4216 memcpy(&tmp_evp
, evp
, sizeof(tmp_evp
));
4219 /* Create route in global routing table using this route entry's
4223 global_dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
4224 &tmp_evp
, &vpn
->prd
, NULL
);
4225 assert(global_dest
);
4227 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4229 update_evpn_route_entry(
4230 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4231 NULL
/* ip */, 1, &global_pi
, 0,
4232 mac_mobility_seqnum(attr
), false /* setup_sync */,
4233 NULL
/* old_is_sync */);
4236 struct bgp_evpn_es
*es
;
4237 int route_changed
= 0;
4239 es
= bgp_evpn_es_find(&evp
->prefix
.ead_addr
.esi
);
4240 bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, global_dest
,
4241 attr
, &global_pi
, &route_changed
);
4244 /* Schedule for processing and unlock node. */
4245 bgp_process(bgp
, global_dest
, afi
, safi
);
4246 bgp_dest_unlock_node(global_dest
);
4250 * Update and advertise local routes for a VNI. Invoked upon router-id
4251 * change. Note that the processing is done only on the global route table
4252 * using routes that already exist in the per-VNI table.
4254 static void update_advertise_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4256 struct prefix_evpn p
;
4257 struct bgp_dest
*dest
, *global_dest
;
4258 struct bgp_path_info
*pi
;
4260 afi_t afi
= AFI_L2VPN
;
4261 safi_t safi
= SAFI_EVPN
;
4263 /* Locate type-3 route for VNI in the per-VNI table and use its
4264 * attributes to create and advertise the type-3 route for this VNI
4265 * in the global table.
4267 * RT-3 only if doing head-end replication
4269 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4270 == VXLAN_FLOOD_HEAD_END_REPL
) {
4271 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4272 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
4273 if (!dest
) /* unexpected */
4275 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
4276 if (pi
->peer
== bgp
->peer_self
&&
4277 pi
->type
== ZEBRA_ROUTE_BGP
4278 && pi
->sub_type
== BGP_ROUTE_STATIC
)
4281 bgp_dest_unlock_node(dest
);
4287 global_dest
= bgp_evpn_global_node_get(
4288 bgp
->rib
[afi
][safi
], afi
, safi
, &p
, &vpn
->prd
, NULL
);
4289 update_evpn_route_entry(
4290 bgp
, vpn
, afi
, safi
, global_dest
, attr
, NULL
/* mac */,
4291 NULL
/* ip */, 1, &pi
, 0, mac_mobility_seqnum(attr
),
4292 false /* setup_sync */, NULL
/* old_is_sync */);
4294 /* Schedule for processing and unlock node. */
4295 bgp_process(bgp
, global_dest
, afi
, safi
);
4296 bgp_dest_unlock_node(global_dest
);
4299 /* Now, walk this VNI's MAC & IP route table and use the route and its
4300 * attribute to create and schedule route in global table.
4302 for (dest
= bgp_table_top(vpn
->mac_table
); dest
;
4303 dest
= bgp_route_next(dest
))
4304 update_advertise_vni_route(bgp
, vpn
, dest
);
4306 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
4307 dest
= bgp_route_next(dest
))
4308 update_advertise_vni_route(bgp
, vpn
, dest
);
4312 * Delete (and withdraw) local routes for a VNI - only from the global
4313 * table. Invoked upon router-id change.
4315 static int delete_withdraw_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4317 struct prefix_evpn p
;
4318 struct bgp_dest
*global_dest
;
4319 struct bgp_path_info
*pi
;
4320 afi_t afi
= AFI_L2VPN
;
4321 safi_t safi
= SAFI_EVPN
;
4323 /* Delete and withdraw locally learnt type-2 routes (MACIP)
4324 * for this VNI - from the global table.
4326 delete_global_type2_routes(bgp
, vpn
);
4328 /* Remove type-3 route for this VNI from global table. */
4329 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4330 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], afi
,
4331 safi
, &p
, &vpn
->prd
, NULL
);
4333 /* Delete route entry in the global EVPN table. */
4334 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
4336 /* Schedule for processing - withdraws to peers happen from
4340 bgp_process(bgp
, global_dest
, afi
, safi
);
4341 bgp_dest_unlock_node(global_dest
);
4345 delete_global_ead_evi_routes(bgp
, vpn
);
4350 * Handle router-id change. Update and advertise local routes corresponding
4351 * to this VNI from peers. Note that this is invoked after updating the
4352 * router-id. The routes in the per-VNI table are used to create routes in
4353 * the global table and schedule them.
4355 static void update_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4357 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4359 /* Skip VNIs with configured RD. */
4360 if (is_rd_configured(vpn
))
4363 bgp_evpn_derive_auto_rd(bgp
, vpn
);
4364 update_advertise_vni_routes(bgp
, vpn
);
4368 * Handle router-id change. Delete and withdraw local routes corresponding
4369 * to this VNI from peers. Note that this is invoked prior to updating
4370 * the router-id and is done only on the global route table, the routes
4371 * are needed in the per-VNI table to re-advertise with new router id.
4373 static void withdraw_router_id_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4375 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4377 /* Skip VNIs with configured RD. */
4378 if (is_rd_configured(vpn
))
4381 delete_withdraw_vni_routes(bgp
, vpn
);
4385 * Create RT-3 for a VNI and schedule for processing and advertisement.
4386 * This is invoked upon flooding mode changing to head-end replication.
4388 static void create_advertise_type3(struct hash_bucket
*bucket
, void *data
)
4390 struct bgpevpn
*vpn
= bucket
->data
;
4391 struct bgp
*bgp
= data
;
4392 struct prefix_evpn p
;
4394 if (!vpn
|| !is_vni_live(vpn
) ||
4395 bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
4396 != VXLAN_FLOOD_HEAD_END_REPL
)
4399 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4400 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
))
4401 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
4402 "Type3 route creation failure for VNI %u", vpn
->vni
);
4406 * Delete RT-3 for a VNI and schedule for processing and withdrawal.
4407 * This is invoked upon flooding mode changing to drop BUM packets.
4409 static void delete_withdraw_type3(struct hash_bucket
*bucket
, void *data
)
4411 struct bgpevpn
*vpn
= bucket
->data
;
4412 struct bgp
*bgp
= data
;
4413 struct prefix_evpn p
;
4415 if (!vpn
|| !is_vni_live(vpn
))
4418 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
4419 delete_evpn_route(bgp
, vpn
, &p
);
4423 * Process received EVPN type-2 route (advertise or withdraw).
4425 static int process_type2_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4426 struct attr
*attr
, uint8_t *pfx
, int psize
,
4427 uint32_t addpath_id
)
4429 struct prefix_rd prd
;
4430 struct prefix_evpn p
= {};
4431 struct bgp_route_evpn evpn
= {};
4433 uint8_t macaddr_len
;
4434 /* holds the VNI(s) as in packet */
4435 mpls_label_t label
[BGP_MAX_LABELS
] = {};
4436 uint32_t num_labels
= 0;
4440 /* Type-2 route should be either 33, 37 or 49 bytes or an
4441 * additional 3 bytes if there is a second label (VNI):
4442 * RD (8), ESI (10), Eth Tag (4), MAC Addr Len (1),
4443 * MAC Addr (6), IP len (1), IP (0, 4 or 16),
4444 * MPLS Lbl1 (3), MPLS Lbl2 (0 or 3)
4446 if (psize
!= 33 && psize
!= 37 && psize
!= 49 && psize
!= 36
4447 && psize
!= 40 && psize
!= 52) {
4448 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4449 "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
4450 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4454 struct stream
*pkt
= stream_new(psize
);
4455 stream_put(pkt
, pfx
, psize
);
4457 /* Make prefix_rd */
4458 prd
.family
= AF_UNSPEC
;
4461 STREAM_GET(&prd
.val
, pkt
, 8);
4463 /* Make EVPN prefix. */
4465 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4466 p
.prefix
.route_type
= BGP_EVPN_MAC_IP_ROUTE
;
4468 /* Copy Ethernet Seg Identifier */
4470 STREAM_GET(&attr
->esi
, pkt
, sizeof(esi_t
));
4472 if (bgp_evpn_is_esi_local_and_non_bypass(&attr
->esi
))
4473 attr
->es_flags
|= ATTR_ES_IS_LOCAL
;
4475 attr
->es_flags
&= ~ATTR_ES_IS_LOCAL
;
4477 STREAM_FORWARD_GETP(pkt
, sizeof(esi_t
));
4480 /* Copy Ethernet Tag */
4481 STREAM_GET(ð_tag
, pkt
, 4);
4482 p
.prefix
.macip_addr
.eth_tag
= ntohl(eth_tag
);
4484 /* Get the MAC Addr len */
4485 STREAM_GETC(pkt
, macaddr_len
);
4487 /* Get the MAC Addr */
4488 if (macaddr_len
== (ETH_ALEN
* 8)) {
4489 STREAM_GET(&p
.prefix
.macip_addr
.mac
.octet
, pkt
, ETH_ALEN
);
4492 EC_BGP_EVPN_ROUTE_INVALID
,
4493 "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
4494 peer
->bgp
->vrf_id
, peer
->host
, macaddr_len
);
4500 STREAM_GETC(pkt
, ipaddr_len
);
4502 if (ipaddr_len
!= 0 && ipaddr_len
!= IPV4_MAX_BITLEN
4503 && ipaddr_len
!= IPV6_MAX_BITLEN
) {
4505 EC_BGP_EVPN_ROUTE_INVALID
,
4506 "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
4507 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4512 ipaddr_len
/= 8; /* Convert to bytes. */
4513 p
.prefix
.macip_addr
.ip
.ipa_type
= (ipaddr_len
== IPV4_MAX_BYTELEN
)
4516 STREAM_GET(&p
.prefix
.macip_addr
.ip
.ip
.addr
, pkt
, ipaddr_len
);
4519 /* Get the VNI(s). Stored as bytes here. */
4520 STREAM_GET(&label
[0], pkt
, BGP_LABEL_BYTES
);
4523 /* Do we have a second VNI? */
4524 if (STREAM_READABLE(pkt
)) {
4526 STREAM_GET(&label
[1], pkt
, BGP_LABEL_BYTES
);
4529 /* Process the route. */
4531 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4532 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4533 &label
[0], num_labels
, 0, &evpn
);
4535 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4536 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4537 &label
[0], num_labels
, &evpn
);
4542 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4543 "%u:%s - Rx EVPN Type-2 NLRI - corrupt, discarding",
4544 peer
->bgp
->vrf_id
, peer
->host
);
4552 * Process received EVPN type-3 route (advertise or withdraw).
4554 static int process_type3_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4555 struct attr
*attr
, uint8_t *pfx
, int psize
,
4556 uint32_t addpath_id
)
4558 struct prefix_rd prd
;
4559 struct prefix_evpn p
;
4563 /* Type-3 route should be either 17 or 29 bytes: RD (8), Eth Tag (4),
4564 * IP len (1) and IP (4 or 16).
4566 if (psize
!= 17 && psize
!= 29) {
4567 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4568 "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
4569 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4573 /* If PMSI is present, log if it is anything other than IR.
4574 * Note: We just simply ignore the values as it is not clear if
4575 * doing anything else is better.
4578 (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
))) {
4579 enum pta_type pmsi_tnl_type
= bgp_attr_get_pmsi_tnl_type(attr
);
4581 if (pmsi_tnl_type
!= PMSI_TNLTYPE_INGR_REPL
4582 && pmsi_tnl_type
!= PMSI_TNLTYPE_PIM_SM
) {
4584 EC_BGP_EVPN_PMSI_PRESENT
,
4585 "%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d",
4586 peer
->bgp
->vrf_id
, peer
->host
, pmsi_tnl_type
);
4590 /* Make prefix_rd */
4591 prd
.family
= AF_UNSPEC
;
4593 memcpy(&prd
.val
, pfx
, 8);
4596 /* Make EVPN prefix. */
4597 memset(&p
, 0, sizeof(p
));
4599 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4600 p
.prefix
.route_type
= BGP_EVPN_IMET_ROUTE
;
4602 /* Copy Ethernet Tag */
4603 memcpy(ð_tag
, pfx
, 4);
4604 p
.prefix
.imet_addr
.eth_tag
= ntohl(eth_tag
);
4608 ipaddr_len
= *pfx
++;
4609 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
4610 p
.prefix
.imet_addr
.ip
.ipa_type
= IPADDR_V4
;
4611 memcpy(&p
.prefix
.imet_addr
.ip
.ip
.addr
, pfx
, IPV4_MAX_BYTELEN
);
4614 EC_BGP_EVPN_ROUTE_INVALID
,
4615 "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
4616 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
4620 /* Process the route. */
4622 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4623 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
,
4626 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4627 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4633 * Process received EVPN type-5 route (advertise or withdraw).
4635 static int process_type5_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
4636 struct attr
*attr
, uint8_t *pfx
, int psize
,
4637 uint32_t addpath_id
)
4639 struct prefix_rd prd
;
4640 struct prefix_evpn p
;
4641 struct bgp_route_evpn evpn
;
4644 mpls_label_t label
; /* holds the VNI as in the packet */
4645 bool is_valid_update
= true;
4647 /* Type-5 route should be 34 or 58 bytes:
4648 * RD (8), ESI (10), Eth Tag (4), IP len (1), IP (4 or 16),
4649 * GW (4 or 16) and VNI (3).
4650 * Note that the IP and GW should both be IPv4 or both IPv6.
4652 if (psize
!= 34 && psize
!= 58) {
4653 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4654 "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
4655 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4659 /* Make prefix_rd */
4660 prd
.family
= AF_UNSPEC
;
4662 memcpy(&prd
.val
, pfx
, 8);
4665 /* Make EVPN prefix. */
4666 memset(&p
, 0, sizeof(p
));
4668 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
4669 p
.prefix
.route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
4671 /* Additional information outside of prefix - ESI and GW IP */
4672 memset(&evpn
, 0, sizeof(evpn
));
4674 /* Fetch ESI overlay index */
4676 memcpy(&evpn
.eth_s_id
, pfx
, sizeof(esi_t
));
4679 /* Fetch Ethernet Tag. */
4680 memcpy(ð_tag
, pfx
, 4);
4681 p
.prefix
.prefix_addr
.eth_tag
= ntohl(eth_tag
);
4684 /* Fetch IP prefix length. */
4686 if (ippfx_len
> IPV6_MAX_BITLEN
) {
4688 EC_BGP_EVPN_ROUTE_INVALID
,
4689 "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
4690 peer
->bgp
->vrf_id
, peer
->host
, ippfx_len
);
4693 p
.prefix
.prefix_addr
.ip_prefix_length
= ippfx_len
;
4695 /* Determine IPv4 or IPv6 prefix */
4696 /* Since the address and GW are from the same family, this just becomes
4697 * a simple check on the total size.
4700 SET_IPADDR_V4(&p
.prefix
.prefix_addr
.ip
);
4701 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v4
, pfx
, 4);
4703 SET_IPADDR_V4(&evpn
.gw_ip
);
4704 memcpy(&evpn
.gw_ip
.ipaddr_v4
, pfx
, 4);
4707 SET_IPADDR_V6(&p
.prefix
.prefix_addr
.ip
);
4708 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v6
, pfx
,
4710 pfx
+= IPV6_MAX_BYTELEN
;
4711 SET_IPADDR_V6(&evpn
.gw_ip
);
4712 memcpy(&evpn
.gw_ip
.ipaddr_v6
, pfx
, IPV6_MAX_BYTELEN
);
4713 pfx
+= IPV6_MAX_BYTELEN
;
4716 /* Get the VNI (in MPLS label field). Stored as bytes here. */
4717 memset(&label
, 0, sizeof(label
));
4718 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
4721 * If in future, we are required to access additional fields,
4722 * we MUST increment pfx by BGP_LABEL_BYTES in before reading the next
4727 * An update containing a non-zero gateway IP and a non-zero ESI
4728 * at the same time is should be treated as withdraw
4730 if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4731 !ipaddr_is_zero(&evpn
.gw_ip
)) {
4732 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4733 "%s - Rx EVPN Type-5 ESI and gateway-IP both non-zero.",
4735 is_valid_update
= false;
4736 } else if (bgp_evpn_is_esi_valid(&evpn
.eth_s_id
))
4737 evpn
.type
= OVERLAY_INDEX_ESI
;
4738 else if (!ipaddr_is_zero(&evpn
.gw_ip
))
4739 evpn
.type
= OVERLAY_INDEX_GATEWAY_IP
;
4741 if (is_zero_mac(&attr
->rmac
) &&
4742 !bgp_evpn_is_esi_valid(&evpn
.eth_s_id
) &&
4743 ipaddr_is_zero(&evpn
.gw_ip
) && label
== 0) {
4744 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
4745 "%s - Rx EVPN Type-5 ESI, gateway-IP, RMAC and label all zero",
4747 is_valid_update
= false;
4750 if (is_mcast_mac(&attr
->rmac
) || is_bcast_mac(&attr
->rmac
))
4751 is_valid_update
= false;
4754 /* Process the route. */
4755 if (attr
&& is_valid_update
)
4756 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4757 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4758 &label
, 1, 0, &evpn
);
4760 if (!is_valid_update
) {
4761 char attr_str
[BUFSIZ
] = {0};
4763 bgp_dump_attr(attr
, attr_str
, BUFSIZ
);
4765 "Invalid update from peer %s vrf %u prefix %pFX attr %s - treat as withdraw",
4766 peer
->hostname
, peer
->bgp
->vrf_id
, &p
,
4769 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
4770 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
4777 static void evpn_mpattr_encode_type5(struct stream
*s
, const struct prefix
*p
,
4778 const struct prefix_rd
*prd
,
4779 mpls_label_t
*label
, uint32_t num_labels
,
4784 const struct evpn_addr
*p_evpn_p
;
4786 memset(&temp
, 0, sizeof(temp
));
4787 if (p
->family
!= AF_EVPN
)
4789 p_evpn_p
= &(p
->u
.prefix_evpn
);
4791 /* len denites the total len of IP and GW-IP in the route
4792 IP and GW-IP have to be both ipv4 or ipv6
4794 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4795 len
= 8; /* IP and GWIP are both ipv4 */
4797 len
= 32; /* IP and GWIP are both ipv6 */
4798 /* Prefix contains RD, ESI, EthTag, IP length, IP, GWIP and VNI */
4799 stream_putc(s
, 8 + 10 + 4 + 1 + len
+ 3);
4800 stream_put(s
, prd
->val
, 8);
4801 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_ESI
)
4802 stream_put(s
, &attr
->esi
, sizeof(esi_t
));
4804 stream_put(s
, 0, sizeof(esi_t
));
4805 stream_putl(s
, p_evpn_p
->prefix_addr
.eth_tag
);
4806 stream_putc(s
, p_evpn_p
->prefix_addr
.ip_prefix_length
);
4807 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4808 stream_put_ipv4(s
, p_evpn_p
->prefix_addr
.ip
.ipaddr_v4
.s_addr
);
4810 stream_put(s
, &p_evpn_p
->prefix_addr
.ip
.ipaddr_v6
, 16);
4811 if (attr
&& attr
->evpn_overlay
.type
== OVERLAY_INDEX_GATEWAY_IP
) {
4812 const struct bgp_route_evpn
*evpn_overlay
=
4813 bgp_attr_get_evpn_overlay(attr
);
4815 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4817 evpn_overlay
->gw_ip
.ipaddr_v4
.s_addr
);
4819 stream_put(s
, &(evpn_overlay
->gw_ip
.ipaddr_v6
), 16);
4821 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
4822 stream_put_ipv4(s
, 0);
4824 stream_put(s
, &temp
, 16);
4828 stream_put(s
, label
, 3);
4834 * Cleanup specific VNI upon EVPN (advertise-all-vni) being disabled.
4836 static void cleanup_vni_on_disable(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4838 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4840 /* Remove EVPN routes and schedule for processing. */
4841 delete_routes_for_vni(bgp
, vpn
);
4843 /* Clear "live" flag and see if hash needs to be freed. */
4844 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
4845 if (!is_vni_configured(vpn
))
4846 bgp_evpn_free(bgp
, vpn
);
4850 * Free a VNI entry; iterator function called during cleanup.
4852 static void free_vni_entry(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4854 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4856 delete_all_vni_routes(bgp
, vpn
);
4857 bgp_evpn_free(bgp
, vpn
);
4861 * Derive AUTO import RT for BGP VRF - L3VNI
4863 static void evpn_auto_rt_import_add_for_vrf(struct bgp
*bgp_vrf
)
4865 struct bgp
*bgp_evpn
= NULL
;
4867 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
, true);
4870 bgp_evpn
= bgp_get_evpn();
4875 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
4879 * Delete AUTO import RT from BGP VRF - L3VNI
4881 static void evpn_auto_rt_import_delete_for_vrf(struct bgp
*bgp_vrf
)
4883 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
,
4888 * Derive AUTO export RT for BGP VRF - L3VNI
4890 static void evpn_auto_rt_export_add_for_vrf(struct bgp
*bgp_vrf
)
4892 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
, true);
4896 * Delete AUTO export RT from BGP VRF - L3VNI
4898 static void evpn_auto_rt_export_delete_for_vrf(struct bgp
*bgp_vrf
)
4900 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
,
4904 static void bgp_evpn_handle_export_rt_change_for_vrf(struct bgp
*bgp_vrf
)
4906 struct bgp
*bgp_evpn
= NULL
;
4907 struct listnode
*node
= NULL
;
4908 struct bgpevpn
*vpn
= NULL
;
4910 bgp_evpn
= bgp_get_evpn();
4914 /* update all type-5 routes */
4915 update_advertise_vrf_routes(bgp_vrf
);
4917 /* update all type-2 routes */
4918 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
4919 update_routes_for_vni(bgp_evpn
, vpn
);
4923 * Handle autort change for a given VNI.
4925 static void update_autort_vni(struct hash_bucket
*bucket
, struct bgp
*bgp
)
4927 struct bgpevpn
*vpn
= bucket
->data
;
4929 if (!is_import_rt_configured(vpn
)) {
4930 if (is_vni_live(vpn
))
4931 bgp_evpn_uninstall_routes(bgp
, vpn
);
4932 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
4933 list_delete_all_node(vpn
->import_rtl
);
4934 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
4935 if (is_vni_live(vpn
))
4936 bgp_evpn_install_routes(bgp
, vpn
);
4938 if (!is_export_rt_configured(vpn
)) {
4939 list_delete_all_node(vpn
->export_rtl
);
4940 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
4941 if (is_vni_live(vpn
))
4942 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
4947 * Handle autort change for L3VNI.
4949 static void update_autort_l3vni(struct bgp
*bgp
)
4951 if ((CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
4952 && (CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)))
4955 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
)) {
4956 if (is_l3vni_live(bgp
))
4957 uninstall_routes_for_vrf(bgp
);
4959 /* Cleanup the RT to VRF mapping */
4960 bgp_evpn_unmap_vrf_from_its_rts(bgp
);
4962 /* Remove auto generated RT */
4963 evpn_auto_rt_import_delete_for_vrf(bgp
);
4965 list_delete_all_node(bgp
->vrf_import_rtl
);
4967 /* Map auto derive or configured RTs */
4968 evpn_auto_rt_import_add_for_vrf(bgp
);
4971 if (!CHECK_FLAG(bgp
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
4972 list_delete_all_node(bgp
->vrf_export_rtl
);
4974 evpn_auto_rt_export_delete_for_vrf(bgp
);
4976 evpn_auto_rt_export_add_for_vrf(bgp
);
4978 if (is_l3vni_live(bgp
))
4979 bgp_evpn_map_vrf_to_its_rts(bgp
);
4982 if (!is_l3vni_live(bgp
))
4985 /* advertise type-5 routes if needed */
4986 update_advertise_vrf_routes(bgp
);
4988 /* install all remote routes belonging to this l3vni
4989 * into corresponding vrf
4991 install_routes_for_vrf(bgp
);
4998 /* withdraw type-5 route corresponding to ip prefix */
4999 void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
5000 afi_t afi
, safi_t safi
)
5003 struct prefix_evpn evp
;
5005 build_type5_prefix_from_ip_prefix(&evp
, p
);
5006 ret
= delete_evpn_type5_route(bgp_vrf
, &evp
);
5009 EC_BGP_EVPN_ROUTE_DELETE
,
5010 "%u failed to delete type-5 route for prefix %pFX in vrf %s",
5011 bgp_vrf
->vrf_id
, p
, vrf_id_to_name(bgp_vrf
->vrf_id
));
5014 /* withdraw all type-5 routes for an address family */
5015 void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
, safi_t safi
)
5017 struct bgp_table
*table
= NULL
;
5018 struct bgp_dest
*dest
= NULL
;
5019 struct bgp_path_info
*pi
;
5021 table
= bgp_vrf
->rib
[afi
][safi
];
5022 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5023 /* Only care about "selected" routes. Also ensure that
5024 * these are routes that are injectable into EVPN.
5026 /* TODO: Support for AddPath for EVPN. */
5027 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5028 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5029 && is_route_injectable_into_evpn(pi
)) {
5030 bgp_evpn_withdraw_type5_route(
5031 bgp_vrf
, bgp_dest_get_prefix(dest
), afi
,
5040 * evpn - enable advertisement of default g/w
5042 void bgp_evpn_install_uninstall_default_route(struct bgp
*bgp_vrf
, afi_t afi
,
5043 safi_t safi
, bool add
)
5045 struct prefix ip_prefix
;
5047 /* form the default prefix 0.0.0.0/0 */
5048 memset(&ip_prefix
, 0, sizeof(ip_prefix
));
5049 ip_prefix
.family
= afi2family(afi
);
5052 bgp_evpn_advertise_type5_route(bgp_vrf
, &ip_prefix
,
5055 bgp_evpn_withdraw_type5_route(bgp_vrf
, &ip_prefix
,
5062 * Advertise IP prefix as type-5 route. The afi/safi and src_attr passed
5063 * to this function correspond to those of the source IP prefix (best
5064 * path in the case of the attr. In the case of a local prefix (when we
5065 * are advertising local subnets), the src_attr will be NULL.
5067 void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
, const struct prefix
*p
,
5068 struct attr
*src_attr
, afi_t afi
,
5072 struct prefix_evpn evp
;
5074 build_type5_prefix_from_ip_prefix(&evp
, p
);
5075 ret
= update_evpn_type5_route(bgp_vrf
, &evp
, src_attr
, afi
, safi
);
5077 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
5078 "%u: Failed to create type-5 route for prefix %pFX",
5079 bgp_vrf
->vrf_id
, p
);
5082 /* Inject all prefixes of a particular address-family (currently, IPv4 or
5083 * IPv6 unicast) into EVPN as type-5 routes. This is invoked when the
5084 * advertisement is enabled.
5086 void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
5089 struct bgp_table
*table
= NULL
;
5090 struct bgp_dest
*dest
= NULL
;
5091 struct bgp_path_info
*pi
;
5093 table
= bgp_vrf
->rib
[afi
][safi
];
5094 for (dest
= bgp_table_top(table
); dest
; dest
= bgp_route_next(dest
)) {
5095 /* Need to identify the "selected" route entry to use its
5096 * attribute. Also, ensure that the route is injectable
5098 * TODO: Support for AddPath for EVPN.
5100 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
) {
5101 if (CHECK_FLAG(pi
->flags
, BGP_PATH_SELECTED
)
5102 && is_route_injectable_into_evpn(pi
)) {
5104 /* apply the route-map */
5105 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
) {
5106 route_map_result_t ret
;
5107 struct bgp_path_info tmp_pi
;
5108 struct bgp_path_info_extra tmp_pie
;
5109 struct attr tmp_attr
;
5111 tmp_attr
= *pi
->attr
;
5113 /* Fill temp path_info */
5114 prep_for_rmap_apply(&tmp_pi
, &tmp_pie
,
5118 RESET_FLAG(tmp_attr
.rmap_change_flags
);
5120 ret
= route_map_apply(
5121 bgp_vrf
->adv_cmd_rmap
[afi
][safi
]
5123 bgp_dest_get_prefix(dest
),
5125 if (ret
== RMAP_DENYMATCH
) {
5126 bgp_attr_flush(&tmp_attr
);
5129 bgp_evpn_advertise_type5_route(
5131 bgp_dest_get_prefix(dest
),
5132 &tmp_attr
, afi
, safi
);
5134 bgp_evpn_advertise_type5_route(
5136 bgp_dest_get_prefix(dest
),
5137 pi
->attr
, afi
, safi
);
5144 static void rt_list_remove_node(struct list
*rt_list
,
5145 struct ecommunity
*ecomdel
, bool is_l3
)
5147 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
5148 struct vrf_route_target
*l3rt
= NULL
;
5149 struct ecommunity
*ecom
= NULL
;
5152 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5153 if (ecommunity_match(l3rt
->ecom
, ecomdel
)) {
5154 evpn_vrf_rt_del(l3rt
);
5160 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, ecom
)) {
5161 if (ecommunity_match(ecom
, ecomdel
)) {
5162 ecommunity_free(&ecom
);
5171 list_delete_node(rt_list
, node_to_del
);
5174 void evpn_rt_delete_auto(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
,
5177 struct ecommunity
*ecom_auto
;
5178 struct ecommunity_val eval
;
5180 if (bgp
->advertise_autort_rfc8365
)
5181 vni
|= EVPN_AUTORT_VXLAN
;
5183 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
);
5185 ecom_auto
= ecommunity_new();
5186 ecommunity_add_val(ecom_auto
, &eval
, false, false);
5188 rt_list_remove_node(rtl
, ecom_auto
, is_l3
);
5190 ecommunity_free(&ecom_auto
);
5193 static void evpn_vrf_rt_routes_map(struct bgp
*bgp_vrf
)
5195 /* map VRFs to its RTs and install routes matching this new RT */
5196 if (is_l3vni_live(bgp_vrf
)) {
5197 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
5198 install_routes_for_vrf(bgp_vrf
);
5202 static void evpn_vrf_rt_routes_unmap(struct bgp
*bgp_vrf
)
5204 /* uninstall routes from vrf */
5205 if (is_l3vni_live(bgp_vrf
))
5206 uninstall_routes_for_vrf(bgp_vrf
);
5208 /* Cleanup the RT to VRF mapping */
5209 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
5212 static bool rt_list_has_cfgd_rt(struct list
*rt_list
)
5214 struct listnode
*node
= NULL
, *nnode
= NULL
;
5215 struct vrf_route_target
*l3rt
= NULL
;
5217 for (ALL_LIST_ELEMENTS(rt_list
, node
, nnode
, l3rt
)) {
5218 if (!CHECK_FLAG(l3rt
->flags
, BGP_VRF_RT_AUTO
))
5225 static void unconfigure_import_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5227 if (!bgp_vrf
->vrf_import_rtl
)
5228 return; /* this should never fail */
5230 if (!is_l3vni_live(bgp_vrf
))
5231 return; /* Nothing to do if no vni */
5233 /* fall back to auto-generated RT if this was the last RT */
5234 if (list_isempty(bgp_vrf
->vrf_import_rtl
))
5235 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5238 static void unconfigure_export_rt_for_vrf_fini(struct bgp
*bgp_vrf
)
5241 if (!bgp_vrf
->vrf_export_rtl
)
5242 return; /* this should never fail */
5244 if (!is_l3vni_live(bgp_vrf
))
5245 return; /* Nothing to do if no vni */
5247 /* fall back to auto-generated RT if this was the last RT */
5248 if (list_isempty(bgp_vrf
->vrf_export_rtl
))
5249 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5251 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5254 void bgp_evpn_configure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5255 struct ecommunity
*ecomadd
,
5258 struct vrf_route_target
*newrt
;
5260 newrt
= evpn_vrf_rt_new(ecomadd
);
5263 SET_FLAG(newrt
->flags
, BGP_VRF_RT_WILD
);
5265 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5267 /* Remove auto generated RT if not configured */
5268 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5269 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5271 /* Add the newly configured RT to RT list */
5272 listnode_add_sort(bgp_vrf
->vrf_import_rtl
, newrt
);
5274 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5276 evpn_vrf_rt_routes_map(bgp_vrf
);
5279 void bgp_evpn_configure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5281 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5282 return; /* Already configured */
5284 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5286 if (!is_l3vni_live(bgp_vrf
))
5287 return; /* Wait for VNI before adding rts */
5289 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5291 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5293 evpn_vrf_rt_routes_map(bgp_vrf
);
5296 void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
5297 struct ecommunity
*ecomdel
)
5299 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
5300 return; /* Already un-configured */
5302 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5305 rt_list_remove_node(bgp_vrf
->vrf_import_rtl
, ecomdel
, true);
5307 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_import_rtl
))
5308 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
5310 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5312 evpn_vrf_rt_routes_map(bgp_vrf
);
5315 void bgp_evpn_unconfigure_import_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5317 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
5318 return; /* Already un-configured */
5320 evpn_vrf_rt_routes_unmap(bgp_vrf
);
5322 /* remove auto-generated RT */
5323 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
5325 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
);
5327 unconfigure_import_rt_for_vrf_fini(bgp_vrf
);
5329 evpn_vrf_rt_routes_map(bgp_vrf
);
5332 void bgp_evpn_configure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5333 struct ecommunity
*ecomadd
)
5335 struct vrf_route_target
*newrt
;
5337 newrt
= evpn_vrf_rt_new(ecomadd
);
5339 /* Remove auto generated RT if not configured */
5340 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5341 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5343 /* Add the new RT to the RT list */
5344 listnode_add_sort(bgp_vrf
->vrf_export_rtl
, newrt
);
5346 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5348 if (is_l3vni_live(bgp_vrf
))
5349 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5352 void bgp_evpn_configure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5354 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5355 return; /* Already configured */
5357 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5359 if (!is_l3vni_live(bgp_vrf
))
5360 return; /* Wait for VNI before adding rts */
5362 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5364 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
5367 void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
5368 struct ecommunity
*ecomdel
)
5370 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
))
5371 return; /* Already un-configured */
5374 rt_list_remove_node(bgp_vrf
->vrf_export_rtl
, ecomdel
, true);
5376 if (!rt_list_has_cfgd_rt(bgp_vrf
->vrf_export_rtl
))
5377 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
5379 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5382 void bgp_evpn_unconfigure_export_auto_rt_for_vrf(struct bgp
*bgp_vrf
)
5384 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
5385 return; /* Already un-configured */
5387 /* remove auto-generated RT */
5388 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
5390 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
);
5392 unconfigure_export_rt_for_vrf_fini(bgp_vrf
);
5396 * Handle change to BGP router id. This is invoked twice by the change
5397 * handler, first before the router id has been changed and then after
5398 * the router id has been changed. The first invocation will result in
5399 * local routes for all VNIs/VRF being deleted and withdrawn and the next
5400 * will result in the routes being re-advertised.
5402 void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
)
5404 struct listnode
*node
;
5405 struct bgp
*bgp_vrf
;
5409 /* delete and withdraw all the type-5 routes
5410 stored in the global table for this vrf
5412 withdraw_router_id_vrf(bgp
);
5414 /* delete all the VNI routes (type-2/type-3) routes for all the
5417 hash_iterate(bgp
->vnihash
,
5418 (void (*)(struct hash_bucket
*,
5419 void *))withdraw_router_id_vni
,
5422 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5423 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5424 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5425 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5427 bgp_vrf
->evpn_info
->pip_ip
.s_addr
5433 /* Assign new default instance router-id */
5434 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_DEFAULT
) {
5435 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
5436 if (bgp_vrf
->evpn_info
->advertise_pip
&&
5437 (bgp_vrf
->evpn_info
->pip_ip_static
.s_addr
5439 bgp_vrf
->evpn_info
->pip_ip
=
5441 /* advertise type-5 routes with
5444 update_advertise_vrf_routes(bgp_vrf
);
5449 /* advertise all routes in the vrf as type-5 routes with the new
5452 update_router_id_vrf(bgp
);
5454 /* advertise all the VNI routes (type-2/type-3) routes with the
5457 hash_iterate(bgp
->vnihash
,
5458 (void (*)(struct hash_bucket
*,
5459 void *))update_router_id_vni
,
5465 * Handle change to auto-RT algorithm - update and advertise local routes.
5467 void bgp_evpn_handle_autort_change(struct bgp
*bgp
)
5469 hash_iterate(bgp
->vnihash
,
5470 (void (*)(struct hash_bucket
*,
5471 void*))update_autort_vni
,
5474 update_autort_l3vni(bgp
);
5478 * Handle change to export RT - update and advertise local routes.
5480 int bgp_evpn_handle_export_rt_change(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5482 return update_routes_for_vni(bgp
, vpn
);
5485 void bgp_evpn_handle_vrf_rd_change(struct bgp
*bgp_vrf
, int withdraw
)
5488 delete_withdraw_vrf_routes(bgp_vrf
);
5490 update_advertise_vrf_routes(bgp_vrf
);
5494 * Handle change to RD. This is invoked twice by the change handler,
5495 * first before the RD has been changed and then after the RD has
5496 * been changed. The first invocation will result in local routes
5497 * of this VNI being deleted and withdrawn and the next will result
5498 * in the routes being re-advertised.
5500 void bgp_evpn_handle_rd_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
5504 delete_withdraw_vni_routes(bgp
, vpn
);
5506 update_advertise_vni_routes(bgp
, vpn
);
5510 * Install routes for this VNI. Invoked upon change to Import RT.
5512 int bgp_evpn_install_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5514 return install_routes_for_vni(bgp
, vpn
);
5518 * Uninstall all routes installed for this VNI. Invoked upon change
5521 int bgp_evpn_uninstall_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5523 return uninstall_routes_for_vni(bgp
, vpn
);
5527 * TODO: Hardcoded for a maximum of 2 VNIs right now
5529 char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
, char *buf
,
5534 vni1
= label2vni(label
);
5535 if (num_labels
== 2) {
5536 vni2
= label2vni(label
+ 1);
5537 snprintf(buf
, len
, "%u/%u", vni1
, vni2
);
5539 snprintf(buf
, len
, "%u", vni1
);
5544 * Function to convert evpn route to json format.
5545 * NOTE: We don't use prefix2str as the output here is a bit different.
5547 void bgp_evpn_route2json(const struct prefix_evpn
*p
, json_object
*json
)
5549 char buf1
[ETHER_ADDR_STRLEN
];
5550 char buf2
[PREFIX2STR_BUFFER
];
5557 json_object_int_add(json
, "routeType", p
->prefix
.route_type
);
5559 switch (p
->prefix
.route_type
) {
5560 case BGP_EVPN_MAC_IP_ROUTE
:
5561 json_object_int_add(json
, "ethTag",
5562 p
->prefix
.macip_addr
.eth_tag
);
5563 json_object_int_add(json
, "macLen", 8 * ETH_ALEN
);
5564 json_object_string_add(json
, "mac",
5565 prefix_mac2str(&p
->prefix
.macip_addr
.mac
, buf1
,
5568 if (!is_evpn_prefix_ipaddr_none(p
)) {
5569 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
:
5571 prefixlen
= (family
== AF_INET
) ?
5572 IPV4_MAX_BITLEN
: IPV6_MAX_BITLEN
;
5573 inet_ntop(family
, &p
->prefix
.macip_addr
.ip
.ip
.addr
,
5574 buf2
, PREFIX2STR_BUFFER
);
5575 json_object_int_add(json
, "ipLen", prefixlen
);
5576 json_object_string_add(json
, "ip", buf2
);
5580 case BGP_EVPN_IMET_ROUTE
:
5581 json_object_int_add(json
, "ethTag",
5582 p
->prefix
.imet_addr
.eth_tag
);
5583 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5584 prefixlen
= (family
== AF_INET
) ? IPV4_MAX_BITLEN
:
5586 inet_ntop(family
, &p
->prefix
.imet_addr
.ip
.ip
.addr
, buf2
,
5588 json_object_int_add(json
, "ipLen", prefixlen
);
5589 json_object_string_add(json
, "ip", buf2
);
5592 case BGP_EVPN_IP_PREFIX_ROUTE
:
5593 json_object_int_add(json
, "ethTag",
5594 p
->prefix
.prefix_addr
.eth_tag
);
5595 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
: AF_INET6
;
5596 inet_ntop(family
, &p
->prefix
.prefix_addr
.ip
.ip
.addr
,
5597 buf2
, sizeof(buf2
));
5598 json_object_int_add(json
, "ipLen",
5599 p
->prefix
.prefix_addr
.ip_prefix_length
);
5600 json_object_string_add(json
, "ip", buf2
);
5609 * Encode EVPN prefix in Update (MP_REACH)
5611 void bgp_evpn_encode_prefix(struct stream
*s
, const struct prefix
*p
,
5612 const struct prefix_rd
*prd
, mpls_label_t
*label
,
5613 uint32_t num_labels
, struct attr
*attr
,
5614 bool addpath_capable
, uint32_t addpath_tx_id
)
5616 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
5617 int len
, ipa_len
= 0;
5619 if (addpath_capable
)
5620 stream_putl(s
, addpath_tx_id
);
5623 stream_putc(s
, evp
->prefix
.route_type
);
5625 switch (evp
->prefix
.route_type
) {
5626 case BGP_EVPN_MAC_IP_ROUTE
:
5627 if (is_evpn_prefix_ipaddr_v4(evp
))
5628 ipa_len
= IPV4_MAX_BYTELEN
;
5629 else if (is_evpn_prefix_ipaddr_v6(evp
))
5630 ipa_len
= IPV6_MAX_BYTELEN
;
5631 /* RD, ESI, EthTag, MAC+len, IP len, [IP], 1 VNI */
5632 len
= 8 + 10 + 4 + 1 + 6 + 1 + ipa_len
+ 3;
5633 if (ipa_len
&& num_labels
> 1) /* There are 2 VNIs */
5635 stream_putc(s
, len
);
5636 stream_put(s
, prd
->val
, 8); /* RD */
5638 stream_put(s
, &attr
->esi
, ESI_BYTES
);
5640 stream_put(s
, 0, 10);
5641 stream_putl(s
, evp
->prefix
.macip_addr
.eth_tag
); /* Ethernet Tag ID */
5642 stream_putc(s
, 8 * ETH_ALEN
); /* Mac Addr Len - bits */
5643 stream_put(s
, evp
->prefix
.macip_addr
.mac
.octet
, 6); /* Mac Addr */
5644 stream_putc(s
, 8 * ipa_len
); /* IP address Length */
5645 if (ipa_len
) /* IP */
5646 stream_put(s
, &evp
->prefix
.macip_addr
.ip
.ip
.addr
,
5648 /* 1st label is the L2 VNI */
5649 stream_put(s
, label
, BGP_LABEL_BYTES
);
5650 /* Include 2nd label (L3 VNI) if advertising MAC+IP */
5651 if (ipa_len
&& num_labels
> 1)
5652 stream_put(s
, label
+ 1, BGP_LABEL_BYTES
);
5655 case BGP_EVPN_IMET_ROUTE
:
5656 stream_putc(s
, 17); // TODO: length - assumes IPv4 address
5657 stream_put(s
, prd
->val
, 8); /* RD */
5658 stream_putl(s
, evp
->prefix
.imet_addr
.eth_tag
); /* Ethernet Tag ID */
5659 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5660 /* Originating Router's IP Addr */
5661 stream_put_in_addr(s
, &evp
->prefix
.imet_addr
.ip
.ipaddr_v4
);
5664 case BGP_EVPN_ES_ROUTE
:
5665 stream_putc(s
, 23); /* TODO: length: assumes ipv4 VTEP */
5666 stream_put(s
, prd
->val
, 8); /* RD */
5667 stream_put(s
, evp
->prefix
.es_addr
.esi
.val
, 10); /* ESI */
5668 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
5670 stream_put_in_addr(s
, &evp
->prefix
.es_addr
.ip
.ipaddr_v4
);
5673 case BGP_EVPN_AD_ROUTE
:
5674 /* RD, ESI, EthTag, 1 VNI */
5675 len
= RD_BYTES
+ ESI_BYTES
+ EVPN_ETH_TAG_BYTES
+ BGP_LABEL_BYTES
;
5676 stream_putc(s
, len
);
5677 stream_put(s
, prd
->val
, RD_BYTES
); /* RD */
5678 stream_put(s
, evp
->prefix
.ead_addr
.esi
.val
, ESI_BYTES
); /* ESI */
5679 stream_putl(s
, evp
->prefix
.ead_addr
.eth_tag
); /* Ethernet Tag */
5680 stream_put(s
, label
, BGP_LABEL_BYTES
);
5683 case BGP_EVPN_IP_PREFIX_ROUTE
:
5684 /* TODO: AddPath support. */
5685 evpn_mpattr_encode_type5(s
, p
, prd
, label
, num_labels
, attr
);
5693 int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
5694 struct bgp_nlri
*packet
, int withdraw
)
5700 uint32_t addpath_id
;
5701 bool addpath_capable
;
5706 /* Start processing the NLRI - there may be multiple in the MP_REACH */
5708 lim
= pnt
+ packet
->length
;
5710 safi
= packet
->safi
;
5713 addpath_capable
= bgp_addpath_encode_rx(peer
, afi
, safi
);
5715 for (; pnt
< lim
; pnt
+= psize
) {
5716 /* Clear prefix structure. */
5717 memset(&p
, 0, sizeof(p
));
5719 /* Deal with path-id if AddPath is supported. */
5720 if (addpath_capable
) {
5721 /* When packet overflow occurs return immediately. */
5722 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
5723 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5725 memcpy(&addpath_id
, pnt
, BGP_ADDPATH_ID_LEN
);
5726 addpath_id
= ntohl(addpath_id
);
5727 pnt
+= BGP_ADDPATH_ID_LEN
;
5730 /* All EVPN NLRI types start with type and length. */
5732 return BGP_NLRI_PARSE_ERROR_EVPN_MISSING_TYPE
;
5737 /* When packet overflow occur return immediately. */
5738 if (pnt
+ psize
> lim
)
5739 return BGP_NLRI_PARSE_ERROR_PACKET_OVERFLOW
;
5742 case BGP_EVPN_MAC_IP_ROUTE
:
5743 if (process_type2_route(peer
, afi
, safi
,
5744 withdraw
? NULL
: attr
, pnt
,
5745 psize
, addpath_id
)) {
5748 "%u:%s - Error in processing EVPN type-2 NLRI size %d",
5749 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5750 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE2_SIZE
;
5754 case BGP_EVPN_IMET_ROUTE
:
5755 if (process_type3_route(peer
, afi
, safi
,
5756 withdraw
? NULL
: attr
, pnt
,
5757 psize
, addpath_id
)) {
5760 "%u:%s - Error in processing EVPN type-3 NLRI size %d",
5761 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5762 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE3_SIZE
;
5766 case BGP_EVPN_ES_ROUTE
:
5767 if (bgp_evpn_type4_route_process(peer
, afi
, safi
,
5768 withdraw
? NULL
: attr
, pnt
,
5769 psize
, addpath_id
)) {
5772 "%u:%s - Error in processing EVPN type-4 NLRI size %d",
5773 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5774 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE4_SIZE
;
5778 case BGP_EVPN_AD_ROUTE
:
5779 if (bgp_evpn_type1_route_process(peer
, afi
, safi
,
5780 withdraw
? NULL
: attr
, pnt
,
5781 psize
, addpath_id
)) {
5784 "%u:%s - Error in processing EVPN type-1 NLRI size %d",
5785 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5786 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE1_SIZE
;
5790 case BGP_EVPN_IP_PREFIX_ROUTE
:
5791 if (process_type5_route(peer
, afi
, safi
,
5792 withdraw
? NULL
: attr
, pnt
,
5793 psize
, addpath_id
)) {
5796 "%u:%s - Error in processing EVPN type-5 NLRI size %d",
5797 peer
->bgp
->vrf_id
, peer
->host
, psize
);
5798 return BGP_NLRI_PARSE_ERROR_EVPN_TYPE5_SIZE
;
5807 /* Packet length consistency check. */
5809 return BGP_NLRI_PARSE_ERROR_PACKET_LENGTH
;
5811 return BGP_NLRI_PARSE_OK
;
5815 * Map the RTs (configured or automatically derived) of a VRF to the VRF.
5816 * The mapping will be used during route processing.
5817 * bgp_vrf: specific bgp vrf instance on which RT is configured
5819 void bgp_evpn_map_vrf_to_its_rts(struct bgp
*bgp_vrf
)
5821 struct listnode
*node
, *nnode
;
5822 struct vrf_route_target
*l3rt
;
5824 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5825 map_vrf_to_rt(bgp_vrf
, l3rt
);
5829 * Unmap the RTs (configured or automatically derived) of a VRF from the VRF.
5831 void bgp_evpn_unmap_vrf_from_its_rts(struct bgp
*bgp_vrf
)
5833 struct listnode
*node
, *nnode
;
5834 struct vrf_route_target
*l3rt
;
5836 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, l3rt
))
5837 unmap_vrf_from_rt(bgp_vrf
, l3rt
);
5841 * Map the RTs (configured or automatically derived) of a VNI to the VNI.
5842 * The mapping will be used during route processing.
5844 void bgp_evpn_map_vni_to_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5847 struct ecommunity_val
*eval
;
5848 struct listnode
*node
, *nnode
;
5849 struct ecommunity
*ecom
;
5851 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5852 for (i
= 0; i
< ecom
->size
; i
++) {
5853 eval
= (struct ecommunity_val
*)(ecom
->val
5855 * ECOMMUNITY_SIZE
));
5856 map_vni_to_rt(bgp
, vpn
, eval
);
5862 * Unmap the RTs (configured or automatically derived) of a VNI from the VNI.
5864 void bgp_evpn_unmap_vni_from_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5867 struct ecommunity_val
*eval
;
5868 struct listnode
*node
, *nnode
;
5869 struct ecommunity
*ecom
;
5871 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
5872 for (i
= 0; i
< ecom
->size
; i
++) {
5873 struct irt_node
*irt
;
5874 struct ecommunity_val eval_tmp
;
5876 eval
= (struct ecommunity_val
*)(ecom
->val
5878 * ECOMMUNITY_SIZE
));
5879 /* If using "automatic" RT, we only care about the
5880 * local-admin sub-field.
5881 * This is to facilitate using VNI as the RT for EBGP
5884 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
5885 if (!is_import_rt_configured(vpn
))
5886 mask_ecom_global_admin(&eval_tmp
, eval
);
5888 irt
= lookup_import_rt(bgp
, &eval_tmp
);
5890 unmap_vni_from_rt(bgp
, vpn
, irt
);
5896 * Derive Import RT automatically for VNI and map VNI to RT.
5897 * The mapping will be used during route processing.
5899 void bgp_evpn_derive_auto_rt_import(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5901 form_auto_rt(bgp
, vpn
->vni
, vpn
->import_rtl
, false);
5902 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
5905 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
5909 * Derive Export RT automatically for VNI.
5911 void bgp_evpn_derive_auto_rt_export(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5913 form_auto_rt(bgp
, vpn
->vni
, vpn
->export_rtl
, false);
5914 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
5918 * Derive RD automatically for VNI using passed information - it
5919 * is of the form RouterId:unique-id-for-vni.
5921 void bgp_evpn_derive_auto_rd_for_vrf(struct bgp
*bgp
)
5923 if (is_vrf_rd_configured(bgp
))
5926 form_auto_rd(bgp
->router_id
, bgp
->vrf_rd_id
, &bgp
->vrf_prd
);
5930 * Derive RD automatically for VNI using passed information - it
5931 * is of the form RouterId:unique-id-for-vni.
5933 void bgp_evpn_derive_auto_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
5935 char buf
[BGP_EVPN_PREFIX_RD_LEN
];
5937 vpn
->prd
.family
= AF_UNSPEC
;
5938 vpn
->prd
.prefixlen
= 64;
5939 snprintfrr(buf
, sizeof(buf
), "%pI4:%hu", &bgp
->router_id
, vpn
->rd_id
);
5940 (void)str2prefix_rd(buf
, &vpn
->prd
);
5941 UNSET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
5947 bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni
)
5949 struct list
*inst
= bm
->bgp
;
5950 struct listnode
*node
;
5951 struct bgp
*bgp_vrf
;
5953 for (ALL_LIST_ELEMENTS_RO(inst
, node
, bgp_vrf
)) {
5954 if (bgp_vrf
->l3vni
== vni
)
5964 struct bgpevpn
*bgp_evpn_lookup_vni(struct bgp
*bgp
, vni_t vni
)
5966 struct bgpevpn
*vpn
;
5969 memset(&tmp
, 0, sizeof(tmp
));
5971 vpn
= hash_lookup(bgp
->vnihash
, &tmp
);
5976 * Create a new vpn - invoked upon configuration or zebra notification.
5978 struct bgpevpn
*bgp_evpn_new(struct bgp
*bgp
, vni_t vni
,
5979 struct in_addr originator_ip
,
5980 vrf_id_t tenant_vrf_id
,
5981 struct in_addr mcast_grp
,
5982 ifindex_t svi_ifindex
)
5984 struct bgpevpn
*vpn
;
5986 vpn
= XCALLOC(MTYPE_BGP_EVPN
, sizeof(struct bgpevpn
));
5988 /* Set values - RD and RT set to defaults. */
5990 vpn
->originator_ip
= originator_ip
;
5991 vpn
->tenant_vrf_id
= tenant_vrf_id
;
5992 vpn
->mcast_grp
= mcast_grp
;
5993 vpn
->svi_ifindex
= svi_ifindex
;
5995 /* Initialize route-target import and export lists */
5996 vpn
->import_rtl
= list_new();
5997 vpn
->import_rtl
->cmp
=
5998 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
5999 vpn
->import_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
6000 vpn
->export_rtl
= list_new();
6001 vpn
->export_rtl
->cmp
=
6002 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
6003 vpn
->export_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
6004 bf_assign_index(bm
->rd_idspace
, vpn
->rd_id
);
6005 derive_rd_rt_for_vni(bgp
, vpn
);
6007 /* Initialize EVPN route tables. */
6008 vpn
->ip_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
6009 vpn
->mac_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
6012 (void)hash_get(bgp
->vnihash
, vpn
, hash_alloc_intern
);
6014 bgp_evpn_remote_ip_hash_init(vpn
);
6015 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6017 /* add to l2vni list on corresponding vrf */
6018 bgpevpn_link_to_l3vni(vpn
);
6020 bgp_evpn_vni_es_init(vpn
);
6022 QOBJ_REG(vpn
, bgpevpn
);
6027 * Free a given VPN - called in multiple scenarios such as zebra
6028 * notification, configuration being deleted, advertise-all-vni disabled etc.
6029 * This just frees appropriate memory, caller should have taken other
6032 void bgp_evpn_free(struct bgp
*bgp
, struct bgpevpn
*vpn
)
6034 bgp_evpn_remote_ip_hash_destroy(vpn
);
6035 bgp_evpn_vni_es_cleanup(vpn
);
6036 bgpevpn_unlink_from_l3vni(vpn
);
6037 bgp_table_unlock(vpn
->ip_table
);
6038 bgp_table_unlock(vpn
->mac_table
);
6039 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
6040 list_delete(&vpn
->import_rtl
);
6041 list_delete(&vpn
->export_rtl
);
6042 bf_release_index(bm
->rd_idspace
, vpn
->rd_id
);
6043 hash_release(bgp
->vni_svi_hash
, vpn
);
6044 hash_release(bgp
->vnihash
, vpn
);
6046 XFREE(MTYPE_BGP_EVPN
, vpn
);
6049 static void hash_evpn_free(struct bgpevpn
*vpn
)
6051 XFREE(MTYPE_BGP_EVPN
, vpn
);
6055 * Import evpn route from global table to VNI/VRF/ESI.
6057 int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6058 const struct prefix
*p
, struct bgp_path_info
*pi
)
6060 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 1);
6064 * Unimport evpn route from VNI/VRF/ESI.
6066 int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
6067 const struct prefix
*p
, struct bgp_path_info
*pi
)
6069 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, pi
, 0);
6072 /* filter routes which have martian next hops */
6073 int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
)
6077 struct bgp_dest
*rd_dest
, *dest
;
6078 struct bgp_table
*table
;
6079 struct bgp_path_info
*pi
;
6084 /* Walk entire global routing table and evaluate routes which could be
6085 * imported into this VPN. Note that we cannot just look at the routes
6086 * for the VNI's RD -
6087 * remote routes applicable for this VNI could have any RD.
6089 /* EVPN routes are a 2-level table. */
6090 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
6091 rd_dest
= bgp_route_next(rd_dest
)) {
6092 table
= bgp_dest_get_bgp_table_info(rd_dest
);
6096 for (dest
= bgp_table_top(table
); dest
;
6097 dest
= bgp_route_next(dest
)) {
6099 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
6102 /* Consider "valid" remote routes applicable for
6104 if (!(pi
->type
== ZEBRA_ROUTE_BGP
6105 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
6107 if (bgp_nexthop_self(bgp
, afi
, pi
->type
,
6108 pi
->sub_type
, pi
->attr
,
6110 const struct prefix
*p
=
6111 bgp_dest_get_prefix(dest
);
6113 if (bgp_debug_update(pi
->peer
, p
, NULL
,
6115 char attr_str
[BUFSIZ
] = {0};
6117 bgp_dump_attr(pi
->attr
,
6122 "%u: prefix %pBD with attr %s - DENIED due to martian or self nexthop",
6126 bgp_evpn_unimport_route(bgp
, afi
, safi
,
6129 bgp_rib_remove(dest
, pi
, pi
->peer
, afi
,
6140 * Handle del of a local MACIP.
6142 int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6143 struct ipaddr
*ip
, int state
)
6145 struct bgpevpn
*vpn
;
6146 struct prefix_evpn p
;
6147 struct bgp_dest
*dest
;
6149 /* Lookup VNI hash - should exist. */
6150 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6151 if (!vpn
|| !is_vni_live(vpn
)) {
6152 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6153 "%u: VNI hash entry for VNI %u %s at MACIP DEL",
6154 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6158 build_evpn_type2_prefix(&p
, mac
, ip
);
6159 if (state
== ZEBRA_NEIGH_ACTIVE
) {
6160 /* Remove EVPN type-2 route and schedule for processing. */
6161 delete_evpn_route(bgp
, vpn
, &p
);
6163 /* Re-instate the current remote best path if any */
6164 dest
= bgp_evpn_vni_node_lookup(vpn
, &p
, NULL
);
6166 evpn_zebra_reinstall_best_route(bgp
, vpn
, dest
);
6167 bgp_dest_unlock_node(dest
);
6175 * Handle add of a local MACIP.
6177 int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
6178 struct ipaddr
*ip
, uint8_t flags
, uint32_t seq
, esi_t
*esi
)
6180 struct bgpevpn
*vpn
;
6181 struct prefix_evpn p
;
6183 /* Lookup VNI hash - should exist. */
6184 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6185 if (!vpn
|| !is_vni_live(vpn
)) {
6186 flog_warn(EC_BGP_EVPN_VPN_VNI
,
6187 "%u: VNI hash entry for VNI %u %s at MACIP ADD",
6188 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
6192 /* Create EVPN type-2 route and schedule for processing. */
6193 build_evpn_type2_prefix(&p
, mac
, ip
);
6194 if (update_evpn_route(bgp
, vpn
, &p
, flags
, seq
, esi
)) {
6196 EC_BGP_EVPN_ROUTE_CREATE
,
6197 "%u:Failed to create Type-2 route, VNI %u %s MAC %pEA IP %pIA (flags: 0x%x)",
6198 bgp
->vrf_id
, vpn
->vni
,
6199 CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
)
6209 static void link_l2vni_hash_to_l3vni(struct hash_bucket
*bucket
,
6210 struct bgp
*bgp_vrf
)
6212 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6213 struct bgp
*bgp_evpn
= NULL
;
6215 bgp_evpn
= bgp_get_evpn();
6218 if (vpn
->tenant_vrf_id
== bgp_vrf
->vrf_id
)
6219 bgpevpn_link_to_l3vni(vpn
);
6222 int bgp_evpn_local_l3vni_add(vni_t l3vni
, vrf_id_t vrf_id
,
6223 struct ethaddr
*svi_rmac
,
6224 struct ethaddr
*vrr_rmac
,
6225 struct in_addr originator_ip
, int filter
,
6226 ifindex_t svi_ifindex
,
6227 bool is_anycast_mac
)
6229 struct bgp
*bgp_vrf
= NULL
; /* bgp VRF instance */
6230 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6231 struct listnode
*node
= NULL
;
6232 struct bgpevpn
*vpn
= NULL
;
6235 /* get the EVPN instance - required to get the AS number for VRF
6238 bgp_evpn
= bgp_get_evpn();
6242 "Cannot process L3VNI %u ADD - EVPN BGP instance not yet created",
6248 /* if the BGP vrf instance doesn't exist - create one */
6249 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6254 ret
= bgp_get_vty(&bgp_vrf
, &as
, vrf_id_to_name(vrf_id
),
6255 vrf_id
== VRF_DEFAULT
6256 ? BGP_INSTANCE_TYPE_DEFAULT
6257 : BGP_INSTANCE_TYPE_VRF
);
6259 case BGP_ERR_AS_MISMATCH
:
6260 flog_err(EC_BGP_EVPN_AS_MISMATCH
,
6261 "BGP instance is already running; AS is %u",
6264 case BGP_ERR_INSTANCE_MISMATCH
:
6265 flog_err(EC_BGP_EVPN_INSTANCE_MISMATCH
,
6266 "BGP instance type mismatch");
6270 /* mark as auto created */
6271 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
);
6274 /* associate the vrf with l3vni and related parameters */
6275 bgp_vrf
->l3vni
= l3vni
;
6276 bgp_vrf
->originator_ip
= originator_ip
;
6277 bgp_vrf
->l3vni_svi_ifindex
= svi_ifindex
;
6278 bgp_vrf
->evpn_info
->is_anycast_mac
= is_anycast_mac
;
6280 /* copy anycast MAC from VRR MAC */
6281 memcpy(&bgp_vrf
->rmac
, vrr_rmac
, ETH_ALEN
);
6282 /* copy sys RMAC from SVI MAC */
6283 memcpy(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, svi_rmac
, ETH_ALEN
);
6284 /* PIP user configured mac is not present use svi mac as sys mac */
6285 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
))
6286 memcpy(&bgp_vrf
->evpn_info
->pip_rmac
, svi_rmac
, ETH_ALEN
);
6288 if (bgp_debug_zebra(NULL
))
6290 "VRF %s vni %u pip %s RMAC %pEA sys RMAC %pEA static RMAC %pEA is_anycast_mac %s",
6291 vrf_id_to_name(bgp_vrf
->vrf_id
), bgp_vrf
->l3vni
,
6292 bgp_vrf
->evpn_info
->advertise_pip
? "enable"
6294 &bgp_vrf
->rmac
, &bgp_vrf
->evpn_info
->pip_rmac
,
6295 &bgp_vrf
->evpn_info
->pip_rmac_static
,
6296 is_anycast_mac
? "Enable" : "Disable");
6298 /* set the right filter - are we using l3vni only for prefix routes? */
6300 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6303 * VNI_FLAG_USE_TWO_LABELS flag for linked L2VNIs should not be
6304 * set before linking vrf to L3VNI. Thus, no need to clear
6308 UNSET_FLAG(bgp_vrf
->vrf_flags
,
6309 BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6311 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6312 if (!CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
6315 * If we are flapping VNI_FLAG_USE_TWO_LABELS
6316 * flag, update all MACIP routes in this VNI
6318 SET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6319 update_all_type2_routes(bgp_evpn
, vpn
);
6324 /* Map auto derive or configured RTs */
6325 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
) ||
6326 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_AUTO_RT_CFGD
))
6327 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
6329 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
6331 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
) ||
6332 CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_AUTO_RT_CFGD
))
6333 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
6335 /* auto derive RD */
6336 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
6338 /* link all corresponding l2vnis */
6339 hash_iterate(bgp_evpn
->vnihash
,
6340 (void (*)(struct hash_bucket
*,
6341 void *))link_l2vni_hash_to_l3vni
,
6344 /* Only update all corresponding type-2 routes if we are advertising two
6345 * labels along with type-2 routes
6348 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
6349 update_routes_for_vni(bgp_evpn
, vpn
);
6351 /* advertise type-5 routes if needed */
6352 update_advertise_vrf_routes(bgp_vrf
);
6354 /* install all remote routes belonging to this l3vni into correspondng
6356 install_routes_for_vrf(bgp_vrf
);
6361 int bgp_evpn_local_l3vni_del(vni_t l3vni
, vrf_id_t vrf_id
)
6363 struct bgp
*bgp_vrf
= NULL
; /* bgp vrf instance */
6364 struct bgp
*bgp_evpn
= NULL
; /* EVPN bgp instance */
6365 struct listnode
*node
= NULL
;
6366 struct listnode
*next
= NULL
;
6367 struct bgpevpn
*vpn
= NULL
;
6369 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
6373 "Cannot process L3VNI %u Del - Could not find BGP instance",
6378 bgp_evpn
= bgp_get_evpn();
6382 "Cannot process L3VNI %u Del - Could not find EVPN BGP instance",
6387 /* Remove remote routes from BGT VRF even if BGP_VRF_AUTO is configured,
6388 * bgp_delete would not remove/decrement bgp_path_info of the ip_prefix
6389 * routes. This will uninstalling the routes from zebra and decremnt the
6392 uninstall_routes_for_vrf(bgp_vrf
);
6394 /* delete/withdraw all type-5 routes */
6395 delete_withdraw_vrf_routes(bgp_vrf
);
6397 /* remove the l3vni from vrf instance */
6400 /* remove the Rmac from the BGP vrf */
6401 memset(&bgp_vrf
->rmac
, 0, sizeof(struct ethaddr
));
6402 memset(&bgp_vrf
->evpn_info
->pip_rmac_zebra
, 0, ETH_ALEN
);
6403 if (is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac_static
) &&
6404 !is_zero_mac(&bgp_vrf
->evpn_info
->pip_rmac
))
6405 memset(&bgp_vrf
->evpn_info
->pip_rmac
, 0, ETH_ALEN
);
6407 /* remove default import RT or Unmap non-default import RT */
6408 if (!list_isempty(bgp_vrf
->vrf_import_rtl
)) {
6409 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6410 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
6411 list_delete_all_node(bgp_vrf
->vrf_import_rtl
);
6414 /* remove default export RT */
6415 if (!list_isempty(bgp_vrf
->vrf_export_rtl
) &&
6416 !CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
)) {
6417 list_delete_all_node(bgp_vrf
->vrf_export_rtl
);
6420 /* update all corresponding local mac-ip routes */
6421 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)) {
6422 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
6423 UNSET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
6424 update_routes_for_vni(bgp_evpn
, vpn
);
6428 /* If any L2VNIs point to this instance, unlink them. */
6429 for (ALL_LIST_ELEMENTS(bgp_vrf
->l2vnis
, node
, next
, vpn
))
6430 bgpevpn_unlink_from_l3vni(vpn
);
6432 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
6434 /* Delete the instance if it was autocreated */
6435 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
))
6436 bgp_delete(bgp_vrf
);
6442 * Handle del of a local VNI.
6444 int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
)
6446 struct bgpevpn
*vpn
;
6448 /* Locate VNI hash */
6449 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6453 /* Remove all local EVPN routes and schedule for processing (to
6454 * withdraw from peers).
6456 delete_routes_for_vni(bgp
, vpn
);
6458 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6460 vpn
->svi_ifindex
= 0;
6462 * tunnel is no longer active, del tunnel ip address from tip_hash
6464 bgp_tip_del(bgp
, &vpn
->originator_ip
);
6466 /* Clear "live" flag and see if hash needs to be freed. */
6467 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6468 if (!is_vni_configured(vpn
))
6469 bgp_evpn_free(bgp
, vpn
);
6475 * Handle add (or update) of a local VNI. The VNI changes we care
6476 * about are for the local-tunnel-ip and the (tenant) VRF.
6478 int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
6479 struct in_addr originator_ip
,
6480 vrf_id_t tenant_vrf_id
,
6481 struct in_addr mcast_grp
,
6482 ifindex_t svi_ifindex
)
6484 struct bgpevpn
*vpn
;
6485 struct prefix_evpn p
;
6487 /* Lookup VNI. If present and no change, exit. */
6488 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
6491 if (is_vni_live(vpn
)
6492 && IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
)
6493 && IPV4_ADDR_SAME(&vpn
->mcast_grp
, &mcast_grp
)
6494 && vpn
->tenant_vrf_id
== tenant_vrf_id
6495 && vpn
->svi_ifindex
== svi_ifindex
)
6496 /* Probably some other param has changed that we don't
6500 bgp_evpn_mcast_grp_change(bgp
, vpn
, mcast_grp
);
6502 if (vpn
->svi_ifindex
!= svi_ifindex
) {
6505 * Unresolve all the gateway IP nexthops for this VNI
6508 bgp_evpn_remote_ip_hash_iterate(
6510 (void (*)(struct hash_bucket
*, void *))
6511 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6513 bgp_evpn_unlink_from_vni_svi_hash(bgp
, vpn
);
6514 vpn
->svi_ifindex
= svi_ifindex
;
6515 bgp_evpn_link_to_vni_svi_hash(bgp
, vpn
);
6518 * Resolve all the gateway IP nexthops for this VNI
6521 bgp_evpn_remote_ip_hash_iterate(
6523 (void (*)(struct hash_bucket
*, void *))
6524 bgp_evpn_remote_ip_hash_link_nexthop
,
6528 /* Update tenant_vrf_id if it has changed. */
6529 if (vpn
->tenant_vrf_id
!= tenant_vrf_id
) {
6532 * Unresolve all the gateway IP nexthops for this VNI
6535 bgp_evpn_remote_ip_hash_iterate(
6537 (void (*)(struct hash_bucket
*, void *))
6538 bgp_evpn_remote_ip_hash_unlink_nexthop
,
6540 bgpevpn_unlink_from_l3vni(vpn
);
6541 vpn
->tenant_vrf_id
= tenant_vrf_id
;
6542 bgpevpn_link_to_l3vni(vpn
);
6545 * Resolve all the gateway IP nexthops for this VNI
6548 bgp_evpn_remote_ip_hash_iterate(
6550 (void (*)(struct hash_bucket
*, void *))
6551 bgp_evpn_remote_ip_hash_link_nexthop
,
6555 /* If tunnel endpoint IP has changed, update (and delete prior
6556 * type-3 route, if needed.)
6558 handle_tunnel_ip_change(bgp
, vpn
, originator_ip
);
6560 /* Update all routes with new endpoint IP and/or export RT
6563 if (is_vni_live(vpn
))
6564 update_routes_for_vni(bgp
, vpn
);
6566 /* Create or update as appropriate. */
6567 vpn
= bgp_evpn_new(bgp
, vni
, originator_ip
, tenant_vrf_id
,
6568 mcast_grp
, svi_ifindex
);
6571 /* if the VNI is live already, there is nothing more to do */
6572 if (is_vni_live(vpn
))
6575 /* Mark as "live" */
6576 SET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
6578 /* tunnel is now active, add tunnel-ip to db */
6579 if (bgp_tip_add(bgp
, &originator_ip
))
6580 /* The originator_ip was not already present in the
6581 * bgp martian next-hop table as a tunnel-ip, so we
6582 * need to go back and filter routes matching the new
6585 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
6588 * Create EVPN type-3 route and schedule for processing.
6590 * RT-3 only if doing head-end replication
6592 if (bgp_evpn_vni_flood_mode_get(bgp
, vpn
)
6593 == VXLAN_FLOOD_HEAD_END_REPL
) {
6594 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
6595 if (update_evpn_route(bgp
, vpn
, &p
, 0, 0, NULL
)) {
6596 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
6597 "%u: Type3 route creation failure for VNI %u",
6603 /* If we have learnt and retained remote routes (VTEPs, MACs) for this
6607 install_routes_for_vni(bgp
, vpn
);
6609 /* If we are advertising gateway mac-ip
6610 It needs to be conveyed again to zebra */
6611 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
, vpn
->vni
);
6613 /* advertise svi mac-ip knob to zebra */
6614 bgp_zebra_advertise_svi_macip(bgp
, vpn
->advertise_svi_macip
, vpn
->vni
);
6620 * Handle change in setting for BUM handling. The supported values
6621 * are head-end replication and dropping all BUM packets. Any change
6622 * should be registered with zebra. Also, if doing head-end replication,
6623 * need to advertise local VNIs as EVPN RT-3 wheras, if BUM packets are
6624 * to be dropped, the RT-3s must be withdrawn.
6626 void bgp_evpn_flood_control_change(struct bgp
*bgp
)
6628 zlog_info("L2VPN EVPN BUM handling is %s",
6629 bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
?
6630 "Flooding" : "Flooding Disabled");
6632 bgp_zebra_vxlan_flood_control(bgp
, bgp
->vxlan_flood_ctrl
);
6633 if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_HEAD_END_REPL
)
6634 hash_iterate(bgp
->vnihash
, create_advertise_type3
, bgp
);
6635 else if (bgp
->vxlan_flood_ctrl
== VXLAN_FLOOD_DISABLED
)
6636 hash_iterate(bgp
->vnihash
, delete_withdraw_type3
, bgp
);
6640 * Cleanup EVPN information on disable - Need to delete and withdraw
6641 * EVPN routes from peers.
6643 void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
)
6645 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_bucket
*,
6646 void *))cleanup_vni_on_disable
,
6651 * Cleanup EVPN information - invoked at the time of bgpd exit or when the
6652 * BGP instance (default) is being freed.
6654 void bgp_evpn_cleanup(struct bgp
*bgp
)
6656 hash_iterate(bgp
->vnihash
,
6657 (void (*)(struct hash_bucket
*, void *))free_vni_entry
,
6660 hash_clean(bgp
->import_rt_hash
, (void (*)(void *))hash_import_rt_free
);
6661 hash_free(bgp
->import_rt_hash
);
6662 bgp
->import_rt_hash
= NULL
;
6664 hash_clean(bgp
->vrf_import_rt_hash
,
6665 (void (*)(void *))hash_vrf_import_rt_free
);
6666 hash_free(bgp
->vrf_import_rt_hash
);
6667 bgp
->vrf_import_rt_hash
= NULL
;
6669 hash_clean(bgp
->vni_svi_hash
, (void (*)(void *))hash_evpn_free
);
6670 hash_free(bgp
->vni_svi_hash
);
6671 bgp
->vni_svi_hash
= NULL
;
6672 hash_free(bgp
->vnihash
);
6673 bgp
->vnihash
= NULL
;
6675 list_delete(&bgp
->vrf_import_rtl
);
6676 list_delete(&bgp
->vrf_export_rtl
);
6677 list_delete(&bgp
->l2vnis
);
6681 * Initialization for EVPN
6684 * hash for RT to VNI
6686 void bgp_evpn_init(struct bgp
*bgp
)
6689 hash_create(vni_hash_key_make
, vni_hash_cmp
, "BGP VNI Hash");
6691 hash_create(vni_svi_hash_key_make
, vni_svi_hash_cmp
,
6692 "BGP VNI hash based on SVI ifindex");
6693 bgp
->import_rt_hash
=
6694 hash_create(import_rt_hash_key_make
, import_rt_hash_cmp
,
6695 "BGP Import RT Hash");
6696 bgp
->vrf_import_rt_hash
=
6697 hash_create(vrf_import_rt_hash_key_make
, vrf_import_rt_hash_cmp
,
6698 "BGP VRF Import RT Hash");
6699 bgp
->vrf_import_rtl
= list_new();
6700 bgp
->vrf_import_rtl
->cmp
=
6701 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6702 bgp
->vrf_import_rtl
->del
= evpn_vrf_rt_del
;
6703 bgp
->vrf_export_rtl
= list_new();
6704 bgp
->vrf_export_rtl
->cmp
=
6705 (int (*)(void *, void *))evpn_vrf_route_target_cmp
;
6706 bgp
->vrf_export_rtl
->del
= evpn_vrf_rt_del
;
6707 bgp
->l2vnis
= list_new();
6708 bgp
->l2vnis
->cmp
= vni_list_cmp
;
6709 /* By default Duplicate Address Dection is enabled.
6710 * Max-moves (N) 5, detection time (M) 180
6711 * default action is warning-only
6712 * freeze action permanently freezes address,
6713 * and freeze time (auto-recovery) is disabled.
6715 if (bgp
->evpn_info
) {
6716 bgp
->evpn_info
->dup_addr_detect
= true;
6717 bgp
->evpn_info
->dad_time
= EVPN_DAD_DEFAULT_TIME
;
6718 bgp
->evpn_info
->dad_max_moves
= EVPN_DAD_DEFAULT_MAX_MOVES
;
6719 bgp
->evpn_info
->dad_freeze
= false;
6720 bgp
->evpn_info
->dad_freeze_time
= 0;
6721 /* Initialize zebra vxlan */
6722 bgp_zebra_dup_addr_detection(bgp
);
6723 /* Enable PIP feature by default for bgp vrf instance */
6724 if (bgp
->inst_type
== BGP_INSTANCE_TYPE_VRF
) {
6725 struct bgp
*bgp_default
;
6727 bgp
->evpn_info
->advertise_pip
= true;
6728 bgp_default
= bgp_get_default();
6730 bgp
->evpn_info
->pip_ip
= bgp_default
->router_id
;
6734 /* Default BUM handling is to do head-end replication. */
6735 bgp
->vxlan_flood_ctrl
= VXLAN_FLOOD_HEAD_END_REPL
;
6737 bgp_evpn_nh_init(bgp
);
6740 void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
)
6742 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
6743 bgp_evpn_nh_finish(bgp_vrf
);
6747 * Get the prefixlen of the ip prefix carried within the type5 evpn route.
6749 int bgp_evpn_get_type5_prefixlen(const struct prefix
*pfx
)
6751 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6753 if (!pfx
|| pfx
->family
!= AF_EVPN
)
6756 if (evp
->prefix
.route_type
!= BGP_EVPN_IP_PREFIX_ROUTE
)
6759 return evp
->prefix
.prefix_addr
.ip_prefix_length
;
6763 * Should we register nexthop for this EVPN prefix for nexthop tracking?
6765 bool bgp_evpn_is_prefix_nht_supported(const struct prefix
*pfx
)
6767 struct prefix_evpn
*evp
= (struct prefix_evpn
*)pfx
;
6770 * EVPN routes should be marked as valid only if the nexthop is
6771 * reachable. Only if this happens, the route should be imported
6772 * (into VNI or VRF routing tables) and/or advertised.
6773 * Note: This is currently applied for EVPN type-1, type-2,
6774 * type-3, type-4 and type-5 routes.
6775 * It may be tweaked later on for other routes, or
6776 * even removed completely when all routes are handled.
6778 if (pfx
&& pfx
->family
== AF_EVPN
6779 && (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
6780 || evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
6781 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
6782 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
6783 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
6789 static void *bgp_evpn_remote_ip_hash_alloc(void *p
)
6791 const struct evpn_remote_ip
*key
= (const struct evpn_remote_ip
*)p
;
6792 struct evpn_remote_ip
*ip
;
6794 ip
= XMALLOC(MTYPE_EVPN_REMOTE_IP
, sizeof(struct evpn_remote_ip
));
6796 ip
->macip_path_list
= list_new();
6801 static unsigned int bgp_evpn_remote_ip_hash_key_make(const void *p
)
6803 const struct evpn_remote_ip
*ip
= p
;
6804 const struct ipaddr
*addr
= &ip
->addr
;
6806 if (IS_IPADDR_V4(addr
))
6807 return jhash_1word(addr
->ipaddr_v4
.s_addr
, 0);
6809 return jhash2(addr
->ipaddr_v6
.s6_addr32
,
6810 array_size(addr
->ipaddr_v6
.s6_addr32
), 0);
6813 static bool bgp_evpn_remote_ip_hash_cmp(const void *p1
, const void *p2
)
6815 const struct evpn_remote_ip
*ip1
= p1
;
6816 const struct evpn_remote_ip
*ip2
= p2
;
6818 return !ipaddr_cmp(&ip1
->addr
, &ip2
->addr
);
6821 static void bgp_evpn_remote_ip_hash_init(struct bgpevpn
*vpn
)
6823 if (!evpn_resolve_overlay_index())
6826 vpn
->remote_ip_hash
= hash_create(bgp_evpn_remote_ip_hash_key_make
,
6827 bgp_evpn_remote_ip_hash_cmp
,
6828 "BGP EVPN remote IP hash");
6831 static void bgp_evpn_remote_ip_hash_free(struct hash_bucket
*bucket
, void *args
)
6833 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6834 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6836 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6838 list_delete(&ip
->macip_path_list
);
6840 hash_release(vpn
->remote_ip_hash
, ip
);
6841 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6844 static void bgp_evpn_remote_ip_hash_destroy(struct bgpevpn
*vpn
)
6846 if (!evpn_resolve_overlay_index() || vpn
->remote_ip_hash
== NULL
)
6849 hash_iterate(vpn
->remote_ip_hash
,
6850 (void (*)(struct hash_bucket
*, void *))bgp_evpn_remote_ip_hash_free
,
6853 hash_free(vpn
->remote_ip_hash
);
6854 vpn
->remote_ip_hash
= NULL
;
6857 /* Add a remote MAC/IP route to hash table */
6858 static void bgp_evpn_remote_ip_hash_add(struct bgpevpn
*vpn
,
6859 struct bgp_path_info
*pi
)
6861 struct evpn_remote_ip tmp
;
6862 struct evpn_remote_ip
*ip
;
6863 struct prefix_evpn
*evp
;
6865 if (!evpn_resolve_overlay_index())
6868 if (pi
->type
!= ZEBRA_ROUTE_BGP
|| pi
->sub_type
!= BGP_ROUTE_IMPORTED
6869 || !CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
))
6872 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6874 if (evp
->family
!= AF_EVPN
6875 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6876 || is_evpn_prefix_ipaddr_none(evp
))
6879 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6880 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6882 if (listnode_lookup(ip
->macip_path_list
, pi
) != NULL
)
6884 (void)listnode_add(ip
->macip_path_list
, pi
);
6888 ip
= hash_get(vpn
->remote_ip_hash
, &tmp
, bgp_evpn_remote_ip_hash_alloc
);
6889 (void)listnode_add(ip
->macip_path_list
, pi
);
6891 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6894 /* Delete a remote MAC/IP route from hash table */
6895 static void bgp_evpn_remote_ip_hash_del(struct bgpevpn
*vpn
,
6896 struct bgp_path_info
*pi
)
6898 struct evpn_remote_ip tmp
;
6899 struct evpn_remote_ip
*ip
;
6900 struct prefix_evpn
*evp
;
6902 if (!evpn_resolve_overlay_index())
6905 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
6907 if (evp
->family
!= AF_EVPN
6908 || evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
6909 || is_evpn_prefix_ipaddr_none(evp
))
6912 tmp
.addr
= evp
->prefix
.macip_addr
.ip
;
6913 ip
= hash_lookup(vpn
->remote_ip_hash
, &tmp
);
6917 listnode_delete(ip
->macip_path_list
, pi
);
6919 if (ip
->macip_path_list
->count
== 0) {
6920 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6921 hash_release(vpn
->remote_ip_hash
, ip
);
6922 list_delete(&ip
->macip_path_list
);
6923 XFREE(MTYPE_EVPN_REMOTE_IP
, ip
);
6927 static void bgp_evpn_remote_ip_hash_iterate(struct bgpevpn
*vpn
,
6928 void (*func
)(struct hash_bucket
*,
6932 if (!evpn_resolve_overlay_index())
6935 hash_iterate(vpn
->remote_ip_hash
, func
, arg
);
6938 static void show_remote_ip_entry(struct hash_bucket
*bucket
, void *args
)
6940 char buf
[INET6_ADDRSTRLEN
];
6941 struct listnode
*node
= NULL
;
6942 struct bgp_path_info
*pi
= NULL
;
6943 struct vty
*vty
= (struct vty
*)args
;
6944 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6946 vty_out(vty
, " Remote IP: %s\n",
6947 ipaddr2str(&ip
->addr
, buf
, sizeof(buf
)));
6948 vty_out(vty
, " Linked MAC/IP routes:\n");
6949 for (ALL_LIST_ELEMENTS_RO(ip
->macip_path_list
, node
, pi
))
6950 vty_out(vty
, " %pFX\n", &pi
->net
->p
);
6953 void bgp_evpn_show_remote_ip_hash(struct hash_bucket
*bucket
, void *args
)
6955 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
6956 struct vty
*vty
= (struct vty
*)args
;
6958 vty_out(vty
, "VNI: %u\n", vpn
->vni
);
6959 bgp_evpn_remote_ip_hash_iterate(
6961 (void (*)(struct hash_bucket
*, void *))show_remote_ip_entry
,
6966 static void bgp_evpn_remote_ip_hash_link_nexthop(struct hash_bucket
*bucket
,
6969 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6970 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6972 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, true);
6975 static void bgp_evpn_remote_ip_hash_unlink_nexthop(struct hash_bucket
*bucket
,
6978 struct evpn_remote_ip
*ip
= (struct evpn_remote_ip
*)bucket
->data
;
6979 struct bgpevpn
*vpn
= (struct bgpevpn
*)args
;
6981 bgp_evpn_remote_ip_process_nexthops(vpn
, &ip
->addr
, false);
6984 static unsigned int vni_svi_hash_key_make(const void *p
)
6986 const struct bgpevpn
*vpn
= p
;
6988 return jhash_1word(vpn
->svi_ifindex
, 0);
6991 static bool vni_svi_hash_cmp(const void *p1
, const void *p2
)
6993 const struct bgpevpn
*vpn1
= p1
;
6994 const struct bgpevpn
*vpn2
= p2
;
6996 return (vpn1
->svi_ifindex
== vpn2
->svi_ifindex
);
6999 static struct bgpevpn
*bgp_evpn_vni_svi_hash_lookup(struct bgp
*bgp
,
7002 struct bgpevpn
*vpn
;
7005 memset(&tmp
, 0, sizeof(tmp
));
7006 tmp
.svi_ifindex
= svi
;
7007 vpn
= hash_lookup(bgp
->vni_svi_hash
, &tmp
);
7011 static void bgp_evpn_link_to_vni_svi_hash(struct bgp
*bgp
, struct bgpevpn
*vpn
)
7013 if (vpn
->svi_ifindex
== 0)
7016 (void)hash_get(bgp
->vni_svi_hash
, vpn
, hash_alloc_intern
);
7019 static void bgp_evpn_unlink_from_vni_svi_hash(struct bgp
*bgp
,
7020 struct bgpevpn
*vpn
)
7022 if (vpn
->svi_ifindex
== 0)
7025 hash_release(bgp
->vni_svi_hash
, vpn
);
7028 void bgp_evpn_show_vni_svi_hash(struct hash_bucket
*bucket
, void *args
)
7030 struct bgpevpn
*evpn
= (struct bgpevpn
*)bucket
->data
;
7031 struct vty
*vty
= (struct vty
*)args
;
7033 vty_out(vty
, "SVI: %u VNI: %u\n", evpn
->svi_ifindex
, evpn
->vni
);
7037 * This function is called for a bgp_nexthop_cache entry when the nexthop is
7038 * gateway IP overlay index.
7039 * This function returns true if there is a remote MAC/IP route for the gateway
7040 * IP in the EVI of the nexthop SVI.
7042 bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache
*bnc
)
7044 struct bgp
*bgp_evpn
= NULL
;
7045 struct bgpevpn
*vpn
= NULL
;
7046 struct evpn_remote_ip tmp
;
7049 if (!evpn_resolve_overlay_index())
7052 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
== 0)
7055 bgp_evpn
= bgp_get_evpn();
7060 * Gateway IP is resolved by nht over SVI interface.
7061 * Use this SVI to find corresponding EVI(L2 context)
7063 vpn
= bgp_evpn_vni_svi_hash_lookup(bgp_evpn
, bnc
->nexthop
->ifindex
);
7067 if (vpn
->bgp_vrf
!= bnc
->bgp
)
7071 * Check if the gateway IP is present in the EVI remote_ip_hash table
7072 * which stores all the remote IP addresses received via MAC/IP routes
7075 memset(&tmp
, 0, sizeof(tmp
));
7078 if (p
->family
== AF_INET
) {
7079 tmp
.addr
.ipa_type
= IPADDR_V4
;
7080 memcpy(&(tmp
.addr
.ipaddr_v4
), &(p
->u
.prefix4
),
7081 sizeof(struct in_addr
));
7082 } else if (p
->family
== AF_INET6
) {
7083 tmp
.addr
.ipa_type
= IPADDR_V6
;
7084 memcpy(&(tmp
.addr
.ipaddr_v6
), &(p
->u
.prefix6
),
7085 sizeof(struct in6_addr
));
7089 if (hash_lookup(vpn
->remote_ip_hash
, &tmp
) == NULL
)
7095 /* Resolve/Unresolve nexthops when a MAC/IP route is added/deleted */
7096 static void bgp_evpn_remote_ip_process_nexthops(struct bgpevpn
*vpn
,
7097 struct ipaddr
*addr
,
7102 struct bgp_nexthop_cache
*bnc
;
7103 struct bgp_nexthop_cache_head
*tree
= NULL
;
7105 if (!vpn
->bgp_vrf
|| vpn
->svi_ifindex
== 0)
7108 memset(&p
, 0, sizeof(p
));
7110 if (addr
->ipa_type
== IPADDR_V4
) {
7113 memcpy(&(p
.u
.prefix4
), &(addr
->ipaddr_v4
),
7114 sizeof(struct in_addr
));
7115 p
.prefixlen
= IPV4_MAX_BITLEN
;
7116 } else if (addr
->ipa_type
== IPADDR_V6
) {
7118 p
.family
= AF_INET6
;
7119 memcpy(&(p
.u
.prefix6
), &(addr
->ipaddr_v6
),
7120 sizeof(struct in6_addr
));
7121 p
.prefixlen
= IPV6_MAX_BITLEN
;
7125 tree
= &vpn
->bgp_vrf
->nexthop_cache_table
[afi
];
7126 bnc
= bnc_find(tree
, &p
, 0, 0);
7128 if (!bnc
|| !bnc
->is_evpn_gwip_nexthop
)
7131 if (!bnc
->nexthop
|| bnc
->nexthop
->ifindex
!= vpn
->svi_ifindex
)
7134 if (BGP_DEBUG(nht
, NHT
))
7135 zlog_debug("%s(%u): vni %u mac/ip %s for NH %pFX",
7136 vpn
->bgp_vrf
->name_pretty
, vpn
->tenant_vrf_id
,
7137 vpn
->vni
, (resolve
? "add" : "delete"),
7141 * MAC/IP route or SVI or tenant vrf being added to EVI.
7142 * Set nexthop as valid only if it is already L3 reachable
7144 if (resolve
&& bnc
->flags
& BGP_NEXTHOP_EVPN_INCOMPLETE
) {
7145 bnc
->flags
&= ~BGP_NEXTHOP_EVPN_INCOMPLETE
;
7146 bnc
->flags
|= BGP_NEXTHOP_VALID
;
7147 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7148 evaluate_paths(bnc
);
7151 /* MAC/IP route or SVI or tenant vrf being deleted from EVI */
7152 if (!resolve
&& bnc
->flags
& BGP_NEXTHOP_VALID
) {
7153 bnc
->flags
&= ~BGP_NEXTHOP_VALID
;
7154 bnc
->flags
|= BGP_NEXTHOP_EVPN_INCOMPLETE
;
7155 bnc
->change_flags
|= BGP_NEXTHOP_MACIP_CHANGED
;
7156 evaluate_paths(bnc
);
7160 void bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket
*bucket
,
7163 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7164 struct bgp_dest
*dest
;
7165 struct bgp_path_info
*pi
;
7167 bgp_evpn_remote_ip_hash_init(vpn
);
7169 for (dest
= bgp_table_top(vpn
->ip_table
); dest
;
7170 dest
= bgp_route_next(dest
))
7171 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
7172 bgp_evpn_remote_ip_hash_add(vpn
, pi
);
7175 void bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket
*bucket
,
7178 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
7180 bgp_evpn_remote_ip_hash_destroy(vpn
);
7184 * Helper function for getting the correct label index for l3vni.
7186 * Returns the label with the l3vni of the path's label stack.
7188 * L3vni is always last label. Type5 will only
7189 * have one label, Type2 will have two.
7192 mpls_label_t
*bgp_evpn_path_info_labels_get_l3vni(mpls_label_t
*labels
,
7193 uint32_t num_labels
)
7201 return &labels
[num_labels
- 1];
7205 * Returns the l3vni of the path converted from the label stack.
7207 vni_t
bgp_evpn_path_info_get_l3vni(const struct bgp_path_info
*pi
)
7212 return label2vni(bgp_evpn_path_info_labels_get_l3vni(
7213 pi
->extra
->label
, pi
->extra
->num_labels
));
7217 * Returns true if the l3vni of any of this path doesn't match vrf's l3vni.
7219 static bool bgp_evpn_path_is_dvni(const struct bgp
*bgp_vrf
,
7220 const struct bgp_path_info
*pi
)
7224 vni
= bgp_evpn_path_info_get_l3vni(pi
);
7226 if ((vni
> 0) && (vni
!= bgp_vrf
->l3vni
))
7233 * Returns true if the l3vni of any of the mpath's doesn't match vrf's l3vni.
7235 bool bgp_evpn_mpath_has_dvni(const struct bgp
*bgp_vrf
,
7236 struct bgp_path_info
*mpinfo
)
7238 for (; mpinfo
; mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
7239 if (bgp_evpn_path_is_dvni(bgp_vrf
, mpinfo
))