]>
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 | |
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 |
51 | RB_HEAD(bgp_es_evi_rb_head, bgp_evpn_es_evi); |
52 | RB_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 | 62 | struct 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 | 128 | DECLARE_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 | 134 | struct 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 | */ | |
146 | struct 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 | ||
163 | struct 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 */ |
192 | struct evpn_remote_ip { | |
193 | struct ipaddr addr; | |
194 | struct list *macip_path_list; | |
195 | }; | |
196 | ||
676f83b9 | 197 | static 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 | ||
202 | static 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 |
208 | static 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 | ||
213 | static 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 | ||
221 | static 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 | ||
229 | static 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 |
237 | extern void bgp_evpn_es_evi_vrf_ref(struct bgpevpn *vpn); |
238 | extern void bgp_evpn_es_evi_vrf_deref(struct bgpevpn *vpn); | |
239 | ||
6a8657d0 MK |
240 | static 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 | ||
256 | static 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 | 283 | static inline int is_vni_configured(struct bgpevpn *vpn) |
128ea8ab | 284 | { |
d62a17ae | 285 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_CFGD)); |
128ea8ab | 286 | } |
287 | ||
d62a17ae | 288 | static inline int is_vni_live(struct bgpevpn *vpn) |
128ea8ab | 289 | { |
d62a17ae | 290 | return (CHECK_FLAG(vpn->flags, VNI_FLAG_LIVE)); |
128ea8ab | 291 | } |
292 | ||
3d0b43d7 | 293 | static inline int is_l3vni_live(struct bgp *bgp_vrf) |
294 | { | |
295 | return (bgp_vrf->l3vni && bgp_vrf->l3vni_svi_ifindex); | |
296 | } | |
297 | ||
d62a17ae | 298 | static 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 | 303 | static 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 | 309 | static 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 | 314 | static 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 | 319 | static 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 |
328 | static 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 |
339 | static 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 |
349 | static 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 |
358 | static 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 | 365 | static 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 | 379 | static 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 | 391 | static 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 | 408 | static 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 | 417 | static 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 | 434 | static 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 | 443 | static 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; | |
cabddbf5 | 453 | memcpy(&p->prefix.macip_addr.ip, ip, sizeof(*ip)); |
128ea8ab | 454 | } |
455 | ||
bd494ec5 DS |
456 | static inline void |
457 | build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp, | |
458 | const struct prefix *ip_prefix) | |
342dd0c6 | 459 | { |
460 | struct ipaddr ip; | |
461 | ||
462 | memset(&ip, 0, sizeof(struct ipaddr)); | |
463 | if (ip_prefix->family == AF_INET) { | |
464 | ip.ipa_type = IPADDR_V4; | |
465 | memcpy(&ip.ipaddr_v4, &ip_prefix->u.prefix4, | |
466 | sizeof(struct in_addr)); | |
467 | } else { | |
468 | ip.ipa_type = IPADDR_V6; | |
469 | memcpy(&ip.ipaddr_v6, &ip_prefix->u.prefix6, | |
470 | sizeof(struct in6_addr)); | |
471 | } | |
472 | ||
473 | memset(evp, 0, sizeof(struct prefix_evpn)); | |
474 | evp->family = AF_EVPN; | |
50f74cf1 | 475 | evp->prefixlen = EVPN_ROUTE_PREFIXLEN; |
342dd0c6 | 476 | evp->prefix.route_type = BGP_EVPN_IP_PREFIX_ROUTE; |
3714a385 | 477 | evp->prefix.prefix_addr.ip_prefix_length = ip_prefix->prefixlen; |
478 | evp->prefix.prefix_addr.ip.ipa_type = ip.ipa_type; | |
479 | memcpy(&evp->prefix.prefix_addr.ip, &ip, sizeof(struct ipaddr)); | |
342dd0c6 | 480 | } |
481 | ||
d62a17ae | 482 | static inline void build_evpn_type3_prefix(struct prefix_evpn *p, |
483 | struct in_addr originator_ip) | |
128ea8ab | 484 | { |
d62a17ae | 485 | memset(p, 0, sizeof(struct prefix_evpn)); |
b03b8898 | 486 | p->family = AF_EVPN; |
50f74cf1 | 487 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; |
d62a17ae | 488 | p->prefix.route_type = BGP_EVPN_IMET_ROUTE; |
3714a385 | 489 | p->prefix.imet_addr.ip.ipa_type = IPADDR_V4; |
490 | p->prefix.imet_addr.ip.ipaddr_v4 = originator_ip; | |
128ea8ab | 491 | } |
492 | ||
50f74cf1 | 493 | static inline void build_evpn_type4_prefix(struct prefix_evpn *p, |
494 | esi_t *esi, | |
495 | struct in_addr originator_ip) | |
496 | { | |
497 | memset(p, 0, sizeof(struct prefix_evpn)); | |
498 | p->family = AF_EVPN; | |
499 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; | |
500 | p->prefix.route_type = BGP_EVPN_ES_ROUTE; | |
501 | p->prefix.es_addr.ip_prefix_length = IPV4_MAX_BITLEN; | |
502 | p->prefix.es_addr.ip.ipa_type = IPADDR_V4; | |
503 | p->prefix.es_addr.ip.ipaddr_v4 = originator_ip; | |
504 | memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t)); | |
505 | } | |
506 | ||
c44ab6f1 AK |
507 | static inline void build_evpn_type1_prefix(struct prefix_evpn *p, |
508 | uint32_t eth_tag, | |
509 | esi_t *esi, | |
510 | struct in_addr originator_ip) | |
511 | { | |
512 | memset(p, 0, sizeof(struct prefix_evpn)); | |
513 | p->family = AF_EVPN; | |
514 | p->prefixlen = EVPN_ROUTE_PREFIXLEN; | |
515 | p->prefix.route_type = BGP_EVPN_AD_ROUTE; | |
516 | p->prefix.ead_addr.eth_tag = eth_tag; | |
c44ab6f1 AK |
517 | p->prefix.ead_addr.ip.ipa_type = IPADDR_V4; |
518 | p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip; | |
519 | memcpy(&p->prefix.ead_addr.esi, esi, sizeof(esi_t)); | |
520 | } | |
521 | ||
522 | static inline void evpn_type1_prefix_global_copy(struct prefix_evpn *global_p, | |
523 | const struct prefix_evpn *vni_p) | |
524 | { | |
525 | memcpy(global_p, vni_p, sizeof(*global_p)); | |
c44ab6f1 | 526 | global_p->prefix.ead_addr.ip.ipa_type = 0; |
3a6290bd | 527 | global_p->prefix.ead_addr.ip.ipaddr_v4.s_addr = INADDR_ANY; |
7b0db0e4 | 528 | global_p->prefix.ead_addr.frag_id = 0; |
c44ab6f1 AK |
529 | } |
530 | ||
531 | /* EAD prefix in the global table doesn't include the VTEP-IP so | |
532 | * we need to create a different copy for the VNI | |
533 | */ | |
534 | static inline struct prefix_evpn *evpn_type1_prefix_vni_copy( | |
535 | struct prefix_evpn *vni_p, | |
536 | const struct prefix_evpn *global_p, | |
537 | struct in_addr originator_ip) | |
538 | { | |
539 | memcpy(vni_p, global_p, sizeof(*vni_p)); | |
c44ab6f1 AK |
540 | vni_p->prefix.ead_addr.ip.ipa_type = IPADDR_V4; |
541 | vni_p->prefix.ead_addr.ip.ipaddr_v4 = originator_ip; | |
542 | ||
543 | return vni_p; | |
544 | } | |
545 | ||
34c7f35f SW |
546 | static inline void |
547 | evpn_type2_prefix_global_copy(struct prefix_evpn *global_p, | |
548 | const struct prefix_evpn *vni_p, | |
549 | const struct ethaddr mac) | |
550 | { | |
551 | memcpy(global_p, vni_p, sizeof(*global_p)); | |
552 | global_p->prefix.macip_addr.mac = mac; | |
553 | } | |
554 | ||
555 | static inline void | |
556 | evpn_type2_prefix_vni_copy(struct prefix_evpn *vni_p, | |
557 | const struct prefix_evpn *global_p) | |
558 | { | |
559 | memcpy(vni_p, global_p, sizeof(*vni_p)); | |
560 | memset(&vni_p->prefix.macip_addr.mac, 0, sizeof(struct ethaddr)); | |
561 | } | |
562 | ||
563 | /* Get MAC of path_info prefix */ | |
564 | static inline struct ethaddr * | |
565 | evpn_type2_path_info_get_mac(const struct bgp_path_info *local_pi) | |
566 | { | |
567 | assert(local_pi->extra); | |
568 | return &local_pi->extra->mac; | |
569 | } | |
570 | ||
571 | /* Set MAC of path_info prefix */ | |
572 | static inline void evpn_type2_path_info_set_mac(struct bgp_path_info *local_pi, | |
573 | const struct ethaddr mac) | |
574 | { | |
575 | assert(local_pi->extra); | |
576 | local_pi->extra->mac = mac; | |
577 | } | |
578 | ||
486456ca MK |
579 | static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi, |
580 | safi_t safi) | |
581 | { | |
582 | if (afi == AFI_IP && | |
583 | CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN], | |
584 | BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV4)) | |
585 | return 1; | |
586 | else if (afi == AFI_IP6 && | |
587 | CHECK_FLAG(bgp->af_flags[AFI_L2VPN][SAFI_EVPN], | |
588 | BGP_L2VPN_EVPN_DEFAULT_ORIGINATE_IPV6)) | |
589 | return 1; | |
590 | return 0; | |
591 | } | |
592 | ||
50f74cf1 | 593 | static inline void es_get_system_mac(esi_t *esi, |
594 | struct ethaddr *mac) | |
595 | { | |
2bb9eff4 DS |
596 | /* |
597 | * for type-1 and type-3 ESIs, | |
598 | * the system mac starts at val[1] | |
50f74cf1 | 599 | */ |
600 | memcpy(mac, &esi->val[1], ETH_ALEN); | |
601 | } | |
602 | ||
0ca10580 CS |
603 | static inline bool bgp_evpn_is_svi_macip_enabled(struct bgpevpn *vpn) |
604 | { | |
605 | struct bgp *bgp_evpn = NULL; | |
606 | ||
607 | bgp_evpn = bgp_get_evpn(); | |
608 | ||
609 | return (bgp_evpn->evpn_info->advertise_svi_macip || | |
610 | vpn->advertise_svi_macip); | |
611 | } | |
612 | ||
9c7edc03 AK |
613 | static inline bool bgp_evpn_is_path_local(struct bgp *bgp, |
614 | struct bgp_path_info *pi) | |
615 | { | |
616 | return (pi->peer == bgp->peer_self | |
617 | && pi->type == ZEBRA_ROUTE_BGP | |
618 | && pi->sub_type == BGP_ROUTE_STATIC); | |
619 | } | |
620 | ||
c44ab6f1 AK |
621 | extern struct zclient *zclient; |
622 | ||
5fd9c12b KA |
623 | extern void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf, |
624 | afi_t afi, safi_t safi, | |
625 | bool add); | |
996c9314 | 626 | extern void evpn_rt_delete_auto(struct bgp *, vni_t, struct list *); |
523cafc4 | 627 | extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf, |
628 | struct ecommunity *ecomadd); | |
629 | extern void bgp_evpn_unconfigure_export_rt_for_vrf(struct bgp *bgp_vrf, | |
630 | struct ecommunity *ecomdel); | |
631 | extern void bgp_evpn_configure_import_rt_for_vrf(struct bgp *bgp_vrf, | |
632 | struct ecommunity *ecomadd); | |
633 | extern void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf, | |
634 | struct ecommunity *ecomdel); | |
d62a17ae | 635 | extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp, |
636 | struct bgpevpn *vpn); | |
bf1061d8 | 637 | extern void bgp_evpn_handle_autort_change(struct bgp *bgp); |
676f83b9 | 638 | extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw); |
d62a17ae | 639 | extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn, |
640 | int withdraw); | |
641 | extern int bgp_evpn_install_routes(struct bgp *bgp, struct bgpevpn *vpn); | |
642 | extern int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn); | |
523cafc4 | 643 | extern void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf); |
644 | extern void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf); | |
d62a17ae | 645 | extern void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn); |
646 | extern void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp, | |
647 | struct bgpevpn *vpn); | |
648 | extern void bgp_evpn_derive_auto_rt_import(struct bgp *bgp, | |
649 | struct bgpevpn *vpn); | |
650 | extern void bgp_evpn_derive_auto_rt_export(struct bgp *bgp, | |
651 | struct bgpevpn *vpn); | |
652 | extern void bgp_evpn_derive_auto_rd(struct bgp *bgp, struct bgpevpn *vpn); | |
676f83b9 | 653 | extern void bgp_evpn_derive_auto_rd_for_vrf(struct bgp *bgp); |
d62a17ae | 654 | extern struct bgpevpn *bgp_evpn_lookup_vni(struct bgp *bgp, vni_t vni); |
655 | extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni, | |
76d07c7a AK |
656 | struct in_addr originator_ip, |
657 | vrf_id_t tenant_vrf_id, | |
9daa5d47 AD |
658 | struct in_addr mcast_grp, |
659 | ifindex_t svi_ifindex); | |
d62a17ae | 660 | extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn); |
7df407ed | 661 | extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni); |
0ca10580 | 662 | extern int update_routes_for_vni(struct bgp *bgp, struct bgpevpn *vpn); |
185fb14a AK |
663 | extern void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi, |
664 | struct bgp_dest *dest, | |
665 | struct bgp_path_info **pi); | |
c44ab6f1 AK |
666 | int vni_list_cmp(void *p1, void *p2); |
667 | extern int evpn_route_select_install(struct bgp *bgp, struct bgpevpn *vpn, | |
09319b4e | 668 | struct bgp_dest *dest); |
09319b4e | 669 | extern struct bgp_dest * |
34c7f35f SW |
670 | bgp_evpn_global_node_get(struct bgp_table *table, afi_t afi, safi_t safi, |
671 | const struct prefix_evpn *evp, struct prefix_rd *prd, | |
672 | const struct bgp_path_info *local_pi); | |
673 | extern struct bgp_dest * | |
674 | bgp_evpn_global_node_lookup(struct bgp_table *table, afi_t afi, safi_t safi, | |
26c03e43 | 675 | const struct prefix_evpn *evp, |
34c7f35f SW |
676 | struct prefix_rd *prd, |
677 | const struct bgp_path_info *local_pi); | |
678 | extern struct bgp_dest * | |
679 | bgp_evpn_vni_node_get(struct bgp_table *const table, | |
680 | const struct prefix_evpn *evp, | |
681 | const struct bgp_path_info *parent_pi); | |
682 | extern struct bgp_dest * | |
683 | bgp_evpn_vni_node_lookup(const struct bgp_table *const table, | |
684 | const struct prefix_evpn *evp, | |
685 | const struct bgp_path_info *parent_pi); | |
686 | extern void bgp_evpn_import_route_in_vrfs(struct bgp_path_info *pi, int import); | |
70524092 AK |
687 | extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp, |
688 | struct bgpevpn *vpn, | |
689 | struct bgp_node *rn, | |
690 | struct bgp_path_info *local_pi, | |
691 | const char *caller); | |
58bff4d1 AK |
692 | extern int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf, |
693 | struct bgp_path_info *pi, | |
694 | int install); | |
74efb822 | 695 | extern void bgp_evpn_import_type2_route(struct bgp_path_info *pi, int import); |
f4a5218d AK |
696 | extern void bgp_evpn_xxport_delete_ecomm(void *val); |
697 | extern int bgp_evpn_route_target_cmp(struct ecommunity *ecom1, | |
698 | struct ecommunity *ecom2); | |
a4168ebc | 699 | #endif /* _BGP_EVPN_PRIVATE_H */ |