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