]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn_mh.h
lib/zebra: zapi for installing EVPN nexthops from bgp
[mirror_frr.git] / bgpd / bgp_evpn_mh.h
CommitLineData
185fb14a
AK
1/* EVPN header for multihoming procedures
2 *
3 * Copyright (C) 2019 Cumulus Networks
c44ab6f1 4 * Anuradha Karuppiah
185fb14a
AK
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
c44ab6f1
AK
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
c44ab6f1
AK
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
a92764da 36#define BGP_EVPN_MH_USE_ES_L3NHG_DEF true
c44ab6f1
AK
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 */
47struct 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)
74be8313
AK
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
c44ab6f1
AK
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
c589d847
AK
103 /* List of ES-VRFs associated with this ES */
104 struct list *es_vrf_list;
105
2eef4f20 106 /* List of MAC-IP VNI paths using this ES as destination -
26c03e43 107 * element is bgp_path_info_extra->es_info
58bff4d1
AK
108 * Note: Only local/zebra-added MACIP paths in the VNI
109 * routing table are linked to this list
26c03e43 110 */
d656e0ae 111 struct list *macip_evi_path_list;
26c03e43 112
58bff4d1
AK
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
c44ab6f1
AK
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
74e2bd89
AK
134 /* preference config for BUM-DF election. advertised via the ESR. */
135 uint16_t df_pref;
136
96244aca 137 QOBJ_FIELDS;
c44ab6f1 138};
96244aca 139DECLARE_QOBJ_TYPE(bgp_evpn_es);
c44ab6f1
AK
140RB_HEAD(bgp_es_rb_head, bgp_evpn_es);
141RB_PROTOTYPE(bgp_es_rb_head, bgp_evpn_es, rb_node, bgp_es_rb_cmp);
142
143/* PE attached to an ES */
144struct 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
74e2bd89
AK
158 /* Algorithm and preference for DF election. Rxed via the ESR */
159 uint8_t df_alg;
160 uint16_t df_pref;
161
c44ab6f1
AK
162 /* memory used for adding the entry to es->es_vtep_list */
163 struct listnode es_listnode;
164};
165
c589d847
AK
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 */
169struct 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;
6348981a 188 uint32_t v6_nhg_id;
c589d847
AK
189
190 /* Number of ES-EVI entries associated with this ES-VRF */
191 uint32_t ref_cnt;
192};
193
c44ab6f1
AK
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 */
202struct 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;
c589d847
AK
227
228 struct bgp_evpn_es_vrf *es_vrf;
c44ab6f1
AK
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 */
234struct 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/* multihoming information stored in bgp_master */
254#define bgp_mh_info (bm->mh_info)
255struct bgp_evpn_mh_info {
256 /* RB tree of Ethernet segments (used for EVPN-MH) */
257 struct bgp_es_rb_head es_rb_tree;
258 /* List of local ESs */
259 struct list *local_es_list;
260 /* List of ESs with pending/periodic processing */
261 struct list *pend_es_list;
262 /* periodic timer for running background consistency checks */
263 struct thread *t_cons_check;
264
265 /* config knobs for optimizing or interop */
266 /* Generate EAD-EVI routes even if the ES is oper-down. This can be
267 * enabled as an optimization to avoid a storm of updates when an ES
268 * link flaps.
269 */
270 bool ead_evi_adv_for_down_links;
271 /* Enable ES consistency checking */
272 bool consistency_checking;
8bcb09a1
AK
273 /* Use L3 NHGs for host routes in symmetric IRB */
274 bool install_l3nhg;
6348981a 275 bool host_routes_use_l3nhg;
fe8293c3
AK
276 /* Some vendors are not generating the EAD-per-EVI route. This knob
277 * can be turned off to activate a remote ES-PE when the EAD-per-ES
278 * route is rxed i.e. not wait on the EAD-per-EVI route
279 */
280 bool ead_evi_rx;
281#define BGP_EVPN_MH_EAD_EVI_RX_DEF true
282 /* Skip EAD-EVI advertisements by turning off this knob */
283 bool ead_evi_tx;
284#define BGP_EVPN_MH_EAD_EVI_TX_DEF true
70524092
AK
285 /* If the Local ES is inactive we advertise the MAC-IP without the
286 * L3 ecomm
287 */
288 bool suppress_l3_ecomm_on_inactive_es;
c44ab6f1
AK
289};
290
291/****************************************************************************/
7904e9fd 292static inline int bgp_evpn_is_es_local(struct bgp_evpn_es *es)
c44ab6f1
AK
293{
294 return CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL) ? 1 : 0;
295}
296
297extern esi_t *zero_esi;
7904e9fd
AK
298static inline bool bgp_evpn_is_esi_valid(esi_t *esi)
299{
300 return !!memcmp(esi, zero_esi, sizeof(esi_t));
301}
302
c44ab6f1
AK
303static inline esi_t *bgp_evpn_attr_get_esi(struct attr *attr)
304{
7904e9fd
AK
305 return attr ? &attr->esi : zero_esi;
306}
307
308static inline bool bgp_evpn_attr_is_sync(struct attr *attr)
309{
310 return attr ? !!(attr->es_flags &
311 (ATTR_ES_PEER_PROXY | ATTR_ES_PEER_ACTIVE)) : false;
312}
313
314static inline uint32_t bgp_evpn_attr_get_sync_seq(struct attr *attr)
315{
316 return attr ? attr->mm_sync_seqnum : 0;
317}
318
319static inline bool bgp_evpn_attr_is_active_on_peer(struct attr *attr)
320{
321 return attr ?
322 !!(attr->es_flags & ATTR_ES_PEER_ACTIVE) : false;
323}
324
325static inline bool bgp_evpn_attr_is_router_on_peer(struct attr *attr)
326{
327 return attr ?
328 !!(attr->es_flags & ATTR_ES_PEER_ROUTER) : false;
329}
330
331static inline bool bgp_evpn_attr_is_proxy(struct attr *attr)
332{
333 return attr ? !!(attr->es_flags & ATTR_ES_PROXY_ADVERT) : false;
334}
335
336static inline bool bgp_evpn_attr_is_local_es(struct attr *attr)
337{
338 return attr ? !!(attr->es_flags & ATTR_ES_IS_LOCAL) : false;
c44ab6f1
AK
339}
340
74e2bd89
AK
341static inline uint32_t bgp_evpn_attr_get_df_pref(struct attr *attr)
342{
343 return (attr) ? attr->df_pref : 0;
344}
345
70524092
AK
346static inline bool bgp_evpn_local_es_is_active(struct bgp_evpn_es *es)
347{
348 return (es->flags & BGP_EVPNES_OPER_UP)
349 && !(es->flags & BGP_EVPNES_BYPASS);
350}
351
c44ab6f1
AK
352/****************************************************************************/
353extern int bgp_evpn_es_route_install_uninstall(struct bgp *bgp,
354 struct bgp_evpn_es *es, afi_t afi, safi_t safi,
355 struct prefix_evpn *evp, struct bgp_path_info *pi,
356 int install);
9c49ac74 357extern void update_type1_routes_for_evi(struct bgp *bgp, struct bgpevpn *vpn);
c44ab6f1
AK
358int bgp_evpn_type1_route_process(struct peer *peer, afi_t afi, safi_t safi,
359 struct attr *attr, uint8_t *pfx, int psize,
360 uint32_t addpath_id);
361int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi,
362 struct attr *attr, uint8_t *pfx, int psize,
363 uint32_t addpath_id);
185fb14a 364extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
74e2bd89 365 struct in_addr originator_ip, bool oper_up,
74be8313 366 uint16_t df_pref, bool bypass);
c44ab6f1
AK
367extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi);
368extern int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni);
369extern int bgp_evpn_local_es_evi_del(struct bgp *bgp, esi_t *esi, vni_t vni);
370extern int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn,
371 const struct prefix_evpn *p);
372extern int bgp_evpn_remote_es_evi_del(struct bgp *bgp, struct bgpevpn *vpn,
373 const struct prefix_evpn *p);
374extern void bgp_evpn_mh_init(void);
375extern void bgp_evpn_mh_finish(void);
376void bgp_evpn_vni_es_init(struct bgpevpn *vpn);
377void bgp_evpn_vni_es_cleanup(struct bgpevpn *vpn);
378void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj);
379void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail);
380void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni,
381 bool uj, bool detail);
382void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail);
383struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi);
7904e9fd 384extern bool bgp_evpn_is_esi_local(esi_t *esi);
c589d847
AK
385extern void bgp_evpn_vrf_es_init(struct bgp *bgp_vrf);
386extern void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi *es_evi);
387extern void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi *es_evi,
388 struct bgp *bgp_vrf);
26c03e43
AK
389extern void bgp_evpn_path_es_info_free(struct bgp_path_es_info *es_info);
390extern void bgp_evpn_path_es_unlink(struct bgp_path_es_info *es_info);
391extern void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni,
392 esi_t *esi);
6348981a
AK
393extern bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf,
394 struct bgp_path_info *pi, uint32_t *nhg_p);
229587fb
AK
395extern void bgp_evpn_es_vrf_show(struct vty *vty, bool uj,
396 struct bgp_evpn_es *es);
397extern void bgp_evpn_es_vrf_show_esi(struct vty *vty, esi_t *esi, bool uj);
acd1d9bc 398extern void bgp_evpn_switch_ead_evi_rx(void);
70524092 399extern bool bgp_evpn_es_add_l3_ecomm_ok(esi_t *esi);
58bff4d1
AK
400extern void bgp_evpn_es_vrf_use_nhg(struct bgp *bgp_vrf, esi_t *esi,
401 bool *use_l3nhg, bool *is_l3nhg_active,
402 struct bgp_evpn_es_vrf **es_vrf_p);
c44ab6f1 403
185fb14a 404#endif /* _FRR_BGP_EVPN_MH_H */