]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_evpn_private.h
*: auto-convert to SPDX License IDs
[mirror_frr.git] / bgpd / bgp_evpn_private.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* BGP EVPN internal definitions
3 * Copyright (C) 2017 Cumulus Networks, Inc.
4 */
5
6 #ifndef _BGP_EVPN_PRIVATE_H
7 #define _BGP_EVPN_PRIVATE_H
8
9 #include "vxlan.h"
10 #include "zebra.h"
11
12 #include "bgpd/bgpd.h"
13 #include "bgpd/bgp_ecommunity.h"
14
15 #define RT_ADDRSTRLEN 28
16
17 /* EVPN prefix lengths. This represents the sizeof struct evpn_addr
18 * in bits */
19 #define EVPN_ROUTE_PREFIXLEN (sizeof(struct evpn_addr) * 8)
20
21 /* EVPN route RD buffer length */
22 #define BGP_EVPN_PREFIX_RD_LEN 100
23
24 /* packet sizes for EVPN routes */
25 /* Type-1 route should be 25 bytes
26 * RD (8), ESI (10), eth-tag (4), vni (3)
27 */
28 #define BGP_EVPN_TYPE1_PSIZE 25
29 /* Type-4 route should be either 23 or 35 bytes
30 * RD (8), ESI (10), ip-len (1), ip (4 or 16)
31 */
32 #define BGP_EVPN_TYPE4_V4_PSIZE 23
33 #define BGP_EVPN_TYPE4_V6_PSIZE 34
34
35 RB_HEAD(bgp_es_evi_rb_head, bgp_evpn_es_evi);
36 RB_PROTOTYPE(bgp_es_evi_rb_head, bgp_evpn_es_evi, rb_node,
37 bgp_es_evi_rb_cmp);
38 /*
39 * Hash table of EVIs. Right now, the only type of EVI supported is with
40 * VxLAN encapsulation, hence each EVI corresponds to a L2 VNI.
41 * The VNIs are not "created" through BGP but through some other interface
42 * on the system. This table stores VNIs that BGP comes to know as present
43 * on the system (through interaction with zebra) as well as pre-configured
44 * VNIs (which need to be defined in the system to become "live").
45 */
46 struct bgpevpn {
47 vni_t vni;
48 vrf_id_t tenant_vrf_id;
49 ifindex_t svi_ifindex;
50 uint32_t flags;
51 #define VNI_FLAG_CFGD 0x1 /* VNI is user configured */
52 #define VNI_FLAG_LIVE 0x2 /* VNI is "live" */
53 #define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */
54 #define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */
55 #define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */
56 #define VNI_FLAG_USE_TWO_LABELS 0x20 /* Attach both L2-VNI and L3-VNI if
57 needed for this VPN */
58
59 struct bgp *bgp_vrf; /* back pointer to the vrf instance */
60
61 /* Flag to indicate if we are
62 * advertising the g/w mac ip for
63 * this VNI*/
64 uint8_t advertise_gw_macip;
65
66 /* Flag to indicate if we are
67 * advertising subnet for this VNI */
68 uint8_t advertise_subnet;
69
70 /* Flag to indicate if we are advertising the svi mac ip for this VNI*/
71 uint8_t advertise_svi_macip;
72
73 /* Id for deriving the RD
74 * automatically for this VNI */
75 uint16_t rd_id;
76
77 /* RD for this VNI. */
78 struct prefix_rd prd;
79
80 /* Route type 3 field */
81 struct in_addr originator_ip;
82
83 /* PIM-SM MDT group for BUM flooding */
84 struct in_addr mcast_grp;
85
86 /* Import and Export RTs. */
87 struct list *import_rtl;
88 struct list *export_rtl;
89
90 /*
91 * EVPN route that uses gateway IP overlay index as its nexthop
92 * needs to do a recursive lookup.
93 * A remote MAC/IP entry should be present for the gateway IP.
94 * Maintain a hash of the addresses received via remote MAC/IP routes
95 * for efficient gateway IP recursive lookup in this EVI
96 */
97 struct hash *remote_ip_hash;
98
99 /* Route tables for EVPN routes for
100 * this VNI. */
101 struct bgp_table *ip_table;
102 struct bgp_table *mac_table;
103
104 /* RB tree of ES-EVIs */
105 struct bgp_es_evi_rb_head es_evi_rb_tree;
106
107 /* List of local ESs */
108 struct list *local_es_evi_list;
109
110 QOBJ_FIELDS;
111 };
112
113 DECLARE_QOBJ_TYPE(bgpevpn);
114
115 /* Mapping of Import RT to VNIs.
116 * The Import RTs of all VNIs are maintained in a hash table with each
117 * RT linking to all VNIs that will import routes matching this RT.
118 */
119 struct irt_node {
120 /* RT */
121 struct ecommunity_val rt;
122
123 /* List of VNIs importing routes matching this RT. */
124 struct list *vnis;
125 };
126
127 /* Mapping of Import RT to VRFs.
128 * The Import RTs of all VRFss are maintained in a hash table with each
129 * RT linking to all VRFs that will import routes matching this RT.
130 */
131 struct vrf_irt_node {
132 /* RT */
133 struct ecommunity_val rt;
134
135 /* List of VNIs importing routes matching this RT. */
136 struct list *vrfs;
137 };
138
139
140 #define RT_TYPE_IMPORT 1
141 #define RT_TYPE_EXPORT 2
142 #define RT_TYPE_BOTH 3
143
144 #define EVPN_DAD_DEFAULT_TIME 180 /* secs */
145 #define EVPN_DAD_DEFAULT_MAX_MOVES 5 /* default from RFC 7432 */
146 #define EVPN_DAD_DEFAULT_AUTO_RECOVERY_TIME 1800 /* secs */
147
148 struct bgp_evpn_info {
149 /* enable disable dup detect */
150 bool dup_addr_detect;
151
152 /* Detection time(M) */
153 int dad_time;
154 /* Detection max moves(N) */
155 uint32_t dad_max_moves;
156 /* Permanent freeze */
157 bool dad_freeze;
158 /* Recovery time */
159 uint32_t dad_freeze_time;
160
161 /* EVPN enable - advertise svi macip routes */
162 int advertise_svi_macip;
163
164 /* PIP feature knob */
165 bool advertise_pip;
166 /* PIP IP (sys ip) */
167 struct in_addr pip_ip;
168 struct in_addr pip_ip_static;
169 /* PIP MAC (sys MAC) */
170 struct ethaddr pip_rmac;
171 struct ethaddr pip_rmac_static;
172 struct ethaddr pip_rmac_zebra;
173 bool is_anycast_mac;
174 };
175
176 /* This structure defines an entry in remote_ip_hash */
177 struct evpn_remote_ip {
178 struct ipaddr addr;
179 struct list *macip_path_list;
180 };
181
182 /*
183 * Wrapper struct for l3 RT's
184 */
185 struct vrf_route_target {
186 /* flags based on config to determine how RTs are handled */
187 uint8_t flags;
188 #define BGP_VRF_RT_AUTO (1 << 0)
189 #define BGP_VRF_RT_WILD (1 << 1)
190
191 struct ecommunity *ecom;
192 };
193
194 static inline int is_vrf_rd_configured(struct bgp *bgp_vrf)
195 {
196 return (CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD));
197 }
198
199 static inline int bgp_evpn_vrf_rd_matches_existing(struct bgp *bgp_vrf,
200 struct prefix_rd *prd)
201 {
202 return (memcmp(&bgp_vrf->vrf_prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
203 }
204
205 static inline vni_t bgpevpn_get_l3vni(struct bgpevpn *vpn)
206 {
207 return vpn->bgp_vrf ? vpn->bgp_vrf->l3vni : 0;
208 }
209
210 static inline void bgpevpn_get_rmac(struct bgpevpn *vpn, struct ethaddr *rmac)
211 {
212 memset(rmac, 0, sizeof(struct ethaddr));
213 if (!vpn->bgp_vrf)
214 return;
215 memcpy(rmac, &vpn->bgp_vrf->rmac, sizeof(struct ethaddr));
216 }
217
218 static inline struct list *bgpevpn_get_vrf_export_rtl(struct bgpevpn *vpn)
219 {
220 if (!vpn->bgp_vrf)
221 return NULL;
222
223 return vpn->bgp_vrf->vrf_export_rtl;
224 }
225
226 static inline struct list *bgpevpn_get_vrf_import_rtl(struct bgpevpn *vpn)
227 {
228 if (!vpn->bgp_vrf)
229 return NULL;
230
231 return vpn->bgp_vrf->vrf_import_rtl;
232 }
233
234 extern void bgp_evpn_es_evi_vrf_ref(struct bgpevpn *vpn);
235 extern void bgp_evpn_es_evi_vrf_deref(struct bgpevpn *vpn);
236
237 static inline void bgpevpn_unlink_from_l3vni(struct bgpevpn *vpn)
238 {
239 /* bail if vpn is not associated to bgp_vrf */
240 if (!vpn->bgp_vrf)
241 return;
242
243 UNSET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS);
244 listnode_delete(vpn->bgp_vrf->l2vnis, vpn);
245
246 bgp_evpn_es_evi_vrf_deref(vpn);
247
248 /* remove the backpointer to the vrf instance */
249 bgp_unlock(vpn->bgp_vrf);
250 vpn->bgp_vrf = NULL;
251 }
252
253 static inline void bgpevpn_link_to_l3vni(struct bgpevpn *vpn)
254 {
255 struct bgp *bgp_vrf = NULL;
256
257 /* bail if vpn is already associated to vrf */
258 if (vpn->bgp_vrf)
259 return;
260
261 bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id);
262 if (!bgp_vrf)
263 return;
264
265 /* associate the vpn to the bgp_vrf instance */
266 vpn->bgp_vrf = bgp_lock(bgp_vrf);
267 listnode_add_sort(bgp_vrf->l2vnis, vpn);
268
269 /*
270 * If L3VNI is configured,
271 * check if we are advertising two labels for this vpn
272 */
273 if (bgp_vrf->l3vni &&
274 !CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY))
275 SET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS);
276
277 bgp_evpn_es_evi_vrf_ref(vpn);
278 }
279
280 static inline int is_vni_configured(struct bgpevpn *vpn)
281 {
282 return (CHECK_FLAG(vpn->flags, VNI_FLAG_CFGD));
283 }
284
285 static inline int is_vni_live(struct bgpevpn *vpn)
286 {
287 return (CHECK_FLAG(vpn->flags, VNI_FLAG_LIVE));
288 }
289
290 static inline int is_l3vni_live(struct bgp *bgp_vrf)
291 {
292 return (bgp_vrf->l3vni && bgp_vrf->l3vni_svi_ifindex);
293 }
294
295 static inline int is_rd_configured(struct bgpevpn *vpn)
296 {
297 return (CHECK_FLAG(vpn->flags, VNI_FLAG_RD_CFGD));
298 }
299
300 static inline int bgp_evpn_rd_matches_existing(struct bgpevpn *vpn,
301 struct prefix_rd *prd)
302 {
303 return (memcmp(&vpn->prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
304 }
305
306 static inline int is_import_rt_configured(struct bgpevpn *vpn)
307 {
308 return (CHECK_FLAG(vpn->flags, VNI_FLAG_IMPRT_CFGD));
309 }
310
311 static inline int is_export_rt_configured(struct bgpevpn *vpn)
312 {
313 return (CHECK_FLAG(vpn->flags, VNI_FLAG_EXPRT_CFGD));
314 }
315
316 static inline void encode_es_rt_extcomm(struct ecommunity_val *eval,
317 struct ethaddr *mac)
318 {
319 memset(eval, 0, sizeof(struct ecommunity_val));
320 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
321 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT;
322 memcpy(&eval->val[2], mac, ETH_ALEN);
323 }
324
325 static inline void encode_df_elect_extcomm(struct ecommunity_val *eval,
326 uint16_t pref)
327 {
328 memset(eval, 0, sizeof(*eval));
329 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
330 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DF_ELECTION;
331 eval->val[2] = EVPN_MH_DF_ALG_PREF;
332 eval->val[6] = (pref >> 8) & 0xff;
333 eval->val[7] = pref & 0xff;
334 }
335
336 static inline void encode_esi_label_extcomm(struct ecommunity_val *eval,
337 bool single_active)
338 {
339 memset(eval, 0, sizeof(struct ecommunity_val));
340 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
341 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL;
342 if (single_active)
343 eval->val[2] |= (1 << 0);
344 }
345
346 static inline void encode_rmac_extcomm(struct ecommunity_val *eval,
347 struct ethaddr *rmac)
348 {
349 memset(eval, 0, sizeof(*eval));
350 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
351 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
352 memcpy(&eval->val[2], rmac, ETH_ALEN);
353 }
354
355 static inline void encode_default_gw_extcomm(struct ecommunity_val *eval)
356 {
357 memset(eval, 0, sizeof(*eval));
358 eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE;
359 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DEF_GW;
360 }
361
362 static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq,
363 struct ecommunity_val *eval)
364 {
365 memset(eval, 0, sizeof(*eval));
366 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
367 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY;
368 if (static_mac)
369 eval->val[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY;
370 eval->val[4] = (seq >> 24) & 0xff;
371 eval->val[5] = (seq >> 16) & 0xff;
372 eval->val[6] = (seq >> 8) & 0xff;
373 eval->val[7] = seq & 0xff;
374 }
375
376 static inline void encode_na_flag_extcomm(struct ecommunity_val *eval,
377 uint8_t na_flag, bool proxy)
378 {
379 memset(eval, 0, sizeof(*eval));
380 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
381 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ND;
382 if (na_flag)
383 eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG;
384 if (proxy)
385 eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG;
386 }
387
388 static inline void ip_prefix_from_type5_prefix(const struct prefix_evpn *evp,
389 struct prefix *ip)
390 {
391 memset(ip, 0, sizeof(struct prefix));
392 if (is_evpn_prefix_ipaddr_v4(evp)) {
393 ip->family = AF_INET;
394 ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length;
395 memcpy(&(ip->u.prefix4), &(evp->prefix.prefix_addr.ip.ip),
396 IPV4_MAX_BYTELEN);
397 } else if (is_evpn_prefix_ipaddr_v6(evp)) {
398 ip->family = AF_INET6;
399 ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length;
400 memcpy(&(ip->u.prefix6), &(evp->prefix.prefix_addr.ip.ip),
401 IPV6_MAX_BYTELEN);
402 }
403 }
404
405 static inline int is_evpn_prefix_default(const struct prefix *evp)
406 {
407 if (evp->family != AF_EVPN)
408 return 0;
409
410 return ((evp->u.prefix_evpn.prefix_addr.ip_prefix_length == 0) ?
411 1 : 0);
412 }
413
414 static inline void ip_prefix_from_type2_prefix(const struct prefix_evpn *evp,
415 struct prefix *ip)
416 {
417 memset(ip, 0, sizeof(struct prefix));
418 if (is_evpn_prefix_ipaddr_v4(evp)) {
419 ip->family = AF_INET;
420 ip->prefixlen = IPV4_MAX_BITLEN;
421 memcpy(&(ip->u.prefix4), &(evp->prefix.macip_addr.ip.ip),
422 IPV4_MAX_BYTELEN);
423 } else if (is_evpn_prefix_ipaddr_v6(evp)) {
424 ip->family = AF_INET6;
425 ip->prefixlen = IPV6_MAX_BITLEN;
426 memcpy(&(ip->u.prefix6), &(evp->prefix.macip_addr.ip.ip),
427 IPV6_MAX_BYTELEN);
428 }
429 }
430
431 static inline void ip_prefix_from_evpn_prefix(const struct prefix_evpn *evp,
432 struct prefix *ip)
433 {
434 if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
435 ip_prefix_from_type2_prefix(evp, ip);
436 else if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
437 ip_prefix_from_type5_prefix(evp, ip);
438 }
439
440 static inline void build_evpn_type2_prefix(struct prefix_evpn *p,
441 struct ethaddr *mac,
442 struct ipaddr *ip)
443 {
444 memset(p, 0, sizeof(struct prefix_evpn));
445 p->family = AF_EVPN;
446 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
447 p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
448 memcpy(&p->prefix.macip_addr.mac.octet, mac->octet, ETH_ALEN);
449 p->prefix.macip_addr.ip.ipa_type = IPADDR_NONE;
450 memcpy(&p->prefix.macip_addr.ip, ip, sizeof(*ip));
451 }
452
453 static inline void
454 build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp,
455 const struct prefix *ip_prefix)
456 {
457 struct ipaddr ip;
458
459 memset(&ip, 0, sizeof(struct ipaddr));
460 if (ip_prefix->family == AF_INET) {
461 ip.ipa_type = IPADDR_V4;
462 memcpy(&ip.ipaddr_v4, &ip_prefix->u.prefix4,
463 sizeof(struct in_addr));
464 } else {
465 ip.ipa_type = IPADDR_V6;
466 memcpy(&ip.ipaddr_v6, &ip_prefix->u.prefix6,
467 sizeof(struct in6_addr));
468 }
469
470 memset(evp, 0, sizeof(struct prefix_evpn));
471 evp->family = AF_EVPN;
472 evp->prefixlen = EVPN_ROUTE_PREFIXLEN;
473 evp->prefix.route_type = BGP_EVPN_IP_PREFIX_ROUTE;
474 evp->prefix.prefix_addr.ip_prefix_length = ip_prefix->prefixlen;
475 evp->prefix.prefix_addr.ip.ipa_type = ip.ipa_type;
476 memcpy(&evp->prefix.prefix_addr.ip, &ip, sizeof(struct ipaddr));
477 }
478
479 static inline void build_evpn_type3_prefix(struct prefix_evpn *p,
480 struct in_addr originator_ip)
481 {
482 memset(p, 0, sizeof(struct prefix_evpn));
483 p->family = AF_EVPN;
484 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
485 p->prefix.route_type = BGP_EVPN_IMET_ROUTE;
486 p->prefix.imet_addr.ip.ipa_type = IPADDR_V4;
487 p->prefix.imet_addr.ip.ipaddr_v4 = originator_ip;
488 }
489
490 static inline void build_evpn_type4_prefix(struct prefix_evpn *p,
491 esi_t *esi,
492 struct in_addr originator_ip)
493 {
494 memset(p, 0, sizeof(struct prefix_evpn));
495 p->family = AF_EVPN;
496 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
497 p->prefix.route_type = BGP_EVPN_ES_ROUTE;
498 p->prefix.es_addr.ip_prefix_length = IPV4_MAX_BITLEN;
499 p->prefix.es_addr.ip.ipa_type = IPADDR_V4;
500 p->prefix.es_addr.ip.ipaddr_v4 = originator_ip;
501 memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t));
502 }
503
504 static inline void build_evpn_type1_prefix(struct prefix_evpn *p,
505 uint32_t eth_tag,
506 esi_t *esi,
507 struct in_addr originator_ip)
508 {
509 memset(p, 0, sizeof(struct prefix_evpn));
510 p->family = AF_EVPN;
511 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
512 p->prefix.route_type = BGP_EVPN_AD_ROUTE;
513 p->prefix.ead_addr.eth_tag = eth_tag;
514 p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
515 p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
516 memcpy(&p->prefix.ead_addr.esi, esi, sizeof(esi_t));
517 }
518
519 static inline void evpn_type1_prefix_global_copy(struct prefix_evpn *global_p,
520 const struct prefix_evpn *vni_p)
521 {
522 memcpy(global_p, vni_p, sizeof(*global_p));
523 global_p->prefix.ead_addr.ip.ipa_type = 0;
524 global_p->prefix.ead_addr.ip.ipaddr_v4.s_addr = INADDR_ANY;
525 global_p->prefix.ead_addr.frag_id = 0;
526 }
527
528 /* EAD prefix in the global table doesn't include the VTEP-IP so
529 * we need to create a different copy for the VNI
530 */
531 static inline struct prefix_evpn *
532 evpn_type1_prefix_vni_ip_copy(struct prefix_evpn *vni_p,
533 const struct prefix_evpn *global_p,
534 struct in_addr originator_ip)
535 {
536 memcpy(vni_p, global_p, sizeof(*vni_p));
537 vni_p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
538 vni_p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
539
540 return vni_p;
541 }
542
543 static inline void evpn_type2_prefix_global_copy(
544 struct prefix_evpn *global_p, const struct prefix_evpn *vni_p,
545 const struct ethaddr *mac, const struct ipaddr *ip)
546 {
547 memcpy(global_p, vni_p, sizeof(*global_p));
548
549 if (mac)
550 global_p->prefix.macip_addr.mac = *mac;
551
552 if (ip)
553 global_p->prefix.macip_addr.ip = *ip;
554 }
555
556 static inline void
557 evpn_type2_prefix_vni_ip_copy(struct prefix_evpn *vni_p,
558 const struct prefix_evpn *global_p)
559 {
560 memcpy(vni_p, global_p, sizeof(*vni_p));
561 memset(&vni_p->prefix.macip_addr.mac, 0, sizeof(struct ethaddr));
562 }
563
564 static inline void
565 evpn_type2_prefix_vni_mac_copy(struct prefix_evpn *vni_p,
566 const struct prefix_evpn *global_p)
567 {
568 memcpy(vni_p, global_p, sizeof(*vni_p));
569 memset(&vni_p->prefix.macip_addr.ip, 0, sizeof(struct ipaddr));
570 }
571
572 /* Get MAC of path_info prefix */
573 static inline struct ethaddr *
574 evpn_type2_path_info_get_mac(const struct bgp_path_info *local_pi)
575 {
576 assert(local_pi->extra);
577 return &local_pi->extra->vni_info.mac;
578 }
579
580 /* Get IP of path_info prefix */
581 static inline struct ipaddr *
582 evpn_type2_path_info_get_ip(const struct bgp_path_info *local_pi)
583 {
584 assert(local_pi->extra);
585 return &local_pi->extra->vni_info.ip;
586 }
587
588 /* Set MAC of path_info prefix */
589 static inline void evpn_type2_path_info_set_mac(struct bgp_path_info *local_pi,
590 const struct ethaddr mac)
591 {
592 assert(local_pi->extra);
593 local_pi->extra->vni_info.mac = mac;
594 }
595
596 /* Set IP of path_info prefix */
597 static inline void evpn_type2_path_info_set_ip(struct bgp_path_info *local_pi,
598 const struct ipaddr ip)
599 {
600 assert(local_pi->extra);
601 local_pi->extra->vni_info.ip = ip;
602 }
603
604 /* Is the IP empty for the RT's dest? */
605 static inline bool is_evpn_type2_dest_ipaddr_none(const struct bgp_dest *dest)
606 {
607 const struct prefix_evpn *evp =
608 (const struct prefix_evpn *)bgp_dest_get_prefix(dest);
609
610 assert(evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE);
611 return is_evpn_prefix_ipaddr_none(evp);
612 }
613
614 static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
615 safi_t safi)
616 {
617 if (afi == AFI_IP &&
618 CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
619 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4))
620 return 1;
621 else if (afi == AFI_IP6 &&
622 CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
623 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6))
624 return 1;
625 return 0;
626 }
627
628 static inline void es_get_system_mac(esi_t *esi,
629 struct ethaddr *mac)
630 {
631 /*
632 * for type-1 and type-3 ESIs,
633 * the system mac starts at val[1]
634 */
635 memcpy(mac, &esi->val[1], ETH_ALEN);
636 }
637
638 static inline bool bgp_evpn_is_svi_macip_enabled(struct bgpevpn *vpn)
639 {
640 struct bgp *bgp_evpn = NULL;
641
642 bgp_evpn = bgp_get_evpn();
643
644 return (bgp_evpn->evpn_info->advertise_svi_macip ||
645 vpn->advertise_svi_macip);
646 }
647
648 static inline bool bgp_evpn_is_path_local(struct bgp *bgp,
649 struct bgp_path_info *pi)
650 {
651 return (pi->peer == bgp->peer_self
652 && pi->type == ZEBRA_ROUTE_BGP
653 && pi->sub_type == BGP_ROUTE_STATIC);
654 }
655
656 extern struct zclient *zclient;
657
658 extern void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf,
659 afi_t afi, safi_t safi,
660 bool add);
661 extern void evpn_rt_delete_auto(struct bgp *bgp, vni_t vni, struct list *rtl,
662 bool is_l3);
663 extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf,
664 struct ecommunity *ecomadd);
665 extern void bgp_evpn_configure_export_auto_rt_for_vrf(struct bgp *bgp_vrf);
666 extern void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp *bgp_vrf,
667 struct ecommunity *ecomdel);
668 extern void bgp_evpn_unconfigure_export_auto_rt_for_vrf(struct bgp *bgp_vrf);
669 extern void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf,
670 struct ecommunity *ecomadd,
671 bool is_wildcard);
672 extern void bgp_evpn_configure_import_auto_rt_for_vrf(struct bgp *bgp_vrf);
673 extern void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf,
674 struct ecommunity *ecomdel);
675 extern void bgp_evpn_unconfigure_import_auto_rt_for_vrf(struct bgp *bgp_vrf);
676 extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp,
677 struct bgpevpn *vpn);
678 extern void bgp_evpn_handle_autort_change(struct bgp *bgp);
679 extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw);
680 extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn,
681 int withdraw);
682 extern int bgp_evpn_install_routes(struct bgp *bgp, struct bgpevpn *vpn);
683 extern int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn);
684 extern void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf);
685 extern void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf);
686 extern void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn);
687 extern void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp,
688 struct bgpevpn *vpn);
689 extern void bgp_evpn_derive_auto_rt_import(struct bgp *bgp,
690 struct bgpevpn *vpn);
691 extern void bgp_evpn_derive_auto_rt_export(struct bgp *bgp,
692 struct bgpevpn *vpn);
693 extern void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn);
694 extern void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp);
695 extern struct bgpevpn *bgp_evpn_lookup_vni(struct bgp *bgp, vni_t vni);
696 extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
697 struct in_addr originator_ip,
698 vrf_id_t tenant_vrf_id,
699 struct in_addr mcast_grp,
700 ifindex_t svi_ifindex);
701 extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn);
702 extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni);
703 extern int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn);
704 extern void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
705 struct bgp_dest *dest,
706 struct bgp_path_info **pi);
707 int vni_list_cmp(void *p1, void *p2);
708 extern int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
709 struct bgp_dest *dest);
710 extern struct bgp_dest *
711 bgp_evpn_global_node_get(struct bgp_table *table, afi_t afi, safi_t safi,
712 const struct prefix_evpn *evp, struct prefix_rd *prd,
713 const struct bgp_path_info *local_pi);
714 extern struct bgp_dest *
715 bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
716 const struct prefix_evpn *evp,
717 struct prefix_rd *prd,
718 const struct bgp_path_info *local_pi);
719 extern struct bgp_dest *
720 bgp_evpn_vni_ip_node_get(struct bgp_table *const table,
721 const struct prefix_evpn *evp,
722 const struct bgp_path_info *parent_pi);
723 extern struct bgp_dest *
724 bgp_evpn_vni_ip_node_lookup(const struct bgp_table *const table,
725 const struct prefix_evpn *evp,
726 const struct bgp_path_info *parent_pi);
727 extern struct bgp_dest *
728 bgp_evpn_vni_mac_node_get(struct bgp_table *const table,
729 const struct prefix_evpn *evp,
730 const struct bgp_path_info *parent_pi);
731 extern struct bgp_dest *
732 bgp_evpn_vni_mac_node_lookup(const struct bgp_table *const table,
733 const struct prefix_evpn *evp,
734 const struct bgp_path_info *parent_pi);
735 extern struct bgp_dest *
736 bgp_evpn_vni_node_get(struct bgpevpn *vpn, const struct prefix_evpn *p,
737 const struct bgp_path_info *parent_pi);
738 extern struct bgp_dest *
739 bgp_evpn_vni_node_lookup(const struct bgpevpn *vpn, const struct prefix_evpn *p,
740 const struct bgp_path_info *parent_pi);
741
742 extern void bgp_evpn_import_route_in_vrfs(struct bgp_path_info *pi, int import);
743 extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
744 struct bgpevpn *vpn,
745 struct bgp_node *rn,
746 struct bgp_path_info *local_pi,
747 const char *caller);
748 extern int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf,
749 struct bgp_path_info *pi,
750 int install);
751 extern void bgp_evpn_import_type2_route(struct bgp_path_info *pi, int import);
752 extern void bgp_evpn_xxport_delete_ecomm(void *val);
753 extern int bgp_evpn_route_target_cmp(struct ecommunity *ecom1,
754 struct ecommunity *ecom2);
755 #endif /* _BGP_EVPN_PRIVATE_H */