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