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"
54 static void bgp_evpn_local_es_down(struct bgp
*bgp
,
55 struct bgp_evpn_es
*es
);
56 static void bgp_evpn_local_type1_evi_route_del(struct bgp
*bgp
,
57 struct bgp_evpn_es
*es
);
58 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_add(struct bgp
*bgp
,
59 struct bgp_evpn_es
*es
,
60 struct in_addr vtep_ip
,
61 bool esr
, uint8_t df_alg
,
63 static void bgp_evpn_es_vtep_del(struct bgp
*bgp
,
64 struct bgp_evpn_es
*es
, struct in_addr vtep_ip
, bool esr
);
65 static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es
*es
);
66 static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es
*es
);
67 static void bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi
*es_evi
);
68 static uint32_t bgp_evpn_es_get_active_vtep_cnt(struct bgp_evpn_es
*es
);
69 static void bgp_evpn_l3nhg_update_on_vtep_chg(struct bgp_evpn_es
*es
);
70 static struct bgp_evpn_es
*bgp_evpn_es_new(struct bgp
*bgp
, const esi_t
*esi
);
71 static void bgp_evpn_es_free(struct bgp_evpn_es
*es
, const char *caller
);
72 static void bgp_evpn_es_path_all_update(struct bgp_evpn_es_vtep
*es_vtep
,
75 esi_t zero_esi_buf
, *zero_esi
= &zero_esi_buf
;
77 /******************************************************************************
78 * per-ES (Ethernet Segment) routing table
80 * Following routes are added to the ES's routing table -
81 * 1. Local and remote ESR (Type-4)
82 * 2. Local EAD-per-ES (Type-1).
84 * Key for these routes is {ESI, VTEP-IP} so the path selection is practically
85 * a no-op i.e. all paths lead to same VTEP-IP (i.e. result in the same VTEP
86 * being added to same ES).
88 * Note the following routes go into the VNI routing table (instead of the
90 * 1. Remote EAD-per-ES
91 * 2. Local and remote EAD-per-EVI
94 /* Calculate the best path for a multi-homing (Type-1 or Type-4) route
95 * installed in the ES's routing table.
97 static int bgp_evpn_es_route_select_install(struct bgp
*bgp
,
98 struct bgp_evpn_es
*es
,
99 struct bgp_dest
*dest
)
102 afi_t afi
= AFI_L2VPN
;
103 safi_t safi
= SAFI_EVPN
;
104 struct bgp_path_info
*old_select
; /* old best */
105 struct bgp_path_info
*new_select
; /* new best */
106 struct bgp_path_info_pair old_and_new
;
108 /* Compute the best path. */
109 bgp_best_selection(bgp
, dest
, &bgp
->maxpaths
[afi
][safi
], &old_and_new
,
111 old_select
= old_and_new
.old
;
112 new_select
= old_and_new
.new;
115 * If the best path hasn't changed - see if something needs to be
118 if (old_select
&& old_select
== new_select
119 && old_select
->type
== ZEBRA_ROUTE_BGP
120 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
121 && !CHECK_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
)
122 && !CHECK_FLAG(old_select
->flags
, BGP_PATH_ATTR_CHANGED
)
123 && !bgp_addpath_is_addpath_used(&bgp
->tx_addpath
, afi
, safi
)) {
124 if (bgp_zebra_has_route_changed(old_select
)) {
125 bgp_evpn_es_vtep_add(bgp
, es
, old_select
->attr
->nexthop
,
127 old_select
->attr
->df_alg
,
128 old_select
->attr
->df_pref
);
130 UNSET_FLAG(old_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
131 bgp_zebra_clear_route_change_flags(dest
);
135 /* If the user did a "clear" this flag will be set */
136 UNSET_FLAG(dest
->flags
, BGP_NODE_USER_CLEAR
);
138 /* bestpath has changed; update relevant fields and install or uninstall
139 * into the zebra RIB.
141 if (old_select
|| new_select
)
142 bgp_bump_version(dest
);
145 bgp_path_info_unset_flag(dest
, old_select
, BGP_PATH_SELECTED
);
147 bgp_path_info_set_flag(dest
, new_select
, BGP_PATH_SELECTED
);
148 bgp_path_info_unset_flag(dest
, new_select
,
149 BGP_PATH_ATTR_CHANGED
);
150 UNSET_FLAG(new_select
->flags
, BGP_PATH_MULTIPATH_CHG
);
153 if (new_select
&& new_select
->type
== ZEBRA_ROUTE_BGP
154 && new_select
->sub_type
== BGP_ROUTE_IMPORTED
) {
155 bgp_evpn_es_vtep_add(bgp
, es
, new_select
->attr
->nexthop
,
156 true /*esr */, new_select
->attr
->df_alg
,
157 new_select
->attr
->df_pref
);
159 if (old_select
&& old_select
->type
== ZEBRA_ROUTE_BGP
160 && old_select
->sub_type
== BGP_ROUTE_IMPORTED
)
161 bgp_evpn_es_vtep_del(
162 bgp
, es
, old_select
->attr
->nexthop
,
166 /* Clear any route change flags. */
167 bgp_zebra_clear_route_change_flags(dest
);
169 /* Reap old select bgp_path_info, if it has been removed */
170 if (old_select
&& CHECK_FLAG(old_select
->flags
, BGP_PATH_REMOVED
))
171 bgp_path_info_reap(dest
, old_select
);
176 /* Install Type-1/Type-4 route entry in the per-ES routing table */
177 static int bgp_evpn_es_route_install(struct bgp
*bgp
,
178 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
,
179 struct bgp_path_info
*parent_pi
)
182 struct bgp_dest
*dest
= NULL
;
183 struct bgp_path_info
*pi
= NULL
;
184 struct attr
*attr_new
= NULL
;
186 /* Create (or fetch) route within the VNI.
187 * NOTE: There is no RD here.
189 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
191 /* Check if route entry is already present. */
192 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
194 && (struct bgp_path_info
*)pi
->extra
->parent
==
199 /* Add (or update) attribute to hash. */
200 attr_new
= bgp_attr_intern(parent_pi
->attr
);
202 /* Create new route with its attribute. */
203 pi
= info_make(parent_pi
->type
, BGP_ROUTE_IMPORTED
, 0,
204 parent_pi
->peer
, attr_new
, dest
);
205 SET_FLAG(pi
->flags
, BGP_PATH_VALID
);
206 bgp_path_info_extra_get(pi
);
207 pi
->extra
->parent
= bgp_path_info_lock(parent_pi
);
208 bgp_dest_lock_node((struct bgp_dest
*)parent_pi
->net
);
209 bgp_path_info_add(dest
, pi
);
211 if (attrhash_cmp(pi
->attr
, parent_pi
->attr
)
212 && !CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
)) {
213 bgp_dest_unlock_node(dest
);
216 /* The attribute has changed. */
217 /* Add (or update) attribute to hash. */
218 attr_new
= bgp_attr_intern(parent_pi
->attr
);
220 /* Restore route, if needed. */
221 if (CHECK_FLAG(pi
->flags
, BGP_PATH_REMOVED
))
222 bgp_path_info_restore(dest
, pi
);
224 /* Mark if nexthop has changed. */
225 if (!IPV4_ADDR_SAME(&pi
->attr
->nexthop
, &attr_new
->nexthop
))
226 SET_FLAG(pi
->flags
, BGP_PATH_IGP_CHANGED
);
228 /* Unintern existing, set to new. */
229 bgp_attr_unintern(&pi
->attr
);
231 pi
->uptime
= bgp_clock();
234 /* Perform route selection and update zebra, if required. */
235 ret
= bgp_evpn_es_route_select_install(bgp
, es
, dest
);
237 bgp_dest_unlock_node(dest
);
242 /* Uninstall Type-1/Type-4 route entry from the ES routing table */
243 static int bgp_evpn_es_route_uninstall(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
244 struct prefix_evpn
*p
, struct bgp_path_info
*parent_pi
)
247 struct bgp_dest
*dest
;
248 struct bgp_path_info
*pi
;
250 if (!es
->route_table
)
253 /* Locate route within the ESI.
254 * NOTE: There is no RD here.
256 dest
= bgp_node_lookup(es
->route_table
, (struct prefix
*)p
);
260 /* Find matching route entry. */
261 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
; pi
= pi
->next
)
263 && (struct bgp_path_info
*)pi
->extra
->parent
==
270 /* Mark entry for deletion */
271 bgp_path_info_delete(dest
, pi
);
273 /* Perform route selection and update zebra, if required. */
274 ret
= bgp_evpn_es_route_select_install(bgp
, es
, dest
);
276 /* Unlock route node. */
277 bgp_dest_unlock_node(dest
);
282 /* Install or unistall a Tyoe-4 route in the per-ES routing table */
283 int bgp_evpn_es_route_install_uninstall(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
284 afi_t afi
, safi_t safi
, struct prefix_evpn
*evp
,
285 struct bgp_path_info
*pi
, int install
)
290 ret
= bgp_evpn_es_route_install(bgp
, es
, evp
, pi
);
292 ret
= bgp_evpn_es_route_uninstall(bgp
, es
, evp
, pi
);
297 "%u: Failed to %s EVPN %s route in ESI %s",
299 install
? "install" : "uninstall",
306 /* Delete (and withdraw) local routes for specified ES from global and ES table.
307 * Also remove all remote routes from the per ES table. Invoked when ES
310 static void bgp_evpn_es_route_del_all(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
312 struct bgp_dest
*dest
;
313 struct bgp_path_info
*pi
, *nextpi
;
315 /* de-activate the ES */
316 bgp_evpn_local_es_down(bgp
, es
);
317 bgp_evpn_local_type1_evi_route_del(bgp
, es
);
319 /* Walk this ES's routing table and delete all routes. */
320 for (dest
= bgp_table_top(es
->route_table
); dest
;
321 dest
= bgp_route_next(dest
)) {
322 for (pi
= bgp_dest_get_bgp_path_info(dest
);
323 (pi
!= NULL
) && (nextpi
= pi
->next
, 1); pi
= nextpi
) {
324 bgp_path_info_delete(dest
, pi
);
325 bgp_path_info_reap(dest
, pi
);
330 /*****************************************************************************
331 * Base APIs for creating MH routes (Type-1 or Type-4) on local ethernet
335 /* create or update local EVPN type1/type4 route entry.
338 * the ES table if ESR/EAD-ES (or)
339 * the VNI table if EAD-EVI (or)
340 * the global table if ESR/EAD-ES/EAD-EVI
342 * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
345 static int bgp_evpn_mh_route_update(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
346 struct bgpevpn
*vpn
, afi_t afi
, safi_t safi
,
347 struct bgp_dest
*dest
, struct attr
*attr
,
348 int add
, struct bgp_path_info
**ri
,
351 struct bgp_path_info
*tmp_pi
= NULL
;
352 struct bgp_path_info
*local_pi
= NULL
; /* local route entry if any */
353 struct bgp_path_info
*remote_pi
= NULL
; /* remote route entry if any */
354 struct attr
*attr_new
= NULL
;
355 struct prefix_evpn
*evp
;
358 evp
= (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
361 /* locate the local and remote entries if any */
362 for (tmp_pi
= bgp_dest_get_bgp_path_info(dest
); tmp_pi
;
363 tmp_pi
= tmp_pi
->next
) {
364 if (tmp_pi
->peer
== bgp
->peer_self
365 && tmp_pi
->type
== ZEBRA_ROUTE_BGP
366 && tmp_pi
->sub_type
== BGP_ROUTE_STATIC
)
368 if (tmp_pi
->type
== ZEBRA_ROUTE_BGP
369 && tmp_pi
->sub_type
== BGP_ROUTE_IMPORTED
370 && CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
))
374 /* we don't expect to see a remote_ri at this point as
375 * an ES route has {esi, vtep_ip} as the key in the ES-rt-table
376 * in the VNI-rt-table.
381 "%u ERROR: local es route for ESI: %s Vtep %pI4 also learnt from remote",
382 bgp
->vrf_id
, es
->esi_str
, &es
->originator_ip
);
386 if (!local_pi
&& !add
)
389 /* create or update the entry */
392 /* Add or update attribute to hash */
393 attr_new
= bgp_attr_intern(attr
);
395 /* Create new route with its attribute. */
396 tmp_pi
= info_make(ZEBRA_ROUTE_BGP
, BGP_ROUTE_STATIC
, 0,
397 bgp
->peer_self
, attr_new
, dest
);
398 SET_FLAG(tmp_pi
->flags
, BGP_PATH_VALID
);
400 if (evp
->prefix
.route_type
== BGP_EVPN_AD_ROUTE
) {
401 bgp_path_info_extra_get(tmp_pi
);
402 tmp_pi
->extra
->num_labels
= 1;
404 vni2label(vpn
->vni
, &tmp_pi
->extra
->label
[0]);
406 tmp_pi
->extra
->label
[0] = 0;
409 /* add the newly created path to the route-node */
410 bgp_path_info_add(dest
, tmp_pi
);
413 if (attrhash_cmp(tmp_pi
->attr
, attr
)
414 && !CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
417 /* The attribute has changed.
418 * Add (or update) attribute to hash.
420 attr_new
= bgp_attr_intern(attr
);
421 bgp_path_info_set_flag(dest
, tmp_pi
,
422 BGP_PATH_ATTR_CHANGED
);
424 /* Restore route, if needed. */
425 if (CHECK_FLAG(tmp_pi
->flags
, BGP_PATH_REMOVED
))
426 bgp_path_info_restore(dest
, tmp_pi
);
428 /* Unintern existing, set to new. */
429 bgp_attr_unintern(&tmp_pi
->attr
);
430 tmp_pi
->attr
= attr_new
;
431 tmp_pi
->uptime
= bgp_clock();
435 if (*route_changed
) {
436 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
438 "local ES %s vni %u route-type %s nexthop %pI4 updated",
439 es
->esi_str
, vpn
? vpn
->vni
: 0,
440 evp
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
442 : (vpn
? "ead-evi" : "ead-es"),
443 &attr
->mp_nexthop_global_in
);
446 /* Return back the route entry. */
451 /* Delete local EVPN ESR (type-4) and EAD (type-1) route
453 * Note: vpn is applicable only to EAD-EVI routes (NULL for EAD-ES and
456 static int bgp_evpn_mh_route_delete(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
457 struct bgpevpn
*vpn
, struct prefix_evpn
*p
)
459 afi_t afi
= AFI_L2VPN
;
460 safi_t safi
= SAFI_EVPN
;
461 struct bgp_path_info
*pi
;
462 struct bgp_dest
*dest
= NULL
; /* dest in esi table */
463 struct bgp_dest
*global_dest
= NULL
; /* dest in global table */
464 struct bgp_table
*rt_table
;
465 struct prefix_rd
*prd
;
468 rt_table
= vpn
->route_table
;
471 rt_table
= es
->route_table
;
475 /* First, locate the route node within the ESI or VNI.
476 * If it doesn't exist, ther is nothing to do.
477 * Note: there is no RD here.
479 dest
= bgp_node_lookup(rt_table
, (struct prefix
*)p
);
483 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
485 "local ES %s vni %u route-type %s nexthop %pI4 delete",
486 es
->esi_str
, vpn
? vpn
->vni
: 0,
487 p
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
489 : (vpn
? "ead-evi" : "ead-es"),
492 /* Next, locate route node in the global EVPN routing table.
493 * Note that this table is a 2-level tree (RD-level + Prefix-level)
496 bgp_global_evpn_node_lookup(bgp
->rib
[afi
][safi
], afi
, safi
,
497 (const struct prefix_evpn
*)p
, prd
);
500 /* Delete route entry in the global EVPN table. */
501 delete_evpn_route_entry(bgp
, afi
, safi
, global_dest
, &pi
);
503 /* Schedule for processing - withdraws to peers happen from
507 bgp_process(bgp
, global_dest
, afi
, safi
);
508 bgp_dest_unlock_node(global_dest
);
512 * Delete route entry in the ESI or VNI routing table.
513 * This can just be removed.
515 delete_evpn_route_entry(bgp
, afi
, safi
, dest
, &pi
);
517 bgp_path_info_reap(dest
, pi
);
518 bgp_dest_unlock_node(dest
);
522 /*****************************************************************************
523 * Ethernet Segment (Type-4) Routes
524 * ESRs are used for DF election. Currently service-carving described in
525 * RFC 7432 is NOT supported. Instead preference based DF election is
527 * Reference: draft-ietf-bess-evpn-pref-df
529 /* Build extended community for EVPN ES (type-4) route */
530 static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es
*es
,
533 struct ecommunity ecom_encap
;
534 struct ecommunity ecom_es_rt
;
535 struct ecommunity ecom_df
;
536 struct ecommunity_val eval
;
537 struct ecommunity_val eval_es_rt
;
538 struct ecommunity_val eval_df
;
539 bgp_encap_types tnl_type
;
543 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
544 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
545 encode_encap_extcomm(tnl_type
, &eval
);
547 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
548 ecom_encap
.val
= (uint8_t *)eval
.val
;
549 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
552 memset(&mac
, 0, sizeof(struct ethaddr
));
553 memset(&ecom_es_rt
, 0, sizeof(ecom_es_rt
));
554 es_get_system_mac(&es
->esi
, &mac
);
555 encode_es_rt_extcomm(&eval_es_rt
, &mac
);
557 ecom_es_rt
.unit_size
= ECOMMUNITY_SIZE
;
558 ecom_es_rt
.val
= (uint8_t *)eval_es_rt
.val
;
560 ecommunity_merge(attr
->ecommunity
, &ecom_es_rt
);
562 /* DF election extended community */
563 memset(&ecom_df
, 0, sizeof(ecom_df
));
564 encode_df_elect_extcomm(&eval_df
, es
->df_pref
);
566 ecom_df
.val
= (uint8_t *)eval_df
.val
;
567 attr
->ecommunity
= ecommunity_merge(attr
->ecommunity
, &ecom_df
);
569 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
572 /* Create or update local type-4 route */
573 static int bgp_evpn_type4_route_update(struct bgp
*bgp
,
574 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
)
577 int route_changed
= 0;
578 afi_t afi
= AFI_L2VPN
;
579 safi_t safi
= SAFI_EVPN
;
581 struct attr
*attr_new
= NULL
;
582 struct bgp_dest
*dest
= NULL
;
583 struct bgp_path_info
*pi
= NULL
;
585 memset(&attr
, 0, sizeof(struct attr
));
587 /* Build path-attribute for this route. */
588 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
589 attr
.nexthop
= es
->originator_ip
;
590 attr
.mp_nexthop_global_in
= es
->originator_ip
;
591 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
593 /* Set up extended community. */
594 bgp_evpn_type4_route_extcomm_build(es
, &attr
);
596 /* First, create (or fetch) route node within the ESI. */
597 /* NOTE: There is no RD here. */
598 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
600 /* Create or update route entry. */
601 ret
= bgp_evpn_mh_route_update(bgp
, es
, NULL
, afi
, safi
, dest
, &attr
, 1,
602 &pi
, &route_changed
);
606 "%u ERROR: Failed to updated ES route ESI: %s VTEP %pI4",
607 bgp
->vrf_id
, es
->esi_str
, &es
->originator_ip
);
612 /* Perform route selection;
613 * this is just to set the flags correctly
614 * as local route in the ES always wins.
616 bgp_evpn_es_route_select_install(bgp
, es
, dest
);
617 bgp_dest_unlock_node(dest
);
619 /* If this is a new route or some attribute has changed, export the
620 * route to the global table. The route will be advertised to peers
621 * from there. Note that this table is a 2-level tree (RD-level +
622 * Prefix-level) similar to L3VPN routes.
625 struct bgp_path_info
*global_pi
;
627 dest
= bgp_global_evpn_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
629 bgp_evpn_mh_route_update(bgp
, es
, NULL
, afi
, safi
, dest
,
630 attr_new
, 1, &global_pi
,
633 /* Schedule for processing and unlock node. */
634 bgp_process(bgp
, dest
, afi
, safi
);
635 bgp_dest_unlock_node(dest
);
638 /* Unintern temporary. */
639 aspath_unintern(&attr
.aspath
);
643 /* Delete local type-4 route */
644 static int bgp_evpn_type4_route_delete(struct bgp
*bgp
,
645 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
)
647 return bgp_evpn_mh_route_delete(bgp
, es
, NULL
/* l2vni */, p
);
650 /* Process remote/received EVPN type-4 route (advertise or withdraw) */
651 int bgp_evpn_type4_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
652 struct attr
*attr
, uint8_t *pfx
, int psize
,
658 struct in_addr vtep_ip
;
659 struct prefix_rd prd
;
660 struct prefix_evpn p
;
662 /* Type-4 route should be either 23 or 35 bytes
663 * RD (8), ESI (10), ip-len (1), ip (4 or 16)
665 if (psize
!= BGP_EVPN_TYPE4_V4_PSIZE
&&
666 psize
!= BGP_EVPN_TYPE4_V6_PSIZE
) {
667 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
668 "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
669 peer
->bgp
->vrf_id
, peer
->host
, psize
);
674 prd
.family
= AF_UNSPEC
;
676 memcpy(&prd
.val
, pfx
, RD_BYTES
);
680 memcpy(&esi
, pfx
, ESI_BYTES
);
686 if (ipaddr_len
== IPV4_MAX_BITLEN
) {
687 memcpy(&vtep_ip
, pfx
, IPV4_MAX_BYTELEN
);
690 EC_BGP_EVPN_ROUTE_INVALID
,
691 "%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
692 peer
->bgp
->vrf_id
, peer
->host
, ipaddr_len
);
696 build_evpn_type4_prefix(&p
, &esi
, vtep_ip
);
697 /* Process the route. */
699 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
700 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
701 &prd
, NULL
, 0, 0, NULL
);
703 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
704 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
705 &prd
, NULL
, 0, NULL
);
710 /* Check if a prefix belongs to the local ES */
711 static bool bgp_evpn_type4_prefix_match(struct prefix_evpn
*p
,
712 struct bgp_evpn_es
*es
)
714 return (p
->prefix
.route_type
== BGP_EVPN_ES_ROUTE
) &&
715 !memcmp(&p
->prefix
.es_addr
.esi
, &es
->esi
, sizeof(esi_t
));
718 /* Import remote ESRs on local ethernet segment add */
719 static int bgp_evpn_type4_remote_routes_import(struct bgp
*bgp
,
720 struct bgp_evpn_es
*es
, bool install
)
725 struct bgp_dest
*rd_dest
, *dest
;
726 struct bgp_table
*table
;
727 struct bgp_path_info
*pi
;
732 /* Walk entire global routing table and evaluate routes which could be
733 * imported into this Ethernet Segment.
735 for (rd_dest
= bgp_table_top(bgp
->rib
[afi
][safi
]); rd_dest
;
736 rd_dest
= bgp_route_next(rd_dest
)) {
737 table
= bgp_dest_get_bgp_table_info(rd_dest
);
741 for (dest
= bgp_table_top(table
); dest
;
742 dest
= bgp_route_next(dest
)) {
743 struct prefix_evpn
*evp
=
744 (struct prefix_evpn
*)bgp_dest_get_prefix(dest
);
746 for (pi
= bgp_dest_get_bgp_path_info(dest
); pi
;
749 * Consider "valid" remote routes applicable for
752 if (!(CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
)
753 && pi
->type
== ZEBRA_ROUTE_BGP
754 && pi
->sub_type
== BGP_ROUTE_NORMAL
))
757 if (!bgp_evpn_type4_prefix_match(evp
, es
))
761 ret
= bgp_evpn_es_route_install(
764 ret
= bgp_evpn_es_route_uninstall(
770 "Failed to %s EVPN %pFX route in ESI %s",
775 bgp_dest_unlock_node(rd_dest
);
776 bgp_dest_unlock_node(dest
);
785 /*****************************************************************************
786 * Ethernet Auto Discovery (EAD/Type-1) route handling
787 * There are two types of EAD routes -
788 * 1. EAD-per-ES - Key: {ESI, ET=0xffffffff}
789 * 2. EAD-per-EVI - Key: {ESI, ET=0}
792 /* Extended communities associated with EAD-per-ES */
793 static void bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es
*es
,
796 struct ecommunity ecom_encap
;
797 struct ecommunity ecom_esi_label
;
798 struct ecommunity_val eval
;
799 struct ecommunity_val eval_esi_label
;
800 bgp_encap_types tnl_type
;
801 struct listnode
*evi_node
, *rt_node
;
802 struct ecommunity
*ecom
;
803 struct bgp_evpn_es_evi
*es_evi
;
806 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
807 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
808 encode_encap_extcomm(tnl_type
, &eval
);
810 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
811 ecom_encap
.val
= (uint8_t *)eval
.val
;
812 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
815 encode_esi_label_extcomm(&eval_esi_label
,
816 false /*single_active*/);
817 ecom_esi_label
.size
= 1;
818 ecom_esi_label
.unit_size
= ECOMMUNITY_SIZE
;
819 ecom_esi_label
.val
= (uint8_t *)eval_esi_label
.val
;
821 ecommunity_merge(attr
->ecommunity
, &ecom_esi_label
);
823 /* Add export RTs for all L2-VNIs associated with this ES */
824 /* XXX - suppress EAD-ES advertisment if there are no EVIs associated
827 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
,
829 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
831 for (ALL_LIST_ELEMENTS_RO(es_evi
->vpn
->export_rtl
,
833 attr
->ecommunity
= ecommunity_merge(attr
->ecommunity
,
837 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
840 /* Extended communities associated with EAD-per-EVI */
841 static void bgp_evpn_type1_evi_route_extcomm_build(struct bgp_evpn_es
*es
,
842 struct bgpevpn
*vpn
, struct attr
*attr
)
844 struct ecommunity ecom_encap
;
845 struct ecommunity_val eval
;
846 bgp_encap_types tnl_type
;
847 struct listnode
*rt_node
;
848 struct ecommunity
*ecom
;
851 tnl_type
= BGP_ENCAP_TYPE_VXLAN
;
852 memset(&ecom_encap
, 0, sizeof(ecom_encap
));
853 encode_encap_extcomm(tnl_type
, &eval
);
855 ecom_encap
.unit_size
= ECOMMUNITY_SIZE
;
856 ecom_encap
.val
= (uint8_t *)eval
.val
;
857 attr
->ecommunity
= ecommunity_dup(&ecom_encap
);
859 /* Add export RTs for the L2-VNI */
860 for (ALL_LIST_ELEMENTS_RO(vpn
->export_rtl
, rt_node
, ecom
))
861 attr
->ecommunity
= ecommunity_merge(attr
->ecommunity
, ecom
);
863 attr
->flag
|= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES
);
866 /* Update EVPN EAD (type-1) route -
867 * vpn - valid for EAD-EVI routes and NULL for EAD-ES routes
869 static int bgp_evpn_type1_route_update(struct bgp
*bgp
,
870 struct bgp_evpn_es
*es
, struct bgpevpn
*vpn
,
871 struct prefix_evpn
*p
)
874 afi_t afi
= AFI_L2VPN
;
875 safi_t safi
= SAFI_EVPN
;
877 struct attr
*attr_new
= NULL
;
878 struct bgp_dest
*dest
= NULL
;
879 struct bgp_path_info
*pi
= NULL
;
880 int route_changed
= 0;
881 struct prefix_rd
*global_rd
;
883 memset(&attr
, 0, sizeof(struct attr
));
885 /* Build path-attribute for this route. */
886 bgp_attr_default_set(&attr
, BGP_ORIGIN_IGP
);
887 attr
.nexthop
= es
->originator_ip
;
888 attr
.mp_nexthop_global_in
= es
->originator_ip
;
889 attr
.mp_nexthop_len
= BGP_ATTR_NHLEN_IPV4
;
892 /* EAD-EVI route update */
894 vni2label(vpn
->vni
, &(attr
.label
));
896 /* Set up extended community */
897 bgp_evpn_type1_evi_route_extcomm_build(es
, vpn
, &attr
);
899 /* First, create (or fetch) route node within the VNI. */
900 dest
= bgp_node_get(vpn
->route_table
, (struct prefix
*)p
);
902 /* Create or update route entry. */
903 ret
= bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
904 &attr
, 1, &pi
, &route_changed
);
908 "%u Failed to update EAD-EVI route ESI: %s VNI %u VTEP %pI4",
909 bgp
->vrf_id
, es
->esi_str
, vpn
->vni
,
911 global_rd
= &vpn
->prd
;
913 /* EAD-ES route update */
914 /* MPLS label is 0 for EAD-ES route */
916 /* Set up extended community */
917 bgp_evpn_type1_es_route_extcomm_build(es
, &attr
);
919 /* First, create (or fetch) route node within the ES. */
920 /* NOTE: There is no RD here. */
921 /* XXX: fragment ID must be included as a part of the prefix. */
922 dest
= bgp_node_get(es
->route_table
, (struct prefix
*)p
);
924 /* Create or update route entry. */
925 ret
= bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
926 &attr
, 1, &pi
, &route_changed
);
930 "%u ERROR: Failed to updated EAD-EVI route ESI: %s VTEP %pI4",
931 bgp
->vrf_id
, es
->esi_str
, &es
->originator_ip
);
933 global_rd
= &es
->prd
;
940 /* Perform route selection;
941 * this is just to set the flags correctly as local route in
942 * the ES always wins.
944 evpn_route_select_install(bgp
, vpn
, dest
);
945 bgp_dest_unlock_node(dest
);
947 /* If this is a new route or some attribute has changed, export the
948 * route to the global table. The route will be advertised to peers
949 * from there. Note that this table is a 2-level tree (RD-level +
950 * Prefix-level) similar to L3VPN routes.
953 struct bgp_path_info
*global_pi
;
955 dest
= bgp_global_evpn_node_get(bgp
->rib
[afi
][safi
], afi
, safi
,
957 bgp_evpn_mh_route_update(bgp
, es
, vpn
, afi
, safi
, dest
,
958 attr_new
, 1, &global_pi
,
961 /* Schedule for processing and unlock node. */
962 bgp_process(bgp
, dest
, afi
, safi
);
963 bgp_dest_unlock_node(dest
);
966 /* Unintern temporary. */
967 aspath_unintern(&attr
.aspath
);
971 /* Delete local Type-1 route */
972 static int bgp_evpn_type1_es_route_delete(struct bgp
*bgp
,
973 struct bgp_evpn_es
*es
, struct prefix_evpn
*p
)
975 return bgp_evpn_mh_route_delete(bgp
, es
, NULL
/* l2vni */, p
);
978 static int bgp_evpn_type1_evi_route_delete(struct bgp
*bgp
,
979 struct bgp_evpn_es
*es
, struct bgpevpn
*vpn
,
980 struct prefix_evpn
*p
)
982 return bgp_evpn_mh_route_delete(bgp
, es
, vpn
, p
);
985 /* Generate EAD-EVI for all VNIs */
986 static void bgp_evpn_local_type1_evi_route_add(struct bgp
*bgp
,
987 struct bgp_evpn_es
*es
)
989 struct listnode
*evi_node
;
990 struct prefix_evpn p
;
991 struct bgp_evpn_es_evi
*es_evi
;
993 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
))
994 /* EAD-EVI route add for this ES is already done */
997 SET_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
);
998 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
999 &es
->esi
, es
->originator_ip
);
1001 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, evi_node
, es_evi
)) {
1002 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
1004 if (bgp_evpn_type1_route_update(bgp
, es
, es_evi
->vpn
, &p
))
1005 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
1006 "%u: Type4 route creation failure for ESI %s",
1007 bgp
->vrf_id
, es
->esi_str
);
1012 * Withdraw EAD-EVI for all VNIs
1014 static void bgp_evpn_local_type1_evi_route_del(struct bgp
*bgp
,
1015 struct bgp_evpn_es
*es
)
1017 struct listnode
*evi_node
;
1018 struct prefix_evpn p
;
1019 struct bgp_evpn_es_evi
*es_evi
;
1021 /* Delete and withdraw locally learnt EAD-EVI route */
1022 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
))
1023 /* EAD-EVI route has not been advertised for this ES */
1026 UNSET_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
);
1027 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
1028 &es
->esi
, es
->originator_ip
);
1029 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, evi_node
, es_evi
)) {
1030 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
1032 if (bgp_evpn_mh_route_delete(bgp
, es
, es_evi
->vpn
, &p
))
1033 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
1034 "%u: Type4 route creation failure for ESI %s",
1035 bgp
->vrf_id
, es
->esi_str
);
1040 * Process received EVPN type-1 route (advertise or withdraw).
1042 int bgp_evpn_type1_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
1043 struct attr
*attr
, uint8_t *pfx
, int psize
,
1044 uint32_t addpath_id
)
1047 struct prefix_rd prd
;
1051 struct in_addr vtep_ip
;
1052 struct prefix_evpn p
;
1054 if (psize
!= BGP_EVPN_TYPE1_PSIZE
) {
1055 flog_err(EC_BGP_EVPN_ROUTE_INVALID
,
1056 "%u:%s - Rx EVPN Type-1 NLRI with invalid length %d",
1057 peer
->bgp
->vrf_id
, peer
->host
, psize
);
1061 /* Make prefix_rd */
1062 prd
.family
= AF_UNSPEC
;
1064 memcpy(&prd
.val
, pfx
, RD_BYTES
);
1068 memcpy(&esi
, pfx
, ESI_BYTES
);
1071 /* Copy Ethernet Tag */
1072 memcpy(ð_tag
, pfx
, EVPN_ETH_TAG_BYTES
);
1073 eth_tag
= ntohl(eth_tag
);
1074 pfx
+= EVPN_ETH_TAG_BYTES
;
1076 memcpy(&label
, pfx
, BGP_LABEL_BYTES
);
1078 /* EAD route prefix doesn't include the nexthop in the global
1082 build_evpn_type1_prefix(&p
, eth_tag
, &esi
, vtep_ip
);
1083 /* Process the route. */
1085 ret
= bgp_update(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
1086 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
1087 &prd
, NULL
, 0, 0, NULL
);
1089 ret
= bgp_withdraw(peer
, (struct prefix
*)&p
, addpath_id
, attr
,
1090 afi
, safi
, ZEBRA_ROUTE_BGP
, BGP_ROUTE_NORMAL
,
1091 &prd
, NULL
, 0, NULL
);
1096 /*****************************************************************************/
1097 /* Ethernet Segment Management
1098 * 1. Ethernet Segment is a collection of links attached to the same
1099 * server (MHD) or switch (MHN)
1100 * 2. An Ethernet Segment can span multiple PEs and is identified by the
1102 * 3. Local ESs are configured in zebra and sent to BGP
1103 * 4. Remote ESs are created by BGP when one or more ES-EVIs reference it i.e.
1104 * created on first reference and release on last de-reference
1105 * 5. An ES can be both local and remote. Infact most local ESs are expected
1106 * to have an ES peer.
1109 /* A list of remote VTEPs is maintained for each ES. This list includes -
1110 * 1. VTEPs for which we have imported the ESR i.e. ES-peers
1111 * 2. VTEPs that have an "active" ES-EVI VTEP i.e. EAD-per-ES and EAD-per-EVI
1112 * have been imported into one or more VNIs
1114 static int bgp_evpn_es_vtep_cmp(void *p1
, void *p2
)
1116 const struct bgp_evpn_es_vtep
*es_vtep1
= p1
;
1117 const struct bgp_evpn_es_vtep
*es_vtep2
= p2
;
1119 return es_vtep1
->vtep_ip
.s_addr
- es_vtep2
->vtep_ip
.s_addr
;
1122 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_new(struct bgp_evpn_es
*es
,
1123 struct in_addr vtep_ip
)
1125 struct bgp_evpn_es_vtep
*es_vtep
;
1127 es_vtep
= XCALLOC(MTYPE_BGP_EVPN_ES_VTEP
, sizeof(*es_vtep
));
1130 es_vtep
->vtep_ip
.s_addr
= vtep_ip
.s_addr
;
1131 listnode_init(&es_vtep
->es_listnode
, es_vtep
);
1132 listnode_add_sort(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1137 static void bgp_evpn_es_vtep_free(struct bgp_evpn_es_vtep
*es_vtep
)
1139 struct bgp_evpn_es
*es
= es_vtep
->es
;
1141 if (CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
) ||
1143 /* as long as there is some reference we can't free it */
1146 list_delete_node(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1147 XFREE(MTYPE_BGP_EVPN_ES_VTEP
, es_vtep
);
1150 /* check if VTEP is already part of the list */
1151 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_find(struct bgp_evpn_es
*es
,
1152 struct in_addr vtep_ip
)
1154 struct listnode
*node
= NULL
;
1155 struct bgp_evpn_es_vtep
*es_vtep
;
1157 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1158 if (es_vtep
->vtep_ip
.s_addr
== vtep_ip
.s_addr
)
1164 /* Send the remote ES to zebra for NHG programming */
1165 static int bgp_zebra_send_remote_es_vtep(struct bgp
*bgp
,
1166 struct bgp_evpn_es_vtep
*es_vtep
, bool add
)
1168 struct bgp_evpn_es
*es
= es_vtep
->es
;
1173 if (!zclient
|| zclient
->sock
< 0)
1176 /* Don't try to register if Zebra doesn't know of this instance. */
1177 if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp
)) {
1178 if (BGP_DEBUG(zebra
, ZEBRA
))
1179 zlog_debug("No zebra instance, not installing remote es %s",
1184 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1185 flags
|= ZAPI_ES_VTEP_FLAG_ESR_RXED
;
1190 zclient_create_header(s
,
1191 add
? ZEBRA_REMOTE_ES_VTEP_ADD
: ZEBRA_REMOTE_ES_VTEP_DEL
,
1193 stream_put(s
, &es
->esi
, sizeof(esi_t
));
1194 stream_put_ipv4(s
, es_vtep
->vtep_ip
.s_addr
);
1196 stream_putl(s
, flags
);
1197 stream_putc(s
, es_vtep
->df_alg
);
1198 stream_putw(s
, es_vtep
->df_pref
);
1201 stream_putw_at(s
, 0, stream_get_endp(s
));
1203 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1204 zlog_debug("Tx %s Remote ESI %s VTEP %pI4", add
? "ADD" : "DEL",
1205 es
->esi_str
, &es_vtep
->vtep_ip
);
1207 return zclient_send_message(zclient
);
1210 static void bgp_evpn_es_vtep_re_eval_active(struct bgp
*bgp
,
1211 struct bgp_evpn_es_vtep
*es_vtep
,
1217 old_active
= !!CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1218 /* currently we need an active EVI reference to use the VTEP as
1219 * a nexthop. this may change...
1221 if (es_vtep
->evi_cnt
)
1222 SET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1224 UNSET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1226 new_active
= !!CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
);
1228 if ((old_active
!= new_active
) || (new_active
&& param_change
)) {
1230 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1231 zlog_debug("es %s vtep %pI4 %s df %u/%u",
1232 es_vtep
->es
->esi_str
, &es_vtep
->vtep_ip
,
1233 new_active
? "active" : "inactive",
1234 es_vtep
->df_alg
, es_vtep
->df_pref
);
1236 /* send remote ES to zebra */
1237 bgp_zebra_send_remote_es_vtep(bgp
, es_vtep
, new_active
);
1239 /* The NHG is updated first for efficient failover handling.
1240 * Note the NHG can be de-activated while there are bgp
1241 * routes referencing it. Zebra is capable of handling that
1242 * elegantly by holding the NHG till all routes using it are
1245 bgp_evpn_l3nhg_update_on_vtep_chg(es_vtep
->es
);
1246 bgp_evpn_es_path_all_update(es_vtep
, new_active
);
1248 /* queue up the es for background consistency checks */
1249 bgp_evpn_es_cons_checks_pend_add(es_vtep
->es
);
1253 static struct bgp_evpn_es_vtep
*bgp_evpn_es_vtep_add(struct bgp
*bgp
,
1254 struct bgp_evpn_es
*es
,
1255 struct in_addr vtep_ip
,
1256 bool esr
, uint8_t df_alg
,
1259 struct bgp_evpn_es_vtep
*es_vtep
;
1260 bool param_change
= false;
1262 es_vtep
= bgp_evpn_es_vtep_find(es
, vtep_ip
);
1265 es_vtep
= bgp_evpn_es_vtep_new(es
, vtep_ip
);
1267 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1268 zlog_debug("es %s vtep %pI4 add %s df %u/%u",
1269 es_vtep
->es
->esi_str
, &es_vtep
->vtep_ip
,
1270 esr
? "esr" : "ead", df_alg
, df_pref
);
1273 SET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
);
1274 if ((es_vtep
->df_pref
!= df_pref
)
1275 || (es_vtep
->df_alg
!= df_alg
)) {
1276 param_change
= true;
1277 es_vtep
->df_pref
= df_pref
;
1278 es_vtep
->df_alg
= df_alg
;
1284 bgp_evpn_es_vtep_re_eval_active(bgp
, es_vtep
, param_change
);
1289 static void bgp_evpn_es_vtep_do_del(struct bgp
*bgp
,
1290 struct bgp_evpn_es_vtep
*es_vtep
, bool esr
)
1292 bool param_change
= false;
1294 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1295 zlog_debug("es %s vtep %pI4 del %s", es_vtep
->es
->esi_str
,
1296 &es_vtep
->vtep_ip
, esr
? "esr" : "ead");
1298 UNSET_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ESR
);
1299 if (es_vtep
->df_pref
|| es_vtep
->df_alg
) {
1300 param_change
= true;
1301 es_vtep
->df_pref
= 0;
1302 es_vtep
->df_alg
= 0;
1305 if (es_vtep
->evi_cnt
)
1309 bgp_evpn_es_vtep_re_eval_active(bgp
, es_vtep
, param_change
);
1310 bgp_evpn_es_vtep_free(es_vtep
);
1313 static void bgp_evpn_es_vtep_del(struct bgp
*bgp
,
1314 struct bgp_evpn_es
*es
, struct in_addr vtep_ip
, bool esr
)
1316 struct bgp_evpn_es_vtep
*es_vtep
;
1318 es_vtep
= bgp_evpn_es_vtep_find(es
, vtep_ip
);
1320 bgp_evpn_es_vtep_do_del(bgp
, es_vtep
, esr
);
1323 bool bgp_evpn_es_is_vtep_active(esi_t
*esi
, struct in_addr nh
)
1325 struct bgp_evpn_es
*es
;
1326 struct bgp_evpn_es_vtep
*es_vtep
;
1327 struct listnode
*node
= NULL
;
1330 if (!memcmp(esi
, zero_esi
, sizeof(*esi
)) || !nh
.s_addr
)
1333 es
= bgp_evpn_es_find(esi
);
1337 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1338 if (es_vtep
->vtep_ip
.s_addr
== nh
.s_addr
) {
1339 if (CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
1347 /********************** ES MAC-IP paths *************************************
1348 * MAC-IP routes in the VNI routing table are linked to the destination
1349 * ES for efficient updates on ES changes (such as VTEP add/del).
1350 ****************************************************************************/
1351 void bgp_evpn_path_es_info_free(struct bgp_path_es_info
*es_info
)
1353 bgp_evpn_path_es_unlink(es_info
);
1354 XFREE(MTYPE_BGP_EVPN_PATH_ES_INFO
, es_info
);
1357 static struct bgp_path_es_info
*
1358 bgp_evpn_path_es_info_new(struct bgp_path_info
*pi
, vni_t vni
)
1360 struct bgp_path_info_extra
*e
;
1362 e
= bgp_path_info_extra_get(pi
);
1364 /* If es_info doesn't exist allocate it */
1366 e
->es_info
= XCALLOC(MTYPE_BGP_EVPN_PATH_ES_INFO
,
1367 sizeof(struct bgp_path_es_info
));
1368 e
->es_info
->pi
= pi
;
1369 e
->es_info
->vni
= vni
;
1375 void bgp_evpn_path_es_unlink(struct bgp_path_es_info
*es_info
)
1377 struct bgp_evpn_es
*es
= es_info
->es
;
1378 struct bgp_path_info
*pi
;
1384 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1385 zlog_debug("vni %u path %pFX unlinked from es %s", es_info
->vni
,
1386 &pi
->net
->p
, es
->esi_str
);
1388 list_delete_node(es
->macip_path_list
, &es_info
->es_listnode
);
1391 /* if there are no other references against the ES it
1394 bgp_evpn_es_free(es
, __func__
);
1396 /* Note we don't free the path es_info on unlink; it will be freed up
1397 * along with the path.
1401 void bgp_evpn_path_es_link(struct bgp_path_info
*pi
, vni_t vni
, esi_t
*esi
)
1403 struct bgp_path_es_info
*es_info
;
1404 struct bgp_evpn_es
*es
;
1405 struct bgp
*bgp_evpn
= bgp_get_evpn();
1407 es_info
= pi
->extra
? pi
->extra
->es_info
: NULL
;
1408 /* if the esi is zero just unlink the path from the old es */
1409 if (!esi
|| !memcmp(esi
, zero_esi
, sizeof(*esi
))) {
1411 bgp_evpn_path_es_unlink(es_info
);
1418 /* setup es_info against the path if it doesn't aleady exist */
1420 es_info
= bgp_evpn_path_es_info_new(pi
, vni
);
1422 /* find-create ES */
1423 es
= bgp_evpn_es_find(esi
);
1425 es
= bgp_evpn_es_new(bgp_evpn
, esi
);
1428 if (es_info
->es
== es
)
1431 /* unlink old ES if any */
1432 bgp_evpn_path_es_unlink(es_info
);
1434 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1435 zlog_debug("vni %u path %pFX linked to es %s", vni
, &pi
->net
->p
,
1438 /* link mac-ip path to the new destination ES */
1440 listnode_init(&es_info
->es_listnode
, es_info
);
1441 listnode_add(es
->macip_path_list
, &es_info
->es_listnode
);
1444 static void bgp_evpn_es_path_all_update(struct bgp_evpn_es_vtep
*es_vtep
,
1447 struct listnode
*node
;
1448 struct bgp_path_es_info
*es_info
;
1449 struct bgp_path_info
*pi
;
1450 struct bgp_path_info
*parent_pi
;
1451 struct bgp_evpn_es
*es
= es_vtep
->es
;
1452 char prefix_buf
[PREFIX_STRLEN
];
1454 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1455 zlog_debug("update all paths linked to es %s", es
->esi_str
);
1457 for (ALL_LIST_ELEMENTS_RO(es
->macip_path_list
, node
, es_info
)) {
1459 if (!CHECK_FLAG(pi
->flags
, BGP_PATH_VALID
))
1462 if (pi
->sub_type
!= BGP_ROUTE_IMPORTED
)
1465 parent_pi
= pi
->extra
? pi
->extra
->parent
: NULL
;
1466 if (!parent_pi
|| !parent_pi
->attr
)
1469 if (es_vtep
->vtep_ip
.s_addr
!= parent_pi
->attr
->nexthop
.s_addr
)
1472 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
1473 zlog_debug("update path %s linked to es %s",
1474 prefix2str(&parent_pi
->net
->p
, prefix_buf
,
1475 sizeof(prefix_buf
)),
1477 bgp_evpn_import_route_in_vrfs(parent_pi
, active
? 1 : 0);
1481 /* compare ES-IDs for the global ES RB tree */
1482 static int bgp_es_rb_cmp(const struct bgp_evpn_es
*es1
,
1483 const struct bgp_evpn_es
*es2
)
1485 return memcmp(&es1
->esi
, &es2
->esi
, ESI_BYTES
);
1487 RB_GENERATE(bgp_es_rb_head
, bgp_evpn_es
, rb_node
, bgp_es_rb_cmp
);
1489 struct bgp_evpn_es
*bgp_evpn_es_find(const esi_t
*esi
)
1491 struct bgp_evpn_es tmp
;
1493 memcpy(&tmp
.esi
, esi
, sizeof(esi_t
));
1494 return RB_FIND(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, &tmp
);
1497 static struct bgp_evpn_es
*bgp_evpn_es_new(struct bgp
*bgp
, const esi_t
*esi
)
1499 struct bgp_evpn_es
*es
;
1504 es
= XCALLOC(MTYPE_BGP_EVPN_ES
, sizeof(struct bgp_evpn_es
));
1507 memcpy(&es
->esi
, esi
, sizeof(esi_t
));
1509 /* Initialise the VTEP list */
1510 es
->es_vtep_list
= list_new();
1511 listset_app_node_mem(es
->es_vtep_list
);
1512 es
->es_vtep_list
->cmp
= bgp_evpn_es_vtep_cmp
;
1514 esi_to_str(&es
->esi
, es
->esi_str
, sizeof(es
->esi_str
));
1516 /* Initialize the ES routing table */
1517 es
->route_table
= bgp_table_init(bgp
, AFI_L2VPN
, SAFI_EVPN
);
1519 /* Add to rb_tree */
1520 if (RB_INSERT(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, es
)) {
1521 XFREE(MTYPE_BGP_EVPN_ES
, es
);
1525 /* Initialise the ES-EVI list */
1526 es
->es_evi_list
= list_new();
1527 listset_app_node_mem(es
->es_evi_list
);
1529 /* Initialise the ES-VRF list used for L3NHG management */
1530 es
->es_vrf_list
= list_new();
1531 listset_app_node_mem(es
->es_vrf_list
);
1533 /* Initialise the route list used for efficient event handling */
1534 es
->macip_path_list
= list_new();
1535 listset_app_node_mem(es
->macip_path_list
);
1537 QOBJ_REG(es
, bgp_evpn_es
);
1542 /* Free a given ES -
1543 * This just frees appropriate memory, caller should have taken other
1546 static void bgp_evpn_es_free(struct bgp_evpn_es
*es
, const char *caller
)
1548 if ((es
->flags
& (BGP_EVPNES_LOCAL
| BGP_EVPNES_REMOTE
))
1549 || listcount(es
->macip_path_list
))
1552 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1553 zlog_debug("%s: es %s free", caller
, es
->esi_str
);
1555 /* cleanup resources maintained against the ES */
1556 list_delete(&es
->es_evi_list
);
1557 list_delete(&es
->es_vrf_list
);
1558 list_delete(&es
->es_vtep_list
);
1559 list_delete(&es
->macip_path_list
);
1560 bgp_table_unlock(es
->route_table
);
1562 /* remove the entry from various databases */
1563 RB_REMOVE(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
, es
);
1564 bgp_evpn_es_cons_checks_pend_del(es
);
1567 XFREE(MTYPE_BGP_EVPN_ES
, es
);
1570 /* init local info associated with the ES */
1571 static void bgp_evpn_es_local_info_set(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
1573 char buf
[BGP_EVPN_PREFIX_RD_LEN
];
1575 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
1578 SET_FLAG(es
->flags
, BGP_EVPNES_LOCAL
);
1579 listnode_init(&es
->es_listnode
, es
);
1580 listnode_add(bgp_mh_info
->local_es_list
, &es
->es_listnode
);
1582 /* auto derive RD for this es */
1583 bf_assign_index(bm
->rd_idspace
, es
->rd_id
);
1584 es
->prd
.family
= AF_UNSPEC
;
1585 es
->prd
.prefixlen
= 64;
1586 snprintfrr(buf
, sizeof(buf
), "%pI4:%hu", &bgp
->router_id
, es
->rd_id
);
1587 (void)str2prefix_rd(buf
, &es
->prd
);
1590 /* clear any local info associated with the ES */
1591 static void bgp_evpn_es_local_info_clear(struct bgp_evpn_es
*es
)
1593 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
1596 UNSET_FLAG(es
->flags
, BGP_EVPNES_LOCAL
);
1598 /* remove from the ES local list */
1599 list_delete_node(bgp_mh_info
->local_es_list
, &es
->es_listnode
);
1601 bf_release_index(bm
->rd_idspace
, es
->rd_id
);
1603 bgp_evpn_es_free(es
, __func__
);
1606 /* eval remote info associated with the ES */
1607 static void bgp_evpn_es_remote_info_re_eval(struct bgp_evpn_es
*es
)
1609 if (es
->remote_es_evi_cnt
) {
1610 SET_FLAG(es
->flags
, BGP_EVPNES_REMOTE
);
1612 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_REMOTE
)) {
1613 UNSET_FLAG(es
->flags
, BGP_EVPNES_REMOTE
);
1614 bgp_evpn_es_free(es
, __func__
);
1619 /* Process ES link oper-down by withdrawing ES-EAD and ESR */
1620 static void bgp_evpn_local_es_down(struct bgp
*bgp
,
1621 struct bgp_evpn_es
*es
)
1623 struct prefix_evpn p
;
1626 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
))
1629 UNSET_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
);
1631 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1632 zlog_debug("local es %s down", es
->esi_str
);
1635 /* Delete and withdraw locally learnt ES route */
1636 build_evpn_type4_prefix(&p
, &es
->esi
, es
->originator_ip
);
1637 ret
= bgp_evpn_type4_route_delete(bgp
, es
, &p
);
1639 flog_err(EC_BGP_EVPN_ROUTE_DELETE
,
1640 "%u failed to delete type-4 route for ESI %s",
1641 bgp
->vrf_id
, es
->esi_str
);
1644 /* withdraw EAD-EVI */
1645 if (!bgp_mh_info
->ead_evi_adv_for_down_links
)
1646 bgp_evpn_local_type1_evi_route_del(bgp
, es
);
1648 /* withdraw EAD-ES */
1649 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
,
1650 &es
->esi
, es
->originator_ip
);
1651 ret
= bgp_evpn_type1_es_route_delete(bgp
, es
, &p
);
1653 flog_err(EC_BGP_EVPN_ROUTE_DELETE
,
1654 "%u failed to delete type-1 route for ESI %s",
1655 bgp
->vrf_id
, es
->esi_str
);
1659 /* Process ES link oper-up by generating ES-EAD and ESR */
1660 static void bgp_evpn_local_es_up(struct bgp
*bgp
, struct bgp_evpn_es
*es
,
1663 struct prefix_evpn p
;
1664 bool regen_ead
= false;
1666 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
)) {
1667 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1668 zlog_debug("local es %s up", es
->esi_str
);
1670 SET_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
);
1676 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1677 zlog_debug("local es %s generate ESR", es
->esi_str
);
1679 build_evpn_type4_prefix(&p
, &es
->esi
, es
->originator_ip
);
1680 if (bgp_evpn_type4_route_update(bgp
, es
, &p
))
1681 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
1682 "%u: Type4 route creation failure for ESI %s",
1683 bgp
->vrf_id
, es
->esi_str
);
1687 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1688 zlog_debug("local es %s generate EAD", es
->esi_str
);
1689 /* generate EAD-EVI */
1690 bgp_evpn_local_type1_evi_route_add(bgp
, es
);
1692 /* generate EAD-ES */
1693 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
, &es
->esi
,
1695 bgp_evpn_type1_route_update(bgp
, es
, NULL
, &p
);
1699 static void bgp_evpn_local_es_do_del(struct bgp
*bgp
, struct bgp_evpn_es
*es
)
1701 struct bgp_evpn_es_evi
*es_evi
;
1702 struct listnode
*evi_node
, *evi_next_node
;
1704 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1705 zlog_debug("del local es %s", es
->esi_str
);
1707 /* Delete all local EVPN ES routes from ESI table
1708 * and schedule for processing (to withdraw from peers))
1710 bgp_evpn_es_route_del_all(bgp
, es
);
1712 /* release all local ES EVIs associated with the ES */
1713 for (ALL_LIST_ELEMENTS(es
->es_evi_list
, evi_node
,
1714 evi_next_node
, es_evi
)) {
1715 bgp_evpn_local_es_evi_do_del(es_evi
);
1718 /* Clear local info associated with the ES and free it up if there is
1719 * no remote reference
1721 bgp_evpn_es_local_info_clear(es
);
1724 bool bgp_evpn_is_esi_local(esi_t
*esi
)
1726 struct bgp_evpn_es
*es
= NULL
;
1728 /* Lookup ESI hash - should exist. */
1729 es
= bgp_evpn_es_find(esi
);
1730 return es
? !!(es
->flags
& BGP_EVPNES_LOCAL
) : false;
1733 int bgp_evpn_local_es_del(struct bgp
*bgp
, esi_t
*esi
)
1735 struct bgp_evpn_es
*es
= NULL
;
1737 /* Lookup ESI hash - should exist. */
1738 es
= bgp_evpn_es_find(esi
);
1740 flog_warn(EC_BGP_EVPN_ESI
,
1741 "%u: ES %s missing at local ES DEL",
1742 bgp
->vrf_id
, es
->esi_str
);
1746 bgp_evpn_local_es_do_del(bgp
, es
);
1750 /* Handle device to ES id association. Results in the creation of a local
1753 int bgp_evpn_local_es_add(struct bgp
*bgp
, esi_t
*esi
,
1754 struct in_addr originator_ip
, bool oper_up
,
1757 char buf
[ESI_STR_LEN
];
1758 struct bgp_evpn_es
*es
;
1760 bool regen_esr
= false;
1762 /* create the new es */
1763 es
= bgp_evpn_es_find(esi
);
1765 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
))
1768 es
= bgp_evpn_es_new(bgp
, esi
);
1770 flog_err(EC_BGP_ES_CREATE
,
1771 "%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
1772 bgp
->vrf_id
, esi_to_str(esi
, buf
, sizeof(buf
)));
1777 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
1778 zlog_debug("add local es %s orig-ip %pI4 df_pref %u", es
->esi_str
,
1779 &originator_ip
, df_pref
);
1781 es
->originator_ip
= originator_ip
;
1782 if (df_pref
!= es
->df_pref
) {
1783 es
->df_pref
= df_pref
;
1786 bgp_evpn_es_local_info_set(bgp
, es
);
1788 /* import all remote Type-4 routes in the ES table */
1790 bgp_evpn_type4_remote_routes_import(bgp
, es
,
1791 true /* install */);
1793 /* create and advertise EAD-EVI routes for the ES -
1794 * XXX - till an ES-EVI reference is created there is really nothing to
1797 if (bgp_mh_info
->ead_evi_adv_for_down_links
)
1798 bgp_evpn_local_type1_evi_route_add(bgp
, es
);
1800 /* If the ES link is operationally up generate EAD-ES. EAD-EVI
1801 * can be generated even if the link is inactive.
1804 bgp_evpn_local_es_up(bgp
, es
, regen_esr
);
1806 bgp_evpn_local_es_down(bgp
, es
);
1811 static char *bgp_evpn_es_vteps_str(char *vtep_str
, struct bgp_evpn_es
*es
,
1812 uint8_t vtep_str_size
)
1814 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
1815 struct listnode
*node
;
1816 struct bgp_evpn_es_vtep
*es_vtep
;
1818 char ip_buf
[INET6_ADDRSTRLEN
];
1821 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1822 vtep_flag_str
[0] = '\0';
1824 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1825 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
1826 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
1827 strlcat(vtep_flag_str
, "A", sizeof(vtep_flag_str
));
1829 if (!strlen(vtep_flag_str
))
1830 strlcat(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
1834 strlcat(vtep_str
, ",", vtep_str_size
);
1836 inet_ntop(AF_INET
, &es_vtep
->vtep_ip
, ip_buf
,
1839 strlcat(vtep_str
, "(", vtep_str_size
);
1840 strlcat(vtep_str
, vtep_flag_str
, vtep_str_size
);
1841 strlcat(vtep_str
, ")", vtep_str_size
);
1847 static void bgp_evpn_es_json_vtep_fill(json_object
*json_vteps
,
1848 struct bgp_evpn_es_vtep
*es_vtep
)
1850 json_object
*json_vtep_entry
;
1851 json_object
*json_flags
;
1852 char ip_buf
[INET6_ADDRSTRLEN
];
1854 json_vtep_entry
= json_object_new_object();
1856 json_object_string_add(
1857 json_vtep_entry
, "vtep_ip",
1858 inet_ntop(AF_INET
, &es_vtep
->vtep_ip
, ip_buf
, sizeof(ip_buf
)));
1859 if (es_vtep
->flags
& (BGP_EVPNES_VTEP_ESR
|
1860 BGP_EVPNES_VTEP_ACTIVE
)) {
1861 json_flags
= json_object_new_array();
1862 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1863 json_array_string_add(json_flags
, "esr");
1864 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
1865 json_array_string_add(json_flags
, "active");
1866 json_object_object_add(json_vtep_entry
, "flags", json_flags
);
1867 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
) {
1868 json_object_int_add(json_vtep_entry
, "dfPreference",
1870 json_object_int_add(json_vtep_entry
, "dfAlgorithm",
1875 json_object_array_add(json_vteps
,
1879 static void bgp_evpn_es_vteps_show_detail(struct vty
*vty
,
1880 struct bgp_evpn_es
*es
)
1882 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
1883 struct listnode
*node
;
1884 struct bgp_evpn_es_vtep
*es_vtep
;
1885 char alg_buf
[EVPN_DF_ALG_STR_LEN
];
1887 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1888 vtep_flag_str
[0] = '\0';
1889 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1890 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
1891 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ACTIVE
)
1892 strlcat(vtep_flag_str
, "A", sizeof(vtep_flag_str
));
1894 if (!strlen(vtep_flag_str
))
1895 strlcat(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
1897 vty_out(vty
, " %pI4 flags: %s", &es_vtep
->vtep_ip
,
1900 if (es_vtep
->flags
& BGP_EVPNES_VTEP_ESR
)
1901 vty_out(vty
, " df_alg: %s df_pref: %u\n",
1902 evpn_es_df_alg2str(es_vtep
->df_alg
, alg_buf
,
1910 static void bgp_evpn_es_show_entry(struct vty
*vty
,
1911 struct bgp_evpn_es
*es
, json_object
*json
)
1913 char buf1
[RD_ADDRSTRLEN
];
1914 struct listnode
*node
;
1915 struct bgp_evpn_es_vtep
*es_vtep
;
1918 json_object
*json_vteps
;
1919 json_object
*json_types
;
1921 json_object_string_add(json
, "esi", es
->esi_str
);
1922 json_object_string_add(json
, "rd",
1923 prefix_rd2str(&es
->prd
, buf1
,
1926 if (es
->flags
& (BGP_EVPNES_LOCAL
| BGP_EVPNES_REMOTE
)) {
1927 json_types
= json_object_new_array();
1928 if (es
->flags
& BGP_EVPNES_LOCAL
)
1929 json_array_string_add(json_types
, "local");
1930 if (es
->flags
& BGP_EVPNES_REMOTE
)
1931 json_array_string_add(json_types
, "remote");
1932 json_object_object_add(json
, "type", json_types
);
1935 if (listcount(es
->es_vtep_list
)) {
1936 json_vteps
= json_object_new_array();
1937 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
,
1939 bgp_evpn_es_json_vtep_fill(json_vteps
, es_vtep
);
1941 json_object_object_add(json
, "vteps", json_vteps
);
1943 json_object_int_add(json
, "vniCount",
1944 listcount(es
->es_evi_list
));
1947 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
1950 if (es
->flags
& BGP_EVPNES_LOCAL
)
1951 strlcat(type_str
, "L", sizeof(type_str
));
1952 if (es
->flags
& BGP_EVPNES_REMOTE
)
1953 strlcat(type_str
, "R", sizeof(type_str
));
1954 if (es
->inconsistencies
)
1955 strlcat(type_str
, "I", sizeof(type_str
));
1957 bgp_evpn_es_vteps_str(vtep_str
, es
, sizeof(vtep_str
));
1959 if (es
->flags
& BGP_EVPNES_LOCAL
)
1960 prefix_rd2str(&es
->prd
, buf1
, sizeof(buf1
));
1962 strlcpy(buf1
, "-", sizeof(buf1
));
1964 vty_out(vty
, "%-30s %-5s %-21s %-8d %s\n",
1965 es
->esi_str
, type_str
, buf1
,
1966 listcount(es
->es_evi_list
), vtep_str
);
1970 static void bgp_evpn_es_show_entry_detail(struct vty
*vty
,
1971 struct bgp_evpn_es
*es
, json_object
*json
)
1973 char ip_buf
[INET6_ADDRSTRLEN
];
1976 json_object
*json_flags
;
1977 json_object
*json_incons
;
1978 json_object
*json_vteps
;
1979 struct listnode
*node
;
1980 struct bgp_evpn_es_vtep
*es_vtep
;
1982 /* Add the "brief" info first */
1983 bgp_evpn_es_show_entry(vty
, es
, json
);
1984 if (es
->flags
& (BGP_EVPNES_OPER_UP
| BGP_EVPNES_ADV_EVI
)) {
1985 json_flags
= json_object_new_array();
1986 if (es
->flags
& BGP_EVPNES_OPER_UP
)
1987 json_array_string_add(json_flags
, "up");
1988 if (es
->flags
& BGP_EVPNES_ADV_EVI
)
1989 json_array_string_add(json_flags
,
1991 json_object_object_add(json
, "flags", json_flags
);
1993 json_object_string_add(json
, "originator_ip",
1994 inet_ntop(AF_INET
, &es
->originator_ip
,
1995 ip_buf
, sizeof(ip_buf
)));
1996 json_object_int_add(json
, "remoteVniCount",
1997 es
->remote_es_evi_cnt
);
1998 json_object_int_add(json
, "vrfCount",
1999 listcount(es
->es_vrf_list
));
2000 json_object_int_add(json
, "macipPathCount",
2001 listcount(es
->macip_path_list
));
2002 json_object_int_add(json
, "inconsistentVniVtepCount",
2003 es
->incons_evi_vtep_cnt
);
2004 if (listcount(es
->es_vtep_list
)) {
2005 json_vteps
= json_object_new_array();
2006 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
,
2008 bgp_evpn_es_json_vtep_fill(json_vteps
, es_vtep
);
2010 json_object_object_add(json
, "vteps", json_vteps
);
2012 if (es
->inconsistencies
) {
2013 json_incons
= json_object_new_array();
2014 if (es
->inconsistencies
& BGP_EVPNES_INCONS_VTEP_LIST
)
2015 json_array_string_add(json_incons
,
2016 "vni-vtep-mismatch");
2017 json_object_object_add(json
, "inconsistencies",
2021 char incons_str
[BGP_EVPNES_INCONS_STR_SZ
];
2023 char buf1
[RD_ADDRSTRLEN
];
2026 if (es
->flags
& BGP_EVPNES_LOCAL
)
2027 strlcat(type_str
, "L", sizeof(type_str
));
2028 if (es
->flags
& BGP_EVPNES_REMOTE
)
2029 strlcat(type_str
, "R", sizeof(type_str
));
2031 if (es
->flags
& BGP_EVPNES_LOCAL
)
2032 prefix_rd2str(&es
->prd
, buf1
, sizeof(buf1
));
2034 strlcpy(buf1
, "-", sizeof(buf1
));
2036 vty_out(vty
, "ESI: %s\n", es
->esi_str
);
2037 vty_out(vty
, " Type: %s\n", type_str
);
2038 vty_out(vty
, " RD: %s\n", buf1
);
2039 vty_out(vty
, " Originator-IP: %pI4\n", &es
->originator_ip
);
2040 if (es
->flags
& BGP_EVPNES_LOCAL
)
2041 vty_out(vty
, " Local ES DF preference: %u\n",
2043 vty_out(vty
, " VNI Count: %d\n", listcount(es
->es_evi_list
));
2044 vty_out(vty
, " Remote VNI Count: %d\n",
2045 es
->remote_es_evi_cnt
);
2046 vty_out(vty
, " VRF Count: %d\n", listcount(es
->es_vrf_list
));
2047 vty_out(vty
, " MACIP Path Count: %d\n",
2048 listcount(es
->macip_path_list
));
2049 vty_out(vty
, " Inconsistent VNI VTEP Count: %d\n",
2050 es
->incons_evi_vtep_cnt
);
2051 if (es
->inconsistencies
) {
2052 incons_str
[0] = '\0';
2053 if (es
->inconsistencies
& BGP_EVPNES_INCONS_VTEP_LIST
)
2054 strlcat(incons_str
, "vni-vtep-mismatch",
2055 sizeof(incons_str
));
2057 strlcpy(incons_str
, "-", sizeof(incons_str
));
2059 vty_out(vty
, " Inconsistencies: %s\n",
2061 if (listcount(es
->es_vtep_list
)) {
2062 vty_out(vty
, " VTEPs:\n");
2063 bgp_evpn_es_vteps_show_detail(vty
, es
);
2069 /* Display all ESs */
2070 void bgp_evpn_es_show(struct vty
*vty
, bool uj
, bool detail
)
2072 struct bgp_evpn_es
*es
;
2073 json_object
*json_array
= NULL
;
2074 json_object
*json
= NULL
;
2077 /* create an array of ESs */
2078 json_array
= json_object_new_array();
2082 "ES Flags: L local, R remote, I inconsistent\n");
2084 "VTEP Flags: E ESR/Type-4, A active nexthop\n");
2086 "%-30s %-5s %-21s %-8s %s\n",
2087 "ESI", "Flags", "RD", "#VNIs", "VTEPs");
2091 RB_FOREACH(es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
) {
2093 /* create a separate json object for each ES */
2094 json
= json_object_new_object();
2096 bgp_evpn_es_show_entry_detail(vty
, es
, json
);
2098 bgp_evpn_es_show_entry(vty
, es
, json
);
2099 /* add ES to the json array */
2101 json_object_array_add(json_array
, json
);
2104 /* print the array of json-ESs */
2106 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2107 json_array
, JSON_C_TO_STRING_PRETTY
));
2108 json_object_free(json_array
);
2112 /* Display specific ES */
2113 void bgp_evpn_es_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
)
2115 struct bgp_evpn_es
*es
;
2116 json_object
*json
= NULL
;
2119 json
= json_object_new_object();
2121 es
= bgp_evpn_es_find(esi
);
2123 bgp_evpn_es_show_entry_detail(vty
, es
, json
);
2126 vty_out(vty
, "ESI not found\n");
2130 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
2131 json
, JSON_C_TO_STRING_PRETTY
));
2132 json_object_free(json
);
2136 /*****************************************************************************/
2137 /* Ethernet Segment to VRF association -
2138 * 1. Each ES-EVI entry is associated with a tenant VRF. This associaton
2139 * triggers the creation of an ES-VRF entry.
2140 * 2. The ES-VRF entry is maintained for the purpose of L3-NHG creation
2141 * 3. Type-2/MAC-IP routes are imported into a tenant VRF and programmed as
2142 * a /32 or host route entry in the dataplane. If the destination of
2143 * the host route is a remote-ES the route is programmed with the
2144 * corresponding (keyed in by {vrf,ES-id}) L3-NHG.
2145 * 4. The reason for this indirection (route->L3-NHG, L3-NHG->list-of-VTEPs)
2146 * is to avoid route updates to the dplane when a remote-ES link flaps i.e.
2147 * instead of updating all the dependent routes the NHG's contents are updated.
2148 * This reduces the amount of datplane updates (nhg updates vs. route updates)
2149 * allowing for a faster failover.
2151 * XXX - can the L3 SVI index change without change in vpn->bgp_vrf
2152 * association? If yes we need to handle that by updating all the L3 NHGs
2155 /******************************** L3 NHG management *************************/
2156 static void bgp_evpn_l3nhg_zebra_add_v4_or_v6(struct bgp_evpn_es_vrf
*es_vrf
,
2159 uint32_t nhg_id
= v4_nhg
? es_vrf
->nhg_id
: es_vrf
->v6_nhg_id
;
2160 struct bgp_evpn_es
*es
= es_vrf
->es
;
2161 struct listnode
*node
;
2162 struct bgp_evpn_es_vtep
*es_vtep
;
2164 struct zapi_nexthop
*api_nh
;
2165 struct zapi_nhg api_nhg
= {};
2167 /* Skip installation of L3-NHG if host routes used */
2171 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2172 zlog_debug("es %s vrf %u %s nhg %u to zebra", es
->esi_str
,
2173 es_vrf
->bgp_vrf
->vrf_id
,
2174 v4_nhg
? "v4_nhg" : "v6_nhg", nhg_id
);
2176 /* only the gateway ip changes for each NH. rest of the params
2179 memset(&nh
, 0, sizeof(nh
));
2180 nh
.vrf_id
= es_vrf
->bgp_vrf
->vrf_id
;
2181 nh
.flags
= NEXTHOP_FLAG_ONLINK
;
2182 nh
.ifindex
= es_vrf
->bgp_vrf
->l3vni_svi_ifindex
;
2185 v4_nhg
? NEXTHOP_TYPE_IPV4_IFINDEX
: NEXTHOP_TYPE_IPV6_IFINDEX
;
2187 api_nhg
.id
= nhg_id
;
2188 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
2189 if (!CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
2192 /* overwrite the gw */
2194 nh
.gate
.ipv4
= es_vtep
->vtep_ip
;
2196 ipv4_to_ipv4_mapped_ipv6(&nh
.gate
.ipv6
,
2199 /* convert to zapi format */
2200 api_nh
= &api_nhg
.nexthops
[api_nhg
.nexthop_num
];
2201 zapi_nexthop_from_nexthop(api_nh
, &nh
);
2203 ++api_nhg
.nexthop_num
;
2204 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2205 zlog_debug("nhg %u vtep %pI4 l3-svi %d", api_nhg
.id
,
2207 es_vrf
->bgp_vrf
->l3vni_svi_ifindex
);
2210 if (!api_nhg
.nexthop_num
)
2213 if (api_nhg
.nexthop_num
> MULTIPATH_NUM
)
2216 zclient_nhg_send(zclient
, ZEBRA_NHG_ADD
, &api_nhg
);
2219 static bool bgp_evpn_l3nhg_zebra_ok(struct bgp_evpn_es_vrf
*es_vrf
)
2221 if (!bgp_mh_info
->host_routes_use_l3nhg
&& !bgp_mh_info
->install_l3nhg
)
2225 if (!zclient
|| zclient
->sock
< 0)
2231 static void bgp_evpn_l3nhg_zebra_add(struct bgp_evpn_es_vrf
*es_vrf
)
2233 if (!bgp_evpn_l3nhg_zebra_ok(es_vrf
))
2236 bgp_evpn_l3nhg_zebra_add_v4_or_v6(es_vrf
, true /*v4_nhg*/);
2237 bgp_evpn_l3nhg_zebra_add_v4_or_v6(es_vrf
, false /*v4_nhg*/);
2240 static void bgp_evpn_l3nhg_zebra_del_v4_or_v6(struct bgp_evpn_es_vrf
*es_vrf
,
2243 struct zapi_nhg api_nhg
= {};
2245 api_nhg
.id
= v4_nhg
? es_vrf
->nhg_id
: es_vrf
->v6_nhg_id
;
2247 /* Skip installation of L3-NHG if host routes used */
2251 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2252 zlog_debug("es %s vrf %u %s nhg %u to zebra",
2253 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2254 v4_nhg
? "v4_nhg" : "v6_nhg", api_nhg
.id
);
2256 zclient_nhg_send(zclient
, ZEBRA_NHG_DEL
, &api_nhg
);
2259 static void bgp_evpn_l3nhg_zebra_del(struct bgp_evpn_es_vrf
*es_vrf
)
2261 if (!bgp_evpn_l3nhg_zebra_ok(es_vrf
))
2264 bgp_evpn_l3nhg_zebra_del_v4_or_v6(es_vrf
, true /*v4_nhg*/);
2265 bgp_evpn_l3nhg_zebra_del_v4_or_v6(es_vrf
, false /*v4_nhg*/);
2268 static void bgp_evpn_l3nhg_deactivate(struct bgp_evpn_es_vrf
*es_vrf
)
2270 if (!(es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
))
2273 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2274 zlog_debug("es %s vrf %u nhg %u de-activate",
2275 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2277 bgp_evpn_l3nhg_zebra_del(es_vrf
);
2278 es_vrf
->flags
&= ~BGP_EVPNES_VRF_NHG_ACTIVE
;
2281 static void bgp_evpn_l3nhg_activate(struct bgp_evpn_es_vrf
*es_vrf
, bool update
)
2283 if (!bgp_evpn_es_get_active_vtep_cnt(es_vrf
->es
)) {
2284 bgp_evpn_l3nhg_deactivate(es_vrf
);
2288 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
) {
2292 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2293 zlog_debug("es %s vrf %u nhg %u activate",
2294 es_vrf
->es
->esi_str
, es_vrf
->bgp_vrf
->vrf_id
,
2296 es_vrf
->flags
|= BGP_EVPNES_VRF_NHG_ACTIVE
;
2299 bgp_evpn_l3nhg_zebra_add(es_vrf
);
2302 /* when a VTEP is activated or de-activated against an ES associated
2303 * VRFs' NHG needs to be updated
2305 static void bgp_evpn_l3nhg_update_on_vtep_chg(struct bgp_evpn_es
*es
)
2307 struct bgp_evpn_es_vrf
*es_vrf
;
2308 struct listnode
*es_vrf_node
;
2310 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2311 zlog_debug("es %s nhg update on vtep chg", es
->esi_str
);
2313 for (ALL_LIST_ELEMENTS_RO(es
->es_vrf_list
, es_vrf_node
, es_vrf
))
2314 bgp_evpn_l3nhg_activate(es_vrf
, true /* update */);
2317 /* compare ES-IDs for the ES-VRF RB tree maintained per-VRF */
2318 static int bgp_es_vrf_rb_cmp(const struct bgp_evpn_es_vrf
*es_vrf1
,
2319 const struct bgp_evpn_es_vrf
*es_vrf2
)
2321 return memcmp(&es_vrf1
->es
->esi
, &es_vrf2
->es
->esi
, ESI_BYTES
);
2323 RB_GENERATE(bgp_es_vrf_rb_head
, bgp_evpn_es_vrf
, rb_node
, bgp_es_vrf_rb_cmp
);
2325 /* Initialize the ES tables maintained per-tenant vrf */
2326 void bgp_evpn_vrf_es_init(struct bgp
*bgp_vrf
)
2328 /* Initialize the ES-VRF RB tree */
2329 RB_INIT(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
);
2332 /* find the ES-VRF in the per-VRF RB tree */
2333 static struct bgp_evpn_es_vrf
*bgp_evpn_es_vrf_find(struct bgp_evpn_es
*es
,
2334 struct bgp
*bgp_vrf
)
2336 struct bgp_evpn_es_vrf es_vrf
;
2340 return RB_FIND(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, &es_vrf
);
2343 /* allocate a new ES-VRF and setup L3NHG for it */
2344 static struct bgp_evpn_es_vrf
*bgp_evpn_es_vrf_create(struct bgp_evpn_es
*es
,
2345 struct bgp
*bgp_vrf
)
2347 struct bgp_evpn_es_vrf
*es_vrf
;
2349 es_vrf
= XCALLOC(MTYPE_BGP_EVPN_ES_VRF
, sizeof(*es_vrf
));
2352 es_vrf
->bgp_vrf
= bgp_vrf
;
2354 /* insert into the VRF-ESI rb tree */
2355 if (RB_INSERT(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, es_vrf
)) {
2356 XFREE(MTYPE_BGP_EVPN_ES_VRF
, es_vrf
);
2360 /* add to the ES's VRF list */
2361 listnode_init(&es_vrf
->es_listnode
, es_vrf
);
2362 listnode_add(es
->es_vrf_list
, &es_vrf
->es_listnode
);
2364 /* setup the L3 NHG id for the ES */
2365 es_vrf
->nhg_id
= bgp_l3nhg_id_alloc();
2366 es_vrf
->v6_nhg_id
= bgp_l3nhg_id_alloc();
2368 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2369 zlog_debug("es %s vrf %u nhg %u v6_nhg %d create", es
->esi_str
,
2370 bgp_vrf
->vrf_id
, es_vrf
->nhg_id
, es_vrf
->v6_nhg_id
);
2371 bgp_evpn_l3nhg_activate(es_vrf
, false /* update */);
2376 /* remove the L3-NHG associated with the ES-VRF and free it */
2377 static void bgp_evpn_es_vrf_delete(struct bgp_evpn_es_vrf
*es_vrf
)
2379 struct bgp_evpn_es
*es
= es_vrf
->es
;
2380 struct bgp
*bgp_vrf
= es_vrf
->bgp_vrf
;
2382 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2383 zlog_debug("es %s vrf %u nhg %u delete", es
->esi_str
,
2384 bgp_vrf
->vrf_id
, es_vrf
->nhg_id
);
2386 /* Remove the NHG resources */
2387 bgp_evpn_l3nhg_deactivate(es_vrf
);
2389 bgp_l3nhg_id_free(es_vrf
->nhg_id
);
2391 if (es_vrf
->v6_nhg_id
)
2392 bgp_l3nhg_id_free(es_vrf
->v6_nhg_id
);
2393 es_vrf
->v6_nhg_id
= 0;
2395 /* remove from the ES's VRF list */
2396 list_delete_node(es
->es_vrf_list
, &es_vrf
->es_listnode
);
2398 /* remove from the VRF-ESI rb tree */
2399 RB_REMOVE(bgp_es_vrf_rb_head
, &bgp_vrf
->es_vrf_rb_tree
, es_vrf
);
2401 XFREE(MTYPE_BGP_EVPN_ES_VRF
, es_vrf
);
2404 /* deref and delete if there are no references */
2405 void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi
*es_evi
)
2407 struct bgp_evpn_es_vrf
*es_vrf
= es_evi
->es_vrf
;
2412 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2413 zlog_debug("es-evi %s vni %u vrf %u de-ref",
2414 es_evi
->es
->esi_str
, es_evi
->vpn
->vni
,
2415 es_vrf
->bgp_vrf
->vrf_id
);
2417 es_evi
->es_vrf
= NULL
;
2418 if (es_vrf
->ref_cnt
)
2421 if (!es_vrf
->ref_cnt
)
2422 bgp_evpn_es_vrf_delete(es_vrf
);
2425 /* find or create and reference */
2426 void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi
*es_evi
, struct bgp
*bgp_vrf
)
2428 struct bgp_evpn_es
*es
= es_evi
->es
;
2429 struct bgp_evpn_es_vrf
*es_vrf
= es_evi
->es_vrf
;
2430 struct bgp
*old_bgp_vrf
= NULL
;
2433 old_bgp_vrf
= es_vrf
->bgp_vrf
;
2435 if (old_bgp_vrf
== bgp_vrf
)
2438 /* deref the old ES-VRF */
2439 bgp_evpn_es_vrf_deref(es_evi
);
2444 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2445 zlog_debug("es-evi %s vni %u vrf %u ref", es_evi
->es
->esi_str
,
2446 es_evi
->vpn
->vni
, bgp_vrf
->vrf_id
);
2448 /* find-create the new ES-VRF */
2449 es_vrf
= bgp_evpn_es_vrf_find(es
, bgp_vrf
);
2451 es_vrf
= bgp_evpn_es_vrf_create(es
, bgp_vrf
);
2455 es_evi
->es_vrf
= es_vrf
;
2459 /* When the L2-VNI is associated with a L3-VNI/VRF update all the
2460 * associated ES-EVI entries
2462 void bgp_evpn_es_evi_vrf_deref(struct bgpevpn
*vpn
)
2464 struct bgp_evpn_es_evi
*es_evi
;
2466 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2467 zlog_debug("es-vrf de-ref for vni %u", vpn
->vni
);
2469 RB_FOREACH (es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
)
2470 bgp_evpn_es_vrf_deref(es_evi
);
2472 void bgp_evpn_es_evi_vrf_ref(struct bgpevpn
*vpn
)
2474 struct bgp_evpn_es_evi
*es_evi
;
2476 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2477 zlog_debug("es-vrf ref for vni %u", vpn
->vni
);
2479 RB_FOREACH (es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
)
2480 bgp_evpn_es_vrf_ref(es_evi
, vpn
->bgp_vrf
);
2483 /* returns false if legacy-exploded mp needs to be used for route install */
2484 bool bgp_evpn_path_es_use_nhg(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
,
2488 struct bgp_evpn_es
*es
;
2489 struct bgp_evpn_es_vrf
*es_vrf
;
2490 struct bgp_path_info
*parent_pi
;
2491 struct bgp_node
*rn
;
2492 struct prefix_evpn
*evp
;
2493 struct bgp_path_info
*mpinfo
;
2497 /* L3NHG support is disabled, use legacy-exploded multipath */
2498 if (!bgp_mh_info
->host_routes_use_l3nhg
)
2501 parent_pi
= get_route_parent_evpn(pi
);
2505 rn
= parent_pi
->net
;
2509 evp
= (struct prefix_evpn
*)&rn
->p
;
2510 if (evp
->prefix
.route_type
!= BGP_EVPN_MAC_IP_ROUTE
)
2513 /* non-es path, use legacy-exploded multipath */
2514 esi
= bgp_evpn_attr_get_esi(parent_pi
->attr
);
2515 if (!memcmp(esi
, zero_esi
, sizeof(*esi
)))
2518 /* if the ES-VRF is not setup or if the NHG has not been installed
2519 * we cannot install the route yet, return a 0-NHG to indicate
2522 es
= bgp_evpn_es_find(esi
);
2525 es_vrf
= bgp_evpn_es_vrf_find(es
, bgp_vrf
);
2526 if (!es_vrf
|| !(es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
))
2529 /* this needs to be set the v6NHG if v6route */
2530 if (is_evpn_prefix_ipaddr_v6(evp
))
2531 *nhg_p
= es_vrf
->v6_nhg_id
;
2533 *nhg_p
= es_vrf
->nhg_id
;
2535 for (mpinfo
= bgp_path_info_mpath_next(pi
); mpinfo
;
2536 mpinfo
= bgp_path_info_mpath_next(mpinfo
)) {
2537 /* if any of the paths of have a different ESI we can't use
2538 * the NHG associated with the ES. fallback to legacy-exploded
2541 if (memcmp(esi
, bgp_evpn_attr_get_esi(mpinfo
->attr
),
2549 static void bgp_evpn_es_vrf_show_entry(struct vty
*vty
,
2550 struct bgp_evpn_es_vrf
*es_vrf
,
2553 struct bgp_evpn_es
*es
= es_vrf
->es
;
2554 struct bgp
*bgp_vrf
= es_vrf
->bgp_vrf
;
2557 json_object
*json_types
;
2559 json_object_string_add(json
, "esi", es
->esi_str
);
2560 json_object_string_add(json
, "vrf", bgp_vrf
->name
);
2562 if (es_vrf
->flags
& (BGP_EVPNES_VRF_NHG_ACTIVE
)) {
2563 json_types
= json_object_new_array();
2564 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
)
2565 json_array_string_add(json_types
, "active");
2566 json_object_object_add(json
, "flags", json_types
);
2569 json_object_int_add(json
, "ipv4NHG", es_vrf
->nhg_id
);
2570 json_object_int_add(json
, "ipv6NHG", es_vrf
->v6_nhg_id
);
2571 json_object_int_add(json
, "refCount", es_vrf
->ref_cnt
);
2575 flags_str
[0] = '\0';
2576 if (es_vrf
->flags
& BGP_EVPNES_VRF_NHG_ACTIVE
)
2577 strlcat(flags_str
, "A", sizeof(flags_str
));
2579 vty_out(vty
, "%-30s %-15s %-5s %-8u %-8u %u\n", es
->esi_str
,
2580 bgp_vrf
->name
, flags_str
, es_vrf
->nhg_id
,
2581 es_vrf
->v6_nhg_id
, es_vrf
->ref_cnt
);
2585 static void bgp_evpn_es_vrf_show_es(struct vty
*vty
, json_object
*json_array
,
2586 struct bgp_evpn_es
*es
)
2588 json_object
*json
= NULL
;
2589 struct listnode
*es_vrf_node
;
2590 struct bgp_evpn_es_vrf
*es_vrf
;
2592 for (ALL_LIST_ELEMENTS_RO(es
->es_vrf_list
, es_vrf_node
, es_vrf
)) {
2593 /* create a separate json object for each ES-VRF */
2595 json
= json_object_new_object();
2596 bgp_evpn_es_vrf_show_entry(vty
, es_vrf
, json
);
2597 /* add ES-VRF to the json array */
2599 json_object_array_add(json_array
, json
);
2603 /* Display all ES VRFs */
2604 void bgp_evpn_es_vrf_show(struct vty
*vty
, bool uj
, struct bgp_evpn_es
*es
)
2606 json_object
*json_array
= NULL
;
2609 /* create an array of ESs */
2610 json_array
= json_object_new_array();
2612 vty_out(vty
, "ES-VRF Flags: A Active\n");
2613 vty_out(vty
, "%-30s %-15s %-5s %-8s %-8s %s\n", "ESI", "VRF",
2614 "Flags", "IPv4-NHG", "IPv6-NHG", "Ref");
2618 bgp_evpn_es_vrf_show_es(vty
, json_array
, es
);
2620 RB_FOREACH (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
)
2621 bgp_evpn_es_vrf_show_es(vty
, json_array
, es
);
2624 /* print the array of json-ESs */
2626 vty_out(vty
, "%s\n",
2627 json_object_to_json_string_ext(
2628 json_array
, JSON_C_TO_STRING_PRETTY
));
2629 json_object_free(json_array
);
2633 /* Display specific ES VRF */
2634 void bgp_evpn_es_vrf_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
)
2636 struct bgp_evpn_es
*es
;
2638 es
= bgp_evpn_es_find(esi
);
2640 bgp_evpn_es_vrf_show(vty
, uj
, es
);
2643 vty_out(vty
, "ESI not found\n");
2647 /*****************************************************************************/
2648 /* Ethernet Segment to EVI association -
2649 * 1. The ES-EVI entry is maintained as a RB tree per L2-VNI
2650 * (bgpevpn->es_evi_rb_tree).
2651 * 2. Each local ES-EVI entry is rxed from zebra and then used by BGP to
2652 * advertises an EAD-EVI (Type-1 EVPN) route
2653 * 3. The remote ES-EVI is created when a bgp_evpn_es_evi_vtep references
2657 /* A list of remote VTEPs is maintained for each ES-EVI. This list includes -
2658 * 1. VTEPs for which we have imported the EAD-per-ES Type1 route
2659 * 2. VTEPs for which we have imported the EAD-per-EVI Type1 route
2660 * VTEPs for which both routes have been rxed are activated. Activation
2661 * creates a NHG in the parent ES.
2663 static int bgp_evpn_es_evi_vtep_cmp(void *p1
, void *p2
)
2665 const struct bgp_evpn_es_evi_vtep
*evi_vtep1
= p1
;
2666 const struct bgp_evpn_es_evi_vtep
*evi_vtep2
= p2
;
2668 return evi_vtep1
->vtep_ip
.s_addr
- evi_vtep2
->vtep_ip
.s_addr
;
2671 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_vtep_new(
2672 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
)
2674 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
2676 evi_vtep
= XCALLOC(MTYPE_BGP_EVPN_ES_EVI_VTEP
, sizeof(*evi_vtep
));
2678 evi_vtep
->es_evi
= es_evi
;
2679 evi_vtep
->vtep_ip
.s_addr
= vtep_ip
.s_addr
;
2680 listnode_init(&evi_vtep
->es_evi_listnode
, evi_vtep
);
2681 listnode_add_sort(es_evi
->es_evi_vtep_list
, &evi_vtep
->es_evi_listnode
);
2686 static void bgp_evpn_es_evi_vtep_free(struct bgp_evpn_es_evi_vtep
*evi_vtep
)
2688 struct bgp_evpn_es_evi
*es_evi
= evi_vtep
->es_evi
;
2690 if (evi_vtep
->flags
& (BGP_EVPN_EVI_VTEP_EAD
))
2691 /* as long as there is some reference we can't free it */
2694 list_delete_node(es_evi
->es_evi_vtep_list
, &evi_vtep
->es_evi_listnode
);
2695 XFREE(MTYPE_BGP_EVPN_ES_EVI_VTEP
, evi_vtep
);
2698 /* check if VTEP is already part of the list */
2699 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_vtep_find(
2700 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
)
2702 struct listnode
*node
= NULL
;
2703 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
2705 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
2706 if (evi_vtep
->vtep_ip
.s_addr
== vtep_ip
.s_addr
)
2712 /* A VTEP can be added as "active" attach to an ES if EAD-per-ES and
2713 * EAD-per-EVI routes are rxed from it.
2715 static void bgp_evpn_es_evi_vtep_re_eval_active(struct bgp
*bgp
,
2716 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
2721 old_active
= !!CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
2723 /* Both EAD-per-ES and EAD-per-EVI routes must be rxed from a PE
2724 * before it can be activated.
2726 if ((evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD
) ==
2727 BGP_EVPN_EVI_VTEP_EAD
)
2728 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
2730 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
2732 new_active
= !!CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
);
2734 if (old_active
== new_active
)
2737 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2738 zlog_debug("es %s evi %u vtep %pI4 %s",
2739 evi_vtep
->es_evi
->es
->esi_str
,
2740 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
2741 new_active
? "active" : "inactive");
2743 /* add VTEP to parent es */
2745 struct bgp_evpn_es_vtep
*es_vtep
;
2747 es_vtep
= bgp_evpn_es_vtep_add(bgp
, evi_vtep
->es_evi
->es
,
2748 evi_vtep
->vtep_ip
, false /*esr*/,
2750 evi_vtep
->es_vtep
= es_vtep
;
2752 if (evi_vtep
->es_vtep
) {
2753 bgp_evpn_es_vtep_do_del(bgp
, evi_vtep
->es_vtep
,
2755 evi_vtep
->es_vtep
= NULL
;
2758 /* queue up the parent es for background consistency checks */
2759 bgp_evpn_es_cons_checks_pend_add(evi_vtep
->es_evi
->es
);
2762 static void bgp_evpn_es_evi_vtep_add(struct bgp
*bgp
,
2763 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
,
2766 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
2768 evi_vtep
= bgp_evpn_es_evi_vtep_find(es_evi
, vtep_ip
);
2771 evi_vtep
= bgp_evpn_es_evi_vtep_new(es_evi
, vtep_ip
);
2773 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2774 zlog_debug("add es %s evi %u vtep %pI4 %s",
2775 evi_vtep
->es_evi
->es
->esi_str
,
2776 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
2777 ead_es
? "ead_es" : "ead_evi");
2780 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_ES
);
2782 SET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_EVI
);
2784 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, evi_vtep
);
2787 static void bgp_evpn_es_evi_vtep_del(struct bgp
*bgp
,
2788 struct bgp_evpn_es_evi
*es_evi
, struct in_addr vtep_ip
,
2791 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
2793 evi_vtep
= bgp_evpn_es_evi_vtep_find(es_evi
, vtep_ip
);
2797 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2798 zlog_debug("del es %s evi %u vtep %pI4 %s",
2799 evi_vtep
->es_evi
->es
->esi_str
,
2800 evi_vtep
->es_evi
->vpn
->vni
, &evi_vtep
->vtep_ip
,
2801 ead_es
? "ead_es" : "ead_evi");
2804 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_ES
);
2806 UNSET_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_EAD_PER_EVI
);
2808 bgp_evpn_es_evi_vtep_re_eval_active(bgp
, evi_vtep
);
2809 bgp_evpn_es_evi_vtep_free(evi_vtep
);
2812 /* compare ES-IDs for the ES-EVI RB tree maintained per-VNI */
2813 static int bgp_es_evi_rb_cmp(const struct bgp_evpn_es_evi
*es_evi1
,
2814 const struct bgp_evpn_es_evi
*es_evi2
)
2816 return memcmp(&es_evi1
->es
->esi
, &es_evi2
->es
->esi
, ESI_BYTES
);
2818 RB_GENERATE(bgp_es_evi_rb_head
, bgp_evpn_es_evi
, rb_node
, bgp_es_evi_rb_cmp
);
2820 /* find the ES-EVI in the per-L2-VNI RB tree */
2821 static struct bgp_evpn_es_evi
*bgp_evpn_es_evi_find(struct bgp_evpn_es
*es
,
2822 struct bgpevpn
*vpn
)
2824 struct bgp_evpn_es_evi es_evi
;
2828 return RB_FIND(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, &es_evi
);
2831 /* allocate a new ES-EVI and insert it into the per-L2-VNI and per-ES
2834 static struct bgp_evpn_es_evi
*bgp_evpn_es_evi_new(struct bgp_evpn_es
*es
,
2835 struct bgpevpn
*vpn
)
2837 struct bgp_evpn_es_evi
*es_evi
;
2839 es_evi
= XCALLOC(MTYPE_BGP_EVPN_ES_EVI
, sizeof(*es_evi
));
2844 /* Initialise the VTEP list */
2845 es_evi
->es_evi_vtep_list
= list_new();
2846 listset_app_node_mem(es_evi
->es_evi_vtep_list
);
2847 es_evi
->es_evi_vtep_list
->cmp
= bgp_evpn_es_evi_vtep_cmp
;
2849 /* insert into the VNI-ESI rb tree */
2850 if (RB_INSERT(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, es_evi
)) {
2851 XFREE(MTYPE_BGP_EVPN_ES_EVI
, es_evi
);
2855 /* add to the ES's VNI list */
2856 listnode_init(&es_evi
->es_listnode
, es_evi
);
2857 listnode_add(es
->es_evi_list
, &es_evi
->es_listnode
);
2859 bgp_evpn_es_vrf_ref(es_evi
, vpn
->bgp_vrf
);
2864 /* remove the ES-EVI from the per-L2-VNI and per-ES tables and free
2867 static void bgp_evpn_es_evi_free(struct bgp_evpn_es_evi
*es_evi
)
2869 struct bgp_evpn_es
*es
= es_evi
->es
;
2870 struct bgpevpn
*vpn
= es_evi
->vpn
;
2872 /* cannot free the element as long as there is a local or remote
2875 if (es_evi
->flags
& (BGP_EVPNES_EVI_LOCAL
| BGP_EVPNES_EVI_REMOTE
))
2878 bgp_evpn_es_vrf_deref(es_evi
);
2880 /* remove from the ES's VNI list */
2881 list_delete_node(es
->es_evi_list
, &es_evi
->es_listnode
);
2883 /* remove from the VNI-ESI rb tree */
2884 RB_REMOVE(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
, es_evi
);
2886 /* free the VTEP list */
2887 list_delete(&es_evi
->es_evi_vtep_list
);
2889 /* remove from the VNI-ESI rb tree */
2890 XFREE(MTYPE_BGP_EVPN_ES_EVI
, es_evi
);
2893 /* init local info associated with the ES-EVI */
2894 static void bgp_evpn_es_evi_local_info_set(struct bgp_evpn_es_evi
*es_evi
)
2896 struct bgpevpn
*vpn
= es_evi
->vpn
;
2898 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
2901 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
);
2902 listnode_init(&es_evi
->l2vni_listnode
, es_evi
);
2903 listnode_add(vpn
->local_es_evi_list
, &es_evi
->l2vni_listnode
);
2906 /* clear any local info associated with the ES-EVI */
2907 static void bgp_evpn_es_evi_local_info_clear(struct bgp_evpn_es_evi
*es_evi
)
2909 struct bgpevpn
*vpn
= es_evi
->vpn
;
2911 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
2914 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
);
2915 list_delete_node(vpn
->local_es_evi_list
, &es_evi
->l2vni_listnode
);
2917 bgp_evpn_es_evi_free(es_evi
);
2920 /* eval remote info associated with the ES */
2921 static void bgp_evpn_es_evi_remote_info_re_eval(struct bgp_evpn_es_evi
*es_evi
)
2923 struct bgp_evpn_es
*es
= es_evi
->es
;
2925 /* if there are remote VTEPs the ES-EVI is classified as "remote" */
2926 if (listcount(es_evi
->es_evi_vtep_list
)) {
2927 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
)) {
2928 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
);
2929 ++es
->remote_es_evi_cnt
;
2930 /* set remote on the parent es */
2931 bgp_evpn_es_remote_info_re_eval(es
);
2934 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
)) {
2935 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_REMOTE
);
2936 if (es
->remote_es_evi_cnt
)
2937 --es
->remote_es_evi_cnt
;
2938 bgp_evpn_es_evi_free(es_evi
);
2939 /* check if "remote" can be cleared from the
2942 bgp_evpn_es_remote_info_re_eval(es
);
2947 static void bgp_evpn_local_es_evi_do_del(struct bgp_evpn_es_evi
*es_evi
)
2949 struct prefix_evpn p
;
2950 struct bgp_evpn_es
*es
= es_evi
->es
;
2953 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
2956 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
2957 zlog_debug("del local es %s evi %u",
2958 es_evi
->es
->esi_str
,
2961 bgp
= bgp_get_evpn();
2964 /* update EAD-ES with new list of VNIs */
2965 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
)) {
2966 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
,
2967 &es
->esi
, es
->originator_ip
);
2968 if (bgp_evpn_type1_route_update(bgp
, es
, NULL
, &p
))
2969 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
2970 "%u: EAD-ES route update failure for ESI %s VNI %u",
2971 bgp
->vrf_id
, es
->esi_str
,
2975 /* withdraw and delete EAD-EVI */
2976 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
)) {
2977 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
2978 &es
->esi
, es
->originator_ip
);
2979 if (bgp_evpn_type1_evi_route_delete(bgp
,
2980 es
, es_evi
->vpn
, &p
))
2981 flog_err(EC_BGP_EVPN_ROUTE_DELETE
,
2982 "%u: EAD-EVI route deletion failure for ESI %s VNI %u",
2983 bgp
->vrf_id
, es
->esi_str
,
2988 bgp_evpn_es_evi_local_info_clear(es_evi
);
2992 int bgp_evpn_local_es_evi_del(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
)
2994 struct bgpevpn
*vpn
;
2995 struct bgp_evpn_es
*es
;
2996 struct bgp_evpn_es_evi
*es_evi
;
2997 char buf
[ESI_STR_LEN
];
2999 es
= bgp_evpn_es_find(esi
);
3003 "%u: Failed to deref VNI %d from ESI %s; ES not present",
3005 esi_to_str(esi
, buf
, sizeof(buf
)));
3009 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3013 "%u: Failed to deref VNI %d from ESI %s; VNI not present",
3014 bgp
->vrf_id
, vni
, es
->esi_str
);
3018 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3022 "%u: Failed to deref VNI %d from ESI %s; ES-VNI not present",
3023 bgp
->vrf_id
, vni
, es
->esi_str
);
3027 bgp_evpn_local_es_evi_do_del(es_evi
);
3031 /* Create ES-EVI and advertise the corresponding EAD routes */
3032 int bgp_evpn_local_es_evi_add(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
)
3034 struct bgpevpn
*vpn
;
3035 struct prefix_evpn p
;
3036 struct bgp_evpn_es
*es
;
3037 struct bgp_evpn_es_evi
*es_evi
;
3038 char buf
[ESI_STR_LEN
];
3040 es
= bgp_evpn_es_find(esi
);
3044 "%u: Failed to associate VNI %d with ESI %s; ES not present",
3046 esi_to_str(esi
, buf
, sizeof(buf
)));
3050 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3054 "%u: Failed to associate VNI %d with ESI %s; VNI not present",
3055 bgp
->vrf_id
, vni
, es
->esi_str
);
3059 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3060 zlog_debug("add local es %s evi %u",
3063 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3066 if (CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_LOCAL
))
3070 es_evi
= bgp_evpn_es_evi_new(es
, vpn
);
3075 bgp_evpn_es_evi_local_info_set(es_evi
);
3077 /* generate an EAD-EVI for this new VNI */
3078 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_EVI_ETH_TAG
,
3079 &es
->esi
, es
->originator_ip
);
3080 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_ADV_EVI
)) {
3081 if (bgp_evpn_type1_route_update(bgp
, es
, vpn
, &p
))
3082 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
3083 "%u: EAD-EVI route creation failure for ESI %s VNI %u",
3084 bgp
->vrf_id
, es
->esi_str
, vni
);
3088 build_evpn_type1_prefix(&p
, BGP_EVPN_AD_ES_ETH_TAG
,
3089 &es
->esi
, es
->originator_ip
);
3090 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_OPER_UP
)) {
3091 if (bgp_evpn_type1_route_update(bgp
, es
, NULL
, &p
))
3092 flog_err(EC_BGP_EVPN_ROUTE_CREATE
,
3093 "%u: EAD-ES route creation failure for ESI %s VNI %u",
3094 bgp
->vrf_id
, es
->esi_str
, vni
);
3100 /* Add remote ES-EVI entry. This is actually the remote VTEP add and the
3101 * ES-EVI is implicity created on first VTEP's reference.
3103 int bgp_evpn_remote_es_evi_add(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3104 const struct prefix_evpn
*p
)
3106 char buf
[ESI_STR_LEN
];
3107 struct bgp_evpn_es
*es
;
3108 struct bgp_evpn_es_evi
*es_evi
;
3110 const esi_t
*esi
= &p
->prefix
.ead_addr
.esi
;
3113 /* local EAD-ES need not be sent back to zebra */
3116 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3117 zlog_debug("add remote %s es %s evi %u vtep %pI4",
3118 p
->prefix
.ead_addr
.eth_tag
? "ead-es" : "ead-evi",
3119 esi_to_str(esi
, buf
, sizeof(buf
)), vpn
->vni
,
3120 &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3122 es
= bgp_evpn_es_find(esi
);
3124 es
= bgp_evpn_es_new(bgp
, esi
);
3126 flog_err(EC_BGP_ES_CREATE
,
3127 "%u: Failed to allocate ES entry for ESI %s - at remote ES Add",
3128 bgp
->vrf_id
, esi_to_str(esi
, buf
, sizeof(buf
)));
3133 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3135 es_evi
= bgp_evpn_es_evi_new(es
, vpn
);
3137 bgp_evpn_es_free(es
, __func__
);
3142 ead_es
= !!p
->prefix
.ead_addr
.eth_tag
;
3143 bgp_evpn_es_evi_vtep_add(bgp
, es_evi
, p
->prefix
.ead_addr
.ip
.ipaddr_v4
,
3146 bgp_evpn_es_evi_remote_info_re_eval(es_evi
);
3150 /* A remote VTEP has withdrawn. The es-evi-vtep will be deleted and the
3151 * parent es-evi freed up implicitly in last VTEP's deref.
3153 int bgp_evpn_remote_es_evi_del(struct bgp
*bgp
, struct bgpevpn
*vpn
,
3154 const struct prefix_evpn
*p
)
3156 char buf
[ESI_STR_LEN
];
3157 struct bgp_evpn_es
*es
;
3158 struct bgp_evpn_es_evi
*es_evi
;
3162 /* local EAD-ES need not be sent back to zebra */
3165 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3167 "del remote %s es %s evi %u vtep %pI4",
3168 p
->prefix
.ead_addr
.eth_tag
? "ead-es" : "ead-evi",
3169 esi_to_str(&p
->prefix
.ead_addr
.esi
, buf
, sizeof(buf
)),
3170 vpn
->vni
, &p
->prefix
.ead_addr
.ip
.ipaddr_v4
);
3172 es
= bgp_evpn_es_find(&p
->prefix
.ead_addr
.esi
);
3174 /* XXX - error logs */
3176 es_evi
= bgp_evpn_es_evi_find(es
, vpn
);
3178 /* XXX - error logs */
3181 ead_es
= !!p
->prefix
.ead_addr
.eth_tag
;
3182 bgp_evpn_es_evi_vtep_del(bgp
, es_evi
, p
->prefix
.ead_addr
.ip
.ipaddr_v4
,
3184 bgp_evpn_es_evi_remote_info_re_eval(es_evi
);
3188 /* Initialize the ES tables maintained per-L2_VNI */
3189 void bgp_evpn_vni_es_init(struct bgpevpn
*vpn
)
3191 /* Initialize the ES-EVI RB tree */
3192 RB_INIT(bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
);
3194 /* Initialize the local list maintained for quick walks by type */
3195 vpn
->local_es_evi_list
= list_new();
3196 listset_app_node_mem(vpn
->local_es_evi_list
);
3199 /* Cleanup the ES info maintained per-L2_VNI */
3200 void bgp_evpn_vni_es_cleanup(struct bgpevpn
*vpn
)
3202 struct bgp_evpn_es_evi
*es_evi
;
3203 struct bgp_evpn_es_evi
*es_evi_next
;
3205 RB_FOREACH_SAFE(es_evi
, bgp_es_evi_rb_head
,
3206 &vpn
->es_evi_rb_tree
, es_evi_next
) {
3207 bgp_evpn_local_es_evi_do_del(es_evi
);
3210 list_delete(&vpn
->local_es_evi_list
);
3213 static char *bgp_evpn_es_evi_vteps_str(char *vtep_str
,
3214 struct bgp_evpn_es_evi
*es_evi
,
3215 uint8_t vtep_str_size
)
3217 char vtep_flag_str
[BGP_EVPN_FLAG_STR_SZ
];
3218 struct listnode
*node
;
3219 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3221 char ip_buf
[INET6_ADDRSTRLEN
];
3224 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
3225 vtep_flag_str
[0] = '\0';
3226 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_ES
)
3227 strlcat(vtep_flag_str
, "E", sizeof(vtep_flag_str
));
3228 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)
3229 strlcat(vtep_flag_str
, "V", sizeof(vtep_flag_str
));
3231 if (!strnlen(vtep_flag_str
, sizeof(vtep_flag_str
)))
3232 strlcpy(vtep_flag_str
, "-", sizeof(vtep_flag_str
));
3236 strlcat(vtep_str
, ",", vtep_str_size
);
3238 inet_ntop(AF_INET
, &evi_vtep
->vtep_ip
, ip_buf
,
3241 strlcat(vtep_str
, "(", vtep_str_size
);
3242 strlcat(vtep_str
, vtep_flag_str
, vtep_str_size
);
3243 strlcat(vtep_str
, ")", vtep_str_size
);
3249 static void bgp_evpn_es_evi_json_vtep_fill(json_object
*json_vteps
,
3250 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
3252 json_object
*json_vtep_entry
;
3253 json_object
*json_flags
;
3254 char ip_buf
[INET6_ADDRSTRLEN
];
3256 json_vtep_entry
= json_object_new_object();
3258 json_object_string_add(
3259 json_vtep_entry
, "vtep_ip",
3260 inet_ntop(AF_INET
, &evi_vtep
->vtep_ip
, ip_buf
, sizeof(ip_buf
)));
3261 if (evi_vtep
->flags
& (BGP_EVPN_EVI_VTEP_EAD_PER_ES
|
3262 BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)) {
3263 json_flags
= json_object_new_array();
3264 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_ES
)
3265 json_array_string_add(json_flags
, "ead-per-es");
3266 if (evi_vtep
->flags
& BGP_EVPN_EVI_VTEP_EAD_PER_EVI
)
3267 json_array_string_add(json_flags
, "ed-per-evi");
3268 json_object_object_add(json_vtep_entry
,
3269 "flags", json_flags
);
3272 json_object_array_add(json_vteps
,
3276 static void bgp_evpn_es_evi_show_entry(struct vty
*vty
,
3277 struct bgp_evpn_es_evi
*es_evi
, json_object
*json
)
3279 struct listnode
*node
;
3280 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3283 json_object
*json_vteps
;
3284 json_object
*json_types
;
3286 json_object_string_add(json
, "esi", es_evi
->es
->esi_str
);
3287 json_object_int_add(json
, "vni", es_evi
->vpn
->vni
);
3289 if (es_evi
->flags
& (BGP_EVPNES_EVI_LOCAL
|
3290 BGP_EVPNES_EVI_REMOTE
)) {
3291 json_types
= json_object_new_array();
3292 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
3293 json_array_string_add(json_types
, "local");
3294 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
3295 json_array_string_add(json_types
, "remote");
3296 json_object_object_add(json
, "type", json_types
);
3299 if (listcount(es_evi
->es_evi_vtep_list
)) {
3300 json_vteps
= json_object_new_array();
3301 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
,
3303 bgp_evpn_es_evi_json_vtep_fill(json_vteps
,
3306 json_object_object_add(json
, "vteps", json_vteps
);
3310 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
3313 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
3314 strlcat(type_str
, "L", sizeof(type_str
));
3315 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
3316 strlcat(type_str
, "R", sizeof(type_str
));
3317 if (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
)
3318 strlcat(type_str
, "I", sizeof(type_str
));
3320 bgp_evpn_es_evi_vteps_str(vtep_str
, es_evi
, sizeof(vtep_str
));
3322 vty_out(vty
, "%-8d %-30s %-5s %s\n",
3323 es_evi
->vpn
->vni
, es_evi
->es
->esi_str
,
3324 type_str
, vtep_str
);
3328 static void bgp_evpn_es_evi_show_entry_detail(struct vty
*vty
,
3329 struct bgp_evpn_es_evi
*es_evi
, json_object
*json
)
3332 json_object
*json_flags
;
3334 /* Add the "brief" info first */
3335 bgp_evpn_es_evi_show_entry(vty
, es_evi
, json
);
3336 if (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
) {
3337 json_flags
= json_object_new_array();
3338 json_array_string_add(json_flags
, "es-vtep-mismatch");
3339 json_object_object_add(json
, "flags", json_flags
);
3342 char vtep_str
[ES_VTEP_LIST_STR_SZ
+ BGP_EVPN_VTEPS_FLAG_STR_SZ
];
3346 if (es_evi
->flags
& BGP_EVPNES_EVI_LOCAL
)
3347 strlcat(type_str
, "L", sizeof(type_str
));
3348 if (es_evi
->flags
& BGP_EVPNES_EVI_REMOTE
)
3349 strlcat(type_str
, "R", sizeof(type_str
));
3351 bgp_evpn_es_evi_vteps_str(vtep_str
, es_evi
, sizeof(vtep_str
));
3352 if (!strlen(vtep_str
))
3353 strlcpy(vtep_str
, "-", sizeof(type_str
));
3355 vty_out(vty
, "VNI: %d ESI: %s\n",
3356 es_evi
->vpn
->vni
, es_evi
->es
->esi_str
);
3357 vty_out(vty
, " Type: %s\n", type_str
);
3358 vty_out(vty
, " Inconsistencies: %s\n",
3359 (es_evi
->flags
& BGP_EVPNES_EVI_INCONS_VTEP_LIST
) ?
3360 "es-vtep-mismatch":"-");
3361 vty_out(vty
, " VTEPs: %s\n", vtep_str
);
3366 static void bgp_evpn_es_evi_show_one_vni(struct bgpevpn
*vpn
, struct vty
*vty
,
3367 json_object
*json_array
, bool detail
)
3369 struct bgp_evpn_es_evi
*es_evi
;
3370 json_object
*json
= NULL
;
3372 RB_FOREACH(es_evi
, bgp_es_evi_rb_head
, &vpn
->es_evi_rb_tree
) {
3374 /* create a separate json object for each ES */
3375 json
= json_object_new_object();
3377 bgp_evpn_es_evi_show_entry_detail(vty
, es_evi
, json
);
3379 bgp_evpn_es_evi_show_entry(vty
, es_evi
, json
);
3380 /* add ES to the json array */
3382 json_object_array_add(json_array
, json
);
3386 struct es_evi_show_ctx
{
3392 static void bgp_evpn_es_evi_show_one_vni_hash_cb(struct hash_bucket
*bucket
,
3395 struct bgpevpn
*vpn
= (struct bgpevpn
*)bucket
->data
;
3396 struct es_evi_show_ctx
*wctx
= (struct es_evi_show_ctx
*)ctxt
;
3398 bgp_evpn_es_evi_show_one_vni(vpn
, wctx
->vty
, wctx
->json
, wctx
->detail
);
3401 /* Display all ES EVIs */
3402 void bgp_evpn_es_evi_show(struct vty
*vty
, bool uj
, bool detail
)
3404 json_object
*json_array
= NULL
;
3405 struct es_evi_show_ctx wctx
;
3409 /* create an array of ES-EVIs */
3410 json_array
= json_object_new_array();
3414 wctx
.json
= json_array
;
3415 wctx
.detail
= detail
;
3417 bgp
= bgp_get_evpn();
3419 if (!json_array
&& !detail
) {
3420 vty_out(vty
, "Flags: L local, R remote, I inconsistent\n");
3421 vty_out(vty
, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
3422 vty_out(vty
, "%-8s %-30s %-5s %s\n",
3423 "VNI", "ESI", "Flags", "VTEPs");
3427 hash_iterate(bgp
->vnihash
,
3428 (void (*)(struct hash_bucket
*,
3429 void *))bgp_evpn_es_evi_show_one_vni_hash_cb
,
3432 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3433 json_array
, JSON_C_TO_STRING_PRETTY
));
3434 json_object_free(json_array
);
3438 /* Display specific ES EVI */
3439 void bgp_evpn_es_evi_show_vni(struct vty
*vty
, vni_t vni
,
3440 bool uj
, bool detail
)
3442 struct bgpevpn
*vpn
= NULL
;
3443 json_object
*json_array
= NULL
;
3447 /* create an array of ES-EVIs */
3448 json_array
= json_object_new_array();
3451 bgp
= bgp_get_evpn();
3453 vpn
= bgp_evpn_lookup_vni(bgp
, vni
);
3456 if (!json_array
&& !detail
) {
3457 vty_out(vty
, "Flags: L local, R remote, I inconsistent\n");
3458 vty_out(vty
, "VTEP-Flags: E EAD-per-ES, V EAD-per-EVI\n");
3459 vty_out(vty
, "%-8s %-30s %-5s %s\n",
3460 "VNI", "ESI", "Flags", "VTEPs");
3463 bgp_evpn_es_evi_show_one_vni(vpn
, vty
, json_array
, detail
);
3466 vty_out(vty
, "VNI not found\n");
3470 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3471 json_array
, JSON_C_TO_STRING_PRETTY
));
3472 json_object_free(json_array
);
3476 /*****************************************************************************
3477 * Ethernet Segment Consistency checks
3478 * Consistency checking is done to detect misconfig or mis-cabling. When
3479 * an inconsistency is detected it is simply logged (and displayed via
3480 * show commands) at this point. A more drastic action can be executed (based
3481 * on user config) in the future.
3483 /* queue up the es for background consistency checks */
3484 static void bgp_evpn_es_cons_checks_pend_add(struct bgp_evpn_es
*es
)
3486 if (!bgp_mh_info
->consistency_checking
)
3487 /* consistency checking is not enabled */
3490 if (CHECK_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
))
3491 /* already queued for consistency checking */
3494 SET_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
);
3495 listnode_init(&es
->pend_es_listnode
, es
);
3496 listnode_add_after(bgp_mh_info
->pend_es_list
,
3497 listtail_unchecked(bgp_mh_info
->pend_es_list
),
3498 &es
->pend_es_listnode
);
3501 /* pull the ES from the consistency check list */
3502 static void bgp_evpn_es_cons_checks_pend_del(struct bgp_evpn_es
*es
)
3504 if (!CHECK_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
))
3507 UNSET_FLAG(es
->flags
, BGP_EVPNES_CONS_CHECK_PEND
);
3508 list_delete_node(bgp_mh_info
->pend_es_list
,
3509 &es
->pend_es_listnode
);
3512 /* Number of active VTEPs associated with the ES-per-EVI */
3513 static uint32_t bgp_evpn_es_evi_get_active_vtep_cnt(
3514 struct bgp_evpn_es_evi
*es_evi
)
3516 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3517 struct listnode
*node
;
3518 uint32_t vtep_cnt
= 0;
3520 for (ALL_LIST_ELEMENTS_RO(es_evi
->es_evi_vtep_list
, node
, evi_vtep
)) {
3521 if (CHECK_FLAG(evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
))
3528 /* Number of active VTEPs associated with the ES */
3529 static uint32_t bgp_evpn_es_get_active_vtep_cnt(struct bgp_evpn_es
*es
)
3531 struct listnode
*node
;
3532 uint32_t vtep_cnt
= 0;
3533 struct bgp_evpn_es_vtep
*es_vtep
;
3535 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
3536 if (CHECK_FLAG(es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
3543 static struct bgp_evpn_es_vtep
*bgp_evpn_es_get_next_active_vtep(
3544 struct bgp_evpn_es
*es
, struct bgp_evpn_es_vtep
*es_vtep
)
3546 struct listnode
*node
;
3547 struct bgp_evpn_es_vtep
*next_es_vtep
;
3550 node
= listnextnode_unchecked(&es_vtep
->es_listnode
);
3552 node
= listhead(es
->es_vtep_list
);
3554 for (; node
; node
= listnextnode_unchecked(node
)) {
3555 next_es_vtep
= listgetdata(node
);
3556 if (CHECK_FLAG(next_es_vtep
->flags
, BGP_EVPNES_VTEP_ACTIVE
))
3557 return next_es_vtep
;
3563 static struct bgp_evpn_es_evi_vtep
*bgp_evpn_es_evi_get_next_active_vtep(
3564 struct bgp_evpn_es_evi
*es_evi
,
3565 struct bgp_evpn_es_evi_vtep
*evi_vtep
)
3567 struct listnode
*node
;
3568 struct bgp_evpn_es_evi_vtep
*next_evi_vtep
;
3571 node
= listnextnode_unchecked(&evi_vtep
->es_evi_listnode
);
3573 node
= listhead(es_evi
->es_evi_vtep_list
);
3575 for (; node
; node
= listnextnode_unchecked(node
)) {
3576 next_evi_vtep
= listgetdata(node
);
3577 if (CHECK_FLAG(next_evi_vtep
->flags
, BGP_EVPN_EVI_VTEP_ACTIVE
))
3578 return next_evi_vtep
;
3584 static void bgp_evpn_es_evi_set_inconsistent(struct bgp_evpn_es_evi
*es_evi
)
3586 if (!CHECK_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
)) {
3587 if (BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3588 zlog_debug("inconsistency detected - es %s evi %u vtep list mismatch",
3589 es_evi
->es
->esi_str
,
3591 SET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
);
3593 /* update parent ES with the incosistency setting */
3594 if (!es_evi
->es
->incons_evi_vtep_cnt
&&
3595 BGP_DEBUG(evpn_mh
, EVPN_MH_ES
))
3596 zlog_debug("inconsistency detected - es %s vtep list mismatch",
3597 es_evi
->es
->esi_str
);
3598 ++es_evi
->es
->incons_evi_vtep_cnt
;
3599 SET_FLAG(es_evi
->es
->inconsistencies
,
3600 BGP_EVPNES_INCONS_VTEP_LIST
);
3604 static uint32_t bgp_evpn_es_run_consistency_checks(struct bgp_evpn_es
*es
)
3607 int es_active_vtep_cnt
;
3608 int evi_active_vtep_cnt
;
3609 struct bgp_evpn_es_evi
*es_evi
;
3610 struct listnode
*evi_node
;
3611 struct bgp_evpn_es_vtep
*es_vtep
;
3612 struct bgp_evpn_es_evi_vtep
*evi_vtep
;
3614 /* reset the inconsistencies and re-evaluate */
3615 es
->incons_evi_vtep_cnt
= 0;
3616 es
->inconsistencies
= 0;
3618 es_active_vtep_cnt
= bgp_evpn_es_get_active_vtep_cnt(es
);
3619 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
,
3620 evi_node
, es_evi
)) {
3623 /* reset the inconsistencies on the EVI and re-evaluate*/
3624 UNSET_FLAG(es_evi
->flags
, BGP_EVPNES_EVI_INCONS_VTEP_LIST
);
3626 evi_active_vtep_cnt
=
3627 bgp_evpn_es_evi_get_active_vtep_cnt(es_evi
);
3628 if (es_active_vtep_cnt
!= evi_active_vtep_cnt
) {
3629 bgp_evpn_es_evi_set_inconsistent(es_evi
);
3633 if (!es_active_vtep_cnt
)
3638 while ((es_vtep
= bgp_evpn_es_get_next_active_vtep(
3640 evi_vtep
= bgp_evpn_es_evi_get_next_active_vtep(es_evi
,
3643 bgp_evpn_es_evi_set_inconsistent(es_evi
);
3646 if (es_vtep
->vtep_ip
.s_addr
!=
3647 evi_vtep
->vtep_ip
.s_addr
) {
3648 /* inconsistency detected; set it and move
3651 bgp_evpn_es_evi_set_inconsistent(es_evi
);
3660 static int bgp_evpn_run_consistency_checks(struct thread
*t
)
3664 struct listnode
*node
;
3665 struct listnode
*nextnode
;
3666 struct bgp_evpn_es
*es
;
3668 for (ALL_LIST_ELEMENTS(bgp_mh_info
->pend_es_list
,
3669 node
, nextnode
, es
)) {
3672 /* run consistency checks on the ES and remove it from the
3675 proc_cnt
+= bgp_evpn_es_run_consistency_checks(es
);
3676 bgp_evpn_es_cons_checks_pend_del(es
);
3681 /* restart the timer */
3682 thread_add_timer(bm
->master
, bgp_evpn_run_consistency_checks
, NULL
,
3683 BGP_EVPN_CONS_CHECK_INTERVAL
,
3684 &bgp_mh_info
->t_cons_check
);
3689 /*****************************************************************************/
3690 void bgp_evpn_mh_init(void)
3692 bm
->mh_info
= XCALLOC(MTYPE_BGP_EVPN_MH_INFO
, sizeof(*bm
->mh_info
));
3694 /* setup ES tables */
3695 RB_INIT(bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
);
3697 bgp_mh_info
->local_es_list
= list_new();
3698 listset_app_node_mem(bgp_mh_info
->local_es_list
);
3699 /* list of ESs with pending processing */
3700 bgp_mh_info
->pend_es_list
= list_new();
3701 listset_app_node_mem(bgp_mh_info
->pend_es_list
);
3703 /* config knobs - XXX add cli to control it */
3704 bgp_mh_info
->ead_evi_adv_for_down_links
= true;
3705 bgp_mh_info
->consistency_checking
= true;
3706 bgp_mh_info
->install_l3nhg
= false;
3707 bgp_mh_info
->host_routes_use_l3nhg
= BGP_EVPN_MH_USE_ES_L3NHG_DEF
;
3709 if (bgp_mh_info
->consistency_checking
)
3710 thread_add_timer(bm
->master
, bgp_evpn_run_consistency_checks
,
3711 NULL
, BGP_EVPN_CONS_CHECK_INTERVAL
,
3712 &bgp_mh_info
->t_cons_check
);
3714 memset(&zero_esi_buf
, 0, sizeof(esi_t
));
3717 void bgp_evpn_mh_finish(void)
3719 struct bgp_evpn_es
*es
;
3720 struct bgp_evpn_es
*es_next
;
3722 if (BGP_DEBUG(evpn_mh
, EVPN_MH_RT
))
3723 zlog_debug("evpn mh finish");
3725 RB_FOREACH_SAFE (es
, bgp_es_rb_head
, &bgp_mh_info
->es_rb_tree
,
3727 bgp_evpn_es_local_info_clear(es
);
3729 thread_cancel(&bgp_mh_info
->t_cons_check
);
3730 list_delete(&bgp_mh_info
->local_es_list
);
3731 list_delete(&bgp_mh_info
->pend_es_list
);
3733 XFREE(MTYPE_BGP_EVPN_MH_INFO
, bgp_mh_info
);