2 * Zebra EVPN multihoming code
4 * Copyright (C) 2019 Cumulus Networks, Inc.
7 * This file is part of FRR.
9 * FRR is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * FRR is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
35 #include "zebra/zebra_router.h"
36 #include "zebra/debug.h"
37 #include "zebra/interface.h"
38 #include "zebra/rib.h"
40 #include "zebra/rt_netlink.h"
41 #include "zebra/if_netlink.h"
42 #include "zebra/zebra_errors.h"
43 #include "zebra/zebra_l2.h"
44 #include "zebra/zebra_ns.h"
45 #include "zebra/zebra_vrf.h"
46 #include "zebra/zebra_vxlan.h"
47 #include "zebra/zebra_evpn.h"
48 #include "zebra/zebra_evpn_mac.h"
49 #include "zebra/zebra_vxlan_private.h"
50 #include "zebra/zebra_router.h"
51 #include "zebra/zebra_evpn_mh.h"
52 #include "zebra/zebra_nhg.h"
54 DEFINE_MTYPE_STATIC(ZEBRA
, ZACC_BD
, "Access Broadcast Domain");
55 DEFINE_MTYPE_STATIC(ZEBRA
, ZES
, "Ethernet Segment");
56 DEFINE_MTYPE_STATIC(ZEBRA
, ZES_EVI
, "ES info per-EVI");
57 DEFINE_MTYPE_STATIC(ZEBRA
, ZMH_INFO
, "MH global info");
58 DEFINE_MTYPE_STATIC(ZEBRA
, ZES_VTEP
, "VTEP attached to the ES");
59 DEFINE_MTYPE_STATIC(ZEBRA
, L2_NH
, "L2 nexthop");
61 static void zebra_evpn_es_get_one_base_evpn(void);
62 static int zebra_evpn_es_evi_send_to_client(struct zebra_evpn_es
*es
,
63 struct zebra_evpn
*zevpn
, bool add
);
64 static void zebra_evpn_local_es_del(struct zebra_evpn_es
**esp
);
65 static int zebra_evpn_local_es_update(struct zebra_if
*zif
, esi_t
*esi
);
66 static bool zebra_evpn_es_br_port_dplane_update(struct zebra_evpn_es
*es
,
68 static void zebra_evpn_mh_uplink_cfg_update(struct zebra_if
*zif
, bool set
);
69 static void zebra_evpn_mh_update_protodown_es(struct zebra_evpn_es
*es
,
71 static void zebra_evpn_mh_clear_protodown_es(struct zebra_evpn_es
*es
);
72 static void zebra_evpn_mh_startup_delay_timer_start(const char *rc
);
74 esi_t zero_esi_buf
, *zero_esi
= &zero_esi_buf
;
76 /*****************************************************************************/
77 /* Ethernet Segment to EVI association -
78 * 1. The ES-EVI entry is maintained as a RB tree per L2-VNI
79 * (struct zebra_evpn.es_evi_rb_tree).
80 * 2. Each local ES-EVI entry is sent to BGP which advertises it as an
81 * EAD-EVI (Type-1 EVPN) route
82 * 3. Local ES-EVI setup is re-evaluated on the following triggers -
83 * a. When an ESI is set or cleared on an access port.
84 * b. When an access port associated with an ESI is deleted.
85 * c. When VLAN member ship changes on an access port.
86 * d. When a VXLAN_IF is set or cleared on an access broadcast domain.
87 * e. When a L2-VNI is added or deleted for a VxLAN_IF.
88 * 4. Currently zebra doesn't remote ES-EVIs. Those are managed and maintained
89 * entirely in BGP which consolidates them into a remote ES. The remote ES
90 * is then sent to zebra which allocates a NHG for it.
93 /* compare ES-IDs for the ES-EVI RB tree maintained per-EVPN */
94 static int zebra_es_evi_rb_cmp(const struct zebra_evpn_es_evi
*es_evi1
,
95 const struct zebra_evpn_es_evi
*es_evi2
)
97 return memcmp(&es_evi1
->es
->esi
, &es_evi2
->es
->esi
, ESI_BYTES
);
99 RB_GENERATE(zebra_es_evi_rb_head
, zebra_evpn_es_evi
,
100 rb_node
, zebra_es_evi_rb_cmp
);
102 /* allocate a new ES-EVI and insert it into the per-L2-VNI and per-ES
105 static struct zebra_evpn_es_evi
*zebra_evpn_es_evi_new(struct zebra_evpn_es
*es
,
106 struct zebra_evpn
*zevpn
)
108 struct zebra_evpn_es_evi
*es_evi
;
110 es_evi
= XCALLOC(MTYPE_ZES_EVI
, sizeof(struct zebra_evpn_es_evi
));
113 es_evi
->zevpn
= zevpn
;
115 /* insert into the EVPN-ESI rb tree */
116 RB_INSERT(zebra_es_evi_rb_head
, &zevpn
->es_evi_rb_tree
, es_evi
);
118 /* add to the ES's VNI list */
119 listnode_init(&es_evi
->es_listnode
, es_evi
);
120 listnode_add(es
->es_evi_list
, &es_evi
->es_listnode
);
122 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
123 zlog_debug("es %s evi %d new",
124 es_evi
->es
->esi_str
, es_evi
->zevpn
->vni
);
129 /* Evaluate if the es_evi is ready to be sent BGP -
130 * 1. If it is ready an add is sent to BGP
131 * 2. If it is not ready a del is sent (if the ES had been previously added
134 static void zebra_evpn_es_evi_re_eval_send_to_client(
135 struct zebra_evpn_es_evi
*es_evi
)
140 old_ready
= !!(es_evi
->flags
& ZEBRA_EVPNES_EVI_READY_FOR_BGP
);
142 /* ES and L2-VNI have to be individually ready for BGP */
143 if ((es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
) &&
144 (es_evi
->es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
) &&
145 zebra_evpn_send_to_client_ok(es_evi
->zevpn
))
146 es_evi
->flags
|= ZEBRA_EVPNES_EVI_READY_FOR_BGP
;
148 es_evi
->flags
&= ~ZEBRA_EVPNES_EVI_READY_FOR_BGP
;
150 new_ready
= !!(es_evi
->flags
& ZEBRA_EVPNES_EVI_READY_FOR_BGP
);
152 if (old_ready
== new_ready
)
156 zebra_evpn_es_evi_send_to_client(es_evi
->es
, es_evi
->zevpn
,
159 zebra_evpn_es_evi_send_to_client(es_evi
->es
, es_evi
->zevpn
,
163 /* remove the ES-EVI from the per-L2-VNI and per-ES tables and free
166 static void zebra_evpn_es_evi_free(struct zebra_evpn_es_evi
*es_evi
)
168 struct zebra_evpn_es
*es
= es_evi
->es
;
169 struct zebra_evpn
*zevpn
= es_evi
->zevpn
;
171 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
172 zlog_debug("es %s evi %d free",
173 es_evi
->es
->esi_str
, es_evi
->zevpn
->vni
);
175 /* remove from the ES's VNI list */
176 list_delete_node(es
->es_evi_list
, &es_evi
->es_listnode
);
178 /* remove from the VNI-ESI rb tree */
179 RB_REMOVE(zebra_es_evi_rb_head
, &zevpn
->es_evi_rb_tree
, es_evi
);
181 /* remove from the VNI-ESI rb tree */
182 XFREE(MTYPE_ZES_EVI
, es_evi
);
185 /* find the ES-EVI in the per-L2-VNI RB tree */
186 struct zebra_evpn_es_evi
*zebra_evpn_es_evi_find(struct zebra_evpn_es
*es
,
187 struct zebra_evpn
*zevpn
)
189 struct zebra_evpn_es_evi es_evi
;
193 return RB_FIND(zebra_es_evi_rb_head
, &zevpn
->es_evi_rb_tree
, &es_evi
);
196 /* Tell BGP about an ES-EVI deletion and then delete it */
197 static void zebra_evpn_local_es_evi_do_del(struct zebra_evpn_es_evi
*es_evi
)
199 if (!(es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
))
202 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
203 zlog_debug("local es %s evi %d del",
204 es_evi
->es
->esi_str
, es_evi
->zevpn
->vni
);
206 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_READY_FOR_BGP
) {
207 /* send a del only if add was sent for it earlier */
208 zebra_evpn_es_evi_send_to_client(es_evi
->es
,
209 es_evi
->zevpn
, false /* add */);
212 /* delete it from the EVPN's local list */
213 list_delete_node(es_evi
->zevpn
->local_es_evi_list
,
214 &es_evi
->l2vni_listnode
);
216 es_evi
->flags
&= ~ZEBRA_EVPNES_EVI_LOCAL
;
217 zebra_evpn_es_evi_free(es_evi
);
219 static void zebra_evpn_local_es_evi_del(struct zebra_evpn_es
*es
,
220 struct zebra_evpn
*zevpn
)
222 struct zebra_evpn_es_evi
*es_evi
;
224 es_evi
= zebra_evpn_es_evi_find(es
, zevpn
);
226 zebra_evpn_local_es_evi_do_del(es_evi
);
229 /* If there are any existing MAC entries for this es/zevpn we need
230 * to install it in the dataplane.
232 * Note: primary purpose of this is to handle es del/re-add windows where
233 * sync MAC entries may be added by bgpd before the es-evi membership is
234 * created in the dataplane and in zebra
236 static void zebra_evpn_es_evi_mac_install(struct zebra_evpn_es_evi
*es_evi
)
238 struct zebra_mac
*mac
;
239 struct listnode
*node
;
240 struct zebra_evpn_es
*es
= es_evi
->es
;
242 if (listcount(es
->mac_list
) && IS_ZEBRA_DEBUG_EVPN_MH_ES
)
243 zlog_debug("dp-mac install on es %s evi %d add", es
->esi_str
,
246 for (ALL_LIST_ELEMENTS_RO(es
->mac_list
, node
, mac
)) {
247 if (mac
->zevpn
!= es_evi
->zevpn
)
250 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
253 zebra_evpn_sync_mac_dp_install(mac
, false, false, __func__
);
257 /* Create an ES-EVI if it doesn't already exist and tell BGP */
258 static void zebra_evpn_local_es_evi_add(struct zebra_evpn_es
*es
,
259 struct zebra_evpn
*zevpn
)
261 struct zebra_evpn_es_evi
*es_evi
;
263 es_evi
= zebra_evpn_es_evi_find(es
, zevpn
);
265 es_evi
= zebra_evpn_es_evi_new(es
, zevpn
);
269 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
270 zlog_debug("local es %s evi %d add",
271 es_evi
->es
->esi_str
, es_evi
->zevpn
->vni
);
272 es_evi
->flags
|= ZEBRA_EVPNES_EVI_LOCAL
;
273 /* add to the EVPN's local list */
274 listnode_init(&es_evi
->l2vni_listnode
, es_evi
);
275 listnode_add(zevpn
->local_es_evi_list
, &es_evi
->l2vni_listnode
);
277 zebra_evpn_es_evi_re_eval_send_to_client(es_evi
);
279 zebra_evpn_es_evi_mac_install(es_evi
);
283 static void zebra_evpn_es_evi_show_entry(struct vty
*vty
,
284 struct zebra_evpn_es_evi
*es_evi
,
285 json_object
*json_array
)
291 json_object
*json_types
;
293 /* Separate JSON object for each es-evi entry */
294 json
= json_object_new_object();
296 json_object_string_add(json
, "esi", es_evi
->es
->esi_str
);
297 json_object_int_add(json
, "vni", es_evi
->zevpn
->vni
);
298 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
) {
299 json_types
= json_object_new_array();
300 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
)
301 json_array_string_add(json_types
, "local");
302 json_object_object_add(json
, "type", json_types
);
305 /* Add es-evi entry to json array */
306 json_object_array_add(json_array
, json
);
309 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
)
310 strlcat(type_str
, "L", sizeof(type_str
));
312 vty_out(vty
, "%-8d %-30s %-4s\n",
313 es_evi
->zevpn
->vni
, es_evi
->es
->esi_str
,
319 zebra_evpn_es_evi_show_entry_detail(struct vty
*vty
,
320 struct zebra_evpn_es_evi
*es_evi
,
321 json_object
*json_array
)
327 json_object
*json_flags
;
329 /* Separate JSON object for each es-evi entry */
330 json
= json_object_new_object();
332 json_object_string_add(json
, "esi", es_evi
->es
->esi_str
);
333 json_object_int_add(json
, "vni", es_evi
->zevpn
->vni
);
335 & (ZEBRA_EVPNES_EVI_LOCAL
336 | ZEBRA_EVPNES_EVI_READY_FOR_BGP
)) {
337 json_flags
= json_object_new_array();
338 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
)
339 json_array_string_add(json_flags
, "local");
340 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_READY_FOR_BGP
)
341 json_array_string_add(json_flags
,
343 json_object_object_add(json
, "flags", json_flags
);
346 /* Add es-evi entry to json array */
347 json_object_array_add(json_array
, json
);
350 if (es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
)
351 strlcat(type_str
, "L", sizeof(type_str
));
353 vty_out(vty
, "VNI %d ESI: %s\n",
354 es_evi
->zevpn
->vni
, es_evi
->es
->esi_str
);
355 vty_out(vty
, " Type: %s\n", type_str
);
356 vty_out(vty
, " Ready for BGP: %s\n",
358 ZEBRA_EVPNES_EVI_READY_FOR_BGP
) ?
364 static void zebra_evpn_es_evi_show_one_evpn(struct zebra_evpn
*zevpn
,
366 json_object
*json_array
, int detail
)
368 struct zebra_evpn_es_evi
*es_evi
;
370 RB_FOREACH(es_evi
, zebra_es_evi_rb_head
, &zevpn
->es_evi_rb_tree
) {
372 zebra_evpn_es_evi_show_entry_detail(vty
, es_evi
,
375 zebra_evpn_es_evi_show_entry(vty
, es_evi
, json_array
);
379 struct evpn_mh_show_ctx
{
385 static void zebra_evpn_es_evi_show_one_evpn_hash_cb(struct hash_bucket
*bucket
,
388 struct zebra_evpn
*zevpn
= (struct zebra_evpn
*)bucket
->data
;
389 struct evpn_mh_show_ctx
*wctx
= (struct evpn_mh_show_ctx
*)ctxt
;
391 zebra_evpn_es_evi_show_one_evpn(zevpn
, wctx
->vty
,
392 wctx
->json
, wctx
->detail
);
395 void zebra_evpn_es_evi_show(struct vty
*vty
, bool uj
, int detail
)
397 json_object
*json_array
= NULL
;
398 struct zebra_vrf
*zvrf
;
399 struct evpn_mh_show_ctx wctx
;
401 zvrf
= zebra_vrf_get_evpn();
403 json_array
= json_object_new_array();
405 memset(&wctx
, 0, sizeof(wctx
));
407 wctx
.json
= json_array
;
408 wctx
.detail
= detail
;
410 if (!detail
&& !json_array
) {
411 vty_out(vty
, "Type: L local, R remote\n");
412 vty_out(vty
, "%-8s %-30s %-4s\n", "VNI", "ESI", "Type");
414 /* Display all L2-VNIs */
415 hash_iterate(zvrf
->evpn_table
, zebra_evpn_es_evi_show_one_evpn_hash_cb
,
419 vty_json(vty
, json_array
);
422 void zebra_evpn_es_evi_show_vni(struct vty
*vty
, bool uj
, vni_t vni
, int detail
)
424 json_object
*json_array
= NULL
;
425 struct zebra_evpn
*zevpn
;
427 zevpn
= zebra_evpn_lookup(vni
);
429 json_array
= json_object_new_array();
432 if (!detail
&& !json_array
) {
433 vty_out(vty
, "Type: L local, R remote\n");
434 vty_out(vty
, "%-8s %-30s %-4s\n", "VNI", "ESI", "Type");
436 zebra_evpn_es_evi_show_one_evpn(zevpn
, vty
, json_array
, detail
);
439 vty_out(vty
, "VNI %d doesn't exist\n", vni
);
443 vty_json(vty
, json_array
);
446 /* Initialize the ES tables maintained per-L2_VNI */
447 void zebra_evpn_es_evi_init(struct zebra_evpn
*zevpn
)
449 /* Initialize the ES-EVI RB tree */
450 RB_INIT(zebra_es_evi_rb_head
, &zevpn
->es_evi_rb_tree
);
452 /* Initialize the local and remote ES lists maintained for quick
455 zevpn
->local_es_evi_list
= list_new();
456 listset_app_node_mem(zevpn
->local_es_evi_list
);
459 /* Cleanup the ES info maintained per- EVPN */
460 void zebra_evpn_es_evi_cleanup(struct zebra_evpn
*zevpn
)
462 struct zebra_evpn_es_evi
*es_evi
;
463 struct zebra_evpn_es_evi
*es_evi_next
;
465 RB_FOREACH_SAFE(es_evi
, zebra_es_evi_rb_head
,
466 &zevpn
->es_evi_rb_tree
, es_evi_next
) {
467 zebra_evpn_local_es_evi_do_del(es_evi
);
470 list_delete(&zevpn
->local_es_evi_list
);
471 zebra_evpn_es_clear_base_evpn(zevpn
);
474 /* called when the oper state or bridge membership changes for the
477 void zebra_evpn_update_all_es(struct zebra_evpn
*zevpn
)
479 struct zebra_evpn_es_evi
*es_evi
;
480 struct listnode
*node
;
481 struct interface
*vlan_if
;
482 struct interface
*vxlan_if
;
483 struct zebra_if
*vxlan_zif
;
485 /* the EVPN is now elgible as a base for EVPN-MH */
486 if (zebra_evpn_send_to_client_ok(zevpn
))
487 zebra_evpn_es_set_base_evpn(zevpn
);
489 zebra_evpn_es_clear_base_evpn(zevpn
);
491 for (ALL_LIST_ELEMENTS_RO(zevpn
->local_es_evi_list
, node
, es_evi
))
492 zebra_evpn_es_evi_re_eval_send_to_client(es_evi
);
494 /* reinstall SVI MAC */
495 vxlan_if
= zevpn
->vxlan_if
;
497 vxlan_zif
= vxlan_if
->info
;
498 if (if_is_operative(vxlan_if
)
499 && vxlan_zif
->brslave_info
.br_if
) {
500 vlan_if
= zvni_map_to_svi(
501 vxlan_zif
->l2info
.vxl
.access_vlan
,
502 vxlan_zif
->brslave_info
.br_if
);
504 zebra_evpn_acc_bd_svi_mac_add(vlan_if
);
509 /*****************************************************************************/
510 /* Access broadcast domains (BD)
511 * 1. These broadcast domains can be VLAN aware (in which case
512 * the key is VID) or VLAN unaware (in which case the key is
513 * 2. A VID-BD is created when a VLAN is associated with an access port or
514 * when the VLAN is associated with VXLAN_IF
515 * 3. A BD is translated into ES-EVI entries when a VNI is associated
516 * with the broadcast domain
518 /* Hash key for VLAN based broadcast domains */
519 static unsigned int zebra_evpn_acc_vl_hash_keymake(const void *p
)
521 const struct zebra_evpn_access_bd
*acc_bd
= p
;
523 return jhash_1word(acc_bd
->vid
, 0);
526 /* Compare two VLAN based broadcast domains */
527 static bool zebra_evpn_acc_vl_cmp(const void *p1
, const void *p2
)
529 const struct zebra_evpn_access_bd
*acc_bd1
= p1
;
530 const struct zebra_evpn_access_bd
*acc_bd2
= p2
;
532 if (acc_bd1
== NULL
&& acc_bd2
== NULL
)
535 if (acc_bd1
== NULL
|| acc_bd2
== NULL
)
538 return (acc_bd1
->vid
== acc_bd2
->vid
);
541 /* Lookup VLAN based broadcast domain */
542 static struct zebra_evpn_access_bd
*zebra_evpn_acc_vl_find(vlanid_t vid
)
544 struct zebra_evpn_access_bd
*acc_bd
;
545 struct zebra_evpn_access_bd tmp
;
548 acc_bd
= hash_lookup(zmh_info
->evpn_vlan_table
, &tmp
);
553 /* A new broadcast domain can be created when a VLAN member or VLAN<=>VxLAN_IF
556 static struct zebra_evpn_access_bd
*
557 zebra_evpn_acc_vl_new(vlanid_t vid
, struct interface
*br_if
)
559 struct zebra_evpn_access_bd
*acc_bd
;
560 struct interface
*vlan_if
;
562 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
563 zlog_debug("access vlan %d add", vid
);
565 acc_bd
= XCALLOC(MTYPE_ZACC_BD
, sizeof(struct zebra_evpn_access_bd
));
569 /* Initialize the mbr list */
570 acc_bd
->mbr_zifs
= list_new();
573 (void)hash_get(zmh_info
->evpn_vlan_table
, acc_bd
, hash_alloc_intern
);
575 /* check if an svi exists for the vlan */
577 vlan_if
= zvni_map_to_svi(vid
, br_if
);
579 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
580 zlog_debug("vlan %d SVI %s set", vid
,
582 acc_bd
->vlan_zif
= vlan_if
->info
;
588 /* Free VLAN based broadcast domain -
589 * This just frees appropriate memory, caller should have taken other
592 static void zebra_evpn_acc_vl_free(struct zebra_evpn_access_bd
*acc_bd
)
594 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
595 zlog_debug("access vlan %d del", acc_bd
->vid
);
597 if (acc_bd
->vlan_zif
&& acc_bd
->zevpn
&& acc_bd
->zevpn
->mac_table
)
598 zebra_evpn_mac_svi_del(acc_bd
->vlan_zif
->ifp
, acc_bd
->zevpn
);
600 /* cleanup resources maintained against the ES */
601 list_delete(&acc_bd
->mbr_zifs
);
603 /* remove EVI from various tables */
604 hash_release(zmh_info
->evpn_vlan_table
, acc_bd
);
606 XFREE(MTYPE_ZACC_BD
, acc_bd
);
609 static void zebra_evpn_acc_vl_cleanup_all(struct hash_bucket
*bucket
, void *arg
)
611 struct zebra_evpn_access_bd
*acc_bd
= bucket
->data
;
613 zebra_evpn_acc_vl_free(acc_bd
);
616 /* called when a bd mbr is removed or VxLAN_IF is diassociated from the access
619 static void zebra_evpn_acc_bd_free_on_deref(struct zebra_evpn_access_bd
*acc_bd
)
621 if (!list_isempty(acc_bd
->mbr_zifs
) || acc_bd
->vxlan_zif
)
624 /* if there are no references free the EVI */
625 zebra_evpn_acc_vl_free(acc_bd
);
628 /* called when a SVI is goes up/down */
629 void zebra_evpn_acc_bd_svi_set(struct zebra_if
*vlan_zif
,
630 struct zebra_if
*br_zif
, bool is_up
)
632 struct zebra_evpn_access_bd
*acc_bd
;
633 struct zebra_l2info_bridge
*br
;
635 struct zebra_if
*tmp_br_zif
= br_zif
;
638 if (!vlan_zif
->link
|| !vlan_zif
->link
->info
)
641 tmp_br_zif
= vlan_zif
->link
->info
;
644 br
= &tmp_br_zif
->l2info
.br
;
645 /* ignore vlan unaware bridges */
649 vid
= vlan_zif
->l2info
.vl
.vid
;
650 acc_bd
= zebra_evpn_acc_vl_find(vid
);
655 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
656 zlog_debug("vlan %d SVI %s set", vid
,
657 vlan_zif
->ifp
->name
);
659 acc_bd
->vlan_zif
= vlan_zif
;
661 zebra_evpn_mac_svi_add(acc_bd
->vlan_zif
->ifp
,
663 } else if (acc_bd
->vlan_zif
) {
664 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
665 zlog_debug("vlan %d SVI clear", vid
);
666 acc_bd
->vlan_zif
= NULL
;
667 if (acc_bd
->zevpn
&& acc_bd
->zevpn
->mac_table
)
668 zebra_evpn_mac_svi_del(vlan_zif
->ifp
, acc_bd
->zevpn
);
672 /* On some events macs are force-flushed. This api can be used to reinstate
673 * the svi-mac after such cleanup-events.
675 void zebra_evpn_acc_bd_svi_mac_add(struct interface
*vlan_if
)
677 zebra_evpn_acc_bd_svi_set(vlan_if
->info
, NULL
,
678 if_is_operative(vlan_if
));
681 /* called when a EVPN-L2VNI is set or cleared against a BD */
682 static void zebra_evpn_acc_bd_evpn_set(struct zebra_evpn_access_bd
*acc_bd
,
683 struct zebra_evpn
*zevpn
,
684 struct zebra_evpn
*old_zevpn
)
686 struct zebra_if
*zif
;
687 struct listnode
*node
;
689 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
690 zlog_debug("access vlan %d l2-vni %u set",
691 acc_bd
->vid
, zevpn
? zevpn
->vni
: 0);
693 for (ALL_LIST_ELEMENTS_RO(acc_bd
->mbr_zifs
, node
, zif
)) {
694 if (!zif
->es_info
.es
)
698 zebra_evpn_local_es_evi_add(zif
->es_info
.es
, zevpn
);
700 zebra_evpn_local_es_evi_del(zif
->es_info
.es
, old_zevpn
);
703 if (acc_bd
->vlan_zif
) {
705 zebra_evpn_mac_svi_add(acc_bd
->vlan_zif
->ifp
,
707 else if (old_zevpn
&& old_zevpn
->mac_table
)
708 zebra_evpn_mac_svi_del(acc_bd
->vlan_zif
->ifp
,
713 /* handle VLAN->VxLAN_IF association */
714 void zebra_evpn_vl_vxl_ref(uint16_t vid
, struct zebra_if
*vxlan_zif
)
716 struct zebra_evpn_access_bd
*acc_bd
;
717 struct zebra_if
*old_vxlan_zif
;
718 struct zebra_evpn
*old_zevpn
;
723 acc_bd
= zebra_evpn_acc_vl_find(vid
);
725 acc_bd
= zebra_evpn_acc_vl_new(vid
,
726 vxlan_zif
->brslave_info
.br_if
);
728 old_vxlan_zif
= acc_bd
->vxlan_zif
;
729 acc_bd
->vxlan_zif
= vxlan_zif
;
730 if (vxlan_zif
== old_vxlan_zif
)
733 old_zevpn
= acc_bd
->zevpn
;
734 acc_bd
->zevpn
= zebra_evpn_lookup(vxlan_zif
->l2info
.vxl
.vni
);
735 if (acc_bd
->zevpn
== old_zevpn
)
738 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
739 zlog_debug("access vlan %d vni %u ref",
740 acc_bd
->vid
, vxlan_zif
->l2info
.vxl
.vni
);
743 zebra_evpn_acc_bd_evpn_set(acc_bd
, NULL
, old_zevpn
);
746 zebra_evpn_acc_bd_evpn_set(acc_bd
, acc_bd
->zevpn
, NULL
);
749 /* handle VLAN->VxLAN_IF deref */
750 void zebra_evpn_vl_vxl_deref(uint16_t vid
, struct zebra_if
*vxlan_zif
)
752 struct zebra_evpn_access_bd
*acc_bd
;
757 acc_bd
= zebra_evpn_acc_vl_find(vid
);
761 /* clear vxlan_if only if it matches */
762 if (acc_bd
->vxlan_zif
!= vxlan_zif
)
765 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
766 zlog_debug("access vlan %d vni %u deref",
767 acc_bd
->vid
, vxlan_zif
->l2info
.vxl
.vni
);
770 zebra_evpn_acc_bd_evpn_set(acc_bd
, NULL
, acc_bd
->zevpn
);
772 acc_bd
->zevpn
= NULL
;
773 acc_bd
->vxlan_zif
= NULL
;
775 /* if there are no other references the access_bd can be freed */
776 zebra_evpn_acc_bd_free_on_deref(acc_bd
);
779 /* handle EVPN add/del */
780 void zebra_evpn_vxl_evpn_set(struct zebra_if
*zif
, struct zebra_evpn
*zevpn
,
783 struct zebra_l2info_vxlan
*vxl
;
784 struct zebra_evpn_access_bd
*acc_bd
;
789 /* locate access_bd associated with the vxlan device */
790 vxl
= &zif
->l2info
.vxl
;
791 acc_bd
= zebra_evpn_acc_vl_find(vxl
->access_vlan
);
796 zebra_evpn_es_set_base_evpn(zevpn
);
797 if (acc_bd
->zevpn
!= zevpn
) {
798 acc_bd
->zevpn
= zevpn
;
799 zebra_evpn_acc_bd_evpn_set(acc_bd
, zevpn
, NULL
);
803 struct zebra_evpn
*old_zevpn
= acc_bd
->zevpn
;
804 acc_bd
->zevpn
= NULL
;
805 zebra_evpn_acc_bd_evpn_set(acc_bd
, NULL
, old_zevpn
);
810 /* handle addition of new VLAN members */
811 void zebra_evpn_vl_mbr_ref(uint16_t vid
, struct zebra_if
*zif
)
813 struct zebra_evpn_access_bd
*acc_bd
;
818 acc_bd
= zebra_evpn_acc_vl_find(vid
);
820 acc_bd
= zebra_evpn_acc_vl_new(vid
, zif
->brslave_info
.br_if
);
822 if (listnode_lookup(acc_bd
->mbr_zifs
, zif
))
825 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
826 zlog_debug("access vlan %d mbr %s ref",
827 vid
, zif
->ifp
->name
);
829 listnode_add(acc_bd
->mbr_zifs
, zif
);
830 if (acc_bd
->zevpn
&& zif
->es_info
.es
)
831 zebra_evpn_local_es_evi_add(zif
->es_info
.es
, acc_bd
->zevpn
);
834 /* handle deletion of VLAN members */
835 void zebra_evpn_vl_mbr_deref(uint16_t vid
, struct zebra_if
*zif
)
837 struct zebra_evpn_access_bd
*acc_bd
;
838 struct listnode
*node
;
843 acc_bd
= zebra_evpn_acc_vl_find(vid
);
847 node
= listnode_lookup(acc_bd
->mbr_zifs
, zif
);
851 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
852 zlog_debug("access vlan %d mbr %s deref",
853 vid
, zif
->ifp
->name
);
855 list_delete_node(acc_bd
->mbr_zifs
, node
);
857 if (acc_bd
->zevpn
&& zif
->es_info
.es
)
858 zebra_evpn_local_es_evi_del(zif
->es_info
.es
, acc_bd
->zevpn
);
860 /* if there are no other references the access_bd can be freed */
861 zebra_evpn_acc_bd_free_on_deref(acc_bd
);
864 static void zebra_evpn_acc_vl_adv_svi_mac_cb(struct hash_bucket
*bucket
,
867 struct zebra_evpn_access_bd
*acc_bd
= bucket
->data
;
869 if (acc_bd
->vlan_zif
&& acc_bd
->zevpn
)
870 zebra_evpn_mac_svi_add(acc_bd
->vlan_zif
->ifp
, acc_bd
->zevpn
);
873 /* called when advertise SVI MAC is enabled on the switch */
874 static void zebra_evpn_acc_vl_adv_svi_mac_all(void)
876 hash_iterate(zmh_info
->evpn_vlan_table
,
877 zebra_evpn_acc_vl_adv_svi_mac_cb
, NULL
);
880 static void zebra_evpn_acc_vl_json_fill(struct zebra_evpn_access_bd
*acc_bd
,
881 json_object
*json
, bool detail
)
883 json_object_int_add(json
, "vlan", acc_bd
->vid
);
884 if (acc_bd
->vxlan_zif
)
885 json_object_string_add(json
, "vxlanIf",
886 acc_bd
->vxlan_zif
->ifp
->name
);
888 json_object_int_add(json
, "vni", acc_bd
->zevpn
->vni
);
889 if (acc_bd
->mbr_zifs
)
890 json_object_int_add(json
, "memberIfCount",
891 listcount(acc_bd
->mbr_zifs
));
894 json_object
*json_mbrs
;
895 json_object
*json_mbr
;
896 struct zebra_if
*zif
;
897 struct listnode
*node
;
900 json_mbrs
= json_object_new_array();
901 for (ALL_LIST_ELEMENTS_RO(acc_bd
->mbr_zifs
, node
, zif
)) {
902 json_mbr
= json_object_new_object();
903 json_object_string_add(json_mbr
, "ifName",
905 json_object_array_add(json_mbrs
, json_mbr
);
907 json_object_object_add(json
, "members", json_mbrs
);
911 static void zebra_evpn_acc_vl_show_entry_detail(struct vty
*vty
,
912 struct zebra_evpn_access_bd
*acc_bd
, json_object
*json
)
914 struct zebra_if
*zif
;
915 struct listnode
*node
;
918 zebra_evpn_acc_vl_json_fill(acc_bd
, json
, true);
920 vty_out(vty
, "VLAN: %u\n", acc_bd
->vid
);
921 vty_out(vty
, " VxLAN Interface: %s\n",
923 acc_bd
->vxlan_zif
->ifp
->name
: "-");
924 vty_out(vty
, " SVI: %s\n",
925 acc_bd
->vlan_zif
? acc_bd
->vlan_zif
->ifp
->name
: "-");
926 vty_out(vty
, " L2-VNI: %d\n",
927 acc_bd
->zevpn
? acc_bd
->zevpn
->vni
: 0);
928 vty_out(vty
, " Member Count: %d\n",
929 listcount(acc_bd
->mbr_zifs
));
930 vty_out(vty
, " Members: \n");
931 for (ALL_LIST_ELEMENTS_RO(acc_bd
->mbr_zifs
, node
, zif
))
932 vty_out(vty
, " %s\n", zif
->ifp
->name
);
937 static void zebra_evpn_acc_vl_show_entry(struct vty
*vty
,
938 struct zebra_evpn_access_bd
*acc_bd
, json_object
*json
)
941 zebra_evpn_acc_vl_json_fill(acc_bd
, json
, false);
943 vty_out(vty
, "%-5u %-15s %-8d %-15s %u\n", acc_bd
->vid
,
944 acc_bd
->vlan_zif
? acc_bd
->vlan_zif
->ifp
->name
: "-",
945 acc_bd
->zevpn
? acc_bd
->zevpn
->vni
: 0,
946 acc_bd
->vxlan_zif
? acc_bd
->vxlan_zif
->ifp
->name
: "-",
947 listcount(acc_bd
->mbr_zifs
));
951 static void zebra_evpn_acc_vl_show_hash(struct hash_bucket
*bucket
, void *ctxt
)
953 struct evpn_mh_show_ctx
*wctx
= ctxt
;
954 struct zebra_evpn_access_bd
*acc_bd
= bucket
->data
;
955 json_object
*json
= NULL
;
958 json
= json_object_new_object();
960 zebra_evpn_acc_vl_show_entry_detail(wctx
->vty
, acc_bd
, json
);
962 zebra_evpn_acc_vl_show_entry(wctx
->vty
, acc_bd
, json
);
964 json_object_array_add(wctx
->json
, json
);
967 void zebra_evpn_acc_vl_show(struct vty
*vty
, bool uj
)
969 struct evpn_mh_show_ctx wctx
;
970 json_object
*json_array
= NULL
;
973 json_array
= json_object_new_array();
975 memset(&wctx
, 0, sizeof(wctx
));
977 wctx
.json
= json_array
;
981 vty_out(vty
, "%-5s %-15s %-8s %-15s %s\n", "VLAN", "SVI",
982 "L2-VNI", "VXLAN-IF", "# Members");
984 hash_iterate(zmh_info
->evpn_vlan_table
, zebra_evpn_acc_vl_show_hash
,
988 vty_json(vty
, json_array
);
991 void zebra_evpn_acc_vl_show_detail(struct vty
*vty
, bool uj
)
993 struct evpn_mh_show_ctx wctx
;
994 json_object
*json_array
= NULL
;
997 json_array
= json_object_new_array();
998 memset(&wctx
, 0, sizeof(wctx
));
1000 wctx
.json
= json_array
;
1003 hash_iterate(zmh_info
->evpn_vlan_table
, zebra_evpn_acc_vl_show_hash
,
1007 vty_json(vty
, json_array
);
1010 void zebra_evpn_acc_vl_show_vid(struct vty
*vty
, bool uj
, vlanid_t vid
)
1012 json_object
*json
= NULL
;
1013 struct zebra_evpn_access_bd
*acc_bd
;
1016 json
= json_object_new_object();
1018 acc_bd
= zebra_evpn_acc_vl_find(vid
);
1020 zebra_evpn_acc_vl_show_entry_detail(vty
, acc_bd
, json
);
1023 vty_out(vty
, "VLAN %u not present\n", vid
);
1027 vty_json(vty
, json
);
1030 /* Initialize VLAN member bitmap on an interface. Although VLAN membership
1031 * is independent of EVPN we only process it if its of interest to EVPN-MH
1032 * i.e. on access ports that can be setup as Ethernet Segments. And that is
1033 * intended as an optimization.
1035 void zebra_evpn_if_init(struct zebra_if
*zif
)
1037 if (!zebra_evpn_is_if_es_capable(zif
))
1040 if (!bf_is_inited(zif
->vlan_bitmap
))
1041 bf_init(zif
->vlan_bitmap
, IF_VLAN_BITMAP_MAX
);
1043 /* if an es_id and sysmac are already present against the interface
1046 zebra_evpn_local_es_update(zif
, &zif
->es_info
.esi
);
1049 /* handle deletion of an access port by removing it from all associated
1050 * broadcast domains.
1052 void zebra_evpn_if_cleanup(struct zebra_if
*zif
)
1055 struct zebra_evpn_es
*es
;
1057 if (bf_is_inited(zif
->vlan_bitmap
)) {
1058 bf_for_each_set_bit(zif
->vlan_bitmap
, vid
, IF_VLAN_BITMAP_MAX
)
1060 zebra_evpn_vl_mbr_deref(vid
, zif
);
1063 bf_free(zif
->vlan_bitmap
);
1066 /* Delete associated Ethernet Segment */
1067 es
= zif
->es_info
.es
;
1069 zebra_evpn_local_es_del(&es
);
1072 /*****************************************************************************
1073 * L2 NH/NHG Management
1074 * A L2 NH entry is programmed in the kernel for every ES-VTEP entry. This
1075 * NH is then added to the L2-ECMP-NHG associated with the ES.
1077 static uint32_t zebra_evpn_nhid_alloc(struct zebra_evpn_es
*es
)
1082 bf_assign_index(zmh_info
->nh_id_bitmap
, id
);
1088 nh_id
= id
| EVPN_NHG_ID_TYPE_BIT
;
1089 /* Add to NHG hash */
1091 (void)hash_get(zmh_info
->nhg_table
, es
, hash_alloc_intern
);
1093 nh_id
= id
| EVPN_NH_ID_TYPE_BIT
;
1099 static void zebra_evpn_nhid_free(uint32_t nh_id
, struct zebra_evpn_es
*es
)
1101 uint32_t id
= (nh_id
& EVPN_NH_ID_VAL_MASK
);
1107 hash_release(zmh_info
->nhg_table
, es
);
1111 bf_release_index(zmh_info
->nh_id_bitmap
, id
);
1114 static unsigned int zebra_evpn_nh_ip_hash_keymake(const void *p
)
1116 const struct zebra_evpn_l2_nh
*nh
= p
;
1118 return jhash_1word(nh
->vtep_ip
.s_addr
, 0);
1121 static bool zebra_evpn_nh_ip_cmp(const void *p1
, const void *p2
)
1123 const struct zebra_evpn_l2_nh
*nh1
= p1
;
1124 const struct zebra_evpn_l2_nh
*nh2
= p2
;
1126 if (nh1
== NULL
&& nh2
== NULL
)
1129 if (nh1
== NULL
|| nh2
== NULL
)
1132 return (nh1
->vtep_ip
.s_addr
== nh2
->vtep_ip
.s_addr
);
1135 static unsigned int zebra_evpn_nhg_hash_keymake(const void *p
)
1137 const struct zebra_evpn_es
*es
= p
;
1139 return jhash_1word(es
->nhg_id
, 0);
1142 static bool zebra_evpn_nhg_cmp(const void *p1
, const void *p2
)
1144 const struct zebra_evpn_es
*es1
= p1
;
1145 const struct zebra_evpn_es
*es2
= p2
;
1147 if (es1
== NULL
&& es2
== NULL
)
1150 if (es1
== NULL
|| es2
== NULL
)
1153 return (es1
->nhg_id
== es2
->nhg_id
);
1156 /* Lookup ES using the NHG id associated with it */
1157 static struct zebra_evpn_es
*zebra_evpn_nhg_find(uint32_t nhg_id
)
1159 struct zebra_evpn_es
*es
;
1160 struct zebra_evpn_es tmp
;
1162 tmp
.nhg_id
= nhg_id
;
1163 es
= hash_lookup(zmh_info
->nhg_table
, &tmp
);
1168 /* Returns TRUE if the NHG is associated with a local ES */
1169 bool zebra_evpn_nhg_is_local_es(uint32_t nhg_id
,
1170 struct zebra_evpn_es
**local_es
)
1172 struct zebra_evpn_es
*es
;
1174 es
= zebra_evpn_nhg_find(nhg_id
);
1175 if (es
&& (es
->flags
& ZEBRA_EVPNES_LOCAL
)) {
1184 /* update remote macs associated with the ES */
1185 static void zebra_evpn_nhg_mac_update(struct zebra_evpn_es
*es
)
1187 struct zebra_mac
*mac
;
1188 struct listnode
*node
;
1191 local_via_nw
= zebra_evpn_es_local_mac_via_network_port(es
);
1192 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1193 zlog_debug("mac update on es %s nhg %s", es
->esi_str
,
1194 (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
)
1198 for (ALL_LIST_ELEMENTS_RO(es
->mac_list
, node
, mac
)) {
1199 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
1200 || (local_via_nw
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
1201 && zebra_evpn_mac_is_static(mac
))) {
1202 if (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
) {
1203 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1205 "%smac %pEA install via es %s nhg 0x%x",
1206 (mac
->flags
& ZEBRA_MAC_REMOTE
)
1209 &mac
->macaddr
, es
->esi_str
,
1211 zebra_evpn_rem_mac_install(
1212 mac
->zevpn
, mac
, false /*was_static*/);
1214 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
1216 "%smac %pEA un-install es %s",
1217 (mac
->flags
& ZEBRA_MAC_REMOTE
)
1220 &mac
->macaddr
, es
->esi_str
);
1221 zebra_evpn_rem_mac_uninstall(mac
->zevpn
, mac
,
1228 /* The MAC ECMP group is activated on the first VTEP */
1229 static void zebra_evpn_nhg_update(struct zebra_evpn_es
*es
)
1231 uint32_t nh_cnt
= 0;
1232 struct nh_grp nh_ids
[ES_VTEP_MAX_CNT
];
1233 struct zebra_evpn_es_vtep
*es_vtep
;
1234 struct listnode
*node
;
1239 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1243 if (nh_cnt
>= ES_VTEP_MAX_CNT
)
1246 memset(&nh_ids
[nh_cnt
], 0, sizeof(struct nh_grp
));
1247 nh_ids
[nh_cnt
].id
= es_vtep
->nh
->nh_id
;
1252 if (IS_ZEBRA_DEBUG_EVPN_MH_NH
) {
1253 char nh_str
[ES_VTEP_LIST_STR_SZ
];
1258 for (i
= 0; i
< nh_cnt
; ++i
) {
1259 snprintf(nh_buf
, sizeof(nh_buf
), "%u ",
1261 strlcat(nh_str
, nh_buf
, sizeof(nh_str
));
1263 zlog_debug("es %s nhg %u add %s", es
->esi_str
,
1264 es
->nhg_id
, nh_str
);
1267 kernel_upd_mac_nhg(es
->nhg_id
, nh_cnt
, nh_ids
);
1268 if (!(es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
)) {
1269 es
->flags
|= ZEBRA_EVPNES_NHG_ACTIVE
;
1270 /* add backup NHG to the br-port */
1271 if ((es
->flags
& ZEBRA_EVPNES_LOCAL
))
1272 zebra_evpn_es_br_port_dplane_update(es
,
1274 zebra_evpn_nhg_mac_update(es
);
1277 if (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
) {
1278 if (IS_ZEBRA_DEBUG_EVPN_MH_NH
)
1279 zlog_debug("es %s nhg %u del", es
->esi_str
,
1281 es
->flags
&= ~ZEBRA_EVPNES_NHG_ACTIVE
;
1282 /* remove backup NHG from the br-port */
1283 if ((es
->flags
& ZEBRA_EVPNES_LOCAL
))
1284 zebra_evpn_es_br_port_dplane_update(es
,
1286 zebra_evpn_nhg_mac_update(es
);
1287 kernel_del_mac_nhg(es
->nhg_id
);
1293 static void zebra_evpn_es_l2_nh_show_entry(struct zebra_evpn_l2_nh
*nh
,
1295 json_object
*json_array
)
1298 json_object
*json
= NULL
;
1300 json
= json_object_new_object();
1301 json_object_string_addf(json
, "vtep", "%pI4", &nh
->vtep_ip
);
1302 json_object_int_add(json
, "nhId", nh
->nh_id
);
1303 json_object_int_add(json
, "refCnt", nh
->ref_cnt
);
1305 json_object_array_add(json_array
, json
);
1307 vty_out(vty
, "%-16pI4 %-10u %u\n", &nh
->vtep_ip
, nh
->nh_id
,
1312 static void zebra_evpn_l2_nh_show_cb(struct hash_bucket
*bucket
, void *ctxt
)
1314 struct zebra_evpn_l2_nh
*nh
= (struct zebra_evpn_l2_nh
*)bucket
->data
;
1315 struct evpn_mh_show_ctx
*wctx
= (struct evpn_mh_show_ctx
*)ctxt
;
1317 zebra_evpn_es_l2_nh_show_entry(nh
, wctx
->vty
, wctx
->json
);
1320 void zebra_evpn_l2_nh_show(struct vty
*vty
, bool uj
)
1322 struct evpn_mh_show_ctx wctx
;
1323 json_object
*json_array
= NULL
;
1326 json_array
= json_object_new_array();
1328 vty_out(vty
, "%-16s %-10s %s\n", "VTEP", "NH id", "#ES");
1331 memset(&wctx
, 0, sizeof(wctx
));
1333 wctx
.json
= json_array
;
1335 hash_iterate(zmh_info
->nh_ip_table
, zebra_evpn_l2_nh_show_cb
, &wctx
);
1338 vty_json(vty
, json_array
);
1341 static struct zebra_evpn_l2_nh
*zebra_evpn_l2_nh_find(struct in_addr vtep_ip
)
1343 struct zebra_evpn_l2_nh
*nh
;
1344 struct zebra_evpn_l2_nh tmp
;
1346 tmp
.vtep_ip
.s_addr
= vtep_ip
.s_addr
;
1347 nh
= hash_lookup(zmh_info
->nh_ip_table
, &tmp
);
1352 static struct zebra_evpn_l2_nh
*zebra_evpn_l2_nh_alloc(struct in_addr vtep_ip
)
1354 struct zebra_evpn_l2_nh
*nh
;
1356 nh
= XCALLOC(MTYPE_L2_NH
, sizeof(*nh
));
1357 nh
->vtep_ip
= vtep_ip
;
1358 (void)hash_get(zmh_info
->nh_ip_table
, nh
, hash_alloc_intern
);
1360 nh
->nh_id
= zebra_evpn_nhid_alloc(NULL
);
1362 hash_release(zmh_info
->nh_ip_table
, nh
);
1363 XFREE(MTYPE_L2_NH
, nh
);
1367 /* install the NH in the dataplane */
1368 kernel_upd_mac_nh(nh
->nh_id
, nh
->vtep_ip
);
1373 static void zebra_evpn_l2_nh_free(struct zebra_evpn_l2_nh
*nh
)
1375 /* delete the NH from the dataplane */
1376 kernel_del_mac_nh(nh
->nh_id
);
1378 zebra_evpn_nhid_free(nh
->nh_id
, NULL
);
1379 hash_release(zmh_info
->nh_ip_table
, nh
);
1380 XFREE(MTYPE_L2_NH
, nh
);
1383 static void zebra_evpn_l2_nh_es_vtep_ref(struct zebra_evpn_es_vtep
*es_vtep
)
1388 es_vtep
->nh
= zebra_evpn_l2_nh_find(es_vtep
->vtep_ip
);
1390 es_vtep
->nh
= zebra_evpn_l2_nh_alloc(es_vtep
->vtep_ip
);
1393 zlog_warn("es %s vtep %pI4 nh ref failed", es_vtep
->es
->esi_str
,
1398 ++es_vtep
->nh
->ref_cnt
;
1400 if (IS_ZEBRA_DEBUG_EVPN_MH_NH
)
1401 zlog_debug("es %s vtep %pI4 nh %u ref %u", es_vtep
->es
->esi_str
,
1402 &es_vtep
->vtep_ip
, es_vtep
->nh
->nh_id
,
1403 es_vtep
->nh
->ref_cnt
);
1405 /* add the NH to the parent NHG */
1406 zebra_evpn_nhg_update(es_vtep
->es
);
1409 static void zebra_evpn_l2_nh_es_vtep_deref(struct zebra_evpn_es_vtep
*es_vtep
)
1411 struct zebra_evpn_l2_nh
*nh
= es_vtep
->nh
;
1420 if (IS_ZEBRA_DEBUG_EVPN_MH_NH
)
1421 zlog_debug("es %s vtep %pI4 nh %u deref %u",
1422 es_vtep
->es
->esi_str
, &es_vtep
->vtep_ip
, nh
->nh_id
,
1425 /* remove the NH from the parent NHG */
1426 zebra_evpn_nhg_update(es_vtep
->es
);
1428 /* uninstall the NH */
1430 zebra_evpn_l2_nh_free(nh
);
1433 /*****************************************************************************/
1434 /* Ethernet Segment Management
1435 * 1. Ethernet Segment is a collection of links attached to the same
1436 * server (MHD) or switch (MHN)
1437 * 2. An Ethernet Segment can span multiple PEs and is identified by the
1439 * 3. Zebra manages the local ESI configuration.
1440 * 4. It also maintains the aliasing that maps an ESI (local or remote)
1441 * to one or more PEs/VTEPs.
1442 * 5. remote ESs are added by BGP (on rxing EAD Type-1 routes)
1444 /* A list of remote VTEPs is maintained for each ES. This list includes -
1445 * 1. VTEPs for which we have imported the ESR i.e. ES-peers
1446 * 2. VTEPs that have an "active" ES-EVI VTEP i.e. EAD-per-ES and EAD-per-EVI
1447 * have been imported into one or more EVPNs
1449 static int zebra_evpn_es_vtep_cmp(void *p1
, void *p2
)
1451 const struct zebra_evpn_es_vtep
*es_vtep1
= p1
;
1452 const struct zebra_evpn_es_vtep
*es_vtep2
= p2
;
1454 return es_vtep1
->vtep_ip
.s_addr
- es_vtep2
->vtep_ip
.s_addr
;
1457 static struct zebra_evpn_es_vtep
*zebra_evpn_es_vtep_new(
1458 struct zebra_evpn_es
*es
, struct in_addr vtep_ip
)
1460 struct zebra_evpn_es_vtep
*es_vtep
;
1462 es_vtep
= XCALLOC(MTYPE_ZES_VTEP
, sizeof(*es_vtep
));
1465 es_vtep
->vtep_ip
.s_addr
= vtep_ip
.s_addr
;
1466 listnode_init(&es_vtep
->es_listnode
, es_vtep
);
1467 listnode_add_sort(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1472 static void zebra_evpn_es_vtep_free(struct zebra_evpn_es_vtep
*es_vtep
)
1474 struct zebra_evpn_es
*es
= es_vtep
->es
;
1476 list_delete_node(es
->es_vtep_list
, &es_vtep
->es_listnode
);
1477 /* update the L2-NHG associated with the ES */
1478 zebra_evpn_l2_nh_es_vtep_deref(es_vtep
);
1479 XFREE(MTYPE_ZES_VTEP
, es_vtep
);
1483 /* check if VTEP is already part of the list */
1484 static struct zebra_evpn_es_vtep
*zebra_evpn_es_vtep_find(
1485 struct zebra_evpn_es
*es
, struct in_addr vtep_ip
)
1487 struct listnode
*node
= NULL
;
1488 struct zebra_evpn_es_vtep
*es_vtep
;
1490 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1491 if (es_vtep
->vtep_ip
.s_addr
== vtep_ip
.s_addr
)
1497 /* flush all the dataplane br-port info associated with the ES */
1498 static bool zebra_evpn_es_br_port_dplane_clear(struct zebra_evpn_es
*es
)
1500 struct in_addr sph_filters
[ES_VTEP_MAX_CNT
];
1502 if (!(es
->flags
& ZEBRA_EVPNES_BR_PORT
))
1505 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1506 zlog_debug("es %s br-port dplane clear", es
->esi_str
);
1508 memset(&sph_filters
, 0, sizeof(sph_filters
));
1509 dplane_br_port_update(es
->zif
->ifp
, false /* non_df */, 0, sph_filters
,
1510 0 /* backup_nhg_id */);
1515 zebra_evpn_es_br_port_dplane_update_needed(struct zebra_evpn_es
*es
)
1517 return (es
->flags
& ZEBRA_EVPNES_NON_DF
)
1518 || (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
)
1519 || listcount(es
->es_vtep_list
);
1522 /* returns TRUE if dplane entry was updated */
1523 static bool zebra_evpn_es_br_port_dplane_update(struct zebra_evpn_es
*es
,
1526 uint32_t backup_nhg_id
;
1527 struct in_addr sph_filters
[ES_VTEP_MAX_CNT
];
1528 struct listnode
*node
= NULL
;
1529 struct zebra_evpn_es_vtep
*es_vtep
;
1530 uint32_t sph_filter_cnt
= 0;
1532 if (!(es
->flags
& ZEBRA_EVPNES_LOCAL
))
1533 return zebra_evpn_es_br_port_dplane_clear(es
);
1535 /* If the ES is not a bridge port there is nothing
1538 if (!(es
->flags
& ZEBRA_EVPNES_BR_PORT
))
1541 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1542 zlog_debug("es %s br-port dplane update by %s", es
->esi_str
,
1544 backup_nhg_id
= (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
) ? es
->nhg_id
: 0;
1546 memset(&sph_filters
, 0, sizeof(sph_filters
));
1547 if (es
->flags
& ZEBRA_EVPNES_BYPASS
) {
1548 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1550 "es %s SPH filter disabled as it is in bypass",
1553 if (listcount(es
->es_vtep_list
) > ES_VTEP_MAX_CNT
) {
1554 zlog_warn("es %s vtep count %d exceeds filter cnt %d",
1555 es
->esi_str
, listcount(es
->es_vtep_list
),
1558 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
,
1561 & ZEBRA_EVPNES_VTEP_DEL_IN_PROG
)
1563 sph_filters
[sph_filter_cnt
] = es_vtep
->vtep_ip
;
1569 dplane_br_port_update(es
->zif
->ifp
, !!(es
->flags
& ZEBRA_EVPNES_NON_DF
),
1570 sph_filter_cnt
, sph_filters
, backup_nhg_id
);
1575 /* returns TRUE if dplane entry was updated */
1576 static bool zebra_evpn_es_df_change(struct zebra_evpn_es
*es
, bool new_non_df
,
1577 const char *caller
, const char *reason
)
1581 old_non_df
= !!(es
->flags
& ZEBRA_EVPNES_NON_DF
);
1583 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1584 zlog_debug("df-change es %s %s to %s; %s: %s", es
->esi_str
,
1585 old_non_df
? "non-df" : "df",
1586 new_non_df
? "non-df" : "df", caller
, reason
);
1588 if (old_non_df
== new_non_df
)
1592 es
->flags
|= ZEBRA_EVPNES_NON_DF
;
1594 es
->flags
&= ~ZEBRA_EVPNES_NON_DF
;
1596 /* update non-DF block filter in the dataplane */
1597 return zebra_evpn_es_br_port_dplane_update(es
, __func__
);
1601 /* returns TRUE if dplane entry was updated */
1602 static bool zebra_evpn_es_run_df_election(struct zebra_evpn_es
*es
,
1605 struct listnode
*node
= NULL
;
1606 struct zebra_evpn_es_vtep
*es_vtep
;
1607 bool new_non_df
= false;
1609 /* If the ES is not ready (i.e. not completely configured) there
1610 * is no need to setup the BUM block filter
1612 if (!(es
->flags
& ZEBRA_EVPNES_LOCAL
)
1613 || (es
->flags
& ZEBRA_EVPNES_BYPASS
)
1614 || !zmh_info
->es_originator_ip
.s_addr
)
1615 return zebra_evpn_es_df_change(es
, new_non_df
, caller
,
1618 /* if oper-state is down DF filtering must be on. when the link comes
1619 * up again dataplane should block BUM till FRR has had the chance
1620 * to run DF election again
1622 if (!(es
->flags
& ZEBRA_EVPNES_OPER_UP
)) {
1624 return zebra_evpn_es_df_change(es
, new_non_df
, caller
,
1628 /* ES was just created; we need to wait for the peers to rx the
1629 * our Type-4 routes and for the switch to import the peers' Type-4
1632 if (es
->df_delay_timer
) {
1634 return zebra_evpn_es_df_change(es
, new_non_df
, caller
,
1638 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
1639 /* Only VTEPs that have advertised the ESR can participate
1642 if (!(es_vtep
->flags
& ZEBRA_EVPNES_VTEP_RXED_ESR
))
1645 /* If the DF alg is not the same we should fall back to
1646 * service-carving. But as service-carving is not supported
1647 * we will stop forwarding BUM
1649 if (es_vtep
->df_alg
!= EVPN_MH_DF_ALG_PREF
) {
1654 /* Peer VTEP wins DF election if -
1655 * the peer-VTEP has higher preference (or)
1656 * the pref is the same but peer's IP address is lower
1658 if ((es_vtep
->df_pref
> es
->df_pref
)
1659 || ((es_vtep
->df_pref
== es
->df_pref
)
1660 && (es_vtep
->vtep_ip
.s_addr
1661 < zmh_info
->es_originator_ip
.s_addr
))) {
1667 return zebra_evpn_es_df_change(es
, new_non_df
, caller
, "elected");
1670 static void zebra_evpn_es_vtep_add(struct zebra_evpn_es
*es
,
1671 struct in_addr vtep_ip
, bool esr_rxed
,
1672 uint8_t df_alg
, uint16_t df_pref
)
1674 struct zebra_evpn_es_vtep
*es_vtep
;
1676 bool dplane_updated
= false;
1678 es_vtep
= zebra_evpn_es_vtep_find(es
, vtep_ip
);
1681 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1682 zlog_debug("es %s vtep %pI4 add",
1683 es
->esi_str
, &vtep_ip
);
1684 es_vtep
= zebra_evpn_es_vtep_new(es
, vtep_ip
);
1685 /* update the L2-NHG associated with the ES */
1686 zebra_evpn_l2_nh_es_vtep_ref(es_vtep
);
1689 old_esr_rxed
= !!(es_vtep
->flags
& ZEBRA_EVPNES_VTEP_RXED_ESR
);
1690 if ((old_esr_rxed
!= esr_rxed
) || (es_vtep
->df_alg
!= df_alg
)
1691 || (es_vtep
->df_pref
!= df_pref
)) {
1692 /* If any of the DF election params changed we need to re-run
1696 es_vtep
->flags
|= ZEBRA_EVPNES_VTEP_RXED_ESR
;
1698 es_vtep
->flags
&= ~ZEBRA_EVPNES_VTEP_RXED_ESR
;
1699 es_vtep
->df_alg
= df_alg
;
1700 es_vtep
->df_pref
= df_pref
;
1701 dplane_updated
= zebra_evpn_es_run_df_election(es
, __func__
);
1703 /* add the vtep to the SPH list */
1704 if (!dplane_updated
&& (es
->flags
& ZEBRA_EVPNES_LOCAL
))
1705 zebra_evpn_es_br_port_dplane_update(es
, __func__
);
1708 static void zebra_evpn_es_vtep_del(struct zebra_evpn_es
*es
,
1709 struct in_addr vtep_ip
)
1711 struct zebra_evpn_es_vtep
*es_vtep
;
1712 bool dplane_updated
= false;
1714 es_vtep
= zebra_evpn_es_vtep_find(es
, vtep_ip
);
1717 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1718 zlog_debug("es %s vtep %pI4 del",
1719 es
->esi_str
, &vtep_ip
);
1720 es_vtep
->flags
|= ZEBRA_EVPNES_VTEP_DEL_IN_PROG
;
1721 if (es_vtep
->flags
& ZEBRA_EVPNES_VTEP_RXED_ESR
) {
1722 es_vtep
->flags
&= ~ZEBRA_EVPNES_VTEP_RXED_ESR
;
1724 zebra_evpn_es_run_df_election(es
, __func__
);
1726 /* remove the vtep from the SPH list */
1727 if (!dplane_updated
&& (es
->flags
& ZEBRA_EVPNES_LOCAL
))
1728 zebra_evpn_es_br_port_dplane_update(es
, __func__
);
1729 zebra_evpn_es_vtep_free(es_vtep
);
1733 /* compare ES-IDs for the global ES RB tree */
1734 static int zebra_es_rb_cmp(const struct zebra_evpn_es
*es1
,
1735 const struct zebra_evpn_es
*es2
)
1737 return memcmp(&es1
->esi
, &es2
->esi
, ESI_BYTES
);
1739 RB_GENERATE(zebra_es_rb_head
, zebra_evpn_es
, rb_node
, zebra_es_rb_cmp
);
1742 struct zebra_evpn_es
*zebra_evpn_es_find(const esi_t
*esi
)
1744 struct zebra_evpn_es tmp
;
1746 memcpy(&tmp
.esi
, esi
, sizeof(esi_t
));
1747 return RB_FIND(zebra_es_rb_head
, &zmh_info
->es_rb_tree
, &tmp
);
1750 /* A new local es is created when a local-es-id and sysmac is configured
1751 * against an interface.
1753 static struct zebra_evpn_es
*zebra_evpn_es_new(const esi_t
*esi
)
1755 struct zebra_evpn_es
*es
;
1757 if (!memcmp(esi
, zero_esi
, sizeof(esi_t
)))
1760 es
= XCALLOC(MTYPE_ZES
, sizeof(struct zebra_evpn_es
));
1763 memcpy(&es
->esi
, esi
, sizeof(esi_t
));
1764 esi_to_str(&es
->esi
, es
->esi_str
, sizeof(es
->esi_str
));
1766 /* Add to rb_tree */
1767 RB_INSERT(zebra_es_rb_head
, &zmh_info
->es_rb_tree
, es
);
1769 /* Initialise the ES-EVI list */
1770 es
->es_evi_list
= list_new();
1771 listset_app_node_mem(es
->es_evi_list
);
1773 /* Initialise the VTEP list */
1774 es
->es_vtep_list
= list_new();
1775 listset_app_node_mem(es
->es_vtep_list
);
1776 es
->es_vtep_list
->cmp
= zebra_evpn_es_vtep_cmp
;
1778 /* mac entries associated with the ES */
1779 es
->mac_list
= list_new();
1780 listset_app_node_mem(es
->mac_list
);
1783 es
->nhg_id
= zebra_evpn_nhid_alloc(es
);
1785 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1786 zlog_debug("es %s nhg %u new", es
->esi_str
, es
->nhg_id
);
1791 /* Free a given ES -
1792 * This just frees appropriate memory, caller should have taken other
1795 static void zebra_evpn_es_free(struct zebra_evpn_es
**esp
)
1797 struct zebra_evpn_es
*es
= *esp
;
1799 /* If the ES has a local or remote reference it cannot be freed.
1800 * Free is also prevented if there are MAC entries referencing
1803 if ((es
->flags
& (ZEBRA_EVPNES_LOCAL
| ZEBRA_EVPNES_REMOTE
)) ||
1804 listcount(es
->mac_list
))
1807 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1808 zlog_debug("es %s free", es
->esi_str
);
1810 /* If the NHG is still installed uninstall it and free the id */
1811 if (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
) {
1812 es
->flags
&= ~ZEBRA_EVPNES_NHG_ACTIVE
;
1813 kernel_del_mac_nhg(es
->nhg_id
);
1815 zebra_evpn_nhid_free(es
->nhg_id
, es
);
1817 /* cleanup resources maintained against the ES */
1818 list_delete(&es
->es_evi_list
);
1819 list_delete(&es
->es_vtep_list
);
1820 list_delete(&es
->mac_list
);
1822 /* remove from the VNI-ESI rb tree */
1823 RB_REMOVE(zebra_es_rb_head
, &zmh_info
->es_rb_tree
, es
);
1825 XFREE(MTYPE_ZES
, es
);
1830 /* Inform BGP about local ES addition */
1831 static int zebra_evpn_es_send_add_to_client(struct zebra_evpn_es
*es
)
1833 struct zserv
*client
;
1838 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1839 /* BGP may not be running. */
1843 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1845 zclient_create_header(s
, ZEBRA_LOCAL_ES_ADD
, zebra_vrf_get_evpn_id());
1846 stream_put(s
, &es
->esi
, sizeof(esi_t
));
1847 stream_put_ipv4(s
, zmh_info
->es_originator_ip
.s_addr
);
1848 oper_up
= !!(es
->flags
& ZEBRA_EVPNES_OPER_UP
);
1849 stream_putc(s
, oper_up
);
1850 stream_putw(s
, es
->df_pref
);
1851 bypass
= !!(es
->flags
& ZEBRA_EVPNES_BYPASS
);
1852 stream_putc(s
, bypass
);
1854 /* Write packet size. */
1855 stream_putw_at(s
, 0, stream_get_endp(s
));
1857 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1859 "send add local es %s %pI4 active %u df_pref %u%s to %s",
1860 es
->esi_str
, &zmh_info
->es_originator_ip
, oper_up
,
1861 es
->df_pref
, bypass
? " bypass" : "",
1862 zebra_route_string(client
->proto
));
1864 client
->local_es_add_cnt
++;
1865 return zserv_send_message(client
, s
);
1868 /* Inform BGP about local ES deletion */
1869 static int zebra_evpn_es_send_del_to_client(struct zebra_evpn_es
*es
)
1871 struct zserv
*client
;
1874 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
1875 /* BGP may not be running. */
1879 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
1882 zclient_create_header(s
, ZEBRA_LOCAL_ES_DEL
, zebra_vrf_get_evpn_id());
1883 stream_put(s
, &es
->esi
, sizeof(esi_t
));
1885 /* Write packet size. */
1886 stream_putw_at(s
, 0, stream_get_endp(s
));
1888 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
1889 zlog_debug("send del local es %s to %s", es
->esi_str
,
1890 zebra_route_string(client
->proto
));
1892 client
->local_es_del_cnt
++;
1893 return zserv_send_message(client
, s
);
1896 static void zebra_evpn_es_re_eval_send_to_client(struct zebra_evpn_es
*es
,
1897 bool es_evi_re_reval
)
1901 struct listnode
*node
;
1902 struct zebra_evpn_es_evi
*es_evi
;
1904 old_ready
= !!(es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
);
1906 if ((es
->flags
& ZEBRA_EVPNES_LOCAL
) &&
1907 zmh_info
->es_originator_ip
.s_addr
)
1908 es
->flags
|= ZEBRA_EVPNES_READY_FOR_BGP
;
1910 es
->flags
&= ~ZEBRA_EVPNES_READY_FOR_BGP
;
1912 new_ready
= !!(es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
);
1913 if (old_ready
== new_ready
)
1917 zebra_evpn_es_send_add_to_client(es
);
1919 zebra_evpn_es_send_del_to_client(es
);
1921 /* re-eval associated EVIs */
1922 if (es_evi_re_reval
) {
1923 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
, node
, es_evi
)) {
1924 if (!(es_evi
->flags
& ZEBRA_EVPNES_EVI_LOCAL
))
1926 zebra_evpn_es_evi_re_eval_send_to_client(es_evi
);
1931 void zebra_evpn_es_send_all_to_client(bool add
)
1933 struct listnode
*es_node
;
1934 struct listnode
*evi_node
;
1935 struct zebra_evpn_es
*es
;
1936 struct zebra_evpn_es_evi
*es_evi
;
1941 for (ALL_LIST_ELEMENTS_RO(zmh_info
->local_es_list
, es_node
, es
)) {
1942 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
) {
1944 zebra_evpn_es_send_add_to_client(es
);
1945 for (ALL_LIST_ELEMENTS_RO(es
->es_evi_list
,
1946 evi_node
, es_evi
)) {
1947 if (!(es_evi
->flags
&
1948 ZEBRA_EVPNES_EVI_READY_FOR_BGP
))
1952 zebra_evpn_es_evi_send_to_client(
1956 zebra_evpn_es_evi_send_to_client(
1961 zebra_evpn_es_send_del_to_client(es
);
1966 /* walk the vlan bitmap associated with the zif and create or delete
1967 * es_evis for all vlans associated with a VNI.
1968 * XXX: This API is really expensive. optimize later if possible.
1970 static void zebra_evpn_es_setup_evis(struct zebra_evpn_es
*es
)
1972 struct zebra_if
*zif
= es
->zif
;
1974 struct zebra_evpn_access_bd
*acc_bd
;
1976 if (!bf_is_inited(zif
->vlan_bitmap
))
1979 bf_for_each_set_bit(zif
->vlan_bitmap
, vid
, IF_VLAN_BITMAP_MAX
) {
1980 acc_bd
= zebra_evpn_acc_vl_find(vid
);
1982 zebra_evpn_local_es_evi_add(es
, acc_bd
->zevpn
);
1986 static void zebra_evpn_flush_local_mac(struct zebra_mac
*mac
,
1987 struct interface
*ifp
)
1989 struct zebra_if
*zif
;
1990 struct interface
*br_ifp
;
1994 br_ifp
= zif
->brslave_info
.br_if
;
1998 if (mac
->zevpn
->vxlan_if
) {
1999 zif
= mac
->zevpn
->vxlan_if
->info
;
2000 vid
= zif
->l2info
.vxl
.access_vlan
;
2005 /* delete the local mac from the dataplane */
2006 dplane_local_mac_del(ifp
, br_ifp
, vid
, &mac
->macaddr
);
2007 /* delete the local mac in zebra */
2008 zebra_evpn_del_local_mac(mac
->zevpn
, mac
, true);
2011 static void zebra_evpn_es_flush_local_macs(struct zebra_evpn_es
*es
,
2012 struct interface
*ifp
, bool add
)
2014 struct zebra_mac
*mac
;
2015 struct listnode
*node
;
2016 struct listnode
*nnode
;
2018 for (ALL_LIST_ELEMENTS(es
->mac_list
, node
, nnode
, mac
)) {
2019 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
2022 /* If ES is being attached/detached from the access port we
2023 * need to clear local activity and peer activity and start
2025 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2026 zlog_debug("VNI %u mac %pEA update; local ES %s %s",
2029 es
->esi_str
, add
? "add" : "del");
2030 zebra_evpn_flush_local_mac(mac
, ifp
);
2034 void zebra_evpn_es_local_br_port_update(struct zebra_if
*zif
)
2036 struct zebra_evpn_es
*es
= zif
->es_info
.es
;
2037 bool old_br_port
= !!(es
->flags
& ZEBRA_EVPNES_BR_PORT
);
2040 if (zif
->brslave_info
.bridge_ifindex
!= IFINDEX_INTERNAL
)
2041 es
->flags
|= ZEBRA_EVPNES_BR_PORT
;
2043 es
->flags
&= ~ZEBRA_EVPNES_BR_PORT
;
2045 new_br_port
= !!(es
->flags
& ZEBRA_EVPNES_BR_PORT
);
2046 if (old_br_port
== new_br_port
)
2049 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2050 zlog_debug("es %s br_port change old %u new %u", es
->esi_str
,
2051 old_br_port
, new_br_port
);
2053 /* update the dataplane br_port attrs */
2054 if (new_br_port
&& zebra_evpn_es_br_port_dplane_update_needed(es
))
2055 zebra_evpn_es_br_port_dplane_update(es
, __func__
);
2058 /* On config of first local-ES turn off DAD */
2059 static void zebra_evpn_mh_dup_addr_detect_off(void)
2061 struct zebra_vrf
*zvrf
;
2065 if (zmh_info
->flags
& ZEBRA_EVPN_MH_DUP_ADDR_DETECT_OFF
)
2068 zvrf
= zebra_vrf_get_evpn();
2070 zmh_info
->flags
|= ZEBRA_EVPN_MH_DUP_ADDR_DETECT_OFF
;
2074 old_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
2075 zmh_info
->flags
|= ZEBRA_EVPN_MH_DUP_ADDR_DETECT_OFF
;
2076 new_detect
= zebra_evpn_do_dup_addr_detect(zvrf
);
2078 if (old_detect
&& !new_detect
) {
2079 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2081 "evpn-mh config caused DAD addr detect chg from %s to %s",
2082 old_detect
? "on" : "off",
2083 new_detect
? "on" : "off");
2084 zebra_vxlan_clear_dup_detect_vni_all(zvrf
);
2088 /* On config of first local-ES turn off advertisement of STALE/DELAY/PROBE
2091 static void zebra_evpn_mh_advertise_reach_neigh_only(void)
2093 if (zmh_info
->flags
& ZEBRA_EVPN_MH_ADV_REACHABLE_NEIGH_ONLY
)
2096 zmh_info
->flags
|= ZEBRA_EVPN_MH_ADV_REACHABLE_NEIGH_ONLY
;
2097 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2098 zlog_debug("evpn-mh: only REACHABLE neigh advertised");
2100 /* XXX - if STALE/DELAY/PROBE neighs were previously advertised we
2101 * need to withdraw them
2105 /* On config of first local-ES turn on advertisement of local SVI-MAC */
2106 static void zebra_evpn_mh_advertise_svi_mac(void)
2108 if (zmh_info
->flags
& ZEBRA_EVPN_MH_ADV_SVI_MAC
)
2111 zmh_info
->flags
|= ZEBRA_EVPN_MH_ADV_SVI_MAC
;
2112 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2113 zlog_debug("evpn-mh: advertise SVI MAC");
2115 /* walk through all SVIs and see if we need to advertise the MAC */
2116 zebra_evpn_acc_vl_adv_svi_mac_all();
2119 static void zebra_evpn_es_df_delay_exp_cb(struct thread
*t
)
2121 struct zebra_evpn_es
*es
;
2125 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2126 zlog_debug("es %s df-delay expired", es
->esi_str
);
2128 zebra_evpn_es_run_df_election(es
, __func__
);
2131 /* currently there is no global config to turn on MH instead we use
2132 * the addition of the first local Ethernet Segment as the trigger to
2133 * init MH specific processing
2135 static void zebra_evpn_mh_on_first_local_es(void)
2137 zebra_evpn_mh_dup_addr_detect_off();
2138 zebra_evpn_mh_advertise_reach_neigh_only();
2139 zebra_evpn_mh_advertise_svi_mac();
2142 static void zebra_evpn_es_local_info_set(struct zebra_evpn_es
*es
,
2143 struct zebra_if
*zif
)
2145 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
2148 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2149 zlog_debug("local es %s add; nhg %u if %s", es
->esi_str
,
2150 es
->nhg_id
, zif
->ifp
->name
);
2152 zebra_evpn_mh_on_first_local_es();
2154 es
->flags
|= ZEBRA_EVPNES_LOCAL
;
2155 listnode_init(&es
->local_es_listnode
, es
);
2156 listnode_add(zmh_info
->local_es_list
, &es
->local_es_listnode
);
2158 /* attach es to interface */
2159 zif
->es_info
.es
= es
;
2160 es
->df_pref
= zif
->es_info
.df_pref
? zif
->es_info
.df_pref
2161 : EVPN_MH_DF_PREF_DEFAULT
;
2163 /* attach interface to es */
2165 if (if_is_operative(zif
->ifp
))
2166 es
->flags
|= ZEBRA_EVPNES_OPER_UP
;
2168 if (zif
->brslave_info
.bridge_ifindex
!= IFINDEX_INTERNAL
)
2169 es
->flags
|= ZEBRA_EVPNES_BR_PORT
;
2171 /* inherit the bypass flag from the interface */
2172 if (zif
->flags
& ZIF_FLAG_LACP_BYPASS
)
2173 es
->flags
|= ZEBRA_EVPNES_BYPASS
;
2175 /* setup base-vni if one doesn't already exist; the ES will get sent
2176 * to BGP as a part of that process
2178 if (!zmh_info
->es_base_evpn
)
2179 zebra_evpn_es_get_one_base_evpn();
2181 /* send notification to bgp */
2182 zebra_evpn_es_re_eval_send_to_client(es
,
2183 false /* es_evi_re_reval */);
2185 /* Start the DF delay timer on the local ES */
2186 if (!es
->df_delay_timer
)
2187 thread_add_timer(zrouter
.master
, zebra_evpn_es_df_delay_exp_cb
,
2188 es
, ZEBRA_EVPN_MH_DF_DELAY_TIME
,
2189 &es
->df_delay_timer
);
2191 /* See if the local VTEP can function as DF on the ES */
2192 if (!zebra_evpn_es_run_df_election(es
, __func__
)) {
2193 /* check if the dplane entry needs to be re-programmed as a
2194 * result of some thing other than DF status change
2196 if (zebra_evpn_es_br_port_dplane_update_needed(es
))
2197 zebra_evpn_es_br_port_dplane_update(es
, __func__
);
2201 /* Setup ES-EVIs for all VxLAN stretched VLANs associated with
2204 zebra_evpn_es_setup_evis(es
);
2205 /* if there any local macs referring to the ES as dest we
2206 * need to clear the contents and start over
2208 zebra_evpn_es_flush_local_macs(es
, zif
->ifp
, true);
2210 /* inherit EVPN protodown flags on the access port */
2211 zebra_evpn_mh_update_protodown_es(es
, true /*resync_dplane*/);
2214 static void zebra_evpn_es_local_info_clear(struct zebra_evpn_es
**esp
)
2216 struct zebra_if
*zif
;
2217 struct zebra_evpn_es
*es
= *esp
;
2218 bool dplane_updated
= false;
2220 if (!(es
->flags
& ZEBRA_EVPNES_LOCAL
))
2225 /* if there any local macs referring to the ES as dest we
2226 * need to clear the contents and start over
2228 zebra_evpn_es_flush_local_macs(es
, zif
->ifp
, false);
2230 es
->flags
&= ~(ZEBRA_EVPNES_LOCAL
| ZEBRA_EVPNES_READY_FOR_BGP
);
2232 THREAD_OFF(es
->df_delay_timer
);
2234 /* clear EVPN protodown flags on the access port */
2235 zebra_evpn_mh_clear_protodown_es(es
);
2237 /* remove the DF filter */
2238 dplane_updated
= zebra_evpn_es_run_df_election(es
, __func__
);
2240 /* flush the BUM filters and backup NHG */
2241 if (!dplane_updated
)
2242 zebra_evpn_es_br_port_dplane_clear(es
);
2244 /* clear the es from the parent interface */
2245 zif
->es_info
.es
= NULL
;
2248 /* clear all local flags associated with the ES */
2249 es
->flags
&= ~(ZEBRA_EVPNES_OPER_UP
| ZEBRA_EVPNES_BR_PORT
2250 | ZEBRA_EVPNES_BYPASS
);
2252 /* remove from the ES list */
2253 list_delete_node(zmh_info
->local_es_list
, &es
->local_es_listnode
);
2255 /* free up the ES if there is no remote reference */
2256 zebra_evpn_es_free(esp
);
2259 /* Delete an ethernet segment and inform BGP */
2260 static void zebra_evpn_local_es_del(struct zebra_evpn_es
**esp
)
2262 struct zebra_evpn_es_evi
*es_evi
;
2263 struct listnode
*node
= NULL
;
2264 struct listnode
*nnode
= NULL
;
2265 struct zebra_if
*zif
;
2266 struct zebra_evpn_es
*es
= *esp
;
2268 if (!CHECK_FLAG(es
->flags
, ZEBRA_EVPNES_LOCAL
))
2271 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
) {
2273 zlog_debug("local es %s del; nhg %u if %s", es
->esi_str
,
2274 es
->nhg_id
, zif
? zif
->ifp
->name
: "-");
2277 /* remove all ES-EVIs associated with the ES */
2278 for (ALL_LIST_ELEMENTS(es
->es_evi_list
, node
, nnode
, es_evi
))
2279 zebra_evpn_local_es_evi_do_del(es_evi
);
2281 /* send a del if the ES had been sent to BGP earlier */
2282 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
2283 zebra_evpn_es_send_del_to_client(es
);
2285 zebra_evpn_es_local_info_clear(esp
);
2288 /* eval remote info associated with the ES */
2289 static void zebra_evpn_es_remote_info_re_eval(struct zebra_evpn_es
**esp
)
2291 struct zebra_evpn_es
*es
= *esp
;
2293 /* if there are remote VTEPs the ES-EVI is classified as "remote" */
2294 if (listcount(es
->es_vtep_list
)) {
2295 if (!(es
->flags
& ZEBRA_EVPNES_REMOTE
)) {
2296 es
->flags
|= ZEBRA_EVPNES_REMOTE
;
2297 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2298 zlog_debug("remote es %s add; nhg %u",
2299 es
->esi_str
, es
->nhg_id
);
2302 if (es
->flags
& ZEBRA_EVPNES_REMOTE
) {
2303 es
->flags
&= ~ZEBRA_EVPNES_REMOTE
;
2304 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2305 zlog_debug("remote es %s del; nhg %u",
2306 es
->esi_str
, es
->nhg_id
);
2307 zebra_evpn_es_free(esp
);
2312 /* A new local es is created when a local-es-id and sysmac is configured
2313 * against an interface.
2315 static int zebra_evpn_local_es_update(struct zebra_if
*zif
, esi_t
*esi
)
2317 struct zebra_evpn_es
*old_es
= zif
->es_info
.es
;
2318 struct zebra_evpn_es
*es
;
2320 memcpy(&zif
->es_info
.esi
, esi
, sizeof(*esi
));
2321 if (old_es
&& !memcmp(&old_es
->esi
, esi
, sizeof(*esi
)))
2322 /* dup - nothing to be done */
2325 /* release the old_es against the zif */
2327 zebra_evpn_local_es_del(&old_es
);
2329 es
= zebra_evpn_es_find(esi
);
2331 /* if it exists against another interface flag an error */
2332 if (es
->zif
&& es
->zif
!= zif
) {
2333 memset(&zif
->es_info
.esi
, 0, sizeof(*esi
));
2338 es
= zebra_evpn_es_new(esi
);
2342 zebra_evpn_es_local_info_set(es
, zif
);
2347 static int zebra_evpn_type3_esi_update(struct zebra_if
*zif
, uint32_t lid
,
2348 struct ethaddr
*sysmac
)
2350 struct zebra_evpn_es
*old_es
= zif
->es_info
.es
;
2353 int field_bytes
= 0;
2355 /* Complete config of the ES-ID bootstraps the ES */
2356 if (!lid
|| is_zero_mac(sysmac
)) {
2358 memset(&zif
->es_info
.esi
, 0, sizeof(zif
->es_info
.esi
));
2359 /* if in ES is attached to zif delete it */
2361 zebra_evpn_local_es_del(&old_es
);
2365 /* build 10-byte type-3-ESI -
2366 * Type(1-byte), MAC(6-bytes), ES-LID (3-bytes)
2369 esi
.val
[offset
] = ESI_TYPE_MAC
;
2370 offset
+= field_bytes
;
2372 field_bytes
= ETH_ALEN
;
2373 memcpy(&esi
.val
[offset
], (uint8_t *)sysmac
, field_bytes
);
2374 offset
+= field_bytes
;
2376 esi
.val
[offset
++] = (uint8_t)(lid
>> 16);
2377 esi
.val
[offset
++] = (uint8_t)(lid
>> 8);
2378 esi
.val
[offset
++] = (uint8_t)lid
;
2380 return zebra_evpn_local_es_update(zif
, &esi
);
2383 int zebra_evpn_remote_es_del(const esi_t
*esi
, struct in_addr vtep_ip
)
2385 char buf
[ESI_STR_LEN
];
2386 struct zebra_evpn_es
*es
;
2388 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2389 zlog_debug("remote es %s vtep %pI4 del",
2390 esi_to_str(esi
, buf
, sizeof(buf
)), &vtep_ip
);
2392 es
= zebra_evpn_es_find(esi
);
2394 zlog_warn("remote es %s vtep %pI4 del failed, es missing",
2395 esi_to_str(esi
, buf
, sizeof(buf
)), &vtep_ip
);
2399 zebra_evpn_es_vtep_del(es
, vtep_ip
);
2400 zebra_evpn_es_remote_info_re_eval(&es
);
2405 /* force delete a remote ES on the way down */
2406 static void zebra_evpn_remote_es_flush(struct zebra_evpn_es
**esp
)
2408 struct zebra_evpn_es_vtep
*es_vtep
;
2409 struct listnode
*node
;
2410 struct listnode
*nnode
;
2411 struct zebra_evpn_es
*es
= *esp
;
2413 for (ALL_LIST_ELEMENTS(es
->es_vtep_list
, node
, nnode
, es_vtep
)) {
2414 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2415 zlog_debug("es %s vtep %pI4 flush",
2418 zebra_evpn_es_vtep_free(es_vtep
);
2420 zebra_evpn_es_remote_info_re_eval(esp
);
2423 int zebra_evpn_remote_es_add(const esi_t
*esi
, struct in_addr vtep_ip
,
2424 bool esr_rxed
, uint8_t df_alg
, uint16_t df_pref
)
2426 char buf
[ESI_STR_LEN
];
2427 struct zebra_evpn_es
*es
;
2429 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2430 zlog_debug("remote es %s vtep %pI4 add %s df_alg %d df_pref %d",
2431 esi_to_str(esi
, buf
, sizeof(buf
)),
2432 &vtep_ip
, esr_rxed
? "esr" : "", df_alg
,
2435 es
= zebra_evpn_es_find(esi
);
2437 es
= zebra_evpn_es_new(esi
);
2440 "remote es %s vtep %pI4 add failed, es missing",
2441 esi_to_str(esi
, buf
, sizeof(buf
)), &vtep_ip
);
2446 if (df_alg
!= EVPN_MH_DF_ALG_PREF
)
2448 "remote es %s vtep %pI4 add %s with unsupported df_alg %d",
2449 esi_to_str(esi
, buf
, sizeof(buf
)), &vtep_ip
,
2450 esr_rxed
? "esr" : "", df_alg
);
2452 zebra_evpn_es_vtep_add(es
, vtep_ip
, esr_rxed
, df_alg
, df_pref
);
2453 zebra_evpn_es_remote_info_re_eval(&es
);
2458 void zebra_evpn_proc_remote_es(ZAPI_HANDLER_ARGS
)
2461 struct in_addr vtep_ip
;
2464 if (!is_evpn_enabled()) {
2466 "%s: EVPN not enabled yet we received a es_add zapi call",
2471 memset(&esi
, 0, sizeof(esi_t
));
2474 STREAM_GET(&esi
, s
, sizeof(esi_t
));
2475 STREAM_GET(&vtep_ip
.s_addr
, s
, sizeof(vtep_ip
.s_addr
));
2477 if (hdr
->command
== ZEBRA_REMOTE_ES_VTEP_ADD
) {
2478 uint32_t zapi_flags
;
2483 STREAM_GETL(s
, zapi_flags
);
2484 esr_rxed
= (zapi_flags
& ZAPI_ES_VTEP_FLAG_ESR_RXED
) ? true
2486 STREAM_GETC(s
, df_alg
);
2487 STREAM_GETW(s
, df_pref
);
2488 zebra_rib_queue_evpn_rem_es_add(&esi
, &vtep_ip
, esr_rxed
,
2491 zebra_rib_queue_evpn_rem_es_del(&esi
, &vtep_ip
);
2498 void zebra_evpn_es_mac_deref_entry(struct zebra_mac
*mac
)
2500 struct zebra_evpn_es
*es
= mac
->es
;
2506 list_delete_node(es
->mac_list
, &mac
->es_listnode
);
2507 if (!listcount(es
->mac_list
))
2508 zebra_evpn_es_free(&es
);
2511 /* Associate a MAC entry with a local or remote ES. Returns false if there
2514 bool zebra_evpn_es_mac_ref_entry(struct zebra_mac
*mac
,
2515 struct zebra_evpn_es
*es
)
2521 zebra_evpn_es_mac_deref_entry(mac
);
2527 listnode_init(&mac
->es_listnode
, mac
);
2528 listnode_add(es
->mac_list
, &mac
->es_listnode
);
2533 bool zebra_evpn_es_mac_ref(struct zebra_mac
*mac
, const esi_t
*esi
)
2535 struct zebra_evpn_es
*es
;
2537 es
= zebra_evpn_es_find(esi
);
2539 /* If non-zero esi implicitly create a new ES */
2540 if (memcmp(esi
, zero_esi
, sizeof(esi_t
))) {
2541 es
= zebra_evpn_es_new(esi
);
2542 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2543 zlog_debug("auto es %s add on mac ref",
2548 return zebra_evpn_es_mac_ref_entry(mac
, es
);
2551 /* Inform BGP about local ES-EVI add or del */
2552 static int zebra_evpn_es_evi_send_to_client(struct zebra_evpn_es
*es
,
2553 struct zebra_evpn
*zevpn
, bool add
)
2555 struct zserv
*client
;
2558 client
= zserv_find_client(ZEBRA_ROUTE_BGP
, 0);
2559 /* BGP may not be running. */
2563 s
= stream_new(ZEBRA_MAX_PACKET_SIZ
);
2565 zclient_create_header(s
,
2566 add
? ZEBRA_LOCAL_ES_EVI_ADD
: ZEBRA_LOCAL_ES_EVI_DEL
,
2567 zebra_vrf_get_evpn_id());
2568 stream_put(s
, &es
->esi
, sizeof(esi_t
));
2569 stream_putl(s
, zevpn
->vni
);
2571 /* Write packet size. */
2572 stream_putw_at(s
, 0, stream_get_endp(s
));
2574 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2575 zlog_debug("send %s local es %s evi %u to %s",
2576 add
? "add" : "del",
2577 es
->esi_str
, zevpn
->vni
,
2578 zebra_route_string(client
->proto
));
2580 client
->local_es_add_cnt
++;
2581 return zserv_send_message(client
, s
);
2584 /* sysmac part of a local ESI has changed */
2585 static int zebra_evpn_es_sys_mac_update(struct zebra_if
*zif
,
2586 struct ethaddr
*sysmac
)
2590 rv
= zebra_evpn_type3_esi_update(zif
, zif
->es_info
.lid
, sysmac
);
2592 memcpy(&zif
->es_info
.sysmac
, sysmac
, sizeof(struct ethaddr
));
2597 /* local-ID part of ESI has changed */
2598 static int zebra_evpn_es_lid_update(struct zebra_if
*zif
, uint32_t lid
)
2602 rv
= zebra_evpn_type3_esi_update(zif
, lid
, &zif
->es_info
.sysmac
);
2604 zif
->es_info
.lid
= lid
;
2609 /* type-0 esi has changed */
2610 static int zebra_evpn_es_type0_esi_update(struct zebra_if
*zif
, esi_t
*esi
)
2614 rv
= zebra_evpn_local_es_update(zif
, esi
);
2616 /* clear the old es_lid, es_sysmac - type-0 is being set so old
2617 * type-3 params need to be flushed
2619 memset(&zif
->es_info
.sysmac
, 0, sizeof(struct ethaddr
));
2620 zif
->es_info
.lid
= 0;
2625 void zebra_evpn_es_cleanup(void)
2627 struct zebra_evpn_es
*es
;
2628 struct zebra_evpn_es
*es_next
;
2630 RB_FOREACH_SAFE(es
, zebra_es_rb_head
,
2631 &zmh_info
->es_rb_tree
, es_next
) {
2632 zebra_evpn_local_es_del(&es
);
2634 zebra_evpn_remote_es_flush(&es
);
2638 static void zebra_evpn_es_df_pref_update(struct zebra_if
*zif
, uint16_t df_pref
)
2640 struct zebra_evpn_es
*es
;
2643 if (zif
->es_info
.df_pref
== df_pref
)
2646 zif
->es_info
.df_pref
= df_pref
;
2647 es
= zif
->es_info
.es
;
2652 tmp_pref
= zif
->es_info
.df_pref
? zif
->es_info
.df_pref
2653 : EVPN_MH_DF_PREF_DEFAULT
;
2655 if (es
->df_pref
== tmp_pref
)
2658 es
->df_pref
= tmp_pref
;
2659 /* run df election */
2660 zebra_evpn_es_run_df_election(es
, __func__
);
2662 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
2663 zebra_evpn_es_send_add_to_client(es
);
2666 /* If bypass mode on an es changed we set all local macs to
2667 * inactive and drop the sync info
2669 static void zebra_evpn_es_bypass_update_macs(struct zebra_evpn_es
*es
,
2670 struct interface
*ifp
, bool bypass
)
2672 struct zebra_mac
*mac
;
2673 struct listnode
*node
;
2674 struct listnode
*nnode
;
2675 struct zebra_if
*zif
;
2677 /* Flush all MACs linked to the ES */
2678 for (ALL_LIST_ELEMENTS(es
->mac_list
, node
, nnode
, mac
)) {
2679 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
2682 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2683 zlog_debug("VNI %u mac %pEA %s update es %s",
2686 bypass
? "bypass" : "non-bypass",
2688 zebra_evpn_flush_local_mac(mac
, ifp
);
2691 /* While in bypass-mode locally learnt MACs are linked
2692 * to the access port instead of the ES
2698 for (ALL_LIST_ELEMENTS(zif
->mac_list
, node
, nnode
, mac
)) {
2699 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
2702 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2703 zlog_debug("VNI %u mac %pEA %s update ifp %s",
2706 bypass
? "bypass" : "non-bypass", ifp
->name
);
2707 zebra_evpn_flush_local_mac(mac
, ifp
);
2711 void zebra_evpn_es_bypass_update(struct zebra_evpn_es
*es
,
2712 struct interface
*ifp
, bool bypass
)
2715 bool dplane_updated
;
2717 old_bypass
= !!(es
->flags
& ZEBRA_EVPNES_BYPASS
);
2718 if (old_bypass
== bypass
)
2722 es
->flags
|= ZEBRA_EVPNES_BYPASS
;
2724 es
->flags
&= ~ZEBRA_EVPNES_BYPASS
;
2726 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2727 zlog_debug("bond %s es %s lacp bypass changed to %s", ifp
->name
,
2728 es
->esi_str
, bypass
? "on" : "off");
2730 /* send bypass update to BGP */
2731 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
2732 zebra_evpn_es_send_add_to_client(es
);
2734 zebra_evpn_es_bypass_update_macs(es
, ifp
, bypass
);
2736 /* re-run DF election */
2737 dplane_updated
= zebra_evpn_es_run_df_election(es
, __func__
);
2739 /* disable SPH filter */
2740 if (!dplane_updated
&& (es
->flags
& ZEBRA_EVPNES_LOCAL
)
2741 && (listcount(es
->es_vtep_list
) > ES_VTEP_MAX_CNT
))
2742 zebra_evpn_es_br_port_dplane_update(es
, __func__
);
2745 static void zebra_evpn_es_bypass_cfg_update(struct zebra_if
*zif
, bool bypass
)
2747 bool old_bypass
= !!(zif
->es_info
.flags
& ZIF_CFG_ES_FLAG_BYPASS
);
2749 if (old_bypass
== bypass
)
2753 zif
->es_info
.flags
|= ZIF_CFG_ES_FLAG_BYPASS
;
2755 zif
->es_info
.flags
&= ~ZIF_CFG_ES_FLAG_BYPASS
;
2758 if (zif
->es_info
.es
)
2759 zebra_evpn_es_bypass_update(zif
->es_info
.es
, zif
->ifp
, bypass
);
2763 /* Only certain types of access ports can be setup as an Ethernet Segment */
2764 bool zebra_evpn_is_if_es_capable(struct zebra_if
*zif
)
2766 if (zif
->zif_type
== ZEBRA_IF_BOND
)
2769 /* XXX: allow swpX i.e. a regular ethernet port to be an ES link too */
2773 void zebra_evpn_if_es_print(struct vty
*vty
, json_object
*json
,
2774 struct zebra_if
*zif
)
2776 char buf
[ETHER_ADDR_STRLEN
];
2777 char esi_buf
[ESI_STR_LEN
];
2780 json_object
*json_evpn
;
2782 json_evpn
= json_object_new_object();
2783 json_object_object_add(json
, "evpnMh", json_evpn
);
2785 if (zif
->es_info
.lid
|| !is_zero_mac(&zif
->es_info
.sysmac
)) {
2786 json_object_int_add(json_evpn
, "esId",
2788 json_object_string_add(
2789 json_evpn
, "esSysmac",
2790 prefix_mac2str(&zif
->es_info
.sysmac
, buf
,
2792 } else if (memcmp(&zif
->es_info
.esi
, zero_esi
,
2793 sizeof(*zero_esi
))) {
2794 json_object_string_add(json_evpn
, "esId",
2795 esi_to_str(&zif
->es_info
.esi
,
2800 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK
)
2801 json_object_string_add(
2802 json_evpn
, "uplink",
2803 CHECK_FLAG(zif
->flags
,
2804 ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
)
2809 bool vty_print
= false;
2812 strlcat(mh_buf
, " EVPN-MH:", sizeof(mh_buf
));
2813 if (zif
->es_info
.lid
|| !is_zero_mac(&zif
->es_info
.sysmac
)) {
2815 snprintf(mh_buf
+ strlen(mh_buf
),
2816 sizeof(mh_buf
) - strlen(mh_buf
),
2817 " ES id %u ES sysmac %s", zif
->es_info
.lid
,
2818 prefix_mac2str(&zif
->es_info
.sysmac
, buf
,
2820 } else if (memcmp(&zif
->es_info
.esi
, zero_esi
,
2821 sizeof(*zero_esi
))) {
2823 snprintf(mh_buf
+ strnlen(mh_buf
, sizeof(mh_buf
)),
2825 - strnlen(mh_buf
, sizeof(mh_buf
)),
2827 esi_to_str(&zif
->es_info
.esi
, esi_buf
,
2831 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK
) {
2833 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
)
2834 strlcat(mh_buf
, " uplink (up)", sizeof(mh_buf
));
2836 strlcat(mh_buf
, " uplink (down)",
2841 vty_out(vty
, "%s\n", mh_buf
);
2845 static void zebra_evpn_local_mac_oper_state_change(struct zebra_evpn_es
*es
)
2847 struct zebra_mac
*mac
;
2848 struct listnode
*node
;
2850 /* If fast-failover is supported by the dataplane via the use
2851 * of an ES backup NHG there is nothing to be done in the
2854 if (!(zmh_info
->flags
& ZEBRA_EVPN_MH_REDIRECT_OFF
))
2857 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
|| IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2858 zlog_debug("mac slow-fail on es %s %s ", es
->esi_str
,
2859 (es
->flags
& ZEBRA_EVPNES_OPER_UP
) ? "up" : "down");
2861 for (ALL_LIST_ELEMENTS_RO(es
->mac_list
, node
, mac
)) {
2862 if (!(mac
->flags
& ZEBRA_MAC_LOCAL
)
2863 || !zebra_evpn_mac_is_static(mac
))
2866 if (es
->flags
& ZEBRA_EVPNES_OPER_UP
) {
2867 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2869 "VNI %u mac %pEA move to acc %s es %s %s ",
2872 es
->zif
->ifp
->name
, es
->esi_str
,
2873 (es
->flags
& ZEBRA_EVPNES_OPER_UP
)
2876 /* switch the local macs to access port */
2877 if (zebra_evpn_sync_mac_dp_install(
2878 mac
, false /*set_inactive*/,
2879 false /*force_clear_static*/, __func__
)
2881 /* if the local mac install fails get rid of the
2884 zebra_evpn_rem_mac_uninstall(mac
->zevpn
, mac
,
2887 /* switch the local macs to network port. if there
2888 * is no active NHG we don't bother deleting the MAC;
2889 * that is left up to the dataplane to handle.
2891 if (!(es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
))
2893 if (IS_ZEBRA_DEBUG_EVPN_MH_MAC
)
2895 "VNI %u mac %pEA move to nhg %u es %s %s ",
2898 es
->nhg_id
, es
->esi_str
,
2899 (es
->flags
& ZEBRA_EVPNES_OPER_UP
)
2902 zebra_evpn_rem_mac_install(mac
->zevpn
, mac
,
2903 true /*was_static*/);
2908 void zebra_evpn_es_if_oper_state_change(struct zebra_if
*zif
, bool up
)
2910 struct zebra_evpn_es
*es
= zif
->es_info
.es
;
2911 bool old_up
= !!(es
->flags
& ZEBRA_EVPNES_OPER_UP
);
2916 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
2917 zlog_debug("es %s state changed to %s ",
2919 up
? "up" : "down");
2921 es
->flags
|= ZEBRA_EVPNES_OPER_UP
;
2923 es
->flags
&= ~ZEBRA_EVPNES_OPER_UP
;
2925 zebra_evpn_es_run_df_election(es
, __func__
);
2926 zebra_evpn_local_mac_oper_state_change(es
);
2928 /* inform BGP of the ES oper state change */
2929 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
2930 zebra_evpn_es_send_add_to_client(es
);
2933 static char *zebra_evpn_es_vtep_str(char *vtep_str
, struct zebra_evpn_es
*es
,
2934 uint8_t vtep_str_size
)
2936 struct zebra_evpn_es_vtep
*zvtep
;
2937 struct listnode
*node
;
2939 char ip_buf
[INET6_ADDRSTRLEN
];
2942 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, zvtep
)) {
2946 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, ip_buf
,
2950 strlcat(vtep_str
, ",", vtep_str_size
);
2952 inet_ntop(AF_INET
, &zvtep
->vtep_ip
, ip_buf
,
2960 static void zebra_evpn_es_json_vtep_fill(struct zebra_evpn_es
*es
,
2961 json_object
*json_vteps
)
2963 struct zebra_evpn_es_vtep
*es_vtep
;
2964 struct listnode
*node
;
2965 json_object
*json_vtep_entry
;
2966 char alg_buf
[EVPN_DF_ALG_STR_LEN
];
2968 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
2969 json_vtep_entry
= json_object_new_object();
2970 json_object_string_addf(json_vtep_entry
, "vtep", "%pI4",
2972 if (es_vtep
->flags
& ZEBRA_EVPNES_VTEP_RXED_ESR
) {
2973 json_object_string_add(
2974 json_vtep_entry
, "dfAlgorithm",
2975 evpn_es_df_alg2str(es_vtep
->df_alg
, alg_buf
,
2977 json_object_int_add(json_vtep_entry
, "dfPreference",
2981 json_object_int_add(json_vtep_entry
, "nexthopId",
2982 es_vtep
->nh
->nh_id
);
2983 json_object_array_add(json_vteps
, json_vtep_entry
);
2987 static void zebra_evpn_es_show_entry(struct vty
*vty
, struct zebra_evpn_es
*es
,
2988 json_object
*json_array
)
2991 char vtep_str
[ES_VTEP_LIST_STR_SZ
];
2994 json_object
*json
= NULL
;
2995 json_object
*json_vteps
;
2996 json_object
*json_flags
;
2998 json
= json_object_new_object();
2999 json_object_string_add(json
, "esi", es
->esi_str
);
3002 & (ZEBRA_EVPNES_LOCAL
| ZEBRA_EVPNES_REMOTE
3003 | ZEBRA_EVPNES_NON_DF
)) {
3004 json_flags
= json_object_new_array();
3005 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
3006 json_array_string_add(json_flags
, "local");
3007 if (es
->flags
& ZEBRA_EVPNES_REMOTE
)
3008 json_array_string_add(json_flags
, "remote");
3009 if (es
->flags
& ZEBRA_EVPNES_NON_DF
)
3010 json_array_string_add(json_flags
, "nonDF");
3011 if (es
->flags
& ZEBRA_EVPNES_BYPASS
)
3012 json_array_string_add(json_flags
, "bypass");
3013 json_object_object_add(json
, "flags", json_flags
);
3017 json_object_string_add(json
, "accessPort",
3018 es
->zif
->ifp
->name
);
3020 if (listcount(es
->es_vtep_list
)) {
3021 json_vteps
= json_object_new_array();
3022 zebra_evpn_es_json_vtep_fill(es
, json_vteps
);
3023 json_object_object_add(json
, "vteps", json_vteps
);
3025 json_object_array_add(json_array
, json
);
3028 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
3029 strlcat(type_str
, "L", sizeof(type_str
));
3030 if (es
->flags
& ZEBRA_EVPNES_REMOTE
)
3031 strlcat(type_str
, "R", sizeof(type_str
));
3032 if (es
->flags
& ZEBRA_EVPNES_NON_DF
)
3033 strlcat(type_str
, "N", sizeof(type_str
));
3034 if (es
->flags
& ZEBRA_EVPNES_BYPASS
)
3035 strlcat(type_str
, "B", sizeof(type_str
));
3037 zebra_evpn_es_vtep_str(vtep_str
, es
, sizeof(vtep_str
));
3039 vty_out(vty
, "%-30s %-4s %-21s %s\n",
3040 es
->esi_str
, type_str
,
3041 es
->zif
? es
->zif
->ifp
->name
: "-",
3046 static void zebra_evpn_es_show_entry_detail(struct vty
*vty
,
3047 struct zebra_evpn_es
*es
, json_object
*json
)
3050 char alg_buf
[EVPN_DF_ALG_STR_LEN
];
3051 struct zebra_evpn_es_vtep
*es_vtep
;
3052 struct listnode
*node
;
3053 char thread_buf
[THREAD_TIMER_STRLEN
];
3056 json_object
*json_vteps
;
3057 json_object
*json_flags
;
3059 json_object_string_add(json
, "esi", es
->esi_str
);
3061 json_object_string_add(json
, "accessPort",
3062 es
->zif
->ifp
->name
);
3066 json_flags
= json_object_new_array();
3067 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
3068 json_array_string_add(json_flags
, "local");
3069 if (es
->flags
& ZEBRA_EVPNES_REMOTE
)
3070 json_array_string_add(json_flags
, "remote");
3071 if (es
->flags
& ZEBRA_EVPNES_NON_DF
)
3072 json_array_string_add(json_flags
, "nonDF");
3073 if (es
->flags
& ZEBRA_EVPNES_BYPASS
)
3074 json_array_string_add(json_flags
, "bypass");
3075 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
3076 json_array_string_add(json_flags
,
3078 if (es
->flags
& ZEBRA_EVPNES_BR_PORT
)
3079 json_array_string_add(json_flags
, "bridgePort");
3080 if (es
->flags
& ZEBRA_EVPNES_OPER_UP
)
3081 json_array_string_add(json_flags
, "operUp");
3082 if (es
->flags
& ZEBRA_EVPNES_NHG_ACTIVE
)
3083 json_array_string_add(json_flags
,
3084 "nexthopGroupActive");
3085 json_object_object_add(json
, "flags", json_flags
);
3088 json_object_int_add(json
, "vniCount",
3089 listcount(es
->es_evi_list
));
3090 json_object_int_add(json
, "macCount", listcount(es
->mac_list
));
3091 json_object_int_add(json
, "dfPreference", es
->df_pref
);
3092 if (es
->df_delay_timer
)
3093 json_object_string_add(
3094 json
, "dfDelayTimer",
3095 thread_timer_to_hhmmss(thread_buf
,
3097 es
->df_delay_timer
));
3098 json_object_int_add(json
, "nexthopGroup", es
->nhg_id
);
3099 if (listcount(es
->es_vtep_list
)) {
3100 json_vteps
= json_object_new_array();
3101 zebra_evpn_es_json_vtep_fill(es
, json_vteps
);
3102 json_object_object_add(json
, "vteps", json_vteps
);
3106 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
3107 strlcat(type_str
, "Local", sizeof(type_str
));
3108 if (es
->flags
& ZEBRA_EVPNES_REMOTE
) {
3109 if (strnlen(type_str
, sizeof(type_str
)))
3110 strlcat(type_str
, ",", sizeof(type_str
));
3111 strlcat(type_str
, "Remote", sizeof(type_str
));
3114 vty_out(vty
, "ESI: %s\n", es
->esi_str
);
3115 vty_out(vty
, " Type: %s\n", type_str
);
3116 vty_out(vty
, " Interface: %s\n",
3118 es
->zif
->ifp
->name
: "-");
3119 if (es
->flags
& ZEBRA_EVPNES_LOCAL
) {
3120 vty_out(vty
, " State: %s\n",
3121 (es
->flags
& ZEBRA_EVPNES_OPER_UP
) ? "up"
3123 vty_out(vty
, " Bridge port: %s\n",
3124 (es
->flags
& ZEBRA_EVPNES_BR_PORT
) ? "yes"
3127 vty_out(vty
, " Ready for BGP: %s\n",
3128 (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
) ?
3130 if (es
->flags
& ZEBRA_EVPNES_BYPASS
)
3131 vty_out(vty
, " LACP bypass: on\n");
3132 vty_out(vty
, " VNI Count: %d\n", listcount(es
->es_evi_list
));
3133 vty_out(vty
, " MAC Count: %d\n", listcount(es
->mac_list
));
3134 if (es
->flags
& ZEBRA_EVPNES_LOCAL
)
3135 vty_out(vty
, " DF status: %s \n",
3136 (es
->flags
& ZEBRA_EVPNES_NON_DF
) ? "non-df"
3138 if (es
->df_delay_timer
)
3139 vty_out(vty
, " DF delay: %s\n",
3140 thread_timer_to_hhmmss(thread_buf
,
3142 es
->df_delay_timer
));
3143 vty_out(vty
, " DF preference: %u\n", es
->df_pref
);
3144 vty_out(vty
, " Nexthop group: %u\n", es
->nhg_id
);
3145 vty_out(vty
, " VTEPs:\n");
3146 for (ALL_LIST_ELEMENTS_RO(es
->es_vtep_list
, node
, es_vtep
)) {
3147 vty_out(vty
, " %pI4",
3149 if (es_vtep
->flags
& ZEBRA_EVPNES_VTEP_RXED_ESR
)
3150 vty_out(vty
, " df_alg: %s df_pref: %d",
3151 evpn_es_df_alg2str(es_vtep
->df_alg
,
3155 vty_out(vty
, " nh: %u\n",
3156 es_vtep
->nh
? es_vtep
->nh
->nh_id
: 0);
3163 void zebra_evpn_es_show(struct vty
*vty
, bool uj
)
3165 struct zebra_evpn_es
*es
;
3166 json_object
*json_array
= NULL
;
3169 json_array
= json_object_new_array();
3171 vty_out(vty
, "Type: B bypass, L local, R remote, N non-DF\n");
3172 vty_out(vty
, "%-30s %-4s %-21s %s\n",
3173 "ESI", "Type", "ES-IF", "VTEPs");
3176 RB_FOREACH(es
, zebra_es_rb_head
, &zmh_info
->es_rb_tree
)
3177 zebra_evpn_es_show_entry(vty
, es
, json_array
);
3180 vty_json(vty
, json_array
);
3183 void zebra_evpn_es_show_detail(struct vty
*vty
, bool uj
)
3185 struct zebra_evpn_es
*es
;
3186 json_object
*json_array
= NULL
;
3189 json_array
= json_object_new_array();
3191 RB_FOREACH (es
, zebra_es_rb_head
, &zmh_info
->es_rb_tree
) {
3192 json_object
*json
= NULL
;
3195 json
= json_object_new_object();
3196 zebra_evpn_es_show_entry_detail(vty
, es
, json
);
3198 json_object_array_add(json_array
, json
);
3202 vty_json(vty
, json_array
);
3205 void zebra_evpn_es_show_esi(struct vty
*vty
, bool uj
, esi_t
*esi
)
3207 struct zebra_evpn_es
*es
;
3208 char esi_str
[ESI_STR_LEN
];
3209 json_object
*json
= NULL
;
3212 json
= json_object_new_object();
3214 es
= zebra_evpn_es_find(esi
);
3217 zebra_evpn_es_show_entry_detail(vty
, es
, json
);
3220 esi_to_str(esi
, esi_str
, sizeof(esi_str
));
3221 vty_out(vty
, "ESI %s does not exist\n", esi_str
);
3226 vty_json(vty
, json
);
3229 int zebra_evpn_mh_if_write(struct vty
*vty
, struct interface
*ifp
)
3231 struct zebra_if
*zif
= ifp
->info
;
3232 char buf
[ETHER_ADDR_STRLEN
];
3233 bool type_3_esi
= false;
3234 char esi_buf
[ESI_STR_LEN
];
3236 if (zif
->es_info
.lid
) {
3237 vty_out(vty
, " evpn mh es-id %u\n", zif
->es_info
.lid
);
3241 if (!is_zero_mac(&zif
->es_info
.sysmac
)) {
3242 vty_out(vty
, " evpn mh es-sys-mac %s\n",
3243 prefix_mac2str(&zif
->es_info
.sysmac
,
3249 && memcmp(&zif
->es_info
.esi
, zero_esi
, sizeof(*zero_esi
)))
3250 vty_out(vty
, " evpn mh es-id %s\n",
3251 esi_to_str(&zif
->es_info
.esi
, esi_buf
, sizeof(esi_buf
)));
3253 if (zif
->es_info
.df_pref
)
3254 vty_out(vty
, " evpn mh es-df-pref %u\n", zif
->es_info
.df_pref
);
3256 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK
)
3257 vty_out(vty
, " evpn mh uplink\n");
3262 #ifndef VTYSH_EXTRACT_PL
3263 #include "zebra/zebra_evpn_mh_clippy.c"
3265 /* CLI for setting an ES in bypass mode */
3266 DEFPY_HIDDEN(zebra_evpn_es_bypass
, zebra_evpn_es_bypass_cmd
,
3267 "[no] evpn mh bypass",
3268 NO_STR
"EVPN\n" EVPN_MH_VTY_STR
"set bypass mode\n")
3270 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3271 struct zebra_if
*zif
;
3276 zebra_evpn_es_bypass_cfg_update(zif
, false);
3278 if (!zebra_evpn_is_if_es_capable(zif
)) {
3280 "%% DF bypass cannot be associated with this interface type\n");
3283 zebra_evpn_es_bypass_cfg_update(zif
, true);
3288 /* CLI for configuring DF preference part for an ES */
3289 DEFPY(zebra_evpn_es_pref
, zebra_evpn_es_pref_cmd
,
3290 "[no$no] evpn mh es-df-pref [(1-65535)$df_pref]",
3291 NO_STR
"EVPN\n" EVPN_MH_VTY_STR
3292 "preference value used for DF election\n"
3295 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3296 struct zebra_if
*zif
;
3301 zebra_evpn_es_df_pref_update(zif
, 0);
3303 if (!zebra_evpn_is_if_es_capable(zif
)) {
3305 "%% DF preference cannot be associated with this interface type\n");
3308 zebra_evpn_es_df_pref_update(zif
, df_pref
);
3313 /* CLI for setting up sysmac part of ESI on an access port */
3314 DEFPY(zebra_evpn_es_sys_mac
,
3315 zebra_evpn_es_sys_mac_cmd
,
3316 "[no$no] evpn mh es-sys-mac [X:X:X:X:X:X$mac]",
3320 "Ethernet segment system MAC\n"
3324 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3325 struct zebra_if
*zif
;
3331 static struct ethaddr zero_mac
;
3333 ret
= zebra_evpn_es_sys_mac_update(zif
, &zero_mac
);
3335 vty_out(vty
, "%% Failed to clear ES sysmac\n");
3340 if (!zebra_evpn_is_if_es_capable(zif
)) {
3342 "%% ESI cannot be associated with this interface type\n");
3346 if (!mac
|| is_zero_mac(&mac
->eth_addr
)) {
3347 vty_out(vty
, "%% ES sysmac value is invalid\n");
3351 ret
= zebra_evpn_es_sys_mac_update(zif
, &mac
->eth_addr
);
3354 "%% ESI already exists on a different interface\n");
3361 /* CLI for setting up local-ID part of ESI on an access port */
3362 DEFPY(zebra_evpn_es_id
,
3363 zebra_evpn_es_id_cmd
,
3364 "[no$no] evpn mh es-id [(1-16777215)$es_lid | NAME$esi_str]",
3368 "Ethernet segment identifier\n"
3369 "local discriminator\n"
3370 "10-byte ID - 00:AA:BB:CC:DD:EE:FF:GG:HH:II\n"
3373 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3374 struct zebra_if
*zif
;
3381 if (zif
->es_info
.lid
)
3382 ret
= zebra_evpn_es_lid_update(zif
, 0);
3383 else if (memcmp(&zif
->es_info
.esi
, zero_esi
, sizeof(*zero_esi
)))
3384 ret
= zebra_evpn_es_type0_esi_update(zif
, zero_esi
);
3388 "%% Failed to clear ES local id or ESI name\n");
3392 if (!zebra_evpn_is_if_es_capable(zif
)) {
3394 "%% ESI cannot be associated with this interface type\n");
3399 if (!str_to_esi(esi_str
, &esi
)) {
3400 vty_out(vty
, "%% Malformed ESI name\n");
3403 ret
= zebra_evpn_es_type0_esi_update(zif
, &esi
);
3407 "%% Specify ES local id or ESI name\n");
3410 ret
= zebra_evpn_es_lid_update(zif
, es_lid
);
3415 "%% ESI already exists on a different interface\n");
3422 /* CLI for tagging an interface as an uplink */
3423 DEFPY(zebra_evpn_mh_uplink
, zebra_evpn_mh_uplink_cmd
, "[no] evpn mh uplink",
3424 NO_STR
"EVPN\n" EVPN_MH_VTY_STR
"uplink to the VxLAN core\n")
3426 VTY_DECLVAR_CONTEXT(interface
, ifp
);
3427 struct zebra_if
*zif
;
3430 zebra_evpn_mh_uplink_cfg_update(zif
, no
? false : true);
3435 void zebra_evpn_mh_json(json_object
*json
)
3437 json_object
*json_array
;
3438 char thread_buf
[THREAD_TIMER_STRLEN
];
3440 json_object_int_add(json
, "macHoldtime", zmh_info
->mac_hold_time
);
3441 json_object_int_add(json
, "neighHoldtime", zmh_info
->neigh_hold_time
);
3442 json_object_int_add(json
, "startupDelay", zmh_info
->startup_delay_time
);
3443 json_object_string_add(
3444 json
, "startupDelayTimer",
3445 thread_timer_to_hhmmss(thread_buf
, sizeof(thread_buf
),
3446 zmh_info
->startup_delay_timer
));
3447 json_object_int_add(json
, "uplinkConfigCount",
3448 zmh_info
->uplink_cfg_cnt
);
3449 json_object_int_add(json
, "uplinkActiveCount",
3450 zmh_info
->uplink_oper_up_cnt
);
3452 if (zmh_info
->protodown_rc
) {
3453 json_array
= json_object_new_array();
3454 if (CHECK_FLAG(zmh_info
->protodown_rc
,
3455 ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
))
3456 json_object_array_add(
3458 json_object_new_string("startupDelay"));
3459 if (CHECK_FLAG(zmh_info
->protodown_rc
,
3460 ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN
))
3461 json_object_array_add(
3463 json_object_new_string("uplinkDown"));
3464 json_object_object_add(json
, "protodownReasons", json_array
);
3468 void zebra_evpn_mh_print(struct vty
*vty
)
3470 char pd_buf
[ZEBRA_PROTODOWN_RC_STR_LEN
];
3471 char thread_buf
[THREAD_TIMER_STRLEN
];
3473 vty_out(vty
, "EVPN MH:\n");
3474 vty_out(vty
, " mac-holdtime: %ds, neigh-holdtime: %ds\n",
3475 zmh_info
->mac_hold_time
, zmh_info
->neigh_hold_time
);
3476 vty_out(vty
, " startup-delay: %ds, start-delay-timer: %s\n",
3477 zmh_info
->startup_delay_time
,
3478 thread_timer_to_hhmmss(thread_buf
, sizeof(thread_buf
),
3479 zmh_info
->startup_delay_timer
));
3480 vty_out(vty
, " uplink-cfg-cnt: %u, uplink-active-cnt: %u\n",
3481 zmh_info
->uplink_cfg_cnt
, zmh_info
->uplink_oper_up_cnt
);
3482 if (zmh_info
->protodown_rc
)
3483 vty_out(vty
, " protodown reasons: %s\n",
3484 zebra_protodown_rc_str(zmh_info
->protodown_rc
, pd_buf
,
3488 /*****************************************************************************/
3489 /* A base L2-VNI is maintained to derive parameters such as ES originator-IP.
3490 * XXX: once single vxlan device model becomes available this will not be
3493 /* called when a new vni is added or becomes oper up or becomes a bridge port */
3494 void zebra_evpn_es_set_base_evpn(struct zebra_evpn
*zevpn
)
3496 struct listnode
*node
;
3497 struct zebra_evpn_es
*es
;
3499 if (zmh_info
->es_base_evpn
) {
3500 if (zmh_info
->es_base_evpn
!= zevpn
) {
3501 /* unrelated EVPN; ignore it */
3504 /* check if the local vtep-ip has changed */
3506 /* check if the EVPN can be used as base EVPN */
3507 if (!zebra_evpn_send_to_client_ok(zevpn
))
3510 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3511 zlog_debug("es base vni set to %d",
3513 zmh_info
->es_base_evpn
= zevpn
;
3516 /* update local VTEP-IP */
3517 if (zmh_info
->es_originator_ip
.s_addr
==
3518 zmh_info
->es_base_evpn
->local_vtep_ip
.s_addr
)
3521 zmh_info
->es_originator_ip
.s_addr
=
3522 zmh_info
->es_base_evpn
->local_vtep_ip
.s_addr
;
3524 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3525 zlog_debug("es originator ip set to %pI4",
3526 &zmh_info
->es_base_evpn
->local_vtep_ip
);
3528 /* if originator ip changes we need to update bgp */
3529 for (ALL_LIST_ELEMENTS_RO(zmh_info
->local_es_list
, node
, es
)) {
3530 zebra_evpn_es_run_df_election(es
, __func__
);
3532 if (es
->flags
& ZEBRA_EVPNES_READY_FOR_BGP
)
3533 zebra_evpn_es_send_add_to_client(es
);
3535 zebra_evpn_es_re_eval_send_to_client(es
,
3536 true /* es_evi_re_reval */);
3540 /* called when a vni is removed or becomes oper down or is removed from a
3543 void zebra_evpn_es_clear_base_evpn(struct zebra_evpn
*zevpn
)
3545 struct listnode
*node
;
3546 struct zebra_evpn_es
*es
;
3548 if (zmh_info
->es_base_evpn
!= zevpn
)
3551 zmh_info
->es_base_evpn
= NULL
;
3552 /* lost current base EVPN; try to find a new one */
3553 zebra_evpn_es_get_one_base_evpn();
3555 /* couldn't locate an eligible base evpn */
3556 if (!zmh_info
->es_base_evpn
&& zmh_info
->es_originator_ip
.s_addr
) {
3557 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3558 zlog_debug("es originator ip cleared");
3560 zmh_info
->es_originator_ip
.s_addr
= 0;
3561 /* lost originator ip */
3562 for (ALL_LIST_ELEMENTS_RO(zmh_info
->local_es_list
, node
, es
)) {
3563 zebra_evpn_es_re_eval_send_to_client(es
,
3564 true /* es_evi_re_reval */);
3569 /* Locate an "eligible" L2-VNI to follow */
3570 static int zebra_evpn_es_get_one_base_evpn_cb(struct hash_bucket
*b
, void *data
)
3572 struct zebra_evpn
*zevpn
= b
->data
;
3574 zebra_evpn_es_set_base_evpn(zevpn
);
3576 if (zmh_info
->es_base_evpn
)
3577 return HASHWALK_ABORT
;
3579 return HASHWALK_CONTINUE
;
3582 /* locate a base_evpn to follow for the purposes of common params like
3585 static void zebra_evpn_es_get_one_base_evpn(void)
3587 struct zebra_vrf
*zvrf
;
3589 zvrf
= zebra_vrf_get_evpn();
3590 hash_walk(zvrf
->evpn_table
, zebra_evpn_es_get_one_base_evpn_cb
, NULL
);
3593 /*****************************************************************************
3594 * local ethernet segments can be error-disabled if the switch is not
3595 * ready to start transmitting traffic via the VxLAN overlay
3597 bool zebra_evpn_is_es_bond(struct interface
*ifp
)
3599 struct zebra_if
*zif
= ifp
->info
;
3601 return !!(struct zebra_if
*)zif
->es_info
.es
;
3604 bool zebra_evpn_is_es_bond_member(struct interface
*ifp
)
3606 struct zebra_if
*zif
= ifp
->info
;
3608 return IS_ZEBRA_IF_BOND_SLAVE(zif
->ifp
) && zif
->bondslave_info
.bond_if
3609 && ((struct zebra_if
*)zif
->bondslave_info
.bond_if
->info
)
3613 void zebra_evpn_mh_update_protodown_bond_mbr(struct zebra_if
*zif
, bool clear
,
3617 uint32_t old_protodown_rc
= 0;
3618 uint32_t new_protodown_rc
= 0;
3619 uint32_t protodown_rc
= 0;
3622 struct zebra_if
*bond_zif
;
3624 bond_zif
= zif
->bondslave_info
.bond_if
->info
;
3625 protodown_rc
= bond_zif
->protodown_rc
;
3628 old_protodown_rc
= zif
->protodown_rc
;
3629 new_protodown_rc
= (old_protodown_rc
& ~ZEBRA_PROTODOWN_EVPN_ALL
);
3630 new_protodown_rc
|= (protodown_rc
& ZEBRA_PROTODOWN_EVPN_ALL
);
3631 new_protodown
= !!new_protodown_rc
;
3633 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
&& (new_protodown_rc
!= old_protodown_rc
))
3635 "%s bond mbr %s protodown_rc changed; old 0x%x new 0x%x",
3636 caller
, zif
->ifp
->name
, old_protodown_rc
,
3639 if (zebra_if_update_protodown_rc(zif
->ifp
, new_protodown
,
3640 new_protodown_rc
) == 0) {
3641 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3642 zlog_debug("%s protodown %s", zif
->ifp
->name
,
3643 new_protodown
? "on" : "off");
3647 /* The bond members inherit the protodown reason code from the bond */
3648 static void zebra_evpn_mh_update_protodown_bond(struct zebra_if
*bond_zif
)
3650 struct zebra_if
*zif
;
3651 struct listnode
*node
;
3653 if (!bond_zif
->bond_info
.mbr_zifs
)
3656 for (ALL_LIST_ELEMENTS_RO(bond_zif
->bond_info
.mbr_zifs
, node
, zif
)) {
3657 zebra_evpn_mh_update_protodown_bond_mbr(zif
, false /*clear*/,
3662 /* The global EVPN MH protodown rc is applied to all local ESs */
3663 static void zebra_evpn_mh_update_protodown_es(struct zebra_evpn_es
*es
,
3666 struct zebra_if
*zif
;
3667 uint32_t old_protodown_rc
;
3670 /* if the reason code is the same bail unless it is a new
3671 * ES bond in that case we would need to ensure that the
3672 * dplane is really in sync with zebra
3675 && (zif
->protodown_rc
& ZEBRA_PROTODOWN_EVPN_ALL
)
3676 == (zmh_info
->protodown_rc
& ZEBRA_PROTODOWN_EVPN_ALL
))
3679 old_protodown_rc
= zif
->protodown_rc
;
3680 zif
->protodown_rc
&= ~ZEBRA_PROTODOWN_EVPN_ALL
;
3681 zif
->protodown_rc
|=
3682 (zmh_info
->protodown_rc
& ZEBRA_PROTODOWN_EVPN_ALL
);
3684 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
3685 && (old_protodown_rc
!= zif
->protodown_rc
))
3687 "es %s ifp %s protodown_rc changed; old 0x%x new 0x%x",
3688 es
->esi_str
, zif
->ifp
->name
, old_protodown_rc
,
3691 /* update dataplane with the new protodown setting */
3692 zebra_evpn_mh_update_protodown_bond(zif
);
3695 static void zebra_evpn_mh_clear_protodown_es(struct zebra_evpn_es
*es
)
3697 struct zebra_if
*zif
;
3698 uint32_t old_protodown_rc
;
3701 if (!(zif
->protodown_rc
& ZEBRA_PROTODOWN_EVPN_ALL
))
3704 old_protodown_rc
= zif
->protodown_rc
;
3705 zif
->protodown_rc
&= ~ZEBRA_PROTODOWN_EVPN_ALL
;
3707 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3709 "clear: es %s ifp %s protodown_rc cleared; old 0x%x new 0x%x",
3710 es
->esi_str
, zif
->ifp
->name
, old_protodown_rc
,
3713 /* update dataplane with the new protodown setting */
3714 zebra_evpn_mh_update_protodown_bond(zif
);
3717 static void zebra_evpn_mh_update_protodown_es_all(void)
3719 struct listnode
*node
;
3720 struct zebra_evpn_es
*es
;
3722 for (ALL_LIST_ELEMENTS_RO(zmh_info
->local_es_list
, node
, es
))
3723 zebra_evpn_mh_update_protodown_es(es
, false /*resync_dplane*/);
3726 static void zebra_evpn_mh_update_protodown(uint32_t protodown_rc
, bool set
)
3728 uint32_t old_protodown_rc
= zmh_info
->protodown_rc
;
3731 if ((protodown_rc
& zmh_info
->protodown_rc
) == protodown_rc
)
3734 zmh_info
->protodown_rc
|= protodown_rc
;
3736 if (!(protodown_rc
& zmh_info
->protodown_rc
))
3738 zmh_info
->protodown_rc
&= ~protodown_rc
;
3741 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3742 zlog_debug("mh protodown_rc changed; old 0x%x new 0x%x",
3743 old_protodown_rc
, zmh_info
->protodown_rc
);
3744 zebra_evpn_mh_update_protodown_es_all();
3747 static inline bool zebra_evpn_mh_is_all_uplinks_down(void)
3749 return zmh_info
->uplink_cfg_cnt
&& !zmh_info
->uplink_oper_up_cnt
;
3752 static void zebra_evpn_mh_uplink_oper_flags_update(struct zebra_if
*zif
,
3755 if (set
&& if_is_operative(zif
->ifp
)) {
3756 if (!(zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
)) {
3757 zif
->flags
|= ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
;
3758 ++zmh_info
->uplink_oper_up_cnt
;
3761 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
) {
3762 zif
->flags
&= ~ZIF_FLAG_EVPN_MH_UPLINK_OPER_UP
;
3763 if (zmh_info
->uplink_oper_up_cnt
)
3764 --zmh_info
->uplink_oper_up_cnt
;
3769 static void zebra_evpn_mh_uplink_cfg_update(struct zebra_if
*zif
, bool set
)
3771 bool old_protodown
= zebra_evpn_mh_is_all_uplinks_down();
3775 if (zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK
)
3778 zif
->flags
|= ZIF_FLAG_EVPN_MH_UPLINK
;
3779 ++zmh_info
->uplink_cfg_cnt
;
3781 if (!(zif
->flags
& ZIF_FLAG_EVPN_MH_UPLINK
))
3784 zif
->flags
&= ~ZIF_FLAG_EVPN_MH_UPLINK
;
3785 if (zmh_info
->uplink_cfg_cnt
)
3786 --zmh_info
->uplink_cfg_cnt
;
3789 zebra_evpn_mh_uplink_oper_flags_update(zif
, set
);
3790 new_protodown
= zebra_evpn_mh_is_all_uplinks_down();
3791 if (old_protodown
== new_protodown
)
3794 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3796 "mh-uplink-cfg-chg on if %s/%d %s uplinks cfg %u up %u",
3797 zif
->ifp
->name
, zif
->ifp
->ifindex
, set
? "set" : "down",
3798 zmh_info
->uplink_cfg_cnt
, zmh_info
->uplink_oper_up_cnt
);
3800 zebra_evpn_mh_update_protodown(ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN
,
3804 void zebra_evpn_mh_uplink_oper_update(struct zebra_if
*zif
)
3806 bool old_protodown
= zebra_evpn_mh_is_all_uplinks_down();
3809 zebra_evpn_mh_uplink_oper_flags_update(zif
, true /*set*/);
3811 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3813 "mh-uplink-oper-chg on if %s/%d %s; uplinks cfg %u up %u",
3814 zif
->ifp
->name
, zif
->ifp
->ifindex
,
3815 if_is_operative(zif
->ifp
) ? "up" : "down",
3816 zmh_info
->uplink_cfg_cnt
, zmh_info
->uplink_oper_up_cnt
);
3818 new_protodown
= zebra_evpn_mh_is_all_uplinks_down();
3819 if (old_protodown
== new_protodown
)
3822 /* if protodown_rc XXX_UPLINK_DOWN is about to be cleared
3823 * fire up the start-up delay timer to allow the EVPN network
3824 * to converge (Type-2 routes need to be advertised and processed)
3826 if (!new_protodown
&& (zmh_info
->uplink_oper_up_cnt
== 1))
3827 zebra_evpn_mh_startup_delay_timer_start("uplink-up");
3829 zebra_evpn_mh_update_protodown(ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN
,
3833 static void zebra_evpn_mh_startup_delay_exp_cb(struct thread
*t
)
3835 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3836 zlog_debug("startup-delay expired");
3838 zebra_evpn_mh_update_protodown(ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
,
3842 static void zebra_evpn_mh_startup_delay_timer_start(const char *rc
)
3844 if (zmh_info
->startup_delay_timer
) {
3845 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3846 zlog_debug("startup-delay timer cancelled");
3847 THREAD_OFF(zmh_info
->startup_delay_timer
);
3850 if (zmh_info
->startup_delay_time
) {
3851 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3853 "startup-delay timer started for %d sec on %s",
3854 zmh_info
->startup_delay_time
, rc
);
3855 thread_add_timer(zrouter
.master
,
3856 zebra_evpn_mh_startup_delay_exp_cb
, NULL
,
3857 zmh_info
->startup_delay_time
,
3858 &zmh_info
->startup_delay_timer
);
3859 zebra_evpn_mh_update_protodown(
3860 ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
, true /* set */);
3862 zebra_evpn_mh_update_protodown(
3863 ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY
, false /* set */);
3867 /*****************************************************************************
3868 * Nexthop management: nexthops associated with Type-2 routes that have
3869 * an ES as destination are consolidated by BGP into a per-VRF nh->rmac
3870 * mapping which is the installed as a remote neigh/fdb entry with a
3871 * dummy (type-1) prefix referencing it.
3872 * This handling is needed because Type-2 routes with ES as dest use NHG
3873 * that are setup using EAD routes (i.e. such NHGs do not include the
3875 ****************************************************************************/
3876 void zebra_evpn_proc_remote_nh(ZAPI_HANDLER_ARGS
)
3881 struct ethaddr rmac
;
3882 struct prefix_evpn dummy_prefix
;
3883 size_t min_len
= 4 + sizeof(nh
);
3888 * Ensure that the stream sent to us is long enough
3890 if (hdr
->command
== ZEBRA_EVPN_REMOTE_NH_ADD
)
3891 min_len
+= sizeof(rmac
);
3892 if (hdr
->length
< min_len
)
3895 vrf_id
= stream_getl(s
);
3896 stream_get(&nh
, s
, sizeof(nh
));
3898 memset(&dummy_prefix
, 0, sizeof(dummy_prefix
));
3899 dummy_prefix
.family
= AF_EVPN
;
3900 dummy_prefix
.prefixlen
= (sizeof(struct evpn_addr
) * 8);
3901 dummy_prefix
.prefix
.route_type
= 1; /* XXX - fixup to type-1 def */
3902 dummy_prefix
.prefix
.ead_addr
.ip
.ipa_type
= nh
.ipa_type
;
3904 if (hdr
->command
== ZEBRA_EVPN_REMOTE_NH_ADD
) {
3905 stream_get(&rmac
, s
, sizeof(rmac
));
3906 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3908 "evpn remote nh %d %pIA rmac %pEA add pfx %pFX",
3909 vrf_id
, &nh
, &rmac
, &dummy_prefix
);
3910 zebra_rib_queue_evpn_route_add(vrf_id
, &rmac
, &nh
,
3911 (struct prefix
*)&dummy_prefix
);
3913 if (IS_ZEBRA_DEBUG_EVPN_MH_ES
)
3914 zlog_debug("evpn remote nh %d %pIA del pfx %pFX",
3915 vrf_id
, &nh
, &dummy_prefix
);
3916 zebra_rib_queue_evpn_route_del(vrf_id
, &nh
,
3917 (struct prefix
*)&dummy_prefix
);
3921 /*****************************************************************************/
3922 void zebra_evpn_mh_config_write(struct vty
*vty
)
3924 if (zmh_info
->mac_hold_time
!= ZEBRA_EVPN_MH_MAC_HOLD_TIME_DEF
)
3925 vty_out(vty
, "evpn mh mac-holdtime %d\n",
3926 zmh_info
->mac_hold_time
);
3928 if (zmh_info
->neigh_hold_time
!= ZEBRA_EVPN_MH_NEIGH_HOLD_TIME_DEF
)
3929 vty_out(vty
, "evpn mh neigh-holdtime %d\n",
3930 zmh_info
->neigh_hold_time
);
3932 if (zmh_info
->startup_delay_time
!= ZEBRA_EVPN_MH_STARTUP_DELAY_DEF
)
3933 vty_out(vty
, "evpn mh startup-delay %d\n",
3934 zmh_info
->startup_delay_time
);
3936 if (zmh_info
->flags
& ZEBRA_EVPN_MH_REDIRECT_OFF
)
3937 vty_out(vty
, "evpn mh redirect-off\n");
3940 int zebra_evpn_mh_neigh_holdtime_update(struct vty
*vty
,
3941 uint32_t duration
, bool set_default
)
3944 duration
= ZEBRA_EVPN_MH_NEIGH_HOLD_TIME_DEF
;
3946 zmh_info
->neigh_hold_time
= duration
;
3951 int zebra_evpn_mh_mac_holdtime_update(struct vty
*vty
,
3952 uint32_t duration
, bool set_default
)
3955 duration
= ZEBRA_EVPN_MH_MAC_HOLD_TIME_DEF
;
3957 zmh_info
->mac_hold_time
= duration
;
3962 int zebra_evpn_mh_startup_delay_update(struct vty
*vty
, uint32_t duration
,
3966 duration
= ZEBRA_EVPN_MH_STARTUP_DELAY_DEF
;
3968 zmh_info
->startup_delay_time
= duration
;
3970 /* if startup_delay_timer is running allow it to be adjusted
3973 if (zmh_info
->startup_delay_timer
)
3974 zebra_evpn_mh_startup_delay_timer_start("config");
3979 int zebra_evpn_mh_redirect_off(struct vty
*vty
, bool redirect_off
)
3981 /* This knob needs to be set before ESs are configured
3982 * i.e. cannot be changed on the fly
3985 zmh_info
->flags
|= ZEBRA_EVPN_MH_REDIRECT_OFF
;
3987 zmh_info
->flags
&= ~ZEBRA_EVPN_MH_REDIRECT_OFF
;
3992 void zebra_evpn_interface_init(void)
3994 install_element(INTERFACE_NODE
, &zebra_evpn_es_id_cmd
);
3995 install_element(INTERFACE_NODE
, &zebra_evpn_es_sys_mac_cmd
);
3996 install_element(INTERFACE_NODE
, &zebra_evpn_es_pref_cmd
);
3997 install_element(INTERFACE_NODE
, &zebra_evpn_es_bypass_cmd
);
3998 install_element(INTERFACE_NODE
, &zebra_evpn_mh_uplink_cmd
);
4001 void zebra_evpn_mh_init(void)
4003 zrouter
.mh_info
= XCALLOC(MTYPE_ZMH_INFO
, sizeof(*zrouter
.mh_info
));
4005 zmh_info
->mac_hold_time
= ZEBRA_EVPN_MH_MAC_HOLD_TIME_DEF
;
4006 zmh_info
->neigh_hold_time
= ZEBRA_EVPN_MH_NEIGH_HOLD_TIME_DEF
;
4007 /* setup ES tables */
4008 RB_INIT(zebra_es_rb_head
, &zmh_info
->es_rb_tree
);
4009 zmh_info
->local_es_list
= list_new();
4010 listset_app_node_mem(zmh_info
->local_es_list
);
4012 bf_init(zmh_info
->nh_id_bitmap
, EVPN_NH_ID_MAX
);
4013 bf_assign_zero_index(zmh_info
->nh_id_bitmap
);
4014 zmh_info
->nhg_table
= hash_create(zebra_evpn_nhg_hash_keymake
,
4015 zebra_evpn_nhg_cmp
, "l2 NHG table");
4016 zmh_info
->nh_ip_table
=
4017 hash_create(zebra_evpn_nh_ip_hash_keymake
, zebra_evpn_nh_ip_cmp
,
4020 /* setup broadcast domain tables */
4021 zmh_info
->evpn_vlan_table
= hash_create(zebra_evpn_acc_vl_hash_keymake
,
4022 zebra_evpn_acc_vl_cmp
, "access VLAN hash table");
4024 zmh_info
->startup_delay_time
= ZEBRA_EVPN_MH_STARTUP_DELAY_DEF
;
4025 zebra_evpn_mh_startup_delay_timer_start("init");
4028 void zebra_evpn_mh_terminate(void)
4030 list_delete(&zmh_info
->local_es_list
);
4032 hash_iterate(zmh_info
->evpn_vlan_table
,
4033 zebra_evpn_acc_vl_cleanup_all
, NULL
);
4034 hash_free(zmh_info
->evpn_vlan_table
);
4035 hash_free(zmh_info
->nhg_table
);
4036 hash_free(zmh_info
->nh_ip_table
);
4037 bf_free(zmh_info
->nh_id_bitmap
);