]>
Commit | Line | Data |
---|---|---|
6006414d PR |
1 | /* |
2 | * Zebra EVPN for VxLAN code | |
3 | * Copyright (C) 2016, 2017 Cumulus Networks, Inc. | |
4 | * | |
5 | * This file is part of FRR. | |
6 | * | |
7 | * FRR is free software; you can redistribute it and/or modify it | |
8 | * under the terms of the GNU General Public License as published by the | |
9 | * Free Software Foundation; either version 2, or (at your option) any | |
10 | * later version. | |
11 | * | |
12 | * FRR is distributed in the hope that it will be useful, but | |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU General Public License | |
18 | * along with FRR; see the file COPYING. If not, write to the Free | |
19 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
20 | * 02111-1307, USA. | |
21 | */ | |
6006414d PR |
22 | #include <zebra.h> |
23 | ||
24 | #include "hash.h" | |
25 | #include "if.h" | |
26 | #include "jhash.h" | |
27 | #include "linklist.h" | |
28 | #include "log.h" | |
29 | #include "memory.h" | |
30 | #include "prefix.h" | |
31 | #include "stream.h" | |
32 | #include "table.h" | |
33 | #include "vlan.h" | |
34 | #include "vxlan.h" | |
35 | #ifdef GNU_LINUX | |
36 | #include <linux/neighbour.h> | |
37 | #endif | |
38 | ||
39 | #include "zebra/zebra_router.h" | |
40 | #include "zebra/debug.h" | |
41 | #include "zebra/interface.h" | |
42 | #include "zebra/rib.h" | |
43 | #include "zebra/rt.h" | |
44 | #include "zebra/rt_netlink.h" | |
45 | #include "zebra/zebra_errors.h" | |
46 | #include "zebra/zebra_l2.h" | |
47 | #include "zebra/zebra_memory.h" | |
48 | #include "zebra/zebra_ns.h" | |
49 | #include "zebra/zebra_vrf.h" | |
50 | #include "zebra/zebra_vxlan.h" | |
51 | #include "zebra/zebra_evpn.h" | |
52 | #include "zebra/zebra_evpn_mac.h" | |
53 | #include "zebra/zebra_evpn_neigh.h" | |
54 | #include "zebra/zebra_vxlan_private.h" | |
55 | #include "zebra/zebra_evpn_mh.h" | |
8b5fdf2e | 56 | #include "zebra/zebra_evpn_vxlan.h" |
6006414d PR |
57 | #include "zebra/zebra_router.h" |
58 | ||
8b5fdf2e PR |
59 | DEFINE_MTYPE_STATIC(ZEBRA, ZEVPN, "VNI hash"); |
60 | DEFINE_MTYPE_STATIC(ZEBRA, ZEVPN_VTEP, "VNI remote VTEP"); | |
6006414d | 61 | |
6006414d PR |
62 | /* PMSI strings. */ |
63 | #define VXLAN_FLOOD_STR_NO_INFO "-" | |
64 | #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO | |
65 | static const struct message zvtep_flood_str[] = { | |
66 | {VXLAN_FLOOD_DISABLED, VXLAN_FLOOD_STR_NO_INFO}, | |
67 | {VXLAN_FLOOD_PIM_SM, "PIM-SM"}, | |
68 | {VXLAN_FLOOD_HEAD_END_REPL, "HER"}, | |
69 | {0} | |
70 | }; | |
71 | ||
6006414d PR |
72 | int advertise_gw_macip_enabled(zebra_evpn_t *zevpn) |
73 | { | |
74 | struct zebra_vrf *zvrf; | |
75 | ||
76 | zvrf = zebra_vrf_get_evpn(); | |
77 | if (zvrf && zvrf->advertise_gw_macip) | |
78 | return 1; | |
79 | ||
80 | if (zevpn && zevpn->advertise_gw_macip) | |
81 | return 1; | |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
86 | int advertise_svi_macip_enabled(zebra_evpn_t *zevpn) | |
87 | { | |
88 | struct zebra_vrf *zvrf; | |
89 | ||
90 | zvrf = zebra_vrf_get_evpn(); | |
91 | if (zvrf && zvrf->advertise_svi_macip) | |
92 | return 1; | |
93 | ||
94 | if (zevpn && zevpn->advertise_svi_macip) | |
95 | return 1; | |
96 | ||
97 | return 0; | |
98 | } | |
99 | ||
6006414d PR |
100 | /* |
101 | * Print a specific EVPN entry. | |
102 | */ | |
8b5fdf2e | 103 | void zebra_evpn_print(zebra_evpn_t *zevpn, void **ctxt) |
6006414d PR |
104 | { |
105 | struct vty *vty; | |
106 | zebra_vtep_t *zvtep; | |
107 | uint32_t num_macs; | |
108 | uint32_t num_neigh; | |
109 | json_object *json = NULL; | |
110 | json_object *json_vtep_list = NULL; | |
111 | json_object *json_ip_str = NULL; | |
112 | ||
113 | vty = ctxt[0]; | |
114 | json = ctxt[1]; | |
115 | ||
116 | if (json == NULL) { | |
117 | vty_out(vty, "VNI: %u\n", zevpn->vni); | |
118 | vty_out(vty, " Type: %s\n", "L2"); | |
119 | vty_out(vty, " Tenant VRF: %s\n", vrf_id_to_name(zevpn->vrf_id)); | |
120 | } else { | |
121 | json_object_int_add(json, "vni", zevpn->vni); | |
122 | json_object_string_add(json, "type", "L2"); | |
123 | json_object_string_add(json, "vrf", | |
124 | vrf_id_to_name(zevpn->vrf_id)); | |
125 | } | |
126 | ||
127 | if (!zevpn->vxlan_if) { // unexpected | |
128 | if (json == NULL) | |
129 | vty_out(vty, " VxLAN interface: unknown\n"); | |
130 | return; | |
131 | } | |
132 | num_macs = num_valid_macs(zevpn); | |
133 | num_neigh = hashcount(zevpn->neigh_table); | |
134 | if (json == NULL) { | |
135 | vty_out(vty, " VxLAN interface: %s\n", zevpn->vxlan_if->name); | |
136 | vty_out(vty, " VxLAN ifIndex: %u\n", zevpn->vxlan_if->ifindex); | |
137 | vty_out(vty, " Local VTEP IP: %s\n", | |
138 | inet_ntoa(zevpn->local_vtep_ip)); | |
139 | vty_out(vty, " Mcast group: %s\n", | |
140 | inet_ntoa(zevpn->mcast_grp)); | |
141 | } else { | |
142 | json_object_string_add(json, "vxlanInterface", | |
143 | zevpn->vxlan_if->name); | |
144 | json_object_int_add(json, "ifindex", zevpn->vxlan_if->ifindex); | |
145 | json_object_string_add(json, "vtepIp", | |
146 | inet_ntoa(zevpn->local_vtep_ip)); | |
147 | json_object_string_add(json, "mcastGroup", | |
148 | inet_ntoa(zevpn->mcast_grp)); | |
149 | json_object_string_add(json, "advertiseGatewayMacip", | |
150 | zevpn->advertise_gw_macip ? "Yes" : "No"); | |
151 | json_object_int_add(json, "numMacs", num_macs); | |
152 | json_object_int_add(json, "numArpNd", num_neigh); | |
153 | } | |
154 | if (!zevpn->vteps) { | |
155 | if (json == NULL) | |
156 | vty_out(vty, " No remote VTEPs known for this VNI\n"); | |
157 | } else { | |
158 | if (json == NULL) | |
159 | vty_out(vty, " Remote VTEPs for this VNI:\n"); | |
160 | else | |
161 | json_vtep_list = json_object_new_array(); | |
162 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
163 | const char *flood_str = lookup_msg(zvtep_flood_str, | |
164 | zvtep->flood_control, | |
165 | VXLAN_FLOOD_STR_DEFAULT); | |
166 | ||
167 | if (json == NULL) { | |
168 | vty_out(vty, " %s flood: %s\n", | |
169 | inet_ntoa(zvtep->vtep_ip), | |
170 | flood_str); | |
171 | } else { | |
172 | json_ip_str = json_object_new_string( | |
173 | inet_ntoa(zvtep->vtep_ip)); | |
174 | json_object_array_add(json_vtep_list, | |
175 | json_ip_str); | |
176 | } | |
177 | } | |
178 | if (json) | |
179 | json_object_object_add(json, "numRemoteVteps", | |
180 | json_vtep_list); | |
181 | } | |
182 | if (json == NULL) { | |
183 | vty_out(vty, | |
184 | " Number of MACs (local and remote) known for this VNI: %u\n", | |
185 | num_macs); | |
186 | vty_out(vty, | |
187 | " Number of ARPs (IPv4 and IPv6, local and remote) " | |
188 | "known for this VNI: %u\n", | |
189 | num_neigh); | |
190 | vty_out(vty, " Advertise-gw-macip: %s\n", | |
191 | zevpn->advertise_gw_macip ? "Yes" : "No"); | |
192 | } | |
193 | } | |
194 | ||
8b5fdf2e PR |
195 | /* |
196 | * Print an EVPN hash entry - called for display of all VNIs. | |
197 | */ | |
198 | void zebra_evpn_print_hash(struct hash_bucket *bucket, void *ctxt[]) | |
6006414d | 199 | { |
8b5fdf2e PR |
200 | struct vty *vty; |
201 | zebra_evpn_t *zevpn; | |
202 | zebra_vtep_t *zvtep; | |
203 | uint32_t num_vteps = 0; | |
204 | uint32_t num_macs = 0; | |
205 | uint32_t num_neigh = 0; | |
6006414d PR |
206 | json_object *json = NULL; |
207 | json_object *json_evpn = NULL; | |
8b5fdf2e PR |
208 | json_object *json_ip_str = NULL; |
209 | json_object *json_vtep_list = NULL; | |
6006414d | 210 | |
8b5fdf2e PR |
211 | vty = ctxt[0]; |
212 | json = ctxt[1]; | |
6006414d | 213 | |
8b5fdf2e | 214 | zevpn = (zebra_evpn_t *)bucket->data; |
6006414d | 215 | |
8b5fdf2e PR |
216 | zvtep = zevpn->vteps; |
217 | while (zvtep) { | |
218 | num_vteps++; | |
219 | zvtep = zvtep->next; | |
6006414d PR |
220 | } |
221 | ||
222 | num_macs = num_valid_macs(zevpn); | |
223 | num_neigh = hashcount(zevpn->neigh_table); | |
224 | if (json == NULL) | |
225 | vty_out(vty, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n", | |
226 | zevpn->vni, "L2", | |
227 | zevpn->vxlan_if ? zevpn->vxlan_if->name : "unknown", | |
228 | num_macs, num_neigh, num_vteps, | |
229 | vrf_id_to_name(zevpn->vrf_id)); | |
230 | else { | |
231 | char vni_str[VNI_STR_LEN]; | |
232 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
233 | json_evpn = json_object_new_object(); | |
234 | json_object_int_add(json_evpn, "vni", zevpn->vni); | |
235 | json_object_string_add(json_evpn, "type", "L2"); | |
236 | json_object_string_add(json_evpn, "vxlanIf", | |
237 | zevpn->vxlan_if ? zevpn->vxlan_if->name | |
238 | : "unknown"); | |
239 | json_object_int_add(json_evpn, "numMacs", num_macs); | |
240 | json_object_int_add(json_evpn, "numArpNd", num_neigh); | |
241 | json_object_int_add(json_evpn, "numRemoteVteps", num_vteps); | |
242 | json_object_string_add(json_evpn, "tenantVrf", | |
243 | vrf_id_to_name(zevpn->vrf_id)); | |
244 | if (num_vteps) { | |
245 | json_vtep_list = json_object_new_array(); | |
246 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
247 | json_ip_str = json_object_new_string( | |
248 | inet_ntoa(zvtep->vtep_ip)); | |
249 | json_object_array_add(json_vtep_list, | |
250 | json_ip_str); | |
251 | } | |
252 | json_object_object_add(json_evpn, "remoteVteps", | |
253 | json_vtep_list); | |
254 | } | |
255 | json_object_object_add(json, vni_str, json_evpn); | |
256 | } | |
257 | } | |
258 | ||
259 | /* | |
260 | * Print an EVPN hash entry in detail - called for display of all EVPNs. | |
261 | */ | |
8b5fdf2e | 262 | void zebra_evpn_print_hash_detail(struct hash_bucket *bucket, void *data) |
6006414d PR |
263 | { |
264 | struct vty *vty; | |
265 | zebra_evpn_t *zevpn; | |
266 | json_object *json_array = NULL; | |
267 | bool use_json = false; | |
8b5fdf2e | 268 | struct zebra_evpn_show *zes = data; |
6006414d PR |
269 | |
270 | vty = zes->vty; | |
271 | json_array = zes->json; | |
272 | use_json = zes->use_json; | |
273 | ||
274 | zevpn = (zebra_evpn_t *)bucket->data; | |
275 | ||
276 | zebra_vxlan_print_vni(vty, zes->zvrf, zevpn->vni, use_json, json_array); | |
277 | ||
278 | if (!use_json) | |
279 | vty_out(vty, "\n"); | |
280 | } | |
281 | ||
8b5fdf2e | 282 | int zebra_evpn_del_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn) |
6006414d PR |
283 | { |
284 | struct listnode *cnode = NULL, *cnnode = NULL; | |
285 | struct connected *c = NULL; | |
286 | struct ethaddr macaddr; | |
287 | ||
288 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
289 | ||
290 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
291 | struct ipaddr ip; | |
292 | ||
293 | memset(&ip, 0, sizeof(struct ipaddr)); | |
294 | if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) | |
295 | continue; | |
296 | ||
297 | if (c->address->family == AF_INET) { | |
298 | ip.ipa_type = IPADDR_V4; | |
299 | memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), | |
300 | sizeof(struct in_addr)); | |
301 | } else if (c->address->family == AF_INET6) { | |
302 | ip.ipa_type = IPADDR_V6; | |
303 | memcpy(&(ip.ipaddr_v6), &(c->address->u.prefix6), | |
304 | sizeof(struct in6_addr)); | |
305 | } else { | |
306 | continue; | |
307 | } | |
308 | ||
8b5fdf2e | 309 | zebra_evpn_gw_macip_del(ifp, zevpn, &ip); |
6006414d PR |
310 | } |
311 | ||
312 | return 0; | |
313 | } | |
314 | ||
8b5fdf2e | 315 | int zebra_evpn_add_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn) |
6006414d PR |
316 | { |
317 | struct listnode *cnode = NULL, *cnnode = NULL; | |
318 | struct connected *c = NULL; | |
319 | struct ethaddr macaddr; | |
320 | ||
321 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
322 | ||
323 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
324 | struct ipaddr ip; | |
325 | ||
326 | memset(&ip, 0, sizeof(struct ipaddr)); | |
327 | if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) | |
328 | continue; | |
329 | ||
330 | if (c->address->family == AF_INET) { | |
331 | ip.ipa_type = IPADDR_V4; | |
332 | memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), | |
333 | sizeof(struct in_addr)); | |
334 | } else if (c->address->family == AF_INET6) { | |
335 | ip.ipa_type = IPADDR_V6; | |
336 | memcpy(&(ip.ipaddr_v6), &(c->address->u.prefix6), | |
337 | sizeof(struct in6_addr)); | |
338 | } else { | |
339 | continue; | |
340 | } | |
341 | ||
8b5fdf2e | 342 | zebra_evpn_gw_macip_add(ifp, zevpn, &macaddr, &ip); |
6006414d PR |
343 | } |
344 | return 0; | |
345 | } | |
346 | ||
8b5fdf2e PR |
347 | static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, |
348 | uint16_t cmd) | |
349 | { | |
350 | struct zserv *client = NULL; | |
351 | struct stream *s = NULL; | |
352 | char buf[PREFIX_STRLEN]; | |
353 | ||
354 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
355 | /* BGP may not be running. */ | |
356 | if (!client) | |
357 | return 0; | |
358 | ||
359 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
360 | ||
361 | zclient_create_header(s, cmd, vrf_id); | |
362 | stream_put(s, p, sizeof(struct prefix)); | |
363 | ||
364 | /* Write packet size. */ | |
365 | stream_putw_at(s, 0, stream_get_endp(s)); | |
366 | ||
367 | if (IS_ZEBRA_DEBUG_VXLAN) | |
368 | zlog_debug("Send ip prefix %s %s on vrf %s", | |
369 | prefix2str(p, buf, sizeof(buf)), | |
370 | (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", | |
371 | vrf_id_to_name(vrf_id)); | |
372 | ||
373 | if (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) | |
374 | client->prefixadd_cnt++; | |
375 | else | |
376 | client->prefixdel_cnt++; | |
377 | ||
378 | return zserv_send_message(client, s); | |
379 | } | |
6006414d | 380 | |
8b5fdf2e PR |
381 | int zebra_evpn_advertise_subnet(zebra_evpn_t *zevpn, struct interface *ifp, |
382 | int advertise) | |
6006414d PR |
383 | { |
384 | struct listnode *cnode = NULL, *cnnode = NULL; | |
385 | struct connected *c = NULL; | |
386 | struct ethaddr macaddr; | |
387 | ||
388 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
389 | ||
390 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
391 | struct prefix p; | |
392 | ||
393 | memcpy(&p, c->address, sizeof(struct prefix)); | |
394 | ||
395 | /* skip link local address */ | |
396 | if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) | |
397 | continue; | |
398 | ||
399 | apply_mask(&p); | |
400 | if (advertise) | |
401 | ip_prefix_send_to_client(ifp->vrf_id, &p, | |
402 | ZEBRA_IP_PREFIX_ROUTE_ADD); | |
403 | else | |
404 | ip_prefix_send_to_client(ifp->vrf_id, &p, | |
405 | ZEBRA_IP_PREFIX_ROUTE_DEL); | |
406 | } | |
407 | return 0; | |
408 | } | |
409 | ||
410 | /* | |
8b5fdf2e | 411 | * zebra_evpn_gw_macip_add_to_client |
6006414d | 412 | */ |
8b5fdf2e PR |
413 | int zebra_evpn_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, |
414 | struct ethaddr *macaddr, struct ipaddr *ip) | |
6006414d PR |
415 | { |
416 | zebra_mac_t *mac = NULL; | |
417 | struct zebra_if *zif = NULL; | |
418 | struct zebra_l2info_vxlan *vxl = NULL; | |
419 | ||
420 | zif = zevpn->vxlan_if->info; | |
421 | if (!zif) | |
422 | return -1; | |
423 | ||
424 | vxl = &zif->l2info.vxl; | |
425 | ||
426 | if (zebra_evpn_mac_gw_macip_add(ifp, zevpn, ip, &mac, macaddr, | |
427 | vxl->access_vlan) | |
428 | != 0) | |
429 | return -1; | |
430 | ||
431 | return zebra_evpn_neigh_gw_macip_add(ifp, zevpn, ip, mac); | |
432 | } | |
433 | ||
434 | /* | |
8b5fdf2e | 435 | * zebra_evpn_gw_macip_del_from_client |
6006414d | 436 | */ |
8b5fdf2e PR |
437 | int zebra_evpn_gw_macip_del(struct interface *ifp, zebra_evpn_t *zevpn, |
438 | struct ipaddr *ip) | |
6006414d PR |
439 | { |
440 | char buf1[ETHER_ADDR_STRLEN]; | |
441 | char buf2[INET6_ADDRSTRLEN]; | |
442 | zebra_neigh_t *n = NULL; | |
443 | zebra_mac_t *mac = NULL; | |
444 | ||
445 | /* If the neigh entry is not present nothing to do*/ | |
446 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
447 | if (!n) | |
448 | return 0; | |
449 | ||
450 | /* mac entry should be present */ | |
451 | mac = zebra_evpn_mac_lookup(zevpn, &n->emac); | |
452 | if (!mac) { | |
453 | if (IS_ZEBRA_DEBUG_VXLAN) | |
454 | zlog_debug("MAC %s doesn't exist for neigh %s on VNI %u", | |
455 | prefix_mac2str(&n->emac, | |
456 | buf1, sizeof(buf1)), | |
457 | ipaddr2str(ip, buf2, sizeof(buf2)), | |
458 | zevpn->vni); | |
459 | return -1; | |
460 | } | |
461 | ||
462 | /* If the entry is not local nothing to do*/ | |
463 | if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) | |
464 | return -1; | |
465 | ||
466 | /* only need to delete the entry from bgp if we sent it before */ | |
467 | if (IS_ZEBRA_DEBUG_VXLAN) | |
468 | zlog_debug( | |
469 | "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", | |
470 | ifp->vrf_id, ifp->name, ifp->ifindex, zevpn->vni, | |
471 | prefix_mac2str(&(n->emac), buf1, sizeof(buf1)), | |
472 | ipaddr2str(ip, buf2, sizeof(buf2))); | |
473 | ||
474 | /* Remove neighbor from BGP. */ | |
475 | zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac, | |
476 | n->flags, ZEBRA_NEIGH_ACTIVE, | |
477 | false /*force*/); | |
478 | ||
479 | /* Delete this neighbor entry. */ | |
480 | zebra_evpn_neigh_del(zevpn, n); | |
481 | ||
482 | /* see if the mac needs to be deleted as well*/ | |
483 | if (mac) | |
484 | zebra_evpn_deref_ip2mac(zevpn, mac); | |
485 | ||
486 | return 0; | |
487 | } | |
488 | ||
8b5fdf2e | 489 | void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket *bucket, |
6006414d PR |
490 | void *ctxt) |
491 | { | |
492 | zebra_evpn_t *zevpn = NULL; | |
493 | struct zebra_if *zif = NULL; | |
494 | struct zebra_l2info_vxlan zl2_info; | |
495 | struct interface *vlan_if = NULL; | |
496 | struct interface *vrr_if = NULL; | |
497 | struct interface *ifp; | |
498 | ||
499 | /* Add primary SVI MAC*/ | |
500 | zevpn = (zebra_evpn_t *)bucket->data; | |
501 | ||
502 | /* Global (Zvrf) advertise-default-gw is disabled, | |
503 | * but zevpn advertise-default-gw is enabled | |
504 | */ | |
505 | if (zevpn->advertise_gw_macip) { | |
506 | if (IS_ZEBRA_DEBUG_VXLAN) | |
507 | zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip", | |
508 | zevpn->vni); | |
509 | return; | |
510 | } | |
511 | ||
512 | ifp = zevpn->vxlan_if; | |
513 | if (!ifp) | |
514 | return; | |
515 | zif = ifp->info; | |
516 | ||
517 | /* If down or not mapped to a bridge, we're done. */ | |
518 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
519 | return; | |
520 | ||
521 | zl2_info = zif->l2info.vxl; | |
522 | ||
523 | vlan_if = | |
524 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
525 | if (!vlan_if) | |
526 | return; | |
527 | ||
528 | /* Del primary MAC-IP */ | |
8b5fdf2e | 529 | zebra_evpn_del_macip_for_intf(vlan_if, zevpn); |
6006414d PR |
530 | |
531 | /* Del VRR MAC-IP - if any*/ | |
532 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
533 | if (vrr_if) | |
8b5fdf2e | 534 | zebra_evpn_del_macip_for_intf(vrr_if, zevpn); |
6006414d PR |
535 | |
536 | return; | |
537 | } | |
538 | ||
8b5fdf2e | 539 | void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket *bucket, |
6006414d PR |
540 | void *ctxt) |
541 | { | |
542 | zebra_evpn_t *zevpn = NULL; | |
543 | struct zebra_if *zif = NULL; | |
544 | struct zebra_l2info_vxlan zl2_info; | |
545 | struct interface *vlan_if = NULL; | |
546 | struct interface *vrr_if = NULL; | |
547 | struct interface *ifp = NULL; | |
548 | ||
549 | zevpn = (zebra_evpn_t *)bucket->data; | |
550 | ||
551 | ifp = zevpn->vxlan_if; | |
552 | if (!ifp) | |
553 | return; | |
554 | zif = ifp->info; | |
555 | ||
556 | /* If down or not mapped to a bridge, we're done. */ | |
557 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
558 | return; | |
559 | zl2_info = zif->l2info.vxl; | |
560 | ||
561 | vlan_if = | |
562 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
563 | if (!vlan_if) | |
564 | return; | |
565 | ||
566 | /* Add primary SVI MAC-IP */ | |
8b5fdf2e | 567 | zebra_evpn_add_macip_for_intf(vlan_if, zevpn); |
6006414d PR |
568 | |
569 | if (advertise_gw_macip_enabled(zevpn)) { | |
570 | /* Add VRR MAC-IP - if any*/ | |
571 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
572 | if (vrr_if) | |
8b5fdf2e | 573 | zebra_evpn_add_macip_for_intf(vrr_if, zevpn); |
6006414d PR |
574 | } |
575 | ||
576 | return; | |
577 | } | |
578 | ||
8b5fdf2e PR |
579 | void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket *bucket, |
580 | void *ctxt) | |
6006414d PR |
581 | { |
582 | zebra_evpn_t *zevpn = NULL; | |
583 | struct zebra_if *zif = NULL; | |
584 | struct zebra_l2info_vxlan zl2_info; | |
585 | struct interface *vlan_if = NULL; | |
586 | struct interface *ifp; | |
587 | ||
588 | /* Add primary SVI MAC*/ | |
589 | zevpn = (zebra_evpn_t *)bucket->data; | |
590 | if (!zevpn) | |
591 | return; | |
592 | ||
593 | /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip | |
594 | * enabled | |
595 | */ | |
596 | if (zevpn->advertise_svi_macip) { | |
597 | if (IS_ZEBRA_DEBUG_VXLAN) | |
598 | zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip", | |
599 | zevpn->vni); | |
600 | return; | |
601 | } | |
602 | ||
603 | ifp = zevpn->vxlan_if; | |
604 | if (!ifp) | |
605 | return; | |
606 | zif = ifp->info; | |
607 | ||
608 | /* If down or not mapped to a bridge, we're done. */ | |
609 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
610 | return; | |
611 | ||
612 | zl2_info = zif->l2info.vxl; | |
613 | ||
614 | vlan_if = | |
615 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
616 | if (!vlan_if) | |
617 | return; | |
618 | ||
619 | /* Del primary MAC-IP */ | |
8b5fdf2e | 620 | zebra_evpn_del_macip_for_intf(vlan_if, zevpn); |
6006414d PR |
621 | |
622 | return; | |
623 | } | |
624 | ||
625 | /* | |
626 | * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC | |
627 | * notifications, to see if they are of interest. | |
628 | */ | |
8b5fdf2e | 629 | zebra_evpn_t *zebra_evpn_map_vlan(struct interface *ifp, |
6006414d PR |
630 | struct interface *br_if, vlanid_t vid) |
631 | { | |
632 | struct zebra_ns *zns; | |
633 | struct route_node *rn; | |
634 | struct interface *tmp_if = NULL; | |
635 | struct zebra_if *zif; | |
636 | struct zebra_l2info_bridge *br; | |
637 | struct zebra_l2info_vxlan *vxl = NULL; | |
638 | uint8_t bridge_vlan_aware; | |
639 | zebra_evpn_t *zevpn; | |
640 | int found = 0; | |
641 | ||
642 | /* Determine if bridge is VLAN-aware or not */ | |
643 | zif = br_if->info; | |
644 | assert(zif); | |
645 | br = &zif->l2info.br; | |
646 | bridge_vlan_aware = br->vlan_aware; | |
647 | ||
648 | /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ | |
649 | /* TODO: Optimize with a hash. */ | |
650 | zns = zebra_ns_lookup(NS_DEFAULT); | |
651 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
652 | tmp_if = (struct interface *)rn->info; | |
653 | if (!tmp_if) | |
654 | continue; | |
655 | zif = tmp_if->info; | |
656 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
657 | continue; | |
658 | if (!if_is_operative(tmp_if)) | |
659 | continue; | |
660 | vxl = &zif->l2info.vxl; | |
661 | ||
662 | if (zif->brslave_info.br_if != br_if) | |
663 | continue; | |
664 | ||
665 | if (!bridge_vlan_aware || vxl->access_vlan == vid) { | |
666 | found = 1; | |
667 | break; | |
668 | } | |
669 | } | |
670 | ||
671 | if (!found) | |
672 | return NULL; | |
673 | ||
8b5fdf2e | 674 | zevpn = zebra_evpn_lookup(vxl->vni); |
6006414d PR |
675 | return zevpn; |
676 | } | |
677 | ||
9d277b8c PG |
678 | struct zevpn_from_svi_param { |
679 | struct interface *br_if; | |
680 | struct zebra_if *zif; | |
681 | uint8_t bridge_vlan_aware; | |
682 | vlanid_t vid; | |
683 | }; | |
684 | ||
685 | static int zebra_evpn_from_svi_zns(struct zebra_ns *zns, | |
686 | void *_in_param, | |
687 | void **_p_zevpn) | |
6006414d | 688 | { |
6006414d | 689 | struct route_node *rn; |
9d277b8c PG |
690 | struct interface *br_if; |
691 | zebra_evpn_t **p_zevpn = (zebra_evpn_t **)_p_zevpn; | |
692 | zebra_evpn_t *zevpn; | |
6006414d PR |
693 | struct interface *tmp_if = NULL; |
694 | struct zebra_if *zif; | |
6006414d | 695 | struct zebra_l2info_vxlan *vxl = NULL; |
9d277b8c PG |
696 | struct zevpn_from_svi_param *in_param = |
697 | (struct zevpn_from_svi_param *)_in_param; | |
6006414d PR |
698 | int found = 0; |
699 | ||
9d277b8c PG |
700 | if (!in_param) |
701 | return ZNS_WALK_STOP; | |
702 | br_if = in_param->br_if; | |
703 | zif = in_param->zif; | |
6006414d | 704 | assert(zif); |
6006414d | 705 | |
6006414d | 706 | /* TODO: Optimize with a hash. */ |
6006414d PR |
707 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { |
708 | tmp_if = (struct interface *)rn->info; | |
709 | if (!tmp_if) | |
710 | continue; | |
711 | zif = tmp_if->info; | |
712 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
713 | continue; | |
714 | if (!if_is_operative(tmp_if)) | |
715 | continue; | |
716 | vxl = &zif->l2info.vxl; | |
717 | ||
718 | if (zif->brslave_info.br_if != br_if) | |
719 | continue; | |
720 | ||
9d277b8c PG |
721 | if (!in_param->bridge_vlan_aware |
722 | || vxl->access_vlan == in_param->vid) { | |
6006414d PR |
723 | found = 1; |
724 | break; | |
725 | } | |
726 | } | |
727 | ||
728 | if (!found) | |
9d277b8c | 729 | return ZNS_WALK_CONTINUE; |
6006414d | 730 | |
8b5fdf2e | 731 | zevpn = zebra_evpn_lookup(vxl->vni); |
9d277b8c PG |
732 | if (p_zevpn) |
733 | *p_zevpn = zevpn; | |
734 | return ZNS_WALK_STOP; | |
735 | } | |
736 | ||
737 | /* | |
738 | * Map SVI and associated bridge to an EVPN. This is invoked upon getting | |
739 | * neighbor notifications, to see if they are of interest. | |
740 | */ | |
741 | zebra_evpn_t *zebra_evpn_from_svi(struct interface *ifp, | |
742 | struct interface *br_if) | |
743 | { | |
744 | struct zebra_l2info_bridge *br; | |
745 | zebra_evpn_t *zevpn = NULL; | |
746 | zebra_evpn_t **p_zevpn; | |
747 | struct zebra_if *zif; | |
748 | struct zevpn_from_svi_param in_param; | |
749 | ||
750 | if (!br_if) | |
751 | return NULL; | |
752 | ||
753 | /* Make sure the linked interface is a bridge. */ | |
754 | if (!IS_ZEBRA_IF_BRIDGE(br_if)) | |
755 | return NULL; | |
756 | ||
757 | /* Determine if bridge is VLAN-aware or not */ | |
758 | zif = br_if->info; | |
759 | assert(zif); | |
760 | br = &zif->l2info.br; | |
761 | in_param.bridge_vlan_aware = br->vlan_aware; | |
762 | in_param.vid = 0; | |
763 | ||
764 | if (in_param.bridge_vlan_aware) { | |
765 | struct zebra_l2info_vlan *vl; | |
766 | ||
767 | if (!IS_ZEBRA_IF_VLAN(ifp)) | |
768 | return NULL; | |
769 | ||
770 | zif = ifp->info; | |
771 | assert(zif); | |
772 | vl = &zif->l2info.vl; | |
773 | in_param.vid = vl->vid; | |
774 | } | |
775 | ||
776 | in_param.br_if = br_if; | |
777 | in_param.zif = zif; | |
778 | p_zevpn = &zevpn; | |
779 | /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ | |
780 | zebra_ns_list_walk(zebra_evpn_from_svi_zns, (void *)&in_param, | |
781 | (void **)p_zevpn); | |
6006414d PR |
782 | return zevpn; |
783 | } | |
784 | ||
6006414d PR |
785 | /* Map to MAC-VLAN interface corresponding to specified SVI interface. |
786 | */ | |
8b5fdf2e PR |
787 | struct interface *zebra_evpn_map_to_macvlan(struct interface *br_if, |
788 | struct interface *svi_if) | |
6006414d PR |
789 | { |
790 | struct zebra_ns *zns; | |
791 | struct route_node *rn; | |
792 | struct interface *tmp_if = NULL; | |
793 | struct zebra_if *zif; | |
794 | int found = 0; | |
795 | ||
796 | /* Defensive check, caller expected to invoke only with valid bridge. */ | |
797 | if (!br_if) | |
798 | return NULL; | |
799 | ||
800 | if (!svi_if) { | |
801 | zlog_debug("svi_if is not passed."); | |
802 | return NULL; | |
803 | } | |
804 | ||
805 | /* Determine if bridge is VLAN-aware or not */ | |
806 | zif = br_if->info; | |
807 | assert(zif); | |
808 | ||
809 | /* Identify corresponding VLAN interface. */ | |
810 | zns = zebra_ns_lookup(NS_DEFAULT); | |
811 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
812 | tmp_if = (struct interface *)rn->info; | |
813 | /* Check oper status of the SVI. */ | |
814 | if (!tmp_if || !if_is_operative(tmp_if)) | |
815 | continue; | |
816 | zif = tmp_if->info; | |
817 | ||
818 | if (!zif || zif->zif_type != ZEBRA_IF_MACVLAN) | |
819 | continue; | |
820 | ||
821 | if (zif->link == svi_if) { | |
822 | found = 1; | |
823 | break; | |
824 | } | |
825 | } | |
826 | ||
827 | return found ? tmp_if : NULL; | |
828 | } | |
829 | ||
830 | /* | |
831 | * Install MAC hash entry - called upon access VLAN change. | |
832 | */ | |
8b5fdf2e | 833 | void zebra_evpn_install_mac_hash(struct hash_bucket *bucket, void *ctxt) |
6006414d PR |
834 | { |
835 | zebra_mac_t *mac; | |
836 | struct mac_walk_ctx *wctx = ctxt; | |
837 | ||
838 | mac = (zebra_mac_t *)bucket->data; | |
839 | ||
840 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) | |
841 | zebra_evpn_rem_mac_install(wctx->zevpn, mac, false); | |
842 | } | |
843 | ||
844 | /* | |
845 | * Read and populate local MACs and neighbors corresponding to this EVPN. | |
846 | */ | |
8b5fdf2e | 847 | void zebra_evpn_read_mac_neigh(zebra_evpn_t *zevpn, struct interface *ifp) |
6006414d PR |
848 | { |
849 | struct zebra_ns *zns; | |
850 | struct zebra_if *zif; | |
851 | struct interface *vlan_if; | |
852 | struct zebra_l2info_vxlan *vxl; | |
853 | struct interface *vrr_if; | |
854 | ||
855 | zif = ifp->info; | |
856 | vxl = &zif->l2info.vxl; | |
857 | zns = zebra_ns_lookup(NS_DEFAULT); | |
858 | ||
859 | if (IS_ZEBRA_DEBUG_VXLAN) | |
860 | zlog_debug( | |
861 | "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u", | |
862 | ifp->name, ifp->ifindex, zevpn->vni, | |
863 | zif->brslave_info.bridge_ifindex); | |
864 | ||
865 | macfdb_read_for_bridge(zns, ifp, zif->brslave_info.br_if); | |
866 | vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); | |
867 | if (vlan_if) { | |
868 | ||
869 | /* Add SVI MAC-IP */ | |
8b5fdf2e | 870 | zebra_evpn_add_macip_for_intf(vlan_if, zevpn); |
6006414d PR |
871 | |
872 | /* Add VRR MAC-IP - if any*/ | |
873 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
874 | if (vrr_if) | |
8b5fdf2e | 875 | zebra_evpn_add_macip_for_intf(vrr_if, zevpn); |
6006414d PR |
876 | |
877 | neigh_read_for_vlan(zns, vlan_if); | |
878 | } | |
879 | } | |
880 | ||
881 | /* | |
8b5fdf2e | 882 | * Hash function for EVPN. |
6006414d | 883 | */ |
8b5fdf2e | 884 | unsigned int zebra_evpn_hash_keymake(const void *p) |
6006414d PR |
885 | { |
886 | const zebra_evpn_t *zevpn = p; | |
887 | ||
888 | return (jhash_1word(zevpn->vni, 0)); | |
889 | } | |
890 | ||
891 | /* | |
8b5fdf2e | 892 | * Compare 2 evpn hash entries. |
6006414d | 893 | */ |
8b5fdf2e | 894 | bool zebra_evpn_hash_cmp(const void *p1, const void *p2) |
6006414d PR |
895 | { |
896 | const zebra_evpn_t *zevpn1 = p1; | |
897 | const zebra_evpn_t *zevpn2 = p2; | |
898 | ||
899 | return (zevpn1->vni == zevpn2->vni); | |
900 | } | |
901 | ||
8b5fdf2e | 902 | int zebra_evpn_list_cmp(void *p1, void *p2) |
6006414d PR |
903 | { |
904 | const zebra_evpn_t *zevpn1 = p1; | |
905 | const zebra_evpn_t *zevpn2 = p2; | |
906 | ||
907 | if (zevpn1->vni == zevpn2->vni) | |
908 | return 0; | |
909 | return (zevpn1->vni < zevpn2->vni) ? -1 : 1; | |
910 | } | |
911 | ||
912 | /* | |
913 | * Callback to allocate VNI hash entry. | |
914 | */ | |
8b5fdf2e | 915 | void *zebra_evpn_alloc(void *p) |
6006414d PR |
916 | { |
917 | const zebra_evpn_t *tmp_vni = p; | |
918 | zebra_evpn_t *zevpn; | |
919 | ||
920 | zevpn = XCALLOC(MTYPE_ZEVPN, sizeof(zebra_evpn_t)); | |
921 | zevpn->vni = tmp_vni->vni; | |
922 | return ((void *)zevpn); | |
923 | } | |
924 | ||
925 | /* | |
926 | * Look up EVPN hash entry. | |
927 | */ | |
8b5fdf2e | 928 | zebra_evpn_t *zebra_evpn_lookup(vni_t vni) |
6006414d PR |
929 | { |
930 | struct zebra_vrf *zvrf; | |
931 | zebra_evpn_t tmp_vni; | |
932 | zebra_evpn_t *zevpn = NULL; | |
933 | ||
934 | zvrf = zebra_vrf_get_evpn(); | |
935 | assert(zvrf); | |
936 | memset(&tmp_vni, 0, sizeof(zebra_evpn_t)); | |
937 | tmp_vni.vni = vni; | |
938 | zevpn = hash_lookup(zvrf->evpn_table, &tmp_vni); | |
939 | ||
940 | return zevpn; | |
941 | } | |
942 | ||
943 | /* | |
944 | * Add EVPN hash entry. | |
945 | */ | |
8b5fdf2e | 946 | zebra_evpn_t *zebra_evpn_add(vni_t vni) |
6006414d PR |
947 | { |
948 | struct zebra_vrf *zvrf; | |
949 | zebra_evpn_t tmp_zevpn; | |
950 | zebra_evpn_t *zevpn = NULL; | |
951 | ||
952 | zvrf = zebra_vrf_get_evpn(); | |
953 | assert(zvrf); | |
954 | memset(&tmp_zevpn, 0, sizeof(zebra_evpn_t)); | |
955 | tmp_zevpn.vni = vni; | |
8b5fdf2e | 956 | zevpn = hash_get(zvrf->evpn_table, &tmp_zevpn, zebra_evpn_alloc); |
6006414d PR |
957 | assert(zevpn); |
958 | ||
959 | zebra_evpn_evpn_es_init(zevpn); | |
960 | ||
961 | /* Create hash table for MAC */ | |
962 | zevpn->mac_table = zebra_mac_db_create("Zebra EVPN MAC Table"); | |
963 | ||
964 | /* Create hash table for neighbors */ | |
965 | zevpn->neigh_table = zebra_neigh_db_create("Zebra EVPN Neighbor Table"); | |
966 | ||
967 | return zevpn; | |
968 | } | |
969 | ||
6006414d PR |
970 | /* |
971 | * Delete EVPN hash entry. | |
972 | */ | |
8b5fdf2e | 973 | int zebra_evpn_del(zebra_evpn_t *zevpn) |
6006414d PR |
974 | { |
975 | struct zebra_vrf *zvrf; | |
976 | zebra_evpn_t *tmp_zevpn; | |
977 | ||
978 | zvrf = zebra_vrf_get_evpn(); | |
979 | assert(zvrf); | |
980 | ||
6006414d PR |
981 | /* Free the neighbor hash table. */ |
982 | hash_free(zevpn->neigh_table); | |
983 | zevpn->neigh_table = NULL; | |
984 | ||
985 | /* Free the MAC hash table. */ | |
986 | hash_free(zevpn->mac_table); | |
987 | zevpn->mac_table = NULL; | |
988 | ||
989 | zebra_evpn_evpn_es_cleanup(zevpn); | |
990 | ||
991 | /* Free the EVPN hash entry and allocated memory. */ | |
992 | tmp_zevpn = hash_release(zvrf->evpn_table, zevpn); | |
993 | XFREE(MTYPE_ZEVPN, tmp_zevpn); | |
994 | ||
995 | return 0; | |
996 | } | |
997 | ||
998 | /* | |
999 | * Inform BGP about local EVPN addition. | |
1000 | */ | |
8b5fdf2e | 1001 | int zebra_evpn_send_add_to_client(zebra_evpn_t *zevpn) |
6006414d PR |
1002 | { |
1003 | struct zserv *client; | |
1004 | struct stream *s; | |
1005 | int rc; | |
1006 | ||
1007 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
1008 | /* BGP may not be running. */ | |
1009 | if (!client) | |
1010 | return 0; | |
1011 | ||
1012 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
1013 | ||
1014 | zclient_create_header(s, ZEBRA_VNI_ADD, zebra_vrf_get_evpn_id()); | |
1015 | stream_putl(s, zevpn->vni); | |
1016 | stream_put_in_addr(s, &zevpn->local_vtep_ip); | |
1017 | stream_put(s, &zevpn->vrf_id, sizeof(vrf_id_t)); /* tenant vrf */ | |
1018 | stream_put_in_addr(s, &zevpn->mcast_grp); | |
1019 | ||
1020 | /* Write packet size. */ | |
1021 | stream_putw_at(s, 0, stream_get_endp(s)); | |
1022 | ||
1023 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1024 | zlog_debug("Send EVPN_ADD %u %s tenant vrf %s to %s", zevpn->vni, | |
1025 | inet_ntoa(zevpn->local_vtep_ip), | |
1026 | vrf_id_to_name(zevpn->vrf_id), | |
1027 | zebra_route_string(client->proto)); | |
1028 | ||
1029 | client->vniadd_cnt++; | |
1030 | rc = zserv_send_message(client, s); | |
1031 | ||
1032 | if (!(zevpn->flags & ZEVPN_READY_FOR_BGP)) { | |
1033 | zevpn->flags |= ZEVPN_READY_FOR_BGP; | |
1034 | /* once the EVPN is sent the ES-EVIs can also be replayed | |
1035 | * to BGP | |
1036 | */ | |
1037 | zebra_evpn_update_all_es(zevpn); | |
1038 | } | |
1039 | return rc; | |
1040 | } | |
1041 | ||
1042 | /* | |
1043 | * Inform BGP about local EVPN deletion. | |
1044 | */ | |
8b5fdf2e | 1045 | int zebra_evpn_send_del_to_client(zebra_evpn_t *zevpn) |
6006414d PR |
1046 | { |
1047 | struct zserv *client; | |
1048 | struct stream *s; | |
1049 | ||
1050 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
1051 | /* BGP may not be running. */ | |
1052 | if (!client) | |
1053 | return 0; | |
1054 | ||
1055 | if (zevpn->flags & ZEVPN_READY_FOR_BGP) { | |
1056 | zevpn->flags &= ~ZEVPN_READY_FOR_BGP; | |
1057 | /* the ES-EVIs must be removed from BGP before the EVPN is */ | |
1058 | zebra_evpn_update_all_es(zevpn); | |
1059 | } | |
1060 | ||
1061 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
1062 | stream_reset(s); | |
1063 | ||
1064 | zclient_create_header(s, ZEBRA_VNI_DEL, zebra_vrf_get_evpn_id()); | |
1065 | stream_putl(s, zevpn->vni); | |
1066 | ||
1067 | /* Write packet size. */ | |
1068 | stream_putw_at(s, 0, stream_get_endp(s)); | |
1069 | ||
1070 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1071 | zlog_debug("Send EVPN_DEL %u to %s", zevpn->vni, | |
1072 | zebra_route_string(client->proto)); | |
1073 | ||
1074 | client->vnidel_cnt++; | |
1075 | return zserv_send_message(client, s); | |
1076 | } | |
1077 | ||
6006414d PR |
1078 | /* |
1079 | * See if remote VTEP matches with prefix. | |
1080 | */ | |
8b5fdf2e | 1081 | static int zebra_evpn_vtep_match(struct in_addr *vtep_ip, zebra_vtep_t *zvtep) |
6006414d PR |
1082 | { |
1083 | return (IPV4_ADDR_SAME(vtep_ip, &zvtep->vtep_ip)); | |
1084 | } | |
1085 | ||
1086 | /* | |
1087 | * Locate remote VTEP in EVPN hash table. | |
1088 | */ | |
8b5fdf2e | 1089 | zebra_vtep_t *zebra_evpn_vtep_find(zebra_evpn_t *zevpn, struct in_addr *vtep_ip) |
6006414d PR |
1090 | { |
1091 | zebra_vtep_t *zvtep; | |
1092 | ||
1093 | if (!zevpn) | |
1094 | return NULL; | |
1095 | ||
1096 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
8b5fdf2e | 1097 | if (zebra_evpn_vtep_match(vtep_ip, zvtep)) |
6006414d PR |
1098 | break; |
1099 | } | |
1100 | ||
1101 | return zvtep; | |
1102 | } | |
1103 | ||
1104 | /* | |
1105 | * Add remote VTEP to EVPN hash table. | |
1106 | */ | |
8b5fdf2e PR |
1107 | zebra_vtep_t *zebra_evpn_vtep_add(zebra_evpn_t *zevpn, struct in_addr *vtep_ip, |
1108 | int flood_control) | |
6006414d PR |
1109 | |
1110 | { | |
1111 | zebra_vtep_t *zvtep; | |
1112 | ||
1113 | zvtep = XCALLOC(MTYPE_ZEVPN_VTEP, sizeof(zebra_vtep_t)); | |
1114 | ||
1115 | zvtep->vtep_ip = *vtep_ip; | |
1116 | zvtep->flood_control = flood_control; | |
1117 | ||
1118 | if (zevpn->vteps) | |
1119 | zevpn->vteps->prev = zvtep; | |
1120 | zvtep->next = zevpn->vteps; | |
1121 | zevpn->vteps = zvtep; | |
1122 | ||
1123 | return zvtep; | |
1124 | } | |
1125 | ||
1126 | /* | |
1127 | * Remove remote VTEP from EVPN hash table. | |
1128 | */ | |
8b5fdf2e | 1129 | int zebra_evpn_vtep_del(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep) |
6006414d PR |
1130 | { |
1131 | if (zvtep->next) | |
1132 | zvtep->next->prev = zvtep->prev; | |
1133 | if (zvtep->prev) | |
1134 | zvtep->prev->next = zvtep->next; | |
1135 | else | |
1136 | zevpn->vteps = zvtep->next; | |
1137 | ||
1138 | zvtep->prev = zvtep->next = NULL; | |
1139 | XFREE(MTYPE_ZEVPN_VTEP, zvtep); | |
1140 | ||
1141 | return 0; | |
1142 | } | |
1143 | ||
1144 | /* | |
1145 | * Delete all remote VTEPs for this EVPN (upon VNI delete). Also | |
1146 | * uninstall from kernel if asked to. | |
1147 | */ | |
8b5fdf2e | 1148 | int zebra_evpn_vtep_del_all(zebra_evpn_t *zevpn, int uninstall) |
6006414d PR |
1149 | { |
1150 | zebra_vtep_t *zvtep, *zvtep_next; | |
1151 | ||
1152 | if (!zevpn) | |
1153 | return -1; | |
1154 | ||
1155 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep_next) { | |
1156 | zvtep_next = zvtep->next; | |
1157 | if (uninstall) | |
8b5fdf2e PR |
1158 | zebra_evpn_vtep_uninstall(zevpn, &zvtep->vtep_ip); |
1159 | zebra_evpn_vtep_del(zevpn, zvtep); | |
6006414d PR |
1160 | } |
1161 | ||
1162 | return 0; | |
1163 | } | |
1164 | ||
1165 | /* | |
1166 | * Install remote VTEP into the kernel if the remote VTEP has asked | |
1167 | * for head-end-replication. | |
1168 | */ | |
8b5fdf2e | 1169 | int zebra_evpn_vtep_install(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep) |
6006414d PR |
1170 | { |
1171 | if (is_vxlan_flooding_head_end() && | |
1172 | (zvtep->flood_control == VXLAN_FLOOD_HEAD_END_REPL)) { | |
1173 | if (ZEBRA_DPLANE_REQUEST_FAILURE == | |
1174 | dplane_vtep_add(zevpn->vxlan_if, | |
1175 | &zvtep->vtep_ip, zevpn->vni)) | |
1176 | return -1; | |
1177 | } | |
1178 | ||
1179 | return 0; | |
1180 | } | |
1181 | ||
1182 | /* | |
1183 | * Uninstall remote VTEP from the kernel. | |
1184 | */ | |
8b5fdf2e | 1185 | int zebra_evpn_vtep_uninstall(zebra_evpn_t *zevpn, struct in_addr *vtep_ip) |
6006414d PR |
1186 | { |
1187 | if (!zevpn->vxlan_if) { | |
1188 | zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf", | |
1189 | zevpn->vni, zevpn); | |
1190 | return -1; | |
1191 | } | |
1192 | ||
1193 | if (ZEBRA_DPLANE_REQUEST_FAILURE == | |
1194 | dplane_vtep_delete(zevpn->vxlan_if, vtep_ip, zevpn->vni)) | |
1195 | return -1; | |
1196 | ||
1197 | return 0; | |
1198 | } | |
1199 | ||
1200 | /* | |
1201 | * Install or uninstall flood entries in the kernel corresponding to | |
1202 | * remote VTEPs. This is invoked upon change to BUM handling. | |
1203 | */ | |
8b5fdf2e PR |
1204 | void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket *bucket, |
1205 | void *zvrf) | |
6006414d PR |
1206 | { |
1207 | zebra_evpn_t *zevpn; | |
1208 | zebra_vtep_t *zvtep; | |
1209 | ||
1210 | zevpn = (zebra_evpn_t *)bucket->data; | |
1211 | if (!zevpn) | |
1212 | return; | |
1213 | ||
1214 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
1215 | if (is_vxlan_flooding_head_end()) | |
8b5fdf2e | 1216 | zebra_evpn_vtep_install(zevpn, zvtep); |
6006414d | 1217 | else |
8b5fdf2e | 1218 | zebra_evpn_vtep_uninstall(zevpn, &zvtep->vtep_ip); |
6006414d PR |
1219 | } |
1220 | } | |
1221 | ||
1222 | /* | |
1223 | * Cleanup EVPN/VTEP and update kernel | |
1224 | */ | |
8b5fdf2e | 1225 | void zebra_evpn_cleanup_all(struct hash_bucket *bucket, void *arg) |
6006414d PR |
1226 | { |
1227 | zebra_evpn_t *zevpn = NULL; | |
6006414d PR |
1228 | |
1229 | zevpn = (zebra_evpn_t *)bucket->data; | |
1230 | ||
6006414d PR |
1231 | /* Free up all neighbors and MACs, if any. */ |
1232 | zebra_evpn_neigh_del_all(zevpn, 1, 0, DEL_ALL_NEIGH); | |
1233 | zebra_evpn_mac_del_all(zevpn, 1, 0, DEL_ALL_MAC); | |
1234 | ||
1235 | /* Free up all remote VTEPs, if any. */ | |
8b5fdf2e | 1236 | zebra_evpn_vtep_del_all(zevpn, 1); |
6006414d PR |
1237 | |
1238 | /* Delete the hash entry. */ | |
8b5fdf2e | 1239 | zebra_evpn_del(zevpn); |
6006414d PR |
1240 | } |
1241 | ||
8b5fdf2e PR |
1242 | static void |
1243 | zebra_evpn_process_sync_macip_add(zebra_evpn_t *zevpn, struct ethaddr *macaddr, | |
1244 | uint16_t ipa_len, struct ipaddr *ipaddr, | |
1245 | uint8_t flags, uint32_t seq, esi_t *esi) | |
6006414d | 1246 | { |
8b5fdf2e PR |
1247 | struct sync_mac_ip_ctx ctx; |
1248 | char macbuf[ETHER_ADDR_STRLEN]; | |
1249 | char ipbuf[INET6_ADDRSTRLEN]; | |
1250 | bool sticky; | |
1251 | bool remote_gw; | |
1252 | zebra_neigh_t *n = NULL; | |
6006414d | 1253 | |
8b5fdf2e PR |
1254 | sticky = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); |
1255 | remote_gw = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW); | |
1256 | /* if sticky or remote-gw ignore updates from the peer */ | |
1257 | if (sticky || remote_gw) { | |
1258 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_NEIGH | |
1259 | || IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
1260 | zlog_debug( | |
1261 | "Ignore sync-macip vni %u mac %s%s%s%s%s", | |
1262 | zevpn->vni, | |
1263 | prefix_mac2str(macaddr, macbuf, sizeof(macbuf)), | |
1264 | ipa_len ? " IP " : "", | |
1265 | ipa_len ? ipaddr2str(ipaddr, ipbuf, | |
1266 | sizeof(ipbuf)) | |
1267 | : "", | |
1268 | sticky ? " sticky" : "", | |
1269 | remote_gw ? " remote_gw" : ""); | |
1270 | return; | |
1271 | } | |
6006414d | 1272 | |
8b5fdf2e PR |
1273 | if (ipa_len) { |
1274 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
1275 | if (n | |
1276 | && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn, n, macaddr, seq)) | |
1277 | return; | |
1278 | } | |
6006414d | 1279 | |
8b5fdf2e PR |
1280 | memset(&ctx, 0, sizeof(ctx)); |
1281 | ctx.mac = zebra_evpn_proc_sync_mac_update( | |
1282 | zevpn, macaddr, ipa_len, ipaddr, flags, seq, esi, &ctx); | |
1283 | if (ctx.ignore_macip || !ctx.mac || !ipa_len) | |
6006414d PR |
1284 | return; |
1285 | ||
8b5fdf2e PR |
1286 | zebra_evpn_proc_sync_neigh_update(zevpn, n, ipa_len, ipaddr, flags, seq, |
1287 | esi, &ctx); | |
6006414d PR |
1288 | } |
1289 | ||
8b5fdf2e PR |
1290 | /************************** remote mac-ip handling **************************/ |
1291 | /* Process a remote MACIP add from BGP. */ | |
1292 | void process_remote_macip_add(vni_t vni, struct ethaddr *macaddr, | |
1293 | uint16_t ipa_len, struct ipaddr *ipaddr, | |
1294 | uint8_t flags, uint32_t seq, | |
1295 | struct in_addr vtep_ip, esi_t *esi) | |
6006414d | 1296 | { |
8b5fdf2e PR |
1297 | zebra_evpn_t *zevpn; |
1298 | zebra_vtep_t *zvtep; | |
1299 | zebra_mac_t *mac = NULL; | |
1300 | struct interface *ifp = NULL; | |
1301 | struct zebra_if *zif = NULL; | |
1302 | struct zebra_vrf *zvrf; | |
6006414d | 1303 | |
8b5fdf2e PR |
1304 | /* Locate EVPN hash entry - expected to exist. */ |
1305 | zevpn = zebra_evpn_lookup(vni); | |
1306 | if (!zevpn) { | |
1307 | zlog_warn("Unknown VNI %u upon remote MACIP ADD", vni); | |
1308 | return; | |
6006414d PR |
1309 | } |
1310 | ||
8b5fdf2e PR |
1311 | ifp = zevpn->vxlan_if; |
1312 | if (ifp) | |
1313 | zif = ifp->info; | |
1314 | if (!ifp || !if_is_operative(ifp) || !zif || !zif->brslave_info.br_if) { | |
1315 | zlog_warn( | |
1316 | "Ignoring remote MACIP ADD VNI %u, invalid interface state or info", | |
1317 | vni); | |
1318 | return; | |
1319 | } | |
6006414d | 1320 | |
8b5fdf2e PR |
1321 | /* Type-2 routes from another PE can be interpreted as remote or |
1322 | * SYNC based on the destination ES - | |
1323 | * SYNC - if ES is local | |
1324 | * REMOTE - if ES is not local | |
1325 | */ | |
1326 | if (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) { | |
1327 | zebra_evpn_process_sync_macip_add(zevpn, macaddr, ipa_len, | |
1328 | ipaddr, flags, seq, esi); | |
1329 | return; | |
1330 | } | |
6006414d | 1331 | |
8b5fdf2e PR |
1332 | /* The remote VTEP specified should normally exist, but it is |
1333 | * possible that when peering comes up, peer may advertise MACIP | |
1334 | * routes before advertising type-3 routes. | |
1335 | */ | |
1336 | if (vtep_ip.s_addr) { | |
1337 | zvtep = zebra_evpn_vtep_find(zevpn, &vtep_ip); | |
1338 | if (!zvtep) { | |
1339 | zvtep = zebra_evpn_vtep_add(zevpn, &vtep_ip, | |
1340 | VXLAN_FLOOD_DISABLED); | |
1341 | if (!zvtep) { | |
1342 | flog_err( | |
1343 | EC_ZEBRA_VTEP_ADD_FAILED, | |
1344 | "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD", | |
1345 | vni, zevpn); | |
1346 | return; | |
1347 | } | |
6006414d | 1348 | |
8b5fdf2e PR |
1349 | zebra_evpn_vtep_install(zevpn, zvtep); |
1350 | } | |
6006414d PR |
1351 | } |
1352 | ||
8b5fdf2e | 1353 | zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id); |
6006414d PR |
1354 | if (!zvrf) |
1355 | return; | |
6006414d | 1356 | |
6006414d | 1357 | |
8b5fdf2e PR |
1358 | if (process_mac_remote_macip_add(zevpn, zvrf, macaddr, ipa_len, ipaddr, |
1359 | &mac, vtep_ip, flags, seq, esi) | |
1360 | != 0) | |
6006414d | 1361 | return; |
6006414d | 1362 | |
8b5fdf2e PR |
1363 | process_neigh_remote_macip_add(zevpn, zvrf, ipaddr, mac, vtep_ip, flags, |
1364 | seq); | |
6006414d PR |
1365 | } |
1366 | ||
8b5fdf2e PR |
1367 | /* Process a remote MACIP delete from BGP. */ |
1368 | void process_remote_macip_del(vni_t vni, struct ethaddr *macaddr, | |
1369 | uint16_t ipa_len, struct ipaddr *ipaddr, | |
1370 | struct in_addr vtep_ip) | |
6006414d | 1371 | { |
8b5fdf2e PR |
1372 | zebra_evpn_t *zevpn; |
1373 | zebra_mac_t *mac = NULL; | |
1374 | zebra_neigh_t *n = NULL; | |
1375 | struct interface *ifp = NULL; | |
1376 | struct zebra_if *zif = NULL; | |
1377 | struct zebra_ns *zns; | |
1378 | struct zebra_l2info_vxlan *vxl; | |
6006414d | 1379 | struct zebra_vrf *zvrf; |
8b5fdf2e PR |
1380 | char buf[ETHER_ADDR_STRLEN]; |
1381 | char buf1[INET6_ADDRSTRLEN]; | |
6006414d | 1382 | |
8b5fdf2e PR |
1383 | /* Locate EVPN hash entry - expected to exist. */ |
1384 | zevpn = zebra_evpn_lookup(vni); | |
1385 | if (!zevpn) { | |
1386 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1387 | zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni); | |
6006414d | 1388 | return; |
6006414d PR |
1389 | } |
1390 | ||
8b5fdf2e PR |
1391 | ifp = zevpn->vxlan_if; |
1392 | if (ifp) | |
1393 | zif = ifp->info; | |
1394 | if (!ifp || !if_is_operative(ifp) || !zif || !zif->brslave_info.br_if) { | |
1395 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1396 | zlog_debug( | |
1397 | "Ignoring remote MACIP DEL VNI %u, invalid interface state or info", | |
1398 | vni); | |
6006414d | 1399 | return; |
8b5fdf2e PR |
1400 | } |
1401 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1402 | vxl = &zif->l2info.vxl; | |
6006414d | 1403 | |
8b5fdf2e PR |
1404 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); |
1405 | if (ipa_len) | |
1406 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
6006414d | 1407 | |
8b5fdf2e PR |
1408 | if (n && !mac) { |
1409 | zlog_warn( | |
1410 | "Failed to locate MAC %s for neigh %s VNI %u upon remote MACIP DEL", | |
1411 | prefix_mac2str(macaddr, buf, sizeof(buf)), | |
1412 | ipaddr2str(ipaddr, buf1, sizeof(buf1)), vni); | |
6006414d | 1413 | return; |
8b5fdf2e | 1414 | } |
6006414d | 1415 | |
8b5fdf2e PR |
1416 | /* If the remote mac or neighbor doesn't exist there is nothing |
1417 | * more to do. Otherwise, uninstall the entry and then remove it. | |
1418 | */ | |
1419 | if (!mac && !n) | |
6006414d PR |
1420 | return; |
1421 | ||
8b5fdf2e | 1422 | zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id); |
6006414d | 1423 | |
8b5fdf2e PR |
1424 | /* Ignore the delete if this mac is a gateway mac-ip */ |
1425 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) | |
1426 | && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) { | |
1427 | zlog_warn( | |
1428 | "Ignore remote MACIP DEL VNI %u MAC %s%s%s as MAC is already configured as gateway MAC", | |
1429 | vni, prefix_mac2str(macaddr, buf, sizeof(buf)), | |
1430 | ipa_len ? " IP " : "", | |
1431 | ipa_len ? ipaddr2str(ipaddr, buf1, sizeof(buf1)) : ""); | |
6006414d | 1432 | return; |
8b5fdf2e | 1433 | } |
6006414d | 1434 | |
8b5fdf2e PR |
1435 | /* Uninstall remote neighbor or MAC. */ |
1436 | if (n) | |
1437 | zebra_evpn_neigh_remote_uninstall(zevpn, zvrf, n, mac, ipaddr); | |
1438 | else { | |
1439 | /* DAD: when MAC is freeze state as remote learn event, | |
1440 | * remote mac-ip delete event is received will result in freeze | |
1441 | * entry removal, first fetch kernel for the same entry present | |
1442 | * as LOCAL and reachable, avoid deleting this entry instead | |
1443 | * use kerenel local entry to update during unfreeze time. | |
1444 | */ | |
1445 | if (zvrf->dad_freeze | |
1446 | && CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE) | |
1447 | && CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
1448 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1449 | zlog_debug( | |
1450 | "%s: MAC %s (flags 0x%x) is remote and duplicate, read kernel for local entry", | |
1451 | __func__, | |
1452 | prefix_mac2str(macaddr, buf, | |
1453 | sizeof(buf)), | |
1454 | mac->flags); | |
1455 | macfdb_read_specific_mac(zns, zif->brslave_info.br_if, | |
1456 | macaddr, vxl->access_vlan); | |
1457 | } | |
6006414d | 1458 | |
8b5fdf2e PR |
1459 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { |
1460 | if (!ipa_len) | |
1461 | zebra_evpn_sync_mac_del(mac); | |
1462 | } else if (CHECK_FLAG(mac->flags, ZEBRA_NEIGH_REMOTE)) { | |
1463 | zebra_evpn_rem_mac_del(zevpn, mac); | |
1464 | } | |
6006414d | 1465 | } |
6006414d PR |
1466 | } |
1467 | ||
1468 | /************************** EVPN BGP config management ************************/ | |
8b5fdf2e | 1469 | void zebra_evpn_cfg_cleanup(struct hash_bucket *bucket, void *ctxt) |
6006414d PR |
1470 | { |
1471 | zebra_evpn_t *zevpn = NULL; | |
1472 | ||
1473 | zevpn = (zebra_evpn_t *)bucket->data; | |
1474 | zevpn->advertise_gw_macip = 0; | |
1475 | zevpn->advertise_svi_macip = 0; | |
1476 | zevpn->advertise_subnet = 0; | |
1477 | ||
1478 | zebra_evpn_neigh_del_all(zevpn, 1, 0, | |
1479 | DEL_REMOTE_NEIGH | DEL_REMOTE_NEIGH_FROM_VTEP); | |
1480 | zebra_evpn_mac_del_all(zevpn, 1, 0, | |
1481 | DEL_REMOTE_MAC | DEL_REMOTE_MAC_FROM_VTEP); | |
8b5fdf2e | 1482 | zebra_evpn_vtep_del_all(zevpn, 1); |
6006414d | 1483 | } |