1 /* EVPN Multihoming procedures
3 * Copyright (C) 2019 Cumulus Networks, Inc.
6 * This file is part of FRR.
8 * FRRouting is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRRouting is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
32 #include "lib/printfrr.h"
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_evpn.h"
41 #include "bgpd/bgp_evpn_private.h"
42 #include "bgpd/bgp_evpn_mh.h"
43 #include "bgpd/bgp_ecommunity.h"
44 #include "bgpd/bgp_encap_types.h"
45 #include "bgpd/bgp_debug.h"
46 #include "bgpd/bgp_errors.h"
47 #include "bgpd/bgp_aspath.h"
48 #include "bgpd/bgp_zebra.h"
49 #include "bgpd/bgp_addpath.h"
50 #include "bgpd/bgp_label.h"
51 #include "bgpd/bgp_nht.h"
52 #include "bgpd/bgp_mpath.h"
53 #include "bgpd/bgp_trace.h"
55 static void bgp_evpn_local_es_down(struct bgp
*bgp
,
56 struct bgp_evpn_es
*es
);
57 static void bgp_evpn_local_type1_evi_route_del(struct bgp
*bgp
,
58 struct bgp_evpn_es
*es
);
59 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_add(struct bgp
*bgp
,
60 struct bgp_evpn_es
*es
,
61 struct in_addr vtep_ip
,
62 bool esr
, uint8_t df_alg
,
64 static void bgp_evpn_es_vtep_del(struct bgp
*bgp
,
65 struct bgp_evpn_es
*es
, struct in_addr vtep_ip
, bool esr
);
66 static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es
*es
);
67 static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es
*es
);
68 static struct bgp_evpn_es_evi
*
69 bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi
*es_evi
);
70 static uint32_t bgp_evpn_es_get_active_vtep_cnt(struct bgp_evpn_es
*es
);
71 static void bgp_evpn_l3nhg_update_on_vtep_chg(struct bgp_evpn_es
*es
);
72 static struct bgp_evpn_es
*bgp_evpn_es_new(struct bgp
*bgp
, const esi_t
*esi
);
73 static void bgp_evpn_es_free(struct bgp_evpn_es
*es
, const char *caller
);
74 static void bgp_evpn_path_es_unlink(struct bgp_path_es_info
*es_info
);
75 static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es
*es
,
78 esi_t zero_esi_buf
, *zero_esi
= &zero_esi_buf
;
79 static void bgp_evpn_run_consistency_checks(struct thread
*t
);
80 static void bgp_evpn_path_nh_info_free(struct bgp_path_evpn_nh_info
*nh_info
);
81 static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info
*nh_info
);
83 /******************************************************************************
84 * per-ES (Ethernet Segment) routing table
86 * Following routes are added to the ES's routing table -
87 * 1. Local and remote ESR (Type-4)
88 * 2. Local EAD-per-ES (Type-1).
90 * Key for these routes is {ESI, VTEP-IP} so the path selection is practically
91 * a no-op i.e. all paths lead to same VTEP-IP (i.e. result in the same VTEP
92 * being added to same ES).
94 * Note the following routes go into the VNI routing table (instead of the
96 * 1. Remote EAD-per-ES
97 * 2. Local and remote EAD-per-EVI
100 /* Calculate the best path for a multi-homing (Type-1 or Type-4) route
101 * installed in the ES's routing table.
103 static int bgp_evpn_es_route_select_install(struct bgp
*bgp
,
104 struct bgp_evpn_es
*es
,
105 struct bgp_dest
*dest
)
108 afi_t afi
= AFI_L2VPN
;
109 safi_t safi
= SAFI_EVPN
;
110 struct bgp_path_info
*old_select
; /* old best */
111 struct bgp_path_info
*new_select
; /* new best */
112 struct bgp_path_info_pair old_and_new
;
114 /* Compute the best path. */
115 bgp_best_selection(bgp
, dest
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
117 old_select
= old_and_new
.old
;
118 new_select
= old_and_new
.new;
121 * If the best path hasn't changed - see if something needs to be
124 if (old_select
&& old_select
== new_select
125 && old_select
->type
== ZEBRA_ROUTE_BGP
126 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
127 && !CHECK_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
)
128 && !CHECK_FLAG(old_select
->flags
, BGP_PATH_ATTR_CHANGED
)
129 && !bgp_addpath_is_addpath_used(&bgp
->tx_addpath
, afi
, safi
)) {
130 if (bgp_zebra_has_route_changed(old_select
)) {
131 bgp_evpn_es_vtep_add(bgp
, es
, old_select
->attr
->nexthop
,
133 old_select
->attr
->df_alg
,
134 old_select
->attr
->df_pref
);
136 UNSET_FLAG(old_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
137 bgp_zebra_clear_route_change_flags(dest
);
141 /* If the user did a "clear" this flag will be set */
142 UNSET_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
);
144 /* bestpath has changed; update relevant fields and install or uninstall
145 * into the zebra RIB.
147 if (old_select
|| new_select
)
148 bgp_bump_version(dest
);
151 bgp_path_info_unset_flag(dest
, old_select
, BGP_PATH_SELECTED
);
153 bgp_path_info_set_flag(dest
, new_select
, BGP_PATH_SELECTED
);
154 bgp_path_info_unset_flag(dest
, new_select
,
155 BGP_PATH_ATTR_CHANGED
);
156 UNSET_FLAG(new_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
159 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
160 && new_select
->sub_type
== BGP_ROUTE_IMPORTED
) {
161 bgp_evpn_es_vtep_add(bgp
, es
, new_select
->attr
->nexthop
,
162 true /*esr */, new_select
->attr
->df_alg
,
163 new_select
->attr
->df_pref
);
165 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
166 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
167 bgp_evpn_es_vtep_del(
168 bgp
, es
, old_select
->attr
->nexthop
,
172 /* Clear any route change flags. */
173 bgp_zebra_clear_route_change_flags(dest
);
175 /* Reap old select bgp_path_info, if it has been removed */
176 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_PATH_REMOVED
))
177 bgp_path_info_reap(dest
, old_select
);
182 /* Install Type-1/Type-4 route entry in the per-ES routing table */
183 static int bgp_evpn_es_route_install(struct bgp
*bgp
,
184 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
,
185 struct bgp_path_info
*parent_pi
)
188 struct bgp_dest
*dest
= NULL
;
189 struct bgp_path_info
*pi
= NULL
;
190 struct attr
*attr_new
= NULL
;
192 /* Create (or fetch) route within the VNI.
193 * NOTE: There is no RD here.
195 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
197 /* Check if route entry is already present. */
198 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
200 (struct bgp_path_info
*)pi
->extra
->parent
== parent_pi
)
204 /* Add (or update) attribute to hash. */
205 attr_new
= bgp_attr_intern(parent_pi
->attr
);
207 /* Create new route with its attribute. */
208 pi
= info_make(parent_pi
->type
, BGP_ROUTE_IMPORTED
, 0,
209 parent_pi
->peer
, attr_new
, dest
);
210 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
211 bgp_path_info_extra_get(pi
);
212 pi
->extra
->parent
= bgp_path_info_lock(parent_pi
);
213 bgp_dest_lock_node((struct bgp_dest
*)parent_pi
->net
);
214 bgp_path_info_add(dest
, pi
);
216 if (attrhash_cmp(pi
->attr
, parent_pi
->attr
)
217 && !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
218 bgp_dest_unlock_node(dest
);
221 /* The attribute has changed. */
222 /* Add (or update) attribute to hash. */
223 attr_new
= bgp_attr_intern(parent_pi
->attr
);
225 /* Restore route, if needed. */
226 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
227 bgp_path_info_restore(dest
, pi
);
229 /* Mark if nexthop has changed. */
230 if (!IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
231 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
233 /* Unintern existing, set to new. */
234 bgp_attr_unintern(&pi
->attr
);
236 pi
->uptime
= monotime(NULL
);
239 /* Perform route selection and update zebra, if required. */
240 ret
= bgp_evpn_es_route_select_install(bgp
, es
, dest
);
242 bgp_dest_unlock_node(dest
);
247 /* Uninstall Type-1/Type-4 route entry from the ES routing table */
248 static int bgp_evpn_es_route_uninstall(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
249 struct prefix_evpn
*p
, struct bgp_path_info
*parent_pi
)
252 struct bgp_dest
*dest
;
253 struct bgp_path_info
*pi
;
255 if (!es
->route_table
)
258 /* Locate route within the ESI.
259 * NOTE: There is no RD here.
261 dest
= bgp_node_lookup(es
->route_table
, (struct prefix
*)p
);
265 /* Find matching route entry. */
266 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
268 && (struct bgp_path_info
*)pi
->extra
->parent
==
273 bgp_dest_unlock_node(dest
);
277 /* Mark entry for deletion */
278 bgp_path_info_delete(dest
, pi
);
280 /* Perform route selection and update zebra, if required. */
281 ret
= bgp_evpn_es_route_select_install(bgp
, es
, dest
);
283 /* Unlock route node. */
284 bgp_dest_unlock_node(dest
);
289 /* Install or unistall a Type-4 route in the per-ES routing table */
290 int bgp_evpn_es_route_install_uninstall(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
291 afi_t afi
, safi_t safi
, struct prefix_evpn
*evp
,
292 struct bgp_path_info
*pi
, int install
)
297 ret
= bgp_evpn_es_route_install(bgp
, es
, evp
, pi
);
299 ret
= bgp_evpn_es_route_uninstall(bgp
, es
, evp
, pi
);
304 "%u: Failed to %s EVPN %s route in ESI %s",
306 install
? "install" : "uninstall",
313 /* Delete (and withdraw) local routes for specified ES from global and ES table.
314 * Also remove all remote routes from the per ES table. Invoked when ES
317 static void bgp_evpn_es_route_del_all(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
319 struct bgp_dest
*dest
;
320 struct bgp_path_info
*pi
, *nextpi
;
322 /* de-activate the ES */
323 bgp_evpn_local_es_down(bgp
, es
);
324 bgp_evpn_local_type1_evi_route_del(bgp
, es
);
326 /* Walk this ES's routing table and delete all routes. */
327 for (dest
= bgp_table_top(es
->route_table
); dest
;
328 dest
= bgp_route_next(dest
)) {
329 for (pi
= bgp_dest_get_bgp_path_info(dest
);
330 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
331 bgp_path_info_delete(dest
, pi
);
332 bgp_path_info_reap(dest
, pi
);
337 /*****************************************************************************
338 * Base APIs for creating MH routes (Type-1 or Type-4) on local ethernet
342 /* create or update local EVPN type1/type4 route entry.
345 * the ES table if ESR/EAD-ES (or)
346 * the VNI table if EAD-EVI (or)
347 * the global table if ESR/EAD-ES/EAD-EVI
349 * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
352 int bgp_evpn_mh_route_update(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
353 struct bgpevpn
*vpn
, afi_t afi
, safi_t safi
,
354 struct bgp_dest
*dest
, struct attr
*attr
,
355 struct bgp_path_info
**ri
, int *route_changed
)
357 struct bgp_path_info
*tmp_pi
= NULL
;
358 struct bgp_path_info
*local_pi
= NULL
; /* local route entry if any */
359 struct bgp_path_info
*remote_pi
= NULL
; /* remote route entry if any */
360 struct attr
*attr_new
= NULL
;
361 struct prefix_evpn
*evp
;
364 evp
= (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
367 /* locate the local and remote entries if any */
368 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
369 tmp_pi
= tmp_pi
->next
) {
370 if (tmp_pi
->peer
== bgp
->peer_self
371 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
372 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
374 if (tmp_pi
->type
== ZEBRA_ROUTE_BGP
375 && tmp_pi
->sub_type
== BGP_ROUTE_IMPORTED
376 && CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
))
380 /* we don't expect to see a remote_pi at this point as
381 * an ES route has {esi, vtep_ip} as the key in the ES-rt-table
382 * in the VNI-rt-table.
387 "%u ERROR: local es route for ESI: %s vtep %pI4 also learnt from remote",
388 bgp
->vrf_id
, es
? es
->esi_str
: "Null",
389 es
? &es
->originator_ip
: NULL
);
393 /* create or update the entry */
396 /* Add or update attribute to hash */
397 attr_new
= bgp_attr_intern(attr
);
399 /* Create new route with its attribute. */
400 tmp_pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
401 bgp
->peer_self
, attr_new
, dest
);
402 SET_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
);
404 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
405 bgp_path_info_extra_get(tmp_pi
);
406 tmp_pi
->extra
->num_labels
= 1;
408 vni2label(vpn
->vni
, &tmp_pi
->extra
->label
[0]);
410 tmp_pi
->extra
->label
[0] = 0;
413 /* add the newly created path to the route-node */
414 bgp_path_info_add(dest
, tmp_pi
);
417 if (attrhash_cmp(tmp_pi
->attr
, attr
)
418 && !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
421 /* The attribute has changed.
422 * Add (or update) attribute to hash.
424 attr_new
= bgp_attr_intern(attr
);
425 bgp_path_info_set_flag(dest
, tmp_pi
,
426 BGP_PATH_ATTR_CHANGED
);
428 /* Restore route, if needed. */
429 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
430 bgp_path_info_restore(dest
, tmp_pi
);
432 /* Unintern existing, set to new. */
433 bgp_attr_unintern(&tmp_pi
->attr
);
434 tmp_pi
->attr
= attr_new
;
435 tmp_pi
->uptime
= monotime(NULL
);
439 if (*route_changed
) {
440 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
442 "local ES %s vni %u route-type %s nexthop %pI4 updated",
443 es
? es
->esi_str
: "Null", vpn
? vpn
->vni
: 0,
444 evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
446 : (vpn
? "ead-evi" : "ead-es"),
447 &attr
->mp_nexthop_global_in
);
450 /* Return back the route entry. */
455 /* Delete local EVPN ESR (type-4) and EAD (type-1) route
457 * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
460 static int bgp_evpn_mh_route_delete(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
462 struct bgp_evpn_es_frag
*es_frag
,
463 struct prefix_evpn
*p
)
465 afi_t afi
= AFI_L2VPN
;
466 safi_t safi
= SAFI_EVPN
;
467 struct bgp_path_info
*pi
;
468 struct bgp_dest
*dest
= NULL
; /* dest in esi table */
469 struct bgp_dest
*global_dest
= NULL
; /* dest in global table */
470 struct bgp_table
*rt_table
;
471 struct prefix_rd
*prd
;
474 rt_table
= vpn
->ip_table
;
477 rt_table
= es
->route_table
;
481 /* First, locate the route node within the ESI or VNI.
482 * If it doesn't exist, ther is nothing to do.
483 * Note: there is no RD here.
485 dest
= bgp_node_lookup(rt_table
, (struct prefix
*)p
);
489 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
491 "local ES %s vni %u route-type %s nexthop %pI4 delete",
492 es
->esi_str
, vpn
? vpn
->vni
: 0,
493 p
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
495 : (vpn
? "ead-evi" : "ead-es"),
498 /* Next, locate route node in the global EVPN routing table.
499 * Note that this table is a 2-level tree (RD-level + Prefix-level)
501 global_dest
= bgp_evpn_global_node_lookup(bgp
->rib
[afi
][safi
], afi
,
505 /* Delete route entry in the global EVPN table. */
506 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
508 /* Schedule for processing - withdraws to peers happen from
512 bgp_process(bgp
, global_dest
, afi
, safi
);
513 bgp_dest_unlock_node(global_dest
);
517 * Delete route entry in the ESI or VNI routing table.
518 * This can just be removed.
520 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
522 bgp_path_info_reap(dest
, pi
);
523 bgp_dest_unlock_node(dest
);
528 * This function is called when the VNI RD changes.
529 * Delete all EAD/EVI local routes for this VNI from the global routing table.
530 * These routes are scheduled for withdraw from peers.
532 int delete_global_ead_evi_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
)
536 struct bgp_dest
*rdrn
, *rn
;
537 struct bgp_table
*table
;
538 struct bgp_path_info
*pi
;
543 /* Find the RD node for the VNI in the global table */
544 rdrn
= bgp_node_lookup(bgp
->rib
[afi
][safi
], (struct prefix
*)&vpn
->prd
);
545 if (rdrn
&& bgp_dest_has_bgp_path_info_data(rdrn
)) {
546 table
= bgp_dest_get_bgp_table_info(rdrn
);
549 * Iterate over all the routes in this table and delete EAD/EVI
552 for (rn
= bgp_table_top(table
); rn
; rn
= bgp_route_next(rn
)) {
553 struct prefix_evpn
*evp
= (struct prefix_evpn
*)&rn
->p
;
555 if (evp
->prefix
.route_type
!= BGP_EVPN_AD_ROUTE
)
558 delete_evpn_route_entry(bgp
, afi
, safi
, rn
, &pi
);
560 bgp_process(bgp
, rn
, afi
, safi
);
564 /* Unlock RD node. */
566 bgp_dest_unlock_node(rdrn
);
571 /*****************************************************************************
572 * Ethernet Segment (Type-4) Routes
573 * ESRs are used for DF election. Currently service-carving described in
574 * RFC 7432 is NOT supported. Instead preference based DF election is
576 * Reference: draft-ietf-bess-evpn-pref-df
578 /* Build extended community for EVPN ES (type-4) route */
579 static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es
*es
,
582 struct ecommunity ecom_encap
;
583 struct ecommunity ecom_es_rt
;
584 struct ecommunity ecom_df
;
585 struct ecommunity_val eval
;
586 struct ecommunity_val eval_es_rt
;
587 struct ecommunity_val eval_df
;
588 bgp_encap_types tnl_type
;
592 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
593 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
594 encode_encap_extcomm(tnl_type
, &eval
);
596 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
597 ecom_encap
.val
= (uint8_t *)eval
.val
;
598 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
601 memset(&mac
, 0, sizeof(mac
));
602 memset(&ecom_es_rt
, 0, sizeof(ecom_es_rt
));
603 es_get_system_mac(&es
->esi
, &mac
);
604 encode_es_rt_extcomm(&eval_es_rt
, &mac
);
606 ecom_es_rt
.unit_size
= ECOMMUNITY_SIZE
;
607 ecom_es_rt
.val
= (uint8_t *)eval_es_rt
.val
;
608 bgp_attr_set_ecommunity(
610 ecommunity_merge(bgp_attr_get_ecommunity(attr
), &ecom_es_rt
));
612 /* DF election extended community */
613 memset(&ecom_df
, 0, sizeof(ecom_df
));
614 encode_df_elect_extcomm(&eval_df
, es
->df_pref
);
616 ecom_df
.val
= (uint8_t *)eval_df
.val
;
617 bgp_attr_set_ecommunity(
619 ecommunity_merge(bgp_attr_get_ecommunity(attr
), &ecom_df
));
622 /* Create or update local type-4 route */
623 static int bgp_evpn_type4_route_update(struct bgp
*bgp
,
624 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
)
627 int route_changed
= 0;
628 afi_t afi
= AFI_L2VPN
;
629 safi_t safi
= SAFI_EVPN
;
631 struct attr
*attr_new
= NULL
;
632 struct bgp_dest
*dest
= NULL
;
633 struct bgp_path_info
*pi
= NULL
;
635 memset(&attr
, 0, sizeof(attr
));
637 /* Build path-attribute for this route. */
638 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
639 attr
.nexthop
= es
->originator_ip
;
640 attr
.mp_nexthop_global_in
= es
->originator_ip
;
641 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
643 /* Set up extended community. */
644 bgp_evpn_type4_route_extcomm_build(es
, &attr
);
646 /* First, create (or fetch) route node within the ESI. */
647 /* NOTE: There is no RD here. */
648 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
650 /* Create or update route entry. */
651 ret
= bgp_evpn_mh_route_update(bgp
, es
, NULL
, afi
, safi
, dest
, &attr
,
652 &pi
, &route_changed
);
656 "%u ERROR: Failed to updated ES route ESI: %s VTEP %pI4",
657 bgp
->vrf_id
, es
->esi_str
, &es
->originator_ip
);
662 /* Perform route selection;
663 * this is just to set the flags correctly
664 * as local route in the ES always wins.
666 bgp_evpn_es_route_select_install(bgp
, es
, dest
);
667 bgp_dest_unlock_node(dest
);
669 /* If this is a new route or some attribute has changed, export the
670 * route to the global table. The route will be advertised to peers
671 * from there. Note that this table is a 2-level tree (RD-level +
672 * Prefix-level) similar to L3VPN routes.
675 struct bgp_path_info
*global_pi
;
677 dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
678 p
, &es
->es_base_frag
->prd
,
680 bgp_evpn_mh_route_update(bgp
, es
, NULL
, afi
, safi
, dest
,
681 attr_new
, &global_pi
, &route_changed
);
683 /* Schedule for processing and unlock node. */
684 bgp_process(bgp
, dest
, afi
, safi
);
685 bgp_dest_unlock_node(dest
);
688 /* Unintern temporary. */
689 aspath_unintern(&attr
.aspath
);
693 /* Delete local type-4 route */
694 static int bgp_evpn_type4_route_delete(struct bgp
*bgp
,
695 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
)
697 if (!es
->es_base_frag
)
700 return bgp_evpn_mh_route_delete(bgp
, es
, NULL
/* l2vni */,
701 es
->es_base_frag
, p
);
704 /* Process remote/received EVPN type-4 route (advertise or withdraw) */
705 int bgp_evpn_type4_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
706 struct attr
*attr
, uint8_t *pfx
, int psize
,
711 struct in_addr vtep_ip
;
712 struct prefix_rd prd
;
713 struct prefix_evpn p
;
715 /* Type-4 route should be either 23 or 35 bytes
716 * RD (8), ESI (10), ip-len (1), ip (4 or 16)
718 if (psize
!= BGP_EVPN_TYPE4_V4_PSIZE
&&
719 psize
!= BGP_EVPN_TYPE4_V6_PSIZE
) {
720 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
721 "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
722 peer
->bgp
->vrf_id
, peer
->host
, psize
);
727 prd
.family
= AF_UNSPEC
;
729 memcpy(&prd
.val
, pfx
, RD_BYTES
);
733 memcpy(&esi
, pfx
, ESI_BYTES
);
739 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
740 memcpy(&vtep_ip
, pfx
, IPV4_MAX_BYTELEN
);
743 EC_BGP_EVPN_ROUTE_INVALID
,
744 "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
745 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
749 build_evpn_type4_prefix(&p
, &esi
, vtep_ip
);
750 /* Process the route. */
752 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
753 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
,
756 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
757 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
763 /* Check if a prefix belongs to the local ES */
764 static bool bgp_evpn_type4_prefix_match(struct prefix_evpn
*p
,
765 struct bgp_evpn_es
*es
)
767 return (p
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) &&
768 !memcmp(&p
->prefix
.es_addr
.esi
, &es
->esi
, sizeof(esi_t
));
771 /* Import remote ESRs on local ethernet segment add */
772 static int bgp_evpn_type4_remote_routes_import(struct bgp
*bgp
,
773 struct bgp_evpn_es
*es
, bool install
)
778 struct bgp_dest
*rd_dest
, *dest
;
779 struct bgp_table
*table
;
780 struct bgp_path_info
*pi
;
785 /* Walk entire global routing table and evaluate routes which could be
786 * imported into this Ethernet Segment.
788 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
789 rd_dest
= bgp_route_next(rd_dest
)) {
790 table
= bgp_dest_get_bgp_table_info(rd_dest
);
794 for (dest
= bgp_table_top(table
); dest
;
795 dest
= bgp_route_next(dest
)) {
796 struct prefix_evpn
*evp
=
797 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
799 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
802 * Consider "valid" remote routes applicable for
805 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
806 && pi
->type
== ZEBRA_ROUTE_BGP
807 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
810 if (!bgp_evpn_type4_prefix_match(evp
, es
))
814 ret
= bgp_evpn_es_route_install(
817 ret
= bgp_evpn_es_route_uninstall(
823 "Failed to %s EVPN %pFX route in ESI %s",
828 bgp_dest_unlock_node(rd_dest
);
829 bgp_dest_unlock_node(dest
);
838 /*****************************************************************************
839 * Ethernet Auto Discovery (EAD/Type-1) route handling
840 * There are two types of EAD routes -
841 * 1. EAD-per-ES - Key: {ESI, ET=0xffffffff}
842 * 2. EAD-per-EVI - Key: {ESI, ET=0}
845 /* Extended communities associated with EAD-per-ES */
847 bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es_frag
*es_frag
,
850 struct ecommunity ecom_encap
;
851 struct ecommunity ecom_esi_label
;
852 struct ecommunity_val eval
;
853 struct ecommunity_val eval_esi_label
;
854 bgp_encap_types tnl_type
;
855 struct listnode
*evi_node
, *rt_node
;
856 struct ecommunity
*ecom
;
857 struct bgp_evpn_es_evi
*es_evi
;
860 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
861 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
862 encode_encap_extcomm(tnl_type
, &eval
);
864 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
865 ecom_encap
.val
= (uint8_t *)eval
.val
;
866 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
869 encode_esi_label_extcomm(&eval_esi_label
,
870 false /*single_active*/);
871 ecom_esi_label
.size
= 1;
872 ecom_esi_label
.unit_size
= ECOMMUNITY_SIZE
;
873 ecom_esi_label
.val
= (uint8_t *)eval_esi_label
.val
;
874 bgp_attr_set_ecommunity(attr
,
875 ecommunity_merge(bgp_attr_get_ecommunity(attr
),
878 /* Add export RTs for all L2-VNIs associated with this ES */
879 /* XXX - suppress EAD-ES advertisment if there are no EVIs associated
882 if (listcount(bgp_mh_info
->ead_es_export_rtl
)) {
883 for (ALL_LIST_ELEMENTS_RO(bgp_mh_info
->ead_es_export_rtl
,
885 bgp_attr_set_ecommunity(
886 attr
, ecommunity_merge(attr
->ecommunity
, ecom
));
888 for (ALL_LIST_ELEMENTS_RO(es_frag
->es_evi_frag_list
, evi_node
,
890 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
892 for (ALL_LIST_ELEMENTS_RO(es_evi
->vpn
->export_rtl
,
894 bgp_attr_set_ecommunity(
895 attr
, ecommunity_merge(attr
->ecommunity
,
901 /* Extended communities associated with EAD-per-EVI */
902 static void bgp_evpn_type1_evi_route_extcomm_build(struct bgp_evpn_es
*es
,
903 struct bgpevpn
*vpn
, struct attr
*attr
)
905 struct ecommunity ecom_encap
;
906 struct ecommunity_val eval
;
907 bgp_encap_types tnl_type
;
908 struct listnode
*rt_node
;
909 struct ecommunity
*ecom
;
912 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
913 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
914 encode_encap_extcomm(tnl_type
, &eval
);
916 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
917 ecom_encap
.val
= (uint8_t *)eval
.val
;
918 bgp_attr_set_ecommunity(attr
, ecommunity_dup(&ecom_encap
));
920 /* Add export RTs for the L2-VNI */
921 for (ALL_LIST_ELEMENTS_RO(vpn
->export_rtl
, rt_node
, ecom
))
922 bgp_attr_set_ecommunity(
924 ecommunity_merge(bgp_attr_get_ecommunity(attr
), ecom
));
927 /* Update EVPN EAD (type-1) route -
928 * vpn - valid for EAD-EVI routes and NULL for EAD-ES routes
930 static int bgp_evpn_type1_route_update(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
932 struct bgp_evpn_es_frag
*es_frag
,
933 struct prefix_evpn
*p
)
936 afi_t afi
= AFI_L2VPN
;
937 safi_t safi
= SAFI_EVPN
;
939 struct attr
*attr_new
= NULL
;
940 struct bgp_dest
*dest
= NULL
;
941 struct bgp_path_info
*pi
= NULL
;
942 int route_changed
= 0;
943 struct prefix_rd
*global_rd
;
945 memset(&attr
, 0, sizeof(attr
));
947 /* Build path-attribute for this route. */
948 bgp_attr_default_set(&attr
, bgp
, BGP_ORIGIN_IGP
);
949 attr
.nexthop
= es
->originator_ip
;
950 attr
.mp_nexthop_global_in
= es
->originator_ip
;
951 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
954 /* EAD-EVI route update */
956 vni2label(vpn
->vni
, &(attr
.label
));
958 /* Set up extended community */
959 bgp_evpn_type1_evi_route_extcomm_build(es
, vpn
, &attr
);
961 /* First, create (or fetch) route node within the VNI. */
962 dest
= bgp_node_get(vpn
->ip_table
, (struct prefix
*)p
);
964 /* Create or update route entry. */
965 ret
= bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
966 &attr
, &pi
, &route_changed
);
970 "%u Failed to update EAD-EVI route ESI: %s VNI %u VTEP %pI4",
971 bgp
->vrf_id
, es
->esi_str
, vpn
->vni
,
973 global_rd
= &vpn
->prd
;
975 /* EAD-ES route update */
976 /* MPLS label is 0 for EAD-ES route */
978 /* Set up extended community */
979 bgp_evpn_type1_es_route_extcomm_build(es_frag
, &attr
);
981 /* First, create (or fetch) route node within the ES. */
982 /* NOTE: There is no RD here. */
983 /* XXX: fragment ID must be included as a part of the prefix. */
984 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
986 /* Create or update route entry. */
987 ret
= bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
988 &attr
, &pi
, &route_changed
);
992 "%u ERROR: Failed to updated EAD-ES route ESI: %s VTEP %pI4",
993 bgp
->vrf_id
, es
->esi_str
, &es
->originator_ip
);
995 global_rd
= &es_frag
->prd
;
1000 attr_new
= pi
->attr
;
1002 /* Perform route selection;
1003 * this is just to set the flags correctly as local route in
1004 * the ES always wins.
1006 evpn_route_select_install(bgp
, vpn
, dest
);
1007 bgp_dest_unlock_node(dest
);
1009 /* If this is a new route or some attribute has changed, export the
1010 * route to the global table. The route will be advertised to peers
1011 * from there. Note that this table is a 2-level tree (RD-level +
1012 * Prefix-level) similar to L3VPN routes.
1014 if (route_changed
) {
1015 struct bgp_path_info
*global_pi
;
1017 dest
= bgp_evpn_global_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
1018 p
, global_rd
, NULL
);
1019 bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
1020 attr_new
, &global_pi
, &route_changed
);
1022 /* Schedule for processing and unlock node. */
1023 bgp_process(bgp
, dest
, afi
, safi
);
1024 bgp_dest_unlock_node(dest
);
1027 /* Unintern temporary. */
1028 aspath_unintern(&attr
.aspath
);
1033 * This function is called when the export RT for a VNI changes.
1034 * Update all type-1 local routes for this VNI from VNI/ES tables and the global
1035 * table and advertise these routes to peers.
1038 static void bgp_evpn_ead_es_route_update(struct bgp
*bgp
,
1039 struct bgp_evpn_es
*es
)
1041 struct listnode
*node
;
1042 struct bgp_evpn_es_frag
*es_frag
;
1043 struct prefix_evpn p
;
1045 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
, &es
->esi
,
1047 for (ALL_LIST_ELEMENTS_RO(es
->es_frag_list
, node
, es_frag
)) {
1048 if (!listcount(es_frag
->es_evi_frag_list
))
1051 p
.prefix
.ead_addr
.frag_id
= es_frag
->rd_id
;
1052 if (bgp_evpn_type1_route_update(bgp
, es
, NULL
, es_frag
, &p
))
1054 EC_BGP_EVPN_ROUTE_CREATE
,
1055 "EAD-ES route creation failure for ESI %s frag %u",
1056 es
->esi_str
, es_frag
->rd_id
);
1060 static void bgp_evpn_ead_evi_route_update(struct bgp
*bgp
,
1061 struct bgp_evpn_es
*es
,
1062 struct bgpevpn
*vpn
,
1063 struct prefix_evpn
*p
)
1065 if (bgp_evpn_type1_route_update(bgp
, es
, vpn
, NULL
, p
))
1066 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
1067 "EAD-EVI route creation failure for ESI %s VNI %u",
1068 es
->esi_str
, vpn
->vni
);
1071 void update_type1_routes_for_evi(struct bgp
*bgp
, struct bgpevpn
*vpn
)
1073 struct prefix_evpn p
;
1074 struct bgp_evpn_es
*es
;
1075 struct bgp_evpn_es_evi
*es_evi
;
1078 RB_FOREACH (es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
) {
1081 if (es_evi
->vpn
!= vpn
)
1085 bgp_evpn_ead_es_route_update(bgp
, es
);
1087 /* Update EAD-EVI */
1088 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
)) {
1089 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
1090 &es
->esi
, es
->originator_ip
);
1091 bgp_evpn_ead_evi_route_update(bgp
, es
, vpn
, &p
);
1096 /* Delete local Type-1 route */
1097 static void bgp_evpn_ead_es_route_delete(struct bgp
*bgp
,
1098 struct bgp_evpn_es
*es
)
1100 struct listnode
*node
;
1101 struct bgp_evpn_es_frag
*es_frag
;
1102 struct prefix_evpn p
;
1104 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
, &es
->esi
,
1106 for (ALL_LIST_ELEMENTS_RO(es
->es_frag_list
, node
, es_frag
)) {
1107 p
.prefix
.ead_addr
.frag_id
= es_frag
->rd_id
;
1108 bgp_evpn_mh_route_delete(bgp
, es
, NULL
, es_frag
, &p
);
1112 static int bgp_evpn_ead_evi_route_delete(struct bgp
*bgp
,
1113 struct bgp_evpn_es
*es
,
1114 struct bgpevpn
*vpn
,
1115 struct prefix_evpn
*p
)
1117 return bgp_evpn_mh_route_delete(bgp
, es
, vpn
, NULL
, p
);
1120 /* Generate EAD-EVI for all VNIs */
1121 static void bgp_evpn_local_type1_evi_route_add(struct bgp
*bgp
,
1122 struct bgp_evpn_es
*es
)
1124 struct listnode
*evi_node
;
1125 struct prefix_evpn p
;
1126 struct bgp_evpn_es_evi
*es_evi
;
1128 /* EAD-per-EVI routes have been suppressed */
1129 if (!bgp_mh_info
->ead_evi_tx
)
1132 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
))
1133 /* EAD-EVI route add for this ES is already done */
1136 SET_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
);
1137 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
1138 &es
->esi
, es
->originator_ip
);
1140 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, evi_node
, es_evi
)) {
1141 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
1143 bgp_evpn_ead_evi_route_update(bgp
, es
, es_evi
->vpn
, &p
);
1148 * Withdraw EAD-EVI for all VNIs
1150 static void bgp_evpn_local_type1_evi_route_del(struct bgp
*bgp
,
1151 struct bgp_evpn_es
*es
)
1153 struct listnode
*evi_node
;
1154 struct prefix_evpn p
;
1155 struct bgp_evpn_es_evi
*es_evi
;
1157 /* Delete and withdraw locally learnt EAD-EVI route */
1158 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
))
1159 /* EAD-EVI route has not been advertised for this ES */
1162 UNSET_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
);
1163 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
1164 &es
->esi
, es
->originator_ip
);
1165 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, evi_node
, es_evi
)) {
1166 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
1168 if (bgp_evpn_mh_route_delete(bgp
, es
, es_evi
->vpn
, NULL
, &p
))
1169 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
1170 "%u: Type4 route creation failure for ESI %s",
1171 bgp
->vrf_id
, es
->esi_str
);
1176 * Process received EVPN type-1 route (advertise or withdraw).
1178 int bgp_evpn_type1_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
1179 struct attr
*attr
, uint8_t *pfx
, int psize
,
1180 uint32_t addpath_id
)
1182 struct prefix_rd prd
;
1186 struct in_addr vtep_ip
;
1187 struct prefix_evpn p
;
1189 if (psize
!= BGP_EVPN_TYPE1_PSIZE
) {
1190 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
1191 "%u:%s - Rx EVPN Type-1 NLRI with invalid length %d",
1192 peer
->bgp
->vrf_id
, peer
->host
, psize
);
1196 /* Make prefix_rd */
1197 prd
.family
= AF_UNSPEC
;
1199 memcpy(&prd
.val
, pfx
, RD_BYTES
);
1203 memcpy(&esi
, pfx
, ESI_BYTES
);
1206 /* Copy Ethernet Tag */
1207 memcpy(ð_tag
, pfx
, EVPN_ETH_TAG_BYTES
);
1208 eth_tag
= ntohl(eth_tag
);
1209 pfx
+= EVPN_ETH_TAG_BYTES
;
1211 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
1213 /* EAD route prefix doesn't include the nexthop in the global
1216 vtep_ip
.s_addr
= INADDR_ANY
;
1217 build_evpn_type1_prefix(&p
, eth_tag
, &esi
, vtep_ip
);
1218 /* Process the route. */
1220 bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
1221 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
, NULL
,
1224 bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
, afi
,
1225 safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
, &prd
,
1231 void bgp_evpn_mh_config_ead_export_rt(struct bgp
*bgp
,
1232 struct ecommunity
*ecomcfg
, bool del
)
1234 struct listnode
*node
, *nnode
, *node_to_del
;
1235 struct ecommunity
*ecom
;
1236 struct bgp_evpn_es
*es
;
1239 if (ecomcfg
== NULL
) {
1240 /* Reset to default and process all routes. */
1241 for (ALL_LIST_ELEMENTS(bgp_mh_info
->ead_es_export_rtl
,
1242 node
, nnode
, ecom
)) {
1243 ecommunity_free(&ecom
);
1244 list_delete_node(bgp_mh_info
->ead_es_export_rtl
,
1249 /* Delete a specific export RT */
1253 for (ALL_LIST_ELEMENTS(bgp_mh_info
->ead_es_export_rtl
,
1254 node
, nnode
, ecom
)) {
1255 if (ecommunity_match(ecom
, ecomcfg
)) {
1256 ecommunity_free(&ecom
);
1262 assert(node_to_del
);
1263 list_delete_node(bgp_mh_info
->ead_es_export_rtl
,
1267 listnode_add_sort(bgp_mh_info
->ead_es_export_rtl
, ecomcfg
);
1270 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1271 zlog_debug("local ES del/re-add EAD route on export RT change");
1273 * walk through all active ESs withdraw the old EAD and
1274 * generate a new one
1276 RB_FOREACH (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
) {
1277 if (!bgp_evpn_is_es_local(es
) ||
1278 !bgp_evpn_local_es_is_active(es
))
1281 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1283 "local ES %s del/re-add EAD route on export RT change",
1287 * withdraw EAD-ES. XXX - this should technically not be
1288 * needed; can be removed after testing
1290 bgp_evpn_ead_es_route_delete(bgp
, es
);
1292 /* generate EAD-ES */
1293 bgp_evpn_ead_es_route_update(bgp
, es
);
1297 /*****************************************************************************/
1298 /* Ethernet Segment Management
1299 * 1. Ethernet Segment is a collection of links attached to the same
1300 * server (MHD) or switch (MHN)
1301 * 2. An Ethernet Segment can span multiple PEs and is identified by the
1303 * 3. Local ESs are configured in zebra and sent to BGP
1304 * 4. Remote ESs are created by BGP when one or more ES-EVIs reference it i.e.
1305 * created on first reference and release on last de-reference
1306 * 5. An ES can be both local and remote. Infact most local ESs are expected
1307 * to have an ES peer.
1310 /* A list of remote VTEPs is maintained for each ES. This list includes -
1311 * 1. VTEPs for which we have imported the ESR i.e. ES-peers
1312 * 2. VTEPs that have an "active" ES-EVI VTEP i.e. EAD-per-ES and EAD-per-EVI
1313 * have been imported into one or more VNIs
1315 static int bgp_evpn_es_vtep_cmp(void *p1
, void *p2
)
1317 const struct bgp_evpn_es_vtep
*es_vtep1
= p1
;
1318 const struct bgp_evpn_es_vtep
*es_vtep2
= p2
;
1320 return es_vtep1
->vtep_ip
.s_addr
- es_vtep2
->vtep_ip
.s_addr
;
1323 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_new(struct bgp_evpn_es
*es
,
1324 struct in_addr vtep_ip
)
1326 struct bgp_evpn_es_vtep
*es_vtep
;
1328 es_vtep
= XCALLOC(MTYPE_BGP_EVPN_ES_VTEP
, sizeof(*es_vtep
));
1331 es_vtep
->vtep_ip
.s_addr
= vtep_ip
.s_addr
;
1332 inet_ntop(AF_INET
, &es_vtep
->vtep_ip
, es_vtep
->vtep_str
,
1333 sizeof(es_vtep
->vtep_str
));
1334 listnode_init(&es_vtep
->es_listnode
, es_vtep
);
1335 listnode_add_sort(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1340 static void bgp_evpn_es_vtep_free(struct bgp_evpn_es_vtep
*es_vtep
)
1342 struct bgp_evpn_es
*es
= es_vtep
->es
;
1344 if (CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
) ||
1346 /* as long as there is some reference we can't free it */
1349 list_delete_node(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1350 XFREE(MTYPE_BGP_EVPN_ES_VTEP
, es_vtep
);
1353 /* check if VTEP is already part of the list */
1354 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_find(struct bgp_evpn_es
*es
,
1355 struct in_addr vtep_ip
)
1357 struct listnode
*node
= NULL
;
1358 struct bgp_evpn_es_vtep
*es_vtep
;
1360 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1361 if (es_vtep
->vtep_ip
.s_addr
== vtep_ip
.s_addr
)
1367 /* Send the remote ES to zebra for NHG programming */
1368 static int bgp_zebra_send_remote_es_vtep(struct bgp
*bgp
,
1369 struct bgp_evpn_es_vtep
*es_vtep
, bool add
)
1371 struct bgp_evpn_es
*es
= es_vtep
->es
;
1376 if (!zclient
|| zclient
->sock
< 0)
1379 /* Don't try to register if Zebra doesn't know of this instance. */
1380 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
1381 if (BGP_DEBUG(zebra
, ZEBRA
))
1382 zlog_debug("No zebra instance, not installing remote es %s",
1387 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1388 flags
|= ZAPI_ES_VTEP_FLAG_ESR_RXED
;
1393 zclient_create_header(s
,
1394 add
? ZEBRA_REMOTE_ES_VTEP_ADD
: ZEBRA_REMOTE_ES_VTEP_DEL
,
1396 stream_put(s
, &es
->esi
, sizeof(esi_t
));
1397 stream_put_ipv4(s
, es_vtep
->vtep_ip
.s_addr
);
1399 stream_putl(s
, flags
);
1400 stream_putc(s
, es_vtep
->df_alg
);
1401 stream_putw(s
, es_vtep
->df_pref
);
1404 stream_putw_at(s
, 0, stream_get_endp(s
));
1406 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1407 zlog_debug("Tx %s Remote ESI %s VTEP %pI4", add
? "ADD" : "DEL",
1408 es
->esi_str
, &es_vtep
->vtep_ip
);
1410 frrtrace(3, frr_bgp
, evpn_mh_vtep_zsend
, add
, es
, es_vtep
);
1412 return zclient_send_message(zclient
);
1415 static void bgp_evpn_es_vtep_re_eval_active(struct bgp
*bgp
,
1416 struct bgp_evpn_es_vtep
*es_vtep
,
1422 old_active
= CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1423 /* currently we need an active EVI reference to use the VTEP as
1424 * a nexthop. this may change...
1426 if (es_vtep
->evi_cnt
)
1427 SET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1429 UNSET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1431 new_active
= CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1433 if ((old_active
!= new_active
) || (new_active
&& param_change
)) {
1435 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1436 zlog_debug("es %s vtep %pI4 %s df %u/%u",
1437 es_vtep
->es
->esi_str
, &es_vtep
->vtep_ip
,
1438 new_active
? "active" : "inactive",
1439 es_vtep
->df_alg
, es_vtep
->df_pref
);
1441 /* send remote ES to zebra */
1442 bgp_zebra_send_remote_es_vtep(bgp
, es_vtep
, new_active
);
1444 /* The NHG is updated first for efficient failover handling.
1445 * Note the NHG can be de-activated while there are bgp
1446 * routes referencing it. Zebra is capable of handling that
1447 * elegantly by holding the NHG till all routes using it are
1450 bgp_evpn_l3nhg_update_on_vtep_chg(es_vtep
->es
);
1451 /* queue up the es for background consistency checks */
1452 bgp_evpn_es_cons_checks_pend_add(es_vtep
->es
);
1456 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_add(struct bgp
*bgp
,
1457 struct bgp_evpn_es
*es
,
1458 struct in_addr vtep_ip
,
1459 bool esr
, uint8_t df_alg
,
1462 struct bgp_evpn_es_vtep
*es_vtep
;
1463 bool param_change
= false;
1465 es_vtep
= bgp_evpn_es_vtep_find(es
, vtep_ip
);
1468 es_vtep
= bgp_evpn_es_vtep_new(es
, vtep_ip
);
1470 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1471 zlog_debug("es %s vtep %pI4 add %s df %u/%u",
1472 es_vtep
->es
->esi_str
, &es_vtep
->vtep_ip
,
1473 esr
? "esr" : "ead", df_alg
, df_pref
);
1476 SET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
);
1477 if ((es_vtep
->df_pref
!= df_pref
)
1478 || (es_vtep
->df_alg
!= df_alg
)) {
1479 param_change
= true;
1480 es_vtep
->df_pref
= df_pref
;
1481 es_vtep
->df_alg
= df_alg
;
1487 bgp_evpn_es_vtep_re_eval_active(bgp
, es_vtep
, param_change
);
1492 static void bgp_evpn_es_vtep_do_del(struct bgp
*bgp
,
1493 struct bgp_evpn_es_vtep
*es_vtep
, bool esr
)
1495 bool param_change
= false;
1497 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1498 zlog_debug("es %s vtep %pI4 del %s", es_vtep
->es
->esi_str
,
1499 &es_vtep
->vtep_ip
, esr
? "esr" : "ead");
1501 UNSET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
);
1502 if (es_vtep
->df_pref
|| es_vtep
->df_alg
) {
1503 param_change
= true;
1504 es_vtep
->df_pref
= 0;
1505 es_vtep
->df_alg
= 0;
1508 if (es_vtep
->evi_cnt
)
1512 bgp_evpn_es_vtep_re_eval_active(bgp
, es_vtep
, param_change
);
1513 bgp_evpn_es_vtep_free(es_vtep
);
1516 static void bgp_evpn_es_vtep_del(struct bgp
*bgp
,
1517 struct bgp_evpn_es
*es
, struct in_addr vtep_ip
, bool esr
)
1519 struct bgp_evpn_es_vtep
*es_vtep
;
1521 es_vtep
= bgp_evpn_es_vtep_find(es
, vtep_ip
);
1523 bgp_evpn_es_vtep_do_del(bgp
, es_vtep
, esr
);
1526 /********************** ES MAC-IP paths *************************************
1527 * 1. Local MAC-IP routes in the VNI routing table are linked to the
1528 * destination ES (macip_evi_path_list) for efficient updates on ES oper
1530 * 2. Non-local MAC-IP routes in the global routing table are linked to
1531 * the detination for efficient updates on -
1532 * a. VTEP add/del - this results in a L3NHG update.
1533 * b. ES-VRF add/del - this may result in the host route being migrated to
1534 * L3NHG or vice versa (flat multipath list).
1535 ****************************************************************************/
1536 static void bgp_evpn_path_es_info_free(struct bgp_path_es_info
*es_info
)
1538 bgp_evpn_path_es_unlink(es_info
);
1539 XFREE(MTYPE_BGP_EVPN_PATH_ES_INFO
, es_info
);
1542 void bgp_evpn_path_mh_info_free(struct bgp_path_mh_info
*mh_info
)
1544 if (mh_info
->es_info
)
1545 bgp_evpn_path_es_info_free(mh_info
->es_info
);
1546 if (mh_info
->nh_info
)
1547 bgp_evpn_path_nh_info_free(mh_info
->nh_info
);
1548 XFREE(MTYPE_BGP_EVPN_PATH_MH_INFO
, mh_info
);
1551 static struct bgp_path_es_info
*
1552 bgp_evpn_path_es_info_new(struct bgp_path_info
*pi
, vni_t vni
)
1554 struct bgp_path_info_extra
*e
;
1555 struct bgp_path_mh_info
*mh_info
;
1556 struct bgp_path_es_info
*es_info
;
1558 e
= bgp_path_info_extra_get(pi
);
1560 /* If mh_info doesn't exist allocate it */
1561 mh_info
= e
->mh_info
;
1563 e
->mh_info
= mh_info
= XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO
,
1564 sizeof(struct bgp_path_mh_info
));
1566 /* If es_info doesn't exist allocate it */
1567 es_info
= mh_info
->es_info
;
1569 mh_info
->es_info
= es_info
=
1570 XCALLOC(MTYPE_BGP_EVPN_PATH_ES_INFO
,
1571 sizeof(struct bgp_path_es_info
));
1579 static void bgp_evpn_path_es_unlink(struct bgp_path_es_info
*es_info
)
1581 struct bgp_evpn_es
*es
= es_info
->es
;
1582 struct bgp_path_info
*pi
;
1588 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1589 zlog_debug("vni %u path %pFX unlinked from es %s", es_info
->vni
,
1590 &pi
->net
->p
, es
->esi_str
);
1593 list_delete_node(es
->macip_evi_path_list
,
1594 &es_info
->es_listnode
);
1596 list_delete_node(es
->macip_global_path_list
,
1597 &es_info
->es_listnode
);
1601 /* if there are no other references against the ES it
1604 bgp_evpn_es_free(es
, __func__
);
1606 /* Note we don't free the path es_info on unlink; it will be freed up
1607 * along with the path.
1611 void bgp_evpn_path_es_link(struct bgp_path_info
*pi
, vni_t vni
, esi_t
*esi
)
1613 struct bgp_path_es_info
*es_info
;
1614 struct bgp_evpn_es
*es
;
1615 struct bgp
*bgp_evpn
;
1617 es_info
= (pi
->extra
&& pi
->extra
->mh_info
)
1618 ? pi
->extra
->mh_info
->es_info
1620 /* if the esi is zero just unlink the path from the old es */
1621 if (!esi
|| !memcmp(esi
, zero_esi
, sizeof(*esi
))) {
1623 bgp_evpn_path_es_unlink(es_info
);
1627 bgp_evpn
= bgp_get_evpn();
1631 /* setup es_info against the path if it doesn't aleady exist */
1633 es_info
= bgp_evpn_path_es_info_new(pi
, vni
);
1635 /* find-create ES */
1636 es
= bgp_evpn_es_find(esi
);
1638 es
= bgp_evpn_es_new(bgp_evpn
, esi
);
1641 if (es_info
->es
== es
)
1644 /* unlink old ES if any */
1645 bgp_evpn_path_es_unlink(es_info
);
1647 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1648 zlog_debug("vni %u path %pFX linked to es %s", vni
, &pi
->net
->p
,
1651 /* link mac-ip path to the new destination ES */
1653 listnode_init(&es_info
->es_listnode
, es_info
);
1655 listnode_add(es
->macip_evi_path_list
, &es_info
->es_listnode
);
1657 listnode_add(es
->macip_global_path_list
, &es_info
->es_listnode
);
1660 static bool bgp_evpn_is_macip_path(struct bgp_path_info
*pi
)
1662 struct prefix_evpn
*evp
;
1664 /* Only MAC-IP routes need to be linked (MAC-only routes can be
1665 * skipped) as these lists are maintained for managing
1666 * host routes in the tenant VRF
1668 evp
= (struct prefix_evpn
*)&pi
->net
->p
;
1669 return is_evpn_prefix_ipaddr_v4(evp
) || is_evpn_prefix_ipaddr_v6(evp
);
1672 /* When a remote ES is added to a VRF, routes using that as
1673 * a destination need to be migrated to a L3NHG or viceversa.
1674 * This is done indirectly by re-attempting an install of the
1675 * route in the associated VRFs. As a part of the VRF install use
1676 * of l3 NHG is evaluated and this results in the
1677 * attr.es_flag ATTR_ES_L3_NHG_USE being set or cleared.
1680 bgp_evpn_es_path_update_on_es_vrf_chg(struct bgp_evpn_es_vrf
*es_vrf
,
1683 struct listnode
*node
;
1684 struct bgp_path_es_info
*es_info
;
1685 struct bgp_path_info
*pi
;
1686 struct bgp_evpn_es
*es
= es_vrf
->es
;
1688 if (!bgp_mh_info
->host_routes_use_l3nhg
)
1691 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1692 zlog_debug("update paths linked to es %s on es-vrf %s %s",
1693 es
->esi_str
, es_vrf
->bgp_vrf
->name_pretty
, reason
);
1695 for (ALL_LIST_ELEMENTS_RO(es
->macip_global_path_list
, node
, es_info
)) {
1698 if (!bgp_evpn_is_macip_path(pi
))
1701 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1703 "update path %pFX linked to es %s on vrf chg",
1704 &pi
->net
->p
, es
->esi_str
);
1705 bgp_evpn_route_entry_install_if_vrf_match(es_vrf
->bgp_vrf
, pi
,
1710 static void bgp_evpn_es_frag_free(struct bgp_evpn_es_frag
*es_frag
)
1712 struct bgp_evpn_es
*es
= es_frag
->es
;
1714 if (es
->es_base_frag
== es_frag
)
1715 es
->es_base_frag
= NULL
;
1717 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1718 zlog_debug("es %s frag %u free", es
->esi_str
, es_frag
->rd_id
);
1719 list_delete_node(es
->es_frag_list
, &es_frag
->es_listnode
);
1721 /* EVIs that are advertised using the info in this fragment */
1722 list_delete(&es_frag
->es_evi_frag_list
);
1724 bf_release_index(bm
->rd_idspace
, es_frag
->rd_id
);
1727 XFREE(MTYPE_BGP_EVPN_ES_FRAG
, es_frag
);
1730 static void bgp_evpn_es_frag_free_unused(struct bgp_evpn_es_frag
*es_frag
)
1732 if ((es_frag
->es
->es_base_frag
== es_frag
) ||
1733 listcount(es_frag
->es_evi_frag_list
))
1736 bgp_evpn_es_frag_free(es_frag
);
1739 static void bgp_evpn_es_frag_free_all(struct bgp_evpn_es
*es
)
1741 struct listnode
*node
;
1742 struct listnode
*nnode
;
1743 struct bgp_evpn_es_frag
*es_frag
;
1745 for (ALL_LIST_ELEMENTS(es
->es_frag_list
, node
, nnode
, es_frag
))
1746 bgp_evpn_es_frag_free(es_frag
);
1749 static struct bgp_evpn_es_frag
*bgp_evpn_es_frag_new(struct bgp_evpn_es
*es
)
1751 struct bgp_evpn_es_frag
*es_frag
;
1752 char buf
[BGP_EVPN_PREFIX_RD_LEN
];
1755 es_frag
= XCALLOC(MTYPE_BGP_EVPN_ES_FRAG
, sizeof(*es_frag
));
1756 bf_assign_index(bm
->rd_idspace
, es_frag
->rd_id
);
1757 es_frag
->prd
.family
= AF_UNSPEC
;
1758 es_frag
->prd
.prefixlen
= 64;
1759 bgp
= bgp_get_evpn();
1760 snprintfrr(buf
, sizeof(buf
), "%pI4:%hu", &bgp
->router_id
,
1762 (void)str2prefix_rd(buf
, &es_frag
->prd
);
1764 /* EVIs that are advertised using the info in this fragment */
1765 es_frag
->es_evi_frag_list
= list_new();
1766 listset_app_node_mem(es_frag
->es_evi_frag_list
);
1768 /* Link the fragment to the parent ES */
1770 listnode_init(&es_frag
->es_listnode
, es_frag
);
1771 listnode_add(es
->es_frag_list
, &es_frag
->es_listnode
);
1773 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1774 zlog_debug("es %s frag %u new", es
->esi_str
, es_frag
->rd_id
);
1778 static struct bgp_evpn_es_frag
*
1779 bgp_evpn_es_find_frag_with_space(struct bgp_evpn_es
*es
)
1781 struct listnode
*node
;
1782 struct bgp_evpn_es_frag
*es_frag
;
1784 for (ALL_LIST_ELEMENTS_RO(es
->es_frag_list
, node
, es_frag
)) {
1785 if (listcount(es_frag
->es_evi_frag_list
) <
1786 bgp_mh_info
->evi_per_es_frag
)
1790 /* No frags where found with space; allocate a new one */
1791 return bgp_evpn_es_frag_new(es
);
1794 /* Link the ES-EVI to one of the ES fragments */
1795 static void bgp_evpn_es_frag_evi_add(struct bgp_evpn_es_evi
*es_evi
)
1797 struct bgp_evpn_es_frag
*es_frag
;
1798 struct bgp_evpn_es
*es
= es_evi
->es
;
1800 if (es_evi
->es_frag
||
1801 !(CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
)))
1804 es_frag
= bgp_evpn_es_find_frag_with_space(es
);
1806 es_evi
->es_frag
= es_frag
;
1807 listnode_init(&es_evi
->es_frag_listnode
, es_evi
);
1808 listnode_add(es_frag
->es_evi_frag_list
, &es_evi
->es_frag_listnode
);
1810 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1811 zlog_debug("es %s vni %d linked to frag %u", es
->esi_str
,
1812 es_evi
->vpn
->vni
, es_frag
->rd_id
);
1815 /* UnLink the ES-EVI from the ES fragment */
1816 static void bgp_evpn_es_frag_evi_del(struct bgp_evpn_es_evi
*es_evi
,
1817 bool send_ead_del_if_empty
)
1819 struct bgp_evpn_es_frag
*es_frag
= es_evi
->es_frag
;
1820 struct prefix_evpn p
;
1821 struct bgp_evpn_es
*es
;
1828 es_evi
->es_frag
= NULL
;
1829 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1830 zlog_debug("es %s vni %d unlinked from frag %u", es
->esi_str
,
1831 es_evi
->vpn
->vni
, es_frag
->rd_id
);
1833 list_delete_node(es_frag
->es_evi_frag_list
, &es_evi
->es_frag_listnode
);
1836 * if there are no other EVIs on the fragment deleted the EAD-ES for
1839 if (send_ead_del_if_empty
&& !listcount(es_frag
->es_evi_frag_list
)) {
1840 bgp
= bgp_get_evpn();
1842 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1843 zlog_debug("es %s frag %u ead-es route delete",
1844 es
->esi_str
, es_frag
->rd_id
);
1845 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
, &es
->esi
,
1847 p
.prefix
.ead_addr
.frag_id
= es_frag
->rd_id
;
1848 bgp_evpn_mh_route_delete(bgp
, es
, NULL
, es_frag
, &p
);
1851 /* We don't attempt to coalesce frags that may not be full. Instead we
1852 * only free up the frag when it is completely empty.
1854 bgp_evpn_es_frag_free_unused(es_frag
);
1857 /* Link the ES-EVIs to one of the ES fragments */
1858 static void bgp_evpn_es_frag_evi_update_all(struct bgp_evpn_es
*es
, bool add
)
1860 struct listnode
*node
;
1861 struct bgp_evpn_es_evi
*es_evi
;
1863 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, node
, es_evi
)) {
1865 bgp_evpn_es_frag_evi_add(es_evi
);
1867 bgp_evpn_es_frag_evi_del(es_evi
, false);
1871 /* compare ES-IDs for the global ES RB tree */
1872 static int bgp_es_rb_cmp(const struct bgp_evpn_es
*es1
,
1873 const struct bgp_evpn_es
*es2
)
1875 return memcmp(&es1
->esi
, &es2
->esi
, ESI_BYTES
);
1877 RB_GENERATE(bgp_es_rb_head
, bgp_evpn_es
, rb_node
, bgp_es_rb_cmp
);
1879 struct bgp_evpn_es
*bgp_evpn_es_find(const esi_t
*esi
)
1881 struct bgp_evpn_es tmp
;
1883 memcpy(&tmp
.esi
, esi
, sizeof(esi_t
));
1884 return RB_FIND(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, &tmp
);
1887 static struct bgp_evpn_es
*bgp_evpn_es_new(struct bgp
*bgp
, const esi_t
*esi
)
1889 struct bgp_evpn_es
*es
;
1891 es
= XCALLOC(MTYPE_BGP_EVPN_ES
, sizeof(struct bgp_evpn_es
));
1894 memcpy(&es
->esi
, esi
, sizeof(esi_t
));
1896 /* Initialise the VTEP list */
1897 es
->es_vtep_list
= list_new();
1898 listset_app_node_mem(es
->es_vtep_list
);
1899 es
->es_vtep_list
->cmp
= bgp_evpn_es_vtep_cmp
;
1901 esi_to_str(&es
->esi
, es
->esi_str
, sizeof(es
->esi_str
));
1903 /* Initialize the ES routing table */
1904 es
->route_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
1906 /* Add to rb_tree */
1907 RB_INSERT(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, es
);
1909 /* Initialise the ES-EVI list */
1910 es
->es_evi_list
= list_new();
1911 listset_app_node_mem(es
->es_evi_list
);
1913 /* Initialise the ES-VRF list used for L3NHG management */
1914 es
->es_vrf_list
= list_new();
1915 listset_app_node_mem(es
->es_vrf_list
);
1917 /* Initialise the route list used for efficient event handling */
1918 es
->macip_evi_path_list
= list_new();
1919 listset_app_node_mem(es
->macip_evi_path_list
);
1920 es
->macip_global_path_list
= list_new();
1921 listset_app_node_mem(es
->macip_global_path_list
);
1922 es
->es_frag_list
= list_new();
1923 listset_app_node_mem(es
->es_frag_list
);
1925 QOBJ_REG(es
, bgp_evpn_es
);
1930 /* Free a given ES -
1931 * This just frees appropriate memory, caller should have taken other
1934 static void bgp_evpn_es_free(struct bgp_evpn_es
*es
, const char *caller
)
1936 if ((es
->flags
& (BGP_EVPNES_LOCAL
| BGP_EVPNES_REMOTE
))
1937 || listcount(es
->macip_evi_path_list
)
1938 || listcount(es
->macip_global_path_list
))
1941 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1942 zlog_debug("%s: es %s free", caller
, es
->esi_str
);
1944 /* cleanup resources maintained against the ES */
1945 list_delete(&es
->es_evi_list
);
1946 list_delete(&es
->es_vrf_list
);
1947 list_delete(&es
->es_vtep_list
);
1948 list_delete(&es
->macip_evi_path_list
);
1949 list_delete(&es
->macip_global_path_list
);
1950 list_delete(&es
->es_frag_list
);
1951 bgp_table_unlock(es
->route_table
);
1953 /* remove the entry from various databases */
1954 RB_REMOVE(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, es
);
1955 bgp_evpn_es_cons_checks_pend_del(es
);
1958 XFREE(MTYPE_BGP_EVPN_ES
, es
);
1961 static inline bool bgp_evpn_is_es_local_and_non_bypass(struct bgp_evpn_es
*es
)
1963 return (es
->flags
& BGP_EVPNES_LOCAL
)
1964 && !(es
->flags
& BGP_EVPNES_BYPASS
);
1967 /* init local info associated with the ES */
1968 static void bgp_evpn_es_local_info_set(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
1973 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
1976 old_is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
1977 SET_FLAG(es
->flags
, BGP_EVPNES_LOCAL
);
1979 listnode_init(&es
->es_listnode
, es
);
1980 listnode_add(bgp_mh_info
->local_es_list
, &es
->es_listnode
);
1982 /* setup the first ES fragment; more fragments may be allocated based
1983 * on the the number of EVI entries
1985 es
->es_base_frag
= bgp_evpn_es_frag_new(es
);
1986 /* distribute ES-EVIs to one or more ES fragments */
1987 bgp_evpn_es_frag_evi_update_all(es
, true);
1989 is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
1990 if (old_is_local
!= is_local
)
1991 bgp_evpn_mac_update_on_es_local_chg(es
, is_local
);
1994 /* clear any local info associated with the ES */
1995 static void bgp_evpn_es_local_info_clear(struct bgp_evpn_es
*es
, bool finish
)
2000 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
2003 /* clear the es frag references and free them up */
2004 bgp_evpn_es_frag_evi_update_all(es
, false);
2005 es
->es_base_frag
= NULL
;
2006 bgp_evpn_es_frag_free_all(es
);
2008 old_is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
2009 UNSET_FLAG(es
->flags
, BGP_EVPNES_LOCAL
);
2011 is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
2012 if (!finish
&& (old_is_local
!= is_local
))
2013 bgp_evpn_mac_update_on_es_local_chg(es
, is_local
);
2015 /* remove from the ES local list */
2016 list_delete_node(bgp_mh_info
->local_es_list
, &es
->es_listnode
);
2018 bgp_evpn_es_free(es
, __func__
);
2021 /* eval remote info associated with the ES */
2022 static void bgp_evpn_es_remote_info_re_eval(struct bgp_evpn_es
*es
)
2024 if (es
->remote_es_evi_cnt
) {
2025 SET_FLAG(es
->flags
, BGP_EVPNES_REMOTE
);
2027 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_REMOTE
)) {
2028 UNSET_FLAG(es
->flags
, BGP_EVPNES_REMOTE
);
2029 bgp_evpn_es_free(es
, __func__
);
2034 /* If ES is present and local it needs to be active/oper-up for
2037 bool bgp_evpn_es_add_l3_ecomm_ok(esi_t
*esi
)
2039 struct bgp_evpn_es
*es
;
2041 if (!esi
|| !bgp_mh_info
->suppress_l3_ecomm_on_inactive_es
)
2044 es
= bgp_evpn_es_find(esi
);
2046 return (!es
|| !(es
->flags
& BGP_EVPNES_LOCAL
)
2047 || bgp_evpn_local_es_is_active(es
));
2050 static bool bgp_evpn_is_valid_local_path(struct bgp_path_info
*pi
)
2052 return (CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
2053 && pi
->type
== ZEBRA_ROUTE_BGP
2054 && pi
->sub_type
== BGP_ROUTE_STATIC
);
2057 /* Update all local MAC-IP routes in the VNI routing table associated
2058 * with the ES. When the ES is down the routes are advertised without
2061 static void bgp_evpn_mac_update_on_es_oper_chg(struct bgp_evpn_es
*es
)
2063 struct listnode
*node
;
2064 struct bgp_path_es_info
*es_info
;
2065 struct bgp_path_info
*pi
;
2067 struct bgpevpn
*vpn
;
2069 if (!bgp_mh_info
->suppress_l3_ecomm_on_inactive_es
)
2072 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2073 zlog_debug("update paths linked to es %s on oper chg",
2076 bgp
= bgp_get_evpn();
2077 for (ALL_LIST_ELEMENTS_RO(es
->macip_evi_path_list
, node
, es_info
)) {
2080 if (!bgp_evpn_is_valid_local_path(pi
))
2083 if (!bgp_evpn_is_macip_path(pi
))
2086 vpn
= bgp_evpn_lookup_vni(bgp
, es_info
->vni
);
2090 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2092 "update path %d %pFX linked to es %s on oper chg",
2093 es_info
->vni
, &pi
->net
->p
, es
->esi_str
);
2095 bgp_evpn_update_type2_route_entry(bgp
, vpn
, pi
->net
, pi
,
2100 static bool bgp_evpn_is_valid_bgp_path(struct bgp_path_info
*pi
)
2102 return (CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
2103 && pi
->type
== ZEBRA_ROUTE_BGP
2104 && pi
->sub_type
== BGP_ROUTE_NORMAL
);
2107 /* If an ES is no longer local (or becomes local) we need to re-install
2108 * paths using that ES as destination. This is needed as the criteria
2109 * for best path selection has changed.
2111 static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es
*es
,
2114 struct listnode
*node
;
2115 struct bgp_path_es_info
*es_info
;
2116 struct bgp_path_info
*pi
;
2118 struct attr
*attr_new
;
2119 struct attr attr_tmp
;
2121 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2122 zlog_debug("update paths linked to es %s on chg to %s",
2123 es
->esi_str
, is_local
? "local" : "non-local");
2125 for (ALL_LIST_ELEMENTS_RO(es
->macip_global_path_list
, node
, es_info
)) {
2128 /* Consider "valid" remote routes */
2129 if (!bgp_evpn_is_valid_bgp_path(pi
))
2135 tmp_local
= !!(pi
->attr
->es_flags
& ATTR_ES_IS_LOCAL
);
2136 if (tmp_local
== is_local
)
2139 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
2141 "update path %pFX linked to es %s on chg to %s",
2142 &pi
->net
->p
, es
->esi_str
,
2143 is_local
? "local" : "non-local");
2145 attr_tmp
= *pi
->attr
;
2147 attr_tmp
.es_flags
|= ATTR_ES_IS_LOCAL
;
2149 attr_tmp
.es_flags
&= ~ATTR_ES_IS_LOCAL
;
2150 attr_new
= bgp_attr_intern(&attr_tmp
);
2151 bgp_attr_unintern(&pi
->attr
);
2152 pi
->attr
= attr_new
;
2153 bgp_evpn_import_type2_route(pi
, 1);
2157 static void bgp_evpn_local_es_deactivate(struct bgp
*bgp
,
2158 struct bgp_evpn_es
*es
)
2160 struct prefix_evpn p
;
2164 /* Delete and withdraw locally learnt ES route */
2165 build_evpn_type4_prefix(&p
, &es
->esi
, es
->originator_ip
);
2166 ret
= bgp_evpn_type4_route_delete(bgp
, es
, &p
);
2168 flog_err(EC_BGP_EVPN_ROUTE_DELETE
,
2169 "%u failed to delete type-4 route for ESI %s",
2170 bgp
->vrf_id
, es
->esi_str
);
2173 /* withdraw EAD-EVI */
2174 if (!bgp_mh_info
->ead_evi_adv_for_down_links
)
2175 bgp_evpn_local_type1_evi_route_del(bgp
, es
);
2177 /* withdraw EAD-ES */
2178 bgp_evpn_ead_es_route_delete(bgp
, es
);
2180 bgp_evpn_mac_update_on_es_oper_chg(es
);
2183 /* Process ES link oper-down by withdrawing ES-EAD and ESR */
2184 static void bgp_evpn_local_es_down(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
2188 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
))
2191 old_active
= bgp_evpn_local_es_is_active(es
);
2192 UNSET_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
);
2194 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2195 zlog_debug("local es %s down", es
->esi_str
);
2198 bgp_evpn_local_es_deactivate(bgp
, es
);
2201 static void bgp_evpn_local_es_activate(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
2202 bool regen_ead
, bool regen_esr
)
2204 struct prefix_evpn p
;
2207 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2208 zlog_debug("local es %s generate ESR", es
->esi_str
);
2210 build_evpn_type4_prefix(&p
, &es
->esi
, es
->originator_ip
);
2211 if (bgp_evpn_type4_route_update(bgp
, es
, &p
))
2212 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
2213 "%u: Type4 route creation failure for ESI %s",
2214 bgp
->vrf_id
, es
->esi_str
);
2218 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2219 zlog_debug("local es %s generate EAD", es
->esi_str
);
2220 /* generate EAD-EVI */
2221 bgp_evpn_local_type1_evi_route_add(bgp
, es
);
2223 /* generate EAD-ES */
2224 bgp_evpn_ead_es_route_update(bgp
, es
);
2227 bgp_evpn_mac_update_on_es_oper_chg(es
);
2230 /* Process ES link oper-up by generating ES-EAD and ESR */
2231 static void bgp_evpn_local_es_up(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
2234 bool regen_ead
= false;
2235 bool active
= false;
2237 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
)) {
2238 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2239 zlog_debug("local es %s up", es
->esi_str
);
2241 SET_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
);
2246 active
= bgp_evpn_local_es_is_active(es
);
2247 if (active
&& (regen_ead
|| regen_esr
))
2248 bgp_evpn_local_es_activate(bgp
, es
, regen_ead
, regen_esr
);
2251 /* If an ethernet segment is in LACP bypass we cannot advertise
2252 * reachability to it i.e. EAD-per-ES and ESR is not advertised in
2254 * PS: EAD-per-EVI will continue to be advertised
2256 static void bgp_evpn_local_es_bypass_update(struct bgp
*bgp
,
2257 struct bgp_evpn_es
*es
, bool bypass
)
2259 bool old_bypass
= !!(es
->flags
& BGP_EVPNES_BYPASS
);
2265 if (bypass
== old_bypass
)
2268 old_active
= bgp_evpn_local_es_is_active(es
);
2269 old_is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
2271 SET_FLAG(es
->flags
, BGP_EVPNES_BYPASS
);
2273 UNSET_FLAG(es
->flags
, BGP_EVPNES_BYPASS
);
2275 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2276 zlog_debug("local es %s bypass %s", es
->esi_str
,
2277 bypass
? "set" : "clear");
2279 new_active
= bgp_evpn_local_es_is_active(es
);
2280 if (old_active
!= new_active
) {
2282 bgp_evpn_local_es_activate(bgp
, es
, true, true);
2284 bgp_evpn_local_es_deactivate(bgp
, es
);
2287 is_local
= bgp_evpn_is_es_local_and_non_bypass(es
);
2288 if (old_is_local
!= is_local
)
2289 bgp_evpn_mac_update_on_es_local_chg(es
, is_local
);
2292 static void bgp_evpn_local_es_do_del(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
2294 struct bgp_evpn_es_evi
*es_evi
;
2295 struct listnode
*evi_node
, *evi_next_node
;
2297 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2298 zlog_debug("del local es %s", es
->esi_str
);
2300 /* Delete all local EVPN ES routes from ESI table
2301 * and schedule for processing (to withdraw from peers))
2303 bgp_evpn_es_route_del_all(bgp
, es
);
2305 /* release all local ES EVIs associated with the ES */
2306 for (ALL_LIST_ELEMENTS(es
->es_evi_list
, evi_node
,
2307 evi_next_node
, es_evi
)) {
2308 bgp_evpn_local_es_evi_do_del(es_evi
);
2311 /* Clear local info associated with the ES and free it up if there is
2312 * no remote reference
2314 bgp_evpn_es_local_info_clear(es
, false);
2317 bool bgp_evpn_is_esi_local_and_non_bypass(esi_t
*esi
)
2319 struct bgp_evpn_es
*es
= NULL
;
2321 /* Lookup ESI hash - should exist. */
2322 es
= bgp_evpn_es_find(esi
);
2324 return es
&& bgp_evpn_is_es_local_and_non_bypass(es
);
2327 int bgp_evpn_local_es_del(struct bgp
*bgp
, esi_t
*esi
)
2329 struct bgp_evpn_es
*es
= NULL
;
2331 /* Lookup ESI hash - should exist. */
2332 es
= bgp_evpn_es_find(esi
);
2334 flog_warn(EC_BGP_EVPN_ESI
, "%u: ES missing at local ES DEL",
2339 bgp_evpn_local_es_do_del(bgp
, es
);
2343 /* Handle device to ES id association. Results in the creation of a local
2346 int bgp_evpn_local_es_add(struct bgp
*bgp
, esi_t
*esi
,
2347 struct in_addr originator_ip
, bool oper_up
,
2348 uint16_t df_pref
, bool bypass
)
2350 struct bgp_evpn_es
*es
;
2352 bool regen_esr
= false;
2354 /* create the new es */
2355 es
= bgp_evpn_es_find(esi
);
2357 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
2360 es
= bgp_evpn_es_new(bgp
, esi
);
2362 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2363 zlog_debug("add local es %s orig-ip %pI4 df_pref %u %s",
2364 es
->esi_str
, &originator_ip
, df_pref
,
2365 bypass
? "bypass" : "");
2367 es
->originator_ip
= originator_ip
;
2368 if (df_pref
!= es
->df_pref
) {
2369 es
->df_pref
= df_pref
;
2372 bgp_evpn_es_local_info_set(bgp
, es
);
2374 /* import all remote Type-4 routes in the ES table */
2376 bgp_evpn_type4_remote_routes_import(bgp
, es
,
2377 true /* install */);
2379 /* create and advertise EAD-EVI routes for the ES -
2380 * XXX - till an ES-EVI reference is created there is really nothing to
2383 if (bgp_mh_info
->ead_evi_adv_for_down_links
)
2384 bgp_evpn_local_type1_evi_route_add(bgp
, es
);
2386 bgp_evpn_local_es_bypass_update(bgp
, es
, bypass
);
2388 /* If the ES link is operationally up generate EAD-ES. EAD-EVI
2389 * can be generated even if the link is inactive.
2392 bgp_evpn_local_es_up(bgp
, es
, regen_esr
);
2394 bgp_evpn_local_es_down(bgp
, es
);
2399 static void bgp_evpn_es_json_frag_fill(json_object
*json_frags
,
2400 struct bgp_evpn_es
*es
)
2402 json_object
*json_frag
;
2403 struct listnode
*node
;
2404 struct bgp_evpn_es_frag
*es_frag
;
2406 for (ALL_LIST_ELEMENTS_RO(es
->es_frag_list
, node
, es_frag
)) {
2407 json_frag
= json_object_new_object();
2409 json_object_string_addf(json_frag
, "rd", "%pRD", &es_frag
->prd
);
2410 json_object_int_add(json_frag
, "eviCount",
2411 listcount(es_frag
->es_evi_frag_list
));
2413 json_object_array_add(json_frags
, json_frag
);
2417 static void bgp_evpn_es_frag_show_detail(struct vty
*vty
,
2418 struct bgp_evpn_es
*es
)
2420 struct listnode
*node
;
2421 struct bgp_evpn_es_frag
*es_frag
;
2423 for (ALL_LIST_ELEMENTS_RO(es
->es_frag_list
, node
, es_frag
)) {
2424 vty_out(vty
, " %pRD EVIs: %d\n", &es_frag
->prd
,
2425 listcount(es_frag
->es_evi_frag_list
));
2429 static char *bgp_evpn_es_vteps_str(char *vtep_str
, struct bgp_evpn_es
*es
,
2430 uint8_t vtep_str_size
)
2432 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
2433 struct listnode
*node
;
2434 struct bgp_evpn_es_vtep
*es_vtep
;
2436 char ip_buf
[INET_ADDRSTRLEN
];
2439 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
2440 vtep_flag_str
[0] = '\0';
2442 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
2443 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
2444 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
2445 strlcat(vtep_flag_str
, "A", sizeof(vtep_flag_str
));
2447 if (!strlen(vtep_flag_str
))
2448 strlcat(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
2452 strlcat(vtep_str
, ",", vtep_str_size
);
2454 inet_ntop(AF_INET
, &es_vtep
->vtep_ip
, ip_buf
,
2457 strlcat(vtep_str
, "(", vtep_str_size
);
2458 strlcat(vtep_str
, vtep_flag_str
, vtep_str_size
);
2459 strlcat(vtep_str
, ")", vtep_str_size
);
2465 static void bgp_evpn_es_json_vtep_fill(json_object
*json_vteps
,
2466 struct bgp_evpn_es_vtep
*es_vtep
)
2468 json_object
*json_vtep_entry
;
2469 json_object
*json_flags
;
2471 json_vtep_entry
= json_object_new_object();
2473 json_object_string_addf(json_vtep_entry
, "vtep_ip", "%pI4",
2475 if (es_vtep
->flags
& (BGP_EVPNES_VTEP_ESR
|
2476 BGP_EVPNES_VTEP_ACTIVE
)) {
2477 json_flags
= json_object_new_array();
2478 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
2479 json_array_string_add(json_flags
, "esr");
2480 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
2481 json_array_string_add(json_flags
, "active");
2482 json_object_object_add(json_vtep_entry
, "flags", json_flags
);
2483 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
) {
2484 json_object_int_add(json_vtep_entry
, "dfPreference",
2486 json_object_int_add(json_vtep_entry
, "dfAlgorithm",
2491 json_object_array_add(json_vteps
,
2495 static void bgp_evpn_es_vteps_show_detail(struct vty
*vty
,
2496 struct bgp_evpn_es
*es
)
2498 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
2499 struct listnode
*node
;
2500 struct bgp_evpn_es_vtep
*es_vtep
;
2501 char alg_buf
[EVPN_DF_ALG_STR_LEN
];
2503 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
2504 vtep_flag_str
[0] = '\0';
2505 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
2506 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
2507 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
2508 strlcat(vtep_flag_str
, "A", sizeof(vtep_flag_str
));
2510 if (!strlen(vtep_flag_str
))
2511 strlcat(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
2513 vty_out(vty
, " %pI4 flags: %s", &es_vtep
->vtep_ip
,
2516 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
2517 vty_out(vty
, " df_alg: %s df_pref: %u\n",
2518 evpn_es_df_alg2str(es_vtep
->df_alg
, alg_buf
,
2526 static void bgp_evpn_es_show_entry(struct vty
*vty
,
2527 struct bgp_evpn_es
*es
, json_object
*json
)
2529 struct listnode
*node
;
2530 struct bgp_evpn_es_vtep
*es_vtep
;
2533 json_object
*json_vteps
;
2534 json_object
*json_types
;
2536 json_object_string_add(json
, "esi", es
->esi_str
);
2537 if (es
->es_base_frag
)
2538 json_object_string_addf(json
, "rd", "%pRD",
2539 &es
->es_base_frag
->prd
);
2541 if (es
->flags
& (BGP_EVPNES_LOCAL
| BGP_EVPNES_REMOTE
)) {
2542 json_types
= json_object_new_array();
2543 if (es
->flags
& BGP_EVPNES_LOCAL
)
2544 json_array_string_add(json_types
, "local");
2545 if (es
->flags
& BGP_EVPNES_REMOTE
)
2546 json_array_string_add(json_types
, "remote");
2547 json_object_object_add(json
, "type", json_types
);
2550 if (listcount(es
->es_vtep_list
)) {
2551 json_vteps
= json_object_new_array();
2552 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
,
2554 bgp_evpn_es_json_vtep_fill(json_vteps
, es_vtep
);
2556 json_object_object_add(json
, "vteps", json_vteps
);
2558 json_object_int_add(json
, "vniCount",
2559 listcount(es
->es_evi_list
));
2562 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
2565 if (es
->flags
& BGP_EVPNES_BYPASS
)
2566 strlcat(type_str
, "B", sizeof(type_str
));
2567 if (es
->flags
& BGP_EVPNES_LOCAL
)
2568 strlcat(type_str
, "L", sizeof(type_str
));
2569 if (es
->flags
& BGP_EVPNES_REMOTE
)
2570 strlcat(type_str
, "R", sizeof(type_str
));
2571 if (es
->inconsistencies
)
2572 strlcat(type_str
, "I", sizeof(type_str
));
2574 bgp_evpn_es_vteps_str(vtep_str
, es
, sizeof(vtep_str
));
2576 vty_out(vty
, "%-30s %-5s %-21pRD %-8d %s\n", es
->esi_str
,
2577 type_str
, &es
->es_base_frag
->prd
,
2578 listcount(es
->es_evi_list
), vtep_str
);
2582 static void bgp_evpn_es_show_entry_detail(struct vty
*vty
,
2583 struct bgp_evpn_es
*es
, json_object
*json
)
2586 json_object
*json_flags
;
2587 json_object
*json_incons
;
2588 json_object
*json_vteps
;
2589 json_object
*json_frags
;
2590 struct listnode
*node
;
2591 struct bgp_evpn_es_vtep
*es_vtep
;
2593 /* Add the "brief" info first */
2594 bgp_evpn_es_show_entry(vty
, es
, json
);
2596 & (BGP_EVPNES_OPER_UP
| BGP_EVPNES_ADV_EVI
2597 | BGP_EVPNES_BYPASS
)) {
2598 json_flags
= json_object_new_array();
2599 if (es
->flags
& BGP_EVPNES_OPER_UP
)
2600 json_array_string_add(json_flags
, "up");
2601 if (es
->flags
& BGP_EVPNES_ADV_EVI
)
2602 json_array_string_add(json_flags
,
2604 if (es
->flags
& BGP_EVPNES_BYPASS
)
2605 json_array_string_add(json_flags
, "bypass");
2606 json_object_object_add(json
, "flags", json_flags
);
2608 json_object_string_addf(json
, "originator_ip", "%pI4",
2609 &es
->originator_ip
);
2610 json_object_int_add(json
, "remoteVniCount",
2611 es
->remote_es_evi_cnt
);
2612 json_object_int_add(json
, "vrfCount",
2613 listcount(es
->es_vrf_list
));
2614 json_object_int_add(json
, "macipPathCount",
2615 listcount(es
->macip_evi_path_list
));
2616 json_object_int_add(json
, "macipGlobalPathCount",
2617 listcount(es
->macip_global_path_list
));
2618 json_object_int_add(json
, "inconsistentVniVtepCount",
2619 es
->incons_evi_vtep_cnt
);
2620 if (listcount(es
->es_vtep_list
)) {
2621 json_vteps
= json_object_new_array();
2622 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
,
2624 bgp_evpn_es_json_vtep_fill(json_vteps
, es_vtep
);
2626 json_object_object_add(json
, "vteps", json_vteps
);
2628 if (listcount(es
->es_frag_list
)) {
2629 json_frags
= json_object_new_array();
2630 bgp_evpn_es_json_frag_fill(json_frags
, es
);
2631 json_object_object_add(json
, "fragments", json_frags
);
2633 if (es
->inconsistencies
) {
2634 json_incons
= json_object_new_array();
2635 if (es
->inconsistencies
& BGP_EVPNES_INCONS_VTEP_LIST
)
2636 json_array_string_add(json_incons
,
2637 "vni-vtep-mismatch");
2638 json_object_object_add(json
, "inconsistencies",
2642 char incons_str
[BGP_EVPNES_INCONS_STR_SZ
];
2646 if (es
->flags
& BGP_EVPNES_LOCAL
)
2647 strlcat(type_str
, "L", sizeof(type_str
));
2648 if (es
->flags
& BGP_EVPNES_REMOTE
)
2649 strlcat(type_str
, "R", sizeof(type_str
));
2651 vty_out(vty
, "ESI: %s\n", es
->esi_str
);
2652 vty_out(vty
, " Type: %s\n", type_str
);
2653 vty_out(vty
, " RD: %pRD\n", &es
->es_base_frag
->prd
);
2654 vty_out(vty
, " Originator-IP: %pI4\n", &es
->originator_ip
);
2655 if (es
->flags
& BGP_EVPNES_LOCAL
)
2656 vty_out(vty
, " Local ES DF preference: %u\n",
2658 if (es
->flags
& BGP_EVPNES_BYPASS
)
2659 vty_out(vty
, " LACP bypass: on\n");
2660 vty_out(vty
, " VNI Count: %d\n", listcount(es
->es_evi_list
));
2661 vty_out(vty
, " Remote VNI Count: %d\n",
2662 es
->remote_es_evi_cnt
);
2663 vty_out(vty
, " VRF Count: %d\n", listcount(es
->es_vrf_list
));
2664 vty_out(vty
, " MACIP EVI Path Count: %d\n",
2665 listcount(es
->macip_evi_path_list
));
2666 vty_out(vty
, " MACIP Global Path Count: %d\n",
2667 listcount(es
->macip_global_path_list
));
2668 vty_out(vty
, " Inconsistent VNI VTEP Count: %d\n",
2669 es
->incons_evi_vtep_cnt
);
2670 if (es
->inconsistencies
) {
2671 incons_str
[0] = '\0';
2672 if (es
->inconsistencies
& BGP_EVPNES_INCONS_VTEP_LIST
)
2673 strlcat(incons_str
, "vni-vtep-mismatch",
2674 sizeof(incons_str
));
2676 strlcpy(incons_str
, "-", sizeof(incons_str
));
2678 vty_out(vty
, " Inconsistencies: %s\n",
2680 if (listcount(es
->es_frag_list
)) {
2681 vty_out(vty
, " Fragments:\n");
2682 bgp_evpn_es_frag_show_detail(vty
, es
);
2684 if (listcount(es
->es_vtep_list
)) {
2685 vty_out(vty
, " VTEPs:\n");
2686 bgp_evpn_es_vteps_show_detail(vty
, es
);
2692 /* Display all ESs */
2693 void bgp_evpn_es_show(struct vty
*vty
, bool uj
, bool detail
)
2695 struct bgp_evpn_es
*es
;
2696 json_object
*json_array
= NULL
;
2697 json_object
*json
= NULL
;
2700 /* create an array of ESs */
2701 json_array
= json_object_new_array();
2705 "ES Flags: B - bypass, L local, R remote, I inconsistent\n");
2707 "VTEP Flags: E ESR/Type-4, A active nexthop\n");
2709 "%-30s %-5s %-21s %-8s %s\n",
2710 "ESI", "Flags", "RD", "#VNIs", "VTEPs");
2714 RB_FOREACH(es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
) {
2716 /* create a separate json object for each ES */
2717 json
= json_object_new_object();
2719 bgp_evpn_es_show_entry_detail(vty
, es
, json
);
2721 bgp_evpn_es_show_entry(vty
, es
, json
);
2722 /* add ES to the json array */
2724 json_object_array_add(json_array
, json
);
2727 /* print the array of json-ESs */
2729 vty_json(vty
, json_array
);
2732 /* Display specific ES */
2733 void bgp_evpn_es_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
)
2735 struct bgp_evpn_es
*es
;
2736 json_object
*json
= NULL
;
2739 json
= json_object_new_object();
2741 es
= bgp_evpn_es_find(esi
);
2743 bgp_evpn_es_show_entry_detail(vty
, es
, json
);
2746 vty_out(vty
, "ESI not found\n");
2750 vty_json(vty
, json
);
2753 /*****************************************************************************/
2754 /* Ethernet Segment to VRF association -
2755 * 1. Each ES-EVI entry is associated with a tenant VRF. This associaton
2756 * triggers the creation of an ES-VRF entry.
2757 * 2. The ES-VRF entry is maintained for the purpose of L3-NHG creation
2758 * 3. Type-2/MAC-IP routes are imported into a tenant VRF and programmed as
2759 * a /32 or host route entry in the dataplane. If the destination of
2760 * the host route is a remote-ES the route is programmed with the
2761 * corresponding (keyed in by {vrf,ES-id}) L3-NHG.
2762 * 4. The reason for this indirection (route->L3-NHG, L3-NHG->list-of-VTEPs)
2763 * is to avoid route updates to the dplane when a remote-ES link flaps i.e.
2764 * instead of updating all the dependent routes the NHG's contents are updated.
2765 * This reduces the amount of datplane updates (nhg updates vs. route updates)
2766 * allowing for a faster failover.
2768 * XXX - can the L3 SVI index change without change in vpn->bgp_vrf
2769 * association? If yes we need to handle that by updating all the L3 NHGs
2772 /******************************** L3 NHG management *************************/
2773 static void bgp_evpn_l3nhg_zebra_add_v4_or_v6(struct bgp_evpn_es_vrf
*es_vrf
,
2776 uint32_t nhg_id
= v4_nhg
? es_vrf
->nhg_id
: es_vrf
->v6_nhg_id
;
2777 struct bgp_evpn_es
*es
= es_vrf
->es
;
2778 struct listnode
*node
;
2779 struct bgp_evpn_es_vtep
*es_vtep
;
2781 struct zapi_nexthop
*api_nh
;
2782 struct zapi_nhg api_nhg
= {};
2784 /* Skip installation of L3-NHG if host routes used */
2788 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2789 zlog_debug("es %s vrf %u %s nhg %u to zebra", es
->esi_str
,
2790 es_vrf
->bgp_vrf
->vrf_id
,
2791 v4_nhg
? "v4_nhg" : "v6_nhg", nhg_id
);
2793 frrtrace(4, frr_bgp
, evpn_mh_nhg_zsend
, true, v4_nhg
, nhg_id
, es_vrf
);
2795 /* only the gateway ip changes for each NH. rest of the params
2798 memset(&nh
, 0, sizeof(nh
));
2799 nh
.vrf_id
= es_vrf
->bgp_vrf
->vrf_id
;
2800 nh
.flags
= NEXTHOP_FLAG_ONLINK
;
2801 nh
.ifindex
= es_vrf
->bgp_vrf
->l3vni_svi_ifindex
;
2804 v4_nhg
? NEXTHOP_TYPE_IPV4_IFINDEX
: NEXTHOP_TYPE_IPV6_IFINDEX
;
2806 api_nhg
.id
= nhg_id
;
2807 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
2808 if (!CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
2811 /* Don't overrun the zapi buffer. */
2812 if (api_nhg
.nexthop_num
== MULTIPATH_NUM
)
2815 /* overwrite the gw */
2817 nh
.gate
.ipv4
= es_vtep
->vtep_ip
;
2819 ipv4_to_ipv4_mapped_ipv6(&nh
.gate
.ipv6
,
2822 /* convert to zapi format */
2823 api_nh
= &api_nhg
.nexthops
[api_nhg
.nexthop_num
];
2824 zapi_nexthop_from_nexthop(api_nh
, &nh
);
2826 ++api_nhg
.nexthop_num
;
2827 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2828 zlog_debug("nhg %u vtep %pI4 l3-svi %d", api_nhg
.id
,
2830 es_vrf
->bgp_vrf
->l3vni_svi_ifindex
);
2832 frrtrace(3, frr_bgp
, evpn_mh_nh_zsend
, nhg_id
, es_vtep
, es_vrf
);
2835 if (!api_nhg
.nexthop_num
)
2838 zclient_nhg_send(zclient
, ZEBRA_NHG_ADD
, &api_nhg
);
2841 static bool bgp_evpn_l3nhg_zebra_ok(struct bgp_evpn_es_vrf
*es_vrf
)
2843 if (!bgp_mh_info
->host_routes_use_l3nhg
)
2847 if (!zclient
|| zclient
->sock
< 0)
2853 static void bgp_evpn_l3nhg_zebra_add(struct bgp_evpn_es_vrf
*es_vrf
)
2855 if (!bgp_evpn_l3nhg_zebra_ok(es_vrf
))
2858 bgp_evpn_l3nhg_zebra_add_v4_or_v6(es_vrf
, true /*v4_nhg*/);
2859 bgp_evpn_l3nhg_zebra_add_v4_or_v6(es_vrf
, false /*v4_nhg*/);
2862 static void bgp_evpn_l3nhg_zebra_del_v4_or_v6(struct bgp_evpn_es_vrf
*es_vrf
,
2865 struct zapi_nhg api_nhg
= {};
2867 api_nhg
.id
= v4_nhg
? es_vrf
->nhg_id
: es_vrf
->v6_nhg_id
;
2869 /* Skip installation of L3-NHG if host routes used */
2873 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2874 zlog_debug("es %s vrf %u %s nhg %u to zebra",
2875 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2876 v4_nhg
? "v4_nhg" : "v6_nhg", api_nhg
.id
);
2879 frrtrace(4, frr_bgp
, evpn_mh_nhg_zsend
, false, v4_nhg
, api_nhg
.id
,
2882 zclient_nhg_send(zclient
, ZEBRA_NHG_DEL
, &api_nhg
);
2885 static void bgp_evpn_l3nhg_zebra_del(struct bgp_evpn_es_vrf
*es_vrf
)
2887 if (!bgp_evpn_l3nhg_zebra_ok(es_vrf
))
2890 bgp_evpn_l3nhg_zebra_del_v4_or_v6(es_vrf
, true /*v4_nhg*/);
2891 bgp_evpn_l3nhg_zebra_del_v4_or_v6(es_vrf
, false /*v4_nhg*/);
2894 static void bgp_evpn_l3nhg_deactivate(struct bgp_evpn_es_vrf
*es_vrf
)
2896 if (!(es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
))
2899 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2900 zlog_debug("es %s vrf %u nhg %u de-activate",
2901 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2903 bgp_evpn_l3nhg_zebra_del(es_vrf
);
2904 es_vrf
->flags
&= ~BGP_EVPNES_VRF_NHG_ACTIVE
;
2905 /* MAC-IPs can now be installed via the L3NHG */
2906 bgp_evpn_es_path_update_on_es_vrf_chg(es_vrf
, "l3nhg-deactivate");
2909 static void bgp_evpn_l3nhg_activate(struct bgp_evpn_es_vrf
*es_vrf
, bool update
)
2911 if (!bgp_evpn_es_get_active_vtep_cnt(es_vrf
->es
)) {
2912 bgp_evpn_l3nhg_deactivate(es_vrf
);
2916 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
) {
2920 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2921 zlog_debug("es %s vrf %u nhg %u activate",
2922 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2924 es_vrf
->flags
|= BGP_EVPNES_VRF_NHG_ACTIVE
;
2925 /* MAC-IPs can now be installed via the L3NHG */
2926 bgp_evpn_es_path_update_on_es_vrf_chg(es_vrf
, "l3nhg_activate");
2929 bgp_evpn_l3nhg_zebra_add(es_vrf
);
2932 /* when a VTEP is activated or de-activated against an ES associated
2933 * VRFs' NHG needs to be updated
2935 static void bgp_evpn_l3nhg_update_on_vtep_chg(struct bgp_evpn_es
*es
)
2937 struct bgp_evpn_es_vrf
*es_vrf
;
2938 struct listnode
*es_vrf_node
;
2940 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2941 zlog_debug("es %s nhg update on vtep chg", es
->esi_str
);
2943 for (ALL_LIST_ELEMENTS_RO(es
->es_vrf_list
, es_vrf_node
, es_vrf
))
2944 bgp_evpn_l3nhg_activate(es_vrf
, true /* update */);
2947 /* compare ES-IDs for the ES-VRF RB tree maintained per-VRF */
2948 static int bgp_es_vrf_rb_cmp(const struct bgp_evpn_es_vrf
*es_vrf1
,
2949 const struct bgp_evpn_es_vrf
*es_vrf2
)
2951 return memcmp(&es_vrf1
->es
->esi
, &es_vrf2
->es
->esi
, ESI_BYTES
);
2953 RB_GENERATE(bgp_es_vrf_rb_head
, bgp_evpn_es_vrf
, rb_node
, bgp_es_vrf_rb_cmp
);
2955 /* Initialize the ES tables maintained per-tenant vrf */
2956 void bgp_evpn_vrf_es_init(struct bgp
*bgp_vrf
)
2958 /* Initialize the ES-VRF RB tree */
2959 RB_INIT(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
);
2962 /* find the ES-VRF in the per-VRF RB tree */
2963 static struct bgp_evpn_es_vrf
*bgp_evpn_es_vrf_find(struct bgp_evpn_es
*es
,
2964 struct bgp
*bgp_vrf
)
2966 struct bgp_evpn_es_vrf es_vrf
;
2970 return RB_FIND(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, &es_vrf
);
2973 /* allocate a new ES-VRF and setup L3NHG for it */
2974 static struct bgp_evpn_es_vrf
*bgp_evpn_es_vrf_create(struct bgp_evpn_es
*es
,
2975 struct bgp
*bgp_vrf
)
2977 struct bgp_evpn_es_vrf
*es_vrf
;
2979 es_vrf
= XCALLOC(MTYPE_BGP_EVPN_ES_VRF
, sizeof(*es_vrf
));
2982 es_vrf
->bgp_vrf
= bgp_vrf
;
2984 /* insert into the VRF-ESI rb tree */
2985 RB_INSERT(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, es_vrf
);
2987 /* add to the ES's VRF list */
2988 listnode_init(&es_vrf
->es_listnode
, es_vrf
);
2989 listnode_add(es
->es_vrf_list
, &es_vrf
->es_listnode
);
2991 /* setup the L3 NHG id for the ES */
2992 es_vrf
->nhg_id
= bgp_l3nhg_id_alloc();
2993 es_vrf
->v6_nhg_id
= bgp_l3nhg_id_alloc();
2995 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2996 zlog_debug("es %s vrf %u nhg %u v6_nhg %d create", es
->esi_str
,
2997 bgp_vrf
->vrf_id
, es_vrf
->nhg_id
, es_vrf
->v6_nhg_id
);
2998 bgp_evpn_l3nhg_activate(es_vrf
, false /* update */);
3000 /* update paths in the VRF that may already be associated with
3001 * this destination ES
3003 bgp_evpn_es_path_update_on_es_vrf_chg(es_vrf
, "es-vrf-create");
3008 /* remove the L3-NHG associated with the ES-VRF and free it */
3009 static void bgp_evpn_es_vrf_delete(struct bgp_evpn_es_vrf
*es_vrf
)
3011 struct bgp_evpn_es
*es
= es_vrf
->es
;
3012 struct bgp
*bgp_vrf
= es_vrf
->bgp_vrf
;
3014 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3015 zlog_debug("es %s vrf %u nhg %u delete", es
->esi_str
,
3016 bgp_vrf
->vrf_id
, es_vrf
->nhg_id
);
3018 /* Remove the NHG resources */
3019 bgp_evpn_l3nhg_deactivate(es_vrf
);
3021 bgp_l3nhg_id_free(es_vrf
->nhg_id
);
3023 if (es_vrf
->v6_nhg_id
)
3024 bgp_l3nhg_id_free(es_vrf
->v6_nhg_id
);
3025 es_vrf
->v6_nhg_id
= 0;
3027 /* remove from the ES's VRF list */
3028 list_delete_node(es
->es_vrf_list
, &es_vrf
->es_listnode
);
3030 /* remove from the VRF-ESI rb tree */
3031 RB_REMOVE(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, es_vrf
);
3033 /* update paths in the VRF that may already be associated with
3034 * this destination ES
3036 bgp_evpn_es_path_update_on_es_vrf_chg(es_vrf
, "es-vrf-delete");
3038 XFREE(MTYPE_BGP_EVPN_ES_VRF
, es_vrf
);
3041 /* deref and delete if there are no references */
3042 void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi
*es_evi
)
3044 struct bgp_evpn_es_vrf
*es_vrf
= es_evi
->es_vrf
;
3049 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3050 zlog_debug("es-evi %s vni %u vrf %u de-ref",
3051 es_evi
->es
->esi_str
, es_evi
->vpn
->vni
,
3052 es_vrf
->bgp_vrf
->vrf_id
);
3054 es_evi
->es_vrf
= NULL
;
3055 if (es_vrf
->ref_cnt
)
3058 if (!es_vrf
->ref_cnt
)
3059 bgp_evpn_es_vrf_delete(es_vrf
);
3062 /* find or create and reference */
3063 void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi
*es_evi
, struct bgp
*bgp_vrf
)
3065 struct bgp_evpn_es
*es
= es_evi
->es
;
3066 struct bgp_evpn_es_vrf
*es_vrf
= es_evi
->es_vrf
;
3067 struct bgp
*old_bgp_vrf
= NULL
;
3070 old_bgp_vrf
= es_vrf
->bgp_vrf
;
3072 if (old_bgp_vrf
== bgp_vrf
)
3075 /* deref the old ES-VRF */
3076 bgp_evpn_es_vrf_deref(es_evi
);
3081 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3082 zlog_debug("es-evi %s vni %u vrf %u ref", es_evi
->es
->esi_str
,
3083 es_evi
->vpn
->vni
, bgp_vrf
->vrf_id
);
3085 /* find-create the new ES-VRF */
3086 es_vrf
= bgp_evpn_es_vrf_find(es
, bgp_vrf
);
3088 es_vrf
= bgp_evpn_es_vrf_create(es
, bgp_vrf
);
3090 es_evi
->es_vrf
= es_vrf
;
3094 /* When the L2-VNI is associated with a L3-VNI/VRF update all the
3095 * associated ES-EVI entries
3097 void bgp_evpn_es_evi_vrf_deref(struct bgpevpn
*vpn
)
3099 struct bgp_evpn_es_evi
*es_evi
;
3101 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3102 zlog_debug("es-vrf de-ref for vni %u", vpn
->vni
);
3104 RB_FOREACH (es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
)
3105 bgp_evpn_es_vrf_deref(es_evi
);
3107 void bgp_evpn_es_evi_vrf_ref(struct bgpevpn
*vpn
)
3109 struct bgp_evpn_es_evi
*es_evi
;
3111 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3112 zlog_debug("es-vrf ref for vni %u", vpn
->vni
);
3114 RB_FOREACH (es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
)
3115 bgp_evpn_es_vrf_ref(es_evi
, vpn
->bgp_vrf
);
3118 /* 1. If ES-VRF is not present install the host route with the exploded/flat
3120 * 2. If ES-VRF is present -
3121 * - if L3NHG has not been activated for the ES-VRF (this could be because
3122 * all the PEs attached to the VRF are down) do not install the route
3124 * - if L3NHG has been activated install the route via that L3NHG
3126 void bgp_evpn_es_vrf_use_nhg(struct bgp
*bgp_vrf
, esi_t
*esi
, bool *use_l3nhg
,
3127 bool *is_l3nhg_active
,
3128 struct bgp_evpn_es_vrf
**es_vrf_p
)
3130 struct bgp_evpn_es
*es
;
3131 struct bgp_evpn_es_vrf
*es_vrf
;
3133 if (!bgp_mh_info
->host_routes_use_l3nhg
)
3136 es
= bgp_evpn_es_find(esi
);
3140 es_vrf
= bgp_evpn_es_vrf_find(es
, bgp_vrf
);
3145 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
)
3146 *is_l3nhg_active
= true;
3151 /* returns false if legacy-exploded mp needs to be used for route install */
3152 bool bgp_evpn_path_es_use_nhg(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
,
3156 struct bgp_evpn_es_vrf
*es_vrf
= NULL
;
3157 struct bgp_path_info
*parent_pi
;
3158 struct bgp_node
*rn
;
3159 struct prefix_evpn
*evp
;
3160 struct bgp_path_info
*mpinfo
;
3161 bool use_l3nhg
= false;
3162 bool is_l3nhg_active
= false;
3166 /* we don't support NHG for routes leaked from another VRF yet */
3167 if (pi
->extra
&& pi
->extra
->bgp_orig
)
3170 parent_pi
= get_route_parent_evpn(pi
);
3174 rn
= parent_pi
->net
;
3178 evp
= (struct prefix_evpn
*)&rn
->p
;
3179 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
3182 /* non-es path, use legacy-exploded multipath */
3183 esi
= bgp_evpn_attr_get_esi(parent_pi
->attr
);
3184 if (!memcmp(esi
, zero_esi
, sizeof(*esi
)))
3187 /* we don't support NHG for d-vni yet */
3188 if (bgp_evpn_mpath_has_dvni(bgp_vrf
, pi
))
3191 bgp_evpn_es_vrf_use_nhg(bgp_vrf
, esi
, &use_l3nhg
, &is_l3nhg_active
,
3194 /* L3NHG support is disabled, use legacy-exploded multipath */
3198 /* if the NHG has not been installed we cannot install the route yet,
3199 * return a 0-NHG to indicate that
3201 if (!is_l3nhg_active
)
3204 /* this needs to be set the v6NHG if v6route */
3205 if (is_evpn_prefix_ipaddr_v6(evp
))
3206 *nhg_p
= es_vrf
->v6_nhg_id
;
3208 *nhg_p
= es_vrf
->nhg_id
;
3210 for (mpinfo
= bgp_path_info_mpath_next(pi
); mpinfo
;
3211 mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
3212 /* if any of the paths have a different ESI we can't use
3213 * the NHG associated with the ES. fallback to legacy-exploded
3216 if (memcmp(esi
, bgp_evpn_attr_get_esi(mpinfo
->attr
),
3224 static void bgp_evpn_es_vrf_show_entry(struct vty
*vty
,
3225 struct bgp_evpn_es_vrf
*es_vrf
,
3228 struct bgp_evpn_es
*es
= es_vrf
->es
;
3229 struct bgp
*bgp_vrf
= es_vrf
->bgp_vrf
;
3232 json_object
*json_types
;
3234 json_object_string_add(json
, "esi", es
->esi_str
);
3235 json_object_string_add(json
, "vrf", bgp_vrf
->name_pretty
);
3237 if (es_vrf
->flags
& (BGP_EVPNES_VRF_NHG_ACTIVE
)) {
3238 json_types
= json_object_new_array();
3239 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
)
3240 json_array_string_add(json_types
, "active");
3241 json_object_object_add(json
, "flags", json_types
);
3244 json_object_int_add(json
, "ipv4NHG", es_vrf
->nhg_id
);
3245 json_object_int_add(json
, "ipv6NHG", es_vrf
->v6_nhg_id
);
3246 json_object_int_add(json
, "refCount", es_vrf
->ref_cnt
);
3250 flags_str
[0] = '\0';
3251 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
)
3252 strlcat(flags_str
, "A", sizeof(flags_str
));
3254 vty_out(vty
, "%-30s %-15s %-5s %-8u %-8u %u\n", es
->esi_str
,
3255 bgp_vrf
->name_pretty
, flags_str
, es_vrf
->nhg_id
,
3256 es_vrf
->v6_nhg_id
, es_vrf
->ref_cnt
);
3260 static void bgp_evpn_es_vrf_show_es(struct vty
*vty
, json_object
*json_array
,
3261 struct bgp_evpn_es
*es
)
3263 json_object
*json
= NULL
;
3264 struct listnode
*es_vrf_node
;
3265 struct bgp_evpn_es_vrf
*es_vrf
;
3267 for (ALL_LIST_ELEMENTS_RO(es
->es_vrf_list
, es_vrf_node
, es_vrf
)) {
3268 /* create a separate json object for each ES-VRF */
3270 json
= json_object_new_object();
3271 bgp_evpn_es_vrf_show_entry(vty
, es_vrf
, json
);
3272 /* add ES-VRF to the json array */
3274 json_object_array_add(json_array
, json
);
3278 /* Display all ES VRFs */
3279 void bgp_evpn_es_vrf_show(struct vty
*vty
, bool uj
, struct bgp_evpn_es
*es
)
3281 json_object
*json_array
= NULL
;
3284 /* create an array of ESs */
3285 json_array
= json_object_new_array();
3287 vty_out(vty
, "ES-VRF Flags: A Active\n");
3288 vty_out(vty
, "%-30s %-15s %-5s %-8s %-8s %s\n", "ESI", "VRF",
3289 "Flags", "IPv4-NHG", "IPv6-NHG", "Ref");
3293 bgp_evpn_es_vrf_show_es(vty
, json_array
, es
);
3295 RB_FOREACH (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
)
3296 bgp_evpn_es_vrf_show_es(vty
, json_array
, es
);
3299 /* print the array of json-ESs */
3301 vty_json(vty
, json_array
);
3304 /* Display specific ES VRF */
3305 void bgp_evpn_es_vrf_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
)
3307 struct bgp_evpn_es
*es
;
3309 es
= bgp_evpn_es_find(esi
);
3311 bgp_evpn_es_vrf_show(vty
, uj
, es
);
3314 vty_out(vty
, "ESI not found\n");
3318 /*****************************************************************************/
3319 /* Ethernet Segment to EVI association -
3320 * 1. The ES-EVI entry is maintained as a RB tree per L2-VNI
3321 * (bgpevpn->es_evi_rb_tree).
3322 * 2. Each local ES-EVI entry is rxed from zebra and then used by BGP to
3323 * advertises an EAD-EVI (Type-1 EVPN) route
3324 * 3. The remote ES-EVI is created when a bgp_evpn_es_evi_vtep references
3328 /* A list of remote VTEPs is maintained for each ES-EVI. This list includes -
3329 * 1. VTEPs for which we have imported the EAD-per-ES Type1 route
3330 * 2. VTEPs for which we have imported the EAD-per-EVI Type1 route
3331 * VTEPs for which both routes have been rxed are activated. Activation
3332 * creates a NHG in the parent ES.
3334 static int bgp_evpn_es_evi_vtep_cmp(void *p1
, void *p2
)
3336 const struct bgp_evpn_es_evi_vtep
*evi_vtep1
= p1
;
3337 const struct bgp_evpn_es_evi_vtep
*evi_vtep2
= p2
;
3339 return evi_vtep1
->vtep_ip
.s_addr
- evi_vtep2
->vtep_ip
.s_addr
;
3342 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_vtep_new(
3343 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
)
3345 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3347 evi_vtep
= XCALLOC(MTYPE_BGP_EVPN_ES_EVI_VTEP
, sizeof(*evi_vtep
));
3349 evi_vtep
->es_evi
= es_evi
;
3350 evi_vtep
->vtep_ip
.s_addr
= vtep_ip
.s_addr
;
3351 listnode_init(&evi_vtep
->es_evi_listnode
, evi_vtep
);
3352 listnode_add_sort(es_evi
->es_evi_vtep_list
, &evi_vtep
->es_evi_listnode
);
3357 static void bgp_evpn_es_evi_vtep_free(struct bgp_evpn_es_evi_vtep
*evi_vtep
)
3359 struct bgp_evpn_es_evi
*es_evi
= evi_vtep
->es_evi
;
3361 if (evi_vtep
->flags
& (BGP_EVPN_EVI_VTEP_EAD
))
3362 /* as long as there is some reference we can't free it */
3365 list_delete_node(es_evi
->es_evi_vtep_list
, &evi_vtep
->es_evi_listnode
);
3366 XFREE(MTYPE_BGP_EVPN_ES_EVI_VTEP
, evi_vtep
);
3369 /* check if VTEP is already part of the list */
3370 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_vtep_find(
3371 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
)
3373 struct listnode
*node
= NULL
;
3374 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3376 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
3377 if (evi_vtep
->vtep_ip
.s_addr
== vtep_ip
.s_addr
)
3383 /* A VTEP can be added as "active" attach to an ES if EAD-per-ES and
3384 * EAD-per-EVI routes are rxed from it.
3386 static void bgp_evpn_es_evi_vtep_re_eval_active(struct bgp
*bgp
,
3387 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
3391 uint32_t ead_activity_flags
;
3393 old_active
= CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
3395 if (bgp_mh_info
->ead_evi_rx
)
3396 /* Both EAD-per-ES and EAD-per-EVI routes must be rxed from a PE
3397 * before it can be activated.
3399 ead_activity_flags
= BGP_EVPN_EVI_VTEP_EAD
;
3401 /* EAD-per-ES is sufficent to activate the PE */
3402 ead_activity_flags
= BGP_EVPN_EVI_VTEP_EAD_PER_ES
;
3404 if ((evi_vtep
->flags
& ead_activity_flags
) == ead_activity_flags
)
3405 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
3407 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
3409 new_active
= CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
3411 if (old_active
== new_active
)
3414 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3415 zlog_debug("es %s evi %u vtep %pI4 %s",
3416 evi_vtep
->es_evi
->es
->esi_str
,
3417 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
3418 new_active
? "active" : "inactive");
3420 /* add VTEP to parent es */
3422 evi_vtep
->es_vtep
= bgp_evpn_es_vtep_add(
3423 bgp
, evi_vtep
->es_evi
->es
, evi_vtep
->vtep_ip
,
3424 false /*esr*/, 0, 0);
3426 if (evi_vtep
->es_vtep
) {
3427 bgp_evpn_es_vtep_do_del(bgp
, evi_vtep
->es_vtep
,
3429 evi_vtep
->es_vtep
= NULL
;
3432 /* queue up the parent es for background consistency checks */
3433 bgp_evpn_es_cons_checks_pend_add(evi_vtep
->es_evi
->es
);
3436 static void bgp_evpn_es_evi_vtep_add(struct bgp
*bgp
,
3437 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
,
3440 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3442 evi_vtep
= bgp_evpn_es_evi_vtep_find(es_evi
, vtep_ip
);
3445 evi_vtep
= bgp_evpn_es_evi_vtep_new(es_evi
, vtep_ip
);
3447 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3448 zlog_debug("add es %s evi %u vtep %pI4 %s",
3449 evi_vtep
->es_evi
->es
->esi_str
,
3450 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
3451 ead_es
? "ead_es" : "ead_evi");
3454 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_ES
);
3456 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_EVI
);
3458 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, evi_vtep
);
3461 static void bgp_evpn_es_evi_vtep_del(struct bgp
*bgp
,
3462 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
,
3465 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3467 evi_vtep
= bgp_evpn_es_evi_vtep_find(es_evi
, vtep_ip
);
3471 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3472 zlog_debug("del es %s evi %u vtep %pI4 %s",
3473 evi_vtep
->es_evi
->es
->esi_str
,
3474 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
3475 ead_es
? "ead_es" : "ead_evi");
3478 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_ES
);
3480 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_EVI
);
3482 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, evi_vtep
);
3483 bgp_evpn_es_evi_vtep_free(evi_vtep
);
3486 /* compare ES-IDs for the ES-EVI RB tree maintained per-VNI */
3487 static int bgp_es_evi_rb_cmp(const struct bgp_evpn_es_evi
*es_evi1
,
3488 const struct bgp_evpn_es_evi
*es_evi2
)
3490 return memcmp(&es_evi1
->es
->esi
, &es_evi2
->es
->esi
, ESI_BYTES
);
3492 RB_GENERATE(bgp_es_evi_rb_head
, bgp_evpn_es_evi
, rb_node
, bgp_es_evi_rb_cmp
);
3494 /* find the ES-EVI in the per-L2-VNI RB tree */
3495 static struct bgp_evpn_es_evi
*bgp_evpn_es_evi_find(struct bgp_evpn_es
*es
,
3496 struct bgpevpn
*vpn
)
3498 struct bgp_evpn_es_evi es_evi
;
3502 return RB_FIND(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, &es_evi
);
3505 /* allocate a new ES-EVI and insert it into the per-L2-VNI and per-ES
3508 static struct bgp_evpn_es_evi
*bgp_evpn_es_evi_new(struct bgp_evpn_es
*es
,
3509 struct bgpevpn
*vpn
)
3511 struct bgp_evpn_es_evi
*es_evi
;
3513 es_evi
= XCALLOC(MTYPE_BGP_EVPN_ES_EVI
, sizeof(*es_evi
));
3518 /* Initialise the VTEP list */
3519 es_evi
->es_evi_vtep_list
= list_new();
3520 listset_app_node_mem(es_evi
->es_evi_vtep_list
);
3521 es_evi
->es_evi_vtep_list
->cmp
= bgp_evpn_es_evi_vtep_cmp
;
3523 /* insert into the VNI-ESI rb tree */
3524 RB_INSERT(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, es_evi
);
3526 /* add to the ES's VNI list */
3527 listnode_init(&es_evi
->es_listnode
, es_evi
);
3528 listnode_add(es
->es_evi_list
, &es_evi
->es_listnode
);
3530 bgp_evpn_es_vrf_ref(es_evi
, vpn
->bgp_vrf
);
3535 /* remove the ES-EVI from the per-L2-VNI and per-ES tables and free
3538 static struct bgp_evpn_es_evi
*
3539 bgp_evpn_es_evi_free(struct bgp_evpn_es_evi
*es_evi
)
3541 struct bgp_evpn_es
*es
= es_evi
->es
;
3542 struct bgpevpn
*vpn
= es_evi
->vpn
;
3544 /* cannot free the element as long as there is a local or remote
3547 if (es_evi
->flags
& (BGP_EVPNES_EVI_LOCAL
| BGP_EVPNES_EVI_REMOTE
))
3549 bgp_evpn_es_frag_evi_del(es_evi
, false);
3550 bgp_evpn_es_vrf_deref(es_evi
);
3552 /* remove from the ES's VNI list */
3553 list_delete_node(es
->es_evi_list
, &es_evi
->es_listnode
);
3555 /* remove from the VNI-ESI rb tree */
3556 RB_REMOVE(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, es_evi
);
3558 /* free the VTEP list */
3559 list_delete(&es_evi
->es_evi_vtep_list
);
3561 /* remove from the VNI-ESI rb tree */
3562 XFREE(MTYPE_BGP_EVPN_ES_EVI
, es_evi
);
3567 /* init local info associated with the ES-EVI */
3568 static void bgp_evpn_es_evi_local_info_set(struct bgp_evpn_es_evi
*es_evi
)
3570 struct bgpevpn
*vpn
= es_evi
->vpn
;
3572 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
3575 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
);
3576 listnode_init(&es_evi
->l2vni_listnode
, es_evi
);
3577 listnode_add(vpn
->local_es_evi_list
, &es_evi
->l2vni_listnode
);
3578 bgp_evpn_es_frag_evi_add(es_evi
);
3581 /* clear any local info associated with the ES-EVI */
3582 static struct bgp_evpn_es_evi
*
3583 bgp_evpn_es_evi_local_info_clear(struct bgp_evpn_es_evi
*es_evi
)
3585 struct bgpevpn
*vpn
= es_evi
->vpn
;
3587 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
);
3588 list_delete_node(vpn
->local_es_evi_list
, &es_evi
->l2vni_listnode
);
3590 return bgp_evpn_es_evi_free(es_evi
);
3593 /* eval remote info associated with the ES */
3594 static void bgp_evpn_es_evi_remote_info_re_eval(struct bgp_evpn_es_evi
*es_evi
)
3596 struct bgp_evpn_es
*es
= es_evi
->es
;
3598 /* if there are remote VTEPs the ES-EVI is classified as "remote" */
3599 if (listcount(es_evi
->es_evi_vtep_list
)) {
3600 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
)) {
3601 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
);
3602 ++es
->remote_es_evi_cnt
;
3603 /* set remote on the parent es */
3604 bgp_evpn_es_remote_info_re_eval(es
);
3607 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
)) {
3608 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
);
3609 if (es
->remote_es_evi_cnt
)
3610 --es
->remote_es_evi_cnt
;
3611 bgp_evpn_es_evi_free(es_evi
);
3612 /* check if "remote" can be cleared from the
3615 bgp_evpn_es_remote_info_re_eval(es
);
3620 static struct bgp_evpn_es_evi
*
3621 bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi
*es_evi
)
3623 struct prefix_evpn p
;
3624 struct bgp_evpn_es
*es
= es_evi
->es
;
3627 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
3630 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3631 zlog_debug("del local es %s evi %u",
3632 es_evi
->es
->esi_str
,
3635 bgp
= bgp_get_evpn();
3637 /* remove the es_evi from the es_frag before sending the update */
3638 bgp_evpn_es_frag_evi_del(es_evi
, true);
3640 /* update EAD-ES with new list of VNIs */
3641 if (bgp_evpn_local_es_is_active(es
))
3642 bgp_evpn_ead_es_route_update(bgp
, es
);
3644 /* withdraw and delete EAD-EVI */
3645 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
)) {
3646 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
3647 &es
->esi
, es
->originator_ip
);
3648 if (bgp_evpn_ead_evi_route_delete(bgp
, es
, es_evi
->vpn
,
3650 flog_err(EC_BGP_EVPN_ROUTE_DELETE
,
3651 "%u: EAD-EVI route deletion failure for ESI %s VNI %u",
3652 bgp
->vrf_id
, es
->esi_str
,
3657 return bgp_evpn_es_evi_local_info_clear(es_evi
);
3660 int bgp_evpn_local_es_evi_del(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
)
3662 struct bgpevpn
*vpn
;
3663 struct bgp_evpn_es
*es
;
3664 struct bgp_evpn_es_evi
*es_evi
;
3665 char buf
[ESI_STR_LEN
];
3667 es
= bgp_evpn_es_find(esi
);
3671 "%u: Failed to deref VNI %d from ESI %s; ES not present",
3673 esi_to_str(esi
, buf
, sizeof(buf
)));
3677 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3681 "%u: Failed to deref VNI %d from ESI %s; VNI not present",
3682 bgp
->vrf_id
, vni
, es
->esi_str
);
3686 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3690 "%u: Failed to deref VNI %d from ESI %s; ES-VNI not present",
3691 bgp
->vrf_id
, vni
, es
->esi_str
);
3695 bgp_evpn_local_es_evi_do_del(es_evi
);
3699 /* Create ES-EVI and advertise the corresponding EAD routes */
3700 int bgp_evpn_local_es_evi_add(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
)
3702 struct bgpevpn
*vpn
;
3703 struct prefix_evpn p
;
3704 struct bgp_evpn_es
*es
;
3705 struct bgp_evpn_es_evi
*es_evi
;
3706 char buf
[ESI_STR_LEN
];
3708 es
= bgp_evpn_es_find(esi
);
3712 "%u: Failed to associate VNI %d with ESI %s; ES not present",
3714 esi_to_str(esi
, buf
, sizeof(buf
)));
3718 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3722 "%u: Failed to associate VNI %d with ESI %s; VNI not present",
3723 bgp
->vrf_id
, vni
, es
->esi_str
);
3727 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3728 zlog_debug("add local es %s evi %u",
3731 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3734 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
3738 es_evi
= bgp_evpn_es_evi_new(es
, vpn
);
3740 bgp_evpn_es_evi_local_info_set(es_evi
);
3742 /* generate an EAD-EVI for this new VNI */
3743 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
)) {
3744 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
, &es
->esi
,
3746 bgp_evpn_ead_evi_route_update(bgp
, es
, vpn
, &p
);
3750 if (bgp_evpn_local_es_is_active(es
))
3751 bgp_evpn_ead_es_route_update(bgp
, es
);
3756 /* Add remote ES-EVI entry. This is actually the remote VTEP add and the
3757 * ES-EVI is implicity created on first VTEP's reference.
3759 int bgp_evpn_remote_es_evi_add(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3760 const struct prefix_evpn
*p
)
3762 char buf
[ESI_STR_LEN
];
3763 struct bgp_evpn_es
*es
;
3764 struct bgp_evpn_es_evi
*es_evi
;
3766 const esi_t
*esi
= &p
->prefix
.ead_addr
.esi
;
3769 /* local EAD-ES need not be sent back to zebra */
3772 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3773 zlog_debug("add remote %s es %s evi %u vtep %pI4",
3774 p
->prefix
.ead_addr
.eth_tag
? "ead-es" : "ead-evi",
3775 esi_to_str(esi
, buf
, sizeof(buf
)), vpn
->vni
,
3776 &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3778 es
= bgp_evpn_es_find(esi
);
3780 es
= bgp_evpn_es_new(bgp
, esi
);
3782 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3784 es_evi
= bgp_evpn_es_evi_new(es
, vpn
);
3786 ead_es
= !!p
->prefix
.ead_addr
.eth_tag
;
3787 bgp_evpn_es_evi_vtep_add(bgp
, es_evi
, p
->prefix
.ead_addr
.ip
.ipaddr_v4
,
3790 bgp_evpn_es_evi_remote_info_re_eval(es_evi
);
3794 /* A remote VTEP has withdrawn. The es-evi-vtep will be deleted and the
3795 * parent es-evi freed up implicitly in last VTEP's deref.
3797 int bgp_evpn_remote_es_evi_del(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3798 const struct prefix_evpn
*p
)
3800 char buf
[ESI_STR_LEN
];
3801 struct bgp_evpn_es
*es
;
3802 struct bgp_evpn_es_evi
*es_evi
;
3806 /* local EAD-ES need not be sent back to zebra */
3809 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3811 "del remote %s es %s evi %u vtep %pI4",
3812 p
->prefix
.ead_addr
.eth_tag
? "ead-es" : "ead-evi",
3813 esi_to_str(&p
->prefix
.ead_addr
.esi
, buf
, sizeof(buf
)),
3814 vpn
->vni
, &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3816 es
= bgp_evpn_es_find(&p
->prefix
.ead_addr
.esi
);
3818 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3820 "del remote %s es %s evi %u vtep %pI4, NO es",
3821 p
->prefix
.ead_addr
.eth_tag
? "ead-es"
3823 esi_to_str(&p
->prefix
.ead_addr
.esi
, buf
,
3825 vpn
->vni
, &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3828 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3830 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3832 "del remote %s es %s evi %u vtep %pI4, NO es-evi",
3833 p
->prefix
.ead_addr
.eth_tag
? "ead-es"
3835 esi_to_str(&p
->prefix
.ead_addr
.esi
, buf
,
3838 &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3842 ead_es
= !!p
->prefix
.ead_addr
.eth_tag
;
3843 bgp_evpn_es_evi_vtep_del(bgp
, es_evi
, p
->prefix
.ead_addr
.ip
.ipaddr_v4
,
3845 bgp_evpn_es_evi_remote_info_re_eval(es_evi
);
3849 /* If a VNI is being deleted we need to force del all remote VTEPs */
3850 static void bgp_evpn_remote_es_evi_flush(struct bgp_evpn_es_evi
*es_evi
)
3852 struct listnode
*node
= NULL
;
3853 struct listnode
*nnode
= NULL
;
3854 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3857 bgp
= bgp_get_evpn();
3861 /* delete all VTEPs */
3862 for (ALL_LIST_ELEMENTS(es_evi
->es_evi_vtep_list
, node
, nnode
,
3864 evi_vtep
->flags
&= ~(BGP_EVPN_EVI_VTEP_EAD_PER_ES
3865 | BGP_EVPN_EVI_VTEP_EAD_PER_EVI
);
3866 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, evi_vtep
);
3867 bgp_evpn_es_evi_vtep_free(evi_vtep
);
3869 /* delete the EVI */
3870 bgp_evpn_es_evi_remote_info_re_eval(es_evi
);
3873 /* Initialize the ES tables maintained per-L2_VNI */
3874 void bgp_evpn_vni_es_init(struct bgpevpn
*vpn
)
3876 /* Initialize the ES-EVI RB tree */
3877 RB_INIT(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
);
3879 /* Initialize the local list maintained for quick walks by type */
3880 vpn
->local_es_evi_list
= list_new();
3881 listset_app_node_mem(vpn
->local_es_evi_list
);
3884 /* Cleanup the ES info maintained per-L2_VNI */
3885 void bgp_evpn_vni_es_cleanup(struct bgpevpn
*vpn
)
3887 struct bgp_evpn_es_evi
*es_evi
;
3888 struct bgp_evpn_es_evi
*es_evi_next
;
3890 RB_FOREACH_SAFE(es_evi
, bgp_es_evi_rb_head
,
3891 &vpn
->es_evi_rb_tree
, es_evi_next
) {
3892 es_evi
= bgp_evpn_local_es_evi_do_del(es_evi
);
3894 bgp_evpn_remote_es_evi_flush(es_evi
);
3897 list_delete(&vpn
->local_es_evi_list
);
3900 static char *bgp_evpn_es_evi_vteps_str(char *vtep_str
,
3901 struct bgp_evpn_es_evi
*es_evi
,
3902 uint8_t vtep_str_size
)
3904 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
3905 struct listnode
*node
;
3906 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3908 char ip_buf
[INET_ADDRSTRLEN
];
3911 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
3912 vtep_flag_str
[0] = '\0';
3913 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_ES
)
3914 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
3915 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)
3916 strlcat(vtep_flag_str
, "V", sizeof(vtep_flag_str
));
3918 if (!strnlen(vtep_flag_str
, sizeof(vtep_flag_str
)))
3919 strlcpy(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
3923 strlcat(vtep_str
, ",", vtep_str_size
);
3925 inet_ntop(AF_INET
, &evi_vtep
->vtep_ip
, ip_buf
,
3928 strlcat(vtep_str
, "(", vtep_str_size
);
3929 strlcat(vtep_str
, vtep_flag_str
, vtep_str_size
);
3930 strlcat(vtep_str
, ")", vtep_str_size
);
3936 static void bgp_evpn_es_evi_json_vtep_fill(json_object
*json_vteps
,
3937 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
3939 json_object
*json_vtep_entry
;
3940 json_object
*json_flags
;
3942 json_vtep_entry
= json_object_new_object();
3944 json_object_string_addf(json_vtep_entry
, "vtep_ip", "%pI4",
3945 &evi_vtep
->vtep_ip
);
3946 if (evi_vtep
->flags
& (BGP_EVPN_EVI_VTEP_EAD_PER_ES
|
3947 BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)) {
3948 json_flags
= json_object_new_array();
3949 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_ES
)
3950 json_array_string_add(json_flags
, "ead-per-es");
3951 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)
3952 json_array_string_add(json_flags
, "ead-per-evi");
3953 json_object_object_add(json_vtep_entry
,
3954 "flags", json_flags
);
3957 json_object_array_add(json_vteps
,
3961 static void bgp_evpn_es_evi_show_entry(struct vty
*vty
,
3962 struct bgp_evpn_es_evi
*es_evi
, json_object
*json
)
3964 struct listnode
*node
;
3965 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3968 json_object
*json_vteps
;
3969 json_object
*json_types
;
3971 json_object_string_add(json
, "esi", es_evi
->es
->esi_str
);
3972 json_object_int_add(json
, "vni", es_evi
->vpn
->vni
);
3974 if (es_evi
->flags
& (BGP_EVPNES_EVI_LOCAL
|
3975 BGP_EVPNES_EVI_REMOTE
)) {
3976 json_types
= json_object_new_array();
3977 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
3978 json_array_string_add(json_types
, "local");
3979 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
3980 json_array_string_add(json_types
, "remote");
3981 json_object_object_add(json
, "type", json_types
);
3984 if (listcount(es_evi
->es_evi_vtep_list
)) {
3985 json_vteps
= json_object_new_array();
3986 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
,
3988 bgp_evpn_es_evi_json_vtep_fill(json_vteps
,
3991 json_object_object_add(json
, "vteps", json_vteps
);
3995 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
3998 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
3999 strlcat(type_str
, "L", sizeof(type_str
));
4000 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
4001 strlcat(type_str
, "R", sizeof(type_str
));
4002 if (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
)
4003 strlcat(type_str
, "I", sizeof(type_str
));
4005 bgp_evpn_es_evi_vteps_str(vtep_str
, es_evi
, sizeof(vtep_str
));
4007 vty_out(vty
, "%-8d %-30s %-5s %s\n",
4008 es_evi
->vpn
->vni
, es_evi
->es
->esi_str
,
4009 type_str
, vtep_str
);
4013 static void bgp_evpn_es_evi_show_entry_detail(struct vty
*vty
,
4014 struct bgp_evpn_es_evi
*es_evi
, json_object
*json
)
4017 json_object
*json_flags
;
4019 /* Add the "brief" info first */
4020 bgp_evpn_es_evi_show_entry(vty
, es_evi
, json
);
4021 if (es_evi
->es_frag
)
4022 json_object_string_addf(json
, "esFragmentRd", "%pRD",
4023 &es_evi
->es_frag
->prd
);
4024 if (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
) {
4025 json_flags
= json_object_new_array();
4026 json_array_string_add(json_flags
, "es-vtep-mismatch");
4027 json_object_object_add(json
, "flags", json_flags
);
4030 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
4034 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
4035 strlcat(type_str
, "L", sizeof(type_str
));
4036 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
4037 strlcat(type_str
, "R", sizeof(type_str
));
4039 bgp_evpn_es_evi_vteps_str(vtep_str
, es_evi
, sizeof(vtep_str
));
4040 if (!strlen(vtep_str
))
4041 strlcpy(vtep_str
, "-", sizeof(type_str
));
4043 vty_out(vty
, "VNI: %d ESI: %s\n",
4044 es_evi
->vpn
->vni
, es_evi
->es
->esi_str
);
4045 vty_out(vty
, " Type: %s\n", type_str
);
4046 if (es_evi
->es_frag
)
4047 vty_out(vty
, " ES fragment RD: %pRD\n",
4048 &es_evi
->es_frag
->prd
);
4049 vty_out(vty
, " Inconsistencies: %s\n",
4050 (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
) ?
4051 "es-vtep-mismatch":"-");
4052 vty_out(vty
, " VTEPs: %s\n", vtep_str
);
4057 static void bgp_evpn_es_evi_show_one_vni(struct bgpevpn
*vpn
, struct vty
*vty
,
4058 json_object
*json_array
, bool detail
)
4060 struct bgp_evpn_es_evi
*es_evi
;
4061 json_object
*json
= NULL
;
4063 RB_FOREACH(es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
) {
4065 /* create a separate json object for each ES */
4066 json
= json_object_new_object();
4068 bgp_evpn_es_evi_show_entry_detail(vty
, es_evi
, json
);
4070 bgp_evpn_es_evi_show_entry(vty
, es_evi
, json
);
4071 /* add ES to the json array */
4073 json_object_array_add(json_array
, json
);
4077 struct es_evi_show_ctx
{
4083 static void bgp_evpn_es_evi_show_one_vni_hash_cb(struct hash_bucket
*bucket
,
4086 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
4087 struct es_evi_show_ctx
*wctx
= (struct es_evi_show_ctx
*)ctxt
;
4089 bgp_evpn_es_evi_show_one_vni(vpn
, wctx
->vty
, wctx
->json
, wctx
->detail
);
4092 /* Display all ES EVIs */
4093 void bgp_evpn_es_evi_show(struct vty
*vty
, bool uj
, bool detail
)
4095 json_object
*json_array
= NULL
;
4096 struct es_evi_show_ctx wctx
;
4100 /* create an array of ES-EVIs */
4101 json_array
= json_object_new_array();
4105 wctx
.json
= json_array
;
4106 wctx
.detail
= detail
;
4108 bgp
= bgp_get_evpn();
4110 if (!json_array
&& !detail
) {
4111 vty_out(vty
, "Flags: L local, R remote, I inconsistent\n");
4112 vty_out(vty
, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
4113 vty_out(vty
, "%-8s %-30s %-5s %s\n",
4114 "VNI", "ESI", "Flags", "VTEPs");
4118 hash_iterate(bgp
->vnihash
,
4119 (void (*)(struct hash_bucket
*,
4120 void *))bgp_evpn_es_evi_show_one_vni_hash_cb
,
4123 vty_json(vty
, json_array
);
4126 /* Display specific ES EVI */
4127 void bgp_evpn_es_evi_show_vni(struct vty
*vty
, vni_t vni
,
4128 bool uj
, bool detail
)
4130 struct bgpevpn
*vpn
= NULL
;
4131 json_object
*json_array
= NULL
;
4135 /* create an array of ES-EVIs */
4136 json_array
= json_object_new_array();
4139 bgp
= bgp_get_evpn();
4141 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
4144 if (!json_array
&& !detail
) {
4145 vty_out(vty
, "Flags: L local, R remote, I inconsistent\n");
4146 vty_out(vty
, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
4147 vty_out(vty
, "%-8s %-30s %-5s %s\n",
4148 "VNI", "ESI", "Flags", "VTEPs");
4151 bgp_evpn_es_evi_show_one_vni(vpn
, vty
, json_array
, detail
);
4154 vty_out(vty
, "VNI not found\n");
4158 vty_json(vty
, json_array
);
4161 /*****************************************************************************
4162 * Ethernet Segment Consistency checks
4163 * Consistency checking is done to detect misconfig or mis-cabling. When
4164 * an inconsistency is detected it is simply logged (and displayed via
4165 * show commands) at this point. A more drastic action can be executed (based
4166 * on user config) in the future.
4168 static void bgp_evpn_es_cons_checks_timer_start(void)
4170 if (!bgp_mh_info
->consistency_checking
|| bgp_mh_info
->t_cons_check
)
4173 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4174 zlog_debug("periodic consistency checking started");
4176 thread_add_timer(bm
->master
, bgp_evpn_run_consistency_checks
, NULL
,
4177 BGP_EVPN_CONS_CHECK_INTERVAL
,
4178 &bgp_mh_info
->t_cons_check
);
4181 /* queue up the es for background consistency checks */
4182 static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es
*es
)
4184 if (!bgp_mh_info
->consistency_checking
)
4185 /* consistency checking is not enabled */
4188 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
))
4189 /* already queued for consistency checking */
4192 /* start the periodic timer for consistency checks if it is not
4193 * already running */
4194 bgp_evpn_es_cons_checks_timer_start();
4196 SET_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
);
4197 listnode_init(&es
->pend_es_listnode
, es
);
4198 listnode_add_after(bgp_mh_info
->pend_es_list
,
4199 listtail_unchecked(bgp_mh_info
->pend_es_list
),
4200 &es
->pend_es_listnode
);
4203 /* pull the ES from the consistency check list */
4204 static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es
*es
)
4206 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
))
4209 UNSET_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
);
4210 list_delete_node(bgp_mh_info
->pend_es_list
,
4211 &es
->pend_es_listnode
);
4214 /* Number of active VTEPs associated with the ES-per-EVI */
4215 static uint32_t bgp_evpn_es_evi_get_active_vtep_cnt(
4216 struct bgp_evpn_es_evi
*es_evi
)
4218 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
4219 struct listnode
*node
;
4220 uint32_t vtep_cnt
= 0;
4222 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
4223 if (CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
))
4230 /* Number of active VTEPs associated with the ES */
4231 static uint32_t bgp_evpn_es_get_active_vtep_cnt(struct bgp_evpn_es
*es
)
4233 struct listnode
*node
;
4234 uint32_t vtep_cnt
= 0;
4235 struct bgp_evpn_es_vtep
*es_vtep
;
4237 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
4238 if (CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
4245 static struct bgp_evpn_es_vtep
*bgp_evpn_es_get_next_active_vtep(
4246 struct bgp_evpn_es
*es
, struct bgp_evpn_es_vtep
*es_vtep
)
4248 struct listnode
*node
;
4249 struct bgp_evpn_es_vtep
*next_es_vtep
;
4252 node
= listnextnode_unchecked(&es_vtep
->es_listnode
);
4254 node
= listhead(es
->es_vtep_list
);
4256 for (; node
; node
= listnextnode_unchecked(node
)) {
4257 next_es_vtep
= listgetdata(node
);
4258 if (CHECK_FLAG(next_es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
4259 return next_es_vtep
;
4265 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_get_next_active_vtep(
4266 struct bgp_evpn_es_evi
*es_evi
,
4267 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
4269 struct listnode
*node
;
4270 struct bgp_evpn_es_evi_vtep
*next_evi_vtep
;
4273 node
= listnextnode_unchecked(&evi_vtep
->es_evi_listnode
);
4275 node
= listhead(es_evi
->es_evi_vtep_list
);
4277 for (; node
; node
= listnextnode_unchecked(node
)) {
4278 next_evi_vtep
= listgetdata(node
);
4279 if (CHECK_FLAG(next_evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
))
4280 return next_evi_vtep
;
4286 static void bgp_evpn_es_evi_set_inconsistent(struct bgp_evpn_es_evi
*es_evi
)
4288 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
)) {
4289 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4290 zlog_debug("inconsistency detected - es %s evi %u vtep list mismatch",
4291 es_evi
->es
->esi_str
,
4293 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
);
4295 /* update parent ES with the incosistency setting */
4296 if (!es_evi
->es
->incons_evi_vtep_cnt
&&
4297 BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4298 zlog_debug("inconsistency detected - es %s vtep list mismatch",
4299 es_evi
->es
->esi_str
);
4300 ++es_evi
->es
->incons_evi_vtep_cnt
;
4301 SET_FLAG(es_evi
->es
->inconsistencies
,
4302 BGP_EVPNES_INCONS_VTEP_LIST
);
4306 static uint32_t bgp_evpn_es_run_consistency_checks(struct bgp_evpn_es
*es
)
4309 int es_active_vtep_cnt
;
4310 int evi_active_vtep_cnt
;
4311 struct bgp_evpn_es_evi
*es_evi
;
4312 struct listnode
*evi_node
;
4313 struct bgp_evpn_es_vtep
*es_vtep
;
4314 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
4316 /* reset the inconsistencies and re-evaluate */
4317 es
->incons_evi_vtep_cnt
= 0;
4318 es
->inconsistencies
= 0;
4320 es_active_vtep_cnt
= bgp_evpn_es_get_active_vtep_cnt(es
);
4321 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
,
4322 evi_node
, es_evi
)) {
4325 /* reset the inconsistencies on the EVI and re-evaluate*/
4326 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
);
4328 evi_active_vtep_cnt
=
4329 bgp_evpn_es_evi_get_active_vtep_cnt(es_evi
);
4330 if (es_active_vtep_cnt
!= evi_active_vtep_cnt
) {
4331 bgp_evpn_es_evi_set_inconsistent(es_evi
);
4335 if (!es_active_vtep_cnt
)
4340 while ((es_vtep
= bgp_evpn_es_get_next_active_vtep(
4342 evi_vtep
= bgp_evpn_es_evi_get_next_active_vtep(es_evi
,
4345 bgp_evpn_es_evi_set_inconsistent(es_evi
);
4348 if (es_vtep
->vtep_ip
.s_addr
!=
4349 evi_vtep
->vtep_ip
.s_addr
) {
4350 /* inconsistency detected; set it and move
4353 bgp_evpn_es_evi_set_inconsistent(es_evi
);
4362 static void bgp_evpn_run_consistency_checks(struct thread
*t
)
4365 struct listnode
*node
;
4366 struct listnode
*nextnode
;
4367 struct bgp_evpn_es
*es
;
4369 for (ALL_LIST_ELEMENTS(bgp_mh_info
->pend_es_list
,
4370 node
, nextnode
, es
)) {
4372 /* run consistency checks on the ES and remove it from the
4375 proc_cnt
+= bgp_evpn_es_run_consistency_checks(es
);
4376 bgp_evpn_es_cons_checks_pend_del(es
);
4381 /* restart the timer */
4382 thread_add_timer(bm
->master
, bgp_evpn_run_consistency_checks
, NULL
,
4383 BGP_EVPN_CONS_CHECK_INTERVAL
,
4384 &bgp_mh_info
->t_cons_check
);
4387 /*****************************************************************************
4388 * EVPN-Nexthop and RMAC management: nexthops associated with Type-2 routes
4389 * that have an ES as destination are consolidated by BGP into a per-VRF
4390 * nh->rmac mapping which is sent to zebra. Zebra installs the nexthop
4391 * as a remote neigh/fdb entry with a dummy (type-1) prefix referencing it.
4393 * This handling is needed because Type-2 routes with ES as dest use NHG
4394 * that is setup using EAD routes (i.e. such NHGs do not include the
4396 ****************************************************************************/
4397 static void bgp_evpn_nh_zebra_update_send(struct bgp_evpn_nh
*nh
, bool add
)
4400 struct bgp
*bgp_vrf
= nh
->bgp_vrf
;
4403 if (!zclient
|| zclient
->sock
< 0)
4406 /* Don't try to register if Zebra doesn't know of this instance. */
4407 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp_vrf
)) {
4408 if (BGP_DEBUG(zebra
, ZEBRA
))
4409 zlog_debug("No zebra instance, not %s remote nh %s",
4410 add
? "adding" : "deleting", nh
->nh_str
);
4417 zclient_create_header(
4418 s
, add
? ZEBRA_EVPN_REMOTE_NH_ADD
: ZEBRA_EVPN_REMOTE_NH_DEL
,
4420 stream_putl(s
, bgp_vrf
->vrf_id
);
4421 stream_put(s
, &nh
->ip
, sizeof(nh
->ip
));
4423 stream_put(s
, &nh
->rmac
, sizeof(nh
->rmac
));
4425 stream_putw_at(s
, 0, stream_get_endp(s
));
4427 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
4429 zlog_debug("evpn vrf %s nh %s rmac %pEA add to zebra",
4430 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
,
4432 else if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4433 zlog_debug("evpn vrf %s nh %s del to zebra",
4434 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
);
4437 frrtrace(2, frr_bgp
, evpn_mh_nh_rmac_zsend
, add
, nh
);
4439 zclient_send_message(zclient
);
4442 static void bgp_evpn_nh_zebra_update(struct bgp_evpn_nh
*nh
, bool add
)
4444 if (add
&& !is_zero_mac(&nh
->rmac
)) {
4445 nh
->flags
|= BGP_EVPN_NH_READY_FOR_ZEBRA
;
4446 bgp_evpn_nh_zebra_update_send(nh
, true);
4448 if (!(nh
->flags
& BGP_EVPN_NH_READY_FOR_ZEBRA
))
4450 nh
->flags
&= ~BGP_EVPN_NH_READY_FOR_ZEBRA
;
4451 bgp_evpn_nh_zebra_update_send(nh
, false);
4455 static void *bgp_evpn_nh_alloc(void *p
)
4457 struct bgp_evpn_nh
*tmp_n
= p
;
4458 struct bgp_evpn_nh
*n
;
4460 n
= XCALLOC(MTYPE_BGP_EVPN_NH
, sizeof(struct bgp_evpn_nh
));
4466 static struct bgp_evpn_nh
*bgp_evpn_nh_find(struct bgp
*bgp_vrf
,
4469 struct bgp_evpn_nh tmp
;
4470 struct bgp_evpn_nh
*n
;
4472 memset(&tmp
, 0, sizeof(tmp
));
4473 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
4474 n
= hash_lookup(bgp_vrf
->evpn_nh_table
, &tmp
);
4479 /* Add nexthop entry - implicitly created on first path reference */
4480 static struct bgp_evpn_nh
*bgp_evpn_nh_add(struct bgp
*bgp_vrf
,
4482 struct bgp_path_info
*pi
)
4484 struct bgp_evpn_nh tmp_n
;
4485 struct bgp_evpn_nh
*n
= NULL
;
4487 memset(&tmp_n
, 0, sizeof(tmp_n
));
4488 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
4489 n
= hash_get(bgp_vrf
->evpn_nh_table
, &tmp_n
, bgp_evpn_nh_alloc
);
4490 ipaddr2str(ip
, n
->nh_str
, sizeof(n
->nh_str
));
4491 n
->bgp_vrf
= bgp_vrf
;
4493 n
->pi_list
= list_new();
4494 listset_app_node_mem(n
->pi_list
);
4496 /* Setup ref_pi when the nh is created */
4497 if (CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
) && pi
->attr
) {
4499 memcpy(&n
->rmac
, &pi
->attr
->rmac
, ETH_ALEN
);
4502 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4503 zlog_debug("evpn vrf %s nh %s rmac %pEA add",
4504 n
->bgp_vrf
->name_pretty
, n
->nh_str
, &n
->rmac
);
4505 bgp_evpn_nh_zebra_update(n
, true);
4509 /* Delete nexthop entry if there are no paths referencing it */
4510 static void bgp_evpn_nh_del(struct bgp_evpn_nh
*n
)
4512 struct bgp_evpn_nh
*tmp_n
;
4513 struct bgp
*bgp_vrf
= n
->bgp_vrf
;
4515 if (listcount(n
->pi_list
))
4518 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4519 zlog_debug("evpn vrf %s nh %s del to zebra",
4520 bgp_vrf
->name_pretty
, n
->nh_str
);
4522 bgp_evpn_nh_zebra_update(n
, false);
4523 list_delete(&n
->pi_list
);
4524 tmp_n
= hash_release(bgp_vrf
->evpn_nh_table
, n
);
4525 XFREE(MTYPE_BGP_EVPN_NH
, tmp_n
);
4528 static void hash_evpn_nh_free(struct bgp_evpn_nh
*ben
)
4530 XFREE(MTYPE_BGP_EVPN_NH
, ben
);
4533 static unsigned int bgp_evpn_nh_hash_keymake(const void *p
)
4535 const struct bgp_evpn_nh
*n
= p
;
4536 const struct ipaddr
*ip
= &n
->ip
;
4538 if (IS_IPADDR_V4(ip
))
4539 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
4541 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
4542 array_size(ip
->ipaddr_v6
.s6_addr32
), 0);
4545 static bool bgp_evpn_nh_cmp(const void *p1
, const void *p2
)
4547 const struct bgp_evpn_nh
*n1
= p1
;
4548 const struct bgp_evpn_nh
*n2
= p2
;
4550 if (n1
== NULL
&& n2
== NULL
)
4553 if (n1
== NULL
|| n2
== NULL
)
4556 return (ipaddr_cmp(&n1
->ip
, &n2
->ip
) == 0);
4559 void bgp_evpn_nh_init(struct bgp
*bgp_vrf
)
4561 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4562 zlog_debug("evpn vrf %s nh init", bgp_vrf
->name_pretty
);
4563 bgp_vrf
->evpn_nh_table
= hash_create(
4564 bgp_evpn_nh_hash_keymake
, bgp_evpn_nh_cmp
, "BGP EVPN NH table");
4567 static void bgp_evpn_nh_flush_entry(struct bgp_evpn_nh
*nh
)
4569 struct listnode
*node
;
4570 struct listnode
*nnode
;
4571 struct bgp_path_evpn_nh_info
*nh_info
;
4573 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4574 zlog_debug("evpn vrf %s nh %s flush", nh
->bgp_vrf
->name_pretty
,
4577 /* force flush paths */
4578 for (ALL_LIST_ELEMENTS(nh
->pi_list
, node
, nnode
, nh_info
))
4579 bgp_evpn_path_nh_del(nh
->bgp_vrf
, nh_info
->pi
);
4582 static void bgp_evpn_nh_flush_cb(struct hash_bucket
*bucket
, void *ctxt
)
4584 struct bgp_evpn_nh
*nh
= (struct bgp_evpn_nh
*)bucket
->data
;
4586 bgp_evpn_nh_flush_entry(nh
);
4589 void bgp_evpn_nh_finish(struct bgp
*bgp_vrf
)
4591 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4592 zlog_debug("evpn vrf %s nh finish", bgp_vrf
->name_pretty
);
4594 bgp_vrf
->evpn_nh_table
,
4595 (void (*)(struct hash_bucket
*, void *))bgp_evpn_nh_flush_cb
,
4597 hash_clean(bgp_vrf
->evpn_nh_table
, (void (*)(void *))hash_evpn_nh_free
);
4598 hash_free(bgp_vrf
->evpn_nh_table
);
4599 bgp_vrf
->evpn_nh_table
= NULL
;
4602 static void bgp_evpn_nh_update_ref_pi(struct bgp_evpn_nh
*nh
)
4604 struct listnode
*node
;
4605 struct bgp_path_info
*pi
;
4606 struct bgp_path_evpn_nh_info
*nh_info
;
4611 for (ALL_LIST_ELEMENTS_RO(nh
->pi_list
, node
, nh_info
)) {
4613 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
) || !pi
->attr
)
4616 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4617 zlog_debug("evpn vrf %s nh %s ref_pi update",
4618 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
);
4620 /* If we have a new pi copy rmac from it and update
4621 * zebra if the new rmac is different
4623 if (memcmp(&nh
->rmac
, &nh
->ref_pi
->attr
->rmac
, ETH_ALEN
)) {
4624 memcpy(&nh
->rmac
, &nh
->ref_pi
->attr
->rmac
, ETH_ALEN
);
4625 bgp_evpn_nh_zebra_update(nh
, true);
4631 static void bgp_evpn_nh_clear_ref_pi(struct bgp_evpn_nh
*nh
,
4632 struct bgp_path_info
*pi
)
4634 if (nh
->ref_pi
!= pi
)
4637 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
4638 zlog_debug("evpn vrf %s nh %s ref_pi clear",
4639 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
);
4641 /* try to find another ref_pi */
4642 bgp_evpn_nh_update_ref_pi(nh
);
4643 /* couldn't find one - clear the old rmac and notify zebra */
4645 memset(&nh
->rmac
, 0, ETH_ALEN
);
4646 bgp_evpn_nh_zebra_update(nh
, true);
4650 static void bgp_evpn_path_nh_info_free(struct bgp_path_evpn_nh_info
*nh_info
)
4652 bgp_evpn_path_nh_unlink(nh_info
);
4653 XFREE(MTYPE_BGP_EVPN_PATH_NH_INFO
, nh_info
);
4656 static struct bgp_path_evpn_nh_info
*
4657 bgp_evpn_path_nh_info_new(struct bgp_path_info
*pi
)
4659 struct bgp_path_info_extra
*e
;
4660 struct bgp_path_mh_info
*mh_info
;
4661 struct bgp_path_evpn_nh_info
*nh_info
;
4663 e
= bgp_path_info_extra_get(pi
);
4665 /* If mh_info doesn't exist allocate it */
4666 mh_info
= e
->mh_info
;
4668 e
->mh_info
= mh_info
= XCALLOC(MTYPE_BGP_EVPN_PATH_MH_INFO
,
4669 sizeof(struct bgp_path_mh_info
));
4671 /* If nh_info doesn't exist allocate it */
4672 nh_info
= mh_info
->nh_info
;
4674 mh_info
->nh_info
= nh_info
=
4675 XCALLOC(MTYPE_BGP_EVPN_PATH_NH_INFO
,
4676 sizeof(struct bgp_path_evpn_nh_info
));
4683 static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info
*nh_info
)
4685 struct bgp_evpn_nh
*nh
= nh_info
->nh
;
4686 struct bgp_path_info
*pi
;
4687 char prefix_buf
[PREFIX_STRLEN
];
4693 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
4694 zlog_debug("path %s unlinked from nh %s %s",
4695 pi
->net
? prefix2str(&pi
->net
->p
, prefix_buf
,
4698 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
);
4700 list_delete_node(nh
->pi_list
, &nh_info
->nh_listnode
);
4704 /* check if the ref_pi need to be updated */
4705 bgp_evpn_nh_clear_ref_pi(nh
, pi
);
4707 /* if there are no other references against the nh it
4710 bgp_evpn_nh_del(nh
);
4712 /* Note we don't free the path nh_info on unlink; it will be freed up
4713 * along with the path.
4717 static void bgp_evpn_path_nh_link(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
)
4719 struct bgp_path_evpn_nh_info
*nh_info
;
4720 struct bgp_evpn_nh
*nh
;
4723 /* EVPN nexthop setup in bgp has been turned off */
4724 if (!bgp_mh_info
->bgp_evpn_nh_setup
)
4727 if (!bgp_vrf
->evpn_nh_table
) {
4728 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
4729 zlog_debug("path %pFX linked to vrf %s failed",
4730 &pi
->net
->p
, bgp_vrf
->name_pretty
);
4734 nh_info
= (pi
->extra
&& pi
->extra
->mh_info
)
4735 ? pi
->extra
->mh_info
->nh_info
4738 /* if NHG is not being used for this path we don't need to manage the
4739 * nexthops in bgp (they are managed by zebra instead)
4741 if (!(pi
->attr
->es_flags
& ATTR_ES_L3_NHG_USE
)) {
4743 bgp_evpn_path_nh_unlink(nh_info
);
4747 /* setup nh_info against the path if it doesn't aleady exist */
4749 nh_info
= bgp_evpn_path_nh_info_new(pi
);
4751 /* find-create nh */
4752 memset(&ip
, 0, sizeof(ip
));
4753 if (pi
->net
->p
.family
== AF_INET6
) {
4755 memcpy(&ip
.ipaddr_v6
, &pi
->attr
->mp_nexthop_global
,
4756 sizeof(ip
.ipaddr_v6
));
4759 memcpy(&ip
.ipaddr_v4
, &pi
->attr
->nexthop
, sizeof(ip
.ipaddr_v4
));
4762 nh
= bgp_evpn_nh_find(bgp_vrf
, &ip
);
4764 nh
= bgp_evpn_nh_add(bgp_vrf
, &ip
, pi
);
4767 if (nh_info
->nh
== nh
) {
4768 /* Check if any of the paths are now valid */
4769 bgp_evpn_nh_update_ref_pi(nh
);
4773 /* unlink old nh if any */
4774 bgp_evpn_path_nh_unlink(nh_info
);
4776 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
4777 zlog_debug("path %pFX linked to nh %s %s", &pi
->net
->p
,
4778 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
);
4780 /* link mac-ip path to the new nh */
4782 listnode_init(&nh_info
->nh_listnode
, nh_info
);
4783 listnode_add(nh
->pi_list
, &nh_info
->nh_listnode
);
4784 /* If a new valid path got linked to the nh see if can get the rmac
4787 bgp_evpn_nh_update_ref_pi(nh
);
4788 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
)) {
4791 "path %pFX linked to nh %s %s with no valid pi",
4792 &pi
->net
->p
, nh
->bgp_vrf
->name_pretty
,
4797 void bgp_evpn_path_nh_del(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
)
4799 struct bgp_path_evpn_nh_info
*nh_info
;
4801 nh_info
= (pi
->extra
&& pi
->extra
->mh_info
)
4802 ? pi
->extra
->mh_info
->nh_info
4808 bgp_evpn_path_nh_unlink(nh_info
);
4811 void bgp_evpn_path_nh_add(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
)
4813 bgp_evpn_path_nh_link(bgp_vrf
, pi
);
4816 static void bgp_evpn_nh_show_entry(struct bgp_evpn_nh
*nh
, struct vty
*vty
,
4817 json_object
*json_array
)
4819 json_object
*json
= NULL
;
4820 char mac_buf
[ETHER_ADDR_STRLEN
];
4821 char prefix_buf
[PREFIX_STRLEN
];
4824 /* create a separate json object for each ES */
4825 json
= json_object_new_object();
4827 prefix_mac2str(&nh
->rmac
, mac_buf
, sizeof(mac_buf
));
4828 if (nh
->ref_pi
&& nh
->ref_pi
->net
)
4829 prefix2str(&nh
->ref_pi
->net
->p
, prefix_buf
, sizeof(prefix_buf
));
4831 prefix_buf
[0] = '\0';
4833 json_object_string_add(json
, "vrf", nh
->bgp_vrf
->name_pretty
);
4834 json_object_string_add(json
, "ip", nh
->nh_str
);
4835 json_object_string_add(json
, "rmac", mac_buf
);
4836 json_object_string_add(json
, "basePath", prefix_buf
);
4837 json_object_int_add(json
, "pathCount", listcount(nh
->pi_list
));
4839 vty_out(vty
, "%-15s %-15s %-17s %-10d %s\n",
4840 nh
->bgp_vrf
->name_pretty
, nh
->nh_str
, mac_buf
,
4841 listcount(nh
->pi_list
), prefix_buf
);
4844 /* add ES to the json array */
4846 json_object_array_add(json_array
, json
);
4849 struct nh_show_ctx
{
4854 static void bgp_evpn_nh_show_hash_cb(struct hash_bucket
*bucket
, void *ctxt
)
4856 struct bgp_evpn_nh
*nh
= (struct bgp_evpn_nh
*)bucket
->data
;
4857 struct nh_show_ctx
*wctx
= (struct nh_show_ctx
*)ctxt
;
4859 bgp_evpn_nh_show_entry(nh
, wctx
->vty
, wctx
->json
);
4862 /* Display all evpn nexthops */
4863 void bgp_evpn_nh_show(struct vty
*vty
, bool uj
)
4865 json_object
*json_array
= NULL
;
4866 struct bgp
*bgp_vrf
;
4867 struct listnode
*node
;
4868 struct nh_show_ctx wctx
;
4871 /* create an array of nexthops */
4872 json_array
= json_object_new_array();
4874 vty_out(vty
, "%-15s %-15s %-17s %-10s %s\n", "VRF", "IP",
4875 "RMAC", "#Paths", "Base Path");
4879 wctx
.json
= json_array
;
4881 /* walk through all vrfs */
4882 for (ALL_LIST_ELEMENTS_RO(bm
->bgp
, node
, bgp_vrf
)) {
4883 hash_iterate(bgp_vrf
->evpn_nh_table
,
4884 (void (*)(struct hash_bucket
*,
4885 void *))bgp_evpn_nh_show_hash_cb
,
4889 /* print the array of json-ESs */
4891 vty_json(vty
, json_array
);
4894 /*****************************************************************************/
4895 void bgp_evpn_mh_init(void)
4897 bm
->mh_info
= XCALLOC(MTYPE_BGP_EVPN_MH_INFO
, sizeof(*bm
->mh_info
));
4899 /* setup ES tables */
4900 RB_INIT(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
);
4902 bgp_mh_info
->local_es_list
= list_new();
4903 listset_app_node_mem(bgp_mh_info
->local_es_list
);
4904 /* list of ESs with pending processing */
4905 bgp_mh_info
->pend_es_list
= list_new();
4906 listset_app_node_mem(bgp_mh_info
->pend_es_list
);
4908 bgp_mh_info
->ead_evi_rx
= BGP_EVPN_MH_EAD_EVI_RX_DEF
;
4909 bgp_mh_info
->ead_evi_tx
= BGP_EVPN_MH_EAD_EVI_TX_DEF
;
4910 bgp_mh_info
->ead_es_export_rtl
= list_new();
4911 bgp_mh_info
->ead_es_export_rtl
->cmp
=
4912 (int (*)(void *, void *))bgp_evpn_route_target_cmp
;
4913 bgp_mh_info
->ead_es_export_rtl
->del
= bgp_evpn_xxport_delete_ecomm
;
4915 /* config knobs - XXX add cli to control it */
4916 bgp_mh_info
->ead_evi_adv_for_down_links
= true;
4917 bgp_mh_info
->consistency_checking
= true;
4918 bgp_mh_info
->host_routes_use_l3nhg
= BGP_EVPN_MH_USE_ES_L3NHG_DEF
;
4919 bgp_mh_info
->suppress_l3_ecomm_on_inactive_es
= true;
4920 bgp_mh_info
->bgp_evpn_nh_setup
= true;
4921 bgp_mh_info
->evi_per_es_frag
= BGP_EVPN_MAX_EVI_PER_ES_FRAG
;
4923 memset(&zero_esi_buf
, 0, sizeof(esi_t
));
4926 void bgp_evpn_mh_finish(void)
4928 struct bgp_evpn_es
*es
;
4929 struct bgp_evpn_es
*es_next
;
4931 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
4932 zlog_debug("evpn mh finish");
4934 RB_FOREACH_SAFE (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
,
4936 bgp_evpn_es_local_info_clear(es
, true);
4938 if (bgp_mh_info
->t_cons_check
)
4939 THREAD_OFF(bgp_mh_info
->t_cons_check
);
4940 list_delete(&bgp_mh_info
->local_es_list
);
4941 list_delete(&bgp_mh_info
->pend_es_list
);
4942 list_delete(&bgp_mh_info
->ead_es_export_rtl
);
4944 XFREE(MTYPE_BGP_EVPN_MH_INFO
, bgp_mh_info
);
4947 /* This function is called when disable-ead-evi-rx knob flaps */
4948 void bgp_evpn_switch_ead_evi_rx(void)
4951 struct bgp_evpn_es
*es
;
4952 struct bgp_evpn_es_evi
*es_evi
;
4953 struct listnode
*evi_node
= NULL
;
4954 struct listnode
*evi_next
= NULL
;
4955 struct bgp_evpn_es_evi_vtep
*vtep
;
4956 struct listnode
*vtep_node
= NULL
;
4957 struct listnode
*vtep_next
= NULL
;
4959 bgp
= bgp_get_evpn();
4964 * Process all the remote es_evi_vteps and reevaluate if the es_evi_vtep
4967 RB_FOREACH(es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
) {
4968 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_REMOTE
))
4971 for (ALL_LIST_ELEMENTS(es
->es_evi_list
, evi_node
, evi_next
,
4973 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
))
4976 for (ALL_LIST_ELEMENTS(es_evi
->es_evi_vtep_list
,
4977 vtep_node
, vtep_next
, vtep
))
4978 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, vtep
);