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 "bgpd/bgp_attr_evpn.h"
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_table.h"
37 #include "bgpd/bgp_route.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_mplsvpn.h"
40 #include "bgpd/bgp_label.h"
41 #include "bgpd/bgp_evpn.h"
42 #include "bgpd/bgp_evpn_private.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_encap_types.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_aspath.h"
47 #include "bgpd/bgp_zebra.h"
48 #include "bgpd/bgp_nexthop.h"
51 * Definitions and external declarations.
53 extern struct zclient
*zclient
;
55 DEFINE_QOBJ_TYPE(bgpevpn
)
56 DEFINE_QOBJ_TYPE(evpnes
)
60 * Static function declarations
62 static void delete_evpn_route_entry(struct bgp
*bgp
,
63 afi_t afi
, safi_t safi
,
65 struct bgp_info
**ri
);
66 static int delete_all_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
);
72 /* compare two IPV4 VTEP IPs */
73 static int evpn_vtep_ip_cmp(const void *p1
, const void *p2
)
75 const struct in_addr
*ip1
= p1
;
76 const struct in_addr
*ip2
= p2
;
82 return (ip1
->s_addr
== ip2
->s_addr
);
86 * Make hash key for ESI.
88 static unsigned int esi_hash_keymake(void *p
)
90 struct evpnes
*pes
= p
;
91 const void *pnt
= (void *)pes
->esi
.val
;
93 return jhash(pnt
, ESI_BYTES
, 0xa5a5a55a);
99 static int esi_cmp(const void *p1
, const void *p2
)
101 const struct evpnes
*pes1
= p1
;
102 const struct evpnes
*pes2
= p2
;
104 if (pes1
== NULL
&& pes2
== NULL
)
107 if (pes1
== NULL
|| pes2
== NULL
)
110 return (memcmp(pes1
->esi
.val
, pes2
->esi
.val
, ESI_BYTES
) == 0);
116 static unsigned int vni_hash_key_make(void *p
)
118 struct bgpevpn
*vpn
= p
;
119 return (jhash_1word(vpn
->vni
, 0));
123 * Comparison function for vni hash
125 static int vni_hash_cmp(const void *p1
, const void *p2
)
127 const struct bgpevpn
*vpn1
= p1
;
128 const struct bgpevpn
*vpn2
= p2
;
134 return (vpn1
->vni
== vpn2
->vni
);
138 * Make vrf import route target hash key.
140 static unsigned int vrf_import_rt_hash_key_make(void *p
)
142 struct vrf_irt_node
*irt
= p
;
143 char *pnt
= irt
->rt
.val
;
145 return jhash(pnt
, 8, 0x5abc1234);
149 * Comparison function for vrf import rt hash
151 static int vrf_import_rt_hash_cmp(const void *p1
, const void *p2
)
153 const struct vrf_irt_node
*irt1
= p1
;
154 const struct vrf_irt_node
*irt2
= p2
;
156 if (irt1
== NULL
&& irt2
== NULL
)
159 if (irt1
== NULL
|| irt2
== NULL
)
162 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
166 * Create a new vrf import_rt in default instance
168 static struct vrf_irt_node
*vrf_import_rt_new(struct ecommunity_val
*rt
)
170 struct bgp
*bgp_def
= NULL
;
171 struct vrf_irt_node
*irt
;
173 bgp_def
= bgp_get_default();
175 zlog_err("vrf import rt new - def instance not created yet");
179 irt
= XCALLOC(MTYPE_BGP_EVPN_VRF_IMPORT_RT
,
180 sizeof(struct vrf_irt_node
));
185 irt
->vrfs
= list_new();
188 if (!hash_get(bgp_def
->vrf_import_rt_hash
, irt
, hash_alloc_intern
)) {
189 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
197 * Free the vrf import rt node
199 static void vrf_import_rt_free(struct vrf_irt_node
*irt
)
201 struct bgp
*bgp_def
= NULL
;
203 bgp_def
= bgp_get_default();
205 zlog_err("vrf import rt free - def instance not created yet");
209 hash_release(bgp_def
->vrf_import_rt_hash
, irt
);
210 list_delete_and_null(&irt
->vrfs
);
211 XFREE(MTYPE_BGP_EVPN_VRF_IMPORT_RT
, irt
);
215 * Function to lookup Import RT node - used to map a RT to set of
216 * VNIs importing routes with that RT.
218 static struct vrf_irt_node
*lookup_vrf_import_rt(struct ecommunity_val
*rt
)
220 struct bgp
*bgp_def
= NULL
;
221 struct vrf_irt_node
*irt
;
222 struct vrf_irt_node tmp
;
224 bgp_def
= bgp_get_default();
226 zlog_err("vrf import rt lookup - def instance not created yet");
230 memset(&tmp
, 0, sizeof(struct vrf_irt_node
));
231 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
232 irt
= hash_lookup(bgp_def
->vrf_import_rt_hash
, &tmp
);
237 * Is specified VRF present on the RT's list of "importing" VRFs?
239 static int is_vrf_present_in_irt_vrfs(struct list
*vrfs
, struct bgp
*bgp_vrf
)
241 struct listnode
*node
= NULL
, *nnode
= NULL
;
242 struct bgp
*tmp_bgp_vrf
= NULL
;
244 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, tmp_bgp_vrf
)) {
245 if (tmp_bgp_vrf
== bgp_vrf
)
252 * Make import route target hash key.
254 static unsigned int import_rt_hash_key_make(void *p
)
256 struct irt_node
*irt
= p
;
257 char *pnt
= irt
->rt
.val
;
259 return jhash(pnt
, 8, 0xdeadbeef);
263 * Comparison function for import rt hash
265 static int import_rt_hash_cmp(const void *p1
, const void *p2
)
267 const struct irt_node
*irt1
= p1
;
268 const struct irt_node
*irt2
= p2
;
270 if (irt1
== NULL
&& irt2
== NULL
)
273 if (irt1
== NULL
|| irt2
== NULL
)
276 return (memcmp(irt1
->rt
.val
, irt2
->rt
.val
, ECOMMUNITY_SIZE
) == 0);
280 * Create a new import_rt
282 static struct irt_node
*import_rt_new(struct bgp
*bgp
,
283 struct ecommunity_val
*rt
)
285 struct irt_node
*irt
;
290 irt
= XCALLOC(MTYPE_BGP_EVPN_IMPORT_RT
, sizeof(struct irt_node
));
295 irt
->vnis
= list_new();
298 if (!hash_get(bgp
->import_rt_hash
, irt
, hash_alloc_intern
)) {
299 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
307 * Free the import rt node
309 static void import_rt_free(struct bgp
*bgp
, struct irt_node
*irt
)
311 hash_release(bgp
->import_rt_hash
, irt
);
312 list_delete_and_null(&irt
->vnis
);
313 XFREE(MTYPE_BGP_EVPN_IMPORT_RT
, irt
);
317 * Function to lookup Import RT node - used to map a RT to set of
318 * VNIs importing routes with that RT.
320 static struct irt_node
*lookup_import_rt(struct bgp
*bgp
,
321 struct ecommunity_val
*rt
)
323 struct irt_node
*irt
;
326 memset(&tmp
, 0, sizeof(struct irt_node
));
327 memcpy(&tmp
.rt
, rt
, ECOMMUNITY_SIZE
);
328 irt
= hash_lookup(bgp
->import_rt_hash
, &tmp
);
333 * Is specified VNI present on the RT's list of "importing" VNIs?
335 static int is_vni_present_in_irt_vnis(struct list
*vnis
, struct bgpevpn
*vpn
)
337 struct listnode
*node
, *nnode
;
338 struct bgpevpn
*tmp_vpn
;
340 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, tmp_vpn
)) {
349 * Compare Route Targets.
351 static int evpn_route_target_cmp(struct ecommunity
*ecom1
,
352 struct ecommunity
*ecom2
)
360 if (!ecom1
&& !ecom2
)
363 if (ecom1
->str
&& !ecom2
->str
)
366 if (!ecom1
->str
&& ecom2
->str
)
369 if (!ecom1
->str
&& !ecom2
->str
)
372 return strcmp(ecom1
->str
, ecom2
->str
);
375 static void evpn_xxport_delete_ecomm(void *val
)
377 struct ecommunity
*ecomm
= val
;
378 ecommunity_free(&ecomm
);
382 * Mask off global-admin field of specified extended community (RT),
383 * just retain the local-admin field.
385 static inline void mask_ecom_global_admin(struct ecommunity_val
*dst
,
386 struct ecommunity_val
*src
)
392 if (type
== ECOMMUNITY_ENCODE_AS
) {
393 dst
->val
[2] = dst
->val
[3] = 0;
394 } else if (type
== ECOMMUNITY_ENCODE_AS4
395 || type
== ECOMMUNITY_ENCODE_IP
) {
396 dst
->val
[2] = dst
->val
[3] = 0;
397 dst
->val
[4] = dst
->val
[5] = 0;
402 * Map one RT to specified VRF.
403 * bgp_vrf = BGP vrf instance
405 static void map_vrf_to_rt(struct bgp
*bgp_vrf
, struct ecommunity_val
*eval
)
407 struct vrf_irt_node
*irt
= NULL
;
408 struct ecommunity_val eval_tmp
;
410 /* If using "automatic" RT,
411 * we only care about the local-admin sub-field.
412 * This is to facilitate using L3VNI(VRF-VNI)
413 * as the RT for EBGP peering too.
415 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
416 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
417 mask_ecom_global_admin(&eval_tmp
, eval
);
419 irt
= lookup_vrf_import_rt(&eval_tmp
);
420 if (irt
&& is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
421 /* Already mapped. */
425 irt
= vrf_import_rt_new(&eval_tmp
);
427 /* Add VRF to the list for this RT. */
428 listnode_add(irt
->vrfs
, bgp_vrf
);
432 * Unmap specified VRF from specified RT. If there are no other
433 * VRFs for this RT, then the RT hash is deleted.
434 * bgp_vrf: BGP VRF specific instance
436 static void unmap_vrf_from_rt(struct bgp
*bgp_vrf
, struct vrf_irt_node
*irt
)
438 /* Delete VRF from list for this RT. */
439 listnode_delete(irt
->vrfs
, bgp_vrf
);
440 if (!listnode_head(irt
->vrfs
)) {
441 vrf_import_rt_free(irt
);
446 * Map one RT to specified VNI.
448 static void map_vni_to_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
449 struct ecommunity_val
*eval
)
451 struct irt_node
*irt
;
452 struct ecommunity_val eval_tmp
;
454 /* If using "automatic" RT, we only care about the local-admin
456 * This is to facilitate using VNI as the RT for EBGP peering too.
458 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
459 if (!is_import_rt_configured(vpn
))
460 mask_ecom_global_admin(&eval_tmp
, eval
);
462 irt
= lookup_import_rt(bgp
, &eval_tmp
);
464 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
465 /* Already mapped. */
469 irt
= import_rt_new(bgp
, &eval_tmp
);
473 /* Add VNI to the hash list for this RT. */
474 listnode_add(irt
->vnis
, vpn
);
478 * Unmap specified VNI from specified RT. If there are no other
479 * VNIs for this RT, then the RT hash is deleted.
481 static void unmap_vni_from_rt(struct bgp
*bgp
, struct bgpevpn
*vpn
,
482 struct irt_node
*irt
)
484 /* Delete VNI from hash list for this RT. */
485 listnode_delete(irt
->vnis
, vpn
);
486 if (!listnode_head(irt
->vnis
)) {
487 import_rt_free(bgp
, irt
);
492 * Create RT extended community automatically from passed information:
493 * of the form AS:VNI.
494 * NOTE: We use only the lower 16 bits of the AS. This is sufficient as
495 * the need is to get a RT value that will be unique across different
496 * VNIs but the same across routers (in the same AS) for a particular
499 static void form_auto_rt(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
)
501 struct ecommunity_val eval
;
502 struct ecommunity
*ecomadd
;
504 if (bgp
->advertise_autort_rfc8365
)
505 vni
|= EVPN_AUTORT_VXLAN
;
506 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
);
508 ecomadd
= ecommunity_new();
509 ecommunity_add_val(ecomadd
, &eval
);
510 listnode_add_sort(rtl
, ecomadd
);
514 * Derive RD and RT for a VNI automatically. Invoked at the time of
517 static void derive_rd_rt_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
519 bgp_evpn_derive_auto_rd(bgp
, vpn
);
520 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
521 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
525 * Convert nexthop (remote VTEP IP) into an IPv6 address.
527 static void evpn_convert_nexthop_to_ipv6(struct attr
*attr
)
529 if (BGP_ATTR_NEXTHOP_AFI_IP6(attr
))
531 ipv4_to_ipv4_mapped_ipv6(&attr
->mp_nexthop_global
, attr
->nexthop
);
532 attr
->mp_nexthop_len
= IPV6_MAX_BYTELEN
;
536 * Add (update) or delete MACIP from zebra.
538 static int bgp_zebra_send_remote_macip(struct bgp
*bgp
, struct bgpevpn
*vpn
,
539 struct prefix_evpn
*p
,
540 struct in_addr remote_vtep_ip
, int add
,
545 char buf1
[ETHER_ADDR_STRLEN
];
546 char buf2
[INET6_ADDRSTRLEN
];
547 char buf3
[INET6_ADDRSTRLEN
];
550 if (!zclient
|| zclient
->sock
< 0)
553 /* Don't try to register if Zebra doesn't know of this instance. */
554 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
560 zclient_create_header(
561 s
, add
? ZEBRA_REMOTE_MACIP_ADD
: ZEBRA_REMOTE_MACIP_DEL
,
563 stream_putl(s
, vpn
->vni
);
564 stream_put(s
, &p
->prefix
.macip_addr
.mac
.octet
, ETH_ALEN
); /* Mac Addr */
565 /* IP address length and IP address, if any. */
566 if (is_evpn_prefix_ipaddr_none(p
))
569 ipa_len
= is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BYTELEN
571 stream_putl(s
, ipa_len
);
572 stream_put(s
, &p
->prefix
.macip_addr
.ip
.ip
.addr
, ipa_len
);
574 stream_put_in_addr(s
, &remote_vtep_ip
);
576 /* TX flags - MAC sticky status and/or gateway mac */
578 stream_putc(s
, flags
);
580 stream_putw_at(s
, 0, stream_get_endp(s
));
582 if (bgp_debug_zebra(NULL
))
584 "Tx %s MACIP, VNI %u MAC %s IP %s (flags: 0x%x) remote VTEP %s",
585 add
? "ADD" : "DEL", vpn
->vni
,
586 prefix_mac2str(&p
->prefix
.macip_addr
.mac
,
588 ipaddr2str(&p
->prefix
.macip_addr
.ip
,
589 buf3
, sizeof(buf3
)), flags
,
590 inet_ntop(AF_INET
, &remote_vtep_ip
, buf2
,
593 return zclient_send_message(zclient
);
597 * Add (update) or delete remote VTEP from zebra.
599 static int bgp_zebra_send_remote_vtep(struct bgp
*bgp
, struct bgpevpn
*vpn
,
600 struct prefix_evpn
*p
, int add
)
605 if (!zclient
|| zclient
->sock
< 0)
608 /* Don't try to register if Zebra doesn't know of this instance. */
609 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
))
615 zclient_create_header(
616 s
, add
? ZEBRA_REMOTE_VTEP_ADD
: ZEBRA_REMOTE_VTEP_DEL
,
618 stream_putl(s
, vpn
->vni
);
619 if (is_evpn_prefix_ipaddr_v4(p
))
620 stream_put_in_addr(s
, &p
->prefix
.imet_addr
.ip
.ipaddr_v4
);
621 else if (is_evpn_prefix_ipaddr_v6(p
)) {
623 "Bad remote IP when trying to %s remote VTEP for VNI %u",
624 add
? "ADD" : "DEL", vpn
->vni
);
628 stream_putw_at(s
, 0, stream_get_endp(s
));
630 if (bgp_debug_zebra(NULL
))
631 zlog_debug("Tx %s Remote VTEP, VNI %u remote VTEP %s",
632 add
? "ADD" : "DEL", vpn
->vni
,
633 inet_ntoa(p
->prefix
.imet_addr
.ip
.ipaddr_v4
));
635 return zclient_send_message(zclient
);
639 * Build extended community for EVPN ES (type-4) route
641 static void build_evpn_type4_route_extcomm(struct evpnes
*es
,
644 struct ecommunity ecom_encap
;
645 struct ecommunity ecom_es_rt
;
646 struct ecommunity_val eval
;
647 struct ecommunity_val eval_es_rt
;
648 bgp_encap_types tnl_type
;
652 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
653 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
654 encode_encap_extcomm(tnl_type
, &eval
);
656 ecom_encap
.val
= (uint8_t *)eval
.val
;
657 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
660 memset(&mac
, 0, sizeof(struct ethaddr
));
661 memset(&ecom_es_rt
, 0, sizeof(ecom_es_rt
));
662 es_get_system_mac(&es
->esi
, &mac
);
663 encode_es_rt_extcomm(&eval_es_rt
, &mac
);
665 ecom_es_rt
.val
= (uint8_t *)eval_es_rt
.val
;
667 ecommunity_merge(attr
->ecommunity
, &ecom_es_rt
);
669 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
673 * Build extended communities for EVPN prefix route.
675 static void build_evpn_type5_route_extcomm(struct bgp
*bgp_vrf
,
678 struct ecommunity ecom_encap
;
679 struct ecommunity ecom_rmac
;
680 struct ecommunity_val eval
;
681 struct ecommunity_val eval_rmac
;
682 bgp_encap_types tnl_type
;
683 struct listnode
*node
, *nnode
;
684 struct ecommunity
*ecom
;
685 struct list
*vrf_export_rtl
= NULL
;
688 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
689 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
690 encode_encap_extcomm(tnl_type
, &eval
);
692 ecom_encap
.val
= (uint8_t *)eval
.val
;
695 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
697 /* Add the export RTs for L3VNI/VRF */
698 vrf_export_rtl
= bgp_vrf
->vrf_export_rtl
;
699 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
, ecom
))
701 ecommunity_merge(attr
->ecommunity
, ecom
);
703 /* add the router mac extended community */
704 if (!is_zero_mac(&attr
->rmac
)) {
705 memset(&ecom_rmac
, 0, sizeof(ecom_rmac
));
706 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
708 ecom_rmac
.val
= (uint8_t *)eval_rmac
.val
;
710 ecommunity_merge(attr
->ecommunity
, &ecom_rmac
);
713 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
717 * Build extended communities for EVPN route.
718 * This function is applicable for type-2 and type-3 routes. The layer-2 RT
719 * and ENCAP extended communities are applicable for all routes.
720 * The default gateway extended community and MAC mobility (sticky) extended
721 * community are added as needed based on passed settings - only for type-2
722 * routes. Likewise, the layer-3 RT and Router MAC extended communities are
723 * added, if present, based on passed settings - only for non-link-local
726 static void build_evpn_route_extcomm(struct bgpevpn
*vpn
, struct attr
*attr
,
729 struct ecommunity ecom_encap
;
730 struct ecommunity ecom_sticky
;
731 struct ecommunity ecom_default_gw
;
732 struct ecommunity ecom_rmac
;
733 struct ecommunity_val eval
;
734 struct ecommunity_val eval_sticky
;
735 struct ecommunity_val eval_default_gw
;
736 struct ecommunity_val eval_rmac
;
737 bgp_encap_types tnl_type
;
738 struct listnode
*node
, *nnode
;
739 struct ecommunity
*ecom
;
741 struct list
*vrf_export_rtl
= NULL
;
744 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
745 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
746 encode_encap_extcomm(tnl_type
, &eval
);
748 ecom_encap
.val
= (uint8_t *)eval
.val
;
751 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
753 /* Add the export RTs for L2VNI */
754 for (ALL_LIST_ELEMENTS(vpn
->export_rtl
, node
, nnode
, ecom
))
755 attr
->ecommunity
= ecommunity_merge(attr
->ecommunity
, ecom
);
757 /* Add the export RTs for L3VNI if told to - caller determines
758 * when this should be done.
761 vrf_export_rtl
= bgpevpn_get_vrf_export_rtl(vpn
);
762 if (vrf_export_rtl
&& !list_isempty(vrf_export_rtl
)) {
763 for (ALL_LIST_ELEMENTS(vrf_export_rtl
, node
, nnode
,
765 attr
->ecommunity
= ecommunity_merge(
766 attr
->ecommunity
, ecom
);
770 /* Add MAC mobility (sticky) if needed. */
773 memset(&ecom_sticky
, 0, sizeof(ecom_sticky
));
774 encode_mac_mobility_extcomm(1, seqnum
, &eval_sticky
);
775 ecom_sticky
.size
= 1;
776 ecom_sticky
.val
= (uint8_t *)eval_sticky
.val
;
778 ecommunity_merge(attr
->ecommunity
, &ecom_sticky
);
781 /* Add RMAC, if told to. */
783 memset(&ecom_rmac
, 0, sizeof(ecom_rmac
));
784 encode_rmac_extcomm(&eval_rmac
, &attr
->rmac
);
786 ecom_rmac
.val
= (uint8_t *)eval_rmac
.val
;
788 ecommunity_merge(attr
->ecommunity
, &ecom_rmac
);
791 /* Add default gateway, if needed. */
792 if (attr
->default_gw
) {
793 memset(&ecom_default_gw
, 0, sizeof(ecom_default_gw
));
794 encode_default_gw_extcomm(&eval_default_gw
);
795 ecom_default_gw
.size
= 1;
796 ecom_default_gw
.val
= (uint8_t *)eval_default_gw
.val
;
798 ecommunity_merge(attr
->ecommunity
, &ecom_default_gw
);
801 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
805 * Add MAC mobility extended community to attribute.
807 static void add_mac_mobility_to_attr(uint32_t seq_num
, struct attr
*attr
)
809 struct ecommunity ecom_tmp
;
810 struct ecommunity_val eval
;
811 uint8_t *ecom_val_ptr
;
818 encode_mac_mobility_extcomm(0, seq_num
, &eval
);
820 /* Find current MM ecommunity */
823 if (attr
->ecommunity
) {
824 for (i
= 0; i
< attr
->ecommunity
->size
; i
++) {
825 pnt
= attr
->ecommunity
->val
+ (i
* 8);
829 if (type
== ECOMMUNITY_ENCODE_EVPN
831 == ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY
) {
832 ecom_val_ptr
= (uint8_t *)(attr
->ecommunity
->val
839 /* Update the existing MM ecommunity */
841 memcpy(ecom_val_ptr
, eval
.val
, sizeof(char) * ECOMMUNITY_SIZE
);
843 /* Add MM to existing */
845 memset(&ecom_tmp
, 0, sizeof(ecom_tmp
));
847 ecom_tmp
.val
= (uint8_t *)eval
.val
;
849 if (attr
->ecommunity
)
851 ecommunity_merge(attr
->ecommunity
, &ecom_tmp
);
853 attr
->ecommunity
= ecommunity_dup(&ecom_tmp
);
857 /* Install EVPN route into zebra. */
858 static int evpn_zebra_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
859 struct prefix_evpn
*p
,
860 struct in_addr remote_vtep_ip
, uint8_t flags
)
864 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
865 ret
= bgp_zebra_send_remote_macip(bgp
, vpn
, p
, remote_vtep_ip
,
868 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
, 1);
873 /* Uninstall EVPN route from zebra. */
874 static int evpn_zebra_uninstall(struct bgp
*bgp
, struct bgpevpn
*vpn
,
875 struct prefix_evpn
*p
,
876 struct in_addr remote_vtep_ip
)
880 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
881 ret
= bgp_zebra_send_remote_macip(bgp
, vpn
, p
, remote_vtep_ip
,
884 ret
= bgp_zebra_send_remote_vtep(bgp
, vpn
, p
, 0);
890 * Due to MAC mobility, the prior "local" best route has been supplanted
891 * by a "remote" best route. The prior route has to be deleted and withdrawn
894 static void evpn_delete_old_local_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
896 struct bgp_info
*old_local
)
898 struct bgp_node
*global_rn
;
900 afi_t afi
= AFI_L2VPN
;
901 safi_t safi
= SAFI_EVPN
;
903 /* Locate route node in the global EVPN routing table. Note that
904 * this table is a 2-level tree (RD-level + Prefix-level) similar to
907 global_rn
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
908 (struct prefix
*)&rn
->p
, &vpn
->prd
);
910 /* Delete route entry in the global EVPN table. */
911 delete_evpn_route_entry(bgp
, afi
, safi
, global_rn
, &ri
);
913 /* Schedule for processing - withdraws to peers happen from
917 bgp_process(bgp
, global_rn
, afi
, safi
);
918 bgp_unlock_node(global_rn
);
921 /* Delete route entry in the VNI route table, caller to remove. */
922 bgp_info_delete(rn
, old_local
);
925 static struct in_addr
*es_vtep_new(struct in_addr vtep
)
929 ip
= XCALLOC(MTYPE_BGP_EVPN_ES_VTEP
, sizeof(struct in_addr
));
933 ip
->s_addr
= vtep
.s_addr
;
937 static void es_vtep_free(struct in_addr
*ip
)
939 XFREE(MTYPE_BGP_EVPN_ES_VTEP
, ip
);
942 /* check if VTEP is already part of the list */
943 static int is_vtep_present_in_list(struct list
*list
,
946 struct listnode
*node
= NULL
;
949 for (ALL_LIST_ELEMENTS_RO(list
, node
, tmp
)) {
950 if (tmp
->s_addr
== vtep
.s_addr
)
957 * Best path for ES route was changed,
958 * update the list of VTEPs for this ES
960 static int evpn_es_install_vtep(struct bgp
*bgp
,
962 struct prefix_evpn
*p
,
963 struct in_addr rvtep
)
965 struct in_addr
*vtep_ip
;
967 if (is_vtep_present_in_list(es
->vtep_list
, rvtep
))
971 vtep_ip
= es_vtep_new(rvtep
);
973 listnode_add_sort(es
->vtep_list
, vtep_ip
);
978 * Best path for ES route was changed,
979 * update the list of VTEPs for this ES
981 static int evpn_es_uninstall_vtep(struct bgp
*bgp
,
983 struct prefix_evpn
*p
,
984 struct in_addr rvtep
)
986 struct listnode
*node
, *nnode
, *node_to_del
= NULL
;
989 for (ALL_LIST_ELEMENTS(es
->vtep_list
, node
, nnode
, tmp
)) {
990 if (tmp
->s_addr
== rvtep
.s_addr
) {
997 list_delete_node(es
->vtep_list
, node_to_del
);
1003 * Calculate the best path for a ES(type-4) route.
1005 static int evpn_es_route_select_install(struct bgp
*bgp
,
1007 struct bgp_node
*rn
)
1010 afi_t afi
= AFI_L2VPN
;
1011 safi_t safi
= SAFI_EVPN
;
1012 struct bgp_info
*old_select
; /* old best */
1013 struct bgp_info
*new_select
; /* new best */
1014 struct bgp_info_pair old_and_new
;
1016 /* Compute the best path. */
1017 bgp_best_selection(bgp
, rn
, &bgp
->maxpaths
[afi
][safi
],
1018 &old_and_new
, afi
, safi
);
1019 old_select
= old_and_new
.old
;
1020 new_select
= old_and_new
.new;
1023 * If the best path hasn't changed - see if something needs to be
1026 if (old_select
&& old_select
== new_select
1027 && old_select
->type
== ZEBRA_ROUTE_BGP
1028 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
1029 && !CHECK_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
)
1030 && !CHECK_FLAG(old_select
->flags
, BGP_INFO_ATTR_CHANGED
)
1031 && !bgp
->addpath_tx_used
[afi
][safi
]) {
1032 if (bgp_zebra_has_route_changed(rn
, old_select
)) {
1033 ret
= evpn_es_install_vtep(bgp
, es
,
1034 (struct prefix_evpn
*)&rn
->p
,
1035 old_select
->attr
->nexthop
);
1037 UNSET_FLAG(old_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
1038 bgp_zebra_clear_route_change_flags(rn
);
1042 /* If the user did a "clear" this flag will be set */
1043 UNSET_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
);
1046 * bestpath has changed; update relevant fields and install or uninstall
1047 * into the zebra RIB.
1049 if (old_select
|| new_select
)
1050 bgp_bump_version(rn
);
1053 bgp_info_unset_flag(rn
, old_select
, BGP_INFO_SELECTED
);
1055 bgp_info_set_flag(rn
, new_select
, BGP_INFO_SELECTED
);
1056 bgp_info_unset_flag(rn
, new_select
, BGP_INFO_ATTR_CHANGED
);
1057 UNSET_FLAG(new_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
1060 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
1061 && new_select
->sub_type
== BGP_ROUTE_IMPORTED
) {
1062 ret
= evpn_es_install_vtep(bgp
, es
,
1063 (struct prefix_evpn
*)&rn
->p
,
1064 new_select
->attr
->nexthop
);
1066 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
1067 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
1068 ret
= evpn_es_uninstall_vtep(
1069 bgp
, es
, (struct prefix_evpn
*)&rn
->p
,
1070 old_select
->attr
->nexthop
);
1073 /* Clear any route change flags. */
1074 bgp_zebra_clear_route_change_flags(rn
);
1076 /* Reap old select bgp_info, if it has been removed */
1077 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_INFO_REMOVED
))
1078 bgp_info_reap(rn
, old_select
);
1084 * Calculate the best path for an EVPN route. Install/update best path in zebra,
1087 static int evpn_route_select_install(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1088 struct bgp_node
*rn
)
1090 struct bgp_info
*old_select
, *new_select
;
1091 struct bgp_info_pair old_and_new
;
1092 afi_t afi
= AFI_L2VPN
;
1093 safi_t safi
= SAFI_EVPN
;
1097 /* Compute the best path. */
1098 bgp_best_selection(bgp
, rn
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
1100 old_select
= old_and_new
.old
;
1101 new_select
= old_and_new
.new;
1103 /* If the best path hasn't changed - see if there is still something to
1107 if (old_select
&& old_select
== new_select
1108 && old_select
->type
== ZEBRA_ROUTE_BGP
1109 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
1110 && !CHECK_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
)
1111 && !CHECK_FLAG(old_select
->flags
, BGP_INFO_ATTR_CHANGED
)
1112 && !bgp
->addpath_tx_used
[afi
][safi
]) {
1113 if (bgp_zebra_has_route_changed(rn
, old_select
)) {
1114 if (old_select
->attr
->sticky
)
1115 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1116 if (old_select
->attr
->default_gw
)
1117 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1118 ret
= evpn_zebra_install(
1119 bgp
, vpn
, (struct prefix_evpn
*)&rn
->p
,
1120 old_select
->attr
->nexthop
, flags
);
1122 UNSET_FLAG(old_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
1123 bgp_zebra_clear_route_change_flags(rn
);
1127 /* If the user did a "clear" this flag will be set */
1128 UNSET_FLAG(rn
->flags
, BGP_NODE_USER_CLEAR
);
1130 /* bestpath has changed; update relevant fields and install or uninstall
1131 * into the zebra RIB.
1133 if (old_select
|| new_select
)
1134 bgp_bump_version(rn
);
1137 bgp_info_unset_flag(rn
, old_select
, BGP_INFO_SELECTED
);
1139 bgp_info_set_flag(rn
, new_select
, BGP_INFO_SELECTED
);
1140 bgp_info_unset_flag(rn
, new_select
, BGP_INFO_ATTR_CHANGED
);
1141 UNSET_FLAG(new_select
->flags
, BGP_INFO_MULTIPATH_CHG
);
1144 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
1145 && new_select
->sub_type
== BGP_ROUTE_IMPORTED
) {
1147 if (new_select
->attr
->sticky
)
1148 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
1149 if (new_select
->attr
->default_gw
)
1150 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1151 ret
= evpn_zebra_install(bgp
, vpn
, (struct prefix_evpn
*)&rn
->p
,
1152 new_select
->attr
->nexthop
, flags
);
1153 /* If an old best existed and it was a "local" route, the only
1155 * it would be supplanted is due to MAC mobility procedures. So,
1157 * need to do an implicit delete and withdraw that route from
1160 if (old_select
&& old_select
->peer
== bgp
->peer_self
1161 && old_select
->type
== ZEBRA_ROUTE_BGP
1162 && old_select
->sub_type
== BGP_ROUTE_STATIC
)
1163 evpn_delete_old_local_route(bgp
, vpn
, rn
, old_select
);
1165 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
1166 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
1167 ret
= evpn_zebra_uninstall(bgp
, vpn
,
1168 (struct prefix_evpn
*)&rn
->p
,
1169 old_select
->attr
->nexthop
);
1172 /* Clear any route change flags. */
1173 bgp_zebra_clear_route_change_flags(rn
);
1175 /* Reap old select bgp_info, if it has been removed */
1176 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_INFO_REMOVED
))
1177 bgp_info_reap(rn
, old_select
);
1183 * Return true if the local ri for this rn is of type gateway mac
1185 static int evpn_route_is_def_gw(struct bgp
*bgp
, struct bgp_node
*rn
)
1187 struct bgp_info
*tmp_ri
= NULL
;
1188 struct bgp_info
*local_ri
= NULL
;
1191 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
) {
1192 if (tmp_ri
->peer
== bgp
->peer_self
1193 && tmp_ri
->type
== ZEBRA_ROUTE_BGP
1194 && tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1201 return local_ri
->attr
->default_gw
;
1206 * Return true if the local ri for this rn has sticky set
1208 static int evpn_route_is_sticky(struct bgp
*bgp
, struct bgp_node
*rn
)
1210 struct bgp_info
*tmp_ri
;
1211 struct bgp_info
*local_ri
;
1214 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
) {
1215 if (tmp_ri
->peer
== bgp
->peer_self
1216 && tmp_ri
->type
== ZEBRA_ROUTE_BGP
1217 && tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1224 return local_ri
->attr
->sticky
;
1228 * create or update EVPN type4 route entry.
1229 * This could be in the ES table or the global table.
1230 * TODO: handle remote ES (type4) routes as well
1232 static int update_evpn_type4_route_entry(struct bgp
*bgp
,
1234 afi_t afi
, safi_t safi
,
1235 struct bgp_node
*rn
,
1238 struct bgp_info
**ri
,
1241 char buf
[ESI_STR_LEN
];
1242 char buf1
[INET6_ADDRSTRLEN
];
1243 struct bgp_info
*tmp_ri
= NULL
;
1244 struct bgp_info
*local_ri
= NULL
; /* local route entry if any */
1245 struct bgp_info
*remote_ri
= NULL
; /* remote route entry if any */
1246 struct attr
*attr_new
= NULL
;
1247 struct prefix_evpn
*evp
= NULL
;
1251 evp
= (struct prefix_evpn
*)&rn
->p
;
1253 /* locate the local and remote entries if any */
1254 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
) {
1255 if (tmp_ri
->peer
== bgp
->peer_self
&&
1256 tmp_ri
->type
== ZEBRA_ROUTE_BGP
&&
1257 tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1259 if (tmp_ri
->type
== ZEBRA_ROUTE_BGP
&&
1260 tmp_ri
->sub_type
== BGP_ROUTE_IMPORTED
&&
1261 CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_VALID
))
1265 /* we don't expect to see a remote_ri at this point.
1266 * An ES route has esi + vtep_ip as the key,
1267 * We shouldn't see the same route from any other vtep.
1271 "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
1273 esi_to_str(&evp
->prefix
.es_addr
.esi
, buf
, sizeof(buf
)),
1274 ipaddr2str(&es
->originator_ip
, buf1
, sizeof(buf1
)));
1278 if (!local_ri
&& !add
)
1281 /* create or update the entry */
1284 /* Add or update attribute to hash */
1285 attr_new
= bgp_attr_intern(attr
);
1287 /* Create new route with its attribute. */
1288 tmp_ri
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
,
1289 0, bgp
->peer_self
, attr_new
, rn
);
1290 SET_FLAG(tmp_ri
->flags
, BGP_INFO_VALID
);
1292 /* add the newly created path to the route-node */
1293 bgp_info_add(rn
, tmp_ri
);
1296 if (attrhash_cmp(tmp_ri
->attr
, attr
)
1297 && !CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_REMOVED
))
1300 /* The attribute has changed.
1301 * Add (or update) attribute to hash. */
1302 attr_new
= bgp_attr_intern(attr
);
1303 bgp_info_set_flag(rn
, tmp_ri
, BGP_INFO_ATTR_CHANGED
);
1305 /* Restore route, if needed. */
1306 if (CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_REMOVED
))
1307 bgp_info_restore(rn
, tmp_ri
);
1309 /* Unintern existing, set to new. */
1310 bgp_attr_unintern(&tmp_ri
->attr
);
1311 tmp_ri
->attr
= attr_new
;
1312 tmp_ri
->uptime
= bgp_clock();
1316 /* Return back the route entry. */
1321 /* update evpn es (type-4) route */
1322 static int update_evpn_type4_route(struct bgp
*bgp
,
1324 struct prefix_evpn
*p
)
1327 int route_changed
= 0;
1328 char buf
[ESI_STR_LEN
];
1329 char buf1
[INET6_ADDRSTRLEN
];
1330 afi_t afi
= AFI_L2VPN
;
1331 safi_t safi
= SAFI_EVPN
;
1333 struct attr
*attr_new
= NULL
;
1334 struct bgp_node
*rn
= NULL
;
1335 struct bgp_info
*ri
= NULL
;
1337 memset(&attr
, 0, sizeof(struct attr
));
1339 /* Build path-attribute for this route. */
1340 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
1341 attr
.nexthop
= es
->originator_ip
.ipaddr_v4
;
1342 attr
.mp_nexthop_global_in
= es
->originator_ip
.ipaddr_v4
;
1343 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1345 /* Set up extended community. */
1346 build_evpn_type4_route_extcomm(es
, &attr
);
1348 /* First, create (or fetch) route node within the ESI. */
1349 /* NOTE: There is no RD here. */
1350 rn
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
1352 /* Create or update route entry. */
1353 ret
= update_evpn_type4_route_entry(bgp
, es
, afi
, safi
, rn
,
1357 zlog_err("%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
1359 esi_to_str(&p
->prefix
.es_addr
.esi
, buf
, sizeof(buf
)),
1360 ipaddr2str(&es
->originator_ip
, buf1
, sizeof(buf1
)));
1364 attr_new
= ri
->attr
;
1366 /* Perform route selection;
1367 * this is just to set the flags correctly
1368 * as local route in the ES always wins.
1370 evpn_es_route_select_install(bgp
, es
, rn
);
1371 bgp_unlock_node(rn
);
1373 /* If this is a new route or some attribute has changed, export the
1374 * route to the global table. The route will be advertised to peers
1375 * from there. Note that this table is a 2-level tree (RD-level +
1376 * Prefix-level) similar to L3VPN routes.
1378 if (route_changed
) {
1379 struct bgp_info
*global_ri
;
1381 rn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
1382 (struct prefix
*)p
, &es
->prd
);
1383 update_evpn_type4_route_entry(bgp
, es
, afi
, safi
,
1388 /* Schedule for processing and unlock node. */
1389 bgp_process(bgp
, rn
, afi
, safi
);
1390 bgp_unlock_node(rn
);
1393 /* Unintern temporary. */
1394 aspath_unintern(&attr
.aspath
);
1398 static int update_evpn_type5_route_entry(struct bgp
*bgp_def
,
1399 struct bgp
*bgp_vrf
, afi_t afi
,
1400 safi_t safi
, struct bgp_node
*rn
,
1401 struct attr
*attr
, int *route_changed
)
1403 struct attr
*attr_new
= NULL
;
1404 struct bgp_info
*ri
= NULL
;
1405 mpls_label_t label
= MPLS_INVALID_LABEL
;
1406 struct bgp_info
*local_ri
= NULL
;
1407 struct bgp_info
*tmp_ri
= NULL
;
1410 /* locate the local route entry if any */
1411 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
) {
1412 if (tmp_ri
->peer
== bgp_def
->peer_self
1413 && tmp_ri
->type
== ZEBRA_ROUTE_BGP
1414 && tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1419 * create a new route entry if one doesnt exist.
1420 * Otherwise see if route attr has changed
1424 /* route has changed as this is the first entry */
1427 /* Add (or update) attribute to hash. */
1428 attr_new
= bgp_attr_intern(attr
);
1430 /* create the route info from attribute */
1431 ri
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1432 bgp_def
->peer_self
, attr_new
, rn
);
1433 SET_FLAG(ri
->flags
, BGP_INFO_VALID
);
1435 /* Type-5 routes advertise the L3-VNI */
1436 bgp_info_extra_get(ri
);
1437 vni2label(bgp_vrf
->l3vni
, &label
);
1438 memcpy(&ri
->extra
->label
, &label
, sizeof(label
));
1439 ri
->extra
->num_labels
= 1;
1441 /* add the route entry to route node*/
1442 bgp_info_add(rn
, ri
);
1446 if (!attrhash_cmp(tmp_ri
->attr
, attr
)) {
1448 /* attribute changed */
1451 /* The attribute has changed. */
1452 /* Add (or update) attribute to hash. */
1453 attr_new
= bgp_attr_intern(attr
);
1454 bgp_info_set_flag(rn
, tmp_ri
, BGP_INFO_ATTR_CHANGED
);
1456 /* Restore route, if needed. */
1457 if (CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_REMOVED
))
1458 bgp_info_restore(rn
, tmp_ri
);
1460 /* Unintern existing, set to new. */
1461 bgp_attr_unintern(&tmp_ri
->attr
);
1462 tmp_ri
->attr
= attr_new
;
1463 tmp_ri
->uptime
= bgp_clock();
1469 /* update evpn type-5 route entry */
1470 static int update_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
,
1471 struct attr
*src_attr
)
1473 afi_t afi
= AFI_L2VPN
;
1474 safi_t safi
= SAFI_EVPN
;
1476 struct bgp_node
*rn
= NULL
;
1477 struct bgp
*bgp_def
= NULL
;
1478 int route_changed
= 0;
1480 bgp_def
= bgp_get_default();
1484 /* Build path attribute for this route - use the source attr, if
1485 * present, else treat as locally originated.
1488 bgp_attr_dup(&attr
, src_attr
);
1490 memset(&attr
, 0, sizeof(struct attr
));
1491 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
1493 /* Set nexthop to ourselves and fill in the Router MAC. */
1494 attr
.nexthop
= bgp_vrf
->originator_ip
;
1495 attr
.mp_nexthop_global_in
= bgp_vrf
->originator_ip
;
1496 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1497 memcpy(&attr
.rmac
, &bgp_vrf
->rmac
, sizeof(struct ethaddr
));
1499 /* Setup RT and encap extended community */
1500 build_evpn_type5_route_extcomm(bgp_vrf
, &attr
);
1502 /* get the route node in global table */
1503 rn
= bgp_afi_node_get(bgp_def
->rib
[afi
][safi
], afi
, safi
,
1504 (struct prefix
*)evp
, &bgp_vrf
->vrf_prd
);
1507 /* create or update the route entry within the route node */
1508 update_evpn_type5_route_entry(bgp_def
, bgp_vrf
, afi
, safi
, rn
, &attr
,
1511 /* schedule for processing and unlock node */
1512 if (route_changed
) {
1513 bgp_process(bgp_def
, rn
, afi
, safi
);
1514 bgp_unlock_node(rn
);
1517 /* uninten temporary */
1519 aspath_unintern(&attr
.aspath
);
1524 * Create or update EVPN route entry. This could be in the VNI route table
1525 * or the global route table.
1527 static int update_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1528 afi_t afi
, safi_t safi
, struct bgp_node
*rn
,
1529 struct attr
*attr
, int add
, int vni_table
,
1530 struct bgp_info
**ri
, uint8_t flags
)
1532 struct bgp_info
*tmp_ri
;
1533 struct bgp_info
*local_ri
, *remote_ri
;
1534 struct attr
*attr_new
;
1535 mpls_label_t label
[BGP_MAX_LABELS
];
1536 uint32_t num_labels
= 1;
1537 int route_change
= 1;
1539 struct prefix_evpn
*evp
;
1542 evp
= (struct prefix_evpn
*)&rn
->p
;
1543 memset(&label
, 0, sizeof(label
));
1545 /* See if this is an update of an existing route, or a new add. Also,
1546 * identify if already known from remote, and if so, the one with the
1547 * highest sequence number; this is only when adding to the VNI routing
1550 local_ri
= remote_ri
= NULL
;
1551 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
) {
1552 if (tmp_ri
->peer
== bgp
->peer_self
1553 && tmp_ri
->type
== ZEBRA_ROUTE_BGP
1554 && tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1557 if (tmp_ri
->type
== ZEBRA_ROUTE_BGP
1558 && tmp_ri
->sub_type
== BGP_ROUTE_IMPORTED
1559 && CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_VALID
)) {
1562 else if (mac_mobility_seqnum(tmp_ri
->attr
)
1563 > mac_mobility_seqnum(remote_ri
->attr
))
1569 /* If route doesn't exist already, create a new one, if told to.
1570 * Otherwise act based on whether the attributes of the route have
1573 if (!local_ri
&& !add
)
1577 /* When learnt locally for the first time but already known from
1578 * remote, we have to initiate appropriate MAC mobility steps.
1579 * This is applicable when updating the VNI routing table.
1580 * We need to skip mobility steps for g/w macs (local mac on g/w
1581 * SVI) advertised in EVPN.
1582 * This will ensure that local routes are preferred for g/w macs
1584 if (remote_ri
&& !CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
)) {
1585 uint32_t cur_seqnum
;
1587 /* Add MM extended community to route. */
1588 cur_seqnum
= mac_mobility_seqnum(remote_ri
->attr
);
1589 add_mac_mobility_to_attr(cur_seqnum
+ 1, attr
);
1592 /* Add (or update) attribute to hash. */
1593 attr_new
= bgp_attr_intern(attr
);
1595 /* Extract MAC mobility sequence number, if any. */
1596 attr_new
->mm_seqnum
=
1597 bgp_attr_mac_mobility_seqnum(attr_new
, &sticky
);
1598 attr_new
->sticky
= sticky
;
1600 /* Create new route with its attribute. */
1601 tmp_ri
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
1602 bgp
->peer_self
, attr_new
, rn
);
1603 SET_FLAG(tmp_ri
->flags
, BGP_INFO_VALID
);
1604 bgp_info_extra_get(tmp_ri
);
1606 /* The VNI goes into the 'label' field of the route */
1607 vni2label(vpn
->vni
, &label
[0]);
1609 /* Type-2 routes may carry a second VNI - the L3-VNI.
1610 * Only attach second label if we are advertising two labels for
1613 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1614 && CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
)) {
1617 l3vni
= bgpevpn_get_l3vni(vpn
);
1619 vni2label(l3vni
, &label
[1]);
1624 memcpy(&tmp_ri
->extra
->label
, label
, sizeof(label
));
1625 tmp_ri
->extra
->num_labels
= num_labels
;
1626 bgp_info_add(rn
, tmp_ri
);
1629 if (attrhash_cmp(tmp_ri
->attr
, attr
)
1630 && !CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_REMOVED
))
1634 * The attributes have changed, type-2 routes needs to
1635 * be advertised with right labels.
1637 vni2label(vpn
->vni
, &label
[0]);
1638 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
1639 && CHECK_FLAG(vpn
->flags
,
1640 VNI_FLAG_USE_TWO_LABELS
)) {
1643 l3vni
= bgpevpn_get_l3vni(vpn
);
1645 vni2label(l3vni
, &label
[1]);
1649 memcpy(&tmp_ri
->extra
->label
, label
, sizeof(label
));
1650 tmp_ri
->extra
->num_labels
= num_labels
;
1652 /* The attribute has changed. */
1653 /* Add (or update) attribute to hash. */
1654 attr_new
= bgp_attr_intern(attr
);
1655 bgp_info_set_flag(rn
, tmp_ri
, BGP_INFO_ATTR_CHANGED
);
1657 /* Restore route, if needed. */
1658 if (CHECK_FLAG(tmp_ri
->flags
, BGP_INFO_REMOVED
))
1659 bgp_info_restore(rn
, tmp_ri
);
1661 /* Unintern existing, set to new. */
1662 bgp_attr_unintern(&tmp_ri
->attr
);
1663 tmp_ri
->attr
= attr_new
;
1664 tmp_ri
->uptime
= bgp_clock();
1668 /* Return back the route entry. */
1670 return route_change
;
1674 * Create or update EVPN route (of type based on prefix) for specified VNI
1675 * and schedule for processing.
1677 static int update_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1678 struct prefix_evpn
*p
, uint8_t flags
)
1680 struct bgp_node
*rn
;
1682 struct attr
*attr_new
;
1683 int add_l3_ecomm
= 0;
1684 struct bgp_info
*ri
;
1685 afi_t afi
= AFI_L2VPN
;
1686 safi_t safi
= SAFI_EVPN
;
1689 memset(&attr
, 0, sizeof(struct attr
));
1691 /* Build path-attribute for this route. */
1692 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
1693 attr
.nexthop
= vpn
->originator_ip
;
1694 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
1695 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1696 attr
.sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
) ? 1 : 0;
1697 attr
.default_gw
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
) ? 1 : 0;
1699 /* PMSI is only needed for type-3 routes */
1700 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
)
1701 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
);
1703 /* router mac is only needed for type-2 routes here. */
1704 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
1705 bgpevpn_get_rmac(vpn
, &attr
.rmac
);
1706 vni2label(vpn
->vni
, &(attr
.label
));
1708 /* Include L3 VNI related RTs and RMAC for type-2 routes, if they're
1709 * IPv4 or IPv6 global addresses and we're advertising L3VNI with
1712 if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
&&
1713 (is_evpn_prefix_ipaddr_v4(p
) ||
1714 !IN6_IS_ADDR_LINKLOCAL(&p
->prefix
.macip_addr
.ip
.ipaddr_v6
)) &&
1715 CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
))
1718 /* Set up extended community. */
1719 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
1721 /* First, create (or fetch) route node within the VNI. */
1722 /* NOTE: There is no RD here. */
1723 rn
= bgp_node_get(vpn
->route_table
, (struct prefix
*)p
);
1725 /* Create or update route entry. */
1726 route_change
= update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
, &attr
,
1729 attr_new
= ri
->attr
;
1731 /* Perform route selection; this is just to set the flags correctly
1732 * as local route in the VNI always wins.
1734 evpn_route_select_install(bgp
, vpn
, rn
);
1735 bgp_unlock_node(rn
);
1737 /* If this is a new route or some attribute has changed, export the
1738 * route to the global table. The route will be advertised to peers
1739 * from there. Note that this table is a 2-level tree (RD-level +
1740 * Prefix-level) similar to L3VPN routes.
1743 struct bgp_info
*global_ri
;
1745 rn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
1746 (struct prefix
*)p
, &vpn
->prd
);
1747 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
, attr_new
, 1, 0,
1750 /* Schedule for processing and unlock node. */
1751 bgp_process(bgp
, rn
, afi
, safi
);
1752 bgp_unlock_node(rn
);
1755 /* Unintern temporary. */
1756 aspath_unintern(&attr
.aspath
);
1762 * Delete EVPN route entry.
1763 * The entry can be in ESI/VNI table or the global table.
1765 static void delete_evpn_route_entry(struct bgp
*bgp
,
1766 afi_t afi
, safi_t safi
,
1767 struct bgp_node
*rn
,
1768 struct bgp_info
**ri
)
1770 struct bgp_info
*tmp_ri
;
1774 /* Now, find matching route. */
1775 for (tmp_ri
= rn
->info
; tmp_ri
; tmp_ri
= tmp_ri
->next
)
1776 if (tmp_ri
->peer
== bgp
->peer_self
1777 && tmp_ri
->type
== ZEBRA_ROUTE_BGP
1778 && tmp_ri
->sub_type
== BGP_ROUTE_STATIC
)
1783 /* Mark route for delete. */
1785 bgp_info_delete(rn
, tmp_ri
);
1790 /* Delete EVPN ES (type-4) route */
1791 static int delete_evpn_type4_route(struct bgp
*bgp
,
1793 struct prefix_evpn
*p
)
1795 afi_t afi
= AFI_L2VPN
;
1796 safi_t safi
= SAFI_EVPN
;
1797 struct bgp_info
*ri
;
1798 struct bgp_node
*rn
= NULL
; /* rn in esi table */
1799 struct bgp_node
*global_rn
= NULL
; /* rn in global table */
1801 /* First, locate the route node within the ESI.
1802 * If it doesn't exist, ther is nothing to do.
1803 * Note: there is no RD here.
1805 rn
= bgp_node_lookup(es
->route_table
, (struct prefix
*)p
);
1809 /* Next, locate route node in the global EVPN routing table.
1810 * Note that this table is a 2-level tree (RD-level + Prefix-level)
1812 global_rn
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
1813 (struct prefix
*)p
, &es
->prd
);
1816 /* Delete route entry in the global EVPN table. */
1817 delete_evpn_route_entry(bgp
, afi
, safi
,
1820 /* Schedule for processing - withdraws to peers happen from
1824 bgp_process(bgp
, global_rn
, afi
, safi
);
1825 bgp_unlock_node(global_rn
);
1829 * Delete route entry in the ESI route table.
1830 * This can just be removed.
1832 delete_evpn_route_entry(bgp
, afi
, safi
, rn
, &ri
);
1834 bgp_info_reap(rn
, ri
);
1835 bgp_unlock_node(rn
);
1839 /* Delete EVPN type5 route */
1840 static int delete_evpn_type5_route(struct bgp
*bgp_vrf
, struct prefix_evpn
*evp
)
1842 afi_t afi
= AFI_L2VPN
;
1843 safi_t safi
= SAFI_EVPN
;
1844 struct bgp_node
*rn
= NULL
;
1845 struct bgp_info
*ri
= NULL
;
1846 struct bgp
*bgp_def
= NULL
; /* default bgp instance */
1848 bgp_def
= bgp_get_default();
1852 /* locate the global route entry for this type-5 prefix */
1853 rn
= bgp_afi_node_lookup(bgp_def
->rib
[afi
][safi
], afi
, safi
,
1854 (struct prefix
*)evp
, &bgp_vrf
->vrf_prd
);
1858 delete_evpn_route_entry(bgp_def
, afi
, safi
, rn
, &ri
);
1860 bgp_process(bgp_def
, rn
, afi
, safi
);
1861 bgp_unlock_node(rn
);
1866 * Delete EVPN route (of type based on prefix) for specified VNI and
1867 * schedule for processing.
1869 static int delete_evpn_route(struct bgp
*bgp
, struct bgpevpn
*vpn
,
1870 struct prefix_evpn
*p
)
1872 struct bgp_node
*rn
, *global_rn
;
1873 struct bgp_info
*ri
;
1874 afi_t afi
= AFI_L2VPN
;
1875 safi_t safi
= SAFI_EVPN
;
1877 /* First, locate the route node within the VNI. If it doesn't exist,
1879 * is nothing further to do.
1881 /* NOTE: There is no RD here. */
1882 rn
= bgp_node_lookup(vpn
->route_table
, (struct prefix
*)p
);
1886 /* Next, locate route node in the global EVPN routing table. Note that
1887 * this table is a 2-level tree (RD-level + Prefix-level) similar to
1890 global_rn
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
1891 (struct prefix
*)p
, &vpn
->prd
);
1893 /* Delete route entry in the global EVPN table. */
1894 delete_evpn_route_entry(bgp
, afi
, safi
, global_rn
, &ri
);
1896 /* Schedule for processing - withdraws to peers happen from
1900 bgp_process(bgp
, global_rn
, afi
, safi
);
1901 bgp_unlock_node(global_rn
);
1904 /* Delete route entry in the VNI route table. This can just be removed.
1906 delete_evpn_route_entry(bgp
, afi
, safi
, rn
, &ri
);
1908 bgp_info_reap(rn
, ri
);
1909 bgp_unlock_node(rn
);
1915 * Update all type-2 (MACIP) local routes for this VNI - these should also
1916 * be scheduled for advertise to peers.
1918 static int update_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1922 struct bgp_node
*rn
;
1923 struct bgp_info
*ri
;
1925 struct attr attr_sticky
;
1926 struct attr attr_def_gw
;
1927 struct attr attr_ip6_ll
;
1928 struct attr
*attr_new
;
1929 int add_l3_ecomm
= 0;
1933 memset(&attr
, 0, sizeof(struct attr
));
1934 memset(&attr_sticky
, 0, sizeof(struct attr
));
1935 memset(&attr_def_gw
, 0, sizeof(struct attr
));
1936 memset(&attr_ip6_ll
, 0, sizeof(struct attr
));
1938 /* Build path-attribute - multiple type-2 routes for this VNI will share
1939 * the same path attribute, but we need separate structures for sticky
1940 * MACs, default gateway and IPv6 link-local addresses (no L3 RT/RMAC).
1942 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
1943 bgp_attr_default_set(&attr_sticky
, BGP_ORIGIN_IGP
);
1944 bgp_attr_default_set(&attr_def_gw
, BGP_ORIGIN_IGP
);
1945 attr
.nexthop
= vpn
->originator_ip
;
1946 attr
.mp_nexthop_global_in
= vpn
->originator_ip
;
1947 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1948 bgpevpn_get_rmac(vpn
, &attr
.rmac
);
1949 attr_sticky
.nexthop
= vpn
->originator_ip
;
1950 attr_sticky
.mp_nexthop_global_in
= vpn
->originator_ip
;
1951 attr_sticky
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1952 attr_sticky
.sticky
= 1;
1953 bgpevpn_get_rmac(vpn
, &attr_sticky
.rmac
);
1954 attr_def_gw
.nexthop
= vpn
->originator_ip
;
1955 attr_def_gw
.mp_nexthop_global_in
= vpn
->originator_ip
;
1956 attr_def_gw
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1957 attr_def_gw
.default_gw
= 1;
1958 bgpevpn_get_rmac(vpn
, &attr_def_gw
.rmac
);
1959 bgp_attr_default_set(&attr_ip6_ll
, BGP_ORIGIN_IGP
);
1960 attr_ip6_ll
.nexthop
= vpn
->originator_ip
;
1961 attr_ip6_ll
.mp_nexthop_global_in
= vpn
->originator_ip
;
1962 attr_ip6_ll
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
1964 /* Add L3 VNI RTs and RMAC for non IPv6 link-local attributes if
1965 * using L3 VNI for type-2 routes also.
1967 if (CHECK_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
))
1970 build_evpn_route_extcomm(vpn
, &attr
, add_l3_ecomm
);
1971 build_evpn_route_extcomm(vpn
, &attr_sticky
, add_l3_ecomm
);
1972 build_evpn_route_extcomm(vpn
, &attr_def_gw
, add_l3_ecomm
);
1973 build_evpn_route_extcomm(vpn
, &attr_ip6_ll
, 0);
1975 /* Walk this VNI's route table and update local type-2 routes. For any
1976 * routes updated, update corresponding entry in the global table too.
1978 for (rn
= bgp_table_top(vpn
->route_table
); rn
;
1979 rn
= bgp_route_next(rn
)) {
1980 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
1981 struct bgp_node
*rd_rn
;
1982 struct bgp_info
*global_ri
;
1984 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
1987 if (is_evpn_prefix_ipaddr_v6(evp
) &&
1988 IN6_IS_ADDR_LINKLOCAL(&evp
->prefix
.macip_addr
.ip
.ipaddr_v6
))
1989 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
,
1990 &attr_ip6_ll
, 0, 1, &ri
, 0);
1992 if (evpn_route_is_sticky(bgp
, rn
))
1993 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
,
1994 &attr_sticky
, 0, 1, &ri
,
1996 else if (evpn_route_is_def_gw(bgp
, rn
))
1997 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
,
1998 &attr_def_gw
, 0, 1, &ri
,
2001 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rn
,
2002 &attr
, 0, 1, &ri
, 0);
2005 /* If a local route exists for this prefix, we need to update
2006 * the global routing table too.
2011 /* Perform route selection; this is just to set the flags
2013 * as local route in the VNI always wins.
2015 evpn_route_select_install(bgp
, vpn
, rn
);
2017 attr_new
= ri
->attr
;
2019 /* Update route in global routing table. */
2020 rd_rn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
2021 (struct prefix
*)evp
, &vpn
->prd
);
2023 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, rd_rn
, attr_new
, 0,
2026 /* Schedule for processing and unlock node. */
2027 bgp_process(bgp
, rd_rn
, afi
, safi
);
2028 bgp_unlock_node(rd_rn
);
2031 /* Unintern temporary. */
2032 aspath_unintern(&attr
.aspath
);
2033 aspath_unintern(&attr_sticky
.aspath
);
2034 aspath_unintern(&attr_def_gw
.aspath
);
2035 aspath_unintern(&attr_ip6_ll
.aspath
);
2041 * Delete all type-2 (MACIP) local routes for this VNI - only from the
2042 * global routing table. These are also scheduled for withdraw from peers.
2044 static int delete_global_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2048 struct bgp_node
*rdrn
, *rn
;
2049 struct bgp_table
*table
;
2050 struct bgp_info
*ri
;
2055 rdrn
= bgp_node_lookup(bgp
->rib
[afi
][safi
], (struct prefix
*)&vpn
->prd
);
2056 if (rdrn
&& rdrn
->info
) {
2057 table
= (struct bgp_table
*)rdrn
->info
;
2058 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2059 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2061 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2064 delete_evpn_route_entry(bgp
, afi
, safi
, rn
, &ri
);
2066 bgp_process(bgp
, rn
, afi
, safi
);
2070 /* Unlock RD node. */
2072 bgp_unlock_node(rdrn
);
2078 * Delete all type-2 (MACIP) local routes for this VNI - from the global
2079 * table as well as the per-VNI route table.
2081 static int delete_all_type2_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2085 struct bgp_node
*rn
;
2086 struct bgp_info
*ri
;
2091 /* First, walk the global route table for this VNI's type-2 local
2093 * EVPN routes are a 2-level table, first get the RD table.
2095 delete_global_type2_routes(bgp
, vpn
);
2097 /* Next, walk this VNI's route table and delete local type-2 routes. */
2098 for (rn
= bgp_table_top(vpn
->route_table
); rn
;
2099 rn
= bgp_route_next(rn
)) {
2100 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2102 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2105 delete_evpn_route_entry(bgp
, afi
, safi
, rn
, &ri
);
2107 /* Route entry in local table gets deleted immediately. */
2109 bgp_info_reap(rn
, ri
);
2116 * Delete all routes in per ES route-table
2118 static int delete_all_es_routes(struct bgp
*bgp
, struct evpnes
*es
)
2120 struct bgp_node
*rn
;
2121 struct bgp_info
*ri
, *nextri
;
2123 /* Walk this ES's route table and delete all routes. */
2124 for (rn
= bgp_table_top(es
->route_table
); rn
;
2125 rn
= bgp_route_next(rn
)) {
2126 for (ri
= rn
->info
; (ri
!= NULL
) && (nextri
= ri
->next
, 1);
2128 bgp_info_delete(rn
, ri
);
2129 bgp_info_reap(rn
, ri
);
2137 * Delete all routes in the per-VNI route table.
2139 static int delete_all_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2141 struct bgp_node
*rn
;
2142 struct bgp_info
*ri
, *nextri
;
2144 /* Walk this VNI's route table and delete all routes. */
2145 for (rn
= bgp_table_top(vpn
->route_table
); rn
;
2146 rn
= bgp_route_next(rn
)) {
2147 for (ri
= rn
->info
; (ri
!= NULL
) && (nextri
= ri
->next
, 1);
2149 bgp_info_delete(rn
, ri
);
2150 bgp_info_reap(rn
, ri
);
2158 * Update (and advertise) local routes for a VNI. Invoked upon the VNI
2159 * export RT getting modified or change to tunnel IP. Note that these
2160 * situations need the route in the per-VNI table as well as the global
2161 * table to be updated (as attributes change).
2163 static int update_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2166 struct prefix_evpn p
;
2168 /* Update and advertise the type-3 route (only one) followed by the
2169 * locally learnt type-2 routes (MACIP) - for this VNI.
2171 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2172 ret
= update_evpn_route(bgp
, vpn
, &p
, 0);
2176 return update_all_type2_routes(bgp
, vpn
);
2179 /* Delete (and withdraw) local routes for specified ES from global and ES table.
2180 * Also remove all other routes from the per ES table.
2181 * Invoked when ES is deleted.
2183 static int delete_routes_for_es(struct bgp
*bgp
, struct evpnes
*es
)
2186 char buf
[ESI_STR_LEN
];
2187 struct prefix_evpn p
;
2189 /* Delete and withdraw locally learnt ES route */
2190 build_evpn_type4_prefix(&p
, &es
->esi
, es
->originator_ip
.ipaddr_v4
);
2191 ret
= delete_evpn_type4_route(bgp
, es
, &p
);
2194 "%u failed to delete type-4 route for ESI %s",
2196 esi_to_str(&es
->esi
, buf
, sizeof(buf
)));
2199 /* Delete all routes from per ES table */
2200 return delete_all_es_routes(bgp
, es
);
2204 * Delete (and withdraw) local routes for specified VNI from the global
2205 * table and per-VNI table. After this, remove all other routes from
2206 * the per-VNI table. Invoked upon the VNI being deleted or EVPN
2207 * (advertise-all-vni) being disabled.
2209 static int delete_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
2212 struct prefix_evpn p
;
2214 /* Delete and withdraw locally learnt type-2 routes (MACIP)
2215 * followed by type-3 routes (only one) - for this VNI.
2217 ret
= delete_all_type2_routes(bgp
, vpn
);
2221 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2222 ret
= delete_evpn_route(bgp
, vpn
, &p
);
2226 /* Delete all routes from the per-VNI table. */
2227 return delete_all_vni_routes(bgp
, vpn
);
2231 * There is a tunnel endpoint IP address change for this VNI, delete
2232 * prior type-3 route (if needed) and update.
2233 * Note: Route re-advertisement happens elsewhere after other processing
2236 static int handle_tunnel_ip_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2237 struct in_addr originator_ip
)
2239 struct prefix_evpn p
;
2241 /* If VNI is not live, we only need to update the originator ip */
2242 if (!is_vni_live(vpn
)) {
2243 vpn
->originator_ip
= originator_ip
;
2247 /* Update the tunnel-ip hash */
2248 bgp_tip_del(bgp
, &vpn
->originator_ip
);
2249 bgp_tip_add(bgp
, &originator_ip
);
2251 /* filter routes as martian nexthop db has changed */
2252 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
2254 /* Need to withdraw type-3 route as the originator IP is part
2257 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
2258 delete_evpn_route(bgp
, vpn
, &p
);
2260 /* Update the tunnel IP and re-advertise all routes for this VNI. */
2261 vpn
->originator_ip
= originator_ip
;
2265 /* Install EVPN route entry in ES */
2266 static int install_evpn_route_entry_in_es(struct bgp
*bgp
,
2268 struct prefix_evpn
*p
,
2269 struct bgp_info
*parent_ri
)
2272 struct bgp_node
*rn
= NULL
;
2273 struct bgp_info
*ri
= NULL
;
2274 struct attr
*attr_new
= NULL
;
2276 /* Create (or fetch) route within the VNI.
2277 * NOTE: There is no RD here.
2279 rn
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
2281 /* Check if route entry is already present. */
2282 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2284 (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2288 /* Add (or update) attribute to hash. */
2289 attr_new
= bgp_attr_intern(parent_ri
->attr
);
2291 /* Create new route with its attribute. */
2292 ri
= info_make(parent_ri
->type
, BGP_ROUTE_IMPORTED
, 0,
2293 parent_ri
->peer
, attr_new
, rn
);
2294 SET_FLAG(ri
->flags
, BGP_INFO_VALID
);
2295 bgp_info_extra_get(ri
);
2296 ri
->extra
->parent
= parent_ri
;
2297 bgp_info_add(rn
, ri
);
2299 if (attrhash_cmp(ri
->attr
, parent_ri
->attr
)
2300 && !CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
)) {
2301 bgp_unlock_node(rn
);
2304 /* The attribute has changed. */
2305 /* Add (or update) attribute to hash. */
2306 attr_new
= bgp_attr_intern(parent_ri
->attr
);
2308 /* Restore route, if needed. */
2309 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
2310 bgp_info_restore(rn
, ri
);
2312 /* Mark if nexthop has changed. */
2313 if (!IPV4_ADDR_SAME(&ri
->attr
->nexthop
, &attr_new
->nexthop
))
2314 SET_FLAG(ri
->flags
, BGP_INFO_IGP_CHANGED
);
2316 /* Unintern existing, set to new. */
2317 bgp_attr_unintern(&ri
->attr
);
2318 ri
->attr
= attr_new
;
2319 ri
->uptime
= bgp_clock();
2322 /* Perform route selection and update zebra, if required. */
2323 ret
= evpn_es_route_select_install(bgp
, es
, rn
);
2328 * Install route entry into the VRF routing table and invoke route selection.
2330 static int install_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
2331 struct prefix_evpn
*evp
,
2332 struct bgp_info
*parent_ri
)
2334 struct bgp_node
*rn
;
2335 struct bgp_info
*ri
;
2337 struct attr
*attr_new
;
2340 struct prefix
*pp
= &p
;
2343 char buf
[PREFIX_STRLEN
];
2344 char buf1
[PREFIX_STRLEN
];
2346 memset(pp
, 0, sizeof(struct prefix
));
2347 ip_prefix_from_evpn_prefix(evp
, pp
);
2349 if (bgp_debug_zebra(NULL
)) {
2351 "installing evpn prefix %s as ip prefix %s in vrf %s",
2352 prefix2str(evp
, buf
, sizeof(buf
)),
2353 prefix2str(pp
, buf1
, sizeof(buf
)),
2354 vrf_id_to_name(bgp_vrf
->vrf_id
));
2357 /* Create (or fetch) route within the VRF. */
2358 /* NOTE: There is no RD here. */
2359 if (is_evpn_prefix_ipaddr_v4(evp
)) {
2361 safi
= SAFI_UNICAST
;
2362 rn
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2363 } else if (is_evpn_prefix_ipaddr_v6(evp
)) {
2365 safi
= SAFI_UNICAST
;
2366 rn
= bgp_node_get(bgp_vrf
->rib
[afi
][safi
], pp
);
2370 /* EVPN routes currently only support a IPv4 next hop which corresponds
2371 * to the remote VTEP. When importing into a VRF, if it is IPv6 host
2372 * or prefix route, we have to convert the next hop to an IPv4-mapped
2373 * address for the rest of the code to flow through. In the case of IPv4,
2374 * make sure to set the flag for next hop attribute.
2376 bgp_attr_dup(&attr
, parent_ri
->attr
);
2378 evpn_convert_nexthop_to_ipv6(&attr
);
2380 attr
.flag
|= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP
);
2382 /* Check if route entry is already present. */
2383 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2385 && (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2389 /* Add (or update) attribute to hash. */
2390 attr_new
= bgp_attr_intern(&attr
);
2392 /* Create new route with its attribute. */
2393 ri
= info_make(parent_ri
->type
, BGP_ROUTE_IMPORTED
, 0,
2394 parent_ri
->peer
, attr_new
, rn
);
2395 SET_FLAG(ri
->flags
, BGP_INFO_VALID
);
2396 bgp_info_extra_get(ri
);
2397 ri
->extra
->parent
= bgp_info_lock(parent_ri
);
2398 bgp_lock_node((struct bgp_node
*)parent_ri
->net
);
2399 if (parent_ri
->extra
) {
2400 memcpy(&ri
->extra
->label
, &parent_ri
->extra
->label
,
2401 sizeof(ri
->extra
->label
));
2402 ri
->extra
->num_labels
= parent_ri
->extra
->num_labels
;
2404 bgp_info_add(rn
, ri
);
2406 if (attrhash_cmp(ri
->attr
, &attr
)
2407 && !CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
)) {
2408 bgp_unlock_node(rn
);
2411 /* The attribute has changed. */
2412 /* Add (or update) attribute to hash. */
2413 attr_new
= bgp_attr_intern(&attr
);
2415 /* Restore route, if needed. */
2416 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
2417 bgp_info_restore(rn
, ri
);
2419 /* Mark if nexthop has changed. */
2420 if ((afi
== AFI_IP
&&
2421 !IPV4_ADDR_SAME(&ri
->attr
->nexthop
, &attr_new
->nexthop
)) ||
2423 !IPV6_ADDR_SAME(&ri
->attr
->mp_nexthop_global
,
2424 &attr_new
->mp_nexthop_global
)))
2425 SET_FLAG(ri
->flags
, BGP_INFO_IGP_CHANGED
);
2427 /* Unintern existing, set to new. */
2428 bgp_attr_unintern(&ri
->attr
);
2429 ri
->attr
= attr_new
;
2430 ri
->uptime
= bgp_clock();
2433 /* Perform route selection and update zebra, if required. */
2434 bgp_process(bgp_vrf
, rn
, afi
, safi
);
2440 * Install route entry into the VNI routing table and invoke route selection.
2442 static int install_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2443 struct prefix_evpn
*p
,
2444 struct bgp_info
*parent_ri
)
2446 struct bgp_node
*rn
;
2447 struct bgp_info
*ri
;
2448 struct attr
*attr_new
;
2451 /* Create (or fetch) route within the VNI. */
2452 /* NOTE: There is no RD here. */
2453 rn
= bgp_node_get(vpn
->route_table
, (struct prefix
*)p
);
2455 /* Check if route entry is already present. */
2456 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2458 && (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2462 /* Add (or update) attribute to hash. */
2463 attr_new
= bgp_attr_intern(parent_ri
->attr
);
2465 /* Create new route with its attribute. */
2466 ri
= info_make(parent_ri
->type
, BGP_ROUTE_IMPORTED
, 0,
2467 parent_ri
->peer
, attr_new
, rn
);
2468 SET_FLAG(ri
->flags
, BGP_INFO_VALID
);
2469 bgp_info_extra_get(ri
);
2470 ri
->extra
->parent
= bgp_info_lock(parent_ri
);
2471 bgp_lock_node((struct bgp_node
*)parent_ri
->net
);
2472 if (parent_ri
->extra
) {
2473 memcpy(&ri
->extra
->label
, &parent_ri
->extra
->label
,
2474 sizeof(ri
->extra
->label
));
2475 ri
->extra
->num_labels
= parent_ri
->extra
->num_labels
;
2477 bgp_info_add(rn
, ri
);
2479 if (attrhash_cmp(ri
->attr
, parent_ri
->attr
)
2480 && !CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
)) {
2481 bgp_unlock_node(rn
);
2484 /* The attribute has changed. */
2485 /* Add (or update) attribute to hash. */
2486 attr_new
= bgp_attr_intern(parent_ri
->attr
);
2488 /* Restore route, if needed. */
2489 if (CHECK_FLAG(ri
->flags
, BGP_INFO_REMOVED
))
2490 bgp_info_restore(rn
, ri
);
2492 /* Mark if nexthop has changed. */
2493 if (!IPV4_ADDR_SAME(&ri
->attr
->nexthop
, &attr_new
->nexthop
))
2494 SET_FLAG(ri
->flags
, BGP_INFO_IGP_CHANGED
);
2496 /* Unintern existing, set to new. */
2497 bgp_attr_unintern(&ri
->attr
);
2498 ri
->attr
= attr_new
;
2499 ri
->uptime
= bgp_clock();
2502 /* Perform route selection and update zebra, if required. */
2503 ret
= evpn_route_select_install(bgp
, vpn
, rn
);
2508 /* Uninstall EVPN route entry from ES route table */
2509 static int uninstall_evpn_route_entry_in_es(struct bgp
*bgp
,
2511 struct prefix_evpn
*p
,
2512 struct bgp_info
*parent_ri
)
2515 struct bgp_node
*rn
;
2516 struct bgp_info
*ri
;
2518 if (!es
->route_table
)
2521 /* Locate route within the ESI.
2522 * NOTE: There is no RD here.
2524 rn
= bgp_node_lookup(es
->route_table
, (struct prefix
*)p
);
2528 /* Find matching route entry. */
2529 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2531 (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2537 /* Mark entry for deletion */
2538 bgp_info_delete(rn
, ri
);
2540 /* Perform route selection and update zebra, if required. */
2541 ret
= evpn_es_route_select_install(bgp
, es
, rn
);
2543 /* Unlock route node. */
2544 bgp_unlock_node(rn
);
2550 * Uninstall route entry from the VRF routing table and send message
2551 * to zebra, if appropriate.
2553 static int uninstall_evpn_route_entry_in_vrf(struct bgp
*bgp_vrf
,
2554 struct prefix_evpn
*evp
,
2555 struct bgp_info
*parent_ri
)
2557 struct bgp_node
*rn
;
2558 struct bgp_info
*ri
;
2561 struct prefix
*pp
= &p
;
2564 char buf
[PREFIX_STRLEN
];
2565 char buf1
[PREFIX_STRLEN
];
2567 memset(pp
, 0, sizeof(struct prefix
));
2568 ip_prefix_from_evpn_prefix(evp
, pp
);
2570 if (bgp_debug_zebra(NULL
)) {
2572 "uninstalling evpn prefix %s as ip prefix %s in vrf %s",
2573 prefix2str(evp
, buf
, sizeof(buf
)),
2574 prefix2str(pp
, buf1
, sizeof(buf
)),
2575 vrf_id_to_name(bgp_vrf
->vrf_id
));
2578 /* Locate route within the VRF. */
2579 /* NOTE: There is no RD here. */
2580 if (is_evpn_prefix_ipaddr_v4(evp
)) {
2582 safi
= SAFI_UNICAST
;
2583 rn
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
2586 safi
= SAFI_UNICAST
;
2587 rn
= bgp_node_lookup(bgp_vrf
->rib
[afi
][safi
], pp
);
2593 /* Find matching route entry. */
2594 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2596 && (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2602 /* Mark entry for deletion */
2603 bgp_info_delete(rn
, ri
);
2605 /* Perform route selection and update zebra, if required. */
2606 bgp_process(bgp_vrf
, rn
, afi
, safi
);
2608 /* Unlock route node. */
2609 bgp_unlock_node(rn
);
2615 * Uninstall route entry from the VNI routing table and send message
2616 * to zebra, if appropriate.
2618 static int uninstall_evpn_route_entry(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2619 struct prefix_evpn
*p
,
2620 struct bgp_info
*parent_ri
)
2622 struct bgp_node
*rn
;
2623 struct bgp_info
*ri
;
2626 /* Locate route within the VNI. */
2627 /* NOTE: There is no RD here. */
2628 rn
= bgp_node_lookup(vpn
->route_table
, (struct prefix
*)p
);
2632 /* Find matching route entry. */
2633 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
2635 && (struct bgp_info
*)ri
->extra
->parent
== parent_ri
)
2641 /* Mark entry for deletion */
2642 bgp_info_delete(rn
, ri
);
2644 /* Perform route selection and update zebra, if required. */
2645 ret
= evpn_route_select_install(bgp
, vpn
, rn
);
2647 /* Unlock route node. */
2648 bgp_unlock_node(rn
);
2654 * Given a prefix, see if it belongs to ES.
2656 static int is_prefix_matching_for_es(struct prefix_evpn
*p
,
2659 /* if not an ES route return false */
2660 if (p
->prefix
.route_type
!= BGP_EVPN_ES_ROUTE
)
2663 if (memcmp(&p
->prefix
.es_addr
.esi
, &es
->esi
, sizeof(esi_t
)) == 0)
2670 * Given a route entry and a VRF, see if this route entry should be
2671 * imported into the VRF i.e., RTs match.
2673 static int is_route_matching_for_vrf(struct bgp
*bgp_vrf
, struct bgp_info
*ri
)
2675 struct attr
*attr
= ri
->attr
;
2676 struct ecommunity
*ecom
;
2680 /* Route should have valid RT to be even considered. */
2681 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
2684 ecom
= attr
->ecommunity
;
2685 if (!ecom
|| !ecom
->size
)
2688 /* For each extended community RT, see if it matches this VNI. If any RT
2689 * matches, we're done.
2691 for (i
= 0; i
< ecom
->size
; i
++) {
2693 uint8_t type
, sub_type
;
2694 struct ecommunity_val
*eval
;
2695 struct ecommunity_val eval_tmp
;
2696 struct vrf_irt_node
*irt
;
2698 /* Only deal with RTs */
2699 pnt
= (ecom
->val
+ (i
* ECOMMUNITY_SIZE
));
2700 eval
= (struct ecommunity_val
*)(ecom
->val
2701 + (i
* ECOMMUNITY_SIZE
));
2704 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
2707 /* See if this RT matches specified VNIs import RTs */
2708 irt
= lookup_vrf_import_rt(eval
);
2710 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
2713 /* Also check for non-exact match. In this, we mask out the AS
2715 * only check on the local-admin sub-field. This is to
2717 * VNI as the RT for EBGP peering too.
2720 if (type
== ECOMMUNITY_ENCODE_AS
2721 || type
== ECOMMUNITY_ENCODE_AS4
2722 || type
== ECOMMUNITY_ENCODE_IP
) {
2723 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
2724 mask_ecom_global_admin(&eval_tmp
, eval
);
2725 irt
= lookup_vrf_import_rt(&eval_tmp
);
2728 if (is_vrf_present_in_irt_vrfs(irt
->vrfs
, bgp_vrf
))
2736 * Given a route entry and a VNI, see if this route entry should be
2737 * imported into the VNI i.e., RTs match.
2739 static int is_route_matching_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
,
2740 struct bgp_info
*ri
)
2742 struct attr
*attr
= ri
->attr
;
2743 struct ecommunity
*ecom
;
2747 /* Route should have valid RT to be even considered. */
2748 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
2751 ecom
= attr
->ecommunity
;
2752 if (!ecom
|| !ecom
->size
)
2755 /* For each extended community RT, see if it matches this VNI. If any RT
2756 * matches, we're done.
2758 for (i
= 0; i
< ecom
->size
; i
++) {
2760 uint8_t type
, sub_type
;
2761 struct ecommunity_val
*eval
;
2762 struct ecommunity_val eval_tmp
;
2763 struct irt_node
*irt
;
2765 /* Only deal with RTs */
2766 pnt
= (ecom
->val
+ (i
* ECOMMUNITY_SIZE
));
2767 eval
= (struct ecommunity_val
*)(ecom
->val
2768 + (i
* ECOMMUNITY_SIZE
));
2771 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
2774 /* See if this RT matches specified VNIs import RTs */
2775 irt
= lookup_import_rt(bgp
, eval
);
2777 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
2780 /* Also check for non-exact match. In this, we mask out the AS
2782 * only check on the local-admin sub-field. This is to
2784 * VNI as the RT for EBGP peering too.
2787 if (type
== ECOMMUNITY_ENCODE_AS
2788 || type
== ECOMMUNITY_ENCODE_AS4
2789 || type
== ECOMMUNITY_ENCODE_IP
) {
2790 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
2791 mask_ecom_global_admin(&eval_tmp
, eval
);
2792 irt
= lookup_import_rt(bgp
, &eval_tmp
);
2795 if (is_vni_present_in_irt_vnis(irt
->vnis
, vpn
))
2802 static int install_uninstall_routes_for_es(struct bgp
*bgp
,
2809 char buf
[PREFIX_STRLEN
];
2810 char buf1
[ESI_STR_LEN
];
2811 struct bgp_node
*rd_rn
, *rn
;
2812 struct bgp_table
*table
;
2813 struct bgp_info
*ri
;
2819 * Walk entire global routing table and evaluate routes which could be
2820 * imported into this VRF. Note that we need to loop through all global
2821 * routes to determine which route matches the import rt on vrf
2823 for (rd_rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_rn
;
2824 rd_rn
= bgp_route_next(rd_rn
)) {
2825 table
= (struct bgp_table
*)(rd_rn
->info
);
2829 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2830 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2832 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
2834 * Consider "valid" remote routes applicable for
2837 if (!(CHECK_FLAG(ri
->flags
, BGP_INFO_VALID
)
2838 && ri
->type
== ZEBRA_ROUTE_BGP
2839 && ri
->sub_type
== BGP_ROUTE_NORMAL
))
2842 if (!is_prefix_matching_for_es(evp
, es
))
2846 ret
= install_evpn_route_entry_in_es(
2849 ret
= uninstall_evpn_route_entry_in_es(
2854 "Failed to %s EVPN %s route in ESI %s",
2857 prefix2str(evp
, buf
,
2859 esi_to_str(&es
->esi
, buf1
,
2870 * Install or uninstall mac-ip routes are appropriate for this
2873 static int install_uninstall_routes_for_vrf(struct bgp
*bgp_vrf
, int install
)
2877 struct bgp_node
*rd_rn
, *rn
;
2878 struct bgp_table
*table
;
2879 struct bgp_info
*ri
;
2881 char buf
[PREFIX_STRLEN
];
2882 struct bgp
*bgp_def
= NULL
;
2886 bgp_def
= bgp_get_default();
2890 /* Walk entire global routing table and evaluate routes which could be
2891 * imported into this VRF. Note that we need to loop through all global
2892 * routes to determine which route matches the import rt on vrf
2894 for (rd_rn
= bgp_table_top(bgp_def
->rib
[afi
][safi
]); rd_rn
;
2895 rd_rn
= bgp_route_next(rd_rn
)) {
2896 table
= (struct bgp_table
*)(rd_rn
->info
);
2900 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2901 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2903 /* if not mac-ip route skip this route */
2904 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
2905 || evp
->prefix
.route_type
2906 == BGP_EVPN_IP_PREFIX_ROUTE
))
2909 /* if not a mac+ip route skip this route */
2910 if (!(is_evpn_prefix_ipaddr_v4(evp
)
2911 || is_evpn_prefix_ipaddr_v6(evp
)))
2914 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
2915 /* Consider "valid" remote routes applicable for
2918 if (!(CHECK_FLAG(ri
->flags
, BGP_INFO_VALID
)
2919 && ri
->type
== ZEBRA_ROUTE_BGP
2920 && ri
->sub_type
== BGP_ROUTE_NORMAL
))
2923 if (is_route_matching_for_vrf(bgp_vrf
, ri
)) {
2925 ret
= install_evpn_route_entry_in_vrf(
2928 ret
= uninstall_evpn_route_entry_in_vrf(
2933 "Failed to %s EVPN %s route in VRF %s",
2936 prefix2str(evp
, buf
,
2951 * Install or uninstall routes of specified type that are appropriate for this
2954 static int install_uninstall_routes_for_vni(struct bgp
*bgp
,
2955 struct bgpevpn
*vpn
,
2956 bgp_evpn_route_type rtype
,
2961 struct bgp_node
*rd_rn
, *rn
;
2962 struct bgp_table
*table
;
2963 struct bgp_info
*ri
;
2969 /* Walk entire global routing table and evaluate routes which could be
2970 * imported into this VPN. Note that we cannot just look at the routes
2972 * the VNI's RD - remote routes applicable for this VNI could have any
2975 /* EVPN routes are a 2-level table. */
2976 for (rd_rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_rn
;
2977 rd_rn
= bgp_route_next(rd_rn
)) {
2978 table
= (struct bgp_table
*)(rd_rn
->info
);
2982 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
2983 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
2985 if (evp
->prefix
.route_type
!= rtype
)
2988 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
2989 /* Consider "valid" remote routes applicable for
2991 if (!(CHECK_FLAG(ri
->flags
, BGP_INFO_VALID
)
2992 && ri
->type
== ZEBRA_ROUTE_BGP
2993 && ri
->sub_type
== BGP_ROUTE_NORMAL
))
2996 if (is_route_matching_for_vni(bgp
, vpn
, ri
)) {
2998 ret
= install_evpn_route_entry(
3001 ret
= uninstall_evpn_route_entry(
3006 "%u: Failed to %s EVPN %s route in VNI %u",
3010 rtype
== BGP_EVPN_MAC_IP_ROUTE
3024 /* Install any existing remote ES routes applicable for this ES into its routing
3025 * table. This is invoked when ES comes up.
3027 static int install_routes_for_es(struct bgp
*bgp
, struct evpnes
*es
)
3029 return install_uninstall_routes_for_es(bgp
, es
, 1);
3033 /* Install any existing remote routes applicable for this VRF into VRF RIB. This
3034 * is invoked upon l3vni-add or l3vni import rt change
3036 static int install_routes_for_vrf(struct bgp
*bgp_vrf
)
3038 install_uninstall_routes_for_vrf(bgp_vrf
, 1);
3043 * Install any existing remote routes applicable for this VNI into its
3044 * routing table. This is invoked when a VNI becomes "live" or its Import
3047 static int install_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3051 /* Install type-3 routes followed by type-2 routes - the ones applicable
3054 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3059 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3063 /* uninstall routes from l3vni vrf. */
3064 static int uninstall_routes_for_vrf(struct bgp
*bgp_vrf
)
3066 install_uninstall_routes_for_vrf(bgp_vrf
, 0);
3071 * Uninstall any existing remote routes for this VNI. One scenario in which
3072 * this is invoked is upon an import RT change.
3074 static int uninstall_routes_for_vni(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3078 /* Uninstall type-2 routes followed by type-3 routes - the ones
3082 ret
= install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_MAC_IP_ROUTE
,
3087 return install_uninstall_routes_for_vni(bgp
, vpn
, BGP_EVPN_IMET_ROUTE
,
3091 /* Install or unistall route in ES */
3092 static int install_uninstall_route_in_es(struct bgp
*bgp
, struct evpnes
*es
,
3093 afi_t afi
, safi_t safi
,
3094 struct prefix_evpn
*evp
,
3095 struct bgp_info
*ri
,
3099 char buf
[ESI_STR_LEN
];
3102 ret
= install_evpn_route_entry_in_es(bgp
, es
, evp
, ri
);
3104 ret
= uninstall_evpn_route_entry_in_es(bgp
, es
, evp
, ri
);
3107 zlog_err("%u: Failed to %s EVPN %s route in ESI %s",
3108 bgp
->vrf_id
, install
? "install" : "uninstall",
3110 esi_to_str(&evp
->prefix
.es_addr
.esi
, buf
,
3118 * Install or uninstall route in matching VRFs (list).
3120 static int install_uninstall_route_in_vrfs(struct bgp
*bgp_def
, afi_t afi
,
3121 safi_t safi
, struct prefix_evpn
*evp
,
3122 struct bgp_info
*ri
,
3123 struct list
*vrfs
, int install
)
3125 char buf
[PREFIX2STR_BUFFER
];
3126 struct bgp
*bgp_vrf
;
3127 struct listnode
*node
, *nnode
;
3129 /* Only type-2/type-5 routes go into a VRF */
3130 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3131 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3134 /* if it is type-2 route and not a mac+ip route skip this route */
3135 if ((evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
)
3136 && !(is_evpn_prefix_ipaddr_v4(evp
)
3137 || is_evpn_prefix_ipaddr_v6(evp
)))
3140 for (ALL_LIST_ELEMENTS(vrfs
, node
, nnode
, bgp_vrf
)) {
3144 ret
= install_evpn_route_entry_in_vrf(bgp_vrf
, evp
, ri
);
3146 ret
= uninstall_evpn_route_entry_in_vrf(bgp_vrf
, evp
,
3150 zlog_err("%u: Failed to %s prefix %s in VRF %s",
3152 install
? "install" : "uninstall",
3153 prefix2str(evp
, buf
, sizeof(buf
)),
3154 vrf_id_to_name(bgp_vrf
->vrf_id
));
3163 * Install or uninstall route in matching VNIs (list).
3165 static int install_uninstall_route_in_vnis(struct bgp
*bgp
, afi_t afi
,
3166 safi_t safi
, struct prefix_evpn
*evp
,
3167 struct bgp_info
*ri
,
3168 struct list
*vnis
, int install
)
3170 struct bgpevpn
*vpn
;
3171 struct listnode
*node
, *nnode
;
3173 for (ALL_LIST_ELEMENTS(vnis
, node
, nnode
, vpn
)) {
3176 if (!is_vni_live(vpn
))
3180 ret
= install_evpn_route_entry(bgp
, vpn
, evp
, ri
);
3182 ret
= uninstall_evpn_route_entry(bgp
, vpn
, evp
, ri
);
3185 zlog_err("%u: Failed to %s EVPN %s route in VNI %u",
3186 bgp
->vrf_id
, install
? "install" : "uninstall",
3187 evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3199 * Install or uninstall route for appropriate VNIs/ESIs.
3201 static int install_uninstall_evpn_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
3202 struct prefix
*p
, struct bgp_info
*ri
,
3205 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
3206 struct attr
*attr
= ri
->attr
;
3207 struct ecommunity
*ecom
;
3212 /* Only type-2, type-3, type-4 and type-5 are supported currently */
3213 if (!(evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
3214 || evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
3215 || evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
3216 || evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
))
3219 /* If we don't have Route Target, nothing much to do. */
3220 if (!(attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
)))
3223 ecom
= attr
->ecommunity
;
3224 if (!ecom
|| !ecom
->size
)
3227 /* An EVPN route belongs to a VNI or a VRF or an ESI based on the RTs
3228 * attached to the route */
3229 for (i
= 0; i
< ecom
->size
; i
++) {
3231 uint8_t type
, sub_type
;
3232 struct ecommunity_val
*eval
;
3233 struct ecommunity_val eval_tmp
;
3234 struct irt_node
*irt
; /* import rt for l2vni */
3235 struct vrf_irt_node
*vrf_irt
; /* import rt for l3vni */
3238 /* Only deal with RTs */
3239 pnt
= (ecom
->val
+ (i
* ECOMMUNITY_SIZE
));
3240 eval
= (struct ecommunity_val
*)(ecom
->val
3241 + (i
* ECOMMUNITY_SIZE
));
3244 if (sub_type
!= ECOMMUNITY_ROUTE_TARGET
)
3248 * macip routes (type-2) are imported into VNI and VRF tables.
3249 * IMET route is imported into VNI table.
3250 * prefix routes are imported into VRF table.
3252 if (evp
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
||
3253 evp
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
||
3254 evp
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
3256 irt
= lookup_import_rt(bgp
, eval
);
3258 install_uninstall_route_in_vnis(bgp
, afi
, safi
,
3263 vrf_irt
= lookup_vrf_import_rt(eval
);
3265 install_uninstall_route_in_vrfs(bgp
, afi
, safi
,
3270 /* Also check for non-exact match.
3271 * In this, we mask out the AS and
3272 * only check on the local-admin sub-field.
3273 * This is to facilitate using
3274 * VNI as the RT for EBGP peering too.
3278 if (type
== ECOMMUNITY_ENCODE_AS
3279 || type
== ECOMMUNITY_ENCODE_AS4
3280 || type
== ECOMMUNITY_ENCODE_IP
) {
3281 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
3282 mask_ecom_global_admin(&eval_tmp
, eval
);
3283 irt
= lookup_import_rt(bgp
, &eval_tmp
);
3284 vrf_irt
= lookup_vrf_import_rt(&eval_tmp
);
3288 install_uninstall_route_in_vnis(bgp
, afi
, safi
,
3293 install_uninstall_route_in_vrfs(bgp
, afi
, safi
,
3299 /* es route is imported into the es table */
3300 if (evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) {
3302 /* we will match based on the entire esi to avoid
3303 * imoort of an es route for esi2 into esi1
3305 es
= bgp_evpn_lookup_es(bgp
, &evp
->prefix
.es_addr
.esi
);
3306 if (es
&& is_es_local(es
))
3307 install_uninstall_route_in_es(bgp
, es
,
3317 * delete and withdraw all ipv4 and ipv6 routes in the vrf table as type-5
3320 static void delete_withdraw_vrf_routes(struct bgp
*bgp_vrf
)
3322 /* delete all ipv4 routes and withdraw from peers */
3323 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
3324 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
3326 /* delete all ipv6 routes and withdraw from peers */
3327 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
3328 bgp_evpn_withdraw_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
3332 * update and advertise all ipv4 and ipv6 routes in thr vrf table as type-5
3335 static void update_advertise_vrf_routes(struct bgp
*bgp_vrf
)
3337 /* update all ipv4 routes */
3338 if (advertise_type5_routes(bgp_vrf
, AFI_IP
))
3339 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP
, SAFI_UNICAST
);
3341 /* update all ipv6 routes */
3342 if (advertise_type5_routes(bgp_vrf
, AFI_IP6
))
3343 bgp_evpn_advertise_type5_routes(bgp_vrf
, AFI_IP6
, SAFI_UNICAST
);
3347 * update and advertise local routes for a VRF as type-5 routes.
3348 * This is invoked upon RD change for a VRF. Note taht the processing is only
3349 * done in the global route table using the routes which already exist in the
3352 static void update_router_id_vrf(struct bgp
*bgp_vrf
)
3354 /* skip if the RD is configured */
3355 if (is_vrf_rd_configured(bgp_vrf
))
3358 /* derive the RD for the VRF based on new router-id */
3359 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
3361 /* update advertise ipv4|ipv6 routes as type-5 routes */
3362 update_advertise_vrf_routes(bgp_vrf
);
3366 * Delete and withdraw all type-5 routes for the RD corresponding to VRF.
3367 * This is invoked upon VRF RD change. The processing is done only from global
3370 static void withdraw_router_id_vrf(struct bgp
*bgp_vrf
)
3372 /* skip if the RD is configured */
3373 if (is_vrf_rd_configured(bgp_vrf
))
3376 /* delete/withdraw ipv4|ipv6 routes as type-5 routes */
3377 delete_withdraw_vrf_routes(bgp_vrf
);
3381 * Update and advertise local routes for a VNI. Invoked upon router-id
3382 * change. Note that the processing is done only on the global route table
3383 * using routes that already exist in the per-VNI table.
3385 static int update_advertise_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3387 struct prefix_evpn p
;
3388 struct bgp_node
*rn
, *global_rn
;
3389 struct bgp_info
*ri
, *global_ri
;
3391 afi_t afi
= AFI_L2VPN
;
3392 safi_t safi
= SAFI_EVPN
;
3394 /* Locate type-3 route for VNI in the per-VNI table and use its
3395 * attributes to create and advertise the type-3 route for this VNI
3396 * in the global table.
3398 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
3399 rn
= bgp_node_lookup(vpn
->route_table
, (struct prefix
*)&p
);
3400 if (!rn
) /* unexpected */
3402 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3403 if (ri
->peer
== bgp
->peer_self
&& ri
->type
== ZEBRA_ROUTE_BGP
3404 && ri
->sub_type
== BGP_ROUTE_STATIC
)
3406 if (!ri
) /* unexpected */
3410 global_rn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
3411 (struct prefix
*)&p
, &vpn
->prd
);
3412 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, global_rn
, attr
, 1, 0, &ri
,
3415 /* Schedule for processing and unlock node. */
3416 bgp_process(bgp
, global_rn
, afi
, safi
);
3417 bgp_unlock_node(global_rn
);
3419 /* Now, walk this VNI's route table and use the route and its attribute
3420 * to create and schedule route in global table.
3422 for (rn
= bgp_table_top(vpn
->route_table
); rn
;
3423 rn
= bgp_route_next(rn
)) {
3424 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
3426 /* Identify MAC-IP local routes. */
3427 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3430 for (ri
= rn
->info
; ri
; ri
= ri
->next
)
3431 if (ri
->peer
== bgp
->peer_self
3432 && ri
->type
== ZEBRA_ROUTE_BGP
3433 && ri
->sub_type
== BGP_ROUTE_STATIC
)
3438 /* Create route in global routing table using this route entry's
3442 global_rn
= bgp_afi_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
3443 (struct prefix
*)evp
, &vpn
->prd
);
3445 update_evpn_route_entry(bgp
, vpn
, afi
, safi
, global_rn
, attr
, 1,
3448 /* Schedule for processing and unlock node. */
3449 bgp_process(bgp
, global_rn
, afi
, safi
);
3450 bgp_unlock_node(global_rn
);
3457 * Delete (and withdraw) local routes for a VNI - only from the global
3458 * table. Invoked upon router-id change.
3460 static int delete_withdraw_vni_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
3463 struct prefix_evpn p
;
3464 struct bgp_node
*global_rn
;
3465 struct bgp_info
*ri
;
3466 afi_t afi
= AFI_L2VPN
;
3467 safi_t safi
= SAFI_EVPN
;
3469 /* Delete and withdraw locally learnt type-2 routes (MACIP)
3470 * for this VNI - from the global table.
3472 ret
= delete_global_type2_routes(bgp
, vpn
);
3476 /* Remove type-3 route for this VNI from global table. */
3477 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
3478 global_rn
= bgp_afi_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
3479 (struct prefix
*)&p
, &vpn
->prd
);
3481 /* Delete route entry in the global EVPN table. */
3482 delete_evpn_route_entry(bgp
, afi
, safi
, global_rn
, &ri
);
3484 /* Schedule for processing - withdraws to peers happen from
3488 bgp_process(bgp
, global_rn
, afi
, safi
);
3489 bgp_unlock_node(global_rn
);
3496 * Handle router-id change. Update and advertise local routes corresponding
3497 * to this VNI from peers. Note that this is invoked after updating the
3498 * router-id. The routes in the per-VNI table are used to create routes in
3499 * the global table and schedule them.
3501 static void update_router_id_vni(struct hash_backet
*backet
, struct bgp
*bgp
)
3503 struct bgpevpn
*vpn
;
3505 vpn
= (struct bgpevpn
*)backet
->data
;
3508 zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__
);
3512 /* Skip VNIs with configured RD. */
3513 if (is_rd_configured(vpn
))
3516 bgp_evpn_derive_auto_rd(bgp
, vpn
);
3517 update_advertise_vni_routes(bgp
, vpn
);
3521 * Handle router-id change. Delete and withdraw local routes corresponding
3522 * to this VNI from peers. Note that this is invoked prior to updating
3523 * the router-id and is done only on the global route table, the routes
3524 * are needed in the per-VNI table to re-advertise with new router id.
3526 static void withdraw_router_id_vni(struct hash_backet
*backet
, struct bgp
*bgp
)
3528 struct bgpevpn
*vpn
;
3530 vpn
= (struct bgpevpn
*)backet
->data
;
3533 zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__
);
3537 /* Skip VNIs with configured RD. */
3538 if (is_rd_configured(vpn
))
3541 delete_withdraw_vni_routes(bgp
, vpn
);
3545 * Process received EVPN type-2 route (advertise or withdraw).
3547 static int process_type2_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
3548 struct attr
*attr
, uint8_t *pfx
, int psize
,
3549 uint32_t addpath_id
)
3551 struct prefix_rd prd
;
3552 struct prefix_evpn p
;
3553 struct bgp_route_evpn evpn
;
3555 uint8_t macaddr_len
;
3556 mpls_label_t label
[BGP_MAX_LABELS
]; /* holds the VNI(s) as in packet */
3557 uint32_t num_labels
= 0;
3561 /* Type-2 route should be either 33, 37 or 49 bytes or an
3562 * additional 3 bytes if there is a second label (VNI):
3563 * RD (8), ESI (10), Eth Tag (4), MAC Addr Len (1),
3564 * MAC Addr (6), IP len (1), IP (0, 4 or 16),
3565 * MPLS Lbl1 (3), MPLS Lbl2 (0 or 3)
3567 if (psize
!= 33 && psize
!= 37 && psize
!= 49 && psize
!= 36
3568 && psize
!= 40 && psize
!= 52) {
3569 zlog_err("%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
3570 peer
->bgp
->vrf_id
, peer
->host
, psize
);
3574 memset(&evpn
, 0, sizeof(evpn
));
3576 /* Make prefix_rd */
3577 prd
.family
= AF_UNSPEC
;
3579 memcpy(&prd
.val
, pfx
, 8);
3582 /* Make EVPN prefix. */
3583 memset(&p
, 0, sizeof(struct prefix_evpn
));
3585 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
3586 p
.prefix
.route_type
= BGP_EVPN_MAC_IP_ROUTE
;
3588 /* Copy Ethernet Seg Identifier */
3589 memcpy(&evpn
.eth_s_id
.val
, pfx
, ESI_LEN
);
3592 /* Copy Ethernet Tag */
3593 memcpy(ð_tag
, pfx
, 4);
3594 p
.prefix
.macip_addr
.eth_tag
= ntohl(eth_tag
);
3597 /* Get the MAC Addr len */
3598 macaddr_len
= *pfx
++;
3600 /* Get the MAC Addr */
3601 if (macaddr_len
== (ETH_ALEN
* 8)) {
3602 memcpy(&p
.prefix
.macip_addr
.mac
.octet
, pfx
, ETH_ALEN
);
3606 "%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
3607 peer
->bgp
->vrf_id
, peer
->host
, macaddr_len
);
3613 ipaddr_len
= *pfx
++;
3614 if (ipaddr_len
!= 0 && ipaddr_len
!= IPV4_MAX_BITLEN
3615 && ipaddr_len
!= IPV6_MAX_BITLEN
) {
3617 "%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
3618 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
3623 ipaddr_len
/= 8; /* Convert to bytes. */
3624 p
.prefix
.macip_addr
.ip
.ipa_type
= (ipaddr_len
== IPV4_MAX_BYTELEN
)
3627 memcpy(&p
.prefix
.macip_addr
.ip
.ip
.addr
, pfx
, ipaddr_len
);
3631 /* Get the VNI(s). Stored as bytes here. */
3633 memset(label
, 0, sizeof(label
));
3634 memcpy(&label
[0], pfx
, BGP_LABEL_BYTES
);
3635 pfx
+= BGP_LABEL_BYTES
;
3636 psize
-= (33 + ipaddr_len
);
3637 /* Do we have a second VNI? */
3640 memcpy(&label
[1], pfx
, BGP_LABEL_BYTES
);
3642 * If in future, we are required to access additional fields,
3643 * we MUST increment pfx by BGP_LABEL_BYTES in before reading
3648 /* Process the route. */
3650 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3651 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3652 &prd
, &label
[0], num_labels
, 0, &evpn
);
3654 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3655 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3656 &prd
, &label
[0], num_labels
, &evpn
);
3661 * Process received EVPN type-3 route (advertise or withdraw).
3663 static int process_type3_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
3664 struct attr
*attr
, uint8_t *pfx
, int psize
,
3665 uint32_t addpath_id
)
3667 struct prefix_rd prd
;
3668 struct prefix_evpn p
;
3673 /* Type-3 route should be either 17 or 29 bytes: RD (8), Eth Tag (4),
3674 * IP len (1) and IP (4 or 16).
3676 if (psize
!= 17 && psize
!= 29) {
3677 zlog_err("%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
3678 peer
->bgp
->vrf_id
, peer
->host
, psize
);
3682 /* If PMSI is present, log if it is anything other than IR.
3683 * Note: We just simply ignore the values as it is not clear if
3684 * doing anything else is better.
3687 (attr
->flag
& ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL
))) {
3688 if (attr
->pmsi_tnl_type
!= PMSI_TNLTYPE_INGR_REPL
) {
3689 zlog_warn("%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d",
3690 peer
->bgp
->vrf_id
, peer
->host
,
3691 attr
->pmsi_tnl_type
);
3695 /* Make prefix_rd */
3696 prd
.family
= AF_UNSPEC
;
3698 memcpy(&prd
.val
, pfx
, 8);
3701 /* Make EVPN prefix. */
3702 memset(&p
, 0, sizeof(struct prefix_evpn
));
3704 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
3705 p
.prefix
.route_type
= BGP_EVPN_IMET_ROUTE
;
3707 /* Copy Ethernet Tag */
3708 memcpy(ð_tag
, pfx
, 4);
3709 p
.prefix
.imet_addr
.eth_tag
= ntohl(eth_tag
);
3713 ipaddr_len
= *pfx
++;
3714 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
3715 p
.prefix
.imet_addr
.ip
.ipa_type
= IPADDR_V4
;
3716 memcpy(&p
.prefix
.imet_addr
.ip
.ip
.addr
, pfx
, IPV4_MAX_BYTELEN
);
3719 "%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
3720 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
3724 /* Process the route. */
3726 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3727 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3728 &prd
, NULL
, 0, 0, NULL
);
3730 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3731 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3732 &prd
, NULL
, 0, NULL
);
3737 * Process received EVPN type-4 route (advertise or withdraw).
3739 static int process_type4_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
3740 struct attr
*attr
, uint8_t *pfx
, int psize
,
3741 uint32_t addpath_id
)
3746 struct in_addr vtep_ip
;
3747 struct prefix_rd prd
;
3748 struct prefix_evpn p
;
3750 /* Type-4 route should be either 23 or 35 bytes
3751 * RD (8), ESI (10), ip-len (1), ip (4 or 16)
3753 if (psize
!= 23 && psize
!= 35) {
3754 zlog_err("%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
3755 peer
->bgp
->vrf_id
, peer
->host
, psize
);
3759 /* Make prefix_rd */
3760 prd
.family
= AF_UNSPEC
;
3762 memcpy(&prd
.val
, pfx
, 8);
3766 memcpy(&esi
, pfx
, ESI_BYTES
);
3771 ipaddr_len
= *pfx
++;
3772 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
3773 memcpy(&vtep_ip
, pfx
, IPV4_MAX_BYTELEN
);
3776 "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
3777 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
3781 build_evpn_type4_prefix(&p
, &esi
, vtep_ip
);
3782 /* Process the route. */
3784 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3785 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3786 &prd
, NULL
, 0, 0, NULL
);
3788 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3789 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3790 &prd
, NULL
, 0, NULL
);
3797 * Process received EVPN type-5 route (advertise or withdraw).
3799 static int process_type5_route(struct peer
*peer
, afi_t afi
, safi_t safi
,
3800 struct attr
*attr
, uint8_t *pfx
, int psize
,
3801 uint32_t addpath_id
, int withdraw
)
3803 struct prefix_rd prd
;
3804 struct prefix_evpn p
;
3805 struct bgp_route_evpn evpn
;
3808 mpls_label_t label
; /* holds the VNI as in the packet */
3811 /* Type-5 route should be 34 or 58 bytes:
3812 * RD (8), ESI (10), Eth Tag (4), IP len (1), IP (4 or 16),
3813 * GW (4 or 16) and VNI (3).
3814 * Note that the IP and GW should both be IPv4 or both IPv6.
3816 if (psize
!= 34 && psize
!= 58) {
3817 zlog_err("%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
3818 peer
->bgp
->vrf_id
, peer
->host
, psize
);
3822 /* Make prefix_rd */
3823 prd
.family
= AF_UNSPEC
;
3825 memcpy(&prd
.val
, pfx
, 8);
3828 /* Make EVPN prefix. */
3829 memset(&p
, 0, sizeof(struct prefix_evpn
));
3831 p
.prefixlen
= EVPN_ROUTE_PREFIXLEN
;
3832 p
.prefix
.route_type
= BGP_EVPN_IP_PREFIX_ROUTE
;
3834 /* Additional information outside of prefix - ESI and GW IP */
3835 memset(&evpn
, 0, sizeof(evpn
));
3838 memcpy(&evpn
.eth_s_id
.val
, pfx
, 10);
3841 /* Fetch Ethernet Tag. */
3842 memcpy(ð_tag
, pfx
, 4);
3843 p
.prefix
.prefix_addr
.eth_tag
= ntohl(eth_tag
);
3846 /* Fetch IP prefix length. */
3848 if (ippfx_len
> IPV6_MAX_BITLEN
) {
3850 "%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
3851 peer
->bgp
->vrf_id
, peer
->host
, ippfx_len
);
3854 p
.prefix
.prefix_addr
.ip_prefix_length
= ippfx_len
;
3856 /* Determine IPv4 or IPv6 prefix */
3857 /* Since the address and GW are from the same family, this just becomes
3858 * a simple check on the total size.
3861 SET_IPADDR_V4(&p
.prefix
.prefix_addr
.ip
);
3862 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v4
, pfx
, 4);
3864 memcpy(&evpn
.gw_ip
.ipv4
, pfx
, 4);
3867 SET_IPADDR_V6(&p
.prefix
.prefix_addr
.ip
);
3868 memcpy(&p
.prefix
.prefix_addr
.ip
.ipaddr_v6
, pfx
, 16);
3870 memcpy(&evpn
.gw_ip
.ipv6
, pfx
, 16);
3874 /* Get the VNI (in MPLS label field). Stored as bytes here. */
3875 memset(&label
, 0, sizeof(label
));
3876 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
3879 * If in future, we are required to access additional fields,
3880 * we MUST increment pfx by BGP_LABEL_BYTES in before reading the next
3884 /* Process the route. */
3886 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3887 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3888 &prd
, &label
, 1, 0, &evpn
);
3890 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
3891 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
3892 &prd
, &label
, 1, &evpn
);
3897 static void evpn_mpattr_encode_type5(struct stream
*s
, struct prefix
*p
,
3898 struct prefix_rd
*prd
, mpls_label_t
*label
,
3899 uint32_t num_labels
, struct attr
*attr
)
3903 struct evpn_addr
*p_evpn_p
;
3905 memset(&temp
, 0, 16);
3906 if (p
->family
!= AF_EVPN
)
3908 p_evpn_p
= &(p
->u
.prefix_evpn
);
3910 /* len denites the total len of IP and GW-IP in the route
3911 IP and GW-IP have to be both ipv4 or ipv6
3913 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
3914 len
= 8; /* IP and GWIP are both ipv4 */
3916 len
= 32; /* IP and GWIP are both ipv6 */
3917 /* Prefix contains RD, ESI, EthTag, IP length, IP, GWIP and VNI */
3918 stream_putc(s
, 8 + 10 + 4 + 1 + len
+ 3);
3919 stream_put(s
, prd
->val
, 8);
3921 stream_put(s
, &(attr
->evpn_overlay
.eth_s_id
), 10);
3923 stream_put(s
, &temp
, 10);
3924 stream_putl(s
, p_evpn_p
->prefix_addr
.eth_tag
);
3925 stream_putc(s
, p_evpn_p
->prefix_addr
.ip_prefix_length
);
3926 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
3927 stream_put_ipv4(s
, p_evpn_p
->prefix_addr
.ip
.ipaddr_v4
.s_addr
);
3929 stream_put(s
, &p_evpn_p
->prefix_addr
.ip
.ipaddr_v6
, 16);
3931 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
3933 attr
->evpn_overlay
.gw_ip
.ipv4
.s_addr
);
3935 stream_put(s
, &(attr
->evpn_overlay
.gw_ip
.ipv6
), 16);
3937 if (IS_IPADDR_V4(&p_evpn_p
->prefix_addr
.ip
))
3938 stream_put_ipv4(s
, 0);
3940 stream_put(s
, &temp
, 16);
3944 stream_put(s
, label
, 3);
3950 * Cleanup specific VNI upon EVPN (advertise-all-vni) being disabled.
3952 static void cleanup_vni_on_disable(struct hash_backet
*backet
, struct bgp
*bgp
)
3954 struct bgpevpn
*vpn
= (struct bgpevpn
*)backet
->data
;
3956 /* Remove EVPN routes and schedule for processing. */
3957 delete_routes_for_vni(bgp
, vpn
);
3959 /* Clear "live" flag and see if hash needs to be freed. */
3960 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
3961 if (!is_vni_configured(vpn
))
3962 bgp_evpn_free(bgp
, vpn
);
3966 * Free a VNI entry; iterator function called during cleanup.
3968 static void free_vni_entry(struct hash_backet
*backet
, struct bgp
*bgp
)
3970 struct bgpevpn
*vpn
;
3972 vpn
= (struct bgpevpn
*)backet
->data
;
3973 delete_all_vni_routes(bgp
, vpn
);
3974 bgp_evpn_free(bgp
, vpn
);
3978 * Derive AUTO import RT for BGP VRF - L3VNI
3980 static void evpn_auto_rt_import_add_for_vrf(struct bgp
*bgp_vrf
)
3982 struct bgp
*bgp_def
= NULL
;
3984 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
);
3985 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
3988 bgp_def
= bgp_get_default();
3991 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
3995 * Delete AUTO import RT from BGP VRF - L3VNI
3997 static void evpn_auto_rt_import_delete_for_vrf(struct bgp
*bgp_vrf
)
3999 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_import_rtl
);
4003 * Derive AUTO export RT for BGP VRF - L3VNI
4005 static void evpn_auto_rt_export_add_for_vrf(struct bgp
*bgp_vrf
)
4007 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
4008 form_auto_rt(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
);
4012 * Delete AUTO export RT from BGP VRF - L3VNI
4014 static void evpn_auto_rt_export_delete_for_vrf(struct bgp
*bgp_vrf
)
4016 evpn_rt_delete_auto(bgp_vrf
, bgp_vrf
->l3vni
, bgp_vrf
->vrf_export_rtl
);
4019 static void bgp_evpn_handle_export_rt_change_for_vrf(struct bgp
*bgp_vrf
)
4021 struct bgp
*bgp_def
= NULL
;
4022 struct listnode
*node
= NULL
;
4023 struct bgpevpn
*vpn
= NULL
;
4025 bgp_def
= bgp_get_default();
4029 /* update all type-5 routes */
4030 update_advertise_vrf_routes(bgp_vrf
);
4032 /* update all type-2 routes */
4033 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
4034 update_routes_for_vni(bgp_def
, vpn
);
4038 * Handle autort change for a given VNI.
4040 static void update_autort_vni(struct hash_backet
*backet
, struct bgp
*bgp
)
4042 struct bgpevpn
*vpn
= backet
->data
;
4045 zlog_warn("%s: VNI hash entry for VNI not found", __PRETTY_FUNCTION__
);
4049 if (!is_import_rt_configured(vpn
)) {
4050 if (is_vni_live(vpn
))
4051 bgp_evpn_uninstall_routes(bgp
, vpn
);
4052 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
4053 list_delete_all_node(vpn
->import_rtl
);
4054 bgp_evpn_derive_auto_rt_import(bgp
, vpn
);
4055 if (is_vni_live(vpn
))
4056 bgp_evpn_install_routes(bgp
, vpn
);
4058 if (!is_export_rt_configured(vpn
)) {
4059 list_delete_all_node(vpn
->export_rtl
);
4060 bgp_evpn_derive_auto_rt_export(bgp
, vpn
);
4061 if (is_vni_live(vpn
))
4062 bgp_evpn_handle_export_rt_change(bgp
, vpn
);
4070 /* withdraw type-5 route corresponding to ip prefix */
4071 void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
, struct prefix
*p
,
4072 afi_t afi
, safi_t safi
)
4075 struct prefix_evpn evp
;
4076 char buf
[PREFIX_STRLEN
];
4078 build_type5_prefix_from_ip_prefix(&evp
, p
);
4079 ret
= delete_evpn_type5_route(bgp_vrf
, &evp
);
4082 "%u failed to delete type-5 route for prefix %s in vrf %s",
4083 bgp_vrf
->vrf_id
, prefix2str(p
, buf
, sizeof(buf
)),
4084 vrf_id_to_name(bgp_vrf
->vrf_id
));
4088 /* withdraw all type-5 routes for an address family */
4089 void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
, safi_t safi
)
4091 struct bgp_table
*table
= NULL
;
4092 struct bgp_node
*rn
= NULL
;
4093 struct bgp_info
*ri
;
4095 table
= bgp_vrf
->rib
[afi
][safi
];
4096 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
4097 /* Only care about "selected" routes - non-imported. */
4098 /* TODO: Support for AddPath for EVPN. */
4099 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
4100 if (CHECK_FLAG(ri
->flags
, BGP_INFO_SELECTED
)
4101 && (!ri
->extra
|| !ri
->extra
->parent
)) {
4102 bgp_evpn_withdraw_type5_route(bgp_vrf
, &rn
->p
,
4111 * Advertise IP prefix as type-5 route. The afi/safi and src_attr passed
4112 * to this function correspond to those of the source IP prefix (best
4113 * path in the case of the attr. In the case of a local prefix (when we
4114 * are advertising local subnets), the src_attr will be NULL.
4116 void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
, struct prefix
*p
,
4117 struct attr
*src_attr
, afi_t afi
,
4121 struct prefix_evpn evp
;
4122 char buf
[PREFIX_STRLEN
];
4124 build_type5_prefix_from_ip_prefix(&evp
, p
);
4125 ret
= update_evpn_type5_route(bgp_vrf
, &evp
, src_attr
);
4127 zlog_err("%u: Failed to create type-5 route for prefix %s",
4128 bgp_vrf
->vrf_id
, prefix2str(p
, buf
, sizeof(buf
)));
4131 /* Inject all prefixes of a particular address-family (currently, IPv4 or
4132 * IPv6 unicast) into EVPN as type-5 routes. This is invoked when the
4133 * advertisement is enabled.
4135 void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
4138 struct bgp_table
*table
= NULL
;
4139 struct bgp_node
*rn
= NULL
;
4140 struct bgp_info
*ri
;
4142 table
= bgp_vrf
->rib
[afi
][safi
];
4143 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
4144 /* Need to identify the "selected" route entry to use its
4145 * attribute. Also, we only consider "non-imported" routes.
4146 * TODO: Support for AddPath for EVPN.
4148 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
4149 if (CHECK_FLAG(ri
->flags
, BGP_INFO_SELECTED
)
4150 && (!ri
->extra
|| !ri
->extra
->parent
)) {
4152 /* apply the route-map */
4153 if (bgp_vrf
->adv_cmd_rmap
[afi
][safi
].map
) {
4156 ret
= route_map_apply(
4157 bgp_vrf
->adv_cmd_rmap
[afi
][safi
]
4159 &rn
->p
, RMAP_BGP
, ri
);
4160 if (ret
== RMAP_DENYMATCH
)
4163 bgp_evpn_advertise_type5_route(
4164 bgp_vrf
, &rn
->p
, ri
->attr
, afi
, safi
);
4171 void evpn_rt_delete_auto(struct bgp
*bgp
, vni_t vni
, struct list
*rtl
)
4173 struct listnode
*node
, *nnode
, *node_to_del
;
4174 struct ecommunity
*ecom
, *ecom_auto
;
4175 struct ecommunity_val eval
;
4177 if (bgp
->advertise_autort_rfc8365
)
4178 vni
|= EVPN_AUTORT_VXLAN
;
4179 encode_route_target_as((bgp
->as
& 0xFFFF), vni
, &eval
);
4181 ecom_auto
= ecommunity_new();
4182 ecommunity_add_val(ecom_auto
, &eval
);
4185 for (ALL_LIST_ELEMENTS(rtl
, node
, nnode
, ecom
)) {
4186 if (ecommunity_match(ecom
, ecom_auto
)) {
4187 ecommunity_free(&ecom
);
4193 list_delete_node(rtl
, node_to_del
);
4195 ecommunity_free(&ecom_auto
);
4198 void bgp_evpn_configure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
4199 struct ecommunity
*ecomadd
)
4201 /* uninstall routes from vrf */
4202 uninstall_routes_for_vrf(bgp_vrf
);
4204 /* Cleanup the RT to VRF mapping */
4205 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
4207 /* Remove auto generated RT */
4208 evpn_auto_rt_import_delete_for_vrf(bgp_vrf
);
4210 /* Add the newly configured RT to RT list */
4211 listnode_add_sort(bgp_vrf
->vrf_import_rtl
, ecomadd
);
4212 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
4214 /* map VRF to its RTs */
4215 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
4217 /* install routes matching the new VRF */
4218 install_routes_for_vrf(bgp_vrf
);
4221 void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp
*bgp_vrf
,
4222 struct ecommunity
*ecomdel
)
4224 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
4225 struct ecommunity
*ecom
= NULL
;
4227 /* uninstall routes from vrf */
4228 uninstall_routes_for_vrf(bgp_vrf
);
4230 /* Cleanup the RT to VRF mapping */
4231 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
4233 /* remove the RT from the RT list */
4234 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, ecom
)) {
4235 if (ecommunity_match(ecom
, ecomdel
)) {
4236 ecommunity_free(&ecom
);
4243 list_delete_node(bgp_vrf
->vrf_import_rtl
, node_to_del
);
4245 /* fallback to auto import rt, if this was the last RT */
4246 if (list_isempty(bgp_vrf
->vrf_import_rtl
)) {
4247 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
);
4248 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
4251 /* map VRFs to its RTs */
4252 bgp_evpn_map_vrf_to_its_rts(bgp_vrf
);
4254 /* install routes matching this new RT */
4255 install_routes_for_vrf(bgp_vrf
);
4258 void bgp_evpn_configure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
4259 struct ecommunity
*ecomadd
)
4261 /* remove auto-generated RT */
4262 evpn_auto_rt_export_delete_for_vrf(bgp_vrf
);
4264 /* Add the new RT to the RT list */
4265 listnode_add_sort(bgp_vrf
->vrf_export_rtl
, ecomadd
);
4266 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
4268 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
4271 void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp
*bgp_vrf
,
4272 struct ecommunity
*ecomdel
)
4274 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
4275 struct ecommunity
*ecom
= NULL
;
4277 /* Remove the RT from the RT list */
4278 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_export_rtl
, node
, nnode
, ecom
)) {
4279 if (ecommunity_match(ecom
, ecomdel
)) {
4280 ecommunity_free(&ecom
);
4287 list_delete_node(bgp_vrf
->vrf_export_rtl
, node_to_del
);
4290 * Temporary assert to make SA happy.
4291 * The ALL_LIST_ELEMENTS macro above has a NULL check
4292 * which means that SA is going to complain about
4293 * the list_isempty call, which doesn't NULL check.
4294 * So until we get this situation cleaned up, here
4297 assert(bgp_vrf
->vrf_export_rtl
);
4299 /* fall back to auto-generated RT if this was the last RT */
4300 if (list_isempty(bgp_vrf
->vrf_export_rtl
)) {
4301 UNSET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
);
4302 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
4305 bgp_evpn_handle_export_rt_change_for_vrf(bgp_vrf
);
4309 * Handle change to BGP router id. This is invoked twice by the change
4310 * handler, first before the router id has been changed and then after
4311 * the router id has been changed. The first invocation will result in
4312 * local routes for all VNIs/VRF being deleted and withdrawn and the next
4313 * will result in the routes being re-advertised.
4315 void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
)
4319 /* delete and withdraw all the type-5 routes
4320 stored in the global table for this vrf
4322 withdraw_router_id_vrf(bgp
);
4324 /* delete all the VNI routes (type-2/type-3) routes for all the
4327 hash_iterate(bgp
->vnihash
,
4328 (void (*)(struct hash_backet
*,
4329 void *))withdraw_router_id_vni
,
4333 /* advertise all routes in the vrf as type-5 routes with the new
4336 update_router_id_vrf(bgp
);
4338 /* advertise all the VNI routes (type-2/type-3) routes with the
4341 hash_iterate(bgp
->vnihash
,
4342 (void (*)(struct hash_backet
*,
4343 void *))update_router_id_vni
,
4349 * Handle change to auto-RT algorithm - update and advertise local routes.
4351 void bgp_evpn_handle_autort_change(struct bgp
*bgp
)
4353 hash_iterate(bgp
->vnihash
,
4354 (void (*)(struct hash_backet
*,
4355 void*))update_autort_vni
,
4360 * Handle change to export RT - update and advertise local routes.
4362 int bgp_evpn_handle_export_rt_change(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4364 return update_routes_for_vni(bgp
, vpn
);
4367 void bgp_evpn_handle_vrf_rd_change(struct bgp
*bgp_vrf
, int withdraw
)
4370 delete_withdraw_vrf_routes(bgp_vrf
);
4372 update_advertise_vrf_routes(bgp_vrf
);
4376 * Handle change to RD. This is invoked twice by the change handler,
4377 * first before the RD has been changed and then after the RD has
4378 * been changed. The first invocation will result in local routes
4379 * of this VNI being deleted and withdrawn and the next will result
4380 * in the routes being re-advertised.
4382 void bgp_evpn_handle_rd_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
4386 delete_withdraw_vni_routes(bgp
, vpn
);
4388 update_advertise_vni_routes(bgp
, vpn
);
4392 * Install routes for this VNI. Invoked upon change to Import RT.
4394 int bgp_evpn_install_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4396 return install_routes_for_vni(bgp
, vpn
);
4400 * Uninstall all routes installed for this VNI. Invoked upon change
4403 int bgp_evpn_uninstall_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4405 return uninstall_routes_for_vni(bgp
, vpn
);
4409 * TODO: Hardcoded for a maximum of 2 VNIs right now
4411 char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
, char *buf
,
4416 vni1
= label2vni(label
);
4417 if (num_labels
== 2) {
4418 vni2
= label2vni(label
+ 1);
4419 snprintf(buf
, len
, "%u/%u", vni1
, vni2
);
4421 snprintf(buf
, len
, "%u", vni1
);
4426 * Function to convert evpn route to json format.
4427 * NOTE: We don't use prefix2str as the output here is a bit different.
4429 void bgp_evpn_route2json(struct prefix_evpn
*p
, json_object
*json
)
4431 char buf1
[ETHER_ADDR_STRLEN
];
4432 char buf2
[PREFIX2STR_BUFFER
];
4437 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
) {
4438 json_object_int_add(json
, "routeType", p
->prefix
.route_type
);
4439 json_object_int_add(json
, "ethTag",
4440 p
->prefix
.imet_addr
.eth_tag
);
4441 json_object_int_add(json
, "ipLen",
4442 is_evpn_prefix_ipaddr_v4(p
)
4445 json_object_string_add(json
, "ip",
4446 inet_ntoa(p
->prefix
.imet_addr
.ip
.ipaddr_v4
));
4447 } else if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4448 if (is_evpn_prefix_ipaddr_none(p
)) {
4449 json_object_int_add(json
, "routeType",
4450 p
->prefix
.route_type
);
4451 json_object_int_add(json
, "ethTag",
4452 p
->prefix
.macip_addr
.eth_tag
);
4453 json_object_int_add(json
, "macLen", 8 * ETH_ALEN
);
4454 json_object_string_add(json
, "mac",
4455 prefix_mac2str(&p
->prefix
.macip_addr
.mac
,
4461 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
4464 json_object_int_add(json
, "routeType",
4465 p
->prefix
.route_type
);
4466 json_object_int_add(json
, "ethTag",
4467 p
->prefix
.macip_addr
.eth_tag
);
4468 json_object_int_add(json
, "macLen", 8 * ETH_ALEN
);
4469 json_object_string_add(json
, "mac",
4470 prefix_mac2str(&p
->prefix
.macip_addr
.mac
,
4473 json_object_int_add(json
, "ipLen",
4474 is_evpn_prefix_ipaddr_v4(p
)
4477 json_object_string_add(
4480 &p
->prefix
.macip_addr
.ip
.ip
.addr
,
4482 PREFIX2STR_BUFFER
));
4485 /* Currently, this is to cater to other AF_ETHERNET code. */
4490 * Function to convert evpn route to string.
4491 * NOTE: We don't use prefix2str as the output here is a bit different.
4493 char *bgp_evpn_route2str(struct prefix_evpn
*p
, char *buf
, int len
)
4495 char buf1
[ETHER_ADDR_STRLEN
];
4496 char buf2
[PREFIX2STR_BUFFER
];
4497 char buf3
[ESI_STR_LEN
];
4499 if (p
->prefix
.route_type
== BGP_EVPN_IMET_ROUTE
) {
4500 snprintf(buf
, len
, "[%d]:[%d]:[%d]:[%s]", p
->prefix
.route_type
,
4501 p
->prefix
.imet_addr
.eth_tag
,
4502 is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BITLEN
4504 inet_ntoa(p
->prefix
.imet_addr
.ip
.ipaddr_v4
));
4505 } else if (p
->prefix
.route_type
== BGP_EVPN_MAC_IP_ROUTE
) {
4506 if (is_evpn_prefix_ipaddr_none(p
))
4507 snprintf(buf
, len
, "[%d]:[%d]:[%d]:[%s]",
4508 p
->prefix
.route_type
,
4509 p
->prefix
.macip_addr
.eth_tag
,
4511 prefix_mac2str(&p
->prefix
.macip_addr
.mac
, buf1
,
4516 family
= is_evpn_prefix_ipaddr_v4(p
) ? AF_INET
4518 snprintf(buf
, len
, "[%d]:[%d]:[%d]:[%s]:[%d]:[%s]",
4519 p
->prefix
.route_type
,
4520 p
->prefix
.macip_addr
.eth_tag
,
4522 prefix_mac2str(&p
->prefix
.macip_addr
.mac
, buf1
,
4524 family
== AF_INET
? IPV4_MAX_BITLEN
4527 &p
->prefix
.macip_addr
.ip
.ip
.addr
,
4529 PREFIX2STR_BUFFER
));
4531 } else if (p
->prefix
.route_type
== BGP_EVPN_IP_PREFIX_ROUTE
) {
4532 snprintf(buf
, len
, "[%d]:[%d]:[%d]:[%s]",
4533 p
->prefix
.route_type
,
4534 p
->prefix
.prefix_addr
.eth_tag
,
4535 p
->prefix
.prefix_addr
.ip_prefix_length
,
4536 is_evpn_prefix_ipaddr_v4(p
)
4537 ? inet_ntoa(p
->prefix
.prefix_addr
.ip
.ipaddr_v4
)
4538 : inet6_ntoa(p
->prefix
.prefix_addr
.ip
.ipaddr_v6
));
4539 } else if (p
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) {
4540 snprintf(buf
, len
, "[%d]:[%s]:[%d]:[%s]",
4541 p
->prefix
.route_type
,
4542 esi_to_str(&p
->prefix
.es_addr
.esi
, buf3
, sizeof(buf3
)),
4543 is_evpn_prefix_ipaddr_v4(p
) ? IPV4_MAX_BITLEN
4545 inet_ntoa(p
->prefix
.es_addr
.ip
.ipaddr_v4
));
4547 /* For EVPN route types not supported yet. */
4548 snprintf(buf
, len
, "(unsupported route type %d)",
4549 p
->prefix
.route_type
);
4556 * Encode EVPN prefix in Update (MP_REACH)
4558 void bgp_evpn_encode_prefix(struct stream
*s
, struct prefix
*p
,
4559 struct prefix_rd
*prd
, mpls_label_t
*label
,
4560 uint32_t num_labels
, struct attr
*attr
,
4561 int addpath_encode
, uint32_t addpath_tx_id
)
4563 struct prefix_evpn
*evp
= (struct prefix_evpn
*)p
;
4564 int len
, ipa_len
= 0;
4567 stream_putl(s
, addpath_tx_id
);
4570 stream_putc(s
, evp
->prefix
.route_type
);
4572 switch (evp
->prefix
.route_type
) {
4573 case BGP_EVPN_MAC_IP_ROUTE
:
4574 if (is_evpn_prefix_ipaddr_v4(evp
))
4575 ipa_len
= IPV4_MAX_BYTELEN
;
4576 else if (is_evpn_prefix_ipaddr_v6(evp
))
4577 ipa_len
= IPV6_MAX_BYTELEN
;
4578 /* RD, ESI, EthTag, MAC+len, IP len, [IP], 1 VNI */
4579 len
= 8 + 10 + 4 + 1 + 6 + 1 + ipa_len
+ 3;
4580 if (ipa_len
&& num_labels
> 1) /* There are 2 VNIs */
4582 stream_putc(s
, len
);
4583 stream_put(s
, prd
->val
, 8); /* RD */
4585 stream_put(s
, &attr
->evpn_overlay
.eth_s_id
, ESI_LEN
);
4587 stream_put(s
, 0, 10);
4588 stream_putl(s
, evp
->prefix
.macip_addr
.eth_tag
); /* Ethernet Tag ID */
4589 stream_putc(s
, 8 * ETH_ALEN
); /* Mac Addr Len - bits */
4590 stream_put(s
, evp
->prefix
.macip_addr
.mac
.octet
, 6); /* Mac Addr */
4591 stream_putc(s
, 8 * ipa_len
); /* IP address Length */
4592 if (ipa_len
) /* IP */
4593 stream_put(s
, &evp
->prefix
.macip_addr
.ip
.ip
.addr
,
4595 /* 1st label is the L2 VNI */
4596 stream_put(s
, label
, BGP_LABEL_BYTES
);
4597 /* Include 2nd label (L3 VNI) if advertising MAC+IP */
4598 if (ipa_len
&& num_labels
> 1)
4599 stream_put(s
, label
+ 1, BGP_LABEL_BYTES
);
4602 case BGP_EVPN_IMET_ROUTE
:
4603 stream_putc(s
, 17); // TODO: length - assumes IPv4 address
4604 stream_put(s
, prd
->val
, 8); /* RD */
4605 stream_putl(s
, evp
->prefix
.imet_addr
.eth_tag
); /* Ethernet Tag ID */
4606 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
4607 /* Originating Router's IP Addr */
4608 stream_put_in_addr(s
, &evp
->prefix
.imet_addr
.ip
.ipaddr_v4
);
4611 case BGP_EVPN_ES_ROUTE
:
4612 stream_putc(s
, 23); /* TODO: length: assumes ipv4 VTEP */
4613 stream_put(s
, prd
->val
, 8); /* RD */
4614 stream_put(s
, evp
->prefix
.es_addr
.esi
.val
, 10); /* ESI */
4615 stream_putc(s
, IPV4_MAX_BITLEN
); /* IP address Length - bits */
4617 stream_put_in_addr(s
, &evp
->prefix
.es_addr
.ip
.ipaddr_v4
);
4620 case BGP_EVPN_IP_PREFIX_ROUTE
:
4621 /* TODO: AddPath support. */
4622 evpn_mpattr_encode_type5(s
, p
, prd
, label
, num_labels
, attr
);
4630 int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
4631 struct bgp_nlri
*packet
, int withdraw
)
4637 uint32_t addpath_id
;
4638 int addpath_encoded
;
4644 /* Start processing the NLRI - there may be multiple in the MP_REACH */
4646 lim
= pnt
+ packet
->length
;
4648 safi
= packet
->safi
;
4652 (CHECK_FLAG(peer
->af_cap
[afi
][safi
], PEER_CAP_ADDPATH_AF_RX_ADV
)
4653 && CHECK_FLAG(peer
->af_cap
[afi
][safi
],
4654 PEER_CAP_ADDPATH_AF_TX_RCV
));
4656 for (; pnt
< lim
; pnt
+= psize
) {
4657 /* Clear prefix structure. */
4658 memset(&p
, 0, sizeof(struct prefix
));
4660 /* Deal with path-id if AddPath is supported. */
4661 if (addpath_encoded
) {
4662 /* When packet overflow occurs return immediately. */
4663 if (pnt
+ BGP_ADDPATH_ID_LEN
> lim
)
4666 addpath_id
= ntohl(*((uint32_t *)pnt
));
4667 pnt
+= BGP_ADDPATH_ID_LEN
;
4670 /* All EVPN NLRI types start with type and length. */
4675 psize
= rlen
= *pnt
++;
4677 /* When packet overflow occur return immediately. */
4678 if (pnt
+ psize
> lim
)
4682 case BGP_EVPN_MAC_IP_ROUTE
:
4683 if (process_type2_route(peer
, afi
, safi
,
4684 withdraw
? NULL
: attr
, pnt
,
4685 psize
, addpath_id
)) {
4687 "%u:%s - Error in processing EVPN type-2 NLRI size %d",
4688 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4693 case BGP_EVPN_IMET_ROUTE
:
4694 if (process_type3_route(peer
, afi
, safi
,
4695 withdraw
? NULL
: attr
, pnt
,
4696 psize
, addpath_id
)) {
4698 "%u:%s - Error in processing EVPN type-3 NLRI size %d",
4699 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4704 case BGP_EVPN_ES_ROUTE
:
4705 if (process_type4_route(peer
, afi
, safi
,
4706 withdraw
? NULL
: attr
, pnt
,
4707 psize
, addpath_id
)) {
4709 "%u:%s - Error in processing EVPN type-4 NLRI size %d",
4710 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4715 case BGP_EVPN_IP_PREFIX_ROUTE
:
4716 if (process_type5_route(peer
, afi
, safi
, attr
, pnt
,
4717 psize
, addpath_id
, withdraw
)) {
4719 "%u:%s - Error in processing EVPN type-5 NLRI size %d",
4720 peer
->bgp
->vrf_id
, peer
->host
, psize
);
4730 /* Packet length consistency check. */
4738 * Map the RTs (configured or automatically derived) of a VRF to the VRF.
4739 * The mapping will be used during route processing.
4740 * bgp_def: default bgp instance
4741 * bgp_vrf: specific bgp vrf instance on which RT is configured
4743 void bgp_evpn_map_vrf_to_its_rts(struct bgp
*bgp_vrf
)
4746 struct ecommunity_val
*eval
= NULL
;
4747 struct listnode
*node
= NULL
, *nnode
= NULL
;
4748 struct ecommunity
*ecom
= NULL
;
4750 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, ecom
)) {
4751 for (i
= 0; i
< ecom
->size
; i
++) {
4752 eval
= (struct ecommunity_val
*)(ecom
->val
4754 * ECOMMUNITY_SIZE
));
4755 map_vrf_to_rt(bgp_vrf
, eval
);
4761 * Unmap the RTs (configured or automatically derived) of a VRF from the VRF.
4763 void bgp_evpn_unmap_vrf_from_its_rts(struct bgp
*bgp_vrf
)
4766 struct ecommunity_val
*eval
;
4767 struct listnode
*node
, *nnode
;
4768 struct ecommunity
*ecom
;
4770 for (ALL_LIST_ELEMENTS(bgp_vrf
->vrf_import_rtl
, node
, nnode
, ecom
)) {
4771 for (i
= 0; i
< ecom
->size
; i
++) {
4772 struct vrf_irt_node
*irt
;
4773 struct ecommunity_val eval_tmp
;
4775 eval
= (struct ecommunity_val
*)(ecom
->val
4777 * ECOMMUNITY_SIZE
));
4778 /* If using "automatic" RT, we only care about the
4779 * local-admin sub-field.
4780 * This is to facilitate using VNI as the RT for EBGP
4783 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
4784 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
,
4785 BGP_VRF_IMPORT_RT_CFGD
))
4786 mask_ecom_global_admin(&eval_tmp
, eval
);
4788 irt
= lookup_vrf_import_rt(&eval_tmp
);
4790 unmap_vrf_from_rt(bgp_vrf
, irt
);
4797 * Map the RTs (configured or automatically derived) of a VNI to the VNI.
4798 * The mapping will be used during route processing.
4800 void bgp_evpn_map_vni_to_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4803 struct ecommunity_val
*eval
;
4804 struct listnode
*node
, *nnode
;
4805 struct ecommunity
*ecom
;
4807 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
4808 for (i
= 0; i
< ecom
->size
; i
++) {
4809 eval
= (struct ecommunity_val
*)(ecom
->val
4811 * ECOMMUNITY_SIZE
));
4812 map_vni_to_rt(bgp
, vpn
, eval
);
4818 * Unmap the RTs (configured or automatically derived) of a VNI from the VNI.
4820 void bgp_evpn_unmap_vni_from_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4823 struct ecommunity_val
*eval
;
4824 struct listnode
*node
, *nnode
;
4825 struct ecommunity
*ecom
;
4827 for (ALL_LIST_ELEMENTS(vpn
->import_rtl
, node
, nnode
, ecom
)) {
4828 for (i
= 0; i
< ecom
->size
; i
++) {
4829 struct irt_node
*irt
;
4830 struct ecommunity_val eval_tmp
;
4832 eval
= (struct ecommunity_val
*)(ecom
->val
4834 * ECOMMUNITY_SIZE
));
4835 /* If using "automatic" RT, we only care about the
4836 * local-admin sub-field.
4837 * This is to facilitate using VNI as the RT for EBGP
4840 memcpy(&eval_tmp
, eval
, ECOMMUNITY_SIZE
);
4841 if (!is_import_rt_configured(vpn
))
4842 mask_ecom_global_admin(&eval_tmp
, eval
);
4844 irt
= lookup_import_rt(bgp
, &eval_tmp
);
4846 unmap_vni_from_rt(bgp
, vpn
, irt
);
4852 * Derive Import RT automatically for VNI and map VNI to RT.
4853 * The mapping will be used during route processing.
4855 void bgp_evpn_derive_auto_rt_import(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4857 form_auto_rt(bgp
, vpn
->vni
, vpn
->import_rtl
);
4858 UNSET_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
);
4861 bgp_evpn_map_vni_to_its_rts(bgp
, vpn
);
4865 * Derive Export RT automatically for VNI.
4867 void bgp_evpn_derive_auto_rt_export(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4869 form_auto_rt(bgp
, vpn
->vni
, vpn
->export_rtl
);
4870 UNSET_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
);
4874 * Derive RD automatically for VNI using passed information - it
4875 * is of the form RouterId:unique-id-for-vni.
4877 void bgp_evpn_derive_auto_rd_for_vrf(struct bgp
*bgp
)
4879 form_auto_rd(bgp
->router_id
, bgp
->vrf_rd_id
, &bgp
->vrf_prd
);
4883 * Derive RD automatically for VNI using passed information - it
4884 * is of the form RouterId:unique-id-for-vni.
4886 void bgp_evpn_derive_auto_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4890 vpn
->prd
.family
= AF_UNSPEC
;
4891 vpn
->prd
.prefixlen
= 64;
4892 sprintf(buf
, "%s:%hu", inet_ntoa(bgp
->router_id
), vpn
->rd_id
);
4893 (void)str2prefix_rd(buf
, &vpn
->prd
);
4894 UNSET_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
);
4900 struct bgpevpn
*bgp_evpn_lookup_vni(struct bgp
*bgp
, vni_t vni
)
4902 struct bgpevpn
*vpn
;
4905 memset(&tmp
, 0, sizeof(struct bgpevpn
));
4907 vpn
= hash_lookup(bgp
->vnihash
, &tmp
);
4912 * Create a new vpn - invoked upon configuration or zebra notification.
4914 struct bgpevpn
*bgp_evpn_new(struct bgp
*bgp
, vni_t vni
,
4915 struct in_addr originator_ip
,
4916 vrf_id_t tenant_vrf_id
)
4918 struct bgpevpn
*vpn
;
4923 vpn
= XCALLOC(MTYPE_BGP_EVPN
, sizeof(struct bgpevpn
));
4927 /* Set values - RD and RT set to defaults. */
4929 vpn
->originator_ip
= originator_ip
;
4930 vpn
->tenant_vrf_id
= tenant_vrf_id
;
4932 /* Initialize route-target import and export lists */
4933 vpn
->import_rtl
= list_new();
4934 vpn
->import_rtl
->cmp
= (int (*)(void *, void *))evpn_route_target_cmp
;
4935 vpn
->import_rtl
->del
= evpn_xxport_delete_ecomm
;
4936 vpn
->export_rtl
= list_new();
4937 vpn
->export_rtl
->cmp
= (int (*)(void *, void *))evpn_route_target_cmp
;
4938 vpn
->export_rtl
->del
= evpn_xxport_delete_ecomm
;
4939 bf_assign_index(bm
->rd_idspace
, vpn
->rd_id
);
4940 derive_rd_rt_for_vni(bgp
, vpn
);
4942 /* Initialize EVPN route table. */
4943 vpn
->route_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
4946 if (!hash_get(bgp
->vnihash
, vpn
, hash_alloc_intern
)) {
4947 XFREE(MTYPE_BGP_EVPN
, vpn
);
4951 /* add to l2vni list on corresponding vrf */
4952 bgpevpn_link_to_l3vni(vpn
);
4954 QOBJ_REG(vpn
, bgpevpn
);
4959 * Free a given VPN - called in multiple scenarios such as zebra
4960 * notification, configuration being deleted, advertise-all-vni disabled etc.
4961 * This just frees appropriate memory, caller should have taken other
4964 void bgp_evpn_free(struct bgp
*bgp
, struct bgpevpn
*vpn
)
4966 bgpevpn_unlink_from_l3vni(vpn
);
4967 bgp_table_unlock(vpn
->route_table
);
4968 bgp_evpn_unmap_vni_from_its_rts(bgp
, vpn
);
4969 list_delete_and_null(&vpn
->import_rtl
);
4970 list_delete_and_null(&vpn
->export_rtl
);
4971 bf_release_index(bm
->rd_idspace
, vpn
->rd_id
);
4972 hash_release(bgp
->vnihash
, vpn
);
4974 XFREE(MTYPE_BGP_EVPN
, vpn
);
4980 struct evpnes
*bgp_evpn_lookup_es(struct bgp
*bgp
, esi_t
*esi
)
4985 memset(&tmp
, 0, sizeof(struct evpnes
));
4986 memcpy(&tmp
.esi
, esi
, sizeof(esi_t
));
4987 es
= hash_lookup(bgp
->esihash
, &tmp
);
4992 * Create a new local es - invoked upon zebra notification.
4994 struct evpnes
*bgp_evpn_es_new(struct bgp
*bgp
,
4996 struct ipaddr
*originator_ip
)
5004 es
= XCALLOC(MTYPE_BGP_EVPN_ES
, sizeof(struct evpnes
));
5008 /* set the ESI and originator_ip */
5009 memcpy(&es
->esi
, esi
, sizeof(esi_t
));
5010 memcpy(&es
->originator_ip
, originator_ip
, sizeof(struct ipaddr
));
5012 /* Initialise the VTEP list */
5013 es
->vtep_list
= list_new();
5014 es
->vtep_list
->cmp
= (int (*)(void *, void *))evpn_vtep_ip_cmp
;
5016 /* auto derive RD for this es */
5017 bf_assign_index(bm
->rd_idspace
, es
->rd_id
);
5018 es
->prd
.family
= AF_UNSPEC
;
5019 es
->prd
.prefixlen
= 64;
5020 sprintf(buf
, "%s:%hu", inet_ntoa(bgp
->router_id
), es
->rd_id
);
5021 (void)str2prefix_rd(buf
, &es
->prd
);
5023 /* Initialize the ES route table */
5024 es
->route_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
5027 if (!hash_get(bgp
->esihash
, es
, hash_alloc_intern
)) {
5028 XFREE(MTYPE_BGP_EVPN_ES
, es
);
5032 QOBJ_REG(es
, evpnes
);
5038 * This just frees appropriate memory, caller should have taken other
5041 void bgp_evpn_es_free(struct bgp
*bgp
, struct evpnes
*es
)
5043 list_delete_and_null(&es
->vtep_list
);
5044 bgp_table_unlock(es
->route_table
);
5045 bf_release_index(bm
->rd_idspace
, es
->rd_id
);
5046 hash_release(bgp
->esihash
, es
);
5048 XFREE(MTYPE_BGP_EVPN_ES
, es
);
5052 * Import evpn route from global table to VNI/VRF/ESI.
5054 int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
5055 struct prefix
*p
, struct bgp_info
*ri
)
5057 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, ri
, 1);
5061 * Unimport evpn route from VNI/VRF/ESI.
5063 int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
5064 struct prefix
*p
, struct bgp_info
*ri
)
5066 return install_uninstall_evpn_route(bgp
, afi
, safi
, p
, ri
, 0);
5069 /* filter routes which have martian next hops */
5070 int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
)
5074 struct bgp_node
*rd_rn
, *rn
;
5075 struct bgp_table
*table
;
5076 struct bgp_info
*ri
;
5081 /* Walk entire global routing table and evaluate routes which could be
5082 * imported into this VPN. Note that we cannot just look at the routes
5083 * for the VNI's RD -
5084 * remote routes applicable for this VNI could have any RD.
5086 /* EVPN routes are a 2-level table. */
5087 for (rd_rn
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_rn
;
5088 rd_rn
= bgp_route_next(rd_rn
)) {
5089 table
= (struct bgp_table
*)(rd_rn
->info
);
5093 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
5095 for (ri
= rn
->info
; ri
; ri
= ri
->next
) {
5097 /* Consider "valid" remote routes applicable for
5099 if (!(ri
->type
== ZEBRA_ROUTE_BGP
5100 && ri
->sub_type
== BGP_ROUTE_NORMAL
))
5103 if (bgp_nexthop_self(bgp
, ri
->attr
->nexthop
)) {
5105 char attr_str
[BUFSIZ
];
5106 char pbuf
[PREFIX_STRLEN
];
5108 bgp_dump_attr(ri
->attr
, attr_str
,
5111 if (bgp_debug_update(ri
->peer
, &rn
->p
,
5114 "%u: prefix %s with attr %s - DENIED due to martian or self nexthop",
5121 bgp_evpn_unimport_route(bgp
, afi
, safi
,
5124 bgp_rib_remove(rn
, ri
, ri
->peer
, afi
,
5135 * Handle del of a local MACIP.
5137 int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
5140 struct bgpevpn
*vpn
;
5141 struct prefix_evpn p
;
5143 /* Lookup VNI hash - should exist. */
5144 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
5145 if (!vpn
|| !is_vni_live(vpn
)) {
5146 zlog_warn("%u: VNI hash entry for VNI %u %s at MACIP DEL",
5147 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
5151 /* Remove EVPN type-2 route and schedule for processing. */
5152 build_evpn_type2_prefix(&p
, mac
, ip
);
5153 delete_evpn_route(bgp
, vpn
, &p
);
5159 * Handle add of a local MACIP.
5161 int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
, struct ethaddr
*mac
,
5162 struct ipaddr
*ip
, uint8_t flags
)
5164 struct bgpevpn
*vpn
;
5165 struct prefix_evpn p
;
5167 /* Lookup VNI hash - should exist. */
5168 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
5169 if (!vpn
|| !is_vni_live(vpn
)) {
5170 zlog_warn("%u: VNI hash entry for VNI %u %s at MACIP ADD",
5171 bgp
->vrf_id
, vni
, vpn
? "not live" : "not found");
5175 /* Create EVPN type-2 route and schedule for processing. */
5176 build_evpn_type2_prefix(&p
, mac
, ip
);
5177 if (update_evpn_route(bgp
, vpn
, &p
, flags
)) {
5178 char buf
[ETHER_ADDR_STRLEN
];
5179 char buf2
[INET6_ADDRSTRLEN
];
5182 "%u:Failed to create Type-2 route, VNI %u %s MAC %s IP %s (flags: 0x%x)",
5183 bgp
->vrf_id
, vpn
->vni
,
5184 CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
)
5187 prefix_mac2str(mac
, buf
, sizeof(buf
)),
5188 ipaddr2str(ip
, buf2
, sizeof(buf2
)), flags
);
5195 static void link_l2vni_hash_to_l3vni(struct hash_backet
*backet
,
5196 struct bgp
*bgp_vrf
)
5198 struct bgpevpn
*vpn
= NULL
;
5199 struct bgp
*bgp_def
= NULL
;
5201 bgp_def
= bgp_get_default();
5204 vpn
= (struct bgpevpn
*)backet
->data
;
5205 if (vpn
->tenant_vrf_id
== bgp_vrf
->vrf_id
)
5206 bgpevpn_link_to_l3vni(vpn
);
5209 int bgp_evpn_local_l3vni_add(vni_t l3vni
, vrf_id_t vrf_id
, struct ethaddr
*rmac
,
5210 struct in_addr originator_ip
, int filter
)
5212 struct bgp
*bgp_vrf
= NULL
; /* bgp VRF instance */
5213 struct bgp
*bgp_def
= NULL
; /* default bgp instance */
5214 struct listnode
*node
= NULL
;
5215 struct bgpevpn
*vpn
= NULL
;
5218 /* get the default instamce - required to get the AS number for VRF
5221 bgp_def
= bgp_get_default();
5224 "Cannot process L3VNI %u ADD - default BGP instance not yet created",
5230 /* if the BGP vrf instance doesnt exist - create one */
5231 bgp_vrf
= bgp_lookup_by_name(vrf_id_to_name(vrf_id
));
5236 ret
= bgp_get(&bgp_vrf
, &as
, vrf_id_to_name(vrf_id
),
5237 BGP_INSTANCE_TYPE_VRF
);
5239 case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET
:
5240 zlog_err("'bgp multiple-instance' not present\n");
5242 case BGP_ERR_AS_MISMATCH
:
5243 zlog_err("BGP is already running; AS is %u\n", as
);
5245 case BGP_ERR_INSTANCE_MISMATCH
:
5246 zlog_err("BGP instance name and AS number mismatch\n");
5250 /* mark as auto created */
5251 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
);
5254 /* associate with l3vni */
5255 bgp_vrf
->l3vni
= l3vni
;
5257 /* set the router mac - to be used in mac-ip routes for this vrf */
5258 memcpy(&bgp_vrf
->rmac
, rmac
, sizeof(struct ethaddr
));
5260 /* set the originator ip */
5261 bgp_vrf
->originator_ip
= originator_ip
;
5263 /* set the right filter - are we using l3vni only for prefix routes? */
5265 SET_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
);
5267 /* auto derive RD/RT */
5268 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_IMPORT_RT_CFGD
))
5269 evpn_auto_rt_import_add_for_vrf(bgp_vrf
);
5270 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_EXPORT_RT_CFGD
))
5271 evpn_auto_rt_export_add_for_vrf(bgp_vrf
);
5272 bgp_evpn_derive_auto_rd_for_vrf(bgp_vrf
);
5274 /* link all corresponding l2vnis */
5275 hash_iterate(bgp_def
->vnihash
,
5276 (void (*)(struct hash_backet
*,
5277 void *))link_l2vni_hash_to_l3vni
,
5280 /* Only update all corresponding type-2 routes if we are advertising two
5281 * labels along with type-2 routes
5284 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
))
5285 update_routes_for_vni(bgp_def
, vpn
);
5287 /* advertise type-5 routes if needed */
5288 update_advertise_vrf_routes(bgp_vrf
);
5290 /* install all remote routes belonging to this l3vni into correspondng
5292 install_routes_for_vrf(bgp_vrf
);
5297 int bgp_evpn_local_l3vni_del(vni_t l3vni
, vrf_id_t vrf_id
)
5299 struct bgp
*bgp_vrf
= NULL
; /* bgp vrf instance */
5300 struct bgp
*bgp_def
= NULL
; /* default bgp instance */
5301 struct listnode
*node
= NULL
;
5302 struct listnode
*next
= NULL
;
5303 struct bgpevpn
*vpn
= NULL
;
5305 bgp_vrf
= bgp_lookup_by_vrf_id(vrf_id
);
5308 "Cannot process L3VNI %u Del - Could not find BGP instance",
5313 bgp_def
= bgp_get_default();
5316 "Cannot process L3VNI %u Del - Could not find default BGP instance",
5321 /* unimport remote routes from VRF, if it is AUTO vrf bgp_delete will
5322 * take care of uninstalling the routes from zebra
5324 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
))
5325 uninstall_routes_for_vrf(bgp_vrf
);
5327 /* delete/withdraw all type-5 routes */
5328 delete_withdraw_vrf_routes(bgp_vrf
);
5330 /* remove the l3vni from vrf instance */
5333 /* remove the Rmac from the BGP vrf */
5334 memset(&bgp_vrf
->rmac
, 0, sizeof(struct ethaddr
));
5337 if (!list_isempty(bgp_vrf
->vrf_import_rtl
)) {
5338 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);
5339 list_delete_all_node(bgp_vrf
->vrf_import_rtl
);
5341 if (!list_isempty(bgp_vrf
->vrf_export_rtl
)) {
5342 list_delete_all_node(bgp_vrf
->vrf_export_rtl
);
5345 /* update all corresponding local mac-ip routes */
5346 if (!CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY
)) {
5347 for (ALL_LIST_ELEMENTS_RO(bgp_vrf
->l2vnis
, node
, vpn
)) {
5348 UNSET_FLAG(vpn
->flags
, VNI_FLAG_USE_TWO_LABELS
);
5349 update_routes_for_vni(bgp_def
, vpn
);
5353 /* If any L2VNIs point to this instance, unlink them. */
5354 for (ALL_LIST_ELEMENTS(bgp_vrf
->l2vnis
, node
, next
, vpn
))
5355 bgpevpn_unlink_from_l3vni(vpn
);
5357 /* Delete the instance if it was autocreated */
5358 if (CHECK_FLAG(bgp_vrf
->vrf_flags
, BGP_VRF_AUTO
))
5359 bgp_delete(bgp_vrf
);
5365 * Handle del of a local VNI.
5367 int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
)
5369 struct bgpevpn
*vpn
;
5371 /* Locate VNI hash */
5372 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
5374 if (bgp_debug_zebra(NULL
))
5376 "%u: VNI hash entry for VNI %u not found at DEL",
5381 /* Remove all local EVPN routes and schedule for processing (to
5382 * withdraw from peers).
5384 delete_routes_for_vni(bgp
, vpn
);
5387 * tunnel is no longer active, del tunnel ip address from tip_hash
5389 bgp_tip_del(bgp
, &vpn
->originator_ip
);
5391 /* Clear "live" flag and see if hash needs to be freed. */
5392 UNSET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
5393 if (!is_vni_configured(vpn
))
5394 bgp_evpn_free(bgp
, vpn
);
5400 * Handle add (or update) of a local VNI. The VNI changes we care
5401 * about are for the local-tunnel-ip and the (tenant) VRF.
5403 int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
5404 struct in_addr originator_ip
, vrf_id_t tenant_vrf_id
)
5406 struct bgpevpn
*vpn
;
5407 struct prefix_evpn p
;
5409 /* Lookup VNI. If present and no change, exit. */
5410 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
5413 if (is_vni_live(vpn
)
5414 && IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
)
5415 && vpn
->tenant_vrf_id
== tenant_vrf_id
)
5416 /* Probably some other param has changed that we don't
5420 /* Update tenant_vrf_id if it has changed. */
5421 if (vpn
->tenant_vrf_id
!= tenant_vrf_id
) {
5422 bgpevpn_unlink_from_l3vni(vpn
);
5423 vpn
->tenant_vrf_id
= tenant_vrf_id
;
5424 bgpevpn_link_to_l3vni(vpn
);
5427 /* If tunnel endpoint IP has changed, update (and delete prior
5428 * type-3 route, if needed.)
5430 if (!IPV4_ADDR_SAME(&vpn
->originator_ip
, &originator_ip
))
5431 handle_tunnel_ip_change(bgp
, vpn
, originator_ip
);
5433 /* Update all routes with new endpoint IP and/or export RT
5436 if (is_vni_live(vpn
))
5437 update_routes_for_vni(bgp
, vpn
);
5440 /* Create or update as appropriate. */
5442 vpn
= bgp_evpn_new(bgp
, vni
, originator_ip
, tenant_vrf_id
);
5445 "%u: Failed to allocate VNI entry for VNI %u - at Add",
5451 /* if the VNI is live already, there is nothing more to do */
5452 if (is_vni_live(vpn
))
5455 /* Mark as "live" */
5456 SET_FLAG(vpn
->flags
, VNI_FLAG_LIVE
);
5458 /* tunnel is now active, add tunnel-ip to db */
5459 bgp_tip_add(bgp
, &originator_ip
);
5461 /* filter routes as nexthop database has changed */
5462 bgp_filter_evpn_routes_upon_martian_nh_change(bgp
);
5464 /* Create EVPN type-3 route and schedule for processing. */
5465 build_evpn_type3_prefix(&p
, vpn
->originator_ip
);
5466 if (update_evpn_route(bgp
, vpn
, &p
, 0)) {
5467 zlog_err("%u: Type3 route creation failure for VNI %u",
5472 /* If we have learnt and retained remote routes (VTEPs, MACs) for this
5476 install_routes_for_vni(bgp
, vpn
);
5478 /* If we are advertising gateway mac-ip
5479 It needs to be conveyed again to zebra */
5480 bgp_zebra_advertise_gw_macip(bgp
, vpn
->advertise_gw_macip
, vpn
->vni
);
5486 * bgp_evpn_local_es_del
5488 int bgp_evpn_local_es_del(struct bgp
*bgp
,
5490 struct ipaddr
*originator_ip
)
5492 char buf
[ESI_STR_LEN
];
5493 struct evpnes
*es
= NULL
;
5495 if (!bgp
->esihash
) {
5496 zlog_err("%u: ESI hash not yet created", bgp
->vrf_id
);
5500 /* Lookup ESI hash - should exist. */
5501 es
= bgp_evpn_lookup_es(bgp
, esi
);
5503 zlog_warn("%u: ESI hash entry for ESI %s at Local ES DEL",
5505 esi_to_str(esi
, buf
, sizeof(buf
)));
5509 /* Delete all local EVPN ES routes from ESI table
5510 * and schedule for processing (to withdraw from peers))
5512 delete_routes_for_es(bgp
, es
);
5514 /* free the hash entry */
5515 bgp_evpn_es_free(bgp
, es
);
5521 * bgp_evpn_local_es_add
5523 int bgp_evpn_local_es_add(struct bgp
*bgp
,
5525 struct ipaddr
*originator_ip
)
5527 char buf
[ESI_STR_LEN
];
5528 struct evpnes
*es
= NULL
;
5529 struct prefix_evpn p
;
5531 if (!bgp
->esihash
) {
5532 zlog_err("%u: ESI hash not yet created", bgp
->vrf_id
);
5536 /* create the new es */
5537 es
= bgp_evpn_lookup_es(bgp
, esi
);
5539 es
= bgp_evpn_es_new(bgp
, esi
, originator_ip
);
5542 "%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
5543 bgp
->vrf_id
, esi_to_str(esi
, buf
, sizeof(buf
)));
5547 UNSET_FLAG(es
->flags
, EVPNES_REMOTE
);
5548 SET_FLAG(es
->flags
, EVPNES_LOCAL
);
5550 build_evpn_type4_prefix(&p
, esi
, originator_ip
->ipaddr_v4
);
5551 if (update_evpn_type4_route(bgp
, es
, &p
)) {
5552 zlog_err("%u: Type4 route creation failure for ESI %s",
5553 bgp
->vrf_id
, esi_to_str(esi
, buf
, sizeof(buf
)));
5557 /* import all remote ES routes in th ES table */
5558 install_routes_for_es(bgp
, es
);
5564 * Cleanup EVPN information on disable - Need to delete and withdraw
5565 * EVPN routes from peers.
5567 void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
)
5569 hash_iterate(bgp
->vnihash
, (void (*)(struct hash_backet
*,
5570 void *))cleanup_vni_on_disable
,
5575 * Cleanup EVPN information - invoked at the time of bgpd exit or when the
5576 * BGP instance (default) is being freed.
5578 void bgp_evpn_cleanup(struct bgp
*bgp
)
5580 hash_iterate(bgp
->vnihash
,
5581 (void (*)(struct hash_backet
*, void *))free_vni_entry
,
5584 hash_free(bgp
->import_rt_hash
);
5585 bgp
->import_rt_hash
= NULL
;
5587 hash_free(bgp
->vrf_import_rt_hash
);
5588 bgp
->vrf_import_rt_hash
= NULL
;
5590 hash_free(bgp
->vnihash
);
5591 bgp
->vnihash
= NULL
;
5593 hash_free(bgp
->esihash
);
5594 bgp
->esihash
= NULL
;
5596 list_delete_and_null(&bgp
->vrf_import_rtl
);
5597 list_delete_and_null(&bgp
->vrf_export_rtl
);
5598 list_delete_and_null(&bgp
->l2vnis
);
5602 * Initialization for EVPN
5605 * hash for RT to VNI
5607 void bgp_evpn_init(struct bgp
*bgp
)
5610 hash_create(vni_hash_key_make
, vni_hash_cmp
, "BGP VNI Hash");
5612 hash_create(esi_hash_keymake
, esi_cmp
,
5613 "BGP EVPN Local ESI Hash");
5614 bgp
->import_rt_hash
=
5615 hash_create(import_rt_hash_key_make
, import_rt_hash_cmp
,
5616 "BGP Import RT Hash");
5617 bgp
->vrf_import_rt_hash
=
5618 hash_create(vrf_import_rt_hash_key_make
, vrf_import_rt_hash_cmp
,
5619 "BGP VRF Import RT Hash");
5620 bgp
->vrf_import_rtl
= list_new();
5621 bgp
->vrf_import_rtl
->cmp
=
5622 (int (*)(void *, void *))evpn_route_target_cmp
;
5623 bgp
->vrf_import_rtl
->del
= evpn_xxport_delete_ecomm
;
5624 bgp
->vrf_export_rtl
= list_new();
5625 bgp
->vrf_export_rtl
->cmp
=
5626 (int (*)(void *, void *))evpn_route_target_cmp
;
5627 bgp
->vrf_export_rtl
->del
= evpn_xxport_delete_ecomm
;
5628 bgp
->l2vnis
= list_new();
5629 bgp
->l2vnis
->cmp
= (int (*)(void *, void *))vni_hash_cmp
;
5632 void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
)
5634 bgp_evpn_unmap_vrf_from_its_rts(bgp_vrf
);