]>
Commit | Line | Data |
---|---|---|
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 | */ | |
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) | |
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 AK |
107 | * element is bgp_path_info_extra->es_info |
108 | */ | |
109 | struct list *macip_path_list; | |
110 | ||
c44ab6f1 AK |
111 | /* Number of remote VNIs referencing this ES */ |
112 | uint32_t remote_es_evi_cnt; | |
113 | ||
114 | uint32_t inconsistencies; | |
115 | /* there are one or more EVIs whose VTEP list doesn't match | |
116 | * with the ES's VTEP list | |
117 | */ | |
118 | #define BGP_EVPNES_INCONS_VTEP_LIST (1 << 0) | |
119 | ||
120 | /* number of es-evi entries whose VTEP list doesn't match | |
121 | * with the ES's | |
122 | */ | |
123 | uint32_t incons_evi_vtep_cnt; | |
124 | ||
74e2bd89 AK |
125 | /* preference config for BUM-DF election. advertised via the ESR. */ |
126 | uint16_t df_pref; | |
127 | ||
96244aca | 128 | QOBJ_FIELDS; |
c44ab6f1 | 129 | }; |
96244aca | 130 | DECLARE_QOBJ_TYPE(bgp_evpn_es); |
c44ab6f1 AK |
131 | RB_HEAD(bgp_es_rb_head, bgp_evpn_es); |
132 | RB_PROTOTYPE(bgp_es_rb_head, bgp_evpn_es, rb_node, bgp_es_rb_cmp); | |
133 | ||
134 | /* PE attached to an ES */ | |
135 | struct bgp_evpn_es_vtep { | |
136 | struct bgp_evpn_es *es; /* parent ES */ | |
137 | struct in_addr vtep_ip; | |
138 | ||
139 | uint32_t flags; | |
140 | /* Rxed a Type4 route from this PE */ | |
141 | #define BGP_EVPNES_VTEP_ESR (1 << 0) | |
142 | /* Active (rxed EAD-ES and EAD-EVI) and can be included as | |
143 | * a nexthop | |
144 | */ | |
145 | #define BGP_EVPNES_VTEP_ACTIVE (1 << 1) | |
146 | ||
147 | uint32_t evi_cnt; /* es_evis referencing this vtep as an active path */ | |
148 | ||
74e2bd89 AK |
149 | /* Algorithm and preference for DF election. Rxed via the ESR */ |
150 | uint8_t df_alg; | |
151 | uint16_t df_pref; | |
152 | ||
c44ab6f1 AK |
153 | /* memory used for adding the entry to es->es_vtep_list */ |
154 | struct listnode es_listnode; | |
155 | }; | |
156 | ||
c589d847 AK |
157 | /* ES-VRF element needed for managing L3 NHGs. It is implicitly created |
158 | * when an ES-EVI is associated with a tenant VRF | |
159 | */ | |
160 | struct bgp_evpn_es_vrf { | |
161 | struct bgp_evpn_es *es; | |
162 | struct bgp *bgp_vrf; | |
163 | ||
164 | uint32_t flags; | |
165 | /* NHG can only be activated if there are active VTEPs in the ES and | |
166 | * there is a valid L3-VNI associated with the VRF | |
167 | */ | |
168 | #define BGP_EVPNES_VRF_NHG_ACTIVE (1 << 0) | |
169 | ||
170 | /* memory used for adding the es_vrf to | |
171 | * es_vrf->bgp_vrf->es_vrf_rb_tree | |
172 | */ | |
173 | RB_ENTRY(bgp_evpn_es_vrf) rb_node; | |
174 | ||
175 | /* memory used for linking the es_vrf to es_vrf->es->es_vrf_list */ | |
176 | struct listnode es_listnode; | |
177 | ||
178 | uint32_t nhg_id; | |
6348981a | 179 | uint32_t v6_nhg_id; |
c589d847 AK |
180 | |
181 | /* Number of ES-EVI entries associated with this ES-VRF */ | |
182 | uint32_t ref_cnt; | |
183 | }; | |
184 | ||
c44ab6f1 AK |
185 | /* ES per-EVI info |
186 | * - ES-EVIs are maintained per-L2-VNI (vpn->es_evi_rb_tree) | |
187 | * - ES-EVIs are also linked to the parent ES (es->es_evi_list) | |
188 | * - Local ES-EVIs are created by zebra (via config). They are linked to a | |
189 | * per-VNI list (vpn->local_es_evi_list) for quick access | |
190 | * - Remote ES-EVIs are created implicitly when a bgp_evpn_es_evi_vtep | |
191 | * references it. | |
192 | */ | |
193 | struct bgp_evpn_es_evi { | |
194 | struct bgp_evpn_es *es; | |
195 | struct bgpevpn *vpn; | |
196 | ||
197 | /* ES-EVI flags */ | |
198 | uint32_t flags; | |
199 | /* local ES-EVI, created by zebra */ | |
200 | #define BGP_EVPNES_EVI_LOCAL (1 << 0) | |
201 | /* created via a remote VTEP imported by BGP */ | |
202 | #define BGP_EVPNES_EVI_REMOTE (1 << 1) | |
203 | #define BGP_EVPNES_EVI_INCONS_VTEP_LIST (1 << 2) | |
204 | ||
205 | /* memory used for adding the es_evi to es_evi->vpn->es_evi_rb_tree */ | |
206 | RB_ENTRY(bgp_evpn_es_evi) rb_node; | |
207 | /* memory used for linking the es_evi to | |
208 | * es_evi->vpn->local_es_evi_list | |
209 | */ | |
210 | struct listnode l2vni_listnode; | |
211 | /* memory used for linking the es_evi to | |
212 | * es_evi->es->es_evi_list | |
213 | */ | |
214 | struct listnode es_listnode; | |
215 | ||
216 | /* list of PEs (bgp_evpn_es_evi_vtep) attached to the ES for this VNI */ | |
217 | struct list *es_evi_vtep_list; | |
c589d847 AK |
218 | |
219 | struct bgp_evpn_es_vrf *es_vrf; | |
c44ab6f1 AK |
220 | }; |
221 | ||
222 | /* PE attached to an ES for a VNI. This entry is created when an EAD-per-ES | |
223 | * or EAD-per-EVI Type1 route is imported into the VNI. | |
224 | */ | |
225 | struct bgp_evpn_es_evi_vtep { | |
226 | struct bgp_evpn_es_evi *es_evi; /* parent ES-EVI */ | |
227 | struct in_addr vtep_ip; | |
228 | ||
229 | uint32_t flags; | |
230 | /* Rxed an EAD-per-ES route from the PE */ | |
231 | #define BGP_EVPN_EVI_VTEP_EAD_PER_ES (1 << 0) /* rxed EAD-per-ES */ | |
232 | /* Rxed an EAD-per-EVI route from the PE */ | |
233 | #define BGP_EVPN_EVI_VTEP_EAD_PER_EVI (1 << 1) /* rxed EAD-per-EVI */ | |
234 | /* VTEP is active i.e. will result in the creation of an es-vtep */ | |
235 | #define BGP_EVPN_EVI_VTEP_ACTIVE (1 << 2) | |
236 | #define BGP_EVPN_EVI_VTEP_EAD (BGP_EVPN_EVI_VTEP_EAD_PER_ES |\ | |
237 | BGP_EVPN_EVI_VTEP_EAD_PER_EVI) | |
238 | ||
239 | /* memory used for adding the entry to es_evi->es_evi_vtep_list */ | |
240 | struct listnode es_evi_listnode; | |
241 | struct bgp_evpn_es_vtep *es_vtep; | |
242 | }; | |
243 | ||
244 | /* multihoming information stored in bgp_master */ | |
245 | #define bgp_mh_info (bm->mh_info) | |
246 | struct bgp_evpn_mh_info { | |
247 | /* RB tree of Ethernet segments (used for EVPN-MH) */ | |
248 | struct bgp_es_rb_head es_rb_tree; | |
249 | /* List of local ESs */ | |
250 | struct list *local_es_list; | |
251 | /* List of ESs with pending/periodic processing */ | |
252 | struct list *pend_es_list; | |
253 | /* periodic timer for running background consistency checks */ | |
254 | struct thread *t_cons_check; | |
255 | ||
256 | /* config knobs for optimizing or interop */ | |
257 | /* Generate EAD-EVI routes even if the ES is oper-down. This can be | |
258 | * enabled as an optimization to avoid a storm of updates when an ES | |
259 | * link flaps. | |
260 | */ | |
261 | bool ead_evi_adv_for_down_links; | |
262 | /* Enable ES consistency checking */ | |
263 | bool consistency_checking; | |
8bcb09a1 AK |
264 | /* Use L3 NHGs for host routes in symmetric IRB */ |
265 | bool install_l3nhg; | |
6348981a | 266 | bool host_routes_use_l3nhg; |
fe8293c3 AK |
267 | /* Some vendors are not generating the EAD-per-EVI route. This knob |
268 | * can be turned off to activate a remote ES-PE when the EAD-per-ES | |
269 | * route is rxed i.e. not wait on the EAD-per-EVI route | |
270 | */ | |
271 | bool ead_evi_rx; | |
272 | #define BGP_EVPN_MH_EAD_EVI_RX_DEF true | |
273 | /* Skip EAD-EVI advertisements by turning off this knob */ | |
274 | bool ead_evi_tx; | |
275 | #define BGP_EVPN_MH_EAD_EVI_TX_DEF true | |
c44ab6f1 AK |
276 | }; |
277 | ||
278 | /****************************************************************************/ | |
7904e9fd | 279 | static inline int bgp_evpn_is_es_local(struct bgp_evpn_es *es) |
c44ab6f1 AK |
280 | { |
281 | return CHECK_FLAG(es->flags, BGP_EVPNES_LOCAL) ? 1 : 0; | |
282 | } | |
283 | ||
284 | extern esi_t *zero_esi; | |
7904e9fd AK |
285 | static inline bool bgp_evpn_is_esi_valid(esi_t *esi) |
286 | { | |
287 | return !!memcmp(esi, zero_esi, sizeof(esi_t)); | |
288 | } | |
289 | ||
c44ab6f1 AK |
290 | static inline esi_t *bgp_evpn_attr_get_esi(struct attr *attr) |
291 | { | |
7904e9fd AK |
292 | return attr ? &attr->esi : zero_esi; |
293 | } | |
294 | ||
295 | static inline bool bgp_evpn_attr_is_sync(struct attr *attr) | |
296 | { | |
297 | return attr ? !!(attr->es_flags & | |
298 | (ATTR_ES_PEER_PROXY | ATTR_ES_PEER_ACTIVE)) : false; | |
299 | } | |
300 | ||
301 | static inline uint32_t bgp_evpn_attr_get_sync_seq(struct attr *attr) | |
302 | { | |
303 | return attr ? attr->mm_sync_seqnum : 0; | |
304 | } | |
305 | ||
306 | static inline bool bgp_evpn_attr_is_active_on_peer(struct attr *attr) | |
307 | { | |
308 | return attr ? | |
309 | !!(attr->es_flags & ATTR_ES_PEER_ACTIVE) : false; | |
310 | } | |
311 | ||
312 | static inline bool bgp_evpn_attr_is_router_on_peer(struct attr *attr) | |
313 | { | |
314 | return attr ? | |
315 | !!(attr->es_flags & ATTR_ES_PEER_ROUTER) : false; | |
316 | } | |
317 | ||
318 | static inline bool bgp_evpn_attr_is_proxy(struct attr *attr) | |
319 | { | |
320 | return attr ? !!(attr->es_flags & ATTR_ES_PROXY_ADVERT) : false; | |
321 | } | |
322 | ||
323 | static inline bool bgp_evpn_attr_is_local_es(struct attr *attr) | |
324 | { | |
325 | return attr ? !!(attr->es_flags & ATTR_ES_IS_LOCAL) : false; | |
c44ab6f1 AK |
326 | } |
327 | ||
74e2bd89 AK |
328 | static inline uint32_t bgp_evpn_attr_get_df_pref(struct attr *attr) |
329 | { | |
330 | return (attr) ? attr->df_pref : 0; | |
331 | } | |
332 | ||
c44ab6f1 AK |
333 | /****************************************************************************/ |
334 | extern int bgp_evpn_es_route_install_uninstall(struct bgp *bgp, | |
335 | struct bgp_evpn_es *es, afi_t afi, safi_t safi, | |
336 | struct prefix_evpn *evp, struct bgp_path_info *pi, | |
337 | int install); | |
9c49ac74 | 338 | extern void update_type1_routes_for_evi(struct bgp *bgp, struct bgpevpn *vpn); |
c44ab6f1 AK |
339 | int bgp_evpn_type1_route_process(struct peer *peer, afi_t afi, safi_t safi, |
340 | struct attr *attr, uint8_t *pfx, int psize, | |
341 | uint32_t addpath_id); | |
342 | int bgp_evpn_type4_route_process(struct peer *peer, afi_t afi, safi_t safi, | |
343 | struct attr *attr, uint8_t *pfx, int psize, | |
344 | uint32_t addpath_id); | |
185fb14a | 345 | extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi, |
74e2bd89 | 346 | struct in_addr originator_ip, bool oper_up, |
74be8313 | 347 | uint16_t df_pref, bool bypass); |
c44ab6f1 AK |
348 | extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi); |
349 | extern int bgp_evpn_local_es_evi_add(struct bgp *bgp, esi_t *esi, vni_t vni); | |
350 | extern int bgp_evpn_local_es_evi_del(struct bgp *bgp, esi_t *esi, vni_t vni); | |
351 | extern int bgp_evpn_remote_es_evi_add(struct bgp *bgp, struct bgpevpn *vpn, | |
352 | const struct prefix_evpn *p); | |
353 | extern int bgp_evpn_remote_es_evi_del(struct bgp *bgp, struct bgpevpn *vpn, | |
354 | const struct prefix_evpn *p); | |
355 | extern void bgp_evpn_mh_init(void); | |
356 | extern void bgp_evpn_mh_finish(void); | |
357 | void bgp_evpn_vni_es_init(struct bgpevpn *vpn); | |
358 | void bgp_evpn_vni_es_cleanup(struct bgpevpn *vpn); | |
359 | void bgp_evpn_es_show_esi(struct vty *vty, esi_t *esi, bool uj); | |
360 | void bgp_evpn_es_show(struct vty *vty, bool uj, bool detail); | |
361 | void bgp_evpn_es_evi_show_vni(struct vty *vty, vni_t vni, | |
362 | bool uj, bool detail); | |
363 | void bgp_evpn_es_evi_show(struct vty *vty, bool uj, bool detail); | |
364 | struct bgp_evpn_es *bgp_evpn_es_find(const esi_t *esi); | |
7904e9fd | 365 | extern bool bgp_evpn_is_esi_local(esi_t *esi); |
c589d847 AK |
366 | extern void bgp_evpn_vrf_es_init(struct bgp *bgp_vrf); |
367 | extern void bgp_evpn_es_vrf_deref(struct bgp_evpn_es_evi *es_evi); | |
368 | extern void bgp_evpn_es_vrf_ref(struct bgp_evpn_es_evi *es_evi, | |
369 | struct bgp *bgp_vrf); | |
26c03e43 AK |
370 | extern void bgp_evpn_path_es_info_free(struct bgp_path_es_info *es_info); |
371 | extern void bgp_evpn_path_es_unlink(struct bgp_path_es_info *es_info); | |
372 | extern void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, | |
373 | esi_t *esi); | |
374 | extern bool bgp_evpn_es_is_vtep_active(esi_t *esi, struct in_addr nh); | |
6348981a AK |
375 | extern bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, |
376 | struct bgp_path_info *pi, uint32_t *nhg_p); | |
229587fb AK |
377 | extern void bgp_evpn_es_vrf_show(struct vty *vty, bool uj, |
378 | struct bgp_evpn_es *es); | |
379 | extern void bgp_evpn_es_vrf_show_esi(struct vty *vty, esi_t *esi, bool uj); | |
acd1d9bc | 380 | extern void bgp_evpn_switch_ead_evi_rx(void); |
c44ab6f1 | 381 | |
185fb14a | 382 | #endif /* _FRR_BGP_EVPN_MH_H */ |