]>
Commit | Line | Data |
---|---|---|
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 | |
e9fc2840 | 33 | /* EVPN prefix lengths. This reprsent the sizeof struct prefix_evpn */ |
50f74cf1 | 34 | #define EVPN_ROUTE_PREFIXLEN 224 |
a4168ebc | 35 | |
36 | /* EVPN route types. */ | |
d62a17ae | 37 | typedef enum { |
38 | BGP_EVPN_AD_ROUTE = 1, /* Ethernet Auto-Discovery (A-D) route */ | |
39 | BGP_EVPN_MAC_IP_ROUTE, /* MAC/IP Advertisement route */ | |
40 | BGP_EVPN_IMET_ROUTE, /* Inclusive Multicast Ethernet Tag route */ | |
41 | BGP_EVPN_ES_ROUTE, /* Ethernet Segment route */ | |
42 | BGP_EVPN_IP_PREFIX_ROUTE, /* IP Prefix route */ | |
a4168ebc | 43 | } bgp_evpn_route_type; |
44 | ||
45 | /* | |
46 | * Hash table of EVIs. Right now, the only type of EVI supported is with | |
47 | * VxLAN encapsulation, hence each EVI corresponds to a L2 VNI. | |
48 | * The VNIs are not "created" through BGP but through some other interface | |
49 | * on the system. This table stores VNIs that BGP comes to know as present | |
50 | * on the system (through interaction with zebra) as well as pre-configured | |
51 | * VNIs (which need to be defined in the system to become "live"). | |
52 | */ | |
d62a17ae | 53 | struct bgpevpn { |
54 | vni_t vni; | |
29c53922 | 55 | vrf_id_t tenant_vrf_id; |
d7c0a89a | 56 | uint32_t flags; |
a4168ebc | 57 | #define VNI_FLAG_CFGD 0x1 /* VNI is user configured */ |
58 | #define VNI_FLAG_LIVE 0x2 /* VNI is "live" */ | |
59 | #define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */ | |
60 | #define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */ | |
61 | #define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */ | |
c48d9f5f MK |
62 | #define VNI_FLAG_USE_TWO_LABELS 0x20 /* Attach both L2-VNI and L3-VNI if |
63 | needed for this VPN */ | |
a4168ebc | 64 | |
bc4606bd MK |
65 | struct bgp *bgp_vrf; /* back pointer to the vrf instance */ |
66 | ||
996c9314 LB |
67 | /* Flag to indicate if we are |
68 | * advertising the g/w mac ip for | |
69 | * this VNI*/ | |
d7c0a89a | 70 | uint8_t advertise_gw_macip; |
1a98c087 | 71 | |
d7c0a89a QY |
72 | /* Flag to indicate if we are |
73 | * advertising subnet for this VNI */ | |
74 | uint8_t advertise_subnet; | |
31310b25 | 75 | |
24864e44 CS |
76 | /* Flag to indicate if we are advertising the svi mac ip for this VNI*/ |
77 | uint8_t advertise_svi_macip; | |
78 | ||
d7c0a89a QY |
79 | /* Id for deriving the RD |
80 | * automatically for this VNI */ | |
81 | uint16_t rd_id; | |
a4168ebc | 82 | |
d7c0a89a QY |
83 | /* RD for this VNI. */ |
84 | struct prefix_rd prd; | |
a4168ebc | 85 | |
d7c0a89a QY |
86 | /* Route type 3 field */ |
87 | struct in_addr originator_ip; | |
a4168ebc | 88 | |
d7c0a89a QY |
89 | /* Import and Export RTs. */ |
90 | struct list *import_rtl; | |
91 | struct list *export_rtl; | |
a4168ebc | 92 | |
d7c0a89a QY |
93 | /* Route table for EVPN routes for |
94 | * this VNI. */ | |
95 | struct bgp_table *route_table; | |
a4168ebc | 96 | |
d7c0a89a | 97 | QOBJ_FIELDS |
a4168ebc | 98 | }; |
99 | ||
100 | DECLARE_QOBJ_TYPE(bgpevpn) | |
101 | ||
50f74cf1 | 102 | struct evpnes { |
103 | ||
104 | /* Ethernet Segment Identifier */ | |
105 | esi_t esi; | |
106 | ||
107 | /* es flags */ | |
108 | uint16_t flags; | |
109 | #define EVPNES_LOCAL 0x01 | |
110 | #define EVPNES_REMOTE 0x02 | |
111 | ||
2bb9eff4 DS |
112 | /* |
113 | * Id for deriving the RD | |
114 | * automatically for this ESI | |
115 | */ | |
50f74cf1 | 116 | uint16_t rd_id; |
117 | ||
118 | /* RD for this VNI. */ | |
119 | struct prefix_rd prd; | |
120 | ||
121 | /* originator ip address */ | |
122 | struct ipaddr originator_ip; | |
123 | ||
124 | /* list of VTEPs in the same site */ | |
125 | struct list *vtep_list; | |
126 | ||
2bb9eff4 DS |
127 | /* |
128 | * Route table for EVPN routes for | |
129 | * this ESI. - type4 routes | |
130 | */ | |
50f74cf1 | 131 | struct bgp_table *route_table; |
132 | ||
133 | QOBJ_FIELDS | |
134 | }; | |
135 | ||
136 | DECLARE_QOBJ_TYPE(evpnes) | |
137 | ||
a4168ebc | 138 | /* Mapping of Import RT to VNIs. |
139 | * The Import RTs of all VNIs are maintained in a hash table with each | |
140 | * RT linking to all VNIs that will import routes matching this RT. | |
141 | */ | |
d62a17ae | 142 | struct irt_node { |
143 | /* RT */ | |
144 | struct ecommunity_val rt; | |
a4168ebc | 145 | |
d62a17ae | 146 | /* List of VNIs importing routes matching this RT. */ |
147 | struct list *vnis; | |
a4168ebc | 148 | }; |
149 | ||
10ebe1ab MK |
150 | /* Mapping of Import RT to VRFs. |
151 | * The Import RTs of all VRFss are maintained in a hash table with each | |
152 | * RT linking to all VRFs that will import routes matching this RT. | |
153 | */ | |
154 | struct vrf_irt_node { | |
155 | /* RT */ | |
156 | struct ecommunity_val rt; | |
157 | ||
158 | /* List of VNIs importing routes matching this RT. */ | |
159 | struct list *vrfs; | |
160 | }; | |
161 | ||
162 | ||
128ea8ab | 163 | #define RT_TYPE_IMPORT 1 |
164 | #define RT_TYPE_EXPORT 2 | |
165 | #define RT_TYPE_BOTH 3 | |
166 | ||
85c8d83b CS |
167 | #define EVPN_DAD_DEFAULT_TIME 180 /* secs */ |
168 | #define EVPN_DAD_DEFAULT_MAX_MOVES 5 /* default from RFC 7432 */ | |
169 | #define EVPN_DAD_DEFAULT_AUTO_RECOVERY_TIME 1800 /* secs */ | |
170 | ||
171 | struct bgp_evpn_info { | |
172 | /* enable disable dup detect */ | |
173 | bool dup_addr_detect; | |
174 | ||
175 | /* Detection time(M) */ | |
176 | int dad_time; | |
177 | /* Detection max moves(N) */ | |
178 | uint32_t dad_max_moves; | |
179 | /* Permanent freeze */ | |
180 | bool dad_freeze; | |
181 | /* Recovery time */ | |
182 | uint32_t dad_freeze_time; | |
24864e44 CS |
183 | |
184 | /* EVPN enable - advertise svi macip routes */ | |
185 | int advertise_svi_macip; | |
186 | ||
85c8d83b CS |
187 | }; |
188 | ||
676f83b9 | 189 | static inline int is_vrf_rd_configured(struct bgp *bgp_vrf) |
190 | { | |
996c9314 | 191 | return (CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_RD_CFGD)); |
676f83b9 | 192 | } |
193 | ||
194 | static inline int bgp_evpn_vrf_rd_matches_existing(struct bgp *bgp_vrf, | |
195 | struct prefix_rd *prd) | |
196 | { | |
197 | return (memcmp(&bgp_vrf->vrf_prd.val, prd->val, ECOMMUNITY_SIZE) == 0); | |
198 | } | |
199 | ||
6d8c58b7 MK |
200 | static inline vni_t bgpevpn_get_l3vni(struct bgpevpn *vpn) |
201 | { | |
bc4606bd | 202 | return vpn->bgp_vrf ? vpn->bgp_vrf->l3vni : 0; |
6d8c58b7 MK |
203 | } |
204 | ||
205 | static inline void bgpevpn_get_rmac(struct bgpevpn *vpn, struct ethaddr *rmac) | |
206 | { | |
6d8c58b7 | 207 | memset(rmac, 0, sizeof(struct ethaddr)); |
bc4606bd | 208 | if (!vpn->bgp_vrf) |
6d8c58b7 | 209 | return; |
bc4606bd | 210 | memcpy(rmac, &vpn->bgp_vrf->rmac, sizeof(struct ethaddr)); |
6d8c58b7 MK |
211 | } |
212 | ||
213 | static inline struct list *bgpevpn_get_vrf_export_rtl(struct bgpevpn *vpn) | |
214 | { | |
bc4606bd | 215 | if (!vpn->bgp_vrf) |
6d8c58b7 MK |
216 | return NULL; |
217 | ||
bc4606bd | 218 | return vpn->bgp_vrf->vrf_export_rtl; |
6d8c58b7 MK |
219 | } |
220 | ||
221 | static inline struct list *bgpevpn_get_vrf_import_rtl(struct bgpevpn *vpn) | |
222 | { | |
bc4606bd | 223 | if (!vpn->bgp_vrf) |
6d8c58b7 MK |
224 | return NULL; |
225 | ||
bc4606bd | 226 | return vpn->bgp_vrf->vrf_import_rtl; |
6d8c58b7 MK |
227 | } |
228 | ||
6a8657d0 MK |
229 | static inline void bgpevpn_unlink_from_l3vni(struct bgpevpn *vpn) |
230 | { | |
bc4606bd MK |
231 | /* bail if vpn is not associated to bgp_vrf */ |
232 | if (!vpn->bgp_vrf) | |
6a8657d0 | 233 | return; |
996c9314 | 234 | |
c48d9f5f | 235 | UNSET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS); |
bc4606bd | 236 | listnode_delete(vpn->bgp_vrf->l2vnis, vpn); |
996c9314 | 237 | |
bc4606bd MK |
238 | /* remove the backpointer to the vrf instance */ |
239 | vpn->bgp_vrf = NULL; | |
6a8657d0 MK |
240 | } |
241 | ||
242 | static inline void bgpevpn_link_to_l3vni(struct bgpevpn *vpn) | |
243 | { | |
244 | struct bgp *bgp_vrf = NULL; | |
245 | ||
bc4606bd MK |
246 | /* bail if vpn is already associated to vrf */ |
247 | if (vpn->bgp_vrf) | |
248 | return; | |
249 | ||
6a8657d0 | 250 | bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); |
c48d9f5f | 251 | if (!bgp_vrf) |
6a8657d0 | 252 | return; |
c48d9f5f | 253 | |
bc4606bd MK |
254 | /* associate the vpn to the bgp_vrf instance */ |
255 | vpn->bgp_vrf = bgp_vrf; | |
6a8657d0 | 256 | listnode_add_sort(bgp_vrf->l2vnis, vpn); |
83ea2eb0 | 257 | |
c48d9f5f | 258 | /* check if we are advertising two labels for this vpn */ |
996c9314 | 259 | if (!CHECK_FLAG(bgp_vrf->vrf_flags, BGP_VRF_L3VNI_PREFIX_ROUTES_ONLY)) |
c48d9f5f | 260 | SET_FLAG(vpn->flags, VNI_FLAG_USE_TWO_LABELS); |
6a8657d0 MK |
261 | } |
262 | ||
d62a17ae | 263 | static inline int is_vni_configured(struct bgpevpn *vpn) |
128ea8ab | 264 | { |
d62a17ae | 265 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_CFGD)); |
128ea8ab | 266 | } |
267 | ||
d62a17ae | 268 | static inline int is_vni_live(struct bgpevpn *vpn) |
128ea8ab | 269 | { |
d62a17ae | 270 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_LIVE)); |
128ea8ab | 271 | } |
272 | ||
d62a17ae | 273 | static inline int is_rd_configured(struct bgpevpn *vpn) |
128ea8ab | 274 | { |
d62a17ae | 275 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_RD_CFGD)); |
128ea8ab | 276 | } |
277 | ||
d62a17ae | 278 | static inline int bgp_evpn_rd_matches_existing(struct bgpevpn *vpn, |
279 | struct prefix_rd *prd) | |
128ea8ab | 280 | { |
d62a17ae | 281 | return (memcmp(&vpn->prd.val, prd->val, ECOMMUNITY_SIZE) == 0); |
128ea8ab | 282 | } |
283 | ||
d62a17ae | 284 | static inline int is_import_rt_configured(struct bgpevpn *vpn) |
128ea8ab | 285 | { |
d62a17ae | 286 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_IMPRT_CFGD)); |
128ea8ab | 287 | } |
288 | ||
d62a17ae | 289 | static inline int is_export_rt_configured(struct bgpevpn *vpn) |
128ea8ab | 290 | { |
d62a17ae | 291 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_EXPRT_CFGD)); |
128ea8ab | 292 | } |
293 | ||
d62a17ae | 294 | static inline int is_vni_param_configured(struct bgpevpn *vpn) |
128ea8ab | 295 | { |
d62a17ae | 296 | return (is_rd_configured(vpn) || is_import_rt_configured(vpn) |
297 | || is_export_rt_configured(vpn)); | |
128ea8ab | 298 | } |
299 | ||
50f74cf1 | 300 | static inline void encode_es_rt_extcomm(struct ecommunity_val *eval, |
301 | struct ethaddr *mac) | |
302 | { | |
303 | memset(eval, 0, sizeof(struct ecommunity_val)); | |
304 | eval->val[0] = ECOMMUNITY_ENCODE_EVPN; | |
305 | eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT; | |
306 | memcpy(&eval->val[2], mac, ETH_ALEN); | |
307 | } | |
308 | ||
bc59a672 MK |
309 | static inline void encode_rmac_extcomm(struct ecommunity_val *eval, |
310 | struct ethaddr *rmac) | |
311 | { | |
312 | memset(eval, 0, sizeof(*eval)); | |
313 | eval->val[0] = ECOMMUNITY_ENCODE_EVPN; | |
314 | eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC; | |
315 | memcpy(&eval->val[2], rmac, ETH_ALEN); | |
316 | } | |
317 | ||
ead40654 MK |
318 | static inline void encode_default_gw_extcomm(struct ecommunity_val *eval) |
319 | { | |
320 | memset(eval, 0, sizeof(*eval)); | |
321 | eval->val[0] = ECOMMUNITY_ENCODE_OPAQUE; | |
322 | eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_DEF_GW; | |
323 | } | |
324 | ||
d7c0a89a | 325 | static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq, |
d62a17ae | 326 | struct ecommunity_val *eval) |
128ea8ab | 327 | { |
d62a17ae | 328 | memset(eval, 0, sizeof(*eval)); |
329 | eval->val[0] = ECOMMUNITY_ENCODE_EVPN; | |
330 | eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY; | |
331 | if (static_mac) | |
332 | eval->val[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY; | |
333 | eval->val[4] = (seq >> 24) & 0xff; | |
334 | eval->val[5] = (seq >> 16) & 0xff; | |
335 | eval->val[6] = (seq >> 8) & 0xff; | |
336 | eval->val[7] = seq & 0xff; | |
128ea8ab | 337 | } |
338 | ||
68e33151 CS |
339 | static inline void encode_na_flag_extcomm(struct ecommunity_val *eval, |
340 | uint8_t na_flag) | |
341 | { | |
342 | memset(eval, 0, sizeof(*eval)); | |
343 | eval->val[0] = ECOMMUNITY_ENCODE_EVPN; | |
344 | eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ND; | |
345 | if (na_flag) | |
346 | eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG; | |
347 | } | |
348 | ||
90264d64 MK |
349 | static inline void ip_prefix_from_type5_prefix(struct prefix_evpn *evp, |
350 | struct prefix *ip) | |
351 | { | |
352 | memset(ip, 0, sizeof(struct prefix)); | |
3714a385 | 353 | if (is_evpn_prefix_ipaddr_v4(evp)) { |
90264d64 | 354 | ip->family = AF_INET; |
3714a385 | 355 | ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length; |
356 | memcpy(&(ip->u.prefix4), &(evp->prefix.prefix_addr.ip.ip), | |
90264d64 | 357 | IPV4_MAX_BYTELEN); |
3714a385 | 358 | } else if (is_evpn_prefix_ipaddr_v6(evp)) { |
90264d64 | 359 | ip->family = AF_INET6; |
3714a385 | 360 | ip->prefixlen = evp->prefix.prefix_addr.ip_prefix_length; |
361 | memcpy(&(ip->u.prefix6), &(evp->prefix.prefix_addr.ip.ip), | |
90264d64 MK |
362 | IPV6_MAX_BYTELEN); |
363 | } | |
364 | } | |
365 | ||
123214ef | 366 | static inline int is_evpn_prefix_default(const struct prefix *evp) |
6fb219da MK |
367 | { |
368 | if (evp->family != AF_EVPN) | |
369 | return 0; | |
370 | ||
3714a385 | 371 | return ((evp->u.prefix_evpn.prefix_addr.ip_prefix_length == 0) ? |
372 | 1 : 0); | |
6fb219da MK |
373 | } |
374 | ||
d3135ba3 | 375 | static inline void ip_prefix_from_type2_prefix(struct prefix_evpn *evp, |
376 | struct prefix *ip) | |
377 | { | |
378 | memset(ip, 0, sizeof(struct prefix)); | |
3714a385 | 379 | if (is_evpn_prefix_ipaddr_v4(evp)) { |
d3135ba3 | 380 | ip->family = AF_INET; |
381 | ip->prefixlen = IPV4_MAX_BITLEN; | |
3714a385 | 382 | memcpy(&(ip->u.prefix4), &(evp->prefix.macip_addr.ip.ip), |
d3135ba3 | 383 | IPV4_MAX_BYTELEN); |
3714a385 | 384 | } else if (is_evpn_prefix_ipaddr_v6(evp)) { |
d3135ba3 | 385 | ip->family = AF_INET6; |
386 | ip->prefixlen = IPV6_MAX_BITLEN; | |
3714a385 | 387 | memcpy(&(ip->u.prefix6), &(evp->prefix.macip_addr.ip.ip), |
d3135ba3 | 388 | IPV6_MAX_BYTELEN); |
389 | } | |
390 | } | |
391 | ||
3714a385 | 392 | static inline void ip_prefix_from_evpn_prefix(struct prefix_evpn *evp, |
393 | struct prefix *ip) | |
394 | { | |
395 | if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) | |
396 | ip_prefix_from_type2_prefix(evp, ip); | |
397 | else if (evp->prefix.route_type == BGP_EVPN_IP_PREFIX_ROUTE) | |
398 | ip_prefix_from_type5_prefix(evp, ip); | |
399 | } | |
400 | ||
d62a17ae | 401 | static inline void build_evpn_type2_prefix(struct prefix_evpn *p, |
402 | struct ethaddr *mac, | |
403 | struct ipaddr *ip) | |
128ea8ab | 404 | { |
d62a17ae | 405 | memset(p, 0, sizeof(struct prefix_evpn)); |
b03b8898 | 406 | p->family = AF_EVPN; |
50f74cf1 | 407 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; |
d62a17ae | 408 | p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE; |
3714a385 | 409 | memcpy(&p->prefix.macip_addr.mac.octet, mac->octet, ETH_ALEN); |
410 | p->prefix.macip_addr.ip.ipa_type = IPADDR_NONE; | |
d62a17ae | 411 | if (ip) |
3714a385 | 412 | memcpy(&p->prefix.macip_addr.ip, ip, sizeof(*ip)); |
128ea8ab | 413 | } |
414 | ||
342dd0c6 | 415 | static inline void build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp, |
416 | struct prefix *ip_prefix) | |
417 | { | |
418 | struct ipaddr ip; | |
419 | ||
420 | memset(&ip, 0, sizeof(struct ipaddr)); | |
421 | if (ip_prefix->family == AF_INET) { | |
422 | ip.ipa_type = IPADDR_V4; | |
423 | memcpy(&ip.ipaddr_v4, &ip_prefix->u.prefix4, | |
424 | sizeof(struct in_addr)); | |
425 | } else { | |
426 | ip.ipa_type = IPADDR_V6; | |
427 | memcpy(&ip.ipaddr_v6, &ip_prefix->u.prefix6, | |
428 | sizeof(struct in6_addr)); | |
429 | } | |
430 | ||
431 | memset(evp, 0, sizeof(struct prefix_evpn)); | |
432 | evp->family = AF_EVPN; | |
50f74cf1 | 433 | evp->prefixlen = EVPN_ROUTE_PREFIXLEN; |
342dd0c6 | 434 | evp->prefix.route_type = BGP_EVPN_IP_PREFIX_ROUTE; |
3714a385 | 435 | evp->prefix.prefix_addr.ip_prefix_length = ip_prefix->prefixlen; |
436 | evp->prefix.prefix_addr.ip.ipa_type = ip.ipa_type; | |
437 | memcpy(&evp->prefix.prefix_addr.ip, &ip, sizeof(struct ipaddr)); | |
342dd0c6 | 438 | } |
439 | ||
d62a17ae | 440 | static inline void build_evpn_type3_prefix(struct prefix_evpn *p, |
441 | struct in_addr originator_ip) | |
128ea8ab | 442 | { |
d62a17ae | 443 | memset(p, 0, sizeof(struct prefix_evpn)); |
b03b8898 | 444 | p->family = AF_EVPN; |
50f74cf1 | 445 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; |
d62a17ae | 446 | p->prefix.route_type = BGP_EVPN_IMET_ROUTE; |
3714a385 | 447 | p->prefix.imet_addr.ip.ipa_type = IPADDR_V4; |
448 | p->prefix.imet_addr.ip.ipaddr_v4 = originator_ip; | |
128ea8ab | 449 | } |
450 | ||
50f74cf1 | 451 | static inline void build_evpn_type4_prefix(struct prefix_evpn *p, |
452 | esi_t *esi, | |
453 | struct in_addr originator_ip) | |
454 | { | |
455 | memset(p, 0, sizeof(struct prefix_evpn)); | |
456 | p->family = AF_EVPN; | |
457 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; | |
458 | p->prefix.route_type = BGP_EVPN_ES_ROUTE; | |
459 | p->prefix.es_addr.ip_prefix_length = IPV4_MAX_BITLEN; | |
460 | p->prefix.es_addr.ip.ipa_type = IPADDR_V4; | |
461 | p->prefix.es_addr.ip.ipaddr_v4 = originator_ip; | |
462 | memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t)); | |
463 | } | |
464 | ||
486456ca MK |
465 | static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi, |
466 | safi_t safi) | |
467 | { | |
468 | if (afi == AFI_IP && | |
469 | CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN], | |
470 | BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4)) | |
471 | return 1; | |
472 | else if (afi == AFI_IP6 && | |
473 | CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN], | |
474 | BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6)) | |
475 | return 1; | |
476 | return 0; | |
477 | } | |
478 | ||
50f74cf1 | 479 | static inline void es_get_system_mac(esi_t *esi, |
480 | struct ethaddr *mac) | |
481 | { | |
2bb9eff4 DS |
482 | /* |
483 | * for type-1 and type-3 ESIs, | |
484 | * the system mac starts at val[1] | |
50f74cf1 | 485 | */ |
486 | memcpy(mac, &esi->val[1], ETH_ALEN); | |
487 | } | |
488 | ||
489 | static inline int is_es_local(struct evpnes *es) | |
490 | { | |
491 | return CHECK_FLAG(es->flags, EVPNES_LOCAL) ? 1 : 0; | |
492 | } | |
493 | ||
5fd9c12b KA |
494 | extern void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf, |
495 | afi_t afi, safi_t safi, | |
496 | bool add); | |
996c9314 | 497 | extern void evpn_rt_delete_auto(struct bgp *, vni_t, struct list *); |
523cafc4 | 498 | extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf, |
499 | struct ecommunity *ecomadd); | |
500 | extern void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp *bgp_vrf, | |
501 | struct ecommunity *ecomdel); | |
502 | extern void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf, | |
503 | struct ecommunity *ecomadd); | |
504 | extern void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf, | |
505 | struct ecommunity *ecomdel); | |
d62a17ae | 506 | extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp, |
507 | struct bgpevpn *vpn); | |
bf1061d8 | 508 | extern void bgp_evpn_handle_autort_change(struct bgp *bgp); |
676f83b9 | 509 | extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw); |
d62a17ae | 510 | extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn, |
511 | int withdraw); | |
512 | extern int bgp_evpn_install_routes(struct bgp *bgp, struct bgpevpn *vpn); | |
513 | extern int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn); | |
523cafc4 | 514 | extern void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf); |
515 | extern void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf); | |
d62a17ae | 516 | extern void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn); |
517 | extern void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp, | |
518 | struct bgpevpn *vpn); | |
519 | extern void bgp_evpn_derive_auto_rt_import(struct bgp *bgp, | |
520 | struct bgpevpn *vpn); | |
521 | extern void bgp_evpn_derive_auto_rt_export(struct bgp *bgp, | |
522 | struct bgpevpn *vpn); | |
523 | extern void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn); | |
676f83b9 | 524 | extern void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp); |
d62a17ae | 525 | extern struct bgpevpn *bgp_evpn_lookup_vni(struct bgp *bgp, vni_t vni); |
526 | extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni, | |
29c53922 MK |
527 | struct in_addr originator_ip, |
528 | vrf_id_t tenant_vrf_id); | |
d62a17ae | 529 | extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn); |
50f74cf1 | 530 | extern struct evpnes *bgp_evpn_lookup_es(struct bgp *bgp, esi_t *esi); |
531 | extern struct evpnes *bgp_evpn_es_new(struct bgp *bgp, esi_t *esi, | |
532 | struct ipaddr *originator_ip); | |
533 | extern void bgp_evpn_es_free(struct bgp *bgp, struct evpnes *es); | |
7df407ed | 534 | extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni); |
a4168ebc | 535 | #endif /* _BGP_EVPN_PRIVATE_H */ |