]>
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 | */ | |
22 | ||
23 | #include <zebra.h> | |
24 | ||
25 | #include "hash.h" | |
26 | #include "if.h" | |
27 | #include "jhash.h" | |
28 | #include "linklist.h" | |
29 | #include "log.h" | |
30 | #include "memory.h" | |
31 | #include "prefix.h" | |
32 | #include "stream.h" | |
33 | #include "table.h" | |
34 | #include "vlan.h" | |
35 | #include "vxlan.h" | |
36 | #ifdef GNU_LINUX | |
37 | #include <linux/neighbour.h> | |
38 | #endif | |
39 | ||
40 | #include "zebra/zebra_router.h" | |
41 | #include "zebra/debug.h" | |
42 | #include "zebra/interface.h" | |
43 | #include "zebra/rib.h" | |
44 | #include "zebra/rt.h" | |
45 | #include "zebra/rt_netlink.h" | |
46 | #include "zebra/zebra_errors.h" | |
47 | #include "zebra/zebra_l2.h" | |
48 | #include "zebra/zebra_memory.h" | |
49 | #include "zebra/zebra_ns.h" | |
50 | #include "zebra/zebra_vrf.h" | |
51 | #include "zebra/zebra_vxlan.h" | |
52 | #include "zebra/zebra_evpn.h" | |
53 | #include "zebra/zebra_evpn_mac.h" | |
54 | #include "zebra/zebra_evpn_neigh.h" | |
55 | #include "zebra/zebra_vxlan_private.h" | |
56 | #include "zebra/zebra_evpn_mh.h" | |
57 | #include "zebra/zebra_router.h" | |
58 | ||
59 | DEFINE_MTYPE_STATIC(ZEBRA, HOST_PREFIX, "host prefix"); | |
60 | DEFINE_MTYPE_STATIC(ZEBRA, ZEVPN, "EVPN hash"); | |
61 | DEFINE_MTYPE_STATIC(ZEBRA, ZL3VNI, "L3 VNI hash"); | |
62 | DEFINE_MTYPE_STATIC(ZEBRA, ZEVPN_VTEP, "EVPN remote VTEP/PTUN"); | |
63 | DEFINE_MTYPE_STATIC(ZEBRA, L3VNI_MAC, "EVPN L3VNI MAC"); | |
64 | DEFINE_MTYPE_STATIC(ZEBRA, L3NEIGH, "EVPN Neighbor"); | |
65 | DEFINE_MTYPE_STATIC(ZEBRA, ZVXLAN_SG, "zebra VxLAN multicast group"); | |
66 | ||
67 | DEFINE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni, | |
68 | bool delete, const char *reason), (rmac, zl3vni, delete, reason)) | |
69 | ||
70 | /* definitions */ | |
71 | /* PMSI strings. */ | |
72 | #define VXLAN_FLOOD_STR_NO_INFO "-" | |
73 | #define VXLAN_FLOOD_STR_DEFAULT VXLAN_FLOOD_STR_NO_INFO | |
74 | static const struct message zvtep_flood_str[] = { | |
75 | {VXLAN_FLOOD_DISABLED, VXLAN_FLOOD_STR_NO_INFO}, | |
76 | {VXLAN_FLOOD_PIM_SM, "PIM-SM"}, | |
77 | {VXLAN_FLOOD_HEAD_END_REPL, "HER"}, | |
78 | {0} | |
79 | }; | |
80 | ||
81 | /* static function declarations */ | |
82 | static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, | |
83 | uint16_t cmd); | |
84 | static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket *bucket, | |
85 | void **args); | |
86 | static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty, | |
87 | json_object *json); | |
88 | static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty, | |
89 | json_object *json); | |
90 | static void zevpn_print_mac_hash_all_evpn(struct hash_bucket *bucket, void *ctxt); | |
91 | static void zevpn_print(zebra_evpn_t *zevpn, void **ctxt); | |
92 | static void zevpn_print_hash(struct hash_bucket *bucket, void *ctxt[]); | |
93 | ||
94 | static zebra_evpn_t *zevpn_from_svi(struct interface *ifp, | |
95 | struct interface *br_if); | |
96 | static struct interface *zevpn_map_to_macvlan(struct interface *br_if, | |
97 | struct interface *svi_if); | |
98 | ||
99 | /* l3-vni next-hop neigh related APIs */ | |
100 | static zebra_neigh_t *zl3vni_nh_lookup(zebra_l3vni_t *zl3vni, | |
101 | const struct ipaddr *ip); | |
102 | static void *zl3vni_nh_alloc(void *p); | |
103 | static zebra_neigh_t *zl3vni_nh_add(zebra_l3vni_t *zl3vni, | |
104 | const struct ipaddr *vtep_ip, | |
105 | const struct ethaddr *rmac); | |
106 | static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *n); | |
107 | static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, zebra_neigh_t *n); | |
108 | static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, zebra_neigh_t *n); | |
109 | ||
110 | /* l3-vni rmac related APIs */ | |
111 | static void zl3vni_print_rmac_hash(struct hash_bucket *, void *); | |
112 | static zebra_mac_t *zl3vni_rmac_lookup(zebra_l3vni_t *zl3vni, | |
113 | const struct ethaddr *rmac); | |
114 | static void *zl3vni_rmac_alloc(void *p); | |
115 | static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, | |
116 | const struct ethaddr *rmac); | |
117 | static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); | |
118 | static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); | |
119 | static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac); | |
120 | ||
121 | /* l3-vni related APIs*/ | |
122 | static zebra_l3vni_t *zl3vni_lookup(vni_t vni); | |
123 | static void *zl3vni_alloc(void *p); | |
124 | static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id); | |
125 | static int zl3vni_del(zebra_l3vni_t *zl3vni); | |
126 | static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t *zl3vni); | |
127 | static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t *zl3vni); | |
128 | ||
129 | static zebra_evpn_t *zevpn_map_vlan(struct interface *ifp, | |
130 | struct interface *br_if, vlanid_t vid); | |
131 | static void zevpn_install_mac_hash(struct hash_bucket *bucket, void *ctxt); | |
132 | ||
133 | static unsigned int evpn_hash_keymake(const void *p); | |
134 | static void *zevpn_alloc(void *p); | |
135 | static zebra_evpn_t *zevpn_add(vni_t vni); | |
136 | static int zevpn_del(zebra_evpn_t *zevpn); | |
137 | static int zevpn_send_add_to_client(zebra_evpn_t *zevpn); | |
138 | static int zevpn_send_del_to_client(zebra_evpn_t *zevpn); | |
139 | static void zevpn_build_hash_table(void); | |
140 | static int zevpn_vtep_match(struct in_addr *vtep_ip, zebra_vtep_t *zvtep); | |
141 | static zebra_vtep_t *zevpn_vtep_find(zebra_evpn_t *zevpn, struct in_addr *vtep_ip); | |
142 | static zebra_vtep_t *zevpn_vtep_add(zebra_evpn_t *zevpn, struct in_addr *vtep_ip, | |
143 | int flood_control); | |
144 | static int zevpn_vtep_del(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep); | |
145 | static int zevpn_vtep_del_all(zebra_evpn_t *zevpn, int uninstall); | |
146 | static int zevpn_vtep_install(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep); | |
147 | static int zevpn_vtep_uninstall(zebra_evpn_t *zevpn, struct in_addr *vtep_ip); | |
148 | static int zevpn_del_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn); | |
149 | static int zevpn_add_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn); | |
150 | static int zevpn_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, | |
151 | struct ethaddr *macaddr, struct ipaddr *ip); | |
152 | static int zevpn_gw_macip_del(struct interface *ifp, zebra_evpn_t *zevpn, | |
153 | struct ipaddr *ip); | |
154 | struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp); | |
155 | static unsigned int zebra_vxlan_sg_hash_key_make(const void *p); | |
156 | static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2); | |
157 | static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf, | |
158 | struct in_addr sip, struct in_addr mcast_grp); | |
159 | static zebra_vxlan_sg_t *zebra_vxlan_sg_do_ref(struct zebra_vrf *vrf, | |
160 | struct in_addr sip, struct in_addr mcast_grp); | |
161 | static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, | |
162 | struct in_addr mcast_grp); | |
163 | static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, | |
164 | struct in_addr mcast_grp); | |
165 | static void zebra_vxlan_sg_cleanup(struct hash_bucket *bucket, void *arg); | |
166 | ||
167 | /* Private functions */ | |
168 | static int host_rb_entry_compare(const struct host_rb_entry *hle1, | |
169 | const struct host_rb_entry *hle2) | |
170 | { | |
171 | if (hle1->p.family < hle2->p.family) | |
172 | return -1; | |
173 | ||
174 | if (hle1->p.family > hle2->p.family) | |
175 | return 1; | |
176 | ||
177 | if (hle1->p.prefixlen < hle2->p.prefixlen) | |
178 | return -1; | |
179 | ||
180 | if (hle1->p.prefixlen > hle2->p.prefixlen) | |
181 | return 1; | |
182 | ||
183 | if (hle1->p.family == AF_INET) { | |
184 | if (hle1->p.u.prefix4.s_addr < hle2->p.u.prefix4.s_addr) | |
185 | return -1; | |
186 | ||
187 | if (hle1->p.u.prefix4.s_addr > hle2->p.u.prefix4.s_addr) | |
188 | return 1; | |
189 | ||
190 | return 0; | |
191 | } else if (hle1->p.family == AF_INET6) { | |
192 | return memcmp(&hle1->p.u.prefix6, &hle2->p.u.prefix6, | |
193 | IPV6_MAX_BYTELEN); | |
194 | } else { | |
195 | zlog_debug("%s: Unexpected family type: %d", __func__, | |
196 | hle1->p.family); | |
197 | return 0; | |
198 | } | |
199 | } | |
200 | RB_GENERATE(host_rb_tree_entry, host_rb_entry, hl_entry, host_rb_entry_compare); | |
201 | ||
202 | static uint32_t rb_host_count(struct host_rb_tree_entry *hrbe) | |
203 | { | |
204 | struct host_rb_entry *hle; | |
205 | uint32_t count = 0; | |
206 | ||
207 | RB_FOREACH (hle, host_rb_tree_entry, hrbe) | |
208 | count++; | |
209 | ||
210 | return count; | |
211 | } | |
212 | ||
213 | int advertise_gw_macip_enabled(zebra_evpn_t *zevpn) | |
214 | { | |
215 | struct zebra_vrf *zvrf; | |
216 | ||
217 | zvrf = zebra_vrf_get_evpn(); | |
218 | if (zvrf && zvrf->advertise_gw_macip) | |
219 | return 1; | |
220 | ||
221 | if (zevpn && zevpn->advertise_gw_macip) | |
222 | return 1; | |
223 | ||
224 | return 0; | |
225 | } | |
226 | ||
227 | int advertise_svi_macip_enabled(zebra_evpn_t *zevpn) | |
228 | { | |
229 | struct zebra_vrf *zvrf; | |
230 | ||
231 | zvrf = zebra_vrf_get_evpn(); | |
232 | if (zvrf && zvrf->advertise_svi_macip) | |
233 | return 1; | |
234 | ||
235 | if (zevpn && zevpn->advertise_svi_macip) | |
236 | return 1; | |
237 | ||
238 | return 0; | |
239 | } | |
240 | ||
241 | /* | |
242 | * Print neighbors for all EVPN. | |
243 | */ | |
244 | static void zevpn_print_neigh_hash_all_evpn(struct hash_bucket *bucket, | |
245 | void **args) | |
246 | { | |
247 | struct vty *vty; | |
248 | json_object *json = NULL, *json_evpn = NULL; | |
249 | zebra_evpn_t *zevpn; | |
250 | uint32_t num_neigh; | |
251 | struct neigh_walk_ctx wctx; | |
252 | char vni_str[VNI_STR_LEN]; | |
253 | uint32_t print_dup; | |
254 | ||
255 | vty = (struct vty *)args[0]; | |
256 | json = (json_object *)args[1]; | |
257 | print_dup = (uint32_t)(uintptr_t)args[2]; | |
258 | ||
259 | zevpn = (zebra_evpn_t *)bucket->data; | |
260 | ||
261 | num_neigh = hashcount(zevpn->neigh_table); | |
262 | ||
263 | if (print_dup) | |
264 | num_neigh = num_dup_detected_neighs(zevpn); | |
265 | ||
266 | if (json == NULL) { | |
267 | vty_out(vty, | |
268 | "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n", | |
269 | zevpn->vni, num_neigh); | |
270 | } else { | |
271 | json_evpn = json_object_new_object(); | |
272 | json_object_int_add(json_evpn, "numArpNd", num_neigh); | |
273 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
274 | } | |
275 | ||
276 | if (!num_neigh) { | |
277 | if (json) | |
278 | json_object_object_add(json, vni_str, json_evpn); | |
279 | return; | |
280 | } | |
281 | ||
282 | /* Since we have IPv6 addresses to deal with which can vary widely in | |
283 | * size, we try to be a bit more elegant in display by first computing | |
284 | * the maximum width. | |
285 | */ | |
286 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); | |
287 | wctx.zevpn = zevpn; | |
288 | wctx.vty = vty; | |
289 | wctx.addr_width = 15; | |
290 | wctx.json = json_evpn; | |
291 | hash_iterate(zevpn->neigh_table, zebra_evpn_find_neigh_addr_width, | |
292 | &wctx); | |
293 | ||
294 | if (json == NULL) | |
295 | zebra_evpn_print_neigh_hdr(vty, &wctx); | |
296 | ||
297 | if (print_dup) | |
298 | hash_iterate(zevpn->neigh_table, | |
299 | zebra_evpn_print_dad_neigh_hash, &wctx); | |
300 | else | |
301 | hash_iterate(zevpn->neigh_table, zebra_evpn_print_neigh_hash, | |
302 | &wctx); | |
303 | ||
304 | if (json) | |
305 | json_object_object_add(json, vni_str, json_evpn); | |
306 | } | |
307 | ||
308 | /* | |
309 | * Print neighbors for all EVPNs in detail. | |
310 | */ | |
311 | static void zevpn_print_neigh_hash_all_evpn_detail(struct hash_bucket *bucket, | |
312 | void **args) | |
313 | { | |
314 | struct vty *vty; | |
315 | json_object *json = NULL, *json_evpn = NULL; | |
316 | zebra_evpn_t *zevpn; | |
317 | uint32_t num_neigh; | |
318 | struct neigh_walk_ctx wctx; | |
319 | char vni_str[VNI_STR_LEN]; | |
320 | uint32_t print_dup; | |
321 | ||
322 | vty = (struct vty *)args[0]; | |
323 | json = (json_object *)args[1]; | |
324 | print_dup = (uint32_t)(uintptr_t)args[2]; | |
325 | ||
326 | zevpn = (zebra_evpn_t *)bucket->data; | |
327 | if (!zevpn) { | |
328 | if (json) | |
329 | vty_out(vty, "{}\n"); | |
330 | return; | |
331 | } | |
332 | num_neigh = hashcount(zevpn->neigh_table); | |
333 | ||
334 | if (print_dup && num_dup_detected_neighs(zevpn) == 0) | |
335 | return; | |
336 | ||
337 | if (json == NULL) { | |
338 | vty_out(vty, | |
339 | "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n", | |
340 | zevpn->vni, num_neigh); | |
341 | } else { | |
342 | json_evpn = json_object_new_object(); | |
343 | json_object_int_add(json_evpn, "numArpNd", num_neigh); | |
344 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
345 | } | |
346 | if (!num_neigh) { | |
347 | if (json) | |
348 | json_object_object_add(json, vni_str, json_evpn); | |
349 | return; | |
350 | } | |
351 | ||
352 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); | |
353 | wctx.zevpn = zevpn; | |
354 | wctx.vty = vty; | |
355 | wctx.addr_width = 15; | |
356 | wctx.json = json_evpn; | |
357 | ||
358 | if (print_dup) | |
359 | hash_iterate(zevpn->neigh_table, | |
360 | zebra_evpn_print_dad_neigh_hash_detail, &wctx); | |
361 | else | |
362 | hash_iterate(zevpn->neigh_table, | |
363 | zebra_evpn_print_neigh_hash_detail, &wctx); | |
364 | ||
365 | if (json) | |
366 | json_object_object_add(json, vni_str, json_evpn); | |
367 | } | |
368 | ||
369 | /* print a specific next hop for an l3vni */ | |
370 | static void zl3vni_print_nh(zebra_neigh_t *n, struct vty *vty, | |
371 | json_object *json) | |
372 | { | |
373 | char buf1[ETHER_ADDR_STRLEN]; | |
374 | char buf2[INET6_ADDRSTRLEN]; | |
375 | json_object *json_hosts = NULL; | |
376 | struct host_rb_entry *hle; | |
377 | ||
378 | if (!json) { | |
379 | vty_out(vty, "Ip: %s\n", | |
380 | ipaddr2str(&n->ip, buf2, sizeof(buf2))); | |
381 | vty_out(vty, " RMAC: %s\n", | |
382 | prefix_mac2str(&n->emac, buf1, sizeof(buf1))); | |
383 | vty_out(vty, " Refcount: %d\n", | |
384 | rb_host_count(&n->host_rb)); | |
385 | vty_out(vty, " Prefixes:\n"); | |
386 | RB_FOREACH (hle, host_rb_tree_entry, &n->host_rb) | |
387 | vty_out(vty, " %s\n", | |
388 | prefix2str(&hle->p, buf2, sizeof(buf2))); | |
389 | } else { | |
390 | json_hosts = json_object_new_array(); | |
391 | json_object_string_add( | |
392 | json, "ip", ipaddr2str(&(n->ip), buf2, sizeof(buf2))); | |
393 | json_object_string_add( | |
394 | json, "routerMac", | |
395 | prefix_mac2str(&n->emac, buf2, sizeof(buf2))); | |
396 | json_object_int_add(json, "refCount", | |
397 | rb_host_count(&n->host_rb)); | |
398 | RB_FOREACH (hle, host_rb_tree_entry, &n->host_rb) | |
399 | json_object_array_add(json_hosts, | |
400 | json_object_new_string(prefix2str( | |
401 | &hle->p, buf2, sizeof(buf2)))); | |
402 | json_object_object_add(json, "prefixList", json_hosts); | |
403 | } | |
404 | } | |
405 | ||
406 | /* Print a specific RMAC entry */ | |
407 | static void zl3vni_print_rmac(zebra_mac_t *zrmac, struct vty *vty, | |
408 | json_object *json) | |
409 | { | |
410 | char buf1[ETHER_ADDR_STRLEN]; | |
411 | char buf2[PREFIX_STRLEN]; | |
412 | json_object *json_hosts = NULL; | |
413 | struct host_rb_entry *hle; | |
414 | ||
415 | if (!json) { | |
416 | vty_out(vty, "MAC: %s\n", | |
417 | prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); | |
418 | vty_out(vty, " Remote VTEP: %s\n", | |
419 | inet_ntoa(zrmac->fwd_info.r_vtep_ip)); | |
420 | vty_out(vty, " Refcount: %d\n", rb_host_count(&zrmac->host_rb)); | |
421 | vty_out(vty, " Prefixes:\n"); | |
422 | RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) | |
423 | vty_out(vty, " %s\n", | |
424 | prefix2str(&hle->p, buf2, sizeof(buf2))); | |
425 | } else { | |
426 | json_hosts = json_object_new_array(); | |
427 | json_object_string_add( | |
428 | json, "routerMac", | |
429 | prefix_mac2str(&zrmac->macaddr, buf1, sizeof(buf1))); | |
430 | json_object_string_add(json, "vtepIp", | |
431 | inet_ntoa(zrmac->fwd_info.r_vtep_ip)); | |
432 | json_object_int_add(json, "refCount", | |
433 | rb_host_count(&zrmac->host_rb)); | |
434 | json_object_int_add(json, "localSequence", zrmac->loc_seq); | |
435 | json_object_int_add(json, "remoteSequence", zrmac->rem_seq); | |
436 | RB_FOREACH (hle, host_rb_tree_entry, &zrmac->host_rb) | |
437 | json_object_array_add( | |
438 | json_hosts, | |
439 | json_object_new_string(prefix2str( | |
440 | &hle->p, buf2, sizeof(buf2)))); | |
441 | json_object_object_add(json, "prefixList", json_hosts); | |
442 | } | |
443 | } | |
444 | ||
445 | /* | |
446 | * Print MACs for all EVPNs. | |
447 | */ | |
448 | static void zevpn_print_mac_hash_all_evpn(struct hash_bucket *bucket, void *ctxt) | |
449 | { | |
450 | struct vty *vty; | |
451 | json_object *json = NULL, *json_evpn = NULL; | |
452 | json_object *json_mac = NULL; | |
453 | zebra_evpn_t *zevpn; | |
454 | uint32_t num_macs; | |
455 | struct mac_walk_ctx *wctx = ctxt; | |
456 | char vni_str[VNI_STR_LEN]; | |
457 | ||
458 | vty = wctx->vty; | |
459 | json = wctx->json; | |
460 | ||
461 | zevpn = (zebra_evpn_t *)bucket->data; | |
462 | wctx->zevpn = zevpn; | |
463 | ||
464 | /*We are iterating over a new VNI, set the count to 0*/ | |
465 | wctx->count = 0; | |
466 | ||
467 | num_macs = num_valid_macs(zevpn); | |
468 | if (!num_macs) | |
469 | return; | |
470 | ||
471 | if (wctx->print_dup) | |
472 | num_macs = num_dup_detected_macs(zevpn); | |
473 | ||
474 | if (json) { | |
475 | json_evpn = json_object_new_object(); | |
476 | json_mac = json_object_new_object(); | |
477 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
478 | } | |
479 | ||
480 | if (!CHECK_FLAG(wctx->flags, SHOW_REMOTE_MAC_FROM_VTEP)) { | |
481 | if (json == NULL) { | |
482 | vty_out(vty, "\nVNI %u #MACs (local and remote) %u\n\n", | |
483 | zevpn->vni, num_macs); | |
484 | vty_out(vty, | |
485 | "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n"); | |
486 | vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC", | |
487 | "Type", "Flags", "Intf/Remote ES/VTEP", | |
488 | "VLAN", "Seq #'s"); | |
489 | } else | |
490 | json_object_int_add(json_evpn, "numMacs", num_macs); | |
491 | } | |
492 | ||
493 | if (!num_macs) { | |
494 | if (json) { | |
495 | json_object_int_add(json_evpn, "numMacs", num_macs); | |
496 | json_object_object_add(json, vni_str, json_evpn); | |
497 | } | |
498 | return; | |
499 | } | |
500 | ||
501 | /* assign per-evpn to wctx->json object to fill macs | |
502 | * under the evpn. Re-assign primary json object to fill | |
503 | * next evpn information. | |
504 | */ | |
505 | wctx->json = json_mac; | |
506 | if (wctx->print_dup) | |
507 | hash_iterate(zevpn->mac_table, zebra_evpn_print_dad_mac_hash, | |
508 | wctx); | |
509 | else | |
510 | hash_iterate(zevpn->mac_table, zebra_evpn_print_mac_hash, wctx); | |
511 | wctx->json = json; | |
512 | if (json) { | |
513 | if (wctx->count) | |
514 | json_object_object_add(json_evpn, "macs", json_mac); | |
515 | json_object_object_add(json, vni_str, json_evpn); | |
516 | } | |
517 | } | |
518 | ||
519 | /* | |
520 | * Print MACs in detail for all EVPNs. | |
521 | */ | |
522 | static void zevpn_print_mac_hash_all_evpn_detail(struct hash_bucket *bucket, | |
523 | void *ctxt) | |
524 | { | |
525 | struct vty *vty; | |
526 | json_object *json = NULL, *json_evpn = NULL; | |
527 | json_object *json_mac = NULL; | |
528 | zebra_evpn_t *zevpn; | |
529 | uint32_t num_macs; | |
530 | struct mac_walk_ctx *wctx = ctxt; | |
531 | char vni_str[VNI_STR_LEN]; | |
532 | ||
533 | vty = wctx->vty; | |
534 | json = wctx->json; | |
535 | ||
536 | zevpn = (zebra_evpn_t *)bucket->data; | |
537 | if (!zevpn) { | |
538 | if (json) | |
539 | vty_out(vty, "{}\n"); | |
540 | return; | |
541 | } | |
542 | wctx->zevpn = zevpn; | |
543 | ||
544 | /*We are iterating over a new EVPN, set the count to 0*/ | |
545 | wctx->count = 0; | |
546 | ||
547 | num_macs = num_valid_macs(zevpn); | |
548 | if (!num_macs) | |
549 | return; | |
550 | ||
551 | if (wctx->print_dup && (num_dup_detected_macs(zevpn) == 0)) | |
552 | return; | |
553 | ||
554 | if (json) { | |
555 | json_evpn = json_object_new_object(); | |
556 | json_mac = json_object_new_object(); | |
557 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
558 | } | |
559 | ||
560 | if (!CHECK_FLAG(wctx->flags, SHOW_REMOTE_MAC_FROM_VTEP)) { | |
561 | if (json == NULL) { | |
562 | vty_out(vty, "\nVNI %u #MACs (local and remote) %u\n\n", | |
563 | zevpn->vni, num_macs); | |
564 | } else | |
565 | json_object_int_add(json_evpn, "numMacs", num_macs); | |
566 | } | |
567 | /* assign per-evpn to wctx->json object to fill macs | |
568 | * under the evpn. Re-assign primary json object to fill | |
569 | * next evpn information. | |
570 | */ | |
571 | wctx->json = json_mac; | |
572 | if (wctx->print_dup) | |
573 | hash_iterate(zevpn->mac_table, | |
574 | zebra_evpn_print_dad_mac_hash_detail, wctx); | |
575 | else | |
576 | hash_iterate(zevpn->mac_table, zebra_evpn_print_mac_hash_detail, | |
577 | wctx); | |
578 | wctx->json = json; | |
579 | if (json) { | |
580 | if (wctx->count) | |
581 | json_object_object_add(json_evpn, "macs", json_mac); | |
582 | json_object_object_add(json, vni_str, json_evpn); | |
583 | } | |
584 | } | |
585 | ||
586 | static void zl3vni_print_nh_hash(struct hash_bucket *bucket, void *ctx) | |
587 | { | |
588 | struct nh_walk_ctx *wctx = NULL; | |
589 | struct vty *vty = NULL; | |
590 | struct json_object *json_evpn = NULL; | |
591 | struct json_object *json_nh = NULL; | |
592 | zebra_neigh_t *n = NULL; | |
593 | char buf1[ETHER_ADDR_STRLEN]; | |
594 | char buf2[INET6_ADDRSTRLEN]; | |
595 | ||
596 | wctx = (struct nh_walk_ctx *)ctx; | |
597 | vty = wctx->vty; | |
598 | json_evpn = wctx->json; | |
599 | if (json_evpn) | |
600 | json_nh = json_object_new_object(); | |
601 | n = (zebra_neigh_t *)bucket->data; | |
602 | ||
603 | if (!json_evpn) { | |
604 | vty_out(vty, "%-15s %-17s\n", | |
605 | ipaddr2str(&(n->ip), buf2, sizeof(buf2)), | |
606 | prefix_mac2str(&n->emac, buf1, sizeof(buf1))); | |
607 | } else { | |
608 | json_object_string_add(json_nh, "nexthopIp", | |
609 | ipaddr2str(&n->ip, buf2, sizeof(buf2))); | |
610 | json_object_string_add( | |
611 | json_nh, "routerMac", | |
612 | prefix_mac2str(&n->emac, buf1, sizeof(buf1))); | |
613 | json_object_object_add(json_evpn, | |
614 | ipaddr2str(&(n->ip), buf2, sizeof(buf2)), | |
615 | json_nh); | |
616 | } | |
617 | } | |
618 | ||
619 | static void zl3vni_print_nh_hash_all_vni(struct hash_bucket *bucket, | |
620 | void **args) | |
621 | { | |
622 | struct vty *vty = NULL; | |
623 | json_object *json = NULL; | |
624 | json_object *json_evpn = NULL; | |
625 | zebra_l3vni_t *zl3vni = NULL; | |
626 | uint32_t num_nh = 0; | |
627 | struct nh_walk_ctx wctx; | |
628 | char vni_str[VNI_STR_LEN]; | |
629 | ||
630 | vty = (struct vty *)args[0]; | |
631 | json = (struct json_object *)args[1]; | |
632 | ||
633 | zl3vni = (zebra_l3vni_t *)bucket->data; | |
634 | ||
635 | num_nh = hashcount(zl3vni->nh_table); | |
636 | if (!num_nh) | |
637 | return; | |
638 | ||
639 | if (json) { | |
640 | json_evpn = json_object_new_object(); | |
641 | snprintf(vni_str, VNI_STR_LEN, "%u", zl3vni->vni); | |
642 | } | |
643 | ||
644 | if (json == NULL) { | |
645 | vty_out(vty, "\nVNI %u #Next-Hops %u\n\n", zl3vni->vni, num_nh); | |
646 | vty_out(vty, "%-15s %-17s\n", "IP", "RMAC"); | |
647 | } else | |
648 | json_object_int_add(json_evpn, "numNextHops", num_nh); | |
649 | ||
650 | memset(&wctx, 0, sizeof(struct nh_walk_ctx)); | |
651 | wctx.vty = vty; | |
652 | wctx.json = json_evpn; | |
653 | hash_iterate(zl3vni->nh_table, zl3vni_print_nh_hash, &wctx); | |
654 | if (json) | |
655 | json_object_object_add(json, vni_str, json_evpn); | |
656 | } | |
657 | ||
658 | static void zl3vni_print_rmac_hash_all_vni(struct hash_bucket *bucket, | |
659 | void **args) | |
660 | { | |
661 | struct vty *vty = NULL; | |
662 | json_object *json = NULL; | |
663 | json_object *json_evpn = NULL; | |
664 | zebra_l3vni_t *zl3vni = NULL; | |
665 | uint32_t num_rmacs; | |
666 | struct rmac_walk_ctx wctx; | |
667 | char vni_str[VNI_STR_LEN]; | |
668 | ||
669 | vty = (struct vty *)args[0]; | |
670 | json = (struct json_object *)args[1]; | |
671 | ||
672 | zl3vni = (zebra_l3vni_t *)bucket->data; | |
673 | ||
674 | num_rmacs = hashcount(zl3vni->rmac_table); | |
675 | if (!num_rmacs) | |
676 | return; | |
677 | ||
678 | if (json) { | |
679 | json_evpn = json_object_new_object(); | |
680 | snprintf(vni_str, VNI_STR_LEN, "%u", zl3vni->vni); | |
681 | } | |
682 | ||
683 | if (json == NULL) { | |
684 | vty_out(vty, "\nVNI %u #RMACs %u\n\n", zl3vni->vni, num_rmacs); | |
685 | vty_out(vty, "%-17s %-21s\n", "RMAC", "Remote VTEP"); | |
686 | } else | |
687 | json_object_int_add(json_evpn, "numRmacs", num_rmacs); | |
688 | ||
689 | /* assign per-vni to wctx->json object to fill macs | |
690 | * under the vni. Re-assign primary json object to fill | |
691 | * next vni information. | |
692 | */ | |
693 | memset(&wctx, 0, sizeof(struct rmac_walk_ctx)); | |
694 | wctx.vty = vty; | |
695 | wctx.json = json_evpn; | |
696 | hash_iterate(zl3vni->rmac_table, zl3vni_print_rmac_hash, &wctx); | |
697 | if (json) | |
698 | json_object_object_add(json, vni_str, json_evpn); | |
699 | } | |
700 | ||
701 | static void zl3vni_print_rmac_hash(struct hash_bucket *bucket, void *ctx) | |
702 | { | |
703 | zebra_mac_t *zrmac = NULL; | |
704 | struct rmac_walk_ctx *wctx = NULL; | |
705 | struct vty *vty = NULL; | |
706 | struct json_object *json = NULL; | |
707 | struct json_object *json_rmac = NULL; | |
708 | char buf[ETHER_ADDR_STRLEN]; | |
709 | ||
710 | wctx = (struct rmac_walk_ctx *)ctx; | |
711 | vty = wctx->vty; | |
712 | json = wctx->json; | |
713 | if (json) | |
714 | json_rmac = json_object_new_object(); | |
715 | zrmac = (zebra_mac_t *)bucket->data; | |
716 | ||
717 | if (!json) { | |
718 | vty_out(vty, "%-17s %-21s\n", | |
719 | prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), | |
720 | inet_ntoa(zrmac->fwd_info.r_vtep_ip)); | |
721 | } else { | |
722 | json_object_string_add( | |
723 | json_rmac, "routerMac", | |
724 | prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf))); | |
725 | json_object_string_add(json_rmac, "vtepIp", | |
726 | inet_ntoa(zrmac->fwd_info.r_vtep_ip)); | |
727 | json_object_object_add( | |
728 | json, prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)), | |
729 | json_rmac); | |
730 | } | |
731 | } | |
732 | ||
733 | /* print a specific L3 VNI entry */ | |
734 | static void zl3vni_print(zebra_l3vni_t *zl3vni, void **ctx) | |
735 | { | |
736 | char buf[ETHER_ADDR_STRLEN]; | |
737 | struct vty *vty = NULL; | |
738 | json_object *json = NULL; | |
739 | zebra_evpn_t *zevpn = NULL; | |
740 | json_object *json_evpn_list = NULL; | |
741 | struct listnode *node = NULL, *nnode = NULL; | |
742 | ||
743 | vty = ctx[0]; | |
744 | json = ctx[1]; | |
745 | ||
746 | if (!json) { | |
747 | vty_out(vty, "VNI: %u\n", zl3vni->vni); | |
748 | vty_out(vty, " Type: %s\n", "L3"); | |
749 | vty_out(vty, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni)); | |
750 | vty_out(vty, " Local Vtep Ip: %s\n", | |
751 | inet_ntoa(zl3vni->local_vtep_ip)); | |
752 | vty_out(vty, " Vxlan-Intf: %s\n", | |
753 | zl3vni_vxlan_if_name(zl3vni)); | |
754 | vty_out(vty, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni)); | |
755 | vty_out(vty, " State: %s\n", zl3vni_state2str(zl3vni)); | |
756 | vty_out(vty, " VNI Filter: %s\n", | |
757 | CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) | |
758 | ? "prefix-routes-only" | |
759 | : "none"); | |
760 | vty_out(vty, " System MAC: %s\n", | |
761 | zl3vni_sysmac2str(zl3vni, buf, sizeof(buf))); | |
762 | vty_out(vty, " Router MAC: %s\n", | |
763 | zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); | |
764 | vty_out(vty, " L2 VNIs: "); | |
765 | for (ALL_LIST_ELEMENTS(zl3vni->l2vnis, node, nnode, zevpn)) | |
766 | vty_out(vty, "%u ", zevpn->vni); | |
767 | vty_out(vty, "\n"); | |
768 | } else { | |
769 | json_evpn_list = json_object_new_array(); | |
770 | json_object_int_add(json, "vni", zl3vni->vni); | |
771 | json_object_string_add(json, "type", "L3"); | |
772 | json_object_string_add(json, "localVtepIp", | |
773 | inet_ntoa(zl3vni->local_vtep_ip)); | |
774 | json_object_string_add(json, "vxlanIntf", | |
775 | zl3vni_vxlan_if_name(zl3vni)); | |
776 | json_object_string_add(json, "sviIntf", | |
777 | zl3vni_svi_if_name(zl3vni)); | |
778 | json_object_string_add(json, "state", zl3vni_state2str(zl3vni)); | |
779 | json_object_string_add(json, "vrf", zl3vni_vrf_name(zl3vni)); | |
780 | json_object_string_add( | |
781 | json, "sysMac", | |
782 | zl3vni_sysmac2str(zl3vni, buf, sizeof(buf))); | |
783 | json_object_string_add( | |
784 | json, "routerMac", | |
785 | zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); | |
786 | json_object_string_add( | |
787 | json, "vniFilter", | |
788 | CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) | |
789 | ? "prefix-routes-only" | |
790 | : "none"); | |
791 | for (ALL_LIST_ELEMENTS(zl3vni->l2vnis, node, nnode, zevpn)) { | |
792 | json_object_array_add(json_evpn_list, | |
793 | json_object_new_int(zevpn->vni)); | |
794 | } | |
795 | json_object_object_add(json, "l2Vnis", json_evpn_list); | |
796 | } | |
797 | } | |
798 | ||
799 | /* | |
800 | * Print a specific EVPN entry. | |
801 | */ | |
802 | static void zevpn_print(zebra_evpn_t *zevpn, void **ctxt) | |
803 | { | |
804 | struct vty *vty; | |
805 | zebra_vtep_t *zvtep; | |
806 | uint32_t num_macs; | |
807 | uint32_t num_neigh; | |
808 | json_object *json = NULL; | |
809 | json_object *json_vtep_list = NULL; | |
810 | json_object *json_ip_str = NULL; | |
811 | ||
812 | vty = ctxt[0]; | |
813 | json = ctxt[1]; | |
814 | ||
815 | if (json == NULL) { | |
816 | vty_out(vty, "VNI: %u\n", zevpn->vni); | |
817 | vty_out(vty, " Type: %s\n", "L2"); | |
818 | vty_out(vty, " Tenant VRF: %s\n", vrf_id_to_name(zevpn->vrf_id)); | |
819 | } else { | |
820 | json_object_int_add(json, "vni", zevpn->vni); | |
821 | json_object_string_add(json, "type", "L2"); | |
822 | json_object_string_add(json, "vrf", | |
823 | vrf_id_to_name(zevpn->vrf_id)); | |
824 | } | |
825 | ||
826 | if (!zevpn->vxlan_if) { // unexpected | |
827 | if (json == NULL) | |
828 | vty_out(vty, " VxLAN interface: unknown\n"); | |
829 | return; | |
830 | } | |
831 | num_macs = num_valid_macs(zevpn); | |
832 | num_neigh = hashcount(zevpn->neigh_table); | |
833 | if (json == NULL) { | |
834 | vty_out(vty, " VxLAN interface: %s\n", zevpn->vxlan_if->name); | |
835 | vty_out(vty, " VxLAN ifIndex: %u\n", zevpn->vxlan_if->ifindex); | |
836 | vty_out(vty, " Local VTEP IP: %s\n", | |
837 | inet_ntoa(zevpn->local_vtep_ip)); | |
838 | vty_out(vty, " Mcast group: %s\n", | |
839 | inet_ntoa(zevpn->mcast_grp)); | |
840 | } else { | |
841 | json_object_string_add(json, "vxlanInterface", | |
842 | zevpn->vxlan_if->name); | |
843 | json_object_int_add(json, "ifindex", zevpn->vxlan_if->ifindex); | |
844 | json_object_string_add(json, "vtepIp", | |
845 | inet_ntoa(zevpn->local_vtep_ip)); | |
846 | json_object_string_add(json, "mcastGroup", | |
847 | inet_ntoa(zevpn->mcast_grp)); | |
848 | json_object_string_add(json, "advertiseGatewayMacip", | |
849 | zevpn->advertise_gw_macip ? "Yes" : "No"); | |
850 | json_object_int_add(json, "numMacs", num_macs); | |
851 | json_object_int_add(json, "numArpNd", num_neigh); | |
852 | } | |
853 | if (!zevpn->vteps) { | |
854 | if (json == NULL) | |
855 | vty_out(vty, " No remote VTEPs known for this VNI\n"); | |
856 | } else { | |
857 | if (json == NULL) | |
858 | vty_out(vty, " Remote VTEPs for this VNI:\n"); | |
859 | else | |
860 | json_vtep_list = json_object_new_array(); | |
861 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
862 | const char *flood_str = lookup_msg(zvtep_flood_str, | |
863 | zvtep->flood_control, | |
864 | VXLAN_FLOOD_STR_DEFAULT); | |
865 | ||
866 | if (json == NULL) { | |
867 | vty_out(vty, " %s flood: %s\n", | |
868 | inet_ntoa(zvtep->vtep_ip), | |
869 | flood_str); | |
870 | } else { | |
871 | json_ip_str = json_object_new_string( | |
872 | inet_ntoa(zvtep->vtep_ip)); | |
873 | json_object_array_add(json_vtep_list, | |
874 | json_ip_str); | |
875 | } | |
876 | } | |
877 | if (json) | |
878 | json_object_object_add(json, "numRemoteVteps", | |
879 | json_vtep_list); | |
880 | } | |
881 | if (json == NULL) { | |
882 | vty_out(vty, | |
883 | " Number of MACs (local and remote) known for this VNI: %u\n", | |
884 | num_macs); | |
885 | vty_out(vty, | |
886 | " Number of ARPs (IPv4 and IPv6, local and remote) " | |
887 | "known for this VNI: %u\n", | |
888 | num_neigh); | |
889 | vty_out(vty, " Advertise-gw-macip: %s\n", | |
890 | zevpn->advertise_gw_macip ? "Yes" : "No"); | |
891 | } | |
892 | } | |
893 | ||
894 | /* print a L3 VNI hash entry */ | |
895 | static void zl3vni_print_hash(struct hash_bucket *bucket, void *ctx[]) | |
896 | { | |
897 | struct vty *vty = NULL; | |
898 | json_object *json = NULL; | |
899 | json_object *json_evpn = NULL; | |
900 | zebra_l3vni_t *zl3vni = NULL; | |
901 | ||
902 | vty = (struct vty *)ctx[0]; | |
903 | json = (json_object *)ctx[1]; | |
904 | ||
905 | zl3vni = (zebra_l3vni_t *)bucket->data; | |
906 | ||
907 | if (!json) { | |
908 | vty_out(vty, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n", | |
909 | zl3vni->vni, "L3", zl3vni_vxlan_if_name(zl3vni), | |
910 | hashcount(zl3vni->rmac_table), | |
911 | hashcount(zl3vni->nh_table), "n/a", | |
912 | zl3vni_vrf_name(zl3vni)); | |
913 | } else { | |
914 | char vni_str[VNI_STR_LEN]; | |
915 | ||
916 | snprintf(vni_str, VNI_STR_LEN, "%u", zl3vni->vni); | |
917 | json_evpn = json_object_new_object(); | |
918 | json_object_int_add(json_evpn, "vni", zl3vni->vni); | |
919 | json_object_string_add(json_evpn, "vxlanIf", | |
920 | zl3vni_vxlan_if_name(zl3vni)); | |
921 | json_object_int_add(json_evpn, "numMacs", | |
922 | hashcount(zl3vni->rmac_table)); | |
923 | json_object_int_add(json_evpn, "numArpNd", | |
924 | hashcount(zl3vni->nh_table)); | |
925 | json_object_string_add(json_evpn, "numRemoteVteps", "n/a"); | |
926 | json_object_string_add(json_evpn, "type", "L3"); | |
927 | json_object_string_add(json_evpn, "tenantVrf", | |
928 | zl3vni_vrf_name(zl3vni)); | |
929 | json_object_object_add(json, vni_str, json_evpn); | |
930 | } | |
931 | } | |
932 | ||
933 | /* Private Structure to pass callback data for hash iterator */ | |
934 | struct zevpn_show { | |
935 | struct vty *vty; | |
936 | json_object *json; | |
937 | struct zebra_vrf *zvrf; | |
938 | bool use_json; | |
939 | }; | |
940 | ||
941 | /* print a L3 VNI hash entry in detail*/ | |
942 | static void zl3vni_print_hash_detail(struct hash_bucket *bucket, void *data) | |
943 | { | |
944 | struct vty *vty = NULL; | |
945 | zebra_l3vni_t *zl3vni = NULL; | |
946 | json_object *json_array = NULL; | |
947 | bool use_json = false; | |
948 | struct zevpn_show *zes = data; | |
949 | ||
950 | vty = zes->vty; | |
951 | json_array = zes->json; | |
952 | use_json = zes->use_json; | |
953 | ||
954 | zl3vni = (zebra_l3vni_t *)bucket->data; | |
955 | ||
956 | zebra_vxlan_print_vni(vty, zes->zvrf, zl3vni->vni, | |
957 | use_json, json_array); | |
958 | ||
959 | if (!use_json) | |
960 | vty_out(vty, "\n"); | |
961 | } | |
962 | ||
963 | ||
964 | /* | |
965 | * Print an EVPN hash entry - called for display of all VNIs. | |
966 | */ | |
967 | static void zevpn_print_hash(struct hash_bucket *bucket, void *ctxt[]) | |
968 | { | |
969 | struct vty *vty; | |
970 | zebra_evpn_t *zevpn; | |
971 | zebra_vtep_t *zvtep; | |
972 | uint32_t num_vteps = 0; | |
973 | uint32_t num_macs = 0; | |
974 | uint32_t num_neigh = 0; | |
975 | json_object *json = NULL; | |
976 | json_object *json_evpn = NULL; | |
977 | json_object *json_ip_str = NULL; | |
978 | json_object *json_vtep_list = NULL; | |
979 | ||
980 | vty = ctxt[0]; | |
981 | json = ctxt[1]; | |
982 | ||
983 | zevpn = (zebra_evpn_t *)bucket->data; | |
984 | ||
985 | zvtep = zevpn->vteps; | |
986 | while (zvtep) { | |
987 | num_vteps++; | |
988 | zvtep = zvtep->next; | |
989 | } | |
990 | ||
991 | num_macs = num_valid_macs(zevpn); | |
992 | num_neigh = hashcount(zevpn->neigh_table); | |
993 | if (json == NULL) | |
994 | vty_out(vty, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n", | |
995 | zevpn->vni, "L2", | |
996 | zevpn->vxlan_if ? zevpn->vxlan_if->name : "unknown", | |
997 | num_macs, num_neigh, num_vteps, | |
998 | vrf_id_to_name(zevpn->vrf_id)); | |
999 | else { | |
1000 | char vni_str[VNI_STR_LEN]; | |
1001 | snprintf(vni_str, VNI_STR_LEN, "%u", zevpn->vni); | |
1002 | json_evpn = json_object_new_object(); | |
1003 | json_object_int_add(json_evpn, "vni", zevpn->vni); | |
1004 | json_object_string_add(json_evpn, "type", "L2"); | |
1005 | json_object_string_add(json_evpn, "vxlanIf", | |
1006 | zevpn->vxlan_if ? zevpn->vxlan_if->name | |
1007 | : "unknown"); | |
1008 | json_object_int_add(json_evpn, "numMacs", num_macs); | |
1009 | json_object_int_add(json_evpn, "numArpNd", num_neigh); | |
1010 | json_object_int_add(json_evpn, "numRemoteVteps", num_vteps); | |
1011 | json_object_string_add(json_evpn, "tenantVrf", | |
1012 | vrf_id_to_name(zevpn->vrf_id)); | |
1013 | if (num_vteps) { | |
1014 | json_vtep_list = json_object_new_array(); | |
1015 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
1016 | json_ip_str = json_object_new_string( | |
1017 | inet_ntoa(zvtep->vtep_ip)); | |
1018 | json_object_array_add(json_vtep_list, | |
1019 | json_ip_str); | |
1020 | } | |
1021 | json_object_object_add(json_evpn, "remoteVteps", | |
1022 | json_vtep_list); | |
1023 | } | |
1024 | json_object_object_add(json, vni_str, json_evpn); | |
1025 | } | |
1026 | } | |
1027 | ||
1028 | /* | |
1029 | * Print an EVPN hash entry in detail - called for display of all EVPNs. | |
1030 | */ | |
1031 | static void zevpn_print_hash_detail(struct hash_bucket *bucket, void *data) | |
1032 | { | |
1033 | struct vty *vty; | |
1034 | zebra_evpn_t *zevpn; | |
1035 | json_object *json_array = NULL; | |
1036 | bool use_json = false; | |
1037 | struct zevpn_show *zes = data; | |
1038 | ||
1039 | vty = zes->vty; | |
1040 | json_array = zes->json; | |
1041 | use_json = zes->use_json; | |
1042 | ||
1043 | zevpn = (zebra_evpn_t *)bucket->data; | |
1044 | ||
1045 | zebra_vxlan_print_vni(vty, zes->zvrf, zevpn->vni, use_json, json_array); | |
1046 | ||
1047 | if (!use_json) | |
1048 | vty_out(vty, "\n"); | |
1049 | } | |
1050 | ||
1051 | /* Get the VRR interface for SVI if any */ | |
1052 | struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp) | |
1053 | { | |
1054 | struct zebra_vrf *zvrf = NULL; | |
1055 | struct interface *tmp_if = NULL; | |
1056 | struct zebra_if *zif = NULL; | |
1057 | ||
1058 | zvrf = vrf_info_lookup(ifp->vrf_id); | |
1059 | assert(zvrf); | |
1060 | ||
1061 | FOR_ALL_INTERFACES (zvrf->vrf, tmp_if) { | |
1062 | zif = tmp_if->info; | |
1063 | if (!zif) | |
1064 | continue; | |
1065 | ||
1066 | if (!IS_ZEBRA_IF_MACVLAN(tmp_if)) | |
1067 | continue; | |
1068 | ||
1069 | if (zif->link == ifp) | |
1070 | return tmp_if; | |
1071 | } | |
1072 | ||
1073 | return NULL; | |
1074 | } | |
1075 | ||
1076 | static int zevpn_del_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn) | |
1077 | { | |
1078 | struct listnode *cnode = NULL, *cnnode = NULL; | |
1079 | struct connected *c = NULL; | |
1080 | struct ethaddr macaddr; | |
1081 | ||
1082 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
1083 | ||
1084 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
1085 | struct ipaddr ip; | |
1086 | ||
1087 | memset(&ip, 0, sizeof(struct ipaddr)); | |
1088 | if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) | |
1089 | continue; | |
1090 | ||
1091 | if (c->address->family == AF_INET) { | |
1092 | ip.ipa_type = IPADDR_V4; | |
1093 | memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), | |
1094 | sizeof(struct in_addr)); | |
1095 | } else if (c->address->family == AF_INET6) { | |
1096 | ip.ipa_type = IPADDR_V6; | |
1097 | memcpy(&(ip.ipaddr_v6), &(c->address->u.prefix6), | |
1098 | sizeof(struct in6_addr)); | |
1099 | } else { | |
1100 | continue; | |
1101 | } | |
1102 | ||
1103 | zevpn_gw_macip_del(ifp, zevpn, &ip); | |
1104 | } | |
1105 | ||
1106 | return 0; | |
1107 | } | |
1108 | ||
1109 | static int zevpn_add_macip_for_intf(struct interface *ifp, zebra_evpn_t *zevpn) | |
1110 | { | |
1111 | struct listnode *cnode = NULL, *cnnode = NULL; | |
1112 | struct connected *c = NULL; | |
1113 | struct ethaddr macaddr; | |
1114 | ||
1115 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
1116 | ||
1117 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
1118 | struct ipaddr ip; | |
1119 | ||
1120 | memset(&ip, 0, sizeof(struct ipaddr)); | |
1121 | if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL)) | |
1122 | continue; | |
1123 | ||
1124 | if (c->address->family == AF_INET) { | |
1125 | ip.ipa_type = IPADDR_V4; | |
1126 | memcpy(&(ip.ipaddr_v4), &(c->address->u.prefix4), | |
1127 | sizeof(struct in_addr)); | |
1128 | } else if (c->address->family == AF_INET6) { | |
1129 | ip.ipa_type = IPADDR_V6; | |
1130 | memcpy(&(ip.ipaddr_v6), &(c->address->u.prefix6), | |
1131 | sizeof(struct in6_addr)); | |
1132 | } else { | |
1133 | continue; | |
1134 | } | |
1135 | ||
1136 | zevpn_gw_macip_add(ifp, zevpn, &macaddr, &ip); | |
1137 | } | |
1138 | return 0; | |
1139 | } | |
1140 | ||
1141 | ||
1142 | static int zevpn_advertise_subnet(zebra_evpn_t *zevpn, struct interface *ifp, | |
1143 | int advertise) | |
1144 | { | |
1145 | struct listnode *cnode = NULL, *cnnode = NULL; | |
1146 | struct connected *c = NULL; | |
1147 | struct ethaddr macaddr; | |
1148 | ||
1149 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
1150 | ||
1151 | for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) { | |
1152 | struct prefix p; | |
1153 | ||
1154 | memcpy(&p, c->address, sizeof(struct prefix)); | |
1155 | ||
1156 | /* skip link local address */ | |
1157 | if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) | |
1158 | continue; | |
1159 | ||
1160 | apply_mask(&p); | |
1161 | if (advertise) | |
1162 | ip_prefix_send_to_client(ifp->vrf_id, &p, | |
1163 | ZEBRA_IP_PREFIX_ROUTE_ADD); | |
1164 | else | |
1165 | ip_prefix_send_to_client(ifp->vrf_id, &p, | |
1166 | ZEBRA_IP_PREFIX_ROUTE_DEL); | |
1167 | } | |
1168 | return 0; | |
1169 | } | |
1170 | ||
1171 | /* | |
1172 | * zevpn_gw_macip_add_to_client | |
1173 | */ | |
1174 | static int zevpn_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, | |
1175 | struct ethaddr *macaddr, struct ipaddr *ip) | |
1176 | { | |
1177 | zebra_mac_t *mac = NULL; | |
1178 | struct zebra_if *zif = NULL; | |
1179 | struct zebra_l2info_vxlan *vxl = NULL; | |
1180 | ||
1181 | zif = zevpn->vxlan_if->info; | |
1182 | if (!zif) | |
1183 | return -1; | |
1184 | ||
1185 | vxl = &zif->l2info.vxl; | |
1186 | ||
1187 | if (zebra_evpn_mac_gw_macip_add(ifp, zevpn, ip, &mac, macaddr, | |
1188 | vxl->access_vlan) | |
1189 | != 0) | |
1190 | return -1; | |
1191 | ||
1192 | return zebra_evpn_neigh_gw_macip_add(ifp, zevpn, ip, mac); | |
1193 | } | |
1194 | ||
1195 | /* | |
1196 | * zevpn_gw_macip_del_from_client | |
1197 | */ | |
1198 | static int zevpn_gw_macip_del(struct interface *ifp, zebra_evpn_t *zevpn, | |
1199 | struct ipaddr *ip) | |
1200 | { | |
1201 | char buf1[ETHER_ADDR_STRLEN]; | |
1202 | char buf2[INET6_ADDRSTRLEN]; | |
1203 | zebra_neigh_t *n = NULL; | |
1204 | zebra_mac_t *mac = NULL; | |
1205 | ||
1206 | /* If the neigh entry is not present nothing to do*/ | |
1207 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
1208 | if (!n) | |
1209 | return 0; | |
1210 | ||
1211 | /* mac entry should be present */ | |
1212 | mac = zebra_evpn_mac_lookup(zevpn, &n->emac); | |
1213 | if (!mac) { | |
1214 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1215 | zlog_debug("MAC %s doesn't exist for neigh %s on VNI %u", | |
1216 | prefix_mac2str(&n->emac, | |
1217 | buf1, sizeof(buf1)), | |
1218 | ipaddr2str(ip, buf2, sizeof(buf2)), | |
1219 | zevpn->vni); | |
1220 | return -1; | |
1221 | } | |
1222 | ||
1223 | /* If the entry is not local nothing to do*/ | |
1224 | if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) | |
1225 | return -1; | |
1226 | ||
1227 | /* only need to delete the entry from bgp if we sent it before */ | |
1228 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1229 | zlog_debug( | |
1230 | "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", | |
1231 | ifp->vrf_id, ifp->name, ifp->ifindex, zevpn->vni, | |
1232 | prefix_mac2str(&(n->emac), buf1, sizeof(buf1)), | |
1233 | ipaddr2str(ip, buf2, sizeof(buf2))); | |
1234 | ||
1235 | /* Remove neighbor from BGP. */ | |
1236 | zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac, | |
1237 | n->flags, ZEBRA_NEIGH_ACTIVE, | |
1238 | false /*force*/); | |
1239 | ||
1240 | /* Delete this neighbor entry. */ | |
1241 | zebra_evpn_neigh_del(zevpn, n); | |
1242 | ||
1243 | /* see if the mac needs to be deleted as well*/ | |
1244 | if (mac) | |
1245 | zebra_evpn_deref_ip2mac(zevpn, mac); | |
1246 | ||
1247 | return 0; | |
1248 | } | |
1249 | ||
1250 | static void zevpn_gw_macip_del_for_evpn_hash(struct hash_bucket *bucket, | |
1251 | void *ctxt) | |
1252 | { | |
1253 | zebra_evpn_t *zevpn = NULL; | |
1254 | struct zebra_if *zif = NULL; | |
1255 | struct zebra_l2info_vxlan zl2_info; | |
1256 | struct interface *vlan_if = NULL; | |
1257 | struct interface *vrr_if = NULL; | |
1258 | struct interface *ifp; | |
1259 | ||
1260 | /* Add primary SVI MAC*/ | |
1261 | zevpn = (zebra_evpn_t *)bucket->data; | |
1262 | ||
1263 | /* Global (Zvrf) advertise-default-gw is disabled, | |
1264 | * but zevpn advertise-default-gw is enabled | |
1265 | */ | |
1266 | if (zevpn->advertise_gw_macip) { | |
1267 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1268 | zlog_debug("VNI: %u GW-MACIP enabled, retain gw-macip", | |
1269 | zevpn->vni); | |
1270 | return; | |
1271 | } | |
1272 | ||
1273 | ifp = zevpn->vxlan_if; | |
1274 | if (!ifp) | |
1275 | return; | |
1276 | zif = ifp->info; | |
1277 | ||
1278 | /* If down or not mapped to a bridge, we're done. */ | |
1279 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
1280 | return; | |
1281 | ||
1282 | zl2_info = zif->l2info.vxl; | |
1283 | ||
1284 | vlan_if = | |
1285 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
1286 | if (!vlan_if) | |
1287 | return; | |
1288 | ||
1289 | /* Del primary MAC-IP */ | |
1290 | zevpn_del_macip_for_intf(vlan_if, zevpn); | |
1291 | ||
1292 | /* Del VRR MAC-IP - if any*/ | |
1293 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
1294 | if (vrr_if) | |
1295 | zevpn_del_macip_for_intf(vrr_if, zevpn); | |
1296 | ||
1297 | return; | |
1298 | } | |
1299 | ||
1300 | static void zevpn_gw_macip_add_for_evpn_hash(struct hash_bucket *bucket, | |
1301 | void *ctxt) | |
1302 | { | |
1303 | zebra_evpn_t *zevpn = NULL; | |
1304 | struct zebra_if *zif = NULL; | |
1305 | struct zebra_l2info_vxlan zl2_info; | |
1306 | struct interface *vlan_if = NULL; | |
1307 | struct interface *vrr_if = NULL; | |
1308 | struct interface *ifp = NULL; | |
1309 | ||
1310 | zevpn = (zebra_evpn_t *)bucket->data; | |
1311 | ||
1312 | ifp = zevpn->vxlan_if; | |
1313 | if (!ifp) | |
1314 | return; | |
1315 | zif = ifp->info; | |
1316 | ||
1317 | /* If down or not mapped to a bridge, we're done. */ | |
1318 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
1319 | return; | |
1320 | zl2_info = zif->l2info.vxl; | |
1321 | ||
1322 | vlan_if = | |
1323 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
1324 | if (!vlan_if) | |
1325 | return; | |
1326 | ||
1327 | /* Add primary SVI MAC-IP */ | |
1328 | zevpn_add_macip_for_intf(vlan_if, zevpn); | |
1329 | ||
1330 | if (advertise_gw_macip_enabled(zevpn)) { | |
1331 | /* Add VRR MAC-IP - if any*/ | |
1332 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
1333 | if (vrr_if) | |
1334 | zevpn_add_macip_for_intf(vrr_if, zevpn); | |
1335 | } | |
1336 | ||
1337 | return; | |
1338 | } | |
1339 | ||
1340 | static void zevpn_svi_macip_del_for_evpn_hash(struct hash_bucket *bucket, | |
1341 | void *ctxt) | |
1342 | { | |
1343 | zebra_evpn_t *zevpn = NULL; | |
1344 | struct zebra_if *zif = NULL; | |
1345 | struct zebra_l2info_vxlan zl2_info; | |
1346 | struct interface *vlan_if = NULL; | |
1347 | struct interface *ifp; | |
1348 | ||
1349 | /* Add primary SVI MAC*/ | |
1350 | zevpn = (zebra_evpn_t *)bucket->data; | |
1351 | if (!zevpn) | |
1352 | return; | |
1353 | ||
1354 | /* Global(vrf) advertise-svi-ip disabled, but zevpn advertise-svi-ip | |
1355 | * enabled | |
1356 | */ | |
1357 | if (zevpn->advertise_svi_macip) { | |
1358 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1359 | zlog_debug("VNI: %u SVI-MACIP enabled, retain svi-macip", | |
1360 | zevpn->vni); | |
1361 | return; | |
1362 | } | |
1363 | ||
1364 | ifp = zevpn->vxlan_if; | |
1365 | if (!ifp) | |
1366 | return; | |
1367 | zif = ifp->info; | |
1368 | ||
1369 | /* If down or not mapped to a bridge, we're done. */ | |
1370 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
1371 | return; | |
1372 | ||
1373 | zl2_info = zif->l2info.vxl; | |
1374 | ||
1375 | vlan_if = | |
1376 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
1377 | if (!vlan_if) | |
1378 | return; | |
1379 | ||
1380 | /* Del primary MAC-IP */ | |
1381 | zevpn_del_macip_for_intf(vlan_if, zevpn); | |
1382 | ||
1383 | return; | |
1384 | } | |
1385 | ||
1386 | /* | |
1387 | * Map port or (port, VLAN) to an EVPN. This is invoked upon getting MAC | |
1388 | * notifications, to see if they are of interest. | |
1389 | */ | |
1390 | static zebra_evpn_t *zevpn_map_vlan(struct interface *ifp, | |
1391 | struct interface *br_if, vlanid_t vid) | |
1392 | { | |
1393 | struct zebra_ns *zns; | |
1394 | struct route_node *rn; | |
1395 | struct interface *tmp_if = NULL; | |
1396 | struct zebra_if *zif; | |
1397 | struct zebra_l2info_bridge *br; | |
1398 | struct zebra_l2info_vxlan *vxl = NULL; | |
1399 | uint8_t bridge_vlan_aware; | |
1400 | zebra_evpn_t *zevpn; | |
1401 | int found = 0; | |
1402 | ||
1403 | /* Determine if bridge is VLAN-aware or not */ | |
1404 | zif = br_if->info; | |
1405 | assert(zif); | |
1406 | br = &zif->l2info.br; | |
1407 | bridge_vlan_aware = br->vlan_aware; | |
1408 | ||
1409 | /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ | |
1410 | /* TODO: Optimize with a hash. */ | |
1411 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1412 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
1413 | tmp_if = (struct interface *)rn->info; | |
1414 | if (!tmp_if) | |
1415 | continue; | |
1416 | zif = tmp_if->info; | |
1417 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
1418 | continue; | |
1419 | if (!if_is_operative(tmp_if)) | |
1420 | continue; | |
1421 | vxl = &zif->l2info.vxl; | |
1422 | ||
1423 | if (zif->brslave_info.br_if != br_if) | |
1424 | continue; | |
1425 | ||
1426 | if (!bridge_vlan_aware || vxl->access_vlan == vid) { | |
1427 | found = 1; | |
1428 | break; | |
1429 | } | |
1430 | } | |
1431 | ||
1432 | if (!found) | |
1433 | return NULL; | |
1434 | ||
1435 | zevpn = zevpn_lookup(vxl->vni); | |
1436 | return zevpn; | |
1437 | } | |
1438 | ||
1439 | /* | |
1440 | * Map SVI and associated bridge to a VNI. This is invoked upon getting | |
1441 | * neighbor notifications, to see if they are of interest. | |
1442 | */ | |
1443 | static zebra_evpn_t *zevpn_from_svi(struct interface *ifp, | |
1444 | struct interface *br_if) | |
1445 | { | |
1446 | struct zebra_ns *zns; | |
1447 | struct route_node *rn; | |
1448 | struct interface *tmp_if = NULL; | |
1449 | struct zebra_if *zif; | |
1450 | struct zebra_l2info_bridge *br; | |
1451 | struct zebra_l2info_vxlan *vxl = NULL; | |
1452 | uint8_t bridge_vlan_aware; | |
1453 | vlanid_t vid = 0; | |
1454 | zebra_evpn_t *zevpn; | |
1455 | int found = 0; | |
1456 | ||
1457 | if (!br_if) | |
1458 | return NULL; | |
1459 | ||
1460 | /* Make sure the linked interface is a bridge. */ | |
1461 | if (!IS_ZEBRA_IF_BRIDGE(br_if)) | |
1462 | return NULL; | |
1463 | ||
1464 | /* Determine if bridge is VLAN-aware or not */ | |
1465 | zif = br_if->info; | |
1466 | assert(zif); | |
1467 | br = &zif->l2info.br; | |
1468 | bridge_vlan_aware = br->vlan_aware; | |
1469 | if (bridge_vlan_aware) { | |
1470 | struct zebra_l2info_vlan *vl; | |
1471 | ||
1472 | if (!IS_ZEBRA_IF_VLAN(ifp)) | |
1473 | return NULL; | |
1474 | ||
1475 | zif = ifp->info; | |
1476 | assert(zif); | |
1477 | vl = &zif->l2info.vl; | |
1478 | vid = vl->vid; | |
1479 | } | |
1480 | ||
1481 | /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ | |
1482 | /* TODO: Optimize with a hash. */ | |
1483 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1484 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
1485 | tmp_if = (struct interface *)rn->info; | |
1486 | if (!tmp_if) | |
1487 | continue; | |
1488 | zif = tmp_if->info; | |
1489 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
1490 | continue; | |
1491 | if (!if_is_operative(tmp_if)) | |
1492 | continue; | |
1493 | vxl = &zif->l2info.vxl; | |
1494 | ||
1495 | if (zif->brslave_info.br_if != br_if) | |
1496 | continue; | |
1497 | ||
1498 | if (!bridge_vlan_aware || vxl->access_vlan == vid) { | |
1499 | found = 1; | |
1500 | break; | |
1501 | } | |
1502 | } | |
1503 | ||
1504 | if (!found) | |
1505 | return NULL; | |
1506 | ||
1507 | zevpn = zevpn_lookup(vxl->vni); | |
1508 | return zevpn; | |
1509 | } | |
1510 | ||
1511 | /* Map to SVI on bridge corresponding to specified VLAN. This can be one | |
1512 | * of two cases: | |
1513 | * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface | |
1514 | * linked to the bridge | |
1515 | * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge interface | |
1516 | * itself | |
1517 | */ | |
1518 | struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if) | |
1519 | { | |
1520 | struct zebra_ns *zns; | |
1521 | struct route_node *rn; | |
1522 | struct interface *tmp_if = NULL; | |
1523 | struct zebra_if *zif; | |
1524 | struct zebra_l2info_bridge *br; | |
1525 | struct zebra_l2info_vlan *vl; | |
1526 | uint8_t bridge_vlan_aware; | |
1527 | int found = 0; | |
1528 | ||
1529 | /* Defensive check, caller expected to invoke only with valid bridge. */ | |
1530 | if (!br_if) | |
1531 | return NULL; | |
1532 | ||
1533 | /* Determine if bridge is VLAN-aware or not */ | |
1534 | zif = br_if->info; | |
1535 | assert(zif); | |
1536 | br = &zif->l2info.br; | |
1537 | bridge_vlan_aware = br->vlan_aware; | |
1538 | ||
1539 | /* Check oper status of the SVI. */ | |
1540 | if (!bridge_vlan_aware) | |
1541 | return if_is_operative(br_if) ? br_if : NULL; | |
1542 | ||
1543 | /* Identify corresponding VLAN interface. */ | |
1544 | /* TODO: Optimize with a hash. */ | |
1545 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1546 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
1547 | tmp_if = (struct interface *)rn->info; | |
1548 | /* Check oper status of the SVI. */ | |
1549 | if (!tmp_if || !if_is_operative(tmp_if)) | |
1550 | continue; | |
1551 | zif = tmp_if->info; | |
1552 | if (!zif || zif->zif_type != ZEBRA_IF_VLAN | |
1553 | || zif->link != br_if) | |
1554 | continue; | |
1555 | vl = &zif->l2info.vl; | |
1556 | ||
1557 | if (vl->vid == vid) { | |
1558 | found = 1; | |
1559 | break; | |
1560 | } | |
1561 | } | |
1562 | ||
1563 | return found ? tmp_if : NULL; | |
1564 | } | |
1565 | ||
1566 | /* Map to MAC-VLAN interface corresponding to specified SVI interface. | |
1567 | */ | |
1568 | static struct interface *zevpn_map_to_macvlan(struct interface *br_if, | |
1569 | struct interface *svi_if) | |
1570 | { | |
1571 | struct zebra_ns *zns; | |
1572 | struct route_node *rn; | |
1573 | struct interface *tmp_if = NULL; | |
1574 | struct zebra_if *zif; | |
1575 | int found = 0; | |
1576 | ||
1577 | /* Defensive check, caller expected to invoke only with valid bridge. */ | |
1578 | if (!br_if) | |
1579 | return NULL; | |
1580 | ||
1581 | if (!svi_if) { | |
1582 | zlog_debug("svi_if is not passed."); | |
1583 | return NULL; | |
1584 | } | |
1585 | ||
1586 | /* Determine if bridge is VLAN-aware or not */ | |
1587 | zif = br_if->info; | |
1588 | assert(zif); | |
1589 | ||
1590 | /* Identify corresponding VLAN interface. */ | |
1591 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1592 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
1593 | tmp_if = (struct interface *)rn->info; | |
1594 | /* Check oper status of the SVI. */ | |
1595 | if (!tmp_if || !if_is_operative(tmp_if)) | |
1596 | continue; | |
1597 | zif = tmp_if->info; | |
1598 | ||
1599 | if (!zif || zif->zif_type != ZEBRA_IF_MACVLAN) | |
1600 | continue; | |
1601 | ||
1602 | if (zif->link == svi_if) { | |
1603 | found = 1; | |
1604 | break; | |
1605 | } | |
1606 | } | |
1607 | ||
1608 | return found ? tmp_if : NULL; | |
1609 | } | |
1610 | ||
1611 | /* | |
1612 | * Install MAC hash entry - called upon access VLAN change. | |
1613 | */ | |
1614 | static void zevpn_install_mac_hash(struct hash_bucket *bucket, void *ctxt) | |
1615 | { | |
1616 | zebra_mac_t *mac; | |
1617 | struct mac_walk_ctx *wctx = ctxt; | |
1618 | ||
1619 | mac = (zebra_mac_t *)bucket->data; | |
1620 | ||
1621 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) | |
1622 | zebra_evpn_rem_mac_install(wctx->zevpn, mac, false); | |
1623 | } | |
1624 | ||
1625 | /* | |
1626 | * Read and populate local MACs and neighbors corresponding to this EVPN. | |
1627 | */ | |
1628 | static void zevpn_read_mac_neigh(zebra_evpn_t *zevpn, struct interface *ifp) | |
1629 | { | |
1630 | struct zebra_ns *zns; | |
1631 | struct zebra_if *zif; | |
1632 | struct interface *vlan_if; | |
1633 | struct zebra_l2info_vxlan *vxl; | |
1634 | struct interface *vrr_if; | |
1635 | ||
1636 | zif = ifp->info; | |
1637 | vxl = &zif->l2info.vxl; | |
1638 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1639 | ||
1640 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1641 | zlog_debug( | |
1642 | "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u", | |
1643 | ifp->name, ifp->ifindex, zevpn->vni, | |
1644 | zif->brslave_info.bridge_ifindex); | |
1645 | ||
1646 | macfdb_read_for_bridge(zns, ifp, zif->brslave_info.br_if); | |
1647 | vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); | |
1648 | if (vlan_if) { | |
1649 | ||
1650 | /* Add SVI MAC-IP */ | |
1651 | zevpn_add_macip_for_intf(vlan_if, zevpn); | |
1652 | ||
1653 | /* Add VRR MAC-IP - if any*/ | |
1654 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
1655 | if (vrr_if) | |
1656 | zevpn_add_macip_for_intf(vrr_if, zevpn); | |
1657 | ||
1658 | neigh_read_for_vlan(zns, vlan_if); | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | /* | |
1663 | * Hash function for VNI. | |
1664 | */ | |
1665 | static unsigned int evpn_hash_keymake(const void *p) | |
1666 | { | |
1667 | const zebra_evpn_t *zevpn = p; | |
1668 | ||
1669 | return (jhash_1word(zevpn->vni, 0)); | |
1670 | } | |
1671 | ||
1672 | /* | |
1673 | * Compare 2 VNI hash entries. | |
1674 | */ | |
1675 | static bool vni_hash_cmp(const void *p1, const void *p2) | |
1676 | { | |
1677 | const zebra_evpn_t *zevpn1 = p1; | |
1678 | const zebra_evpn_t *zevpn2 = p2; | |
1679 | ||
1680 | return (zevpn1->vni == zevpn2->vni); | |
1681 | } | |
1682 | ||
1683 | int vni_list_cmp(void *p1, void *p2) | |
1684 | { | |
1685 | const zebra_evpn_t *zevpn1 = p1; | |
1686 | const zebra_evpn_t *zevpn2 = p2; | |
1687 | ||
1688 | if (zevpn1->vni == zevpn2->vni) | |
1689 | return 0; | |
1690 | return (zevpn1->vni < zevpn2->vni) ? -1 : 1; | |
1691 | } | |
1692 | ||
1693 | /* | |
1694 | * Callback to allocate VNI hash entry. | |
1695 | */ | |
1696 | static void *zevpn_alloc(void *p) | |
1697 | { | |
1698 | const zebra_evpn_t *tmp_vni = p; | |
1699 | zebra_evpn_t *zevpn; | |
1700 | ||
1701 | zevpn = XCALLOC(MTYPE_ZEVPN, sizeof(zebra_evpn_t)); | |
1702 | zevpn->vni = tmp_vni->vni; | |
1703 | return ((void *)zevpn); | |
1704 | } | |
1705 | ||
1706 | /* | |
1707 | * Look up EVPN hash entry. | |
1708 | */ | |
1709 | zebra_evpn_t *zevpn_lookup(vni_t vni) | |
1710 | { | |
1711 | struct zebra_vrf *zvrf; | |
1712 | zebra_evpn_t tmp_vni; | |
1713 | zebra_evpn_t *zevpn = NULL; | |
1714 | ||
1715 | zvrf = zebra_vrf_get_evpn(); | |
1716 | assert(zvrf); | |
1717 | memset(&tmp_vni, 0, sizeof(zebra_evpn_t)); | |
1718 | tmp_vni.vni = vni; | |
1719 | zevpn = hash_lookup(zvrf->evpn_table, &tmp_vni); | |
1720 | ||
1721 | return zevpn; | |
1722 | } | |
1723 | ||
1724 | /* | |
1725 | * Add EVPN hash entry. | |
1726 | */ | |
1727 | static zebra_evpn_t *zevpn_add(vni_t vni) | |
1728 | { | |
1729 | struct zebra_vrf *zvrf; | |
1730 | zebra_evpn_t tmp_zevpn; | |
1731 | zebra_evpn_t *zevpn = NULL; | |
1732 | ||
1733 | zvrf = zebra_vrf_get_evpn(); | |
1734 | assert(zvrf); | |
1735 | memset(&tmp_zevpn, 0, sizeof(zebra_evpn_t)); | |
1736 | tmp_zevpn.vni = vni; | |
1737 | zevpn = hash_get(zvrf->evpn_table, &tmp_zevpn, zevpn_alloc); | |
1738 | assert(zevpn); | |
1739 | ||
1740 | zebra_evpn_evpn_es_init(zevpn); | |
1741 | ||
1742 | /* Create hash table for MAC */ | |
1743 | zevpn->mac_table = zebra_mac_db_create("Zebra EVPN MAC Table"); | |
1744 | ||
1745 | /* Create hash table for neighbors */ | |
1746 | zevpn->neigh_table = zebra_neigh_db_create("Zebra EVPN Neighbor Table"); | |
1747 | ||
1748 | return zevpn; | |
1749 | } | |
1750 | ||
1751 | /* EVPN<=>vxlan_zif association */ | |
1752 | static void zevpn_vxlan_if_set(zebra_evpn_t *zevpn, struct interface *ifp, | |
1753 | bool set) | |
1754 | { | |
1755 | struct zebra_if *zif; | |
1756 | ||
1757 | if (set) { | |
1758 | if (zevpn->vxlan_if == ifp) | |
1759 | return; | |
1760 | zevpn->vxlan_if = ifp; | |
1761 | } else { | |
1762 | if (!zevpn->vxlan_if) | |
1763 | return; | |
1764 | zevpn->vxlan_if = NULL; | |
1765 | } | |
1766 | ||
1767 | if (ifp) | |
1768 | zif = ifp->info; | |
1769 | else | |
1770 | zif = NULL; | |
1771 | ||
1772 | zebra_evpn_vxl_evpn_set(zif, zevpn, set); | |
1773 | } | |
1774 | ||
1775 | /* | |
1776 | * Delete EVPN hash entry. | |
1777 | */ | |
1778 | static int zevpn_del(zebra_evpn_t *zevpn) | |
1779 | { | |
1780 | struct zebra_vrf *zvrf; | |
1781 | zebra_evpn_t *tmp_zevpn; | |
1782 | ||
1783 | zvrf = zebra_vrf_get_evpn(); | |
1784 | assert(zvrf); | |
1785 | ||
1786 | zevpn_vxlan_if_set(zevpn, zevpn->vxlan_if, false /* set */); | |
1787 | ||
1788 | /* Remove references to the BUM mcast grp */ | |
1789 | zebra_vxlan_sg_deref(zevpn->local_vtep_ip, zevpn->mcast_grp); | |
1790 | ||
1791 | /* Free the neighbor hash table. */ | |
1792 | hash_free(zevpn->neigh_table); | |
1793 | zevpn->neigh_table = NULL; | |
1794 | ||
1795 | /* Free the MAC hash table. */ | |
1796 | hash_free(zevpn->mac_table); | |
1797 | zevpn->mac_table = NULL; | |
1798 | ||
1799 | zebra_evpn_evpn_es_cleanup(zevpn); | |
1800 | ||
1801 | /* Free the EVPN hash entry and allocated memory. */ | |
1802 | tmp_zevpn = hash_release(zvrf->evpn_table, zevpn); | |
1803 | XFREE(MTYPE_ZEVPN, tmp_zevpn); | |
1804 | ||
1805 | return 0; | |
1806 | } | |
1807 | ||
1808 | /* | |
1809 | * Inform BGP about local EVPN addition. | |
1810 | */ | |
1811 | static int zevpn_send_add_to_client(zebra_evpn_t *zevpn) | |
1812 | { | |
1813 | struct zserv *client; | |
1814 | struct stream *s; | |
1815 | int rc; | |
1816 | ||
1817 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
1818 | /* BGP may not be running. */ | |
1819 | if (!client) | |
1820 | return 0; | |
1821 | ||
1822 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
1823 | ||
1824 | zclient_create_header(s, ZEBRA_VNI_ADD, zebra_vrf_get_evpn_id()); | |
1825 | stream_putl(s, zevpn->vni); | |
1826 | stream_put_in_addr(s, &zevpn->local_vtep_ip); | |
1827 | stream_put(s, &zevpn->vrf_id, sizeof(vrf_id_t)); /* tenant vrf */ | |
1828 | stream_put_in_addr(s, &zevpn->mcast_grp); | |
1829 | ||
1830 | /* Write packet size. */ | |
1831 | stream_putw_at(s, 0, stream_get_endp(s)); | |
1832 | ||
1833 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1834 | zlog_debug("Send EVPN_ADD %u %s tenant vrf %s to %s", zevpn->vni, | |
1835 | inet_ntoa(zevpn->local_vtep_ip), | |
1836 | vrf_id_to_name(zevpn->vrf_id), | |
1837 | zebra_route_string(client->proto)); | |
1838 | ||
1839 | client->vniadd_cnt++; | |
1840 | rc = zserv_send_message(client, s); | |
1841 | ||
1842 | if (!(zevpn->flags & ZEVPN_READY_FOR_BGP)) { | |
1843 | zevpn->flags |= ZEVPN_READY_FOR_BGP; | |
1844 | /* once the EVPN is sent the ES-EVIs can also be replayed | |
1845 | * to BGP | |
1846 | */ | |
1847 | zebra_evpn_update_all_es(zevpn); | |
1848 | } | |
1849 | return rc; | |
1850 | } | |
1851 | ||
1852 | /* | |
1853 | * Inform BGP about local EVPN deletion. | |
1854 | */ | |
1855 | static int zevpn_send_del_to_client(zebra_evpn_t *zevpn) | |
1856 | { | |
1857 | struct zserv *client; | |
1858 | struct stream *s; | |
1859 | ||
1860 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
1861 | /* BGP may not be running. */ | |
1862 | if (!client) | |
1863 | return 0; | |
1864 | ||
1865 | if (zevpn->flags & ZEVPN_READY_FOR_BGP) { | |
1866 | zevpn->flags &= ~ZEVPN_READY_FOR_BGP; | |
1867 | /* the ES-EVIs must be removed from BGP before the EVPN is */ | |
1868 | zebra_evpn_update_all_es(zevpn); | |
1869 | } | |
1870 | ||
1871 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
1872 | stream_reset(s); | |
1873 | ||
1874 | zclient_create_header(s, ZEBRA_VNI_DEL, zebra_vrf_get_evpn_id()); | |
1875 | stream_putl(s, zevpn->vni); | |
1876 | ||
1877 | /* Write packet size. */ | |
1878 | stream_putw_at(s, 0, stream_get_endp(s)); | |
1879 | ||
1880 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1881 | zlog_debug("Send EVPN_DEL %u to %s", zevpn->vni, | |
1882 | zebra_route_string(client->proto)); | |
1883 | ||
1884 | client->vnidel_cnt++; | |
1885 | return zserv_send_message(client, s); | |
1886 | } | |
1887 | ||
1888 | /* | |
1889 | * Build the VNI hash table by going over the VxLAN interfaces. This | |
1890 | * is called when EVPN (advertise-all-vni) is enabled. | |
1891 | */ | |
1892 | static void zevpn_build_hash_table(void) | |
1893 | { | |
1894 | struct zebra_ns *zns; | |
1895 | struct route_node *rn; | |
1896 | struct interface *ifp; | |
1897 | ||
1898 | /* Walk VxLAN interfaces and create EVPN hash. */ | |
1899 | zns = zebra_ns_lookup(NS_DEFAULT); | |
1900 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
1901 | vni_t vni; | |
1902 | zebra_evpn_t *zevpn = NULL; | |
1903 | zebra_l3vni_t *zl3vni = NULL; | |
1904 | struct zebra_if *zif; | |
1905 | struct zebra_l2info_vxlan *vxl; | |
1906 | ||
1907 | ifp = (struct interface *)rn->info; | |
1908 | if (!ifp) | |
1909 | continue; | |
1910 | zif = ifp->info; | |
1911 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
1912 | continue; | |
1913 | ||
1914 | vxl = &zif->l2info.vxl; | |
1915 | vni = vxl->vni; | |
1916 | ||
1917 | /* L3-VNI and L2-VNI are handled seperately */ | |
1918 | zl3vni = zl3vni_lookup(vni); | |
1919 | if (zl3vni) { | |
1920 | ||
1921 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1922 | zlog_debug( | |
1923 | "create L3-VNI hash for Intf %s(%u) L3-VNI %u", | |
1924 | ifp->name, ifp->ifindex, vni); | |
1925 | ||
1926 | /* associate with vxlan_if */ | |
1927 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
1928 | zl3vni->vxlan_if = ifp; | |
1929 | ||
1930 | /* | |
1931 | * we need to associate with SVI. | |
1932 | * we can associate with svi-if only after association | |
1933 | * with vxlan-intf is complete | |
1934 | */ | |
1935 | zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); | |
1936 | ||
1937 | /* Associate l3vni to mac-vlan and extract VRR MAC */ | |
1938 | zl3vni->mac_vlan_if = zl3vni_map_to_mac_vlan_if(zl3vni); | |
1939 | ||
1940 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1941 | zlog_debug("create l3vni %u svi_if %s mac_vlan_if %s", | |
1942 | vni, zl3vni->svi_if ? zl3vni->svi_if->name | |
1943 | : "NIL", | |
1944 | zl3vni->mac_vlan_if ? | |
1945 | zl3vni->mac_vlan_if->name : "NIL"); | |
1946 | ||
1947 | if (is_l3vni_oper_up(zl3vni)) | |
1948 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
1949 | ||
1950 | } else { | |
1951 | struct interface *vlan_if = NULL; | |
1952 | ||
1953 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1954 | zlog_debug( | |
1955 | "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %s", | |
1956 | ifp->name, ifp->ifindex, vni, | |
1957 | inet_ntoa(vxl->vtep_ip)); | |
1958 | ||
1959 | /* EVPN hash entry is expected to exist, if the BGP process is killed */ | |
1960 | zevpn = zevpn_lookup(vni); | |
1961 | if (zevpn) { | |
1962 | zlog_debug( | |
1963 | "EVPN hash already present for IF %s(%u) L2-VNI %u", | |
1964 | ifp->name, ifp->ifindex, vni); | |
1965 | ||
1966 | /* | |
1967 | * Inform BGP if intf is up and mapped to | |
1968 | * bridge. | |
1969 | */ | |
1970 | if (if_is_operative(ifp) && | |
1971 | zif->brslave_info.br_if) | |
1972 | zevpn_send_add_to_client(zevpn); | |
1973 | ||
1974 | /* Send Local MAC-entries to client */ | |
1975 | zebra_evpn_send_mac_list_to_client(zevpn); | |
1976 | ||
1977 | /* Send Loval Neighbor entries to client */ | |
1978 | zebra_evpn_send_neigh_to_client(zevpn); | |
1979 | } else { | |
1980 | zevpn = zevpn_add(vni); | |
1981 | if (!zevpn) { | |
1982 | zlog_debug( | |
1983 | "Failed to add EVPN hash, IF %s(%u) L2-VNI %u", | |
1984 | ifp->name, ifp->ifindex, vni); | |
1985 | return; | |
1986 | } | |
1987 | ||
1988 | if (zevpn->local_vtep_ip.s_addr != | |
1989 | vxl->vtep_ip.s_addr || | |
1990 | zevpn->mcast_grp.s_addr != | |
1991 | vxl->mcast_grp.s_addr) { | |
1992 | zebra_vxlan_sg_deref( | |
1993 | zevpn->local_vtep_ip, | |
1994 | zevpn->mcast_grp); | |
1995 | zebra_vxlan_sg_ref(vxl->vtep_ip, | |
1996 | vxl->mcast_grp); | |
1997 | zevpn->local_vtep_ip = vxl->vtep_ip; | |
1998 | zevpn->mcast_grp = vxl->mcast_grp; | |
1999 | /* on local vtep-ip check if ES | |
2000 | * orig-ip needs to be updated | |
2001 | */ | |
2002 | zebra_evpn_es_set_base_evpn(zevpn); | |
2003 | } | |
2004 | zevpn_vxlan_if_set(zevpn, ifp, true /* set */); | |
2005 | vlan_if = zvni_map_to_svi( | |
2006 | vxl->access_vlan, | |
2007 | zif->brslave_info.br_if); | |
2008 | if (vlan_if) { | |
2009 | zevpn->vrf_id = vlan_if->vrf_id; | |
2010 | zl3vni = zl3vni_from_vrf( | |
2011 | vlan_if->vrf_id); | |
2012 | if (zl3vni) | |
2013 | listnode_add_sort( | |
2014 | zl3vni->l2vnis, zevpn); | |
2015 | } | |
2016 | ||
2017 | /* | |
2018 | * Inform BGP if intf is up and mapped to | |
2019 | * bridge. | |
2020 | */ | |
2021 | if (if_is_operative(ifp) && | |
2022 | zif->brslave_info.br_if) | |
2023 | zevpn_send_add_to_client(zevpn); | |
2024 | } | |
2025 | } | |
2026 | } | |
2027 | } | |
2028 | ||
2029 | /* | |
2030 | * See if remote VTEP matches with prefix. | |
2031 | */ | |
2032 | static int zevpn_vtep_match(struct in_addr *vtep_ip, zebra_vtep_t *zvtep) | |
2033 | { | |
2034 | return (IPV4_ADDR_SAME(vtep_ip, &zvtep->vtep_ip)); | |
2035 | } | |
2036 | ||
2037 | /* | |
2038 | * Locate remote VTEP in EVPN hash table. | |
2039 | */ | |
2040 | static zebra_vtep_t *zevpn_vtep_find(zebra_evpn_t *zevpn, struct in_addr *vtep_ip) | |
2041 | { | |
2042 | zebra_vtep_t *zvtep; | |
2043 | ||
2044 | if (!zevpn) | |
2045 | return NULL; | |
2046 | ||
2047 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
2048 | if (zevpn_vtep_match(vtep_ip, zvtep)) | |
2049 | break; | |
2050 | } | |
2051 | ||
2052 | return zvtep; | |
2053 | } | |
2054 | ||
2055 | /* | |
2056 | * Add remote VTEP to EVPN hash table. | |
2057 | */ | |
2058 | static zebra_vtep_t *zevpn_vtep_add(zebra_evpn_t *zevpn, struct in_addr *vtep_ip, | |
2059 | int flood_control) | |
2060 | ||
2061 | { | |
2062 | zebra_vtep_t *zvtep; | |
2063 | ||
2064 | zvtep = XCALLOC(MTYPE_ZEVPN_VTEP, sizeof(zebra_vtep_t)); | |
2065 | ||
2066 | zvtep->vtep_ip = *vtep_ip; | |
2067 | zvtep->flood_control = flood_control; | |
2068 | ||
2069 | if (zevpn->vteps) | |
2070 | zevpn->vteps->prev = zvtep; | |
2071 | zvtep->next = zevpn->vteps; | |
2072 | zevpn->vteps = zvtep; | |
2073 | ||
2074 | return zvtep; | |
2075 | } | |
2076 | ||
2077 | /* | |
2078 | * Remove remote VTEP from EVPN hash table. | |
2079 | */ | |
2080 | static int zevpn_vtep_del(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep) | |
2081 | { | |
2082 | if (zvtep->next) | |
2083 | zvtep->next->prev = zvtep->prev; | |
2084 | if (zvtep->prev) | |
2085 | zvtep->prev->next = zvtep->next; | |
2086 | else | |
2087 | zevpn->vteps = zvtep->next; | |
2088 | ||
2089 | zvtep->prev = zvtep->next = NULL; | |
2090 | XFREE(MTYPE_ZEVPN_VTEP, zvtep); | |
2091 | ||
2092 | return 0; | |
2093 | } | |
2094 | ||
2095 | /* | |
2096 | * Delete all remote VTEPs for this EVPN (upon VNI delete). Also | |
2097 | * uninstall from kernel if asked to. | |
2098 | */ | |
2099 | static int zevpn_vtep_del_all(zebra_evpn_t *zevpn, int uninstall) | |
2100 | { | |
2101 | zebra_vtep_t *zvtep, *zvtep_next; | |
2102 | ||
2103 | if (!zevpn) | |
2104 | return -1; | |
2105 | ||
2106 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep_next) { | |
2107 | zvtep_next = zvtep->next; | |
2108 | if (uninstall) | |
2109 | zevpn_vtep_uninstall(zevpn, &zvtep->vtep_ip); | |
2110 | zevpn_vtep_del(zevpn, zvtep); | |
2111 | } | |
2112 | ||
2113 | return 0; | |
2114 | } | |
2115 | ||
2116 | /* | |
2117 | * Install remote VTEP into the kernel if the remote VTEP has asked | |
2118 | * for head-end-replication. | |
2119 | */ | |
2120 | static int zevpn_vtep_install(zebra_evpn_t *zevpn, zebra_vtep_t *zvtep) | |
2121 | { | |
2122 | if (is_vxlan_flooding_head_end() && | |
2123 | (zvtep->flood_control == VXLAN_FLOOD_HEAD_END_REPL)) { | |
2124 | if (ZEBRA_DPLANE_REQUEST_FAILURE == | |
2125 | dplane_vtep_add(zevpn->vxlan_if, | |
2126 | &zvtep->vtep_ip, zevpn->vni)) | |
2127 | return -1; | |
2128 | } | |
2129 | ||
2130 | return 0; | |
2131 | } | |
2132 | ||
2133 | /* | |
2134 | * Uninstall remote VTEP from the kernel. | |
2135 | */ | |
2136 | static int zevpn_vtep_uninstall(zebra_evpn_t *zevpn, struct in_addr *vtep_ip) | |
2137 | { | |
2138 | if (!zevpn->vxlan_if) { | |
2139 | zlog_debug("VNI %u hash %p couldn't be uninstalled - no intf", | |
2140 | zevpn->vni, zevpn); | |
2141 | return -1; | |
2142 | } | |
2143 | ||
2144 | if (ZEBRA_DPLANE_REQUEST_FAILURE == | |
2145 | dplane_vtep_delete(zevpn->vxlan_if, vtep_ip, zevpn->vni)) | |
2146 | return -1; | |
2147 | ||
2148 | return 0; | |
2149 | } | |
2150 | ||
2151 | /* | |
2152 | * Install or uninstall flood entries in the kernel corresponding to | |
2153 | * remote VTEPs. This is invoked upon change to BUM handling. | |
2154 | */ | |
2155 | static void zevpn_handle_flooding_remote_vteps(struct hash_bucket *bucket, | |
2156 | void *zvrf) | |
2157 | { | |
2158 | zebra_evpn_t *zevpn; | |
2159 | zebra_vtep_t *zvtep; | |
2160 | ||
2161 | zevpn = (zebra_evpn_t *)bucket->data; | |
2162 | if (!zevpn) | |
2163 | return; | |
2164 | ||
2165 | for (zvtep = zevpn->vteps; zvtep; zvtep = zvtep->next) { | |
2166 | if (is_vxlan_flooding_head_end()) | |
2167 | zevpn_vtep_install(zevpn, zvtep); | |
2168 | else | |
2169 | zevpn_vtep_uninstall(zevpn, &zvtep->vtep_ip); | |
2170 | } | |
2171 | } | |
2172 | ||
2173 | /* | |
2174 | * Cleanup EVPN/VTEP and update kernel | |
2175 | */ | |
2176 | static void zevpn_cleanup_all(struct hash_bucket *bucket, void *arg) | |
2177 | { | |
2178 | zebra_evpn_t *zevpn = NULL; | |
2179 | zebra_l3vni_t *zl3vni = NULL; | |
2180 | struct zebra_vrf *zvrf = (struct zebra_vrf *)arg; | |
2181 | ||
2182 | zevpn = (zebra_evpn_t *)bucket->data; | |
2183 | ||
2184 | /* remove from l3-vni list */ | |
2185 | if (zvrf->l3vni) | |
2186 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
2187 | if (zl3vni) | |
2188 | listnode_delete(zl3vni->l2vnis, zevpn); | |
2189 | ||
2190 | /* Free up all neighbors and MACs, if any. */ | |
2191 | zebra_evpn_neigh_del_all(zevpn, 1, 0, DEL_ALL_NEIGH); | |
2192 | zebra_evpn_mac_del_all(zevpn, 1, 0, DEL_ALL_MAC); | |
2193 | ||
2194 | /* Free up all remote VTEPs, if any. */ | |
2195 | zevpn_vtep_del_all(zevpn, 1); | |
2196 | ||
2197 | /* Delete the hash entry. */ | |
2198 | zevpn_del(zevpn); | |
2199 | } | |
2200 | ||
2201 | /* cleanup L3VNI */ | |
2202 | static void zl3vni_cleanup_all(struct hash_bucket *bucket, void *args) | |
2203 | { | |
2204 | zebra_l3vni_t *zl3vni = NULL; | |
2205 | ||
2206 | zl3vni = (zebra_l3vni_t *)bucket->data; | |
2207 | ||
2208 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
2209 | } | |
2210 | ||
2211 | static void rb_find_or_add_host(struct host_rb_tree_entry *hrbe, | |
2212 | const struct prefix *host) | |
2213 | { | |
2214 | struct host_rb_entry lookup; | |
2215 | struct host_rb_entry *hle; | |
2216 | ||
2217 | memset(&lookup, 0, sizeof(lookup)); | |
2218 | memcpy(&lookup.p, host, sizeof(*host)); | |
2219 | ||
2220 | hle = RB_FIND(host_rb_tree_entry, hrbe, &lookup); | |
2221 | if (hle) | |
2222 | return; | |
2223 | ||
2224 | hle = XCALLOC(MTYPE_HOST_PREFIX, sizeof(struct host_rb_entry)); | |
2225 | memcpy(hle, &lookup, sizeof(lookup)); | |
2226 | ||
2227 | RB_INSERT(host_rb_tree_entry, hrbe, hle); | |
2228 | } | |
2229 | ||
2230 | static void rb_delete_host(struct host_rb_tree_entry *hrbe, struct prefix *host) | |
2231 | { | |
2232 | struct host_rb_entry lookup; | |
2233 | struct host_rb_entry *hle; | |
2234 | ||
2235 | memset(&lookup, 0, sizeof(lookup)); | |
2236 | memcpy(&lookup.p, host, sizeof(*host)); | |
2237 | ||
2238 | hle = RB_FIND(host_rb_tree_entry, hrbe, &lookup); | |
2239 | if (hle) { | |
2240 | RB_REMOVE(host_rb_tree_entry, hrbe, hle); | |
2241 | XFREE(MTYPE_HOST_PREFIX, hle); | |
2242 | } | |
2243 | ||
2244 | return; | |
2245 | } | |
2246 | ||
2247 | /* | |
2248 | * Look up MAC hash entry. | |
2249 | */ | |
2250 | static zebra_mac_t *zl3vni_rmac_lookup(zebra_l3vni_t *zl3vni, | |
2251 | const struct ethaddr *rmac) | |
2252 | { | |
2253 | zebra_mac_t tmp; | |
2254 | zebra_mac_t *pmac; | |
2255 | ||
2256 | memset(&tmp, 0, sizeof(tmp)); | |
2257 | memcpy(&tmp.macaddr, rmac, ETH_ALEN); | |
2258 | pmac = hash_lookup(zl3vni->rmac_table, &tmp); | |
2259 | ||
2260 | return pmac; | |
2261 | } | |
2262 | ||
2263 | /* | |
2264 | * Callback to allocate RMAC hash entry. | |
2265 | */ | |
2266 | static void *zl3vni_rmac_alloc(void *p) | |
2267 | { | |
2268 | const zebra_mac_t *tmp_rmac = p; | |
2269 | zebra_mac_t *zrmac; | |
2270 | ||
2271 | zrmac = XCALLOC(MTYPE_L3VNI_MAC, sizeof(zebra_mac_t)); | |
2272 | *zrmac = *tmp_rmac; | |
2273 | ||
2274 | return ((void *)zrmac); | |
2275 | } | |
2276 | ||
2277 | /* | |
2278 | * Add RMAC entry to l3-vni | |
2279 | */ | |
2280 | static zebra_mac_t *zl3vni_rmac_add(zebra_l3vni_t *zl3vni, | |
2281 | const struct ethaddr *rmac) | |
2282 | { | |
2283 | zebra_mac_t tmp_rmac; | |
2284 | zebra_mac_t *zrmac = NULL; | |
2285 | ||
2286 | memset(&tmp_rmac, 0, sizeof(zebra_mac_t)); | |
2287 | memcpy(&tmp_rmac.macaddr, rmac, ETH_ALEN); | |
2288 | zrmac = hash_get(zl3vni->rmac_table, &tmp_rmac, zl3vni_rmac_alloc); | |
2289 | assert(zrmac); | |
2290 | ||
2291 | RB_INIT(host_rb_tree_entry, &zrmac->host_rb); | |
2292 | ||
2293 | SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE); | |
2294 | SET_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC); | |
2295 | ||
2296 | return zrmac; | |
2297 | } | |
2298 | ||
2299 | /* | |
2300 | * Delete MAC entry. | |
2301 | */ | |
2302 | static int zl3vni_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) | |
2303 | { | |
2304 | zebra_mac_t *tmp_rmac; | |
2305 | struct host_rb_entry *hle; | |
2306 | ||
2307 | while (!RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) { | |
2308 | hle = RB_ROOT(host_rb_tree_entry, &zrmac->host_rb); | |
2309 | ||
2310 | RB_REMOVE(host_rb_tree_entry, &zrmac->host_rb, hle); | |
2311 | XFREE(MTYPE_HOST_PREFIX, hle); | |
2312 | } | |
2313 | ||
2314 | tmp_rmac = hash_release(zl3vni->rmac_table, zrmac); | |
2315 | XFREE(MTYPE_L3VNI_MAC, tmp_rmac); | |
2316 | ||
2317 | return 0; | |
2318 | } | |
2319 | ||
2320 | /* | |
2321 | * Install remote RMAC into the forwarding plane. | |
2322 | */ | |
2323 | static int zl3vni_rmac_install(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) | |
2324 | { | |
2325 | const struct zebra_if *zif = NULL, *br_zif = NULL; | |
2326 | const struct zebra_l2info_vxlan *vxl = NULL; | |
2327 | const struct interface *br_ifp; | |
2328 | enum zebra_dplane_result res; | |
2329 | vlanid_t vid; | |
2330 | ||
2331 | if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) | |
2332 | || !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) | |
2333 | return 0; | |
2334 | ||
2335 | zif = zl3vni->vxlan_if->info; | |
2336 | if (!zif) | |
2337 | return -1; | |
2338 | ||
2339 | br_ifp = zif->brslave_info.br_if; | |
2340 | if (br_ifp == NULL) | |
2341 | return -1; | |
2342 | ||
2343 | vxl = &zif->l2info.vxl; | |
2344 | ||
2345 | br_zif = (const struct zebra_if *)br_ifp->info; | |
2346 | ||
2347 | if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif)) | |
2348 | vid = vxl->access_vlan; | |
2349 | else | |
2350 | vid = 0; | |
2351 | ||
2352 | res = dplane_rem_mac_add(zl3vni->vxlan_if, br_ifp, vid, | |
2353 | &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip, 0, 0, | |
2354 | false /*was_static*/); | |
2355 | if (res != ZEBRA_DPLANE_REQUEST_FAILURE) | |
2356 | return 0; | |
2357 | else | |
2358 | return -1; | |
2359 | } | |
2360 | ||
2361 | /* | |
2362 | * Uninstall remote RMAC from the forwarding plane. | |
2363 | */ | |
2364 | static int zl3vni_rmac_uninstall(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac) | |
2365 | { | |
2366 | char buf[ETHER_ADDR_STRLEN]; | |
2367 | const struct zebra_if *zif = NULL, *br_zif; | |
2368 | const struct zebra_l2info_vxlan *vxl = NULL; | |
2369 | const struct interface *br_ifp; | |
2370 | vlanid_t vid; | |
2371 | enum zebra_dplane_result res; | |
2372 | ||
2373 | if (!(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE)) | |
2374 | || !(CHECK_FLAG(zrmac->flags, ZEBRA_MAC_REMOTE_RMAC))) | |
2375 | return 0; | |
2376 | ||
2377 | if (!zl3vni->vxlan_if) { | |
2378 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2379 | zlog_debug( | |
2380 | "RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if", | |
2381 | prefix_mac2str(&zrmac->macaddr, | |
2382 | buf, sizeof(buf)), | |
2383 | zl3vni->vni, zl3vni); | |
2384 | return -1; | |
2385 | } | |
2386 | ||
2387 | zif = zl3vni->vxlan_if->info; | |
2388 | if (!zif) | |
2389 | return -1; | |
2390 | ||
2391 | br_ifp = zif->brslave_info.br_if; | |
2392 | if (br_ifp == NULL) | |
2393 | return -1; | |
2394 | ||
2395 | vxl = &zif->l2info.vxl; | |
2396 | ||
2397 | br_zif = (const struct zebra_if *)br_ifp->info; | |
2398 | if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif)) | |
2399 | vid = vxl->access_vlan; | |
2400 | else | |
2401 | vid = 0; | |
2402 | ||
2403 | res = dplane_rem_mac_del(zl3vni->vxlan_if, br_ifp, vid, | |
2404 | &zrmac->macaddr, zrmac->fwd_info.r_vtep_ip); | |
2405 | if (res != ZEBRA_DPLANE_REQUEST_FAILURE) | |
2406 | return 0; | |
2407 | else | |
2408 | return -1; | |
2409 | } | |
2410 | ||
2411 | /* handle rmac add */ | |
2412 | static int zl3vni_remote_rmac_add(zebra_l3vni_t *zl3vni, | |
2413 | const struct ethaddr *rmac, | |
2414 | const struct ipaddr *vtep_ip, | |
2415 | const struct prefix *host_prefix) | |
2416 | { | |
2417 | char buf[ETHER_ADDR_STRLEN]; | |
2418 | char buf1[INET6_ADDRSTRLEN]; | |
2419 | char buf2[PREFIX_STRLEN]; | |
2420 | zebra_mac_t *zrmac = NULL; | |
2421 | ||
2422 | zrmac = zl3vni_rmac_lookup(zl3vni, rmac); | |
2423 | if (!zrmac) { | |
2424 | ||
2425 | /* Create the RMAC entry, or update its vtep, if necessary. */ | |
2426 | zrmac = zl3vni_rmac_add(zl3vni, rmac); | |
2427 | if (!zrmac) { | |
2428 | zlog_debug( | |
2429 | "Failed to add RMAC %s L3VNI %u Remote VTEP %s, prefix %s", | |
2430 | prefix_mac2str(rmac, buf, sizeof(buf)), | |
2431 | zl3vni->vni, | |
2432 | ipaddr2str(vtep_ip, buf1, sizeof(buf1)), | |
2433 | prefix2str(host_prefix, buf2, sizeof(buf2))); | |
2434 | return -1; | |
2435 | } | |
2436 | memset(&zrmac->fwd_info, 0, sizeof(zrmac->fwd_info)); | |
2437 | zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; | |
2438 | ||
2439 | /* Send RMAC for FPM processing */ | |
2440 | hook_call(zebra_rmac_update, zrmac, zl3vni, false, | |
2441 | "new RMAC added"); | |
2442 | ||
2443 | /* install rmac in kernel */ | |
2444 | zl3vni_rmac_install(zl3vni, zrmac); | |
2445 | } else if (!IPV4_ADDR_SAME(&zrmac->fwd_info.r_vtep_ip, | |
2446 | &vtep_ip->ipaddr_v4)) { | |
2447 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2448 | zlog_debug( | |
2449 | "L3VNI %u Remote VTEP change(%s -> %s) for RMAC %s, prefix %s", | |
2450 | zl3vni->vni, | |
2451 | inet_ntoa(zrmac->fwd_info.r_vtep_ip), | |
2452 | ipaddr2str(vtep_ip, buf1, sizeof(buf1)), | |
2453 | prefix_mac2str(rmac, buf, sizeof(buf)), | |
2454 | prefix2str(host_prefix, buf2, sizeof(buf2))); | |
2455 | ||
2456 | zrmac->fwd_info.r_vtep_ip = vtep_ip->ipaddr_v4; | |
2457 | ||
2458 | /* install rmac in kernel */ | |
2459 | zl3vni_rmac_install(zl3vni, zrmac); | |
2460 | } | |
2461 | ||
2462 | rb_find_or_add_host(&zrmac->host_rb, host_prefix); | |
2463 | ||
2464 | return 0; | |
2465 | } | |
2466 | ||
2467 | ||
2468 | /* handle rmac delete */ | |
2469 | static void zl3vni_remote_rmac_del(zebra_l3vni_t *zl3vni, zebra_mac_t *zrmac, | |
2470 | struct prefix *host_prefix) | |
2471 | { | |
2472 | rb_delete_host(&zrmac->host_rb, host_prefix); | |
2473 | ||
2474 | if (RB_EMPTY(host_rb_tree_entry, &zrmac->host_rb)) { | |
2475 | /* uninstall from kernel */ | |
2476 | zl3vni_rmac_uninstall(zl3vni, zrmac); | |
2477 | ||
2478 | /* Send RMAC for FPM processing */ | |
2479 | hook_call(zebra_rmac_update, zrmac, zl3vni, true, | |
2480 | "RMAC deleted"); | |
2481 | ||
2482 | /* del the rmac entry */ | |
2483 | zl3vni_rmac_del(zl3vni, zrmac); | |
2484 | } | |
2485 | } | |
2486 | ||
2487 | /* | |
2488 | * Look up nh hash entry on a l3-vni. | |
2489 | */ | |
2490 | static zebra_neigh_t *zl3vni_nh_lookup(zebra_l3vni_t *zl3vni, | |
2491 | const struct ipaddr *ip) | |
2492 | { | |
2493 | zebra_neigh_t tmp; | |
2494 | zebra_neigh_t *n; | |
2495 | ||
2496 | memset(&tmp, 0, sizeof(tmp)); | |
2497 | memcpy(&tmp.ip, ip, sizeof(struct ipaddr)); | |
2498 | n = hash_lookup(zl3vni->nh_table, &tmp); | |
2499 | ||
2500 | return n; | |
2501 | } | |
2502 | ||
2503 | ||
2504 | /* | |
2505 | * Callback to allocate NH hash entry on L3-VNI. | |
2506 | */ | |
2507 | static void *zl3vni_nh_alloc(void *p) | |
2508 | { | |
2509 | const zebra_neigh_t *tmp_n = p; | |
2510 | zebra_neigh_t *n; | |
2511 | ||
2512 | n = XCALLOC(MTYPE_L3NEIGH, sizeof(zebra_neigh_t)); | |
2513 | *n = *tmp_n; | |
2514 | ||
2515 | return ((void *)n); | |
2516 | } | |
2517 | ||
2518 | /* | |
2519 | * Add neighbor entry. | |
2520 | */ | |
2521 | static zebra_neigh_t *zl3vni_nh_add(zebra_l3vni_t *zl3vni, | |
2522 | const struct ipaddr *ip, | |
2523 | const struct ethaddr *mac) | |
2524 | { | |
2525 | zebra_neigh_t tmp_n; | |
2526 | zebra_neigh_t *n = NULL; | |
2527 | ||
2528 | memset(&tmp_n, 0, sizeof(zebra_neigh_t)); | |
2529 | memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr)); | |
2530 | n = hash_get(zl3vni->nh_table, &tmp_n, zl3vni_nh_alloc); | |
2531 | assert(n); | |
2532 | ||
2533 | RB_INIT(host_rb_tree_entry, &n->host_rb); | |
2534 | ||
2535 | memcpy(&n->emac, mac, ETH_ALEN); | |
2536 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
2537 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE_NH); | |
2538 | ||
2539 | return n; | |
2540 | } | |
2541 | ||
2542 | /* | |
2543 | * Delete neighbor entry. | |
2544 | */ | |
2545 | static int zl3vni_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) | |
2546 | { | |
2547 | zebra_neigh_t *tmp_n; | |
2548 | struct host_rb_entry *hle; | |
2549 | ||
2550 | while (!RB_EMPTY(host_rb_tree_entry, &n->host_rb)) { | |
2551 | hle = RB_ROOT(host_rb_tree_entry, &n->host_rb); | |
2552 | ||
2553 | RB_REMOVE(host_rb_tree_entry, &n->host_rb, hle); | |
2554 | XFREE(MTYPE_HOST_PREFIX, hle); | |
2555 | } | |
2556 | ||
2557 | tmp_n = hash_release(zl3vni->nh_table, n); | |
2558 | XFREE(MTYPE_L3NEIGH, tmp_n); | |
2559 | ||
2560 | return 0; | |
2561 | } | |
2562 | ||
2563 | /* | |
2564 | * Install remote nh as neigh into the kernel. | |
2565 | */ | |
2566 | static int zl3vni_nh_install(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) | |
2567 | { | |
2568 | uint8_t flags; | |
2569 | int ret = 0; | |
2570 | ||
2571 | if (!is_l3vni_oper_up(zl3vni)) | |
2572 | return -1; | |
2573 | ||
2574 | if (!(n->flags & ZEBRA_NEIGH_REMOTE) | |
2575 | || !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) | |
2576 | return 0; | |
2577 | ||
2578 | flags = DPLANE_NTF_EXT_LEARNED; | |
2579 | if (n->flags & ZEBRA_NEIGH_ROUTER_FLAG) | |
2580 | flags |= DPLANE_NTF_ROUTER; | |
2581 | ||
2582 | dplane_rem_neigh_add(zl3vni->svi_if, &n->ip, &n->emac, flags, | |
2583 | false /*was_static*/); | |
2584 | ||
2585 | return ret; | |
2586 | } | |
2587 | ||
2588 | /* | |
2589 | * Uninstall remote nh from the kernel. | |
2590 | */ | |
2591 | static int zl3vni_nh_uninstall(zebra_l3vni_t *zl3vni, zebra_neigh_t *n) | |
2592 | { | |
2593 | if (!(n->flags & ZEBRA_NEIGH_REMOTE) | |
2594 | || !(n->flags & ZEBRA_NEIGH_REMOTE_NH)) | |
2595 | return 0; | |
2596 | ||
2597 | if (!zl3vni->svi_if || !if_is_operative(zl3vni->svi_if)) | |
2598 | return 0; | |
2599 | ||
2600 | dplane_rem_neigh_delete(zl3vni->svi_if, &n->ip); | |
2601 | ||
2602 | return 0; | |
2603 | } | |
2604 | ||
2605 | /* add remote vtep as a neigh entry */ | |
2606 | static int zl3vni_remote_nh_add(zebra_l3vni_t *zl3vni, | |
2607 | const struct ipaddr *vtep_ip, | |
2608 | const struct ethaddr *rmac, | |
2609 | const struct prefix *host_prefix) | |
2610 | { | |
2611 | char buf[ETHER_ADDR_STRLEN]; | |
2612 | char buf1[ETHER_ADDR_STRLEN]; | |
2613 | char buf2[INET6_ADDRSTRLEN]; | |
2614 | char buf3[PREFIX_STRLEN]; | |
2615 | zebra_neigh_t *nh = NULL; | |
2616 | ||
2617 | /* Create the next hop entry, or update its mac, if necessary. */ | |
2618 | nh = zl3vni_nh_lookup(zl3vni, vtep_ip); | |
2619 | if (!nh) { | |
2620 | nh = zl3vni_nh_add(zl3vni, vtep_ip, rmac); | |
2621 | if (!nh) { | |
2622 | zlog_debug( | |
2623 | "Failed to add NH %s as Neigh (RMAC %s L3-VNI %u prefix %s)", | |
2624 | ipaddr2str(vtep_ip, buf1, sizeof(buf2)), | |
2625 | prefix_mac2str(rmac, buf, sizeof(buf)), | |
2626 | zl3vni->vni, | |
2627 | prefix2str(host_prefix, buf2, sizeof(buf2))); | |
2628 | return -1; | |
2629 | } | |
2630 | ||
2631 | /* install the nh neigh in kernel */ | |
2632 | zl3vni_nh_install(zl3vni, nh); | |
2633 | } else if (memcmp(&nh->emac, rmac, ETH_ALEN) != 0) { | |
2634 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2635 | zlog_debug("L3VNI %u RMAC change(%s --> %s) for nexthop %s, prefix %s", | |
2636 | zl3vni->vni, | |
2637 | prefix_mac2str(&nh->emac, buf, sizeof(buf)), | |
2638 | prefix_mac2str(rmac, buf1, sizeof(buf1)), | |
2639 | ipaddr2str(vtep_ip, buf2, sizeof(buf2)), | |
2640 | prefix2str(host_prefix, buf3, sizeof(buf3))); | |
2641 | ||
2642 | memcpy(&nh->emac, rmac, ETH_ALEN); | |
2643 | /* install (update) the nh neigh in kernel */ | |
2644 | zl3vni_nh_install(zl3vni, nh); | |
2645 | } | |
2646 | ||
2647 | rb_find_or_add_host(&nh->host_rb, host_prefix); | |
2648 | ||
2649 | return 0; | |
2650 | } | |
2651 | ||
2652 | /* handle nh neigh delete */ | |
2653 | static void zl3vni_remote_nh_del(zebra_l3vni_t *zl3vni, zebra_neigh_t *nh, | |
2654 | struct prefix *host_prefix) | |
2655 | { | |
2656 | rb_delete_host(&nh->host_rb, host_prefix); | |
2657 | ||
2658 | if (RB_EMPTY(host_rb_tree_entry, &nh->host_rb)) { | |
2659 | /* uninstall from kernel */ | |
2660 | zl3vni_nh_uninstall(zl3vni, nh); | |
2661 | ||
2662 | /* delete the nh entry */ | |
2663 | zl3vni_nh_del(zl3vni, nh); | |
2664 | } | |
2665 | } | |
2666 | ||
2667 | /* handle neigh update from kernel - the only thing of interest is to | |
2668 | * readd stale entries. | |
2669 | */ | |
2670 | static int zl3vni_local_nh_add_update(zebra_l3vni_t *zl3vni, struct ipaddr *ip, | |
2671 | uint16_t state) | |
2672 | { | |
2673 | #ifdef GNU_LINUX | |
2674 | zebra_neigh_t *n = NULL; | |
2675 | ||
2676 | n = zl3vni_nh_lookup(zl3vni, ip); | |
2677 | if (!n) | |
2678 | return 0; | |
2679 | ||
2680 | /* all next hop neigh are remote and installed by frr. | |
2681 | * If the kernel has aged this entry, re-install. | |
2682 | */ | |
2683 | if (state & NUD_STALE) | |
2684 | zl3vni_nh_install(zl3vni, n); | |
2685 | #endif | |
2686 | return 0; | |
2687 | } | |
2688 | ||
2689 | /* handle neigh delete from kernel */ | |
2690 | static int zl3vni_local_nh_del(zebra_l3vni_t *zl3vni, struct ipaddr *ip) | |
2691 | { | |
2692 | zebra_neigh_t *n = NULL; | |
2693 | ||
2694 | n = zl3vni_nh_lookup(zl3vni, ip); | |
2695 | if (!n) | |
2696 | return 0; | |
2697 | ||
2698 | /* all next hop neigh are remote and installed by frr. | |
2699 | * If we get an age out notification for these neigh entries, we have to | |
2700 | * install it back | |
2701 | */ | |
2702 | zl3vni_nh_install(zl3vni, n); | |
2703 | ||
2704 | return 0; | |
2705 | } | |
2706 | ||
2707 | /* | |
2708 | * Hash function for L3 VNI. | |
2709 | */ | |
2710 | static unsigned int l3vni_hash_keymake(const void *p) | |
2711 | { | |
2712 | const zebra_l3vni_t *zl3vni = p; | |
2713 | ||
2714 | return jhash_1word(zl3vni->vni, 0); | |
2715 | } | |
2716 | ||
2717 | /* | |
2718 | * Compare 2 L3 VNI hash entries. | |
2719 | */ | |
2720 | static bool l3vni_hash_cmp(const void *p1, const void *p2) | |
2721 | { | |
2722 | const zebra_l3vni_t *zl3vni1 = p1; | |
2723 | const zebra_l3vni_t *zl3vni2 = p2; | |
2724 | ||
2725 | return (zl3vni1->vni == zl3vni2->vni); | |
2726 | } | |
2727 | ||
2728 | /* | |
2729 | * Callback to allocate L3 VNI hash entry. | |
2730 | */ | |
2731 | static void *zl3vni_alloc(void *p) | |
2732 | { | |
2733 | zebra_l3vni_t *zl3vni = NULL; | |
2734 | const zebra_l3vni_t *tmp_l3vni = p; | |
2735 | ||
2736 | zl3vni = XCALLOC(MTYPE_ZL3VNI, sizeof(zebra_l3vni_t)); | |
2737 | zl3vni->vni = tmp_l3vni->vni; | |
2738 | return ((void *)zl3vni); | |
2739 | } | |
2740 | ||
2741 | /* | |
2742 | * Look up L3 VNI hash entry. | |
2743 | */ | |
2744 | static zebra_l3vni_t *zl3vni_lookup(vni_t vni) | |
2745 | { | |
2746 | zebra_l3vni_t tmp_l3vni; | |
2747 | zebra_l3vni_t *zl3vni = NULL; | |
2748 | ||
2749 | memset(&tmp_l3vni, 0, sizeof(zebra_l3vni_t)); | |
2750 | tmp_l3vni.vni = vni; | |
2751 | zl3vni = hash_lookup(zrouter.l3vni_table, &tmp_l3vni); | |
2752 | ||
2753 | return zl3vni; | |
2754 | } | |
2755 | ||
2756 | /* | |
2757 | * Add L3 VNI hash entry. | |
2758 | */ | |
2759 | static zebra_l3vni_t *zl3vni_add(vni_t vni, vrf_id_t vrf_id) | |
2760 | { | |
2761 | zebra_l3vni_t tmp_zl3vni; | |
2762 | zebra_l3vni_t *zl3vni = NULL; | |
2763 | ||
2764 | memset(&tmp_zl3vni, 0, sizeof(zebra_l3vni_t)); | |
2765 | tmp_zl3vni.vni = vni; | |
2766 | ||
2767 | zl3vni = hash_get(zrouter.l3vni_table, &tmp_zl3vni, zl3vni_alloc); | |
2768 | assert(zl3vni); | |
2769 | ||
2770 | zl3vni->vrf_id = vrf_id; | |
2771 | zl3vni->svi_if = NULL; | |
2772 | zl3vni->vxlan_if = NULL; | |
2773 | zl3vni->l2vnis = list_new(); | |
2774 | zl3vni->l2vnis->cmp = vni_list_cmp; | |
2775 | ||
2776 | /* Create hash table for remote RMAC */ | |
2777 | zl3vni->rmac_table = zebra_mac_db_create("Zebra L3-VNI RMAC-Table"); | |
2778 | ||
2779 | /* Create hash table for neighbors */ | |
2780 | zl3vni->nh_table = zebra_neigh_db_create("Zebra L3-VNI next-hop table"); | |
2781 | ||
2782 | return zl3vni; | |
2783 | } | |
2784 | ||
2785 | /* | |
2786 | * Delete L3 VNI hash entry. | |
2787 | */ | |
2788 | static int zl3vni_del(zebra_l3vni_t *zl3vni) | |
2789 | { | |
2790 | zebra_l3vni_t *tmp_zl3vni; | |
2791 | ||
2792 | /* free the list of l2vnis */ | |
2793 | list_delete(&zl3vni->l2vnis); | |
2794 | zl3vni->l2vnis = NULL; | |
2795 | ||
2796 | /* Free the rmac table */ | |
2797 | hash_free(zl3vni->rmac_table); | |
2798 | zl3vni->rmac_table = NULL; | |
2799 | ||
2800 | /* Free the nh table */ | |
2801 | hash_free(zl3vni->nh_table); | |
2802 | zl3vni->nh_table = NULL; | |
2803 | ||
2804 | /* Free the VNI hash entry and allocated memory. */ | |
2805 | tmp_zl3vni = hash_release(zrouter.l3vni_table, zl3vni); | |
2806 | XFREE(MTYPE_ZL3VNI, tmp_zl3vni); | |
2807 | ||
2808 | return 0; | |
2809 | } | |
2810 | ||
2811 | struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni) | |
2812 | { | |
2813 | struct zebra_ns *zns = NULL; | |
2814 | struct route_node *rn = NULL; | |
2815 | struct interface *ifp = NULL; | |
2816 | ||
2817 | /* loop through all vxlan-interface */ | |
2818 | zns = zebra_ns_lookup(NS_DEFAULT); | |
2819 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
2820 | ||
2821 | struct zebra_if *zif = NULL; | |
2822 | struct zebra_l2info_vxlan *vxl = NULL; | |
2823 | ||
2824 | ifp = (struct interface *)rn->info; | |
2825 | if (!ifp) | |
2826 | continue; | |
2827 | ||
2828 | zif = ifp->info; | |
2829 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
2830 | continue; | |
2831 | ||
2832 | vxl = &zif->l2info.vxl; | |
2833 | if (vxl->vni == zl3vni->vni) { | |
2834 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
2835 | return ifp; | |
2836 | } | |
2837 | } | |
2838 | ||
2839 | return NULL; | |
2840 | } | |
2841 | ||
2842 | struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni) | |
2843 | { | |
2844 | struct zebra_if *zif = NULL; /* zebra_if for vxlan_if */ | |
2845 | struct zebra_l2info_vxlan *vxl = NULL; /* l2 info for vxlan_if */ | |
2846 | ||
2847 | if (!zl3vni) | |
2848 | return NULL; | |
2849 | ||
2850 | if (!zl3vni->vxlan_if) | |
2851 | return NULL; | |
2852 | ||
2853 | zif = zl3vni->vxlan_if->info; | |
2854 | if (!zif) | |
2855 | return NULL; | |
2856 | ||
2857 | vxl = &zif->l2info.vxl; | |
2858 | ||
2859 | return zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); | |
2860 | } | |
2861 | ||
2862 | struct interface *zl3vni_map_to_mac_vlan_if(zebra_l3vni_t *zl3vni) | |
2863 | { | |
2864 | struct zebra_if *zif = NULL; /* zebra_if for vxlan_if */ | |
2865 | ||
2866 | if (!zl3vni) | |
2867 | return NULL; | |
2868 | ||
2869 | if (!zl3vni->vxlan_if) | |
2870 | return NULL; | |
2871 | ||
2872 | zif = zl3vni->vxlan_if->info; | |
2873 | if (!zif) | |
2874 | return NULL; | |
2875 | ||
2876 | return zevpn_map_to_macvlan(zif->brslave_info.br_if, zl3vni->svi_if); | |
2877 | } | |
2878 | ||
2879 | ||
2880 | zebra_l3vni_t *zl3vni_from_vrf(vrf_id_t vrf_id) | |
2881 | { | |
2882 | struct zebra_vrf *zvrf = NULL; | |
2883 | ||
2884 | zvrf = zebra_vrf_lookup_by_id(vrf_id); | |
2885 | if (!zvrf) | |
2886 | return NULL; | |
2887 | ||
2888 | return zl3vni_lookup(zvrf->l3vni); | |
2889 | } | |
2890 | ||
2891 | /* | |
2892 | * Map SVI and associated bridge to a VNI. This is invoked upon getting | |
2893 | * neighbor notifications, to see if they are of interest. | |
2894 | */ | |
2895 | static zebra_l3vni_t *zl3vni_from_svi(struct interface *ifp, | |
2896 | struct interface *br_if) | |
2897 | { | |
2898 | int found = 0; | |
2899 | vlanid_t vid = 0; | |
2900 | uint8_t bridge_vlan_aware = 0; | |
2901 | zebra_l3vni_t *zl3vni = NULL; | |
2902 | struct zebra_ns *zns = NULL; | |
2903 | struct route_node *rn = NULL; | |
2904 | struct zebra_if *zif = NULL; | |
2905 | struct interface *tmp_if = NULL; | |
2906 | struct zebra_l2info_bridge *br = NULL; | |
2907 | struct zebra_l2info_vxlan *vxl = NULL; | |
2908 | ||
2909 | if (!br_if) | |
2910 | return NULL; | |
2911 | ||
2912 | /* Make sure the linked interface is a bridge. */ | |
2913 | if (!IS_ZEBRA_IF_BRIDGE(br_if)) | |
2914 | return NULL; | |
2915 | ||
2916 | /* Determine if bridge is VLAN-aware or not */ | |
2917 | zif = br_if->info; | |
2918 | assert(zif); | |
2919 | br = &zif->l2info.br; | |
2920 | bridge_vlan_aware = br->vlan_aware; | |
2921 | if (bridge_vlan_aware) { | |
2922 | struct zebra_l2info_vlan *vl; | |
2923 | ||
2924 | if (!IS_ZEBRA_IF_VLAN(ifp)) | |
2925 | return NULL; | |
2926 | ||
2927 | zif = ifp->info; | |
2928 | assert(zif); | |
2929 | vl = &zif->l2info.vl; | |
2930 | vid = vl->vid; | |
2931 | } | |
2932 | ||
2933 | /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */ | |
2934 | /* TODO: Optimize with a hash. */ | |
2935 | zns = zebra_ns_lookup(NS_DEFAULT); | |
2936 | for (rn = route_top(zns->if_table); rn; rn = route_next(rn)) { | |
2937 | tmp_if = (struct interface *)rn->info; | |
2938 | if (!tmp_if) | |
2939 | continue; | |
2940 | zif = tmp_if->info; | |
2941 | if (!zif || zif->zif_type != ZEBRA_IF_VXLAN) | |
2942 | continue; | |
2943 | if (!if_is_operative(tmp_if)) | |
2944 | continue; | |
2945 | vxl = &zif->l2info.vxl; | |
2946 | ||
2947 | if (zif->brslave_info.br_if != br_if) | |
2948 | continue; | |
2949 | ||
2950 | if (!bridge_vlan_aware || vxl->access_vlan == vid) { | |
2951 | found = 1; | |
2952 | break; | |
2953 | } | |
2954 | } | |
2955 | ||
2956 | if (!found) | |
2957 | return NULL; | |
2958 | ||
2959 | zl3vni = zl3vni_lookup(vxl->vni); | |
2960 | return zl3vni; | |
2961 | } | |
2962 | ||
2963 | static inline void zl3vni_get_vrr_rmac(zebra_l3vni_t *zl3vni, | |
2964 | struct ethaddr *rmac) | |
2965 | { | |
2966 | if (!zl3vni) | |
2967 | return; | |
2968 | ||
2969 | if (!is_l3vni_oper_up(zl3vni)) | |
2970 | return; | |
2971 | ||
2972 | if (zl3vni->mac_vlan_if && if_is_operative(zl3vni->mac_vlan_if)) | |
2973 | memcpy(rmac->octet, zl3vni->mac_vlan_if->hw_addr, ETH_ALEN); | |
2974 | } | |
2975 | ||
2976 | /* | |
2977 | * Inform BGP about l3-vni. | |
2978 | */ | |
2979 | static int zl3vni_send_add_to_client(zebra_l3vni_t *zl3vni) | |
2980 | { | |
2981 | struct stream *s = NULL; | |
2982 | struct zserv *client = NULL; | |
2983 | struct ethaddr svi_rmac, vrr_rmac = {.octet = {0} }; | |
2984 | struct zebra_vrf *zvrf; | |
2985 | char buf[ETHER_ADDR_STRLEN]; | |
2986 | char buf1[ETHER_ADDR_STRLEN]; | |
2987 | bool is_anycast_mac = true; | |
2988 | ||
2989 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
2990 | /* BGP may not be running. */ | |
2991 | if (!client) | |
2992 | return 0; | |
2993 | ||
2994 | zvrf = zebra_vrf_lookup_by_id(zl3vni->vrf_id); | |
2995 | assert(zvrf); | |
2996 | ||
2997 | /* get the svi and vrr rmac values */ | |
2998 | memset(&svi_rmac, 0, sizeof(struct ethaddr)); | |
2999 | zl3vni_get_svi_rmac(zl3vni, &svi_rmac); | |
3000 | zl3vni_get_vrr_rmac(zl3vni, &vrr_rmac); | |
3001 | ||
3002 | /* In absence of vrr mac use svi mac as anycast MAC value */ | |
3003 | if (is_zero_mac(&vrr_rmac)) { | |
3004 | memcpy(&vrr_rmac, &svi_rmac, ETH_ALEN); | |
3005 | is_anycast_mac = false; | |
3006 | } | |
3007 | ||
3008 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
3009 | ||
3010 | /* The message is used for both vni add and/or update like | |
3011 | * vrr mac is added for l3vni SVI. | |
3012 | */ | |
3013 | zclient_create_header(s, ZEBRA_L3VNI_ADD, zl3vni_vrf_id(zl3vni)); | |
3014 | stream_putl(s, zl3vni->vni); | |
3015 | stream_put(s, &svi_rmac, sizeof(struct ethaddr)); | |
3016 | stream_put_in_addr(s, &zl3vni->local_vtep_ip); | |
3017 | stream_put(s, &zl3vni->filter, sizeof(int)); | |
3018 | stream_putl(s, zl3vni->svi_if->ifindex); | |
3019 | stream_put(s, &vrr_rmac, sizeof(struct ethaddr)); | |
3020 | stream_putl(s, is_anycast_mac); | |
3021 | ||
3022 | /* Write packet size. */ | |
3023 | stream_putw_at(s, 0, stream_get_endp(s)); | |
3024 | ||
3025 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3026 | zlog_debug( | |
3027 | "Send L3_VNI_ADD %u VRF %s RMAC %s VRR %s local-ip %s filter %s to %s", | |
3028 | zl3vni->vni, vrf_id_to_name(zl3vni_vrf_id(zl3vni)), | |
3029 | prefix_mac2str(&svi_rmac, buf, sizeof(buf)), | |
3030 | prefix_mac2str(&vrr_rmac, buf1, sizeof(buf1)), | |
3031 | inet_ntoa(zl3vni->local_vtep_ip), | |
3032 | CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) | |
3033 | ? "prefix-routes-only" | |
3034 | : "none", | |
3035 | zebra_route_string(client->proto)); | |
3036 | ||
3037 | client->l3vniadd_cnt++; | |
3038 | return zserv_send_message(client, s); | |
3039 | } | |
3040 | ||
3041 | /* | |
3042 | * Inform BGP about local l3-VNI deletion. | |
3043 | */ | |
3044 | static int zl3vni_send_del_to_client(zebra_l3vni_t *zl3vni) | |
3045 | { | |
3046 | struct stream *s = NULL; | |
3047 | struct zserv *client = NULL; | |
3048 | ||
3049 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
3050 | /* BGP may not be running. */ | |
3051 | if (!client) | |
3052 | return 0; | |
3053 | ||
3054 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
3055 | ||
3056 | zclient_create_header(s, ZEBRA_L3VNI_DEL, zl3vni_vrf_id(zl3vni)); | |
3057 | stream_putl(s, zl3vni->vni); | |
3058 | ||
3059 | /* Write packet size. */ | |
3060 | stream_putw_at(s, 0, stream_get_endp(s)); | |
3061 | ||
3062 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3063 | zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni->vni, | |
3064 | vrf_id_to_name(zl3vni_vrf_id(zl3vni)), | |
3065 | zebra_route_string(client->proto)); | |
3066 | ||
3067 | client->l3vnidel_cnt++; | |
3068 | return zserv_send_message(client, s); | |
3069 | } | |
3070 | ||
3071 | static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t *zl3vni) | |
3072 | { | |
3073 | if (!zl3vni) | |
3074 | return; | |
3075 | ||
3076 | /* send l3vni add to BGP */ | |
3077 | zl3vni_send_add_to_client(zl3vni); | |
3078 | } | |
3079 | ||
3080 | static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t *zl3vni) | |
3081 | { | |
3082 | if (!zl3vni) | |
3083 | return; | |
3084 | ||
3085 | /* send l3-vni del to BGP*/ | |
3086 | zl3vni_send_del_to_client(zl3vni); | |
3087 | } | |
3088 | ||
3089 | static void zevpn_add_to_l3vni_list(struct hash_bucket *bucket, void *ctxt) | |
3090 | { | |
3091 | zebra_evpn_t *zevpn = (zebra_evpn_t *)bucket->data; | |
3092 | zebra_l3vni_t *zl3vni = (zebra_l3vni_t *)ctxt; | |
3093 | ||
3094 | if (zevpn->vrf_id == zl3vni_vrf_id(zl3vni)) | |
3095 | listnode_add_sort(zl3vni->l2vnis, zevpn); | |
3096 | } | |
3097 | ||
3098 | /* | |
3099 | * handle transition of vni from l2 to l3 and vice versa | |
3100 | */ | |
3101 | static int zebra_vxlan_handle_vni_transition(struct zebra_vrf *zvrf, vni_t vni, | |
3102 | int add) | |
3103 | { | |
3104 | zebra_evpn_t *zevpn = NULL; | |
3105 | ||
3106 | /* There is a possibility that VNI notification was already received | |
3107 | * from kernel and we programmed it as L2-VNI | |
3108 | * In such a case we need to delete this L2-VNI first, so | |
3109 | * that it can be reprogrammed as L3-VNI in the system. It is also | |
3110 | * possible that the vrf-vni mapping is removed from FRR while the vxlan | |
3111 | * interface is still present in kernel. In this case to keep it | |
3112 | * symmetric, we will delete the l3-vni and reprogram it as l2-vni | |
3113 | */ | |
3114 | if (add) { | |
3115 | /* Locate hash entry */ | |
3116 | zevpn = zevpn_lookup(vni); | |
3117 | if (!zevpn) | |
3118 | return 0; | |
3119 | ||
3120 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3121 | zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni); | |
3122 | ||
3123 | /* Delete EVPN from BGP. */ | |
3124 | zevpn_send_del_to_client(zevpn); | |
3125 | ||
3126 | zebra_evpn_neigh_del_all(zevpn, 0, 0, DEL_ALL_NEIGH); | |
3127 | zebra_evpn_mac_del_all(zevpn, 0, 0, DEL_ALL_MAC); | |
3128 | ||
3129 | /* Free up all remote VTEPs, if any. */ | |
3130 | zevpn_vtep_del_all(zevpn, 0); | |
3131 | ||
3132 | /* Delete the hash entry. */ | |
3133 | if (zevpn_del(zevpn)) { | |
3134 | flog_err(EC_ZEBRA_VNI_DEL_FAILED, | |
3135 | "Failed to del EVPN hash %p, VNI %u", zevpn, | |
3136 | zevpn->vni); | |
3137 | return -1; | |
3138 | } | |
3139 | } else { | |
3140 | /* TODO_MITESH: This needs to be thought through. We don't have | |
3141 | * enough information at this point to reprogram the vni as | |
3142 | * l2-vni. One way is to store the required info in l3-vni and | |
3143 | * used it solely for this purpose | |
3144 | */ | |
3145 | } | |
3146 | ||
3147 | return 0; | |
3148 | } | |
3149 | ||
3150 | /* delete and uninstall rmac hash entry */ | |
3151 | static void zl3vni_del_rmac_hash_entry(struct hash_bucket *bucket, void *ctx) | |
3152 | { | |
3153 | zebra_mac_t *zrmac = NULL; | |
3154 | zebra_l3vni_t *zl3vni = NULL; | |
3155 | ||
3156 | zrmac = (zebra_mac_t *)bucket->data; | |
3157 | zl3vni = (zebra_l3vni_t *)ctx; | |
3158 | zl3vni_rmac_uninstall(zl3vni, zrmac); | |
3159 | ||
3160 | /* Send RMAC for FPM processing */ | |
3161 | hook_call(zebra_rmac_update, zrmac, zl3vni, true, "RMAC deleted"); | |
3162 | ||
3163 | zl3vni_rmac_del(zl3vni, zrmac); | |
3164 | } | |
3165 | ||
3166 | /* delete and uninstall nh hash entry */ | |
3167 | static void zl3vni_del_nh_hash_entry(struct hash_bucket *bucket, void *ctx) | |
3168 | { | |
3169 | zebra_neigh_t *n = NULL; | |
3170 | zebra_l3vni_t *zl3vni = NULL; | |
3171 | ||
3172 | n = (zebra_neigh_t *)bucket->data; | |
3173 | zl3vni = (zebra_l3vni_t *)ctx; | |
3174 | zl3vni_nh_uninstall(zl3vni, n); | |
3175 | zl3vni_nh_del(zl3vni, n); | |
3176 | } | |
3177 | ||
3178 | static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p, | |
3179 | uint16_t cmd) | |
3180 | { | |
3181 | struct zserv *client = NULL; | |
3182 | struct stream *s = NULL; | |
3183 | char buf[PREFIX_STRLEN]; | |
3184 | ||
3185 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); | |
3186 | /* BGP may not be running. */ | |
3187 | if (!client) | |
3188 | return 0; | |
3189 | ||
3190 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
3191 | ||
3192 | zclient_create_header(s, cmd, vrf_id); | |
3193 | stream_put(s, p, sizeof(struct prefix)); | |
3194 | ||
3195 | /* Write packet size. */ | |
3196 | stream_putw_at(s, 0, stream_get_endp(s)); | |
3197 | ||
3198 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3199 | zlog_debug("Send ip prefix %s %s on vrf %s", | |
3200 | prefix2str(p, buf, sizeof(buf)), | |
3201 | (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", | |
3202 | vrf_id_to_name(vrf_id)); | |
3203 | ||
3204 | if (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) | |
3205 | client->prefixadd_cnt++; | |
3206 | else | |
3207 | client->prefixdel_cnt++; | |
3208 | ||
3209 | return zserv_send_message(client, s); | |
3210 | } | |
3211 | ||
3212 | /* re-add remote rmac if needed */ | |
3213 | static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t *zl3vni, | |
3214 | struct ethaddr *rmac) | |
3215 | { | |
3216 | char buf[ETHER_ADDR_STRLEN]; | |
3217 | zebra_mac_t *zrmac = NULL; | |
3218 | ||
3219 | zrmac = zl3vni_rmac_lookup(zl3vni, rmac); | |
3220 | if (!zrmac) | |
3221 | return 0; | |
3222 | ||
3223 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3224 | zlog_debug("Del remote RMAC %s L3VNI %u - readd", | |
3225 | prefix_mac2str(rmac, buf, sizeof(buf)), zl3vni->vni); | |
3226 | ||
3227 | zl3vni_rmac_install(zl3vni, zrmac); | |
3228 | return 0; | |
3229 | } | |
3230 | ||
3231 | static void zebra_vxlan_process_sync_macip_add(zebra_evpn_t *zevpn, | |
3232 | struct ethaddr *macaddr, | |
3233 | uint16_t ipa_len, | |
3234 | struct ipaddr *ipaddr, | |
3235 | uint8_t flags, | |
3236 | uint32_t seq, | |
3237 | esi_t *esi) | |
3238 | { | |
3239 | struct sync_mac_ip_ctx ctx; | |
3240 | char macbuf[ETHER_ADDR_STRLEN]; | |
3241 | char ipbuf[INET6_ADDRSTRLEN]; | |
3242 | bool sticky; | |
3243 | bool remote_gw; | |
3244 | zebra_neigh_t *n = NULL; | |
3245 | ||
3246 | sticky = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); | |
3247 | remote_gw = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW); | |
3248 | /* if sticky or remote-gw ignore updates from the peer */ | |
3249 | if (sticky || remote_gw) { | |
3250 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_NEIGH || | |
3251 | IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
3252 | zlog_debug("Ignore sync-macip vni %u mac %s%s%s%s%s", | |
3253 | zevpn->vni, | |
3254 | prefix_mac2str(macaddr, macbuf, sizeof(macbuf)), | |
3255 | ipa_len ? " IP " : "", | |
3256 | ipa_len ? | |
3257 | ipaddr2str(ipaddr, ipbuf, sizeof(ipbuf)) : "", | |
3258 | sticky ? " sticky" : "", | |
3259 | remote_gw ? " remote_gw" : ""); | |
3260 | return; | |
3261 | } | |
3262 | ||
3263 | if (ipa_len) { | |
3264 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
3265 | if (n | |
3266 | && !zebra_evpn_neigh_is_bgp_seq_ok(zevpn, n, macaddr, seq)) | |
3267 | return; | |
3268 | } | |
3269 | ||
3270 | memset(&ctx, 0, sizeof(ctx)); | |
3271 | ctx.mac = zebra_evpn_proc_sync_mac_update( | |
3272 | zevpn, macaddr, ipa_len, ipaddr, flags, seq, esi, &ctx); | |
3273 | if (ctx.ignore_macip || !ctx.mac || !ipa_len) | |
3274 | return; | |
3275 | ||
3276 | zebra_evpn_proc_sync_neigh_update(zevpn, n, ipa_len, ipaddr, flags, seq, | |
3277 | esi, &ctx); | |
3278 | } | |
3279 | ||
3280 | /************************** remote mac-ip handling **************************/ | |
3281 | /* Process a remote MACIP add from BGP. */ | |
3282 | static void process_remote_macip_add(vni_t vni, | |
3283 | struct ethaddr *macaddr, | |
3284 | uint16_t ipa_len, | |
3285 | struct ipaddr *ipaddr, | |
3286 | uint8_t flags, | |
3287 | uint32_t seq, | |
3288 | struct in_addr vtep_ip, | |
3289 | esi_t *esi) | |
3290 | { | |
3291 | zebra_evpn_t *zevpn; | |
3292 | zebra_vtep_t *zvtep; | |
3293 | zebra_mac_t *mac = NULL; | |
3294 | struct interface *ifp = NULL; | |
3295 | struct zebra_if *zif = NULL; | |
3296 | struct zebra_vrf *zvrf; | |
3297 | ||
3298 | /* Locate EVPN hash entry - expected to exist. */ | |
3299 | zevpn = zevpn_lookup(vni); | |
3300 | if (!zevpn) { | |
3301 | zlog_warn("Unknown VNI %u upon remote MACIP ADD", vni); | |
3302 | return; | |
3303 | } | |
3304 | ||
3305 | ifp = zevpn->vxlan_if; | |
3306 | if (ifp) | |
3307 | zif = ifp->info; | |
3308 | if (!ifp || | |
3309 | !if_is_operative(ifp) || | |
3310 | !zif || | |
3311 | !zif->brslave_info.br_if) { | |
3312 | zlog_warn("Ignoring remote MACIP ADD VNI %u, invalid interface state or info", | |
3313 | vni); | |
3314 | return; | |
3315 | } | |
3316 | ||
3317 | /* Type-2 routes from another PE can be interpreted as remote or | |
3318 | * SYNC based on the destination ES - | |
3319 | * SYNC - if ES is local | |
3320 | * REMOTE - if ES is not local | |
3321 | */ | |
3322 | if (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) { | |
3323 | zebra_vxlan_process_sync_macip_add(zevpn, macaddr, ipa_len, | |
3324 | ipaddr, flags, seq, esi); | |
3325 | return; | |
3326 | } | |
3327 | ||
3328 | /* The remote VTEP specified should normally exist, but it is | |
3329 | * possible that when peering comes up, peer may advertise MACIP | |
3330 | * routes before advertising type-3 routes. | |
3331 | */ | |
3332 | if (vtep_ip.s_addr) { | |
3333 | zvtep = zevpn_vtep_find(zevpn, &vtep_ip); | |
3334 | if (!zvtep) { | |
3335 | zvtep = zevpn_vtep_add(zevpn, &vtep_ip, | |
3336 | VXLAN_FLOOD_DISABLED); | |
3337 | if (!zvtep) { | |
3338 | flog_err( | |
3339 | EC_ZEBRA_VTEP_ADD_FAILED, | |
3340 | "Failed to add remote VTEP, VNI %u zevpn %p upon remote MACIP ADD", | |
3341 | vni, zevpn); | |
3342 | return; | |
3343 | } | |
3344 | ||
3345 | zevpn_vtep_install(zevpn, zvtep); | |
3346 | } | |
3347 | } | |
3348 | ||
3349 | zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id); | |
3350 | if (!zvrf) | |
3351 | return; | |
3352 | ||
3353 | ||
3354 | if (process_mac_remote_macip_add(zevpn, zvrf, macaddr, ipa_len, ipaddr, | |
3355 | &mac, vtep_ip, flags, seq, esi) | |
3356 | != 0) | |
3357 | return; | |
3358 | ||
3359 | process_neigh_remote_macip_add(zevpn, zvrf, ipaddr, mac, vtep_ip, flags, | |
3360 | seq); | |
3361 | } | |
3362 | ||
3363 | /* Process a remote MACIP delete from BGP. */ | |
3364 | static void process_remote_macip_del(vni_t vni, | |
3365 | struct ethaddr *macaddr, | |
3366 | uint16_t ipa_len, | |
3367 | struct ipaddr *ipaddr, | |
3368 | struct in_addr vtep_ip) | |
3369 | { | |
3370 | zebra_evpn_t *zevpn; | |
3371 | zebra_mac_t *mac = NULL; | |
3372 | zebra_neigh_t *n = NULL; | |
3373 | struct interface *ifp = NULL; | |
3374 | struct zebra_if *zif = NULL; | |
3375 | struct zebra_ns *zns; | |
3376 | struct zebra_l2info_vxlan *vxl; | |
3377 | struct zebra_vrf *zvrf; | |
3378 | char buf[ETHER_ADDR_STRLEN]; | |
3379 | char buf1[INET6_ADDRSTRLEN]; | |
3380 | ||
3381 | /* Locate EVPN hash entry - expected to exist. */ | |
3382 | zevpn = zevpn_lookup(vni); | |
3383 | if (!zevpn) { | |
3384 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3385 | zlog_debug("Unknown VNI %u upon remote MACIP DEL", vni); | |
3386 | return; | |
3387 | } | |
3388 | ||
3389 | ifp = zevpn->vxlan_if; | |
3390 | if (ifp) | |
3391 | zif = ifp->info; | |
3392 | if (!ifp || | |
3393 | !if_is_operative(ifp) || | |
3394 | !zif || | |
3395 | !zif->brslave_info.br_if) { | |
3396 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3397 | zlog_debug("Ignoring remote MACIP DEL VNI %u, invalid interface state or info", | |
3398 | vni); | |
3399 | return; | |
3400 | } | |
3401 | zns = zebra_ns_lookup(NS_DEFAULT); | |
3402 | vxl = &zif->l2info.vxl; | |
3403 | ||
3404 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
3405 | if (ipa_len) | |
3406 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
3407 | ||
3408 | if (n && !mac) { | |
3409 | zlog_warn("Failed to locate MAC %s for neigh %s VNI %u upon remote MACIP DEL", | |
3410 | prefix_mac2str(macaddr, buf, sizeof(buf)), | |
3411 | ipaddr2str(ipaddr, buf1, sizeof(buf1)), vni); | |
3412 | return; | |
3413 | } | |
3414 | ||
3415 | /* If the remote mac or neighbor doesn't exist there is nothing | |
3416 | * more to do. Otherwise, uninstall the entry and then remove it. | |
3417 | */ | |
3418 | if (!mac && !n) | |
3419 | return; | |
3420 | ||
3421 | zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id); | |
3422 | ||
3423 | /* Ignore the delete if this mac is a gateway mac-ip */ | |
3424 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) | |
3425 | && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) { | |
3426 | zlog_warn( | |
3427 | "Ignore remote MACIP DEL VNI %u MAC %s%s%s as MAC is already configured as gateway MAC", | |
3428 | vni, | |
3429 | prefix_mac2str(macaddr, buf, sizeof(buf)), | |
3430 | ipa_len ? " IP " : "", | |
3431 | ipa_len ? | |
3432 | ipaddr2str(ipaddr, buf1, sizeof(buf1)) : ""); | |
3433 | return; | |
3434 | } | |
3435 | ||
3436 | /* Uninstall remote neighbor or MAC. */ | |
3437 | if (n) | |
3438 | zebra_evpn_neigh_remote_uninstall(zevpn, zvrf, n, mac, ipaddr); | |
3439 | else { | |
3440 | /* DAD: when MAC is freeze state as remote learn event, | |
3441 | * remote mac-ip delete event is received will result in freeze | |
3442 | * entry removal, first fetch kernel for the same entry present | |
3443 | * as LOCAL and reachable, avoid deleting this entry instead | |
3444 | * use kerenel local entry to update during unfreeze time. | |
3445 | */ | |
3446 | if (zvrf->dad_freeze && | |
3447 | CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE) && | |
3448 | CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
3449 | if (IS_ZEBRA_DEBUG_VXLAN) | |
3450 | zlog_debug( | |
3451 | "%s: MAC %s (flags 0x%x) is remote and duplicate, read kernel for local entry", | |
3452 | __func__, | |
3453 | prefix_mac2str(macaddr, buf, | |
3454 | sizeof(buf)), | |
3455 | mac->flags); | |
3456 | macfdb_read_specific_mac(zns, zif->brslave_info.br_if, | |
3457 | macaddr, vxl->access_vlan); | |
3458 | } | |
3459 | ||
3460 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
3461 | if (!ipa_len) | |
3462 | zebra_evpn_sync_mac_del(mac); | |
3463 | } else if (CHECK_FLAG(mac->flags, ZEBRA_NEIGH_REMOTE)) { | |
3464 | zebra_evpn_rem_mac_del(zevpn, mac); | |
3465 | } | |
3466 | } | |
3467 | } | |
3468 | ||
3469 | ||
3470 | /* Public functions */ | |
3471 | ||
3472 | int is_l3vni_for_prefix_routes_only(vni_t vni) | |
3473 | { | |
3474 | zebra_l3vni_t *zl3vni = NULL; | |
3475 | ||
3476 | zl3vni = zl3vni_lookup(vni); | |
3477 | if (!zl3vni) | |
3478 | return 0; | |
3479 | ||
3480 | return CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY) ? 1 : 0; | |
3481 | } | |
3482 | ||
3483 | /* handle evpn route in vrf table */ | |
3484 | void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id, const struct ethaddr *rmac, | |
3485 | const struct ipaddr *vtep_ip, | |
3486 | const struct prefix *host_prefix) | |
3487 | { | |
3488 | zebra_l3vni_t *zl3vni = NULL; | |
3489 | struct ipaddr ipv4_vtep; | |
3490 | ||
3491 | zl3vni = zl3vni_from_vrf(vrf_id); | |
3492 | if (!zl3vni || !is_l3vni_oper_up(zl3vni)) | |
3493 | return; | |
3494 | ||
3495 | /* | |
3496 | * add the next hop neighbor - | |
3497 | * neigh to be installed is the ipv6 nexthop neigh | |
3498 | */ | |
3499 | zl3vni_remote_nh_add(zl3vni, vtep_ip, rmac, host_prefix); | |
3500 | ||
3501 | /* | |
3502 | * if the remote vtep is a ipv4 mapped ipv6 address convert it to ipv4 | |
3503 | * address. Rmac is programmed against the ipv4 vtep because we only | |
3504 | * support ipv4 tunnels in the h/w right now | |
3505 | */ | |
3506 | memset(&ipv4_vtep, 0, sizeof(struct ipaddr)); | |
3507 | ipv4_vtep.ipa_type = IPADDR_V4; | |
3508 | if (vtep_ip->ipa_type == IPADDR_V6) | |
3509 | ipv4_mapped_ipv6_to_ipv4(&vtep_ip->ipaddr_v6, | |
3510 | &(ipv4_vtep.ipaddr_v4)); | |
3511 | else | |
3512 | memcpy(&(ipv4_vtep.ipaddr_v4), &vtep_ip->ipaddr_v4, | |
3513 | sizeof(struct in_addr)); | |
3514 | ||
3515 | /* | |
3516 | * add the rmac - remote rmac to be installed is against the ipv4 | |
3517 | * nexthop address | |
3518 | */ | |
3519 | zl3vni_remote_rmac_add(zl3vni, rmac, &ipv4_vtep, host_prefix); | |
3520 | } | |
3521 | ||
3522 | /* handle evpn vrf route delete */ | |
3523 | void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id, | |
3524 | struct ipaddr *vtep_ip, | |
3525 | struct prefix *host_prefix) | |
3526 | { | |
3527 | zebra_l3vni_t *zl3vni = NULL; | |
3528 | zebra_neigh_t *nh = NULL; | |
3529 | zebra_mac_t *zrmac = NULL; | |
3530 | ||
3531 | zl3vni = zl3vni_from_vrf(vrf_id); | |
3532 | if (!zl3vni) | |
3533 | return; | |
3534 | ||
3535 | /* find the next hop entry and rmac entry */ | |
3536 | nh = zl3vni_nh_lookup(zl3vni, vtep_ip); | |
3537 | if (!nh) | |
3538 | return; | |
3539 | zrmac = zl3vni_rmac_lookup(zl3vni, &nh->emac); | |
3540 | ||
3541 | /* delete the next hop entry */ | |
3542 | zl3vni_remote_nh_del(zl3vni, nh, host_prefix); | |
3543 | ||
3544 | /* delete the rmac entry */ | |
3545 | if (zrmac) | |
3546 | zl3vni_remote_rmac_del(zl3vni, zrmac, host_prefix); | |
3547 | ||
3548 | } | |
3549 | ||
3550 | void zebra_vxlan_print_specific_rmac_l3vni(struct vty *vty, vni_t l3vni, | |
3551 | struct ethaddr *rmac, bool use_json) | |
3552 | { | |
3553 | zebra_l3vni_t *zl3vni = NULL; | |
3554 | zebra_mac_t *zrmac = NULL; | |
3555 | json_object *json = NULL; | |
3556 | ||
3557 | if (!is_evpn_enabled()) { | |
3558 | if (use_json) | |
3559 | vty_out(vty, "{}\n"); | |
3560 | return; | |
3561 | } | |
3562 | ||
3563 | if (use_json) | |
3564 | json = json_object_new_object(); | |
3565 | ||
3566 | zl3vni = zl3vni_lookup(l3vni); | |
3567 | if (!zl3vni) { | |
3568 | if (use_json) | |
3569 | vty_out(vty, "{}\n"); | |
3570 | else | |
3571 | vty_out(vty, "%% L3-VNI %u doesn't exist\n", l3vni); | |
3572 | return; | |
3573 | } | |
3574 | ||
3575 | zrmac = zl3vni_rmac_lookup(zl3vni, rmac); | |
3576 | if (!zrmac) { | |
3577 | if (use_json) | |
3578 | vty_out(vty, "{}\n"); | |
3579 | else | |
3580 | vty_out(vty, | |
3581 | "%% Requested RMAC doesn't exist in L3-VNI %u", | |
3582 | l3vni); | |
3583 | return; | |
3584 | } | |
3585 | ||
3586 | zl3vni_print_rmac(zrmac, vty, json); | |
3587 | ||
3588 | if (use_json) { | |
3589 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3590 | json, JSON_C_TO_STRING_PRETTY)); | |
3591 | json_object_free(json); | |
3592 | } | |
3593 | } | |
3594 | ||
3595 | void zebra_vxlan_print_rmacs_l3vni(struct vty *vty, vni_t l3vni, bool use_json) | |
3596 | { | |
3597 | zebra_l3vni_t *zl3vni; | |
3598 | uint32_t num_rmacs; | |
3599 | struct rmac_walk_ctx wctx; | |
3600 | json_object *json = NULL; | |
3601 | ||
3602 | if (!is_evpn_enabled()) | |
3603 | return; | |
3604 | ||
3605 | zl3vni = zl3vni_lookup(l3vni); | |
3606 | if (!zl3vni) { | |
3607 | if (use_json) | |
3608 | vty_out(vty, "{}\n"); | |
3609 | else | |
3610 | vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); | |
3611 | return; | |
3612 | } | |
3613 | num_rmacs = hashcount(zl3vni->rmac_table); | |
3614 | if (!num_rmacs) | |
3615 | return; | |
3616 | ||
3617 | if (use_json) | |
3618 | json = json_object_new_object(); | |
3619 | ||
3620 | memset(&wctx, 0, sizeof(struct rmac_walk_ctx)); | |
3621 | wctx.vty = vty; | |
3622 | wctx.json = json; | |
3623 | if (!use_json) { | |
3624 | vty_out(vty, "Number of Remote RMACs known for this VNI: %u\n", | |
3625 | num_rmacs); | |
3626 | vty_out(vty, "%-17s %-21s\n", "MAC", "Remote VTEP"); | |
3627 | } else | |
3628 | json_object_int_add(json, "numRmacs", num_rmacs); | |
3629 | ||
3630 | hash_iterate(zl3vni->rmac_table, zl3vni_print_rmac_hash, &wctx); | |
3631 | ||
3632 | if (use_json) { | |
3633 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3634 | json, JSON_C_TO_STRING_PRETTY)); | |
3635 | json_object_free(json); | |
3636 | } | |
3637 | } | |
3638 | ||
3639 | void zebra_vxlan_print_rmacs_all_l3vni(struct vty *vty, bool use_json) | |
3640 | { | |
3641 | json_object *json = NULL; | |
3642 | void *args[2]; | |
3643 | ||
3644 | if (!is_evpn_enabled()) { | |
3645 | if (use_json) | |
3646 | vty_out(vty, "{}\n"); | |
3647 | return; | |
3648 | } | |
3649 | ||
3650 | if (use_json) | |
3651 | json = json_object_new_object(); | |
3652 | ||
3653 | args[0] = vty; | |
3654 | args[1] = json; | |
3655 | hash_iterate(zrouter.l3vni_table, | |
3656 | (void (*)(struct hash_bucket *, | |
3657 | void *))zl3vni_print_rmac_hash_all_vni, | |
3658 | args); | |
3659 | ||
3660 | if (use_json) { | |
3661 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3662 | json, JSON_C_TO_STRING_PRETTY)); | |
3663 | json_object_free(json); | |
3664 | } | |
3665 | } | |
3666 | ||
3667 | void zebra_vxlan_print_specific_nh_l3vni(struct vty *vty, vni_t l3vni, | |
3668 | struct ipaddr *ip, bool use_json) | |
3669 | { | |
3670 | zebra_l3vni_t *zl3vni = NULL; | |
3671 | zebra_neigh_t *n = NULL; | |
3672 | json_object *json = NULL; | |
3673 | ||
3674 | if (!is_evpn_enabled()) { | |
3675 | if (use_json) | |
3676 | vty_out(vty, "{}\n"); | |
3677 | return; | |
3678 | } | |
3679 | ||
3680 | if (use_json) | |
3681 | json = json_object_new_object(); | |
3682 | ||
3683 | zl3vni = zl3vni_lookup(l3vni); | |
3684 | if (!zl3vni) { | |
3685 | if (use_json) | |
3686 | vty_out(vty, "{}\n"); | |
3687 | else | |
3688 | vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); | |
3689 | return; | |
3690 | } | |
3691 | ||
3692 | n = zl3vni_nh_lookup(zl3vni, ip); | |
3693 | if (!n) { | |
3694 | if (use_json) | |
3695 | vty_out(vty, "{}\n"); | |
3696 | else | |
3697 | vty_out(vty, | |
3698 | "%% Requested next-hop not present for L3-VNI %u", | |
3699 | l3vni); | |
3700 | return; | |
3701 | } | |
3702 | ||
3703 | zl3vni_print_nh(n, vty, json); | |
3704 | ||
3705 | if (use_json) { | |
3706 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3707 | json, JSON_C_TO_STRING_PRETTY)); | |
3708 | json_object_free(json); | |
3709 | } | |
3710 | } | |
3711 | ||
3712 | void zebra_vxlan_print_nh_l3vni(struct vty *vty, vni_t l3vni, bool use_json) | |
3713 | { | |
3714 | uint32_t num_nh; | |
3715 | struct nh_walk_ctx wctx; | |
3716 | json_object *json = NULL; | |
3717 | zebra_l3vni_t *zl3vni = NULL; | |
3718 | ||
3719 | if (!is_evpn_enabled()) | |
3720 | return; | |
3721 | ||
3722 | zl3vni = zl3vni_lookup(l3vni); | |
3723 | if (!zl3vni) { | |
3724 | if (use_json) | |
3725 | vty_out(vty, "{}\n"); | |
3726 | else | |
3727 | vty_out(vty, "%% L3-VNI %u does not exist\n", l3vni); | |
3728 | return; | |
3729 | } | |
3730 | ||
3731 | num_nh = hashcount(zl3vni->nh_table); | |
3732 | if (!num_nh) | |
3733 | return; | |
3734 | ||
3735 | if (use_json) | |
3736 | json = json_object_new_object(); | |
3737 | ||
3738 | wctx.vty = vty; | |
3739 | wctx.json = json; | |
3740 | if (!use_json) { | |
3741 | vty_out(vty, "Number of NH Neighbors known for this VNI: %u\n", | |
3742 | num_nh); | |
3743 | vty_out(vty, "%-15s %-17s\n", "IP", "RMAC"); | |
3744 | } else | |
3745 | json_object_int_add(json, "numNextHops", num_nh); | |
3746 | ||
3747 | hash_iterate(zl3vni->nh_table, zl3vni_print_nh_hash, &wctx); | |
3748 | ||
3749 | if (use_json) { | |
3750 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3751 | json, JSON_C_TO_STRING_PRETTY)); | |
3752 | json_object_free(json); | |
3753 | } | |
3754 | } | |
3755 | ||
3756 | void zebra_vxlan_print_nh_all_l3vni(struct vty *vty, bool use_json) | |
3757 | { | |
3758 | json_object *json = NULL; | |
3759 | void *args[2]; | |
3760 | ||
3761 | if (!is_evpn_enabled()) { | |
3762 | if (use_json) | |
3763 | vty_out(vty, "{}\n"); | |
3764 | return; | |
3765 | } | |
3766 | ||
3767 | if (use_json) | |
3768 | json = json_object_new_object(); | |
3769 | ||
3770 | args[0] = vty; | |
3771 | args[1] = json; | |
3772 | hash_iterate(zrouter.l3vni_table, | |
3773 | (void (*)(struct hash_bucket *, | |
3774 | void *))zl3vni_print_nh_hash_all_vni, | |
3775 | args); | |
3776 | ||
3777 | if (use_json) { | |
3778 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3779 | json, JSON_C_TO_STRING_PRETTY)); | |
3780 | json_object_free(json); | |
3781 | } | |
3782 | } | |
3783 | ||
3784 | /* | |
3785 | * Display L3 VNI information (VTY command handler). | |
3786 | */ | |
3787 | void zebra_vxlan_print_l3vni(struct vty *vty, vni_t vni, bool use_json) | |
3788 | { | |
3789 | void *args[2]; | |
3790 | json_object *json = NULL; | |
3791 | zebra_l3vni_t *zl3vni = NULL; | |
3792 | ||
3793 | if (!is_evpn_enabled()) { | |
3794 | if (use_json) | |
3795 | vty_out(vty, "{}\n"); | |
3796 | return; | |
3797 | } | |
3798 | ||
3799 | zl3vni = zl3vni_lookup(vni); | |
3800 | if (!zl3vni) { | |
3801 | if (use_json) | |
3802 | vty_out(vty, "{}\n"); | |
3803 | else | |
3804 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
3805 | return; | |
3806 | } | |
3807 | ||
3808 | if (use_json) | |
3809 | json = json_object_new_object(); | |
3810 | ||
3811 | args[0] = vty; | |
3812 | args[1] = json; | |
3813 | zl3vni_print(zl3vni, (void *)args); | |
3814 | ||
3815 | if (use_json) { | |
3816 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3817 | json, JSON_C_TO_STRING_PRETTY)); | |
3818 | json_object_free(json); | |
3819 | } | |
3820 | } | |
3821 | ||
3822 | void zebra_vxlan_print_vrf_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
3823 | json_object *json_vrfs) | |
3824 | { | |
3825 | char buf[ETHER_ADDR_STRLEN]; | |
3826 | zebra_l3vni_t *zl3vni = NULL; | |
3827 | ||
3828 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
3829 | if (!zl3vni) | |
3830 | return; | |
3831 | ||
3832 | if (!json_vrfs) { | |
3833 | vty_out(vty, "%-37s %-10u %-20s %-20s %-5s %-18s\n", | |
3834 | zvrf_name(zvrf), zl3vni->vni, | |
3835 | zl3vni_vxlan_if_name(zl3vni), | |
3836 | zl3vni_svi_if_name(zl3vni), zl3vni_state2str(zl3vni), | |
3837 | zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); | |
3838 | } else { | |
3839 | json_object *json_vrf = NULL; | |
3840 | ||
3841 | json_vrf = json_object_new_object(); | |
3842 | json_object_string_add(json_vrf, "vrf", zvrf_name(zvrf)); | |
3843 | json_object_int_add(json_vrf, "vni", zl3vni->vni); | |
3844 | json_object_string_add(json_vrf, "vxlanIntf", | |
3845 | zl3vni_vxlan_if_name(zl3vni)); | |
3846 | json_object_string_add(json_vrf, "sviIntf", | |
3847 | zl3vni_svi_if_name(zl3vni)); | |
3848 | json_object_string_add(json_vrf, "state", | |
3849 | zl3vni_state2str(zl3vni)); | |
3850 | json_object_string_add( | |
3851 | json_vrf, "routerMac", | |
3852 | zl3vni_rmac2str(zl3vni, buf, sizeof(buf))); | |
3853 | json_object_array_add(json_vrfs, json_vrf); | |
3854 | } | |
3855 | } | |
3856 | ||
3857 | /* | |
3858 | * Display Neighbors for a VNI (VTY command handler). | |
3859 | */ | |
3860 | void zebra_vxlan_print_neigh_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
3861 | vni_t vni, bool use_json) | |
3862 | { | |
3863 | zebra_evpn_t *zevpn; | |
3864 | uint32_t num_neigh; | |
3865 | struct neigh_walk_ctx wctx; | |
3866 | json_object *json = NULL; | |
3867 | ||
3868 | if (!is_evpn_enabled()) | |
3869 | return; | |
3870 | zevpn = zevpn_lookup(vni); | |
3871 | if (!zevpn) { | |
3872 | if (use_json) | |
3873 | vty_out(vty, "{}\n"); | |
3874 | else | |
3875 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
3876 | return; | |
3877 | } | |
3878 | num_neigh = hashcount(zevpn->neigh_table); | |
3879 | if (!num_neigh) | |
3880 | return; | |
3881 | ||
3882 | if (use_json) | |
3883 | json = json_object_new_object(); | |
3884 | ||
3885 | /* Since we have IPv6 addresses to deal with which can vary widely in | |
3886 | * size, we try to be a bit more elegant in display by first computing | |
3887 | * the maximum width. | |
3888 | */ | |
3889 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); | |
3890 | wctx.zevpn = zevpn; | |
3891 | wctx.vty = vty; | |
3892 | wctx.addr_width = 15; | |
3893 | wctx.json = json; | |
3894 | hash_iterate(zevpn->neigh_table, zebra_evpn_find_neigh_addr_width, | |
3895 | &wctx); | |
3896 | ||
3897 | if (!use_json) { | |
3898 | vty_out(vty, | |
3899 | "Number of ARPs (local and remote) known for this VNI: %u\n", | |
3900 | num_neigh); | |
3901 | zebra_evpn_print_neigh_hdr(vty, &wctx); | |
3902 | } else | |
3903 | json_object_int_add(json, "numArpNd", num_neigh); | |
3904 | ||
3905 | hash_iterate(zevpn->neigh_table, zebra_evpn_print_neigh_hash, &wctx); | |
3906 | if (use_json) { | |
3907 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3908 | json, JSON_C_TO_STRING_PRETTY)); | |
3909 | json_object_free(json); | |
3910 | } | |
3911 | } | |
3912 | ||
3913 | /* | |
3914 | * Display neighbors across all VNIs (VTY command handler). | |
3915 | */ | |
3916 | void zebra_vxlan_print_neigh_all_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
3917 | bool print_dup, bool use_json) | |
3918 | { | |
3919 | json_object *json = NULL; | |
3920 | void *args[3]; | |
3921 | ||
3922 | if (!is_evpn_enabled()) | |
3923 | return; | |
3924 | ||
3925 | if (use_json) | |
3926 | json = json_object_new_object(); | |
3927 | ||
3928 | args[0] = vty; | |
3929 | args[1] = json; | |
3930 | args[2] = (void *)(ptrdiff_t)print_dup; | |
3931 | ||
3932 | hash_iterate(zvrf->evpn_table, | |
3933 | (void (*)(struct hash_bucket *, | |
3934 | void *))zevpn_print_neigh_hash_all_evpn, | |
3935 | args); | |
3936 | if (use_json) { | |
3937 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3938 | json, JSON_C_TO_STRING_PRETTY)); | |
3939 | json_object_free(json); | |
3940 | } | |
3941 | } | |
3942 | ||
3943 | /* | |
3944 | * Display neighbors across all VNIs in detail(VTY command handler). | |
3945 | */ | |
3946 | void zebra_vxlan_print_neigh_all_vni_detail(struct vty *vty, | |
3947 | struct zebra_vrf *zvrf, | |
3948 | bool print_dup, bool use_json) | |
3949 | { | |
3950 | json_object *json = NULL; | |
3951 | void *args[3]; | |
3952 | ||
3953 | if (!is_evpn_enabled()) | |
3954 | return; | |
3955 | ||
3956 | if (use_json) | |
3957 | json = json_object_new_object(); | |
3958 | ||
3959 | args[0] = vty; | |
3960 | args[1] = json; | |
3961 | args[2] = (void *)(ptrdiff_t)print_dup; | |
3962 | ||
3963 | hash_iterate(zvrf->evpn_table, | |
3964 | (void (*)(struct hash_bucket *, | |
3965 | void *))zevpn_print_neigh_hash_all_evpn_detail, | |
3966 | args); | |
3967 | if (use_json) { | |
3968 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
3969 | json, JSON_C_TO_STRING_PRETTY)); | |
3970 | json_object_free(json); | |
3971 | } | |
3972 | } | |
3973 | ||
3974 | /* | |
3975 | * Display specific neighbor for a VNI, if present (VTY command handler). | |
3976 | */ | |
3977 | void zebra_vxlan_print_specific_neigh_vni(struct vty *vty, | |
3978 | struct zebra_vrf *zvrf, vni_t vni, | |
3979 | struct ipaddr *ip, bool use_json) | |
3980 | { | |
3981 | zebra_evpn_t *zevpn; | |
3982 | zebra_neigh_t *n; | |
3983 | json_object *json = NULL; | |
3984 | ||
3985 | if (!is_evpn_enabled()) | |
3986 | return; | |
3987 | zevpn = zevpn_lookup(vni); | |
3988 | if (!zevpn) { | |
3989 | if (use_json) | |
3990 | vty_out(vty, "{}\n"); | |
3991 | else | |
3992 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
3993 | return; | |
3994 | } | |
3995 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
3996 | if (!n) { | |
3997 | if (!use_json) | |
3998 | vty_out(vty, | |
3999 | "%% Requested neighbor does not exist in VNI %u\n", | |
4000 | vni); | |
4001 | return; | |
4002 | } | |
4003 | if (use_json) | |
4004 | json = json_object_new_object(); | |
4005 | ||
4006 | zebra_evpn_print_neigh(n, vty, json); | |
4007 | ||
4008 | if (use_json) { | |
4009 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4010 | json, JSON_C_TO_STRING_PRETTY)); | |
4011 | json_object_free(json); | |
4012 | } | |
4013 | } | |
4014 | ||
4015 | /* | |
4016 | * Display neighbors for a VNI from specific VTEP (VTY command handler). | |
4017 | * By definition, these are remote neighbors. | |
4018 | */ | |
4019 | void zebra_vxlan_print_neigh_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, | |
4020 | vni_t vni, struct in_addr vtep_ip, | |
4021 | bool use_json) | |
4022 | { | |
4023 | zebra_evpn_t *zevpn; | |
4024 | uint32_t num_neigh; | |
4025 | struct neigh_walk_ctx wctx; | |
4026 | json_object *json = NULL; | |
4027 | ||
4028 | if (!is_evpn_enabled()) | |
4029 | return; | |
4030 | zevpn = zevpn_lookup(vni); | |
4031 | if (!zevpn) { | |
4032 | if (use_json) | |
4033 | vty_out(vty, "{}\n"); | |
4034 | else | |
4035 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4036 | return; | |
4037 | } | |
4038 | num_neigh = hashcount(zevpn->neigh_table); | |
4039 | if (!num_neigh) | |
4040 | return; | |
4041 | ||
4042 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); | |
4043 | wctx.zevpn = zevpn; | |
4044 | wctx.vty = vty; | |
4045 | wctx.addr_width = 15; | |
4046 | wctx.flags = SHOW_REMOTE_NEIGH_FROM_VTEP; | |
4047 | wctx.r_vtep_ip = vtep_ip; | |
4048 | wctx.json = json; | |
4049 | hash_iterate(zevpn->neigh_table, zebra_evpn_find_neigh_addr_width, | |
4050 | &wctx); | |
4051 | hash_iterate(zevpn->neigh_table, zebra_evpn_print_neigh_hash, &wctx); | |
4052 | ||
4053 | if (use_json) { | |
4054 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4055 | json, JSON_C_TO_STRING_PRETTY)); | |
4056 | json_object_free(json); | |
4057 | } | |
4058 | } | |
4059 | ||
4060 | /* | |
4061 | * Display Duplicate detected Neighbors for a VNI | |
4062 | * (VTY command handler). | |
4063 | */ | |
4064 | void zebra_vxlan_print_neigh_vni_dad(struct vty *vty, | |
4065 | struct zebra_vrf *zvrf, | |
4066 | vni_t vni, | |
4067 | bool use_json) | |
4068 | { | |
4069 | zebra_evpn_t *zevpn; | |
4070 | uint32_t num_neigh; | |
4071 | struct neigh_walk_ctx wctx; | |
4072 | json_object *json = NULL; | |
4073 | ||
4074 | if (!is_evpn_enabled()) | |
4075 | return; | |
4076 | ||
4077 | zevpn = zevpn_lookup(vni); | |
4078 | if (!zevpn) { | |
4079 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4080 | return; | |
4081 | } | |
4082 | ||
4083 | num_neigh = hashcount(zevpn->neigh_table); | |
4084 | if (!num_neigh) | |
4085 | return; | |
4086 | ||
4087 | num_neigh = num_dup_detected_neighs(zevpn); | |
4088 | if (!num_neigh) | |
4089 | return; | |
4090 | ||
4091 | if (use_json) | |
4092 | json = json_object_new_object(); | |
4093 | ||
4094 | /* Since we have IPv6 addresses to deal with which can vary widely in | |
4095 | * size, we try to be a bit more elegant in display by first computing | |
4096 | * the maximum width. | |
4097 | */ | |
4098 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); | |
4099 | wctx.zevpn = zevpn; | |
4100 | wctx.vty = vty; | |
4101 | wctx.addr_width = 15; | |
4102 | wctx.json = json; | |
4103 | hash_iterate(zevpn->neigh_table, zebra_evpn_find_neigh_addr_width, | |
4104 | &wctx); | |
4105 | ||
4106 | if (!use_json) { | |
4107 | vty_out(vty, | |
4108 | "Number of ARPs (local and remote) known for this VNI: %u\n", | |
4109 | num_neigh); | |
4110 | vty_out(vty, "%*s %-6s %-8s %-17s %-30s\n", | |
4111 | -wctx.addr_width, "IP", "Type", | |
4112 | "State", "MAC", "Remote ES/VTEP"); | |
4113 | } else | |
4114 | json_object_int_add(json, "numArpNd", num_neigh); | |
4115 | ||
4116 | hash_iterate(zevpn->neigh_table, zebra_evpn_print_dad_neigh_hash, | |
4117 | &wctx); | |
4118 | ||
4119 | if (use_json) { | |
4120 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4121 | json, JSON_C_TO_STRING_PRETTY)); | |
4122 | json_object_free(json); | |
4123 | } | |
4124 | } | |
4125 | ||
4126 | /* | |
4127 | * Display MACs for a VNI (VTY command handler). | |
4128 | */ | |
4129 | void zebra_vxlan_print_macs_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
4130 | vni_t vni, bool use_json) | |
4131 | { | |
4132 | zebra_evpn_t *zevpn; | |
4133 | uint32_t num_macs; | |
4134 | struct mac_walk_ctx wctx; | |
4135 | json_object *json = NULL; | |
4136 | json_object *json_mac = NULL; | |
4137 | ||
4138 | if (!is_evpn_enabled()) | |
4139 | return; | |
4140 | zevpn = zevpn_lookup(vni); | |
4141 | if (!zevpn) { | |
4142 | if (use_json) | |
4143 | vty_out(vty, "{}\n"); | |
4144 | else | |
4145 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4146 | return; | |
4147 | } | |
4148 | num_macs = num_valid_macs(zevpn); | |
4149 | if (!num_macs) | |
4150 | return; | |
4151 | ||
4152 | if (use_json) { | |
4153 | json = json_object_new_object(); | |
4154 | json_mac = json_object_new_object(); | |
4155 | } | |
4156 | ||
4157 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4158 | wctx.zevpn = zevpn; | |
4159 | wctx.vty = vty; | |
4160 | wctx.json = json_mac; | |
4161 | ||
4162 | if (!use_json) { | |
4163 | vty_out(vty, | |
4164 | "Number of MACs (local and remote) known for this VNI: %u\n", | |
4165 | num_macs); | |
4166 | vty_out(vty, | |
4167 | "Flags: N=sync-neighs, I=local-inactive, P=peer-active, X=peer-proxy\n"); | |
4168 | vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %s\n", "MAC", | |
4169 | "Type", "Flags", "Intf/Remote ES/VTEP", | |
4170 | "VLAN", "Seq #'s"); | |
4171 | } else | |
4172 | json_object_int_add(json, "numMacs", num_macs); | |
4173 | ||
4174 | hash_iterate(zevpn->mac_table, zebra_evpn_print_mac_hash, &wctx); | |
4175 | ||
4176 | if (use_json) { | |
4177 | json_object_object_add(json, "macs", json_mac); | |
4178 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4179 | json, JSON_C_TO_STRING_PRETTY)); | |
4180 | json_object_free(json); | |
4181 | } | |
4182 | } | |
4183 | ||
4184 | /* | |
4185 | * Display MACs for all VNIs (VTY command handler). | |
4186 | */ | |
4187 | void zebra_vxlan_print_macs_all_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
4188 | bool print_dup, bool use_json) | |
4189 | { | |
4190 | struct mac_walk_ctx wctx; | |
4191 | json_object *json = NULL; | |
4192 | ||
4193 | if (!is_evpn_enabled()) { | |
4194 | if (use_json) | |
4195 | vty_out(vty, "{}\n"); | |
4196 | return; | |
4197 | } | |
4198 | if (use_json) | |
4199 | json = json_object_new_object(); | |
4200 | ||
4201 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4202 | wctx.vty = vty; | |
4203 | wctx.json = json; | |
4204 | wctx.print_dup = print_dup; | |
4205 | hash_iterate(zvrf->evpn_table, zevpn_print_mac_hash_all_evpn, &wctx); | |
4206 | ||
4207 | if (use_json) { | |
4208 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4209 | json, JSON_C_TO_STRING_PRETTY)); | |
4210 | json_object_free(json); | |
4211 | } | |
4212 | } | |
4213 | ||
4214 | /* | |
4215 | * Display MACs in detail for all VNIs (VTY command handler). | |
4216 | */ | |
4217 | void zebra_vxlan_print_macs_all_vni_detail(struct vty *vty, | |
4218 | struct zebra_vrf *zvrf, | |
4219 | bool print_dup, bool use_json) | |
4220 | { | |
4221 | struct mac_walk_ctx wctx; | |
4222 | json_object *json = NULL; | |
4223 | ||
4224 | if (!is_evpn_enabled()) { | |
4225 | if (use_json) | |
4226 | vty_out(vty, "{}\n"); | |
4227 | return; | |
4228 | } | |
4229 | if (use_json) | |
4230 | json = json_object_new_object(); | |
4231 | ||
4232 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4233 | wctx.vty = vty; | |
4234 | wctx.json = json; | |
4235 | wctx.print_dup = print_dup; | |
4236 | hash_iterate(zvrf->evpn_table, zevpn_print_mac_hash_all_evpn_detail, | |
4237 | &wctx); | |
4238 | ||
4239 | if (use_json) { | |
4240 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4241 | json, JSON_C_TO_STRING_PRETTY)); | |
4242 | json_object_free(json); | |
4243 | } | |
4244 | } | |
4245 | ||
4246 | /* | |
4247 | * Display MACs for all VNIs (VTY command handler). | |
4248 | */ | |
4249 | void zebra_vxlan_print_macs_all_vni_vtep(struct vty *vty, | |
4250 | struct zebra_vrf *zvrf, | |
4251 | struct in_addr vtep_ip, bool use_json) | |
4252 | { | |
4253 | struct mac_walk_ctx wctx; | |
4254 | json_object *json = NULL; | |
4255 | ||
4256 | if (!is_evpn_enabled()) | |
4257 | return; | |
4258 | ||
4259 | if (use_json) | |
4260 | json = json_object_new_object(); | |
4261 | ||
4262 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4263 | wctx.vty = vty; | |
4264 | wctx.flags = SHOW_REMOTE_MAC_FROM_VTEP; | |
4265 | wctx.r_vtep_ip = vtep_ip; | |
4266 | wctx.json = json; | |
4267 | hash_iterate(zvrf->evpn_table, zevpn_print_mac_hash_all_evpn, &wctx); | |
4268 | ||
4269 | if (use_json) { | |
4270 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4271 | json, JSON_C_TO_STRING_PRETTY)); | |
4272 | json_object_free(json); | |
4273 | } | |
4274 | } | |
4275 | ||
4276 | /* | |
4277 | * Display specific MAC for a VNI, if present (VTY command handler). | |
4278 | */ | |
4279 | void zebra_vxlan_print_specific_mac_vni(struct vty *vty, struct zebra_vrf *zvrf, | |
4280 | vni_t vni, struct ethaddr *macaddr, | |
4281 | bool use_json) | |
4282 | { | |
4283 | zebra_evpn_t *zevpn; | |
4284 | zebra_mac_t *mac; | |
4285 | json_object *json = NULL; | |
4286 | ||
4287 | if (!is_evpn_enabled()) | |
4288 | return; | |
4289 | ||
4290 | zevpn = zevpn_lookup(vni); | |
4291 | if (!zevpn) { | |
4292 | if (use_json) | |
4293 | vty_out(vty, "{}\n"); | |
4294 | else | |
4295 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4296 | return; | |
4297 | } | |
4298 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
4299 | if (!mac) { | |
4300 | if (use_json) | |
4301 | vty_out(vty, "{}\n"); | |
4302 | else | |
4303 | vty_out(vty, | |
4304 | "%% Requested MAC does not exist in VNI %u\n", | |
4305 | vni); | |
4306 | return; | |
4307 | } | |
4308 | ||
4309 | if (use_json) | |
4310 | json = json_object_new_object(); | |
4311 | ||
4312 | zebra_evpn_print_mac(mac, vty, json); | |
4313 | if (use_json) { | |
4314 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4315 | json, JSON_C_TO_STRING_PRETTY)); | |
4316 | json_object_free(json); | |
4317 | } | |
4318 | } | |
4319 | ||
4320 | /* Print Duplicate MACs per VNI */ | |
4321 | void zebra_vxlan_print_macs_vni_dad(struct vty *vty, | |
4322 | struct zebra_vrf *zvrf, | |
4323 | vni_t vni, bool use_json) | |
4324 | { | |
4325 | zebra_evpn_t *zevpn; | |
4326 | struct mac_walk_ctx wctx; | |
4327 | uint32_t num_macs; | |
4328 | json_object *json = NULL; | |
4329 | json_object *json_mac = NULL; | |
4330 | ||
4331 | if (!is_evpn_enabled()) | |
4332 | return; | |
4333 | ||
4334 | zevpn = zevpn_lookup(vni); | |
4335 | if (!zevpn) { | |
4336 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4337 | return; | |
4338 | } | |
4339 | ||
4340 | num_macs = num_valid_macs(zevpn); | |
4341 | if (!num_macs) | |
4342 | return; | |
4343 | ||
4344 | num_macs = num_dup_detected_macs(zevpn); | |
4345 | if (!num_macs) | |
4346 | return; | |
4347 | ||
4348 | if (use_json) { | |
4349 | json = json_object_new_object(); | |
4350 | json_mac = json_object_new_object(); | |
4351 | } | |
4352 | ||
4353 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4354 | wctx.zevpn = zevpn; | |
4355 | wctx.vty = vty; | |
4356 | wctx.json = json_mac; | |
4357 | ||
4358 | if (!use_json) { | |
4359 | vty_out(vty, | |
4360 | "Number of MACs (local and remote) known for this VNI: %u\n", | |
4361 | num_macs); | |
4362 | vty_out(vty, "%-17s %-6s %-5s %-30s %-5s\n", "MAC", "Type", | |
4363 | "Flags", "Intf/Remote ES/VTEP", "VLAN"); | |
4364 | } else | |
4365 | json_object_int_add(json, "numMacs", num_macs); | |
4366 | ||
4367 | hash_iterate(zevpn->mac_table, zebra_evpn_print_dad_mac_hash, &wctx); | |
4368 | ||
4369 | if (use_json) { | |
4370 | json_object_object_add(json, "macs", json_mac); | |
4371 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4372 | json, JSON_C_TO_STRING_PRETTY)); | |
4373 | json_object_free(json); | |
4374 | } | |
4375 | ||
4376 | } | |
4377 | ||
4378 | int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni, | |
4379 | struct ethaddr *macaddr) | |
4380 | { | |
4381 | zebra_evpn_t *zevpn; | |
4382 | zebra_mac_t *mac; | |
4383 | struct listnode *node = NULL; | |
4384 | zebra_neigh_t *nbr = NULL; | |
4385 | ||
4386 | if (!is_evpn_enabled()) | |
4387 | return 0; | |
4388 | ||
4389 | zevpn = zevpn_lookup(vni); | |
4390 | if (!zevpn) { | |
4391 | zlog_warn("VNI %u does not exist\n", vni); | |
4392 | return -1; | |
4393 | } | |
4394 | ||
4395 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
4396 | if (!mac) { | |
4397 | zlog_warn("Requested MAC does not exist in VNI %u\n", vni); | |
4398 | return -1; | |
4399 | } | |
4400 | ||
4401 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) { | |
4402 | zlog_warn("Requested MAC is not duplicate detected\n"); | |
4403 | return -1; | |
4404 | } | |
4405 | ||
4406 | /* Remove all IPs as duplicate associcated with this MAC */ | |
4407 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) { | |
4408 | /* For local neigh mark inactive so MACIP update is generated | |
4409 | * to BGP. This is a scenario where MAC update received | |
4410 | * and detected as duplicate which marked neigh as duplicate. | |
4411 | * Later local neigh update did not get a chance to relay | |
4412 | * to BGP. Similarly remote macip update, neigh needs to be | |
4413 | * installed locally. | |
4414 | */ | |
4415 | if (zvrf->dad_freeze && | |
4416 | CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { | |
4417 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) | |
4418 | ZEBRA_NEIGH_SET_INACTIVE(nbr); | |
4419 | else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) | |
4420 | zebra_evpn_rem_neigh_install( | |
4421 | zevpn, nbr, false /*was_static*/); | |
4422 | } | |
4423 | ||
4424 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
4425 | nbr->dad_count = 0; | |
4426 | nbr->detect_start_time.tv_sec = 0; | |
4427 | nbr->dad_dup_detect_time = 0; | |
4428 | } | |
4429 | ||
4430 | UNSET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE); | |
4431 | mac->dad_count = 0; | |
4432 | mac->detect_start_time.tv_sec = 0; | |
4433 | mac->detect_start_time.tv_usec = 0; | |
4434 | mac->dad_dup_detect_time = 0; | |
4435 | THREAD_OFF(mac->dad_mac_auto_recovery_timer); | |
4436 | ||
4437 | /* warn-only action return */ | |
4438 | if (!zvrf->dad_freeze) | |
4439 | return 0; | |
4440 | ||
4441 | /* Local: Notify Peer VTEPs, Remote: Install the entry */ | |
4442 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
4443 | /* Inform to BGP */ | |
4444 | if (zebra_evpn_mac_send_add_to_client(zevpn->vni, &mac->macaddr, | |
4445 | mac->flags, mac->loc_seq, | |
4446 | mac->es)) | |
4447 | return 0; | |
4448 | ||
4449 | /* Process all neighbors associated with this MAC. */ | |
4450 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0, | |
4451 | 0 /*es_change*/); | |
4452 | ||
4453 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
4454 | zebra_evpn_process_neigh_on_remote_mac_add(zevpn, mac); | |
4455 | ||
4456 | /* Install the entry. */ | |
4457 | zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */); | |
4458 | } | |
4459 | ||
4460 | return 0; | |
4461 | } | |
4462 | ||
4463 | int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf, vni_t vni, | |
4464 | struct ipaddr *ip) | |
4465 | { | |
4466 | zebra_evpn_t *zevpn; | |
4467 | zebra_neigh_t *nbr; | |
4468 | zebra_mac_t *mac; | |
4469 | char buf[INET6_ADDRSTRLEN]; | |
4470 | char buf2[ETHER_ADDR_STRLEN]; | |
4471 | ||
4472 | if (!is_evpn_enabled()) | |
4473 | return 0; | |
4474 | ||
4475 | zevpn = zevpn_lookup(vni); | |
4476 | if (!zevpn) { | |
4477 | zlog_debug("VNI %u does not exist\n", vni); | |
4478 | return -1; | |
4479 | } | |
4480 | ||
4481 | nbr = zebra_evpn_neigh_lookup(zevpn, ip); | |
4482 | if (!nbr) { | |
4483 | zlog_warn("Requested host IP does not exist in VNI %u\n", vni); | |
4484 | return -1; | |
4485 | } | |
4486 | ||
4487 | ipaddr2str(&nbr->ip, buf, sizeof(buf)); | |
4488 | ||
4489 | if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { | |
4490 | zlog_warn("Requested host IP %s is not duplicate detected\n", | |
4491 | buf); | |
4492 | return -1; | |
4493 | } | |
4494 | ||
4495 | mac = zebra_evpn_mac_lookup(zevpn, &nbr->emac); | |
4496 | ||
4497 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) { | |
4498 | zlog_warn( | |
4499 | "Requested IP's associated MAC %s is still in duplicate state\n", | |
4500 | prefix_mac2str(&nbr->emac, buf2, sizeof(buf2))); | |
4501 | return -1; | |
4502 | } | |
4503 | ||
4504 | if (IS_ZEBRA_DEBUG_VXLAN) | |
4505 | zlog_debug("%s: clear neigh %s in dup state, flags 0x%x seq %u", | |
4506 | __func__, buf, nbr->flags, nbr->loc_seq); | |
4507 | ||
4508 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
4509 | nbr->dad_count = 0; | |
4510 | nbr->detect_start_time.tv_sec = 0; | |
4511 | nbr->detect_start_time.tv_usec = 0; | |
4512 | nbr->dad_dup_detect_time = 0; | |
4513 | THREAD_OFF(nbr->dad_ip_auto_recovery_timer); | |
4514 | ||
4515 | if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) { | |
4516 | zebra_evpn_neigh_send_add_to_client(zevpn->vni, ip, &nbr->emac, | |
4517 | nbr->mac, nbr->flags, | |
4518 | nbr->loc_seq); | |
4519 | } else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { | |
4520 | zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); | |
4521 | } | |
4522 | ||
4523 | return 0; | |
4524 | } | |
4525 | ||
4526 | static void zevpn_clear_dup_mac_hash(struct hash_bucket *bucket, void *ctxt) | |
4527 | { | |
4528 | struct mac_walk_ctx *wctx = ctxt; | |
4529 | zebra_mac_t *mac; | |
4530 | zebra_evpn_t *zevpn; | |
4531 | struct listnode *node = NULL; | |
4532 | zebra_neigh_t *nbr = NULL; | |
4533 | ||
4534 | mac = (zebra_mac_t *)bucket->data; | |
4535 | if (!mac) | |
4536 | return; | |
4537 | ||
4538 | zevpn = wctx->zevpn; | |
4539 | ||
4540 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) | |
4541 | return; | |
4542 | ||
4543 | UNSET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE); | |
4544 | mac->dad_count = 0; | |
4545 | mac->detect_start_time.tv_sec = 0; | |
4546 | mac->detect_start_time.tv_usec = 0; | |
4547 | mac->dad_dup_detect_time = 0; | |
4548 | THREAD_OFF(mac->dad_mac_auto_recovery_timer); | |
4549 | ||
4550 | /* Remove all IPs as duplicate associcated with this MAC */ | |
4551 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) { | |
4552 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL) | |
4553 | && nbr->dad_count) | |
4554 | ZEBRA_NEIGH_SET_INACTIVE(nbr); | |
4555 | ||
4556 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
4557 | nbr->dad_count = 0; | |
4558 | nbr->detect_start_time.tv_sec = 0; | |
4559 | nbr->dad_dup_detect_time = 0; | |
4560 | } | |
4561 | ||
4562 | /* Local: Notify Peer VTEPs, Remote: Install the entry */ | |
4563 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
4564 | /* Inform to BGP */ | |
4565 | if (zebra_evpn_mac_send_add_to_client(zevpn->vni, &mac->macaddr, | |
4566 | mac->flags, mac->loc_seq, | |
4567 | mac->es)) | |
4568 | return; | |
4569 | ||
4570 | /* Process all neighbors associated with this MAC. */ | |
4571 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0, | |
4572 | 0 /*es_change*/); | |
4573 | ||
4574 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
4575 | zebra_evpn_process_neigh_on_remote_mac_add(zevpn, mac); | |
4576 | ||
4577 | /* Install the entry. */ | |
4578 | zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */); | |
4579 | } | |
4580 | } | |
4581 | ||
4582 | static void zevpn_clear_dup_detect_hash_vni_all(struct hash_bucket *bucket, | |
4583 | void **args) | |
4584 | { | |
4585 | zebra_evpn_t *zevpn; | |
4586 | struct zebra_vrf *zvrf; | |
4587 | struct mac_walk_ctx m_wctx; | |
4588 | struct neigh_walk_ctx n_wctx; | |
4589 | ||
4590 | zevpn = (zebra_evpn_t *)bucket->data; | |
4591 | if (!zevpn) | |
4592 | return; | |
4593 | ||
4594 | zvrf = (struct zebra_vrf *)args[0]; | |
4595 | ||
4596 | if (hashcount(zevpn->neigh_table)) { | |
4597 | memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); | |
4598 | n_wctx.zevpn = zevpn; | |
4599 | n_wctx.zvrf = zvrf; | |
4600 | hash_iterate(zevpn->neigh_table, | |
4601 | zebra_evpn_clear_dup_neigh_hash, &n_wctx); | |
4602 | } | |
4603 | ||
4604 | if (num_valid_macs(zevpn)) { | |
4605 | memset(&m_wctx, 0, sizeof(struct mac_walk_ctx)); | |
4606 | m_wctx.zevpn = zevpn; | |
4607 | m_wctx.zvrf = zvrf; | |
4608 | hash_iterate(zevpn->mac_table, zevpn_clear_dup_mac_hash, &m_wctx); | |
4609 | } | |
4610 | ||
4611 | } | |
4612 | ||
4613 | int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf *zvrf) | |
4614 | { | |
4615 | void *args[1]; | |
4616 | ||
4617 | if (!is_evpn_enabled()) | |
4618 | return 0; | |
4619 | ||
4620 | args[0] = zvrf; | |
4621 | ||
4622 | hash_iterate(zvrf->evpn_table, | |
4623 | (void (*)(struct hash_bucket *, void *)) | |
4624 | zevpn_clear_dup_detect_hash_vni_all, args); | |
4625 | ||
4626 | return 0; | |
4627 | } | |
4628 | ||
4629 | int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf *zvrf, vni_t vni) | |
4630 | { | |
4631 | zebra_evpn_t *zevpn; | |
4632 | struct mac_walk_ctx m_wctx; | |
4633 | struct neigh_walk_ctx n_wctx; | |
4634 | ||
4635 | if (!is_evpn_enabled()) | |
4636 | return 0; | |
4637 | ||
4638 | zevpn = zevpn_lookup(vni); | |
4639 | if (!zevpn) { | |
4640 | zlog_warn("VNI %u does not exist\n", vni); | |
4641 | return CMD_WARNING; | |
4642 | } | |
4643 | ||
4644 | if (hashcount(zevpn->neigh_table)) { | |
4645 | memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); | |
4646 | n_wctx.zevpn = zevpn; | |
4647 | n_wctx.zvrf = zvrf; | |
4648 | hash_iterate(zevpn->neigh_table, | |
4649 | zebra_evpn_clear_dup_neigh_hash, &n_wctx); | |
4650 | } | |
4651 | ||
4652 | if (num_valid_macs(zevpn)) { | |
4653 | memset(&m_wctx, 0, sizeof(struct mac_walk_ctx)); | |
4654 | m_wctx.zevpn = zevpn; | |
4655 | m_wctx.zvrf = zvrf; | |
4656 | hash_iterate(zevpn->mac_table, zevpn_clear_dup_mac_hash, &m_wctx); | |
4657 | } | |
4658 | ||
4659 | return 0; | |
4660 | } | |
4661 | ||
4662 | /* | |
4663 | * Display MACs for a VNI from specific VTEP (VTY command handler). | |
4664 | */ | |
4665 | void zebra_vxlan_print_macs_vni_vtep(struct vty *vty, struct zebra_vrf *zvrf, | |
4666 | vni_t vni, struct in_addr vtep_ip, | |
4667 | bool use_json) | |
4668 | { | |
4669 | zebra_evpn_t *zevpn; | |
4670 | uint32_t num_macs; | |
4671 | struct mac_walk_ctx wctx; | |
4672 | json_object *json = NULL; | |
4673 | json_object *json_mac = NULL; | |
4674 | ||
4675 | if (!is_evpn_enabled()) | |
4676 | return; | |
4677 | zevpn = zevpn_lookup(vni); | |
4678 | if (!zevpn) { | |
4679 | if (use_json) | |
4680 | vty_out(vty, "{}\n"); | |
4681 | else | |
4682 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4683 | return; | |
4684 | } | |
4685 | num_macs = num_valid_macs(zevpn); | |
4686 | if (!num_macs) | |
4687 | return; | |
4688 | ||
4689 | if (use_json) { | |
4690 | json = json_object_new_object(); | |
4691 | json_mac = json_object_new_object(); | |
4692 | } | |
4693 | ||
4694 | memset(&wctx, 0, sizeof(struct mac_walk_ctx)); | |
4695 | wctx.zevpn = zevpn; | |
4696 | wctx.vty = vty; | |
4697 | wctx.flags = SHOW_REMOTE_MAC_FROM_VTEP; | |
4698 | wctx.r_vtep_ip = vtep_ip; | |
4699 | wctx.json = json_mac; | |
4700 | hash_iterate(zevpn->mac_table, zebra_evpn_print_mac_hash, &wctx); | |
4701 | ||
4702 | if (use_json) { | |
4703 | json_object_int_add(json, "numMacs", wctx.count); | |
4704 | if (wctx.count) | |
4705 | json_object_object_add(json, "macs", json_mac); | |
4706 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4707 | json, JSON_C_TO_STRING_PRETTY)); | |
4708 | json_object_free(json); | |
4709 | } | |
4710 | } | |
4711 | ||
4712 | ||
4713 | /* | |
4714 | * Display VNI information (VTY command handler). | |
4715 | * | |
4716 | * use_json flag indicates that output should be in JSON format. | |
4717 | * json_array is non NULL when JSON output needs to be aggregated (by the | |
4718 | * caller) and then printed, otherwise, JSON evpn vni info is printed | |
4719 | * right away. | |
4720 | */ | |
4721 | void zebra_vxlan_print_vni(struct vty *vty, struct zebra_vrf *zvrf, vni_t vni, | |
4722 | bool use_json, json_object *json_array) | |
4723 | { | |
4724 | json_object *json = NULL; | |
4725 | void *args[2]; | |
4726 | zebra_l3vni_t *zl3vni = NULL; | |
4727 | zebra_evpn_t *zevpn = NULL; | |
4728 | ||
4729 | if (!is_evpn_enabled()) | |
4730 | return; | |
4731 | ||
4732 | if (use_json) | |
4733 | json = json_object_new_object(); | |
4734 | ||
4735 | args[0] = vty; | |
4736 | args[1] = json; | |
4737 | ||
4738 | zl3vni = zl3vni_lookup(vni); | |
4739 | if (zl3vni) { | |
4740 | zl3vni_print(zl3vni, (void *)args); | |
4741 | } else { | |
4742 | zevpn = zevpn_lookup(vni); | |
4743 | if (zevpn) | |
4744 | zevpn_print(zevpn, (void *)args); | |
4745 | else if (!json) | |
4746 | vty_out(vty, "%% VNI %u does not exist\n", vni); | |
4747 | } | |
4748 | ||
4749 | if (use_json) { | |
4750 | /* | |
4751 | * Each "json" object contains info about 1 VNI. | |
4752 | * When "json_array" is non-null, we aggreggate the json output | |
4753 | * into json_array and print it as a JSON array. | |
4754 | */ | |
4755 | if (json_array) | |
4756 | json_object_array_add(json_array, json); | |
4757 | else { | |
4758 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4759 | json, JSON_C_TO_STRING_PRETTY)); | |
4760 | json_object_free(json); | |
4761 | } | |
4762 | } | |
4763 | } | |
4764 | ||
4765 | /* Display all global details for EVPN */ | |
4766 | void zebra_vxlan_print_evpn(struct vty *vty, bool uj) | |
4767 | { | |
4768 | int num_l2vnis = 0; | |
4769 | int num_l3vnis = 0; | |
4770 | int num_vnis = 0; | |
4771 | json_object *json = NULL; | |
4772 | struct zebra_vrf *zvrf = NULL; | |
4773 | ||
4774 | if (!is_evpn_enabled()) | |
4775 | return; | |
4776 | ||
4777 | zvrf = zebra_vrf_get_evpn(); | |
4778 | if (!zvrf) | |
4779 | return; | |
4780 | ||
4781 | num_l3vnis = hashcount(zrouter.l3vni_table); | |
4782 | num_l2vnis = hashcount(zvrf->evpn_table); | |
4783 | num_vnis = num_l2vnis + num_l3vnis; | |
4784 | ||
4785 | if (uj) { | |
4786 | json = json_object_new_object(); | |
4787 | json_object_string_add(json, "advertiseGatewayMacip", | |
4788 | zvrf->advertise_gw_macip ? "Yes" : "No"); | |
4789 | json_object_int_add(json, "numVnis", num_vnis); | |
4790 | json_object_int_add(json, "numL2Vnis", num_l2vnis); | |
4791 | json_object_int_add(json, "numL3Vnis", num_l3vnis); | |
4792 | if (zvrf->dup_addr_detect) | |
4793 | json_object_boolean_true_add(json, | |
4794 | "isDuplicateAddrDetection"); | |
4795 | else | |
4796 | json_object_boolean_false_add(json, | |
4797 | "isDuplicateAddrDetection"); | |
4798 | json_object_int_add(json, "maxMoves", zvrf->dad_max_moves); | |
4799 | json_object_int_add(json, "detectionTime", zvrf->dad_time); | |
4800 | json_object_int_add(json, "detectionFreezeTime", | |
4801 | zvrf->dad_freeze_time); | |
4802 | ||
4803 | } else { | |
4804 | vty_out(vty, "L2 VNIs: %u\n", num_l2vnis); | |
4805 | vty_out(vty, "L3 VNIs: %u\n", num_l3vnis); | |
4806 | vty_out(vty, "Advertise gateway mac-ip: %s\n", | |
4807 | zvrf->advertise_gw_macip ? "Yes" : "No"); | |
4808 | vty_out(vty, "Advertise svi mac-ip: %s\n", | |
4809 | zvrf->advertise_svi_macip ? "Yes" : "No"); | |
4810 | vty_out(vty, "Duplicate address detection: %s\n", | |
4811 | zvrf->dup_addr_detect ? "Enable" : "Disable"); | |
4812 | vty_out(vty, " Detection max-moves %u, time %d\n", | |
4813 | zvrf->dad_max_moves, zvrf->dad_time); | |
4814 | if (zvrf->dad_freeze) { | |
4815 | if (zvrf->dad_freeze_time) | |
4816 | vty_out(vty, " Detection freeze %u\n", | |
4817 | zvrf->dad_freeze_time); | |
4818 | else | |
4819 | vty_out(vty, " Detection freeze %s\n", | |
4820 | "permanent"); | |
4821 | } | |
4822 | } | |
4823 | ||
4824 | if (uj) { | |
4825 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4826 | json, JSON_C_TO_STRING_PRETTY)); | |
4827 | json_object_free(json); | |
4828 | } | |
4829 | } | |
4830 | ||
4831 | /* | |
4832 | * Display VNI hash table (VTY command handler). | |
4833 | */ | |
4834 | void zebra_vxlan_print_vnis(struct vty *vty, struct zebra_vrf *zvrf, | |
4835 | bool use_json) | |
4836 | { | |
4837 | json_object *json = NULL; | |
4838 | void *args[2]; | |
4839 | ||
4840 | if (!is_evpn_enabled()) | |
4841 | return; | |
4842 | ||
4843 | if (use_json) | |
4844 | json = json_object_new_object(); | |
4845 | else | |
4846 | vty_out(vty, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI", | |
4847 | "Type", "VxLAN IF", "# MACs", "# ARPs", | |
4848 | "# Remote VTEPs", "Tenant VRF"); | |
4849 | ||
4850 | args[0] = vty; | |
4851 | args[1] = json; | |
4852 | ||
4853 | /* Display all L2-VNIs */ | |
4854 | hash_iterate(zvrf->evpn_table, | |
4855 | (void (*)(struct hash_bucket *, void *))zevpn_print_hash, | |
4856 | args); | |
4857 | ||
4858 | /* Display all L3-VNIs */ | |
4859 | hash_iterate(zrouter.l3vni_table, | |
4860 | (void (*)(struct hash_bucket *, void *))zl3vni_print_hash, | |
4861 | args); | |
4862 | ||
4863 | if (use_json) { | |
4864 | vty_out(vty, "%s\n", json_object_to_json_string_ext( | |
4865 | json, JSON_C_TO_STRING_PRETTY)); | |
4866 | json_object_free(json); | |
4867 | } | |
4868 | } | |
4869 | ||
4870 | void zebra_vxlan_dup_addr_detection(ZAPI_HANDLER_ARGS) | |
4871 | { | |
4872 | struct stream *s; | |
4873 | int time = 0; | |
4874 | uint32_t max_moves = 0; | |
4875 | uint32_t freeze_time = 0; | |
4876 | bool dup_addr_detect = false; | |
4877 | bool freeze = false; | |
4878 | ||
4879 | s = msg; | |
4880 | STREAM_GETL(s, dup_addr_detect); | |
4881 | STREAM_GETL(s, time); | |
4882 | STREAM_GETL(s, max_moves); | |
4883 | STREAM_GETL(s, freeze); | |
4884 | STREAM_GETL(s, freeze_time); | |
4885 | ||
4886 | /* DAD previous state was enabled, and new state is disable, | |
4887 | * clear all duplicate detected addresses. | |
4888 | */ | |
4889 | if (zvrf->dup_addr_detect && !dup_addr_detect) | |
4890 | zebra_vxlan_clear_dup_detect_vni_all(zvrf); | |
4891 | ||
4892 | zvrf->dup_addr_detect = dup_addr_detect; | |
4893 | zvrf->dad_time = time; | |
4894 | zvrf->dad_max_moves = max_moves; | |
4895 | zvrf->dad_freeze = freeze; | |
4896 | zvrf->dad_freeze_time = freeze_time; | |
4897 | ||
4898 | if (IS_ZEBRA_DEBUG_VXLAN) | |
4899 | zlog_debug( | |
4900 | "VRF %s duplicate detect %s max_moves %u timeout %u freeze %s freeze_time %u", | |
4901 | vrf_id_to_name(zvrf->vrf->vrf_id), | |
4902 | zvrf->dup_addr_detect ? "enable" : "disable", | |
4903 | zvrf->dad_max_moves, | |
4904 | zvrf->dad_time, | |
4905 | zvrf->dad_freeze ? "enable" : "disable", | |
4906 | zvrf->dad_freeze_time); | |
4907 | ||
4908 | stream_failure: | |
4909 | return; | |
4910 | } | |
4911 | ||
4912 | /* | |
4913 | * Display VNI hash table in detail(VTY command handler). | |
4914 | */ | |
4915 | void zebra_vxlan_print_vnis_detail(struct vty *vty, struct zebra_vrf *zvrf, | |
4916 | bool use_json) | |
4917 | { | |
4918 | json_object *json_array = NULL; | |
4919 | struct zebra_ns *zns = NULL; | |
4920 | struct zevpn_show zes; | |
4921 | ||
4922 | if (!is_evpn_enabled()) | |
4923 | return; | |
4924 | ||
4925 | zns = zebra_ns_lookup(NS_DEFAULT); | |
4926 | if (!zns) | |
4927 | return; | |
4928 | ||
4929 | if (use_json) | |
4930 | json_array = json_object_new_array(); | |
4931 | ||
4932 | zes.vty = vty; | |
4933 | zes.json = json_array; | |
4934 | zes.zvrf = zvrf; | |
4935 | zes.use_json = use_json; | |
4936 | ||
4937 | /* Display all L2-VNIs */ | |
4938 | hash_iterate( | |
4939 | zvrf->evpn_table, | |
4940 | (void (*)(struct hash_bucket *, void *))zevpn_print_hash_detail, | |
4941 | &zes); | |
4942 | ||
4943 | /* Display all L3-VNIs */ | |
4944 | hash_iterate(zrouter.l3vni_table, | |
4945 | (void (*)(struct hash_bucket *, | |
4946 | void *))zl3vni_print_hash_detail, | |
4947 | &zes); | |
4948 | ||
4949 | if (use_json) { | |
4950 | vty_out(vty, "%s\n", | |
4951 | json_object_to_json_string_ext( | |
4952 | json_array, JSON_C_TO_STRING_PRETTY)); | |
4953 | json_object_free(json_array); | |
4954 | } | |
4955 | } | |
4956 | ||
4957 | /* | |
4958 | * Handle neighbor delete notification from the kernel (on a VLAN device | |
4959 | * / L3 interface). This may result in either the neighbor getting deleted | |
4960 | * from our database or being re-added to the kernel (if it is a valid | |
4961 | * remote neighbor). | |
4962 | */ | |
4963 | int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp, | |
4964 | struct interface *link_if, | |
4965 | struct ipaddr *ip) | |
4966 | { | |
4967 | char buf[INET6_ADDRSTRLEN]; | |
4968 | zebra_evpn_t *zevpn = NULL; | |
4969 | zebra_l3vni_t *zl3vni = NULL; | |
4970 | ||
4971 | /* check if this is a remote neigh entry corresponding to remote | |
4972 | * next-hop | |
4973 | */ | |
4974 | zl3vni = zl3vni_from_svi(ifp, link_if); | |
4975 | if (zl3vni) | |
4976 | return zl3vni_local_nh_del(zl3vni, ip); | |
4977 | ||
4978 | /* We are only interested in neighbors on an SVI that resides on top | |
4979 | * of a VxLAN bridge. | |
4980 | */ | |
4981 | zevpn = zevpn_from_svi(ifp, link_if); | |
4982 | if (!zevpn) { | |
4983 | if (IS_ZEBRA_DEBUG_VXLAN) | |
4984 | zlog_debug( | |
4985 | "%s: Del neighbor %s EVPN is not present for interface %s", | |
4986 | __func__, ipaddr2str(ip, buf, sizeof(buf)), | |
4987 | ifp->name); | |
4988 | return 0; | |
4989 | } | |
4990 | ||
4991 | if (!zevpn->vxlan_if) { | |
4992 | zlog_debug( | |
4993 | "VNI %u hash %p doesn't have intf upon local neighbor DEL", | |
4994 | zevpn->vni, zevpn); | |
4995 | return -1; | |
4996 | } | |
4997 | ||
4998 | if (IS_ZEBRA_DEBUG_VXLAN) | |
4999 | zlog_debug("Del neighbor %s intf %s(%u) -> L2-VNI %u", | |
5000 | ipaddr2str(ip, buf, sizeof(buf)), ifp->name, | |
5001 | ifp->ifindex, zevpn->vni); | |
5002 | ||
5003 | return zebra_evpn_neigh_del_ip(zevpn, ip); | |
5004 | } | |
5005 | ||
5006 | /* | |
5007 | * Handle neighbor add or update notification from the kernel (on a VLAN | |
5008 | * device / L3 interface). This is typically for a local neighbor but can | |
5009 | * also be for a remote neighbor (e.g., ageout notification). It could | |
5010 | * also be a "move" scenario. | |
5011 | */ | |
5012 | int zebra_vxlan_handle_kernel_neigh_update(struct interface *ifp, | |
5013 | struct interface *link_if, | |
5014 | struct ipaddr *ip, | |
5015 | struct ethaddr *macaddr, | |
5016 | uint16_t state, | |
5017 | bool is_ext, | |
5018 | bool is_router, | |
5019 | bool local_inactive, bool dp_static) | |
5020 | { | |
5021 | char buf[ETHER_ADDR_STRLEN]; | |
5022 | char buf2[INET6_ADDRSTRLEN]; | |
5023 | zebra_evpn_t *zevpn = NULL; | |
5024 | zebra_l3vni_t *zl3vni = NULL; | |
5025 | ||
5026 | /* check if this is a remote neigh entry corresponding to remote | |
5027 | * next-hop | |
5028 | */ | |
5029 | zl3vni = zl3vni_from_svi(ifp, link_if); | |
5030 | if (zl3vni) | |
5031 | return zl3vni_local_nh_add_update(zl3vni, ip, state); | |
5032 | ||
5033 | /* We are only interested in neighbors on an SVI that resides on top | |
5034 | * of a VxLAN bridge. | |
5035 | */ | |
5036 | zevpn = zevpn_from_svi(ifp, link_if); | |
5037 | if (!zevpn) | |
5038 | return 0; | |
5039 | ||
5040 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
5041 | zlog_debug( | |
5042 | "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x %s%s%s-> L2-VNI %u", | |
5043 | ipaddr2str(ip, buf2, sizeof(buf2)), | |
5044 | prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, | |
5045 | ifp->ifindex, state, is_ext ? "ext-learned " : "", | |
5046 | is_router ? "router " : "", | |
5047 | local_inactive ? "local_inactive " : "", | |
5048 | zevpn->vni); | |
5049 | ||
5050 | /* Is this about a local neighbor or a remote one? */ | |
5051 | if (!is_ext) | |
5052 | return zebra_evpn_local_neigh_update(zevpn, ifp, ip, macaddr, | |
5053 | is_router, local_inactive, | |
5054 | dp_static); | |
5055 | ||
5056 | return zebra_evpn_remote_neigh_update(zevpn, ifp, ip, macaddr, state); | |
5057 | } | |
5058 | ||
5059 | static int32_t | |
5060 | zebra_vxlan_remote_macip_helper(bool add, struct stream *s, vni_t *vni, | |
5061 | struct ethaddr *macaddr, uint16_t *ipa_len, | |
5062 | struct ipaddr *ip, struct in_addr *vtep_ip, | |
5063 | uint8_t *flags, uint32_t *seq, esi_t *esi) | |
5064 | { | |
5065 | uint16_t l = 0; | |
5066 | ||
5067 | /* | |
5068 | * Obtain each remote MACIP and process. | |
5069 | * Message contains VNI, followed by MAC followed by IP (if any) | |
5070 | * followed by remote VTEP IP. | |
5071 | */ | |
5072 | memset(ip, 0, sizeof(*ip)); | |
5073 | STREAM_GETL(s, *vni); | |
5074 | STREAM_GET(macaddr->octet, s, ETH_ALEN); | |
5075 | STREAM_GETL(s, *ipa_len); | |
5076 | ||
5077 | if (*ipa_len) { | |
5078 | if (*ipa_len == IPV4_MAX_BYTELEN) | |
5079 | ip->ipa_type = IPADDR_V4; | |
5080 | else if (*ipa_len == IPV6_MAX_BYTELEN) | |
5081 | ip->ipa_type = IPADDR_V6; | |
5082 | else { | |
5083 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5084 | zlog_debug( | |
5085 | "ipa_len *must* be %d or %d bytes in length not %d", | |
5086 | IPV4_MAX_BYTELEN, IPV6_MAX_BYTELEN, | |
5087 | *ipa_len); | |
5088 | goto stream_failure; | |
5089 | } | |
5090 | ||
5091 | STREAM_GET(&ip->ip.addr, s, *ipa_len); | |
5092 | } | |
5093 | l += 4 + ETH_ALEN + 4 + *ipa_len; | |
5094 | STREAM_GET(&vtep_ip->s_addr, s, IPV4_MAX_BYTELEN); | |
5095 | l += IPV4_MAX_BYTELEN; | |
5096 | ||
5097 | if (add) { | |
5098 | STREAM_GETC(s, *flags); | |
5099 | STREAM_GETL(s, *seq); | |
5100 | l += 5; | |
5101 | STREAM_GET(esi, s, sizeof(esi_t)); | |
5102 | l += sizeof(esi_t); | |
5103 | } | |
5104 | ||
5105 | return l; | |
5106 | ||
5107 | stream_failure: | |
5108 | return -1; | |
5109 | } | |
5110 | ||
5111 | /* | |
5112 | * Handle message from client to delete a remote MACIP for a VNI. | |
5113 | */ | |
5114 | void zebra_vxlan_remote_macip_del(ZAPI_HANDLER_ARGS) | |
5115 | { | |
5116 | struct stream *s; | |
5117 | vni_t vni; | |
5118 | struct ethaddr macaddr; | |
5119 | struct ipaddr ip; | |
5120 | struct in_addr vtep_ip; | |
5121 | uint16_t l = 0, ipa_len; | |
5122 | char buf[ETHER_ADDR_STRLEN]; | |
5123 | char buf1[INET6_ADDRSTRLEN]; | |
5124 | ||
5125 | memset(&macaddr, 0, sizeof(struct ethaddr)); | |
5126 | memset(&ip, 0, sizeof(struct ipaddr)); | |
5127 | memset(&vtep_ip, 0, sizeof(struct in_addr)); | |
5128 | ||
5129 | s = msg; | |
5130 | ||
5131 | while (l < hdr->length) { | |
5132 | int res_length = zebra_vxlan_remote_macip_helper( | |
5133 | false, s, &vni, &macaddr, &ipa_len, &ip, &vtep_ip, NULL, | |
5134 | NULL, NULL); | |
5135 | ||
5136 | if (res_length == -1) | |
5137 | goto stream_failure; | |
5138 | ||
5139 | l += res_length; | |
5140 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5141 | zlog_debug( | |
5142 | "Recv MACIP DEL VNI %u MAC %s%s%s Remote VTEP %s from %s", | |
5143 | vni, | |
5144 | prefix_mac2str(&macaddr, buf, sizeof(buf)), | |
5145 | ipa_len ? " IP " : "", | |
5146 | ipa_len ? | |
5147 | ipaddr2str(&ip, buf1, sizeof(buf1)) : "", | |
5148 | inet_ntoa(vtep_ip), | |
5149 | zebra_route_string(client->proto)); | |
5150 | ||
5151 | process_remote_macip_del(vni, &macaddr, ipa_len, &ip, vtep_ip); | |
5152 | } | |
5153 | ||
5154 | stream_failure: | |
5155 | return; | |
5156 | } | |
5157 | ||
5158 | /* | |
5159 | * Handle message from client to add a remote MACIP for a VNI. This | |
5160 | * could be just the add of a MAC address or the add of a neighbor | |
5161 | * (IP+MAC). | |
5162 | */ | |
5163 | void zebra_vxlan_remote_macip_add(ZAPI_HANDLER_ARGS) | |
5164 | { | |
5165 | struct stream *s; | |
5166 | vni_t vni; | |
5167 | struct ethaddr macaddr; | |
5168 | struct ipaddr ip; | |
5169 | struct in_addr vtep_ip; | |
5170 | uint16_t l = 0, ipa_len; | |
5171 | uint8_t flags = 0; | |
5172 | uint32_t seq; | |
5173 | char buf[ETHER_ADDR_STRLEN]; | |
5174 | char buf1[INET6_ADDRSTRLEN]; | |
5175 | esi_t esi; | |
5176 | char esi_buf[ESI_STR_LEN]; | |
5177 | ||
5178 | memset(&macaddr, 0, sizeof(struct ethaddr)); | |
5179 | memset(&ip, 0, sizeof(struct ipaddr)); | |
5180 | memset(&vtep_ip, 0, sizeof(struct in_addr)); | |
5181 | ||
5182 | if (!EVPN_ENABLED(zvrf)) { | |
5183 | zlog_debug("EVPN not enabled, ignoring remote MACIP ADD"); | |
5184 | return; | |
5185 | } | |
5186 | ||
5187 | s = msg; | |
5188 | ||
5189 | while (l < hdr->length) { | |
5190 | int res_length = zebra_vxlan_remote_macip_helper( | |
5191 | true, s, &vni, &macaddr, &ipa_len, &ip, &vtep_ip, | |
5192 | &flags, &seq, &esi); | |
5193 | ||
5194 | if (res_length == -1) | |
5195 | goto stream_failure; | |
5196 | ||
5197 | l += res_length; | |
5198 | if (IS_ZEBRA_DEBUG_VXLAN) { | |
5199 | if (memcmp(&esi, zero_esi, sizeof(esi_t))) | |
5200 | esi_to_str(&esi, esi_buf, sizeof(esi_buf)); | |
5201 | else | |
5202 | strcpy(esi_buf, "-"); | |
5203 | zlog_debug( | |
5204 | "Recv %sMACIP ADD VNI %u MAC %s%s%s flags 0x%x seq %u VTEP %s ESI %s from %s", | |
5205 | (flags & ZEBRA_MACIP_TYPE_SYNC_PATH) ? | |
5206 | "sync-" : "", | |
5207 | vni, | |
5208 | prefix_mac2str(&macaddr, buf, sizeof(buf)), | |
5209 | ipa_len ? " IP " : "", | |
5210 | ipa_len ? | |
5211 | ipaddr2str(&ip, buf1, sizeof(buf1)) : "", | |
5212 | flags, seq, inet_ntoa(vtep_ip), esi_buf, | |
5213 | zebra_route_string(client->proto)); | |
5214 | } | |
5215 | ||
5216 | process_remote_macip_add(vni, &macaddr, ipa_len, &ip, | |
5217 | flags, seq, vtep_ip, &esi); | |
5218 | } | |
5219 | ||
5220 | stream_failure: | |
5221 | return; | |
5222 | } | |
5223 | ||
5224 | /* | |
5225 | * Handle remote vtep delete by kernel; re-add the vtep if we have it | |
5226 | */ | |
5227 | int zebra_vxlan_check_readd_vtep(struct interface *ifp, | |
5228 | struct in_addr vtep_ip) | |
5229 | { | |
5230 | struct zebra_if *zif; | |
5231 | struct zebra_vrf *zvrf = NULL; | |
5232 | struct zebra_l2info_vxlan *vxl; | |
5233 | vni_t vni; | |
5234 | zebra_evpn_t *zevpn = NULL; | |
5235 | zebra_vtep_t *zvtep = NULL; | |
5236 | ||
5237 | zif = ifp->info; | |
5238 | assert(zif); | |
5239 | vxl = &zif->l2info.vxl; | |
5240 | vni = vxl->vni; | |
5241 | ||
5242 | /* If EVPN is not enabled, nothing to do. */ | |
5243 | if (!is_evpn_enabled()) | |
5244 | return 0; | |
5245 | ||
5246 | /* Locate VRF corresponding to interface. */ | |
5247 | zvrf = vrf_info_lookup(ifp->vrf_id); | |
5248 | if (!zvrf) | |
5249 | return -1; | |
5250 | ||
5251 | /* Locate hash entry; it is expected to exist. */ | |
5252 | zevpn = zevpn_lookup(vni); | |
5253 | if (!zevpn) | |
5254 | return 0; | |
5255 | ||
5256 | /* If the remote vtep entry doesn't exists nothing to do */ | |
5257 | zvtep = zevpn_vtep_find(zevpn, &vtep_ip); | |
5258 | if (!zvtep) | |
5259 | return 0; | |
5260 | ||
5261 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5262 | zlog_debug( | |
5263 | "Del MAC for remote VTEP %s intf %s(%u) VNI %u - readd", | |
5264 | inet_ntoa(vtep_ip), ifp->name, ifp->ifindex, vni); | |
5265 | ||
5266 | zevpn_vtep_install(zevpn, zvtep); | |
5267 | return 0; | |
5268 | } | |
5269 | ||
5270 | /* | |
5271 | * Handle notification of MAC add/update over VxLAN. If the kernel is notifying | |
5272 | * us, this must involve a multihoming scenario. Treat this as implicit delete | |
5273 | * of any prior local MAC. | |
5274 | */ | |
5275 | int zebra_vxlan_check_del_local_mac(struct interface *ifp, | |
5276 | struct interface *br_if, | |
5277 | struct ethaddr *macaddr, vlanid_t vid) | |
5278 | { | |
5279 | struct zebra_if *zif; | |
5280 | struct zebra_l2info_vxlan *vxl; | |
5281 | vni_t vni; | |
5282 | zebra_evpn_t *zevpn; | |
5283 | zebra_mac_t *mac; | |
5284 | char buf[ETHER_ADDR_STRLEN]; | |
5285 | ||
5286 | zif = ifp->info; | |
5287 | assert(zif); | |
5288 | vxl = &zif->l2info.vxl; | |
5289 | vni = vxl->vni; | |
5290 | ||
5291 | /* Check if EVPN is enabled. */ | |
5292 | if (!is_evpn_enabled()) | |
5293 | return 0; | |
5294 | ||
5295 | /* Locate hash entry; it is expected to exist. */ | |
5296 | zevpn = zevpn_lookup(vni); | |
5297 | if (!zevpn) | |
5298 | return 0; | |
5299 | ||
5300 | /* If entry doesn't exist, nothing to do. */ | |
5301 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
5302 | if (!mac) | |
5303 | return 0; | |
5304 | ||
5305 | /* Is it a local entry? */ | |
5306 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) | |
5307 | return 0; | |
5308 | ||
5309 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5310 | zlog_debug( | |
5311 | "Add/update remote MAC %s intf %s(%u) VNI %u flags 0x%x - del local", | |
5312 | prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, | |
5313 | ifp->ifindex, vni, mac->flags); | |
5314 | ||
5315 | /* Remove MAC from BGP. */ | |
5316 | zebra_evpn_mac_send_del_to_client(zevpn->vni, macaddr, mac->flags, | |
5317 | false /* force */); | |
5318 | ||
5319 | /* | |
5320 | * If there are no neigh associated with the mac delete the mac | |
5321 | * else mark it as AUTO for forward reference | |
5322 | */ | |
5323 | if (!listcount(mac->neigh_list)) { | |
5324 | zebra_evpn_mac_del(zevpn, mac); | |
5325 | } else { | |
5326 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS); | |
5327 | UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
5328 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
5329 | } | |
5330 | ||
5331 | return 0; | |
5332 | } | |
5333 | ||
5334 | /* | |
5335 | * Handle remote MAC delete by kernel; readd the remote MAC if we have it. | |
5336 | * This can happen because the remote MAC entries are also added as "dynamic", | |
5337 | * so the kernel can ageout the entry. | |
5338 | */ | |
5339 | int zebra_vxlan_check_readd_remote_mac(struct interface *ifp, | |
5340 | struct interface *br_if, | |
5341 | struct ethaddr *macaddr, vlanid_t vid) | |
5342 | { | |
5343 | struct zebra_if *zif = NULL; | |
5344 | struct zebra_l2info_vxlan *vxl = NULL; | |
5345 | vni_t vni; | |
5346 | zebra_evpn_t *zevpn = NULL; | |
5347 | zebra_l3vni_t *zl3vni = NULL; | |
5348 | zebra_mac_t *mac = NULL; | |
5349 | char buf[ETHER_ADDR_STRLEN]; | |
5350 | ||
5351 | zif = ifp->info; | |
5352 | assert(zif); | |
5353 | vxl = &zif->l2info.vxl; | |
5354 | vni = vxl->vni; | |
5355 | ||
5356 | /* Check if EVPN is enabled. */ | |
5357 | if (!is_evpn_enabled()) | |
5358 | return 0; | |
5359 | ||
5360 | /* check if this is a remote RMAC and readd simillar to remote macs */ | |
5361 | zl3vni = zl3vni_lookup(vni); | |
5362 | if (zl3vni) | |
5363 | return zebra_vxlan_readd_remote_rmac(zl3vni, macaddr); | |
5364 | ||
5365 | /* Locate hash entry; it is expected to exist. */ | |
5366 | zevpn = zevpn_lookup(vni); | |
5367 | if (!zevpn) | |
5368 | return 0; | |
5369 | ||
5370 | /* If entry doesn't exist, nothing to do. */ | |
5371 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
5372 | if (!mac) | |
5373 | return 0; | |
5374 | ||
5375 | /* Is it a remote entry? */ | |
5376 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) | |
5377 | return 0; | |
5378 | ||
5379 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5380 | zlog_debug("Del remote MAC %s intf %s(%u) VNI %u - readd", | |
5381 | prefix_mac2str(macaddr, buf, sizeof(buf)), ifp->name, | |
5382 | ifp->ifindex, vni); | |
5383 | ||
5384 | zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */); | |
5385 | return 0; | |
5386 | } | |
5387 | ||
5388 | /* | |
5389 | * Handle local MAC delete (on a port or VLAN corresponding to this VNI). | |
5390 | */ | |
5391 | int zebra_vxlan_local_mac_del(struct interface *ifp, struct interface *br_if, | |
5392 | struct ethaddr *macaddr, vlanid_t vid) | |
5393 | { | |
5394 | zebra_evpn_t *zevpn; | |
5395 | ||
5396 | /* We are interested in MACs only on ports or (port, VLAN) that | |
5397 | * map to a VNI. | |
5398 | */ | |
5399 | zevpn = zevpn_map_vlan(ifp, br_if, vid); | |
5400 | if (!zevpn) | |
5401 | return 0; | |
5402 | if (!zevpn->vxlan_if) { | |
5403 | zlog_debug( | |
5404 | "VNI %u hash %p doesn't have intf upon local MAC DEL", | |
5405 | zevpn->vni, zevpn); | |
5406 | return -1; | |
5407 | } | |
5408 | ||
5409 | return zebra_evpn_del_local_mac(zevpn, macaddr, ifp); | |
5410 | } | |
5411 | ||
5412 | /* | |
5413 | * Handle local MAC add (on a port or VLAN corresponding to this VNI). | |
5414 | */ | |
5415 | int zebra_vxlan_local_mac_add_update(struct interface *ifp, | |
5416 | struct interface *br_if, | |
5417 | struct ethaddr *macaddr, vlanid_t vid, | |
5418 | bool sticky, bool local_inactive, | |
5419 | bool dp_static) | |
5420 | { | |
5421 | zebra_evpn_t *zevpn; | |
5422 | struct zebra_vrf *zvrf; | |
5423 | char buf[ETHER_ADDR_STRLEN]; | |
5424 | ||
5425 | /* We are interested in MACs only on ports or (port, VLAN) that | |
5426 | * map to an EVPN. | |
5427 | */ | |
5428 | zevpn = zevpn_map_vlan(ifp, br_if, vid); | |
5429 | if (!zevpn) { | |
5430 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5431 | zlog_debug( | |
5432 | " Add/Update %sMAC %s intf %s(%u) VID %u, could not find EVPN", | |
5433 | sticky ? "sticky " : "", | |
5434 | prefix_mac2str(macaddr, buf, sizeof(buf)), | |
5435 | ifp->name, ifp->ifindex, vid); | |
5436 | return 0; | |
5437 | } | |
5438 | ||
5439 | if (!zevpn->vxlan_if) { | |
5440 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5441 | zlog_debug( | |
5442 | " VNI %u hash %p doesn't have intf upon local MAC ADD", | |
5443 | zevpn->vni, zevpn); | |
5444 | return -1; | |
5445 | } | |
5446 | ||
5447 | zvrf = vrf_info_lookup(zevpn->vxlan_if->vrf_id); | |
5448 | if (!zvrf) { | |
5449 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5450 | zlog_debug(" No Vrf found for vrf_id: %d", | |
5451 | zevpn->vxlan_if->vrf_id); | |
5452 | return -1; | |
5453 | } | |
5454 | ||
5455 | return zebra_evpn_add_update_local_mac(zvrf, zevpn, ifp, macaddr, vid, | |
5456 | sticky, local_inactive, | |
5457 | dp_static); | |
5458 | } | |
5459 | ||
5460 | /* | |
5461 | * Handle message from client to delete a remote VTEP for an EVPN. | |
5462 | */ | |
5463 | void zebra_vxlan_remote_vtep_del(ZAPI_HANDLER_ARGS) | |
5464 | { | |
5465 | struct stream *s; | |
5466 | unsigned short l = 0; | |
5467 | vni_t vni; | |
5468 | struct in_addr vtep_ip; | |
5469 | zebra_evpn_t *zevpn; | |
5470 | zebra_vtep_t *zvtep; | |
5471 | struct interface *ifp; | |
5472 | struct zebra_if *zif; | |
5473 | ||
5474 | if (!is_evpn_enabled()) { | |
5475 | zlog_debug( | |
5476 | "%s: EVPN is not enabled yet we have received a vtep del command", | |
5477 | __func__); | |
5478 | return; | |
5479 | } | |
5480 | ||
5481 | if (!EVPN_ENABLED(zvrf)) { | |
5482 | zlog_debug("Recv MACIP DEL for non-EVPN VRF %u", | |
5483 | zvrf_id(zvrf)); | |
5484 | return; | |
5485 | } | |
5486 | ||
5487 | s = msg; | |
5488 | ||
5489 | while (l < hdr->length) { | |
5490 | int flood_control __attribute__((unused)); | |
5491 | ||
5492 | /* Obtain each remote VTEP and process. */ | |
5493 | STREAM_GETL(s, vni); | |
5494 | l += 4; | |
5495 | STREAM_GET(&vtep_ip.s_addr, s, IPV4_MAX_BYTELEN); | |
5496 | l += IPV4_MAX_BYTELEN; | |
5497 | ||
5498 | /* Flood control is intentionally ignored right now */ | |
5499 | STREAM_GETL(s, flood_control); | |
5500 | l += 4; | |
5501 | ||
5502 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5503 | zlog_debug("Recv VTEP_DEL %s VNI %u from %s", | |
5504 | inet_ntoa(vtep_ip), vni, | |
5505 | zebra_route_string(client->proto)); | |
5506 | ||
5507 | /* Locate VNI hash entry - expected to exist. */ | |
5508 | zevpn = zevpn_lookup(vni); | |
5509 | if (!zevpn) { | |
5510 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5511 | zlog_debug( | |
5512 | "Failed to locate VNI hash upon remote VTEP DEL, " | |
5513 | "VNI %u", | |
5514 | vni); | |
5515 | continue; | |
5516 | } | |
5517 | ||
5518 | ifp = zevpn->vxlan_if; | |
5519 | if (!ifp) { | |
5520 | zlog_debug( | |
5521 | "VNI %u hash %p doesn't have intf upon remote VTEP DEL", | |
5522 | zevpn->vni, zevpn); | |
5523 | continue; | |
5524 | } | |
5525 | zif = ifp->info; | |
5526 | ||
5527 | /* If down or not mapped to a bridge, we're done. */ | |
5528 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
5529 | continue; | |
5530 | ||
5531 | /* If the remote VTEP does not exist, there's nothing more to | |
5532 | * do. | |
5533 | * Otherwise, uninstall any remote MACs pointing to this VTEP | |
5534 | * and | |
5535 | * then, the VTEP entry itself and remove it. | |
5536 | */ | |
5537 | zvtep = zevpn_vtep_find(zevpn, &vtep_ip); | |
5538 | if (!zvtep) | |
5539 | continue; | |
5540 | ||
5541 | zevpn_vtep_uninstall(zevpn, &vtep_ip); | |
5542 | zevpn_vtep_del(zevpn, zvtep); | |
5543 | } | |
5544 | ||
5545 | stream_failure: | |
5546 | return; | |
5547 | } | |
5548 | ||
5549 | /* | |
5550 | * Handle message from client to add a remote VTEP for an EVPN. | |
5551 | */ | |
5552 | void zebra_vxlan_remote_vtep_add(ZAPI_HANDLER_ARGS) | |
5553 | { | |
5554 | struct stream *s; | |
5555 | unsigned short l = 0; | |
5556 | vni_t vni; | |
5557 | struct in_addr vtep_ip; | |
5558 | zebra_evpn_t *zevpn; | |
5559 | struct interface *ifp; | |
5560 | struct zebra_if *zif; | |
5561 | int flood_control; | |
5562 | zebra_vtep_t *zvtep; | |
5563 | ||
5564 | if (!is_evpn_enabled()) { | |
5565 | zlog_debug( | |
5566 | "%s: EVPN not enabled yet we received a vtep_add zapi call", | |
5567 | __func__); | |
5568 | return; | |
5569 | } | |
5570 | ||
5571 | if (!EVPN_ENABLED(zvrf)) { | |
5572 | zlog_debug("Recv MACIP ADD for non-EVPN VRF %u", | |
5573 | zvrf_id(zvrf)); | |
5574 | return; | |
5575 | } | |
5576 | ||
5577 | s = msg; | |
5578 | ||
5579 | while (l < hdr->length) { | |
5580 | /* Obtain each remote VTEP and process. */ | |
5581 | STREAM_GETL(s, vni); | |
5582 | l += 4; | |
5583 | STREAM_GET(&vtep_ip.s_addr, s, IPV4_MAX_BYTELEN); | |
5584 | STREAM_GETL(s, flood_control); | |
5585 | l += IPV4_MAX_BYTELEN + 4; | |
5586 | ||
5587 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5588 | zlog_debug("Recv VTEP_ADD %s VNI %u flood %d from %s", | |
5589 | inet_ntoa(vtep_ip), vni, flood_control, | |
5590 | zebra_route_string(client->proto)); | |
5591 | ||
5592 | /* Locate VNI hash entry - expected to exist. */ | |
5593 | zevpn = zevpn_lookup(vni); | |
5594 | if (!zevpn) { | |
5595 | flog_err( | |
5596 | EC_ZEBRA_VTEP_ADD_FAILED, | |
5597 | "Failed to locate EVPN hash upon remote VTEP ADD, VNI %u", | |
5598 | vni); | |
5599 | continue; | |
5600 | } | |
5601 | ||
5602 | ifp = zevpn->vxlan_if; | |
5603 | if (!ifp) { | |
5604 | flog_err( | |
5605 | EC_ZEBRA_VTEP_ADD_FAILED, | |
5606 | "VNI %u hash %p doesn't have intf upon remote VTEP ADD", | |
5607 | zevpn->vni, zevpn); | |
5608 | continue; | |
5609 | } | |
5610 | ||
5611 | zif = ifp->info; | |
5612 | ||
5613 | /* If down or not mapped to a bridge, we're done. */ | |
5614 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
5615 | continue; | |
5616 | ||
5617 | zvtep = zevpn_vtep_find(zevpn, &vtep_ip); | |
5618 | if (zvtep) { | |
5619 | /* If the remote VTEP already exists check if | |
5620 | * the flood mode has changed | |
5621 | */ | |
5622 | if (zvtep->flood_control != flood_control) { | |
5623 | if (zvtep->flood_control | |
5624 | == VXLAN_FLOOD_DISABLED) | |
5625 | /* old mode was head-end-replication but | |
5626 | * is no longer; get rid of the HER fdb | |
5627 | * entry installed before | |
5628 | */ | |
5629 | zevpn_vtep_uninstall(zevpn, &vtep_ip); | |
5630 | zvtep->flood_control = flood_control; | |
5631 | zevpn_vtep_install(zevpn, zvtep); | |
5632 | } | |
5633 | } else { | |
5634 | zvtep = zevpn_vtep_add(zevpn, &vtep_ip, flood_control); | |
5635 | if (zvtep) | |
5636 | zevpn_vtep_install(zevpn, zvtep); | |
5637 | else | |
5638 | flog_err(EC_ZEBRA_VTEP_ADD_FAILED, | |
5639 | "Failed to add remote VTEP, VNI %u zevpn %p", | |
5640 | vni, zevpn); | |
5641 | } | |
5642 | } | |
5643 | ||
5644 | stream_failure: | |
5645 | return; | |
5646 | } | |
5647 | ||
5648 | /* | |
5649 | * Add/Del gateway macip to evpn | |
5650 | * g/w can be: | |
5651 | * 1. SVI interface on a vlan aware bridge | |
5652 | * 2. SVI interface on a vlan unaware bridge | |
5653 | * 3. vrr interface (MACVLAN) associated to a SVI | |
5654 | * We advertise macip routes for an interface if it is associated to VxLan vlan | |
5655 | */ | |
5656 | int zebra_vxlan_add_del_gw_macip(struct interface *ifp, struct prefix *p, | |
5657 | int add) | |
5658 | { | |
5659 | struct ipaddr ip; | |
5660 | struct ethaddr macaddr; | |
5661 | zebra_evpn_t *zevpn = NULL; | |
5662 | ||
5663 | memset(&ip, 0, sizeof(struct ipaddr)); | |
5664 | memset(&macaddr, 0, sizeof(struct ethaddr)); | |
5665 | ||
5666 | /* Check if EVPN is enabled. */ | |
5667 | if (!is_evpn_enabled()) | |
5668 | return 0; | |
5669 | ||
5670 | if (IS_ZEBRA_IF_MACVLAN(ifp)) { | |
5671 | struct interface *svi_if = | |
5672 | NULL; /* SVI corresponding to the MACVLAN */ | |
5673 | struct zebra_if *ifp_zif = | |
5674 | NULL; /* Zebra daemon specific info for MACVLAN */ | |
5675 | struct zebra_if *svi_if_zif = | |
5676 | NULL; /* Zebra daemon specific info for SVI*/ | |
5677 | ||
5678 | ifp_zif = ifp->info; | |
5679 | if (!ifp_zif) | |
5680 | return -1; | |
5681 | ||
5682 | /* | |
5683 | * for a MACVLAN interface the link represents the svi_if | |
5684 | */ | |
5685 | svi_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), | |
5686 | ifp_zif->link_ifindex); | |
5687 | if (!svi_if) { | |
5688 | zlog_debug("MACVLAN %s(%u) without link information", | |
5689 | ifp->name, ifp->ifindex); | |
5690 | return -1; | |
5691 | } | |
5692 | ||
5693 | if (IS_ZEBRA_IF_VLAN(svi_if)) { | |
5694 | /* | |
5695 | * If it is a vlan aware bridge then the link gives the | |
5696 | * bridge information | |
5697 | */ | |
5698 | struct interface *svi_if_link = NULL; | |
5699 | ||
5700 | svi_if_zif = svi_if->info; | |
5701 | if (svi_if_zif) { | |
5702 | svi_if_link = if_lookup_by_index_per_ns( | |
5703 | zebra_ns_lookup(NS_DEFAULT), | |
5704 | svi_if_zif->link_ifindex); | |
5705 | zevpn = zevpn_from_svi(svi_if, svi_if_link); | |
5706 | } | |
5707 | } else if (IS_ZEBRA_IF_BRIDGE(svi_if)) { | |
5708 | /* | |
5709 | * If it is a vlan unaware bridge then svi is the bridge | |
5710 | * itself | |
5711 | */ | |
5712 | zevpn = zevpn_from_svi(svi_if, svi_if); | |
5713 | } | |
5714 | } else if (IS_ZEBRA_IF_VLAN(ifp)) { | |
5715 | struct zebra_if *svi_if_zif = | |
5716 | NULL; /* Zebra daemon specific info for SVI */ | |
5717 | struct interface *svi_if_link = | |
5718 | NULL; /* link info for the SVI = bridge info */ | |
5719 | ||
5720 | svi_if_zif = ifp->info; | |
5721 | if (svi_if_zif) { | |
5722 | svi_if_link = if_lookup_by_index_per_ns( | |
5723 | zebra_ns_lookup(NS_DEFAULT), | |
5724 | svi_if_zif->link_ifindex); | |
5725 | if (svi_if_link) | |
5726 | zevpn = zevpn_from_svi(ifp, svi_if_link); | |
5727 | } | |
5728 | } else if (IS_ZEBRA_IF_BRIDGE(ifp)) { | |
5729 | zevpn = zevpn_from_svi(ifp, ifp); | |
5730 | } | |
5731 | ||
5732 | if (!zevpn) | |
5733 | return 0; | |
5734 | ||
5735 | if (!zevpn->vxlan_if) { | |
5736 | zlog_debug("VNI %u hash %p doesn't have intf upon MACVLAN up", | |
5737 | zevpn->vni, zevpn); | |
5738 | return -1; | |
5739 | } | |
5740 | ||
5741 | ||
5742 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
5743 | ||
5744 | if (p->family == AF_INET) { | |
5745 | ip.ipa_type = IPADDR_V4; | |
5746 | memcpy(&(ip.ipaddr_v4), &(p->u.prefix4), | |
5747 | sizeof(struct in_addr)); | |
5748 | } else if (p->family == AF_INET6) { | |
5749 | ip.ipa_type = IPADDR_V6; | |
5750 | memcpy(&(ip.ipaddr_v6), &(p->u.prefix6), | |
5751 | sizeof(struct in6_addr)); | |
5752 | } | |
5753 | ||
5754 | ||
5755 | if (add) | |
5756 | zevpn_gw_macip_add(ifp, zevpn, &macaddr, &ip); | |
5757 | else | |
5758 | zevpn_gw_macip_del(ifp, zevpn, &ip); | |
5759 | ||
5760 | return 0; | |
5761 | } | |
5762 | ||
5763 | /* | |
5764 | * Handle SVI interface going down. | |
5765 | * SVI can be associated to either L3-VNI or L2-VNI. | |
5766 | * For L2-VNI: At this point, this is a NOP since | |
5767 | * the kernel deletes the neighbor entries on this SVI (if any). | |
5768 | * We only need to update the vrf corresponding to zevpn. | |
5769 | * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete | |
5770 | * from bgp | |
5771 | */ | |
5772 | int zebra_vxlan_svi_down(struct interface *ifp, struct interface *link_if) | |
5773 | { | |
5774 | zebra_l3vni_t *zl3vni = NULL; | |
5775 | ||
5776 | zl3vni = zl3vni_from_svi(ifp, link_if); | |
5777 | if (zl3vni) { | |
5778 | ||
5779 | /* process l3-vni down */ | |
5780 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
5781 | ||
5782 | /* remove association with svi-if */ | |
5783 | zl3vni->svi_if = NULL; | |
5784 | } else { | |
5785 | zebra_evpn_t *zevpn = NULL; | |
5786 | ||
5787 | /* since we dont have svi corresponding to zevpn, we associate it | |
5788 | * to default vrf. Note: the corresponding neigh entries on the | |
5789 | * SVI would have already been deleted */ | |
5790 | zevpn = zevpn_from_svi(ifp, link_if); | |
5791 | if (zevpn) { | |
5792 | zevpn->vrf_id = VRF_DEFAULT; | |
5793 | ||
5794 | /* update the tenant vrf in BGP */ | |
5795 | zevpn_send_add_to_client(zevpn); | |
5796 | } | |
5797 | } | |
5798 | return 0; | |
5799 | } | |
5800 | ||
5801 | /* | |
5802 | * Handle SVI interface coming up. | |
5803 | * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni | |
5804 | * vxlan intf). | |
5805 | * For L2-VNI: we need to install any remote neighbors entried (used for | |
5806 | * apr-suppression) | |
5807 | * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI | |
5808 | */ | |
5809 | int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) | |
5810 | { | |
5811 | zebra_evpn_t *zevpn = NULL; | |
5812 | zebra_l3vni_t *zl3vni = NULL; | |
5813 | ||
5814 | zl3vni = zl3vni_from_svi(ifp, link_if); | |
5815 | if (zl3vni) { | |
5816 | ||
5817 | /* associate with svi */ | |
5818 | zl3vni->svi_if = ifp; | |
5819 | ||
5820 | /* process oper-up */ | |
5821 | if (is_l3vni_oper_up(zl3vni)) | |
5822 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
5823 | } else { | |
5824 | ||
5825 | /* process SVI up for l2-vni */ | |
5826 | struct neigh_walk_ctx n_wctx; | |
5827 | ||
5828 | zevpn = zevpn_from_svi(ifp, link_if); | |
5829 | if (!zevpn) | |
5830 | return 0; | |
5831 | ||
5832 | if (!zevpn->vxlan_if) { | |
5833 | zlog_debug( | |
5834 | "VNI %u hash %p doesn't have intf upon SVI up", | |
5835 | zevpn->vni, zevpn); | |
5836 | return -1; | |
5837 | } | |
5838 | ||
5839 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5840 | zlog_debug( | |
5841 | "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors", | |
5842 | ifp->name, ifp->ifindex, zevpn->vni, | |
5843 | vrf_id_to_name(ifp->vrf_id)); | |
5844 | ||
5845 | /* update the vrf information for l2-vni and inform bgp */ | |
5846 | zevpn->vrf_id = ifp->vrf_id; | |
5847 | zevpn_send_add_to_client(zevpn); | |
5848 | ||
5849 | /* Install any remote neighbors for this VNI. */ | |
5850 | memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); | |
5851 | n_wctx.zevpn = zevpn; | |
5852 | hash_iterate(zevpn->neigh_table, zebra_evpn_install_neigh_hash, | |
5853 | &n_wctx); | |
5854 | } | |
5855 | ||
5856 | return 0; | |
5857 | } | |
5858 | ||
5859 | /* | |
5860 | * Handle MAC-VLAN interface going down. | |
5861 | * L3VNI: When MAC-VLAN interface goes down, | |
5862 | * find its associated SVI and update type2/type-5 routes | |
5863 | * with SVI as RMAC | |
5864 | */ | |
5865 | void zebra_vxlan_macvlan_down(struct interface *ifp) | |
5866 | { | |
5867 | zebra_l3vni_t *zl3vni = NULL; | |
5868 | struct zebra_if *zif, *link_zif; | |
5869 | struct interface *link_ifp, *link_if; | |
5870 | ||
5871 | zif = ifp->info; | |
5872 | assert(zif); | |
5873 | link_ifp = zif->link; | |
5874 | if (!link_ifp) { | |
5875 | if (IS_ZEBRA_DEBUG_VXLAN) { | |
5876 | struct interface *ifp; | |
5877 | ||
5878 | ifp = if_lookup_by_index_all_vrf(zif->link_ifindex); | |
5879 | zlog_debug("macvlan parent link is not found. Parent index %d ifp %s", | |
5880 | zif->link_ifindex, ifp ? ifp->name : " "); | |
5881 | } | |
5882 | return; | |
5883 | } | |
5884 | link_zif = link_ifp->info; | |
5885 | assert(link_zif); | |
5886 | ||
5887 | link_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), | |
5888 | link_zif->link_ifindex); | |
5889 | ||
5890 | zl3vni = zl3vni_from_svi(link_ifp, link_if); | |
5891 | if (zl3vni) { | |
5892 | zl3vni->mac_vlan_if = NULL; | |
5893 | if (is_l3vni_oper_up(zl3vni)) | |
5894 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
5895 | } | |
5896 | } | |
5897 | ||
5898 | /* | |
5899 | * Handle MAC-VLAN interface going up. | |
5900 | * L3VNI: When MAC-VLAN interface comes up, | |
5901 | * find its associated SVI and update type-2 routes | |
5902 | * with MAC-VLAN's MAC as RMAC and for type-5 routes | |
5903 | * use SVI's MAC as RMAC. | |
5904 | */ | |
5905 | void zebra_vxlan_macvlan_up(struct interface *ifp) | |
5906 | { | |
5907 | zebra_l3vni_t *zl3vni = NULL; | |
5908 | struct zebra_if *zif, *link_zif; | |
5909 | struct interface *link_ifp, *link_if; | |
5910 | ||
5911 | zif = ifp->info; | |
5912 | assert(zif); | |
5913 | link_ifp = zif->link; | |
5914 | link_zif = link_ifp->info; | |
5915 | assert(link_zif); | |
5916 | ||
5917 | link_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT), | |
5918 | link_zif->link_ifindex); | |
5919 | zl3vni = zl3vni_from_svi(link_ifp, link_if); | |
5920 | if (zl3vni) { | |
5921 | /* associate with macvlan (VRR) interface */ | |
5922 | zl3vni->mac_vlan_if = ifp; | |
5923 | ||
5924 | /* process oper-up */ | |
5925 | if (is_l3vni_oper_up(zl3vni)) | |
5926 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
5927 | } | |
5928 | } | |
5929 | ||
5930 | /* | |
5931 | * Handle VxLAN interface down | |
5932 | */ | |
5933 | int zebra_vxlan_if_down(struct interface *ifp) | |
5934 | { | |
5935 | vni_t vni; | |
5936 | struct zebra_if *zif = NULL; | |
5937 | struct zebra_l2info_vxlan *vxl = NULL; | |
5938 | zebra_l3vni_t *zl3vni = NULL; | |
5939 | zebra_evpn_t *zevpn; | |
5940 | ||
5941 | /* Check if EVPN is enabled. */ | |
5942 | if (!is_evpn_enabled()) | |
5943 | return 0; | |
5944 | ||
5945 | zif = ifp->info; | |
5946 | assert(zif); | |
5947 | vxl = &zif->l2info.vxl; | |
5948 | vni = vxl->vni; | |
5949 | ||
5950 | zl3vni = zl3vni_lookup(vni); | |
5951 | if (zl3vni) { | |
5952 | /* process-if-down for l3-vni */ | |
5953 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5954 | zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp->name, | |
5955 | ifp->ifindex, vni); | |
5956 | ||
5957 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
5958 | } else { | |
5959 | /* process if-down for l2-vni */ | |
5960 | if (IS_ZEBRA_DEBUG_VXLAN) | |
5961 | zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp->name, | |
5962 | ifp->ifindex, vni); | |
5963 | ||
5964 | /* Locate hash entry; it is expected to exist. */ | |
5965 | zevpn = zevpn_lookup(vni); | |
5966 | if (!zevpn) { | |
5967 | zlog_debug( | |
5968 | "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u", | |
5969 | ifp->name, ifp->ifindex, vni); | |
5970 | return -1; | |
5971 | } | |
5972 | ||
5973 | assert(zevpn->vxlan_if == ifp); | |
5974 | ||
5975 | /* Delete this VNI from BGP. */ | |
5976 | zevpn_send_del_to_client(zevpn); | |
5977 | ||
5978 | /* Free up all neighbors and MACs, if any. */ | |
5979 | zebra_evpn_neigh_del_all(zevpn, 1, 0, DEL_ALL_NEIGH); | |
5980 | zebra_evpn_mac_del_all(zevpn, 1, 0, DEL_ALL_MAC); | |
5981 | ||
5982 | /* Free up all remote VTEPs, if any. */ | |
5983 | zevpn_vtep_del_all(zevpn, 1); | |
5984 | } | |
5985 | return 0; | |
5986 | } | |
5987 | ||
5988 | /* | |
5989 | * Handle VxLAN interface up - update BGP if required. | |
5990 | */ | |
5991 | int zebra_vxlan_if_up(struct interface *ifp) | |
5992 | { | |
5993 | vni_t vni; | |
5994 | struct zebra_if *zif = NULL; | |
5995 | struct zebra_l2info_vxlan *vxl = NULL; | |
5996 | zebra_evpn_t *zevpn = NULL; | |
5997 | zebra_l3vni_t *zl3vni = NULL; | |
5998 | ||
5999 | /* Check if EVPN is enabled. */ | |
6000 | if (!is_evpn_enabled()) | |
6001 | return 0; | |
6002 | ||
6003 | zif = ifp->info; | |
6004 | assert(zif); | |
6005 | vxl = &zif->l2info.vxl; | |
6006 | vni = vxl->vni; | |
6007 | ||
6008 | zl3vni = zl3vni_lookup(vni); | |
6009 | if (zl3vni) { | |
6010 | /* we need to associate with SVI, if any, we can associate with | |
6011 | * svi-if only after association with vxlan-intf is complete | |
6012 | */ | |
6013 | zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); | |
6014 | zl3vni->mac_vlan_if = zl3vni_map_to_mac_vlan_if(zl3vni); | |
6015 | ||
6016 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6017 | zlog_debug("Intf %s(%u) L3-VNI %u is UP svi_if %s mac_vlan_if %s" | |
6018 | , ifp->name, ifp->ifindex, vni, | |
6019 | zl3vni->svi_if ? zl3vni->svi_if->name : "NIL", | |
6020 | zl3vni->mac_vlan_if ? | |
6021 | zl3vni->mac_vlan_if->name : "NIL"); | |
6022 | ||
6023 | if (is_l3vni_oper_up(zl3vni)) | |
6024 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
6025 | } else { | |
6026 | /* Handle L2-VNI add */ | |
6027 | struct interface *vlan_if = NULL; | |
6028 | ||
6029 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6030 | zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp->name, | |
6031 | ifp->ifindex, vni); | |
6032 | ||
6033 | /* Locate hash entry; it is expected to exist. */ | |
6034 | zevpn = zevpn_lookup(vni); | |
6035 | if (!zevpn) { | |
6036 | zlog_debug( | |
6037 | "Failed to locate EVPN hash at UP, IF %s(%u) VNI %u", | |
6038 | ifp->name, ifp->ifindex, vni); | |
6039 | return -1; | |
6040 | } | |
6041 | ||
6042 | assert(zevpn->vxlan_if == ifp); | |
6043 | vlan_if = zvni_map_to_svi(vxl->access_vlan, | |
6044 | zif->brslave_info.br_if); | |
6045 | if (vlan_if) { | |
6046 | zevpn->vrf_id = vlan_if->vrf_id; | |
6047 | zl3vni = zl3vni_from_vrf(vlan_if->vrf_id); | |
6048 | if (zl3vni) | |
6049 | listnode_add_sort(zl3vni->l2vnis, zevpn); | |
6050 | } | |
6051 | ||
6052 | /* If part of a bridge, inform BGP about this VNI. */ | |
6053 | /* Also, read and populate local MACs and neighbors. */ | |
6054 | if (zif->brslave_info.br_if) { | |
6055 | zevpn_send_add_to_client(zevpn); | |
6056 | zevpn_read_mac_neigh(zevpn, ifp); | |
6057 | } | |
6058 | } | |
6059 | ||
6060 | return 0; | |
6061 | } | |
6062 | ||
6063 | /* | |
6064 | * Handle VxLAN interface delete. Locate and remove entry in hash table | |
6065 | * and update BGP, if required. | |
6066 | */ | |
6067 | int zebra_vxlan_if_del(struct interface *ifp) | |
6068 | { | |
6069 | vni_t vni; | |
6070 | struct zebra_if *zif = NULL; | |
6071 | struct zebra_l2info_vxlan *vxl = NULL; | |
6072 | zebra_evpn_t *zevpn = NULL; | |
6073 | zebra_l3vni_t *zl3vni = NULL; | |
6074 | ||
6075 | /* Check if EVPN is enabled. */ | |
6076 | if (!is_evpn_enabled()) | |
6077 | return 0; | |
6078 | ||
6079 | zif = ifp->info; | |
6080 | assert(zif); | |
6081 | vxl = &zif->l2info.vxl; | |
6082 | vni = vxl->vni; | |
6083 | ||
6084 | zl3vni = zl3vni_lookup(vni); | |
6085 | if (zl3vni) { | |
6086 | ||
6087 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6088 | zlog_debug("Del L3-VNI %u intf %s(%u)", vni, ifp->name, | |
6089 | ifp->ifindex); | |
6090 | ||
6091 | /* process oper-down for l3-vni */ | |
6092 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6093 | ||
6094 | /* remove the association with vxlan_if */ | |
6095 | memset(&zl3vni->local_vtep_ip, 0, sizeof(struct in_addr)); | |
6096 | zl3vni->vxlan_if = NULL; | |
6097 | } else { | |
6098 | ||
6099 | /* process if-del for l2-vni*/ | |
6100 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6101 | zlog_debug("Del L2-VNI %u intf %s(%u)", vni, ifp->name, | |
6102 | ifp->ifindex); | |
6103 | ||
6104 | /* Locate hash entry; it is expected to exist. */ | |
6105 | zevpn = zevpn_lookup(vni); | |
6106 | if (!zevpn) { | |
6107 | zlog_debug( | |
6108 | "Failed to locate VNI hash at del, IF %s(%u) VNI %u", | |
6109 | ifp->name, ifp->ifindex, vni); | |
6110 | return 0; | |
6111 | } | |
6112 | ||
6113 | /* remove from l3-vni list */ | |
6114 | zl3vni = zl3vni_from_vrf(zevpn->vrf_id); | |
6115 | if (zl3vni) | |
6116 | listnode_delete(zl3vni->l2vnis, zevpn); | |
6117 | /* Delete VNI from BGP. */ | |
6118 | zevpn_send_del_to_client(zevpn); | |
6119 | ||
6120 | /* Free up all neighbors and MAC, if any. */ | |
6121 | zebra_evpn_neigh_del_all(zevpn, 0, 0, DEL_ALL_NEIGH); | |
6122 | zebra_evpn_mac_del_all(zevpn, 0, 0, DEL_ALL_MAC); | |
6123 | ||
6124 | /* Free up all remote VTEPs, if any. */ | |
6125 | zevpn_vtep_del_all(zevpn, 0); | |
6126 | ||
6127 | /* Delete the hash entry. */ | |
6128 | if (zevpn_del(zevpn)) { | |
6129 | flog_err(EC_ZEBRA_VNI_DEL_FAILED, | |
6130 | "Failed to del EVPN hash %p, IF %s(%u) VNI %u", | |
6131 | zevpn, ifp->name, ifp->ifindex, zevpn->vni); | |
6132 | return -1; | |
6133 | } | |
6134 | } | |
6135 | return 0; | |
6136 | } | |
6137 | ||
6138 | /* | |
6139 | * Handle VxLAN interface update - change to tunnel IP, master or VLAN. | |
6140 | */ | |
6141 | int zebra_vxlan_if_update(struct interface *ifp, uint16_t chgflags) | |
6142 | { | |
6143 | vni_t vni; | |
6144 | struct zebra_if *zif = NULL; | |
6145 | struct zebra_l2info_vxlan *vxl = NULL; | |
6146 | zebra_evpn_t *zevpn = NULL; | |
6147 | zebra_l3vni_t *zl3vni = NULL; | |
6148 | ||
6149 | /* Check if EVPN is enabled. */ | |
6150 | if (!is_evpn_enabled()) | |
6151 | return 0; | |
6152 | ||
6153 | zif = ifp->info; | |
6154 | assert(zif); | |
6155 | vxl = &zif->l2info.vxl; | |
6156 | vni = vxl->vni; | |
6157 | ||
6158 | zl3vni = zl3vni_lookup(vni); | |
6159 | if (zl3vni) { | |
6160 | ||
6161 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6162 | zlog_debug( | |
6163 | "Update L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", | |
6164 | vni, ifp->name, ifp->ifindex, vxl->access_vlan, | |
6165 | inet_ntoa(vxl->vtep_ip), | |
6166 | zif->brslave_info.bridge_ifindex, chgflags); | |
6167 | ||
6168 | /* Removed from bridge? Cleanup and return */ | |
6169 | if ((chgflags & ZEBRA_VXLIF_MASTER_CHANGE) | |
6170 | && (zif->brslave_info.bridge_ifindex == IFINDEX_INTERNAL)) { | |
6171 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6172 | return 0; | |
6173 | } | |
6174 | ||
6175 | /* access-vlan change - process oper down, associate with new | |
6176 | * svi_if and then process oper up again | |
6177 | */ | |
6178 | if (chgflags & ZEBRA_VXLIF_VLAN_CHANGE) { | |
6179 | if (if_is_operative(ifp)) { | |
6180 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6181 | zl3vni->svi_if = NULL; | |
6182 | zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); | |
6183 | zl3vni->mac_vlan_if = | |
6184 | zl3vni_map_to_mac_vlan_if(zl3vni); | |
6185 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
6186 | if (is_l3vni_oper_up(zl3vni)) | |
6187 | zebra_vxlan_process_l3vni_oper_up( | |
6188 | zl3vni); | |
6189 | } | |
6190 | } | |
6191 | ||
6192 | /* | |
6193 | * local-ip change - process oper down, associate with new | |
6194 | * local-ip and then process oper up again | |
6195 | */ | |
6196 | if (chgflags & ZEBRA_VXLIF_LOCAL_IP_CHANGE) { | |
6197 | if (if_is_operative(ifp)) { | |
6198 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6199 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
6200 | if (is_l3vni_oper_up(zl3vni)) | |
6201 | zebra_vxlan_process_l3vni_oper_up( | |
6202 | zl3vni); | |
6203 | } | |
6204 | } | |
6205 | ||
6206 | /* Update local tunnel IP. */ | |
6207 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
6208 | ||
6209 | /* if we have a valid new master, process l3-vni oper up */ | |
6210 | if (chgflags & ZEBRA_VXLIF_MASTER_CHANGE) { | |
6211 | if (if_is_operative(ifp) && is_l3vni_oper_up(zl3vni)) | |
6212 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
6213 | } | |
6214 | } else { | |
6215 | ||
6216 | /* Update VNI hash. */ | |
6217 | zevpn = zevpn_lookup(vni); | |
6218 | if (!zevpn) { | |
6219 | zlog_debug( | |
6220 | "Failed to find EVPN hash on update, IF %s(%u) VNI %u", | |
6221 | ifp->name, ifp->ifindex, vni); | |
6222 | return -1; | |
6223 | } | |
6224 | ||
6225 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6226 | zlog_debug( | |
6227 | "Update L2-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x", | |
6228 | vni, ifp->name, ifp->ifindex, vxl->access_vlan, | |
6229 | inet_ntoa(vxl->vtep_ip), | |
6230 | zif->brslave_info.bridge_ifindex, chgflags); | |
6231 | ||
6232 | /* Removed from bridge? Cleanup and return */ | |
6233 | if ((chgflags & ZEBRA_VXLIF_MASTER_CHANGE) | |
6234 | && (zif->brslave_info.bridge_ifindex == IFINDEX_INTERNAL)) { | |
6235 | /* Delete from client, remove all remote VTEPs */ | |
6236 | /* Also, free up all MACs and neighbors. */ | |
6237 | zevpn_send_del_to_client(zevpn); | |
6238 | zebra_evpn_neigh_del_all(zevpn, 1, 0, DEL_ALL_NEIGH); | |
6239 | zebra_evpn_mac_del_all(zevpn, 1, 0, DEL_ALL_MAC); | |
6240 | zevpn_vtep_del_all(zevpn, 1); | |
6241 | return 0; | |
6242 | } | |
6243 | ||
6244 | /* Handle other changes. */ | |
6245 | if (chgflags & ZEBRA_VXLIF_VLAN_CHANGE) { | |
6246 | /* Remove all existing local neigh and MACs for this VNI | |
6247 | * (including from BGP) | |
6248 | */ | |
6249 | zebra_evpn_neigh_del_all(zevpn, 0, 1, DEL_LOCAL_MAC); | |
6250 | zebra_evpn_mac_del_all(zevpn, 0, 1, DEL_LOCAL_MAC); | |
6251 | } | |
6252 | ||
6253 | if (zevpn->local_vtep_ip.s_addr != vxl->vtep_ip.s_addr || | |
6254 | zevpn->mcast_grp.s_addr != vxl->mcast_grp.s_addr) { | |
6255 | zebra_vxlan_sg_deref(zevpn->local_vtep_ip, | |
6256 | zevpn->mcast_grp); | |
6257 | zebra_vxlan_sg_ref(vxl->vtep_ip, vxl->mcast_grp); | |
6258 | zevpn->local_vtep_ip = vxl->vtep_ip; | |
6259 | zevpn->mcast_grp = vxl->mcast_grp; | |
6260 | /* on local vtep-ip check if ES orig-ip | |
6261 | * needs to be updated | |
6262 | */ | |
6263 | zebra_evpn_es_set_base_evpn(zevpn); | |
6264 | } | |
6265 | zevpn_vxlan_if_set(zevpn, ifp, true /* set */); | |
6266 | /* Take further actions needed. | |
6267 | * Note that if we are here, there is a change of interest. | |
6268 | */ | |
6269 | /* If down or not mapped to a bridge, we're done. */ | |
6270 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
6271 | return 0; | |
6272 | ||
6273 | /* Inform BGP, if there is a change of interest. */ | |
6274 | if (chgflags | |
6275 | & (ZEBRA_VXLIF_MASTER_CHANGE | | |
6276 | ZEBRA_VXLIF_LOCAL_IP_CHANGE | | |
6277 | ZEBRA_VXLIF_MCAST_GRP_CHANGE)) | |
6278 | zevpn_send_add_to_client(zevpn); | |
6279 | ||
6280 | /* If there is a valid new master or a VLAN mapping change, | |
6281 | * read and populate local MACs and neighbors. | |
6282 | * Also, reinstall any remote MACs and neighbors | |
6283 | * for this VNI (based on new VLAN). | |
6284 | */ | |
6285 | if (chgflags & ZEBRA_VXLIF_MASTER_CHANGE) | |
6286 | zevpn_read_mac_neigh(zevpn, ifp); | |
6287 | else if (chgflags & ZEBRA_VXLIF_VLAN_CHANGE) { | |
6288 | struct mac_walk_ctx m_wctx; | |
6289 | struct neigh_walk_ctx n_wctx; | |
6290 | ||
6291 | zevpn_read_mac_neigh(zevpn, ifp); | |
6292 | ||
6293 | memset(&m_wctx, 0, sizeof(struct mac_walk_ctx)); | |
6294 | m_wctx.zevpn = zevpn; | |
6295 | hash_iterate(zevpn->mac_table, zevpn_install_mac_hash, | |
6296 | &m_wctx); | |
6297 | ||
6298 | memset(&n_wctx, 0, sizeof(struct neigh_walk_ctx)); | |
6299 | n_wctx.zevpn = zevpn; | |
6300 | hash_iterate(zevpn->neigh_table, | |
6301 | zebra_evpn_install_neigh_hash, &n_wctx); | |
6302 | } | |
6303 | } | |
6304 | ||
6305 | return 0; | |
6306 | } | |
6307 | ||
6308 | /* | |
6309 | * Handle VxLAN interface add. | |
6310 | */ | |
6311 | int zebra_vxlan_if_add(struct interface *ifp) | |
6312 | { | |
6313 | vni_t vni; | |
6314 | struct zebra_if *zif = NULL; | |
6315 | struct zebra_l2info_vxlan *vxl = NULL; | |
6316 | zebra_evpn_t *zevpn = NULL; | |
6317 | zebra_l3vni_t *zl3vni = NULL; | |
6318 | ||
6319 | /* Check if EVPN is enabled. */ | |
6320 | if (!is_evpn_enabled()) | |
6321 | return 0; | |
6322 | ||
6323 | zif = ifp->info; | |
6324 | assert(zif); | |
6325 | vxl = &zif->l2info.vxl; | |
6326 | vni = vxl->vni; | |
6327 | ||
6328 | zl3vni = zl3vni_lookup(vni); | |
6329 | if (zl3vni) { | |
6330 | ||
6331 | /* process if-add for l3-vni*/ | |
6332 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6333 | zlog_debug( | |
6334 | "Add L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u", | |
6335 | vni, ifp->name, ifp->ifindex, vxl->access_vlan, | |
6336 | inet_ntoa(vxl->vtep_ip), | |
6337 | zif->brslave_info.bridge_ifindex); | |
6338 | ||
6339 | /* associate with vxlan_if */ | |
6340 | zl3vni->local_vtep_ip = vxl->vtep_ip; | |
6341 | zl3vni->vxlan_if = ifp; | |
6342 | ||
6343 | /* Associate with SVI, if any. We can associate with svi-if only | |
6344 | * after association with vxlan_if is complete */ | |
6345 | zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); | |
6346 | ||
6347 | zl3vni->mac_vlan_if = zl3vni_map_to_mac_vlan_if(zl3vni); | |
6348 | ||
6349 | if (is_l3vni_oper_up(zl3vni)) | |
6350 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
6351 | } else { | |
6352 | ||
6353 | /* process if-add for l2-vni */ | |
6354 | struct interface *vlan_if = NULL; | |
6355 | ||
6356 | /* Create or update EVPN hash. */ | |
6357 | zevpn = zevpn_lookup(vni); | |
6358 | if (!zevpn) { | |
6359 | zevpn = zevpn_add(vni); | |
6360 | if (!zevpn) { | |
6361 | flog_err( | |
6362 | EC_ZEBRA_VNI_ADD_FAILED, | |
6363 | "Failed to add EVPN hash, IF %s(%u) VNI %u", | |
6364 | ifp->name, ifp->ifindex, vni); | |
6365 | return -1; | |
6366 | } | |
6367 | } | |
6368 | ||
6369 | if (zevpn->local_vtep_ip.s_addr != vxl->vtep_ip.s_addr || | |
6370 | zevpn->mcast_grp.s_addr != vxl->mcast_grp.s_addr) { | |
6371 | zebra_vxlan_sg_deref(zevpn->local_vtep_ip, | |
6372 | zevpn->mcast_grp); | |
6373 | zebra_vxlan_sg_ref(vxl->vtep_ip, vxl->mcast_grp); | |
6374 | zevpn->local_vtep_ip = vxl->vtep_ip; | |
6375 | zevpn->mcast_grp = vxl->mcast_grp; | |
6376 | /* on local vtep-ip check if ES orig-ip | |
6377 | * needs to be updated | |
6378 | */ | |
6379 | zebra_evpn_es_set_base_evpn(zevpn); | |
6380 | } | |
6381 | zevpn_vxlan_if_set(zevpn, ifp, true /* set */); | |
6382 | vlan_if = zvni_map_to_svi(vxl->access_vlan, | |
6383 | zif->brslave_info.br_if); | |
6384 | if (vlan_if) { | |
6385 | zevpn->vrf_id = vlan_if->vrf_id; | |
6386 | zl3vni = zl3vni_from_vrf(vlan_if->vrf_id); | |
6387 | if (zl3vni) | |
6388 | listnode_add_sort(zl3vni->l2vnis, zevpn); | |
6389 | } | |
6390 | ||
6391 | if (IS_ZEBRA_DEBUG_VXLAN) { | |
6392 | char addr_buf1[INET_ADDRSTRLEN]; | |
6393 | char addr_buf2[INET_ADDRSTRLEN]; | |
6394 | ||
6395 | inet_ntop(AF_INET, &vxl->vtep_ip, | |
6396 | addr_buf1, INET_ADDRSTRLEN); | |
6397 | inet_ntop(AF_INET, &vxl->mcast_grp, | |
6398 | addr_buf2, INET_ADDRSTRLEN); | |
6399 | ||
6400 | zlog_debug( | |
6401 | "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s mcast_grp %s master %u", | |
6402 | vni, | |
6403 | vlan_if ? vrf_id_to_name(vlan_if->vrf_id) | |
6404 | : VRF_DEFAULT_NAME, | |
6405 | ifp->name, ifp->ifindex, vxl->access_vlan, | |
6406 | addr_buf1, addr_buf2, | |
6407 | zif->brslave_info.bridge_ifindex); | |
6408 | } | |
6409 | ||
6410 | /* If down or not mapped to a bridge, we're done. */ | |
6411 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
6412 | return 0; | |
6413 | ||
6414 | /* Inform BGP */ | |
6415 | zevpn_send_add_to_client(zevpn); | |
6416 | ||
6417 | /* Read and populate local MACs and neighbors */ | |
6418 | zevpn_read_mac_neigh(zevpn, ifp); | |
6419 | } | |
6420 | ||
6421 | return 0; | |
6422 | } | |
6423 | ||
6424 | int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf *zvrf, vni_t vni, | |
6425 | char *err, int err_str_sz, int filter, | |
6426 | int add) | |
6427 | { | |
6428 | zebra_l3vni_t *zl3vni = NULL; | |
6429 | struct zebra_vrf *zvrf_evpn = NULL; | |
6430 | ||
6431 | zvrf_evpn = zebra_vrf_get_evpn(); | |
6432 | if (!zvrf_evpn) | |
6433 | return -1; | |
6434 | ||
6435 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6436 | zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf), vni, | |
6437 | add ? "ADD" : "DEL"); | |
6438 | ||
6439 | if (add) { | |
6440 | ||
6441 | zebra_vxlan_handle_vni_transition(zvrf, vni, add); | |
6442 | ||
6443 | /* check if the vni is already present under zvrf */ | |
6444 | if (zvrf->l3vni) { | |
6445 | snprintf(err, err_str_sz, | |
6446 | "VNI is already configured under the vrf"); | |
6447 | return -1; | |
6448 | } | |
6449 | ||
6450 | /* check if this VNI is already present in the system */ | |
6451 | zl3vni = zl3vni_lookup(vni); | |
6452 | if (zl3vni) { | |
6453 | snprintf(err, err_str_sz, | |
6454 | "VNI is already configured as L3-VNI"); | |
6455 | return -1; | |
6456 | } | |
6457 | ||
6458 | /* add the L3-VNI to the global table */ | |
6459 | zl3vni = zl3vni_add(vni, zvrf_id(zvrf)); | |
6460 | if (!zl3vni) { | |
6461 | snprintf(err, err_str_sz, "Could not add L3-VNI"); | |
6462 | return -1; | |
6463 | } | |
6464 | ||
6465 | /* associate the vrf with vni */ | |
6466 | zvrf->l3vni = vni; | |
6467 | ||
6468 | /* set the filter in l3vni to denote if we are using l3vni only | |
6469 | * for prefix routes | |
6470 | */ | |
6471 | if (filter) | |
6472 | SET_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY); | |
6473 | ||
6474 | /* associate with vxlan-intf; | |
6475 | * we need to associate with the vxlan-intf first | |
6476 | */ | |
6477 | zl3vni->vxlan_if = zl3vni_map_to_vxlan_if(zl3vni); | |
6478 | ||
6479 | /* associate with corresponding SVI interface, we can associate | |
6480 | * with svi-if only after vxlan interface association is | |
6481 | * complete | |
6482 | */ | |
6483 | zl3vni->svi_if = zl3vni_map_to_svi_if(zl3vni); | |
6484 | ||
6485 | zl3vni->mac_vlan_if = zl3vni_map_to_mac_vlan_if(zl3vni); | |
6486 | ||
6487 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6488 | zlog_debug( | |
6489 | "%s: l3vni %u svi_if %s mac_vlan_if %s", | |
6490 | __func__, vni, | |
6491 | zl3vni->svi_if ? zl3vni->svi_if->name : "NIL", | |
6492 | zl3vni->mac_vlan_if ? zl3vni->mac_vlan_if->name | |
6493 | : "NIL"); | |
6494 | ||
6495 | /* formulate l2vni list */ | |
6496 | hash_iterate(zvrf_evpn->evpn_table, zevpn_add_to_l3vni_list, | |
6497 | zl3vni); | |
6498 | ||
6499 | if (is_l3vni_oper_up(zl3vni)) | |
6500 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
6501 | ||
6502 | } else { | |
6503 | zl3vni = zl3vni_lookup(vni); | |
6504 | if (!zl3vni) { | |
6505 | snprintf(err, err_str_sz, "VNI doesn't exist"); | |
6506 | return -1; | |
6507 | } | |
6508 | ||
6509 | if (zvrf->l3vni != vni) { | |
6510 | snprintf(err, err_str_sz, | |
6511 | "VNI %d doesn't exist in VRF: %s", | |
6512 | vni, zvrf->vrf->name); | |
6513 | return -1; | |
6514 | } | |
6515 | ||
6516 | if (filter && !CHECK_FLAG(zl3vni->filter, PREFIX_ROUTES_ONLY)) { | |
6517 | snprintf(err, ERR_STR_SZ, | |
6518 | "prefix-routes-only is not set for the vni"); | |
6519 | return -1; | |
6520 | } | |
6521 | ||
6522 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6523 | ||
6524 | /* delete and uninstall all rmacs */ | |
6525 | hash_iterate(zl3vni->rmac_table, zl3vni_del_rmac_hash_entry, | |
6526 | zl3vni); | |
6527 | ||
6528 | /* delete and uninstall all next-hops */ | |
6529 | hash_iterate(zl3vni->nh_table, zl3vni_del_nh_hash_entry, | |
6530 | zl3vni); | |
6531 | ||
6532 | zvrf->l3vni = 0; | |
6533 | zl3vni_del(zl3vni); | |
6534 | ||
6535 | zebra_vxlan_handle_vni_transition(zvrf, vni, add); | |
6536 | } | |
6537 | return 0; | |
6538 | } | |
6539 | ||
6540 | int zebra_vxlan_vrf_enable(struct zebra_vrf *zvrf) | |
6541 | { | |
6542 | zebra_l3vni_t *zl3vni = NULL; | |
6543 | ||
6544 | if (zvrf->l3vni) | |
6545 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
6546 | if (!zl3vni) | |
6547 | return 0; | |
6548 | ||
6549 | zl3vni->vrf_id = zvrf_id(zvrf); | |
6550 | if (is_l3vni_oper_up(zl3vni)) | |
6551 | zebra_vxlan_process_l3vni_oper_up(zl3vni); | |
6552 | return 0; | |
6553 | } | |
6554 | ||
6555 | int zebra_vxlan_vrf_disable(struct zebra_vrf *zvrf) | |
6556 | { | |
6557 | zebra_l3vni_t *zl3vni = NULL; | |
6558 | ||
6559 | if (zvrf->l3vni) | |
6560 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
6561 | if (!zl3vni) | |
6562 | return 0; | |
6563 | ||
6564 | zl3vni->vrf_id = VRF_UNKNOWN; | |
6565 | zebra_vxlan_process_l3vni_oper_down(zl3vni); | |
6566 | return 0; | |
6567 | } | |
6568 | ||
6569 | int zebra_vxlan_vrf_delete(struct zebra_vrf *zvrf) | |
6570 | { | |
6571 | zebra_l3vni_t *zl3vni = NULL; | |
6572 | vni_t vni; | |
6573 | ||
6574 | if (zvrf->l3vni) | |
6575 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
6576 | if (!zl3vni) | |
6577 | return 0; | |
6578 | ||
6579 | vni = zl3vni->vni; | |
6580 | zl3vni_del(zl3vni); | |
6581 | zebra_vxlan_handle_vni_transition(zvrf, vni, 0); | |
6582 | ||
6583 | return 0; | |
6584 | } | |
6585 | ||
6586 | /* | |
6587 | * Handle message from client to specify the flooding mechanism for | |
6588 | * BUM packets. The default is to do head-end (ingress) replication | |
6589 | * and the other supported option is to disable it. This applies to | |
6590 | * all BUM traffic and disabling it applies to both the transmit and | |
6591 | * receive direction. | |
6592 | */ | |
6593 | void zebra_vxlan_flood_control(ZAPI_HANDLER_ARGS) | |
6594 | { | |
6595 | struct stream *s; | |
6596 | enum vxlan_flood_control flood_ctrl; | |
6597 | ||
6598 | if (!EVPN_ENABLED(zvrf)) { | |
6599 | zlog_err("EVPN flood control for non-EVPN VRF %u", | |
6600 | zvrf_id(zvrf)); | |
6601 | return; | |
6602 | } | |
6603 | ||
6604 | s = msg; | |
6605 | STREAM_GETC(s, flood_ctrl); | |
6606 | ||
6607 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6608 | zlog_debug("EVPN flood control %u, currently %u", | |
6609 | flood_ctrl, zvrf->vxlan_flood_ctrl); | |
6610 | ||
6611 | if (zvrf->vxlan_flood_ctrl == flood_ctrl) | |
6612 | return; | |
6613 | ||
6614 | zvrf->vxlan_flood_ctrl = flood_ctrl; | |
6615 | ||
6616 | /* Install or uninstall flood entries corresponding to | |
6617 | * remote VTEPs. | |
6618 | */ | |
6619 | hash_iterate(zvrf->evpn_table, zevpn_handle_flooding_remote_vteps, | |
6620 | zvrf); | |
6621 | ||
6622 | stream_failure: | |
6623 | return; | |
6624 | } | |
6625 | ||
6626 | /* | |
6627 | * Handle message from client to enable/disable advertisement of svi macip | |
6628 | * routes | |
6629 | */ | |
6630 | void zebra_vxlan_advertise_svi_macip(ZAPI_HANDLER_ARGS) | |
6631 | { | |
6632 | struct stream *s; | |
6633 | int advertise; | |
6634 | vni_t vni = 0; | |
6635 | zebra_evpn_t *zevpn = NULL; | |
6636 | struct interface *ifp = NULL; | |
6637 | ||
6638 | if (!EVPN_ENABLED(zvrf)) { | |
6639 | zlog_debug("EVPN SVI-MACIP Adv for non-EVPN VRF %u", | |
6640 | zvrf_id(zvrf)); | |
6641 | return; | |
6642 | } | |
6643 | ||
6644 | s = msg; | |
6645 | STREAM_GETC(s, advertise); | |
6646 | STREAM_GETL(s, vni); | |
6647 | ||
6648 | if (!vni) { | |
6649 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6650 | zlog_debug("EVPN SVI-MACIP Adv %s, currently %s", | |
6651 | advertise ? "enabled" : "disabled", | |
6652 | advertise_svi_macip_enabled(NULL) | |
6653 | ? "enabled" | |
6654 | : "disabled"); | |
6655 | ||
6656 | if (zvrf->advertise_svi_macip == advertise) | |
6657 | return; | |
6658 | ||
6659 | ||
6660 | if (advertise) { | |
6661 | zvrf->advertise_svi_macip = advertise; | |
6662 | hash_iterate(zvrf->evpn_table, | |
6663 | zevpn_gw_macip_add_for_evpn_hash, NULL); | |
6664 | } else { | |
6665 | hash_iterate(zvrf->evpn_table, | |
6666 | zevpn_svi_macip_del_for_evpn_hash, NULL); | |
6667 | zvrf->advertise_svi_macip = advertise; | |
6668 | } | |
6669 | ||
6670 | } else { | |
6671 | struct zebra_if *zif = NULL; | |
6672 | struct zebra_l2info_vxlan zl2_info; | |
6673 | struct interface *vlan_if = NULL; | |
6674 | ||
6675 | zevpn = zevpn_lookup(vni); | |
6676 | if (!zevpn) | |
6677 | return; | |
6678 | ||
6679 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6680 | zlog_debug( | |
6681 | "EVPN SVI macip Adv %s on VNI %d , currently %s", | |
6682 | advertise ? "enabled" : "disabled", vni, | |
6683 | advertise_svi_macip_enabled(zevpn) | |
6684 | ? "enabled" | |
6685 | : "disabled"); | |
6686 | ||
6687 | if (zevpn->advertise_svi_macip == advertise) | |
6688 | return; | |
6689 | ||
6690 | /* Store flag even though SVI is not present. | |
6691 | * Once SVI comes up triggers self MAC-IP route add. | |
6692 | */ | |
6693 | zevpn->advertise_svi_macip = advertise; | |
6694 | ||
6695 | ifp = zevpn->vxlan_if; | |
6696 | if (!ifp) | |
6697 | return; | |
6698 | ||
6699 | zif = ifp->info; | |
6700 | ||
6701 | /* If down or not mapped to a bridge, we're done. */ | |
6702 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
6703 | return; | |
6704 | ||
6705 | zl2_info = zif->l2info.vxl; | |
6706 | vlan_if = zvni_map_to_svi(zl2_info.access_vlan, | |
6707 | zif->brslave_info.br_if); | |
6708 | if (!vlan_if) | |
6709 | return; | |
6710 | ||
6711 | if (advertise) { | |
6712 | /* Add primary SVI MAC-IP */ | |
6713 | zevpn_add_macip_for_intf(vlan_if, zevpn); | |
6714 | } else { | |
6715 | /* Del primary SVI MAC-IP */ | |
6716 | zevpn_del_macip_for_intf(vlan_if, zevpn); | |
6717 | } | |
6718 | } | |
6719 | ||
6720 | stream_failure: | |
6721 | return; | |
6722 | } | |
6723 | ||
6724 | /* | |
6725 | * Handle message from client to enable/disable advertisement of g/w macip | |
6726 | * routes | |
6727 | */ | |
6728 | void zebra_vxlan_advertise_subnet(ZAPI_HANDLER_ARGS) | |
6729 | { | |
6730 | struct stream *s; | |
6731 | int advertise; | |
6732 | vni_t vni = 0; | |
6733 | zebra_evpn_t *zevpn = NULL; | |
6734 | struct interface *ifp = NULL; | |
6735 | struct zebra_if *zif = NULL; | |
6736 | struct zebra_l2info_vxlan zl2_info; | |
6737 | struct interface *vlan_if = NULL; | |
6738 | ||
6739 | if (!EVPN_ENABLED(zvrf)) { | |
6740 | zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u", | |
6741 | zvrf_id(zvrf)); | |
6742 | return; | |
6743 | } | |
6744 | ||
6745 | s = msg; | |
6746 | STREAM_GETC(s, advertise); | |
6747 | STREAM_GET(&vni, s, 3); | |
6748 | ||
6749 | zevpn = zevpn_lookup(vni); | |
6750 | if (!zevpn) | |
6751 | return; | |
6752 | ||
6753 | if (zevpn->advertise_subnet == advertise) | |
6754 | return; | |
6755 | ||
6756 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6757 | zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s", | |
6758 | advertise ? "enabled" : "disabled", vni, | |
6759 | zevpn->advertise_subnet ? "enabled" : "disabled"); | |
6760 | ||
6761 | ||
6762 | zevpn->advertise_subnet = advertise; | |
6763 | ||
6764 | ifp = zevpn->vxlan_if; | |
6765 | if (!ifp) | |
6766 | return; | |
6767 | ||
6768 | zif = ifp->info; | |
6769 | ||
6770 | /* If down or not mapped to a bridge, we're done. */ | |
6771 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
6772 | return; | |
6773 | ||
6774 | zl2_info = zif->l2info.vxl; | |
6775 | ||
6776 | vlan_if = | |
6777 | zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if); | |
6778 | if (!vlan_if) | |
6779 | return; | |
6780 | ||
6781 | if (zevpn->advertise_subnet) | |
6782 | zevpn_advertise_subnet(zevpn, vlan_if, 1); | |
6783 | else | |
6784 | zevpn_advertise_subnet(zevpn, vlan_if, 0); | |
6785 | ||
6786 | stream_failure: | |
6787 | return; | |
6788 | } | |
6789 | ||
6790 | /* | |
6791 | * Handle message from client to enable/disable advertisement of g/w macip | |
6792 | * routes | |
6793 | */ | |
6794 | void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS) | |
6795 | { | |
6796 | struct stream *s; | |
6797 | int advertise; | |
6798 | vni_t vni = 0; | |
6799 | zebra_evpn_t *zevpn = NULL; | |
6800 | struct interface *ifp = NULL; | |
6801 | ||
6802 | if (!EVPN_ENABLED(zvrf)) { | |
6803 | zlog_debug("EVPN GW-MACIP Adv for non-EVPN VRF %u", | |
6804 | zvrf_id(zvrf)); | |
6805 | return; | |
6806 | } | |
6807 | ||
6808 | s = msg; | |
6809 | STREAM_GETC(s, advertise); | |
6810 | STREAM_GETL(s, vni); | |
6811 | ||
6812 | if (!vni) { | |
6813 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6814 | zlog_debug("EVPN gateway macip Adv %s, currently %s", | |
6815 | advertise ? "enabled" : "disabled", | |
6816 | advertise_gw_macip_enabled(NULL) | |
6817 | ? "enabled" | |
6818 | : "disabled"); | |
6819 | ||
6820 | if (zvrf->advertise_gw_macip == advertise) | |
6821 | return; | |
6822 | ||
6823 | zvrf->advertise_gw_macip = advertise; | |
6824 | ||
6825 | if (advertise_gw_macip_enabled(zevpn)) | |
6826 | hash_iterate(zvrf->evpn_table, | |
6827 | zevpn_gw_macip_add_for_evpn_hash, NULL); | |
6828 | else | |
6829 | hash_iterate(zvrf->evpn_table, | |
6830 | zevpn_gw_macip_del_for_evpn_hash, NULL); | |
6831 | ||
6832 | } else { | |
6833 | struct zebra_if *zif = NULL; | |
6834 | struct zebra_l2info_vxlan zl2_info; | |
6835 | struct interface *vlan_if = NULL; | |
6836 | struct interface *vrr_if = NULL; | |
6837 | ||
6838 | zevpn = zevpn_lookup(vni); | |
6839 | if (!zevpn) | |
6840 | return; | |
6841 | ||
6842 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6843 | zlog_debug( | |
6844 | "EVPN gateway macip Adv %s on VNI %d , currently %s", | |
6845 | advertise ? "enabled" : "disabled", vni, | |
6846 | advertise_gw_macip_enabled(zevpn) ? "enabled" | |
6847 | : "disabled"); | |
6848 | ||
6849 | if (zevpn->advertise_gw_macip == advertise) | |
6850 | return; | |
6851 | ||
6852 | zevpn->advertise_gw_macip = advertise; | |
6853 | ||
6854 | ifp = zevpn->vxlan_if; | |
6855 | if (!ifp) | |
6856 | return; | |
6857 | ||
6858 | zif = ifp->info; | |
6859 | ||
6860 | /* If down or not mapped to a bridge, we're done. */ | |
6861 | if (!if_is_operative(ifp) || !zif->brslave_info.br_if) | |
6862 | return; | |
6863 | ||
6864 | zl2_info = zif->l2info.vxl; | |
6865 | ||
6866 | vlan_if = zvni_map_to_svi(zl2_info.access_vlan, | |
6867 | zif->brslave_info.br_if); | |
6868 | if (!vlan_if) | |
6869 | return; | |
6870 | ||
6871 | if (advertise_gw_macip_enabled(zevpn)) { | |
6872 | /* Add primary SVI MAC-IP */ | |
6873 | zevpn_add_macip_for_intf(vlan_if, zevpn); | |
6874 | ||
6875 | /* Add VRR MAC-IP - if any*/ | |
6876 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
6877 | if (vrr_if) | |
6878 | zevpn_add_macip_for_intf(vrr_if, zevpn); | |
6879 | } else { | |
6880 | /* Del primary MAC-IP */ | |
6881 | zevpn_del_macip_for_intf(vlan_if, zevpn); | |
6882 | ||
6883 | /* Del VRR MAC-IP - if any*/ | |
6884 | vrr_if = zebra_get_vrr_intf_for_svi(vlan_if); | |
6885 | if (vrr_if) | |
6886 | zevpn_del_macip_for_intf(vrr_if, zevpn); | |
6887 | } | |
6888 | } | |
6889 | ||
6890 | stream_failure: | |
6891 | return; | |
6892 | } | |
6893 | ||
6894 | ||
6895 | /* | |
6896 | * Handle message from client to learn (or stop learning) about VNIs and MACs. | |
6897 | * When enabled, the VNI hash table will be built and MAC FDB table read; | |
6898 | * when disabled, the entries should be deleted and remote VTEPs and MACs | |
6899 | * uninstalled from the kernel. | |
6900 | * This also informs the setting for BUM handling at the time this change | |
6901 | * occurs; it is relevant only when specifying "learn". | |
6902 | */ | |
6903 | void zebra_vxlan_advertise_all_vni(ZAPI_HANDLER_ARGS) | |
6904 | { | |
6905 | struct stream *s = NULL; | |
6906 | int advertise = 0; | |
6907 | enum vxlan_flood_control flood_ctrl; | |
6908 | ||
6909 | /* Mismatch between EVPN VRF and current VRF (should be prevented by | |
6910 | * bgpd's cli) */ | |
6911 | if (is_evpn_enabled() && !EVPN_ENABLED(zvrf)) | |
6912 | return; | |
6913 | ||
6914 | s = msg; | |
6915 | STREAM_GETC(s, advertise); | |
6916 | STREAM_GETC(s, flood_ctrl); | |
6917 | ||
6918 | if (IS_ZEBRA_DEBUG_VXLAN) | |
6919 | zlog_debug("EVPN VRF %s(%u) VNI Adv %s, currently %s, flood control %u", | |
6920 | zvrf_name(zvrf), zvrf_id(zvrf), | |
6921 | advertise ? "enabled" : "disabled", | |
6922 | is_evpn_enabled() ? "enabled" : "disabled", | |
6923 | flood_ctrl); | |
6924 | ||
6925 | if (zvrf->advertise_all_vni == advertise) | |
6926 | return; | |
6927 | ||
6928 | zvrf->advertise_all_vni = advertise; | |
6929 | if (EVPN_ENABLED(zvrf)) { | |
6930 | zrouter.evpn_vrf = zvrf; | |
6931 | ||
6932 | /* Note BUM handling */ | |
6933 | zvrf->vxlan_flood_ctrl = flood_ctrl; | |
6934 | ||
6935 | /* Replay all ESs */ | |
6936 | zebra_evpn_es_send_all_to_client(true /* add */); | |
6937 | ||
6938 | /* Build EVPN hash table and inform BGP. */ | |
6939 | zevpn_build_hash_table(); | |
6940 | ||
6941 | /* Add all SVI (L3 GW) MACs to BGP*/ | |
6942 | hash_iterate(zvrf->evpn_table, zevpn_gw_macip_add_for_evpn_hash, | |
6943 | NULL); | |
6944 | ||
6945 | /* Read the MAC FDB */ | |
6946 | macfdb_read(zvrf->zns); | |
6947 | ||
6948 | /* Read neighbors */ | |
6949 | neigh_read(zvrf->zns); | |
6950 | } else { | |
6951 | /* Cleanup VTEPs for all EVPNs - uninstall from | |
6952 | * kernel and free entries. | |
6953 | */ | |
6954 | hash_iterate(zvrf->evpn_table, zevpn_cleanup_all, zvrf); | |
6955 | ||
6956 | /* Delete all ESs in BGP */ | |
6957 | zebra_evpn_es_send_all_to_client(false /* add */); | |
6958 | ||
6959 | /* cleanup all l3vnis */ | |
6960 | hash_iterate(zrouter.l3vni_table, zl3vni_cleanup_all, NULL); | |
6961 | ||
6962 | /* Mark as "no EVPN VRF" */ | |
6963 | zrouter.evpn_vrf = NULL; | |
6964 | } | |
6965 | ||
6966 | stream_failure: | |
6967 | return; | |
6968 | } | |
6969 | ||
6970 | /* | |
6971 | * Allocate EVPN hash table for this VRF and do other initialization. | |
6972 | * NOTE: Currently supported only for default VRF. | |
6973 | */ | |
6974 | void zebra_vxlan_init_tables(struct zebra_vrf *zvrf) | |
6975 | { | |
6976 | if (!zvrf) | |
6977 | return; | |
6978 | zvrf->evpn_table = hash_create(evpn_hash_keymake, vni_hash_cmp, | |
6979 | "Zebra VRF EVPN Table"); | |
6980 | zvrf->vxlan_sg_table = hash_create(zebra_vxlan_sg_hash_key_make, | |
6981 | zebra_vxlan_sg_hash_eq, "Zebra VxLAN SG Table"); | |
6982 | } | |
6983 | ||
6984 | /* Cleanup EVPN info, but don't free the table. */ | |
6985 | void zebra_vxlan_cleanup_tables(struct zebra_vrf *zvrf) | |
6986 | { | |
6987 | struct zebra_vrf *evpn_zvrf = zebra_vrf_get_evpn(); | |
6988 | ||
6989 | if (!zvrf) | |
6990 | return; | |
6991 | hash_iterate(zvrf->evpn_table, zevpn_cleanup_all, zvrf); | |
6992 | hash_iterate(zvrf->vxlan_sg_table, zebra_vxlan_sg_cleanup, NULL); | |
6993 | ||
6994 | if (zvrf == evpn_zvrf) | |
6995 | zebra_evpn_es_cleanup(); | |
6996 | } | |
6997 | ||
6998 | /* Close all EVPN handling */ | |
6999 | void zebra_vxlan_close_tables(struct zebra_vrf *zvrf) | |
7000 | { | |
7001 | if (!zvrf) | |
7002 | return; | |
7003 | hash_iterate(zvrf->evpn_table, zevpn_cleanup_all, zvrf); | |
7004 | hash_free(zvrf->evpn_table); | |
7005 | } | |
7006 | ||
7007 | /* init the l3vni table */ | |
7008 | void zebra_vxlan_init(void) | |
7009 | { | |
7010 | zrouter.l3vni_table = hash_create(l3vni_hash_keymake, l3vni_hash_cmp, | |
7011 | "Zebra VRF L3 VNI table"); | |
7012 | zrouter.evpn_vrf = NULL; | |
7013 | zebra_evpn_mh_init(); | |
7014 | } | |
7015 | ||
7016 | /* free l3vni table */ | |
7017 | void zebra_vxlan_disable(void) | |
7018 | { | |
7019 | hash_free(zrouter.l3vni_table); | |
7020 | zebra_evpn_mh_terminate(); | |
7021 | } | |
7022 | ||
7023 | /* get the l3vni svi ifindex */ | |
7024 | ifindex_t get_l3vni_svi_ifindex(vrf_id_t vrf_id) | |
7025 | { | |
7026 | zebra_l3vni_t *zl3vni = NULL; | |
7027 | ||
7028 | zl3vni = zl3vni_from_vrf(vrf_id); | |
7029 | if (!zl3vni || !is_l3vni_oper_up(zl3vni)) | |
7030 | return 0; | |
7031 | ||
7032 | return zl3vni->svi_if->ifindex; | |
7033 | } | |
7034 | ||
7035 | /************************** vxlan SG cache management ************************/ | |
7036 | /* Inform PIM about the mcast group */ | |
7037 | static int zebra_vxlan_sg_send(struct zebra_vrf *zvrf, | |
7038 | struct prefix_sg *sg, | |
7039 | char *sg_str, uint16_t cmd) | |
7040 | { | |
7041 | struct zserv *client = NULL; | |
7042 | struct stream *s = NULL; | |
7043 | ||
7044 | client = zserv_find_client(ZEBRA_ROUTE_PIM, 0); | |
7045 | if (!client) | |
7046 | return 0; | |
7047 | ||
7048 | if (!CHECK_FLAG(zvrf->flags, ZEBRA_PIM_SEND_VXLAN_SG)) | |
7049 | return 0; | |
7050 | ||
7051 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); | |
7052 | ||
7053 | zclient_create_header(s, cmd, VRF_DEFAULT); | |
7054 | stream_putl(s, IPV4_MAX_BYTELEN); | |
7055 | stream_put(s, &sg->src.s_addr, IPV4_MAX_BYTELEN); | |
7056 | stream_put(s, &sg->grp.s_addr, IPV4_MAX_BYTELEN); | |
7057 | ||
7058 | /* Write packet size. */ | |
7059 | stream_putw_at(s, 0, stream_get_endp(s)); | |
7060 | ||
7061 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7062 | zlog_debug( | |
7063 | "Send %s %s to %s", | |
7064 | (cmd == ZEBRA_VXLAN_SG_ADD) ? "add" : "del", sg_str, | |
7065 | zebra_route_string(client->proto)); | |
7066 | ||
7067 | if (cmd == ZEBRA_VXLAN_SG_ADD) | |
7068 | client->vxlan_sg_add_cnt++; | |
7069 | else | |
7070 | client->vxlan_sg_del_cnt++; | |
7071 | ||
7072 | return zserv_send_message(client, s); | |
7073 | } | |
7074 | ||
7075 | static unsigned int zebra_vxlan_sg_hash_key_make(const void *p) | |
7076 | { | |
7077 | const zebra_vxlan_sg_t *vxlan_sg = p; | |
7078 | ||
7079 | return (jhash_2words(vxlan_sg->sg.src.s_addr, | |
7080 | vxlan_sg->sg.grp.s_addr, 0)); | |
7081 | } | |
7082 | ||
7083 | static bool zebra_vxlan_sg_hash_eq(const void *p1, const void *p2) | |
7084 | { | |
7085 | const zebra_vxlan_sg_t *sg1 = p1; | |
7086 | const zebra_vxlan_sg_t *sg2 = p2; | |
7087 | ||
7088 | return ((sg1->sg.src.s_addr == sg2->sg.src.s_addr) | |
7089 | && (sg1->sg.grp.s_addr == sg2->sg.grp.s_addr)); | |
7090 | } | |
7091 | ||
7092 | static zebra_vxlan_sg_t *zebra_vxlan_sg_new(struct zebra_vrf *zvrf, | |
7093 | struct prefix_sg *sg) | |
7094 | { | |
7095 | zebra_vxlan_sg_t *vxlan_sg; | |
7096 | ||
7097 | vxlan_sg = XCALLOC(MTYPE_ZVXLAN_SG, sizeof(*vxlan_sg)); | |
7098 | ||
7099 | vxlan_sg->zvrf = zvrf; | |
7100 | vxlan_sg->sg = *sg; | |
7101 | prefix_sg2str(sg, vxlan_sg->sg_str); | |
7102 | ||
7103 | vxlan_sg = hash_get(zvrf->vxlan_sg_table, vxlan_sg, hash_alloc_intern); | |
7104 | ||
7105 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7106 | zlog_debug("vxlan SG %s created", vxlan_sg->sg_str); | |
7107 | ||
7108 | return vxlan_sg; | |
7109 | } | |
7110 | ||
7111 | static zebra_vxlan_sg_t *zebra_vxlan_sg_find(struct zebra_vrf *zvrf, | |
7112 | struct prefix_sg *sg) | |
7113 | { | |
7114 | zebra_vxlan_sg_t lookup; | |
7115 | ||
7116 | lookup.sg = *sg; | |
7117 | return hash_lookup(zvrf->vxlan_sg_table, &lookup); | |
7118 | } | |
7119 | ||
7120 | static zebra_vxlan_sg_t *zebra_vxlan_sg_add(struct zebra_vrf *zvrf, | |
7121 | struct prefix_sg *sg) | |
7122 | { | |
7123 | zebra_vxlan_sg_t *vxlan_sg; | |
7124 | zebra_vxlan_sg_t *parent = NULL; | |
7125 | struct in_addr sip; | |
7126 | ||
7127 | vxlan_sg = zebra_vxlan_sg_find(zvrf, sg); | |
7128 | if (vxlan_sg) | |
7129 | return vxlan_sg; | |
7130 | ||
7131 | /* create a *G entry for every BUM group implicitly - | |
7132 | * 1. The SG entry is used by pimd to setup the vxlan-origination-mroute | |
7133 | * 2. the XG entry is used by pimd to setup the | |
7134 | * vxlan-termination-mroute | |
7135 | */ | |
7136 | if (sg->src.s_addr != INADDR_ANY) { | |
7137 | memset(&sip, 0, sizeof(sip)); | |
7138 | parent = zebra_vxlan_sg_do_ref(zvrf, sip, sg->grp); | |
7139 | if (!parent) | |
7140 | return NULL; | |
7141 | } | |
7142 | ||
7143 | vxlan_sg = zebra_vxlan_sg_new(zvrf, sg); | |
7144 | if (!vxlan_sg) { | |
7145 | if (parent) | |
7146 | zebra_vxlan_sg_do_deref(zvrf, sip, sg->grp); | |
7147 | return vxlan_sg; | |
7148 | } | |
7149 | ||
7150 | zebra_vxlan_sg_send(zvrf, sg, vxlan_sg->sg_str, | |
7151 | ZEBRA_VXLAN_SG_ADD); | |
7152 | ||
7153 | return vxlan_sg; | |
7154 | } | |
7155 | ||
7156 | static void zebra_vxlan_sg_del(zebra_vxlan_sg_t *vxlan_sg) | |
7157 | { | |
7158 | struct in_addr sip; | |
7159 | struct zebra_vrf *zvrf; | |
7160 | ||
7161 | zvrf = vrf_info_lookup(VRF_DEFAULT); | |
7162 | if (!zvrf) | |
7163 | return; | |
7164 | ||
7165 | /* On SG entry deletion remove the reference to its parent XG | |
7166 | * entry | |
7167 | */ | |
7168 | if (vxlan_sg->sg.src.s_addr != INADDR_ANY) { | |
7169 | memset(&sip, 0, sizeof(sip)); | |
7170 | zebra_vxlan_sg_do_deref(zvrf, sip, vxlan_sg->sg.grp); | |
7171 | } | |
7172 | ||
7173 | zebra_vxlan_sg_send(zvrf, &vxlan_sg->sg, | |
7174 | vxlan_sg->sg_str, ZEBRA_VXLAN_SG_DEL); | |
7175 | ||
7176 | hash_release(vxlan_sg->zvrf->vxlan_sg_table, vxlan_sg); | |
7177 | ||
7178 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7179 | zlog_debug("VXLAN SG %s deleted", vxlan_sg->sg_str); | |
7180 | ||
7181 | XFREE(MTYPE_ZVXLAN_SG, vxlan_sg); | |
7182 | } | |
7183 | ||
7184 | static void zebra_vxlan_sg_do_deref(struct zebra_vrf *zvrf, | |
7185 | struct in_addr sip, struct in_addr mcast_grp) | |
7186 | { | |
7187 | zebra_vxlan_sg_t *vxlan_sg; | |
7188 | struct prefix_sg sg; | |
7189 | ||
7190 | sg.family = AF_INET; | |
7191 | sg.prefixlen = IPV4_MAX_BYTELEN; | |
7192 | sg.src = sip; | |
7193 | sg.grp = mcast_grp; | |
7194 | vxlan_sg = zebra_vxlan_sg_find(zvrf, &sg); | |
7195 | if (!vxlan_sg) | |
7196 | return; | |
7197 | ||
7198 | if (vxlan_sg->ref_cnt) | |
7199 | --vxlan_sg->ref_cnt; | |
7200 | ||
7201 | if (!vxlan_sg->ref_cnt) | |
7202 | zebra_vxlan_sg_del(vxlan_sg); | |
7203 | } | |
7204 | ||
7205 | static zebra_vxlan_sg_t *zebra_vxlan_sg_do_ref(struct zebra_vrf *zvrf, | |
7206 | struct in_addr sip, struct in_addr mcast_grp) | |
7207 | { | |
7208 | zebra_vxlan_sg_t *vxlan_sg; | |
7209 | struct prefix_sg sg; | |
7210 | ||
7211 | sg.family = AF_INET; | |
7212 | sg.prefixlen = IPV4_MAX_BYTELEN; | |
7213 | sg.src = sip; | |
7214 | sg.grp = mcast_grp; | |
7215 | vxlan_sg = zebra_vxlan_sg_add(zvrf, &sg); | |
7216 | if (vxlan_sg) | |
7217 | ++vxlan_sg->ref_cnt; | |
7218 | ||
7219 | return vxlan_sg; | |
7220 | } | |
7221 | ||
7222 | static void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip, | |
7223 | struct in_addr mcast_grp) | |
7224 | { | |
7225 | struct zebra_vrf *zvrf; | |
7226 | ||
7227 | if (local_vtep_ip.s_addr == INADDR_ANY | |
7228 | || mcast_grp.s_addr == INADDR_ANY) | |
7229 | return; | |
7230 | ||
7231 | zvrf = vrf_info_lookup(VRF_DEFAULT); | |
7232 | if (!zvrf) | |
7233 | return; | |
7234 | ||
7235 | zebra_vxlan_sg_do_deref(zvrf, local_vtep_ip, mcast_grp); | |
7236 | } | |
7237 | ||
7238 | static void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip, | |
7239 | struct in_addr mcast_grp) | |
7240 | { | |
7241 | struct zebra_vrf *zvrf; | |
7242 | ||
7243 | if (local_vtep_ip.s_addr == INADDR_ANY | |
7244 | || mcast_grp.s_addr == INADDR_ANY) | |
7245 | return; | |
7246 | ||
7247 | zvrf = vrf_info_lookup(VRF_DEFAULT); | |
7248 | if (!zvrf) | |
7249 | return; | |
7250 | zebra_vxlan_sg_do_ref(zvrf, local_vtep_ip, mcast_grp); | |
7251 | } | |
7252 | ||
7253 | static void zebra_vxlan_sg_cleanup(struct hash_bucket *backet, void *arg) | |
7254 | { | |
7255 | zebra_vxlan_sg_t *vxlan_sg = (zebra_vxlan_sg_t *)backet->data; | |
7256 | ||
7257 | zebra_vxlan_sg_del(vxlan_sg); | |
7258 | } | |
7259 | ||
7260 | static void zebra_vxlan_sg_replay_send(struct hash_bucket *backet, void *arg) | |
7261 | { | |
7262 | zebra_vxlan_sg_t *vxlan_sg = (zebra_vxlan_sg_t *)backet->data; | |
7263 | ||
7264 | zebra_vxlan_sg_send(vxlan_sg->zvrf, &vxlan_sg->sg, | |
7265 | vxlan_sg->sg_str, ZEBRA_VXLAN_SG_ADD); | |
7266 | } | |
7267 | ||
7268 | /* Handle message from client to replay vxlan SG entries */ | |
7269 | void zebra_vxlan_sg_replay(ZAPI_HANDLER_ARGS) | |
7270 | { | |
7271 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7272 | zlog_debug("VxLAN SG updates to PIM, start"); | |
7273 | ||
7274 | SET_FLAG(zvrf->flags, ZEBRA_PIM_SEND_VXLAN_SG); | |
7275 | ||
7276 | if (!EVPN_ENABLED(zvrf)) { | |
7277 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7278 | zlog_debug("VxLAN SG replay request on unexpected vrf %d", | |
7279 | zvrf->vrf->vrf_id); | |
7280 | return; | |
7281 | } | |
7282 | ||
7283 | hash_iterate(zvrf->vxlan_sg_table, zebra_vxlan_sg_replay_send, NULL); | |
7284 | } | |
7285 | ||
7286 | /************************** EVPN BGP config management ************************/ | |
7287 | static void zevpn_cfg_cleanup(struct hash_bucket *bucket, void *ctxt) | |
7288 | { | |
7289 | zebra_evpn_t *zevpn = NULL; | |
7290 | ||
7291 | zevpn = (zebra_evpn_t *)bucket->data; | |
7292 | zevpn->advertise_gw_macip = 0; | |
7293 | zevpn->advertise_svi_macip = 0; | |
7294 | zevpn->advertise_subnet = 0; | |
7295 | ||
7296 | zebra_evpn_neigh_del_all(zevpn, 1, 0, | |
7297 | DEL_REMOTE_NEIGH | DEL_REMOTE_NEIGH_FROM_VTEP); | |
7298 | zebra_evpn_mac_del_all(zevpn, 1, 0, | |
7299 | DEL_REMOTE_MAC | DEL_REMOTE_MAC_FROM_VTEP); | |
7300 | zevpn_vtep_del_all(zevpn, 1); | |
7301 | } | |
7302 | ||
7303 | /* Cleanup EVPN configuration of a specific VRF */ | |
7304 | static void zebra_evpn_vrf_cfg_cleanup(struct zebra_vrf *zvrf) | |
7305 | { | |
7306 | zebra_l3vni_t *zl3vni = NULL; | |
7307 | ||
7308 | zvrf->advertise_all_vni = 0; | |
7309 | zvrf->advertise_gw_macip = 0; | |
7310 | zvrf->advertise_svi_macip = 0; | |
7311 | zvrf->vxlan_flood_ctrl = VXLAN_FLOOD_HEAD_END_REPL; | |
7312 | ||
7313 | hash_iterate(zvrf->evpn_table, zevpn_cfg_cleanup, NULL); | |
7314 | ||
7315 | if (zvrf->l3vni) | |
7316 | zl3vni = zl3vni_lookup(zvrf->l3vni); | |
7317 | if (zl3vni) { | |
7318 | /* delete and uninstall all rmacs */ | |
7319 | hash_iterate(zl3vni->rmac_table, zl3vni_del_rmac_hash_entry, | |
7320 | zl3vni); | |
7321 | /* delete and uninstall all next-hops */ | |
7322 | hash_iterate(zl3vni->nh_table, zl3vni_del_nh_hash_entry, | |
7323 | zl3vni); | |
7324 | } | |
7325 | } | |
7326 | ||
7327 | /* Cleanup BGP EVPN configuration upon client disconnect */ | |
7328 | static int zebra_evpn_bgp_cfg_clean_up(struct zserv *client) | |
7329 | { | |
7330 | struct vrf *vrf; | |
7331 | struct zebra_vrf *zvrf; | |
7332 | ||
7333 | RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { | |
7334 | zvrf = vrf->info; | |
7335 | if (zvrf) | |
7336 | zebra_evpn_vrf_cfg_cleanup(zvrf); | |
7337 | } | |
7338 | ||
7339 | return 0; | |
7340 | } | |
7341 | ||
7342 | static int zebra_evpn_pim_cfg_clean_up(struct zserv *client) | |
7343 | { | |
7344 | struct zebra_vrf *zvrf = zebra_vrf_get_evpn(); | |
7345 | ||
7346 | if (zvrf && CHECK_FLAG(zvrf->flags, ZEBRA_PIM_SEND_VXLAN_SG)) { | |
7347 | if (IS_ZEBRA_DEBUG_VXLAN) | |
7348 | zlog_debug("VxLAN SG updates to PIM, stop"); | |
7349 | UNSET_FLAG(zvrf->flags, ZEBRA_PIM_SEND_VXLAN_SG); | |
7350 | } | |
7351 | ||
7352 | return 0; | |
7353 | } | |
7354 | ||
7355 | static int zebra_evpn_cfg_clean_up(struct zserv *client) | |
7356 | { | |
7357 | if (client->proto == ZEBRA_ROUTE_BGP) | |
7358 | return zebra_evpn_bgp_cfg_clean_up(client); | |
7359 | ||
7360 | if (client->proto == ZEBRA_ROUTE_PIM) | |
7361 | return zebra_evpn_pim_cfg_clean_up(client); | |
7362 | ||
7363 | return 0; | |
7364 | } | |
7365 | ||
7366 | /* | |
7367 | * Handle results for vxlan dataplane operations. | |
7368 | */ | |
7369 | extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx *ctx) | |
7370 | { | |
7371 | /* TODO -- anything other than freeing the context? */ | |
7372 | dplane_ctx_fini(&ctx); | |
7373 | } | |
7374 | ||
7375 | /* Cleanup BGP EVPN configuration upon client disconnect */ | |
7376 | extern void zebra_evpn_init(void) | |
7377 | { | |
7378 | hook_register(zserv_client_close, zebra_evpn_cfg_clean_up); | |
7379 | } |