1 /* EVPN header for multihoming procedures
3 * Copyright (C) 2019 Cumulus Networks
6 * This file is part of FRRouting.
8 * FRRouting is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * FRRouting is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
20 #ifndef _FRR_BGP_EVPN_MH_H
21 #define _FRR_BGP_EVPN_MH_H
26 #include "bgp_evpn_private.h"
28 #define BGP_EVPN_AD_ES_ETH_TAG 0xffffffff
29 #define BGP_EVPN_AD_EVI_ETH_TAG 0
31 #define BGP_EVPNES_INCONS_STR_SZ 80
32 #define BGP_EVPN_VTEPS_FLAG_STR_SZ (BGP_EVPN_FLAG_STR_SZ * ES_VTEP_MAX_CNT)
34 #define BGP_EVPN_CONS_CHECK_INTERVAL 60
36 #define BGP_EVPN_MH_USE_ES_L3NHG_DEF true
38 /* Ethernet Segment entry -
39 * - Local and remote ESs are maintained in a global RB tree,
40 * bgp_mh_info->es_rb_tree using ESI as key
41 * - Local ESs are received from zebra (BGP_EVPNES_LOCAL)
42 * - Remotes ESs are implicitly created (by reference) by a remote ES-EVI
44 * - An ES can be simulatenously LOCAL and REMOTE; infact all LOCAL ESs are
45 * expected to have REMOTE ES peers.
48 /* Ethernet Segment Identifier */
50 char esi_str
[ESI_STR_LEN
];
54 /* created via zebra config */
55 #define BGP_EVPNES_LOCAL (1 << 0)
56 /* created implicitly by a remote ES-EVI reference */
57 #define BGP_EVPNES_REMOTE (1 << 1)
58 /* local ES link is oper-up */
59 #define BGP_EVPNES_OPER_UP (1 << 2)
60 /* enable generation of EAD-EVI routes */
61 #define BGP_EVPNES_ADV_EVI (1 << 3)
62 /* consistency checks pending */
63 #define BGP_EVPNES_CONS_CHECK_PEND (1 << 4)
64 /* ES is in LACP bypass mode - don't advertise EAD-ES or ESR */
65 #define BGP_EVPNES_BYPASS (1 << 5)
66 /* bits needed for printing the flags + null */
67 #define BGP_EVPN_FLAG_STR_SZ 7
69 /* memory used for adding the es to bgp->es_rb_tree */
70 RB_ENTRY(bgp_evpn_es
) rb_node
;
72 /* [EVPNES_LOCAL] memory used for linking the es to
73 * bgp_mh_info->local_es_list
75 struct listnode es_listnode
;
77 /* memory used for linking the es to "processing" pending list
78 * bgp_mh_info->pend_es_list
80 struct listnode pend_es_listnode
;
82 /* [EVPNES_LOCAL] Id for deriving the RD automatically for this ESI */
85 /* [EVPNES_LOCAL] RD for this ES */
88 /* [EVPNES_LOCAL] originator ip address */
89 struct in_addr originator_ip
;
91 /* [EVPNES_LOCAL] Route table for EVPN routes for this ESI-
92 * - Type-4 local and remote routes
93 * - Type-1 local routes
95 struct bgp_table
*route_table
;
97 /* list of PEs (bgp_evpn_es_vtep) attached to the ES */
98 struct list
*es_vtep_list
;
100 /* List of ES-EVIs associated with this ES */
101 struct list
*es_evi_list
;
103 /* List of ES-VRFs associated with this ES */
104 struct list
*es_vrf_list
;
106 /* List of MAC-IP VNI paths using this ES as destination -
107 * element is bgp_path_info_extra->es_info
108 * Note: Only local/zebra-added MACIP paths in the VNI
109 * routing table are linked to this list
111 struct list
*macip_evi_path_list
;
113 /* List of MAC-IP paths in the global routing table using this
114 * ES as destination - data is bgp_path_info_extra->es_info
115 * Note: Only non-local/imported MACIP paths in the global
116 * routing table are linked to this list
118 struct list
*macip_global_path_list
;
120 /* Number of remote VNIs referencing this ES */
121 uint32_t remote_es_evi_cnt
;
123 uint32_t inconsistencies
;
124 /* there are one or more EVIs whose VTEP list doesn't match
125 * with the ES's VTEP list
127 #define BGP_EVPNES_INCONS_VTEP_LIST (1 << 0)
129 /* number of es-evi entries whose VTEP list doesn't match
132 uint32_t incons_evi_vtep_cnt
;
134 /* preference config for BUM-DF election. advertised via the ESR. */
139 DECLARE_QOBJ_TYPE(bgp_evpn_es
);
140 RB_HEAD(bgp_es_rb_head
, bgp_evpn_es
);
141 RB_PROTOTYPE(bgp_es_rb_head
, bgp_evpn_es
, rb_node
, bgp_es_rb_cmp
);
143 /* PE attached to an ES */
144 struct bgp_evpn_es_vtep
{
145 struct bgp_evpn_es
*es
; /* parent ES */
146 struct in_addr vtep_ip
;
149 /* Rxed a Type4 route from this PE */
150 #define BGP_EVPNES_VTEP_ESR (1 << 0)
151 /* Active (rxed EAD-ES and EAD-EVI) and can be included as
154 #define BGP_EVPNES_VTEP_ACTIVE (1 << 1)
156 uint32_t evi_cnt
; /* es_evis referencing this vtep as an active path */
158 /* Algorithm and preference for DF election. Rxed via the ESR */
162 /* memory used for adding the entry to es->es_vtep_list */
163 struct listnode es_listnode
;
166 /* ES-VRF element needed for managing L3 NHGs. It is implicitly created
167 * when an ES-EVI is associated with a tenant VRF
169 struct bgp_evpn_es_vrf
{
170 struct bgp_evpn_es
*es
;
174 /* NHG can only be activated if there are active VTEPs in the ES and
175 * there is a valid L3-VNI associated with the VRF
177 #define BGP_EVPNES_VRF_NHG_ACTIVE (1 << 0)
179 /* memory used for adding the es_vrf to
180 * es_vrf->bgp_vrf->es_vrf_rb_tree
182 RB_ENTRY(bgp_evpn_es_vrf
) rb_node
;
184 /* memory used for linking the es_vrf to es_vrf->es->es_vrf_list */
185 struct listnode es_listnode
;
190 /* Number of ES-EVI entries associated with this ES-VRF */
195 * - ES-EVIs are maintained per-L2-VNI (vpn->es_evi_rb_tree)
196 * - ES-EVIs are also linked to the parent ES (es->es_evi_list)
197 * - Local ES-EVIs are created by zebra (via config). They are linked to a
198 * per-VNI list (vpn->local_es_evi_list) for quick access
199 * - Remote ES-EVIs are created implicitly when a bgp_evpn_es_evi_vtep
202 struct bgp_evpn_es_evi
{
203 struct bgp_evpn_es
*es
;
208 /* local ES-EVI, created by zebra */
209 #define BGP_EVPNES_EVI_LOCAL (1 << 0)
210 /* created via a remote VTEP imported by BGP */
211 #define BGP_EVPNES_EVI_REMOTE (1 << 1)
212 #define BGP_EVPNES_EVI_INCONS_VTEP_LIST (1 << 2)
214 /* memory used for adding the es_evi to es_evi->vpn->es_evi_rb_tree */
215 RB_ENTRY(bgp_evpn_es_evi
) rb_node
;
216 /* memory used for linking the es_evi to
217 * es_evi->vpn->local_es_evi_list
219 struct listnode l2vni_listnode
;
220 /* memory used for linking the es_evi to
221 * es_evi->es->es_evi_list
223 struct listnode es_listnode
;
225 /* list of PEs (bgp_evpn_es_evi_vtep) attached to the ES for this VNI */
226 struct list
*es_evi_vtep_list
;
228 struct bgp_evpn_es_vrf
*es_vrf
;
231 /* PE attached to an ES for a VNI. This entry is created when an EAD-per-ES
232 * or EAD-per-EVI Type1 route is imported into the VNI.
234 struct bgp_evpn_es_evi_vtep
{
235 struct bgp_evpn_es_evi
*es_evi
; /* parent ES-EVI */
236 struct in_addr vtep_ip
;
239 /* Rxed an EAD-per-ES route from the PE */
240 #define BGP_EVPN_EVI_VTEP_EAD_PER_ES (1 << 0) /* rxed EAD-per-ES */
241 /* Rxed an EAD-per-EVI route from the PE */
242 #define BGP_EVPN_EVI_VTEP_EAD_PER_EVI (1 << 1) /* rxed EAD-per-EVI */
243 /* VTEP is active i.e. will result in the creation of an es-vtep */
244 #define BGP_EVPN_EVI_VTEP_ACTIVE (1 << 2)
245 #define BGP_EVPN_EVI_VTEP_EAD (BGP_EVPN_EVI_VTEP_EAD_PER_ES |\
246 BGP_EVPN_EVI_VTEP_EAD_PER_EVI)
248 /* memory used for adding the entry to es_evi->es_evi_vtep_list */
249 struct listnode es_evi_listnode
;
250 struct bgp_evpn_es_vtep
*es_vtep
;
253 /* A nexthop is created when a path (imported from an EVPN type-2 route)
254 * is added to the VRF route table using that nexthop.
255 * It is added on first pi reference and removed on last pi deref.
258 /* backpointer to the VRF */
260 /* nexthop/VTEP IP */
262 /* description for easy logging */
263 char nh_str
[INET6_ADDRSTRLEN
];
265 /* pi from which we are pulling the nh RMAC */
266 struct bgp_path_info
*ref_pi
;
267 /* List of VRF paths using this nexthop */
268 struct list
*pi_list
;
270 #define BGP_EVPN_NH_READY_FOR_ZEBRA (1 << 0)
273 /* multihoming information stored in bgp_master */
274 #define bgp_mh_info (bm->mh_info)
275 struct bgp_evpn_mh_info
{
276 /* RB tree of Ethernet segments (used for EVPN-MH) */
277 struct bgp_es_rb_head es_rb_tree
;
278 /* List of local ESs */
279 struct list
*local_es_list
;
280 /* List of ESs with pending/periodic processing */
281 struct list
*pend_es_list
;
282 /* periodic timer for running background consistency checks */
283 struct thread
*t_cons_check
;
285 /* config knobs for optimizing or interop */
286 /* Generate EAD-EVI routes even if the ES is oper-down. This can be
287 * enabled as an optimization to avoid a storm of updates when an ES
290 bool ead_evi_adv_for_down_links
;
291 /* Enable ES consistency checking */
292 bool consistency_checking
;
293 /* Use L3 NHGs for host routes in symmetric IRB */
295 bool host_routes_use_l3nhg
;
296 /* Some vendors are not generating the EAD-per-EVI route. This knob
297 * can be turned off to activate a remote ES-PE when the EAD-per-ES
298 * route is rxed i.e. not wait on the EAD-per-EVI route
301 #define BGP_EVPN_MH_EAD_EVI_RX_DEF true
302 /* Skip EAD-EVI advertisements by turning off this knob */
304 #define BGP_EVPN_MH_EAD_EVI_TX_DEF true
305 /* If the Local ES is inactive we advertise the MAC-IP without the
308 bool suppress_l3_ecomm_on_inactive_es
;
309 /* Setup EVPN PE nexthops and their RMAC in bgpd */
310 bool bgp_evpn_nh_setup
;
313 /****************************************************************************/
314 static inline int bgp_evpn_is_es_local(struct bgp_evpn_es
*es
)
316 return CHECK_FLAG(es
->flags
, BGP_EVPNES_LOCAL
) ? 1 : 0;
319 extern esi_t
*zero_esi
;
320 static inline bool bgp_evpn_is_esi_valid(esi_t
*esi
)
322 return !!memcmp(esi
, zero_esi
, sizeof(esi_t
));
325 static inline esi_t
*bgp_evpn_attr_get_esi(struct attr
*attr
)
327 return attr
? &attr
->esi
: zero_esi
;
330 static inline bool bgp_evpn_attr_is_sync(struct attr
*attr
)
332 return attr
? !!(attr
->es_flags
&
333 (ATTR_ES_PEER_PROXY
| ATTR_ES_PEER_ACTIVE
)) : false;
336 static inline uint32_t bgp_evpn_attr_get_sync_seq(struct attr
*attr
)
338 return attr
? attr
->mm_sync_seqnum
: 0;
341 static inline bool bgp_evpn_attr_is_active_on_peer(struct attr
*attr
)
344 !!(attr
->es_flags
& ATTR_ES_PEER_ACTIVE
) : false;
347 static inline bool bgp_evpn_attr_is_router_on_peer(struct attr
*attr
)
350 !!(attr
->es_flags
& ATTR_ES_PEER_ROUTER
) : false;
353 static inline bool bgp_evpn_attr_is_proxy(struct attr
*attr
)
355 return attr
? !!(attr
->es_flags
& ATTR_ES_PROXY_ADVERT
) : false;
358 static inline bool bgp_evpn_attr_is_local_es(struct attr
*attr
)
360 return attr
? !!(attr
->es_flags
& ATTR_ES_IS_LOCAL
) : false;
363 static inline uint32_t bgp_evpn_attr_get_df_pref(struct attr
*attr
)
365 return (attr
) ? attr
->df_pref
: 0;
368 static inline bool bgp_evpn_local_es_is_active(struct bgp_evpn_es
*es
)
370 return (es
->flags
& BGP_EVPNES_OPER_UP
)
371 && !(es
->flags
& BGP_EVPNES_BYPASS
);
374 /****************************************************************************/
375 extern int bgp_evpn_es_route_install_uninstall(struct bgp
*bgp
,
376 struct bgp_evpn_es
*es
, afi_t afi
, safi_t safi
,
377 struct prefix_evpn
*evp
, struct bgp_path_info
*pi
,
379 extern void update_type1_routes_for_evi(struct bgp
*bgp
, struct bgpevpn
*vpn
);
380 int bgp_evpn_type1_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
381 struct attr
*attr
, uint8_t *pfx
, int psize
,
382 uint32_t addpath_id
);
383 int bgp_evpn_type4_route_process(struct peer
*peer
, afi_t afi
, safi_t safi
,
384 struct attr
*attr
, uint8_t *pfx
, int psize
,
385 uint32_t addpath_id
);
386 extern int bgp_evpn_local_es_add(struct bgp
*bgp
, esi_t
*esi
,
387 struct in_addr originator_ip
, bool oper_up
,
388 uint16_t df_pref
, bool bypass
);
389 extern int bgp_evpn_local_es_del(struct bgp
*bgp
, esi_t
*esi
);
390 extern int bgp_evpn_local_es_evi_add(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
);
391 extern int bgp_evpn_local_es_evi_del(struct bgp
*bgp
, esi_t
*esi
, vni_t vni
);
392 extern int bgp_evpn_remote_es_evi_add(struct bgp
*bgp
, struct bgpevpn
*vpn
,
393 const struct prefix_evpn
*p
);
394 extern int bgp_evpn_remote_es_evi_del(struct bgp
*bgp
, struct bgpevpn
*vpn
,
395 const struct prefix_evpn
*p
);
396 extern void bgp_evpn_mh_init(void);
397 extern void bgp_evpn_mh_finish(void);
398 void bgp_evpn_vni_es_init(struct bgpevpn
*vpn
);
399 void bgp_evpn_vni_es_cleanup(struct bgpevpn
*vpn
);
400 void bgp_evpn_es_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
);
401 void bgp_evpn_es_show(struct vty
*vty
, bool uj
, bool detail
);
402 void bgp_evpn_es_evi_show_vni(struct vty
*vty
, vni_t vni
,
403 bool uj
, bool detail
);
404 void bgp_evpn_es_evi_show(struct vty
*vty
, bool uj
, bool detail
);
405 struct bgp_evpn_es
*bgp_evpn_es_find(const esi_t
*esi
);
406 extern void bgp_evpn_vrf_es_init(struct bgp
*bgp_vrf
);
407 extern bool bgp_evpn_is_esi_local_and_non_bypass(esi_t
*esi
);
408 extern void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi
*es_evi
);
409 extern void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi
*es_evi
,
410 struct bgp
*bgp_vrf
);
411 extern void bgp_evpn_path_mh_info_free(struct bgp_path_mh_info
*mh_info
);
412 extern void bgp_evpn_path_es_link(struct bgp_path_info
*pi
, vni_t vni
,
414 extern bool bgp_evpn_path_es_use_nhg(struct bgp
*bgp_vrf
,
415 struct bgp_path_info
*pi
, uint32_t *nhg_p
);
416 extern void bgp_evpn_es_vrf_show(struct vty
*vty
, bool uj
,
417 struct bgp_evpn_es
*es
);
418 extern void bgp_evpn_es_vrf_show_esi(struct vty
*vty
, esi_t
*esi
, bool uj
);
419 extern void bgp_evpn_switch_ead_evi_rx(void);
420 extern bool bgp_evpn_es_add_l3_ecomm_ok(esi_t
*esi
);
421 extern void bgp_evpn_es_vrf_use_nhg(struct bgp
*bgp_vrf
, esi_t
*esi
,
422 bool *use_l3nhg
, bool *is_l3nhg_active
,
423 struct bgp_evpn_es_vrf
**es_vrf_p
);
424 extern void bgp_evpn_nh_init(struct bgp
*bgp_vrf
);
425 extern void bgp_evpn_nh_finish(struct bgp
*bgp_vrf
);
426 extern void bgp_evpn_nh_show(struct vty
*vty
, bool uj
);
427 extern void bgp_evpn_path_nh_add(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
);
428 extern void bgp_evpn_path_nh_del(struct bgp
*bgp_vrf
, struct bgp_path_info
*pi
);
430 #endif /* _FRR_BGP_EVPN_MH_H */