]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_evpn_mh.h
Merge pull request #9497 from opensourcerouting/cli-better-no
[mirror_frr.git] / bgpd / bgp_evpn_mh.h
1 /* EVPN header for multihoming procedures
2 *
3 * Copyright (C) 2019 Cumulus Networks
4 * Anuradha Karuppiah
5 *
6 * This file is part of FRRouting.
7 *
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
11 * later version.
12 *
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.
17 *
18 */
19
20 #ifndef _FRR_BGP_EVPN_MH_H
21 #define _FRR_BGP_EVPN_MH_H
22
23 #include "vxlan.h"
24 #include "bgpd.h"
25 #include "bgp_evpn.h"
26 #include "bgp_evpn_private.h"
27
28 #define BGP_EVPN_AD_ES_ETH_TAG 0xffffffff
29 #define BGP_EVPN_AD_EVI_ETH_TAG 0
30
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)
33
34 #define BGP_EVPN_CONS_CHECK_INTERVAL 60
35
36 #define BGP_EVPN_MH_USE_ES_L3NHG_DEF true
37
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
43 * (BGP_EVPNES_REMOTE)
44 * - An ES can be simulatenously LOCAL and REMOTE; infact all LOCAL ESs are
45 * expected to have REMOTE ES peers.
46 */
47 struct bgp_evpn_es {
48 /* Ethernet Segment Identifier */
49 esi_t esi;
50 char esi_str[ESI_STR_LEN];
51
52 /* es flags */
53 uint32_t flags;
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
68
69 /* memory used for adding the es to bgp->es_rb_tree */
70 RB_ENTRY(bgp_evpn_es) rb_node;
71
72 /* [EVPNES_LOCAL] memory used for linking the es to
73 * bgp_mh_info->local_es_list
74 */
75 struct listnode es_listnode;
76
77 /* memory used for linking the es to "processing" pending list
78 * bgp_mh_info->pend_es_list
79 */
80 struct listnode pend_es_listnode;
81
82 /* [EVPNES_LOCAL] Id for deriving the RD automatically for this ESI */
83 uint16_t rd_id;
84
85 /* [EVPNES_LOCAL] RD for this ES */
86 struct prefix_rd prd;
87
88 /* [EVPNES_LOCAL] originator ip address */
89 struct in_addr originator_ip;
90
91 /* [EVPNES_LOCAL] Route table for EVPN routes for this ESI-
92 * - Type-4 local and remote routes
93 * - Type-1 local routes
94 */
95 struct bgp_table *route_table;
96
97 /* list of PEs (bgp_evpn_es_vtep) attached to the ES */
98 struct list *es_vtep_list;
99
100 /* List of ES-EVIs associated with this ES */
101 struct list *es_evi_list;
102
103 /* List of ES-VRFs associated with this ES */
104 struct list *es_vrf_list;
105
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
110 */
111 struct list *macip_evi_path_list;
112
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
117 */
118 struct list *macip_global_path_list;
119
120 /* Number of remote VNIs referencing this ES */
121 uint32_t remote_es_evi_cnt;
122
123 uint32_t inconsistencies;
124 /* there are one or more EVIs whose VTEP list doesn't match
125 * with the ES's VTEP list
126 */
127 #define BGP_EVPNES_INCONS_VTEP_LIST (1 << 0)
128
129 /* number of es-evi entries whose VTEP list doesn't match
130 * with the ES's
131 */
132 uint32_t incons_evi_vtep_cnt;
133
134 /* preference config for BUM-DF election. advertised via the ESR. */
135 uint16_t df_pref;
136
137 QOBJ_FIELDS;
138 };
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);
142
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;
147
148 uint32_t flags;
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
152 * a nexthop
153 */
154 #define BGP_EVPNES_VTEP_ACTIVE (1 << 1)
155
156 uint32_t evi_cnt; /* es_evis referencing this vtep as an active path */
157
158 /* Algorithm and preference for DF election. Rxed via the ESR */
159 uint8_t df_alg;
160 uint16_t df_pref;
161
162 /* memory used for adding the entry to es->es_vtep_list */
163 struct listnode es_listnode;
164 };
165
166 /* ES-VRF element needed for managing L3 NHGs. It is implicitly created
167 * when an ES-EVI is associated with a tenant VRF
168 */
169 struct bgp_evpn_es_vrf {
170 struct bgp_evpn_es *es;
171 struct bgp *bgp_vrf;
172
173 uint32_t flags;
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
176 */
177 #define BGP_EVPNES_VRF_NHG_ACTIVE (1 << 0)
178
179 /* memory used for adding the es_vrf to
180 * es_vrf->bgp_vrf->es_vrf_rb_tree
181 */
182 RB_ENTRY(bgp_evpn_es_vrf) rb_node;
183
184 /* memory used for linking the es_vrf to es_vrf->es->es_vrf_list */
185 struct listnode es_listnode;
186
187 uint32_t nhg_id;
188 uint32_t v6_nhg_id;
189
190 /* Number of ES-EVI entries associated with this ES-VRF */
191 uint32_t ref_cnt;
192 };
193
194 /* ES per-EVI info
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
200 * references it.
201 */
202 struct bgp_evpn_es_evi {
203 struct bgp_evpn_es *es;
204 struct bgpevpn *vpn;
205
206 /* ES-EVI flags */
207 uint32_t flags;
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)
213
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
218 */
219 struct listnode l2vni_listnode;
220 /* memory used for linking the es_evi to
221 * es_evi->es->es_evi_list
222 */
223 struct listnode es_listnode;
224
225 /* list of PEs (bgp_evpn_es_evi_vtep) attached to the ES for this VNI */
226 struct list *es_evi_vtep_list;
227
228 struct bgp_evpn_es_vrf *es_vrf;
229 };
230
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.
233 */
234 struct bgp_evpn_es_evi_vtep {
235 struct bgp_evpn_es_evi *es_evi; /* parent ES-EVI */
236 struct in_addr vtep_ip;
237
238 uint32_t flags;
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)
247
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;
251 };
252
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.
256 */
257 struct bgp_evpn_nh {
258 /* backpointer to the VRF */
259 struct bgp *bgp_vrf;
260 /* nexthop/VTEP IP */
261 struct ipaddr ip;
262 /* description for easy logging */
263 char nh_str[INET6_ADDRSTRLEN];
264 struct ethaddr rmac;
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;
269 uint8_t flags;
270 #define BGP_EVPN_NH_READY_FOR_ZEBRA (1 << 0)
271 };
272
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;
284
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
288 * link flaps.
289 */
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 */
294 bool install_l3nhg;
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
299 */
300 bool ead_evi_rx;
301 #define BGP_EVPN_MH_EAD_EVI_RX_DEF true
302 /* Skip EAD-EVI advertisements by turning off this knob */
303 bool ead_evi_tx;
304 #define BGP_EVPN_MH_EAD_EVI_TX_DEF true
305 /* If the Local ES is inactive we advertise the MAC-IP without the
306 * L3 ecomm
307 */
308 bool suppress_l3_ecomm_on_inactive_es;
309 /* Setup EVPN PE nexthops and their RMAC in bgpd */
310 bool bgp_evpn_nh_setup;
311 };
312
313 /****************************************************************************/
314 static inline int bgp_evpn_is_es_local(struct bgp_evpn_es *es)
315 {
316 return CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL) ? 1 : 0;
317 }
318
319 extern esi_t *zero_esi;
320 static inline bool bgp_evpn_is_esi_valid(esi_t *esi)
321 {
322 return !!memcmp(esi, zero_esi, sizeof(esi_t));
323 }
324
325 static inline esi_t *bgp_evpn_attr_get_esi(struct attr *attr)
326 {
327 return attr ? &attr->esi : zero_esi;
328 }
329
330 static inline bool bgp_evpn_attr_is_sync(struct attr *attr)
331 {
332 return attr ? !!(attr->es_flags &
333 (ATTR_ES_PEER_PROXY | ATTR_ES_PEER_ACTIVE)) : false;
334 }
335
336 static inline uint32_t bgp_evpn_attr_get_sync_seq(struct attr *attr)
337 {
338 return attr ? attr->mm_sync_seqnum : 0;
339 }
340
341 static inline bool bgp_evpn_attr_is_active_on_peer(struct attr *attr)
342 {
343 return attr ?
344 !!(attr->es_flags & ATTR_ES_PEER_ACTIVE) : false;
345 }
346
347 static inline bool bgp_evpn_attr_is_router_on_peer(struct attr *attr)
348 {
349 return attr ?
350 !!(attr->es_flags & ATTR_ES_PEER_ROUTER) : false;
351 }
352
353 static inline bool bgp_evpn_attr_is_proxy(struct attr *attr)
354 {
355 return attr ? !!(attr->es_flags & ATTR_ES_PROXY_ADVERT) : false;
356 }
357
358 static inline bool bgp_evpn_attr_is_local_es(struct attr *attr)
359 {
360 return attr ? !!(attr->es_flags & ATTR_ES_IS_LOCAL) : false;
361 }
362
363 static inline uint32_t bgp_evpn_attr_get_df_pref(struct attr *attr)
364 {
365 return (attr) ? attr->df_pref : 0;
366 }
367
368 static inline bool bgp_evpn_local_es_is_active(struct bgp_evpn_es *es)
369 {
370 return (es->flags & BGP_EVPNES_OPER_UP)
371 && !(es->flags & BGP_EVPNES_BYPASS);
372 }
373
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,
378 int install);
379 extern void update_type1_routes_for_evi(struct bgp *bgp, struct bgpevpn *vpn);
380 extern int delete_global_ead_evi_routes(struct bgp *bgp, struct bgpevpn *vpn);
381 extern int bgp_evpn_mh_route_update(struct bgp *bgp, struct bgp_evpn_es *es,
382 struct bgpevpn *vpn, afi_t afi, safi_t safi,
383 struct bgp_dest *dest, struct attr *attr,
384 int add, struct bgp_path_info **ri,
385 int *route_changed);
386 int bgp_evpn_type1_route_process(struct peer *peer, afi_t afi, safi_t safi,
387 struct attr *attr, uint8_t *pfx, int psize,
388 uint32_t addpath_id);
389 int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi,
390 struct attr *attr, uint8_t *pfx, int psize,
391 uint32_t addpath_id);
392 extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
393 struct in_addr originator_ip, bool oper_up,
394 uint16_t df_pref, bool bypass);
395 extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi);
396 extern int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni);
397 extern int bgp_evpn_local_es_evi_del(struct bgp *bgp, esi_t *esi, vni_t vni);
398 extern int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn,
399 const struct prefix_evpn *p);
400 extern int bgp_evpn_remote_es_evi_del(struct bgp *bgp, struct bgpevpn *vpn,
401 const struct prefix_evpn *p);
402 extern void bgp_evpn_mh_init(void);
403 extern void bgp_evpn_mh_finish(void);
404 void bgp_evpn_vni_es_init(struct bgpevpn *vpn);
405 void bgp_evpn_vni_es_cleanup(struct bgpevpn *vpn);
406 void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj);
407 void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail);
408 void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,
409 bool uj, bool detail);
410 void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail);
411 struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi);
412 extern void bgp_evpn_vrf_es_init(struct bgp *bgp_vrf);
413 extern bool bgp_evpn_is_esi_local_and_non_bypass(esi_t *esi);
414 extern void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi *es_evi);
415 extern void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi *es_evi,
416 struct bgp *bgp_vrf);
417 extern void bgp_evpn_path_mh_info_free(struct bgp_path_mh_info *mh_info);
418 extern void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni,
419 esi_t *esi);
420 extern bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf,
421 struct bgp_path_info *pi, uint32_t *nhg_p);
422 extern void bgp_evpn_es_vrf_show(struct vty *vty, bool uj,
423 struct bgp_evpn_es *es);
424 extern void bgp_evpn_es_vrf_show_esi(struct vty *vty, esi_t *esi, bool uj);
425 extern void bgp_evpn_switch_ead_evi_rx(void);
426 extern bool bgp_evpn_es_add_l3_ecomm_ok(esi_t *esi);
427 extern void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, esi_t *esi,
428 bool *use_l3nhg, bool *is_l3nhg_active,
429 struct bgp_evpn_es_vrf **es_vrf_p);
430 extern void bgp_evpn_nh_init(struct bgp *bgp_vrf);
431 extern void bgp_evpn_nh_finish(struct bgp *bgp_vrf);
432 extern void bgp_evpn_nh_show(struct vty *vty, bool uj);
433 extern void bgp_evpn_path_nh_add(struct bgp *bgp_vrf, struct bgp_path_info *pi);
434 extern void bgp_evpn_path_nh_del(struct bgp *bgp_vrf, struct bgp_path_info *pi);
435
436 #endif /* _FRR_BGP_EVPN_MH_H */