]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn_private.h
Merge pull request #11138 from opensourcerouting/fix/rpki
[mirror_frr.git] / bgpd / bgp_evpn_private.h
CommitLineData
a4168ebc 1/* BGP EVPN internal definitions
2 * Copyright (C) 2017 Cumulus Networks, Inc.
3 *
4 * This file is part of FRR.
5 *
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#ifndef _BGP_EVPN_PRIVATE_H
23#define _BGP_EVPN_PRIVATE_H
24
25#include "vxlan.h"
26#include "zebra.h"
27
28#include "bgpd/bgpd.h"
29#include "bgpd/bgp_ecommunity.h"
30
60466a63 31#define RT_ADDRSTRLEN 28
9c92b5f7 32
2f04c4f0
AK
33/* EVPN prefix lengths. This represents the sizeof struct evpn_addr
34 * in bits */
35#define EVPN_ROUTE_PREFIXLEN (sizeof(struct evpn_addr) * 8)
a4168ebc 36
c44ab6f1
AK
37/* EVPN route RD buffer length */
38#define BGP_EVPN_PREFIX_RD_LEN 100
39
40/* packet sizes for EVPN routes */
41/* Type-1 route should be 25 bytes
42 * RD (8), ESI (10), eth-tag (4), vni (3)
43 */
44#define BGP_EVPN_TYPE1_PSIZE 25
45/* Type-4 route should be either 23 or 35 bytes
46 * RD (8), ESI (10), ip-len (1), ip (4 or 16)
47 */
48#define BGP_EVPN_TYPE4_V4_PSIZE 23
49#define BGP_EVPN_TYPE4_V6_PSIZE 34
50
c44ab6f1
AK
51RB_HEAD(bgp_es_evi_rb_head, bgp_evpn_es_evi);
52RB_PROTOTYPE(bgp_es_evi_rb_head, bgp_evpn_es_evi, rb_node,
53 bgp_es_evi_rb_cmp);
a4168ebc 54/*
55 * Hash table of EVIs. Right now, the only type of EVI supported is with
56 * VxLAN encapsulation, hence each EVI corresponds to a L2 VNI.
57 * The VNIs are not "created" through BGP but through some other interface
58 * on the system. This table stores VNIs that BGP comes to know as present
59 * on the system (through interaction with zebra) as well as pre-configured
60 * VNIs (which need to be defined in the system to become "live").
61 */
d62a17ae 62struct bgpevpn {
63 vni_t vni;
29c53922 64 vrf_id_t tenant_vrf_id;
9daa5d47 65 ifindex_t svi_ifindex;
d7c0a89a 66 uint32_t flags;
a4168ebc 67#define VNI_FLAG_CFGD 0x1 /* VNI is user configured */
68#define VNI_FLAG_LIVE 0x2 /* VNI is "live" */
69#define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */
70#define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */
71#define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */
c48d9f5f
MK
72#define VNI_FLAG_USE_TWO_LABELS 0x20 /* Attach both L2-VNI and L3-VNI if
73 needed for this VPN */
a4168ebc 74
bc4606bd
MK
75 struct bgp *bgp_vrf; /* back pointer to the vrf instance */
76
996c9314
LB
77 /* Flag to indicate if we are
78 * advertising the g/w mac ip for
79 * this VNI*/
d7c0a89a 80 uint8_t advertise_gw_macip;
1a98c087 81
d7c0a89a
QY
82 /* Flag to indicate if we are
83 * advertising subnet for this VNI */
84 uint8_t advertise_subnet;
31310b25 85
24864e44
CS
86 /* Flag to indicate if we are advertising the svi mac ip for this VNI*/
87 uint8_t advertise_svi_macip;
88
d7c0a89a
QY
89 /* Id for deriving the RD
90 * automatically for this VNI */
91 uint16_t rd_id;
a4168ebc 92
d7c0a89a
QY
93 /* RD for this VNI. */
94 struct prefix_rd prd;
a4168ebc 95
d7c0a89a
QY
96 /* Route type 3 field */
97 struct in_addr originator_ip;
a4168ebc 98
76d07c7a
AK
99 /* PIM-SM MDT group for BUM flooding */
100 struct in_addr mcast_grp;
101
d7c0a89a
QY
102 /* Import and Export RTs. */
103 struct list *import_rtl;
104 struct list *export_rtl;
a4168ebc 105
021b6596
AD
106 /*
107 * EVPN route that uses gateway IP overlay index as its nexthop
108 * needs to do a recursive lookup.
109 * A remote MAC/IP entry should be present for the gateway IP.
110 * Maintain a hash of the addresses received via remote MAC/IP routes
111 * for efficient gateway IP recursive lookup in this EVI
112 */
113 struct hash *remote_ip_hash;
114
d7c0a89a
QY
115 /* Route table for EVPN routes for
116 * this VNI. */
117 struct bgp_table *route_table;
a4168ebc 118
c44ab6f1
AK
119 /* RB tree of ES-EVIs */
120 struct bgp_es_evi_rb_head es_evi_rb_tree;
50f74cf1 121
c44ab6f1
AK
122 /* List of local ESs */
123 struct list *local_es_evi_list;
50f74cf1 124
96244aca 125 QOBJ_FIELDS;
50f74cf1 126};
127
96244aca 128DECLARE_QOBJ_TYPE(bgpevpn);
50f74cf1 129
a4168ebc 130/* Mapping of Import RT to VNIs.
131 * The Import RTs of all VNIs are maintained in a hash table with each
132 * RT linking to all VNIs that will import routes matching this RT.
133 */
d62a17ae 134struct irt_node {
135 /* RT */
136 struct ecommunity_val rt;
a4168ebc 137
d62a17ae 138 /* List of VNIs importing routes matching this RT. */
139 struct list *vnis;
a4168ebc 140};
141
10ebe1ab
MK
142/* Mapping of Import RT to VRFs.
143 * The Import RTs of all VRFss are maintained in a hash table with each
144 * RT linking to all VRFs that will import routes matching this RT.
145 */
146struct vrf_irt_node {
147 /* RT */
148 struct ecommunity_val rt;
149
150 /* List of VNIs importing routes matching this RT. */
151 struct list *vrfs;
152};
153
154
128ea8ab 155#define RT_TYPE_IMPORT 1
156#define RT_TYPE_EXPORT 2
157#define RT_TYPE_BOTH 3
158
85c8d83b
CS
159#define EVPN_DAD_DEFAULT_TIME 180 /* secs */
160#define EVPN_DAD_DEFAULT_MAX_MOVES 5 /* default from RFC 7432 */
161#define EVPN_DAD_DEFAULT_AUTO_RECOVERY_TIME 1800 /* secs */
162
163struct bgp_evpn_info {
164 /* enable disable dup detect */
165 bool dup_addr_detect;
166
167 /* Detection time(M) */
168 int dad_time;
169 /* Detection max moves(N) */
170 uint32_t dad_max_moves;
171 /* Permanent freeze */
172 bool dad_freeze;
173 /* Recovery time */
174 uint32_t dad_freeze_time;
24864e44
CS
175
176 /* EVPN enable - advertise svi macip routes */
177 int advertise_svi_macip;
178
5394a276
CS
179 /* PIP feature knob */
180 bool advertise_pip;
181 /* PIP IP (sys ip) */
182 struct in_addr pip_ip;
183 struct in_addr pip_ip_static;
184 /* PIP MAC (sys MAC) */
185 struct ethaddr pip_rmac;
186 struct ethaddr pip_rmac_static;
187 struct ethaddr pip_rmac_zebra;
188 bool is_anycast_mac;
85c8d83b
CS
189};
190
021b6596
AD
191/* This structure defines an entry in remote_ip_hash */
192struct evpn_remote_ip {
193 struct ipaddr addr;
194 struct list *macip_path_list;
195};
196
676f83b9 197static inline int is_vrf_rd_configured(struct bgp *bgp_vrf)
198{
996c9314 199 return (CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD));
676f83b9 200}
201
202static inline int bgp_evpn_vrf_rd_matches_existing(struct bgp *bgp_vrf,
203 struct prefix_rd *prd)
204{
205 return (memcmp(&bgp_vrf->vrf_prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
206}
207
6d8c58b7
MK
208static inline vni_t bgpevpn_get_l3vni(struct bgpevpn *vpn)
209{
bc4606bd 210 return vpn->bgp_vrf ? vpn->bgp_vrf->l3vni : 0;
6d8c58b7
MK
211}
212
213static inline void bgpevpn_get_rmac(struct bgpevpn *vpn, struct ethaddr *rmac)
214{
6d8c58b7 215 memset(rmac, 0, sizeof(struct ethaddr));
bc4606bd 216 if (!vpn->bgp_vrf)
6d8c58b7 217 return;
bc4606bd 218 memcpy(rmac, &vpn->bgp_vrf->rmac, sizeof(struct ethaddr));
6d8c58b7
MK
219}
220
221static inline struct list *bgpevpn_get_vrf_export_rtl(struct bgpevpn *vpn)
222{
bc4606bd 223 if (!vpn->bgp_vrf)
6d8c58b7
MK
224 return NULL;
225
bc4606bd 226 return vpn->bgp_vrf->vrf_export_rtl;
6d8c58b7
MK
227}
228
229static inline struct list *bgpevpn_get_vrf_import_rtl(struct bgpevpn *vpn)
230{
bc4606bd 231 if (!vpn->bgp_vrf)
6d8c58b7
MK
232 return NULL;
233
bc4606bd 234 return vpn->bgp_vrf->vrf_import_rtl;
6d8c58b7
MK
235}
236
c589d847
AK
237extern void bgp_evpn_es_evi_vrf_ref(struct bgpevpn *vpn);
238extern void bgp_evpn_es_evi_vrf_deref(struct bgpevpn *vpn);
239
6a8657d0
MK
240static inline void bgpevpn_unlink_from_l3vni(struct bgpevpn *vpn)
241{
bc4606bd
MK
242 /* bail if vpn is not associated to bgp_vrf */
243 if (!vpn->bgp_vrf)
6a8657d0 244 return;
996c9314 245
c48d9f5f 246 UNSET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS);
bc4606bd 247 listnode_delete(vpn->bgp_vrf->l2vnis, vpn);
996c9314 248
c589d847
AK
249 bgp_evpn_es_evi_vrf_deref(vpn);
250
bc4606bd 251 /* remove the backpointer to the vrf instance */
0c68e088 252 bgp_unlock(vpn->bgp_vrf);
bc4606bd 253 vpn->bgp_vrf = NULL;
6a8657d0
MK
254}
255
256static inline void bgpevpn_link_to_l3vni(struct bgpevpn *vpn)
257{
258 struct bgp *bgp_vrf = NULL;
259
bc4606bd
MK
260 /* bail if vpn is already associated to vrf */
261 if (vpn->bgp_vrf)
262 return;
263
6a8657d0 264 bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id);
c48d9f5f 265 if (!bgp_vrf)
6a8657d0 266 return;
c48d9f5f 267
bc4606bd 268 /* associate the vpn to the bgp_vrf instance */
0c68e088 269 vpn->bgp_vrf = bgp_lock(bgp_vrf);
6a8657d0 270 listnode_add_sort(bgp_vrf->l2vnis, vpn);
83ea2eb0 271
10f70510
AD
272 /*
273 * If L3VNI is configured,
274 * check if we are advertising two labels for this vpn
275 */
276 if (bgp_vrf->l3vni &&
277 !CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY))
c48d9f5f 278 SET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS);
c589d847
AK
279
280 bgp_evpn_es_evi_vrf_ref(vpn);
6a8657d0
MK
281}
282
d62a17ae 283static inline int is_vni_configured(struct bgpevpn *vpn)
128ea8ab 284{
d62a17ae 285 return (CHECK_FLAG(vpn->flags, VNI_FLAG_CFGD));
128ea8ab 286}
287
d62a17ae 288static inline int is_vni_live(struct bgpevpn *vpn)
128ea8ab 289{
d62a17ae 290 return (CHECK_FLAG(vpn->flags, VNI_FLAG_LIVE));
128ea8ab 291}
292
3d0b43d7 293static inline int is_l3vni_live(struct bgp *bgp_vrf)
294{
295 return (bgp_vrf->l3vni && bgp_vrf->l3vni_svi_ifindex);
296}
297
d62a17ae 298static inline int is_rd_configured(struct bgpevpn *vpn)
128ea8ab 299{
d62a17ae 300 return (CHECK_FLAG(vpn->flags, VNI_FLAG_RD_CFGD));
128ea8ab 301}
302
d62a17ae 303static inline int bgp_evpn_rd_matches_existing(struct bgpevpn *vpn,
304 struct prefix_rd *prd)
128ea8ab 305{
d62a17ae 306 return (memcmp(&vpn->prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
128ea8ab 307}
308
d62a17ae 309static inline int is_import_rt_configured(struct bgpevpn *vpn)
128ea8ab 310{
d62a17ae 311 return (CHECK_FLAG(vpn->flags, VNI_FLAG_IMPRT_CFGD));
128ea8ab 312}
313
d62a17ae 314static inline int is_export_rt_configured(struct bgpevpn *vpn)
128ea8ab 315{
d62a17ae 316 return (CHECK_FLAG(vpn->flags, VNI_FLAG_EXPRT_CFGD));
128ea8ab 317}
318
50f74cf1 319static inline void encode_es_rt_extcomm(struct ecommunity_val *eval,
320 struct ethaddr *mac)
321{
322 memset(eval, 0, sizeof(struct ecommunity_val));
323 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
324 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT;
325 memcpy(&eval->val[2], mac, ETH_ALEN);
326}
327
74e2bd89
AK
328static inline void encode_df_elect_extcomm(struct ecommunity_val *eval,
329 uint16_t pref)
330{
331 memset(eval, 0, sizeof(*eval));
332 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
333 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DF_ELECTION;
334 eval->val[2] = EVPN_MH_DF_ALG_PREF;
335 eval->val[6] = (pref >> 8) & 0xff;
336 eval->val[7] = pref & 0xff;
337}
338
c44ab6f1
AK
339static inline void encode_esi_label_extcomm(struct ecommunity_val *eval,
340 bool single_active)
341{
342 memset(eval, 0, sizeof(struct ecommunity_val));
343 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
344 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL;
345 if (single_active)
346 eval->val[2] |= (1 << 0);
347}
348
bc59a672
MK
349static inline void encode_rmac_extcomm(struct ecommunity_val *eval,
350 struct ethaddr *rmac)
351{
352 memset(eval, 0, sizeof(*eval));
353 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
354 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
355 memcpy(&eval->val[2], rmac, ETH_ALEN);
356}
357
ead40654
MK
358static inline void encode_default_gw_extcomm(struct ecommunity_val *eval)
359{
360 memset(eval, 0, sizeof(*eval));
361 eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE;
362 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DEF_GW;
363}
364
d7c0a89a 365static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq,
d62a17ae 366 struct ecommunity_val *eval)
128ea8ab 367{
d62a17ae 368 memset(eval, 0, sizeof(*eval));
369 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
370 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY;
371 if (static_mac)
372 eval->val[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY;
373 eval->val[4] = (seq >> 24) & 0xff;
374 eval->val[5] = (seq >> 16) & 0xff;
375 eval->val[6] = (seq >> 8) & 0xff;
376 eval->val[7] = seq & 0xff;
128ea8ab 377}
378
68e33151 379static inline void encode_na_flag_extcomm(struct ecommunity_val *eval,
9c7edc03 380 uint8_t na_flag, bool proxy)
68e33151
CS
381{
382 memset(eval, 0, sizeof(*eval));
383 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
384 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ND;
385 if (na_flag)
386 eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG;
9c7edc03
AK
387 if (proxy)
388 eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_PROXY_FLAG;
68e33151
CS
389}
390
bd494ec5 391static inline void ip_prefix_from_type5_prefix(const struct prefix_evpn *evp,
90264d64
MK
392 struct prefix *ip)
393{
394 memset(ip, 0, sizeof(struct prefix));
3714a385 395 if (is_evpn_prefix_ipaddr_v4(evp)) {
90264d64 396 ip->family = AF_INET;
3714a385 397 ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length;
398 memcpy(&(ip->u.prefix4), &(evp->prefix.prefix_addr.ip.ip),
90264d64 399 IPV4_MAX_BYTELEN);
3714a385 400 } else if (is_evpn_prefix_ipaddr_v6(evp)) {
90264d64 401 ip->family = AF_INET6;
3714a385 402 ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length;
403 memcpy(&(ip->u.prefix6), &(evp->prefix.prefix_addr.ip.ip),
90264d64
MK
404 IPV6_MAX_BYTELEN);
405 }
406}
407
123214ef 408static inline int is_evpn_prefix_default(const struct prefix *evp)
6fb219da
MK
409{
410 if (evp->family != AF_EVPN)
411 return 0;
412
3714a385 413 return ((evp->u.prefix_evpn.prefix_addr.ip_prefix_length == 0) ?
414 1 : 0);
6fb219da
MK
415}
416
bd494ec5 417static inline void ip_prefix_from_type2_prefix(const struct prefix_evpn *evp,
d3135ba3 418 struct prefix *ip)
419{
420 memset(ip, 0, sizeof(struct prefix));
3714a385 421 if (is_evpn_prefix_ipaddr_v4(evp)) {
d3135ba3 422 ip->family = AF_INET;
423 ip->prefixlen = IPV4_MAX_BITLEN;
3714a385 424 memcpy(&(ip->u.prefix4), &(evp->prefix.macip_addr.ip.ip),
d3135ba3 425 IPV4_MAX_BYTELEN);
3714a385 426 } else if (is_evpn_prefix_ipaddr_v6(evp)) {
d3135ba3 427 ip->family = AF_INET6;
428 ip->prefixlen = IPV6_MAX_BITLEN;
3714a385 429 memcpy(&(ip->u.prefix6), &(evp->prefix.macip_addr.ip.ip),
d3135ba3 430 IPV6_MAX_BYTELEN);
431 }
432}
433
bd494ec5 434static inline void ip_prefix_from_evpn_prefix(const struct prefix_evpn *evp,
3714a385 435 struct prefix *ip)
436{
437 if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE)
438 ip_prefix_from_type2_prefix(evp, ip);
439 else if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE)
440 ip_prefix_from_type5_prefix(evp, ip);
441}
442
d62a17ae 443static inline void build_evpn_type2_prefix(struct prefix_evpn *p,
444 struct ethaddr *mac,
445 struct ipaddr *ip)
128ea8ab 446{
d62a17ae 447 memset(p, 0, sizeof(struct prefix_evpn));
b03b8898 448 p->family = AF_EVPN;
50f74cf1 449 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
d62a17ae 450 p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
3714a385 451 memcpy(&p->prefix.macip_addr.mac.octet, mac->octet, ETH_ALEN);
452 p->prefix.macip_addr.ip.ipa_type = IPADDR_NONE;
d62a17ae 453 if (ip)
3714a385 454 memcpy(&p->prefix.macip_addr.ip, ip, sizeof(*ip));
128ea8ab 455}
456
bd494ec5
DS
457static inline void
458build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp,
459 const struct prefix *ip_prefix)
342dd0c6 460{
461 struct ipaddr ip;
462
463 memset(&ip, 0, sizeof(struct ipaddr));
464 if (ip_prefix->family == AF_INET) {
465 ip.ipa_type = IPADDR_V4;
466 memcpy(&ip.ipaddr_v4, &ip_prefix->u.prefix4,
467 sizeof(struct in_addr));
468 } else {
469 ip.ipa_type = IPADDR_V6;
470 memcpy(&ip.ipaddr_v6, &ip_prefix->u.prefix6,
471 sizeof(struct in6_addr));
472 }
473
474 memset(evp, 0, sizeof(struct prefix_evpn));
475 evp->family = AF_EVPN;
50f74cf1 476 evp->prefixlen = EVPN_ROUTE_PREFIXLEN;
342dd0c6 477 evp->prefix.route_type = BGP_EVPN_IP_PREFIX_ROUTE;
3714a385 478 evp->prefix.prefix_addr.ip_prefix_length = ip_prefix->prefixlen;
479 evp->prefix.prefix_addr.ip.ipa_type = ip.ipa_type;
480 memcpy(&evp->prefix.prefix_addr.ip, &ip, sizeof(struct ipaddr));
342dd0c6 481}
482
d62a17ae 483static inline void build_evpn_type3_prefix(struct prefix_evpn *p,
484 struct in_addr originator_ip)
128ea8ab 485{
d62a17ae 486 memset(p, 0, sizeof(struct prefix_evpn));
b03b8898 487 p->family = AF_EVPN;
50f74cf1 488 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
d62a17ae 489 p->prefix.route_type = BGP_EVPN_IMET_ROUTE;
3714a385 490 p->prefix.imet_addr.ip.ipa_type = IPADDR_V4;
491 p->prefix.imet_addr.ip.ipaddr_v4 = originator_ip;
128ea8ab 492}
493
50f74cf1 494static inline void build_evpn_type4_prefix(struct prefix_evpn *p,
495 esi_t *esi,
496 struct in_addr originator_ip)
497{
498 memset(p, 0, sizeof(struct prefix_evpn));
499 p->family = AF_EVPN;
500 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
501 p->prefix.route_type = BGP_EVPN_ES_ROUTE;
502 p->prefix.es_addr.ip_prefix_length = IPV4_MAX_BITLEN;
503 p->prefix.es_addr.ip.ipa_type = IPADDR_V4;
504 p->prefix.es_addr.ip.ipaddr_v4 = originator_ip;
505 memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t));
506}
507
c44ab6f1
AK
508static inline void build_evpn_type1_prefix(struct prefix_evpn *p,
509 uint32_t eth_tag,
510 esi_t *esi,
511 struct in_addr originator_ip)
512{
513 memset(p, 0, sizeof(struct prefix_evpn));
514 p->family = AF_EVPN;
515 p->prefixlen = EVPN_ROUTE_PREFIXLEN;
516 p->prefix.route_type = BGP_EVPN_AD_ROUTE;
517 p->prefix.ead_addr.eth_tag = eth_tag;
c44ab6f1
AK
518 p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
519 p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
520 memcpy(&p->prefix.ead_addr.esi, esi, sizeof(esi_t));
521}
522
523static inline void evpn_type1_prefix_global_copy(struct prefix_evpn *global_p,
524 const struct prefix_evpn *vni_p)
525{
526 memcpy(global_p, vni_p, sizeof(*global_p));
c44ab6f1 527 global_p->prefix.ead_addr.ip.ipa_type = 0;
3a6290bd 528 global_p->prefix.ead_addr.ip.ipaddr_v4.s_addr = INADDR_ANY;
7b0db0e4 529 global_p->prefix.ead_addr.frag_id = 0;
c44ab6f1
AK
530}
531
532/* EAD prefix in the global table doesn't include the VTEP-IP so
533 * we need to create a different copy for the VNI
534 */
535static inline struct prefix_evpn *evpn_type1_prefix_vni_copy(
536 struct prefix_evpn *vni_p,
537 const struct prefix_evpn *global_p,
538 struct in_addr originator_ip)
539{
540 memcpy(vni_p, global_p, sizeof(*vni_p));
c44ab6f1
AK
541 vni_p->prefix.ead_addr.ip.ipa_type = IPADDR_V4;
542 vni_p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip;
543
544 return vni_p;
545}
546
486456ca
MK
547static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
548 safi_t safi)
549{
550 if (afi == AFI_IP &&
551 CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
552 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4))
553 return 1;
554 else if (afi == AFI_IP6 &&
555 CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN],
556 BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6))
557 return 1;
558 return 0;
559}
560
50f74cf1 561static inline void es_get_system_mac(esi_t *esi,
562 struct ethaddr *mac)
563{
2bb9eff4
DS
564 /*
565 * for type-1 and type-3 ESIs,
566 * the system mac starts at val[1]
50f74cf1 567 */
568 memcpy(mac, &esi->val[1], ETH_ALEN);
569}
570
0ca10580
CS
571static inline bool bgp_evpn_is_svi_macip_enabled(struct bgpevpn *vpn)
572{
573 struct bgp *bgp_evpn = NULL;
574
575 bgp_evpn = bgp_get_evpn();
576
577 return (bgp_evpn->evpn_info->advertise_svi_macip ||
578 vpn->advertise_svi_macip);
579}
580
9c7edc03
AK
581static inline bool bgp_evpn_is_path_local(struct bgp *bgp,
582 struct bgp_path_info *pi)
583{
584 return (pi->peer == bgp->peer_self
585 && pi->type == ZEBRA_ROUTE_BGP
586 && pi->sub_type == BGP_ROUTE_STATIC);
587}
588
c44ab6f1
AK
589extern struct zclient *zclient;
590
5fd9c12b
KA
591extern void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf,
592 afi_t afi, safi_t safi,
593 bool add);
996c9314 594extern void evpn_rt_delete_auto(struct bgp *, vni_t, struct list *);
523cafc4 595extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf,
596 struct ecommunity *ecomadd);
597extern void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp *bgp_vrf,
598 struct ecommunity *ecomdel);
599extern void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf,
600 struct ecommunity *ecomadd);
601extern void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf,
602 struct ecommunity *ecomdel);
d62a17ae 603extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp,
604 struct bgpevpn *vpn);
bf1061d8 605extern void bgp_evpn_handle_autort_change(struct bgp *bgp);
676f83b9 606extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw);
d62a17ae 607extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn,
608 int withdraw);
609extern int bgp_evpn_install_routes(struct bgp *bgp, struct bgpevpn *vpn);
610extern int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn);
523cafc4 611extern void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf);
612extern void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf);
d62a17ae 613extern void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn);
614extern void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp,
615 struct bgpevpn *vpn);
616extern void bgp_evpn_derive_auto_rt_import(struct bgp *bgp,
617 struct bgpevpn *vpn);
618extern void bgp_evpn_derive_auto_rt_export(struct bgp *bgp,
619 struct bgpevpn *vpn);
620extern void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn);
676f83b9 621extern void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp);
d62a17ae 622extern struct bgpevpn *bgp_evpn_lookup_vni(struct bgp *bgp, vni_t vni);
623extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
76d07c7a
AK
624 struct in_addr originator_ip,
625 vrf_id_t tenant_vrf_id,
9daa5d47
AD
626 struct in_addr mcast_grp,
627 ifindex_t svi_ifindex);
d62a17ae 628extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn);
7df407ed 629extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni);
0ca10580 630extern int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn);
185fb14a
AK
631extern void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi,
632 struct bgp_dest *dest,
633 struct bgp_path_info **pi);
c44ab6f1
AK
634int vni_list_cmp(void *p1, void *p2);
635extern int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn,
09319b4e
DS
636 struct bgp_dest *dest);
637extern struct bgp_dest *bgp_global_evpn_node_get(struct bgp_table *table,
638 afi_t afi, safi_t safi,
639 const struct prefix_evpn *evp,
640 struct prefix_rd *prd);
641extern struct bgp_dest *
26c03e43
AK
642bgp_global_evpn_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi,
643 const struct prefix_evpn *evp,
644 struct prefix_rd *prd);
70524092
AK
645extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
646 struct bgpevpn *vpn,
647 struct bgp_node *rn,
648 struct bgp_path_info *local_pi,
649 const char *caller);
58bff4d1
AK
650extern int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf,
651 struct bgp_path_info *pi,
652 int install);
74efb822 653extern void bgp_evpn_import_type2_route(struct bgp_path_info *pi, int import);
f4a5218d
AK
654extern void bgp_evpn_xxport_delete_ecomm(void *val);
655extern int bgp_evpn_route_target_cmp(struct ecommunity *ecom1,
656 struct ecommunity *ecom2);
a4168ebc 657#endif /* _BGP_EVPN_PRIVATE_H */