]>
Commit | Line | Data |
---|---|---|
24268cd0 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" | |
b2998086 | 26 | #include "interface.h" |
24268cd0 | 27 | #include "jhash.h" |
24268cd0 PR |
28 | #include "memory.h" |
29 | #include "prefix.h" | |
24268cd0 | 30 | #include "vlan.h" |
b2998086 | 31 | #include "json.h" |
bf902d4c | 32 | #include "printfrr.h" |
24268cd0 | 33 | |
b2998086 | 34 | #include "zebra/zserv.h" |
24268cd0 | 35 | #include "zebra/debug.h" |
b2998086 | 36 | #include "zebra/zebra_router.h" |
b2998086 | 37 | #include "zebra/zebra_errors.h" |
24268cd0 | 38 | #include "zebra/zebra_vrf.h" |
b2998086 | 39 | #include "zebra/zebra_evpn.h" |
24268cd0 | 40 | #include "zebra/zebra_evpn_mh.h" |
b2998086 PR |
41 | #include "zebra/zebra_evpn_mac.h" |
42 | #include "zebra/zebra_evpn_neigh.h" | |
24268cd0 | 43 | |
24268cd0 | 44 | DEFINE_MTYPE_STATIC(ZEBRA, MAC, "EVPN MAC"); |
24268cd0 PR |
45 | |
46 | /* | |
47 | * Return number of valid MACs in an EVPN's MAC hash table - all | |
48 | * remote MACs and non-internal (auto) local MACs count. | |
49 | */ | |
f6371c34 | 50 | uint32_t num_valid_macs(struct zebra_evpn *zevpn) |
24268cd0 PR |
51 | { |
52 | unsigned int i; | |
53 | uint32_t num_macs = 0; | |
54 | struct hash *hash; | |
55 | struct hash_bucket *hb; | |
3198b2b3 | 56 | struct zebra_mac *mac; |
24268cd0 PR |
57 | |
58 | hash = zevpn->mac_table; | |
59 | if (!hash) | |
60 | return num_macs; | |
61 | for (i = 0; i < hash->size; i++) { | |
62 | for (hb = hash->index[i]; hb; hb = hb->next) { | |
3198b2b3 | 63 | mac = (struct zebra_mac *)hb->data; |
24268cd0 PR |
64 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) |
65 | || CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) | |
66 | || !CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) | |
67 | num_macs++; | |
68 | } | |
69 | } | |
70 | ||
71 | return num_macs; | |
72 | } | |
73 | ||
f6371c34 | 74 | uint32_t num_dup_detected_macs(struct zebra_evpn *zevpn) |
24268cd0 PR |
75 | { |
76 | unsigned int i; | |
77 | uint32_t num_macs = 0; | |
78 | struct hash *hash; | |
79 | struct hash_bucket *hb; | |
3198b2b3 | 80 | struct zebra_mac *mac; |
24268cd0 PR |
81 | |
82 | hash = zevpn->mac_table; | |
83 | if (!hash) | |
84 | return num_macs; | |
85 | for (i = 0; i < hash->size; i++) { | |
86 | for (hb = hash->index[i]; hb; hb = hb->next) { | |
3198b2b3 | 87 | mac = (struct zebra_mac *)hb->data; |
24268cd0 PR |
88 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) |
89 | num_macs++; | |
90 | } | |
91 | } | |
92 | ||
93 | return num_macs; | |
94 | } | |
95 | ||
8b07f173 AK |
96 | /* Setup mac_list against the access port. This is done when a mac uses |
97 | * the ifp as destination for the first time | |
98 | */ | |
99 | static void zebra_evpn_mac_ifp_new(struct zebra_if *zif) | |
100 | { | |
101 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
102 | zlog_debug("MAC list created for ifp %s (%u)", zif->ifp->name, | |
103 | zif->ifp->ifindex); | |
104 | ||
105 | zif->mac_list = list_new(); | |
106 | listset_app_node_mem(zif->mac_list); | |
107 | } | |
108 | ||
8b07f173 | 109 | /* Unlink local mac from a destination access port */ |
3198b2b3 | 110 | static void zebra_evpn_mac_ifp_unlink(struct zebra_mac *zmac) |
8b07f173 AK |
111 | { |
112 | struct zebra_if *zif; | |
113 | struct interface *ifp = zmac->ifp; | |
114 | ||
115 | if (!ifp) | |
116 | return; | |
117 | ||
118 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
119 | zlog_debug("VNI %d MAC %pEA unlinked from ifp %s (%u)", | |
120 | zmac->zevpn->vni, | |
121 | &zmac->macaddr, | |
122 | ifp->name, ifp->ifindex); | |
123 | ||
124 | zif = ifp->info; | |
125 | list_delete_node(zif->mac_list, &zmac->ifp_listnode); | |
126 | zmac->ifp = NULL; | |
127 | } | |
128 | ||
51aa2693 AK |
129 | /* Free up the mac_list if any as a part of the interface del/cleanup */ |
130 | void zebra_evpn_mac_ifp_del(struct interface *ifp) | |
131 | { | |
132 | struct zebra_if *zif = ifp->info; | |
133 | struct listnode *node; | |
134 | struct zebra_mac *zmac; | |
135 | ||
136 | if (zif->mac_list) { | |
137 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
138 | zlog_debug("MAC list deleted for ifp %s (%u)", | |
139 | zif->ifp->name, zif->ifp->ifindex); | |
140 | ||
141 | for (ALL_LIST_ELEMENTS_RO(zif->mac_list, node, zmac)) { | |
142 | zebra_evpn_mac_ifp_unlink(zmac); | |
143 | } | |
144 | list_delete(&zif->mac_list); | |
145 | } | |
146 | } | |
147 | ||
8b07f173 AK |
148 | /* Link local mac to destination access port. This is done only if the |
149 | * local mac is associated with a zero ESI i.e. single attach or lacp-bypass | |
150 | * bridge port member | |
151 | */ | |
3198b2b3 DS |
152 | static void zebra_evpn_mac_ifp_link(struct zebra_mac *zmac, |
153 | struct interface *ifp) | |
8b07f173 AK |
154 | { |
155 | struct zebra_if *zif; | |
156 | ||
157 | if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) | |
158 | return; | |
159 | ||
160 | /* already linked to the destination */ | |
161 | if (zmac->ifp == ifp) | |
162 | return; | |
163 | ||
164 | /* unlink the mac from any old destination */ | |
165 | if (zmac->ifp) | |
166 | zebra_evpn_mac_ifp_unlink(zmac); | |
167 | ||
168 | if (!ifp) | |
169 | return; | |
170 | ||
171 | zif = ifp->info; | |
172 | /* the interface mac_list is created on first mac link attempt */ | |
173 | if (!zif->mac_list) | |
174 | zebra_evpn_mac_ifp_new(zif); | |
175 | ||
176 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
177 | zlog_debug("VNI %d MAC %pEA linked to ifp %s (%u)", | |
178 | zmac->zevpn->vni, | |
179 | &zmac->macaddr, | |
180 | ifp->name, ifp->ifindex); | |
181 | ||
182 | zmac->ifp = ifp; | |
183 | listnode_init(&zmac->ifp_listnode, zmac); | |
184 | listnode_add(zif->mac_list, &zmac->ifp_listnode); | |
185 | } | |
186 | ||
187 | /* If the mac is a local mac clear links to destination access port */ | |
3198b2b3 | 188 | void zebra_evpn_mac_clear_fwd_info(struct zebra_mac *zmac) |
8b07f173 AK |
189 | { |
190 | zebra_evpn_mac_ifp_unlink(zmac); | |
191 | memset(&zmac->fwd_info, 0, sizeof(zmac->fwd_info)); | |
192 | } | |
193 | ||
b2998086 PR |
194 | /* |
195 | * Install remote MAC into the forwarding plane. | |
196 | */ | |
3198b2b3 | 197 | int zebra_evpn_rem_mac_install(struct zebra_evpn *zevpn, struct zebra_mac *mac, |
b2998086 | 198 | bool was_static) |
24268cd0 | 199 | { |
b2998086 PR |
200 | const struct zebra_if *zif, *br_zif; |
201 | const struct zebra_l2info_vxlan *vxl; | |
202 | bool sticky; | |
203 | enum zebra_dplane_result res; | |
204 | const struct interface *br_ifp; | |
205 | vlanid_t vid; | |
206 | uint32_t nhg_id; | |
207 | struct in_addr vtep_ip; | |
24268cd0 | 208 | |
b2998086 PR |
209 | zif = zevpn->vxlan_if->info; |
210 | if (!zif) | |
211 | return -1; | |
212 | ||
213 | br_ifp = zif->brslave_info.br_if; | |
214 | if (br_ifp == NULL) | |
215 | return -1; | |
216 | ||
217 | vxl = &zif->l2info.vxl; | |
218 | ||
219 | sticky = !!CHECK_FLAG(mac->flags, | |
220 | (ZEBRA_MAC_STICKY | ZEBRA_MAC_REMOTE_DEF_GW)); | |
221 | ||
222 | /* If nexthop group for the FDB entry is inactive (not programmed in | |
223 | * the dataplane) the MAC entry cannot be installed | |
224 | */ | |
225 | if (mac->es) { | |
226 | if (!(mac->es->flags & ZEBRA_EVPNES_NHG_ACTIVE)) | |
227 | return -1; | |
228 | nhg_id = mac->es->nhg_id; | |
229 | vtep_ip.s_addr = 0; | |
230 | } else { | |
231 | nhg_id = 0; | |
232 | vtep_ip = mac->fwd_info.r_vtep_ip; | |
24268cd0 PR |
233 | } |
234 | ||
b2998086 PR |
235 | br_zif = (const struct zebra_if *)(br_ifp->info); |
236 | ||
237 | if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif)) | |
238 | vid = vxl->access_vlan; | |
239 | else | |
240 | vid = 0; | |
241 | ||
242 | res = dplane_rem_mac_add(zevpn->vxlan_if, br_ifp, vid, &mac->macaddr, | |
243 | vtep_ip, sticky, nhg_id, was_static); | |
244 | if (res != ZEBRA_DPLANE_REQUEST_FAILURE) | |
245 | return 0; | |
246 | else | |
247 | return -1; | |
24268cd0 PR |
248 | } |
249 | ||
b2998086 PR |
250 | /* |
251 | * Uninstall remote MAC from the forwarding plane. | |
252 | */ | |
3198b2b3 DS |
253 | int zebra_evpn_rem_mac_uninstall(struct zebra_evpn *zevpn, |
254 | struct zebra_mac *mac, bool force) | |
24268cd0 | 255 | { |
b2998086 PR |
256 | const struct zebra_if *zif, *br_zif; |
257 | const struct zebra_l2info_vxlan *vxl; | |
258 | struct in_addr vtep_ip; | |
259 | const struct interface *ifp, *br_ifp; | |
260 | vlanid_t vid; | |
261 | enum zebra_dplane_result res; | |
24268cd0 | 262 | |
f3722826 AK |
263 | /* If the MAC was not installed there is no need to uninstall it */ |
264 | if (!force && mac->es && !(mac->es->flags & ZEBRA_EVPNES_NHG_ACTIVE)) | |
265 | return -1; | |
266 | ||
b2998086 PR |
267 | if (!zevpn->vxlan_if) { |
268 | if (IS_ZEBRA_DEBUG_VXLAN) | |
269 | zlog_debug( | |
270 | "VNI %u hash %p couldn't be uninstalled - no intf", | |
271 | zevpn->vni, zevpn); | |
272 | return -1; | |
273 | } | |
24268cd0 | 274 | |
b2998086 PR |
275 | zif = zevpn->vxlan_if->info; |
276 | if (!zif) | |
277 | return -1; | |
24268cd0 | 278 | |
b2998086 PR |
279 | br_ifp = zif->brslave_info.br_if; |
280 | if (br_ifp == NULL) | |
281 | return -1; | |
24268cd0 | 282 | |
b2998086 | 283 | vxl = &zif->l2info.vxl; |
24268cd0 | 284 | |
b2998086 | 285 | br_zif = (const struct zebra_if *)br_ifp->info; |
24268cd0 | 286 | |
b2998086 PR |
287 | if (IS_ZEBRA_IF_BRIDGE_VLAN_AWARE(br_zif)) |
288 | vid = vxl->access_vlan; | |
289 | else | |
290 | vid = 0; | |
24268cd0 | 291 | |
b2998086 PR |
292 | ifp = zevpn->vxlan_if; |
293 | vtep_ip = mac->fwd_info.r_vtep_ip; | |
294 | ||
295 | res = dplane_rem_mac_del(ifp, br_ifp, vid, &mac->macaddr, vtep_ip); | |
296 | if (res != ZEBRA_DPLANE_REQUEST_FAILURE) | |
297 | return 0; | |
298 | else | |
299 | return -1; | |
24268cd0 PR |
300 | } |
301 | ||
b2998086 PR |
302 | /* |
303 | * Decrement neighbor refcount of MAC; uninstall and free it if | |
304 | * appropriate. | |
24268cd0 | 305 | */ |
3198b2b3 | 306 | void zebra_evpn_deref_ip2mac(struct zebra_evpn *zevpn, struct zebra_mac *mac) |
24268cd0 | 307 | { |
b2998086 PR |
308 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) |
309 | return; | |
24268cd0 | 310 | |
b2998086 PR |
311 | /* If all remote neighbors referencing a remote MAC go away, |
312 | * we need to uninstall the MAC. | |
24268cd0 | 313 | */ |
b2998086 PR |
314 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) |
315 | && remote_neigh_count(mac) == 0) { | |
f3722826 | 316 | zebra_evpn_rem_mac_uninstall(zevpn, mac, false /*force*/); |
b2998086 PR |
317 | zebra_evpn_es_mac_deref_entry(mac); |
318 | UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE); | |
319 | } | |
320 | ||
243b74ed AK |
321 | /* If no references, delete the MAC. */ |
322 | if (!zebra_evpn_mac_in_use(mac)) | |
b2998086 PR |
323 | zebra_evpn_mac_del(zevpn, mac); |
324 | } | |
325 | ||
3198b2b3 | 326 | static void zebra_evpn_mac_get_access_info(struct zebra_mac *mac, |
e3f05a8a | 327 | struct interface **p_ifp, |
d9d3455e | 328 | vlanid_t *vid) |
b2998086 PR |
329 | { |
330 | /* if the mac is associated with an ES we must get the access | |
331 | * info from the ES | |
24268cd0 | 332 | */ |
b2998086 PR |
333 | if (mac->es) { |
334 | struct zebra_if *zif; | |
335 | ||
336 | /* get the access port from the es */ | |
e3f05a8a | 337 | *p_ifp = mac->es->zif ? mac->es->zif->ifp : NULL; |
b2998086 PR |
338 | /* get the vlan from the EVPN */ |
339 | if (mac->zevpn->vxlan_if) { | |
340 | zif = mac->zevpn->vxlan_if->info; | |
341 | *vid = zif->l2info.vxl.access_vlan; | |
342 | } else { | |
343 | *vid = 0; | |
344 | } | |
345 | } else { | |
346 | struct zebra_ns *zns; | |
347 | ||
348 | *vid = mac->fwd_info.local.vid; | |
47c58929 | 349 | zns = zebra_ns_lookup(mac->fwd_info.local.ns_id); |
e3f05a8a | 350 | *p_ifp = if_lookup_by_index_per_ns(zns, |
351 | mac->fwd_info.local.ifindex); | |
b2998086 PR |
352 | } |
353 | } | |
354 | ||
b16e8004 | 355 | #define MAC_BUF_SIZE 256 |
3198b2b3 | 356 | static char *zebra_evpn_zebra_mac_flag_dump(struct zebra_mac *mac, char *buf, |
b16e8004 DS |
357 | size_t len) |
358 | { | |
359 | if (mac->flags == 0) { | |
360 | snprintfrr(buf, len, "None "); | |
361 | return buf; | |
362 | } | |
363 | ||
364 | snprintfrr( | |
365 | buf, len, "%s%s%s%s%s%s%s%s%s%s%s%s", | |
366 | CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) ? "LOC " : "", | |
367 | CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) ? "REM " : "", | |
368 | CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO) ? "AUTO " : "", | |
369 | CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) ? "STICKY " : "", | |
370 | CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_RMAC) ? "REM Router " | |
371 | : "", | |
372 | CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW) ? "Default GW " : "", | |
373 | CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW) ? "REM DEF GW " | |
374 | : "", | |
375 | CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE) ? "DUP " : "", | |
376 | CHECK_FLAG(mac->flags, ZEBRA_MAC_FPM_SENT) ? "FPM " : "", | |
0ef63eb5 | 377 | CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE) |
378 | ? "PEER Active " | |
379 | : "", | |
b16e8004 DS |
380 | CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY) ? "PROXY " : "", |
381 | CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE) | |
382 | ? "LOC Inactive " | |
383 | : ""); | |
384 | return buf; | |
385 | } | |
386 | ||
cc9f21da | 387 | static void zebra_evpn_dad_mac_auto_recovery_exp(struct thread *t) |
b2998086 PR |
388 | { |
389 | struct zebra_vrf *zvrf = NULL; | |
3198b2b3 | 390 | struct zebra_mac *mac = NULL; |
f6371c34 | 391 | struct zebra_evpn *zevpn = NULL; |
b2998086 | 392 | struct listnode *node = NULL; |
72de4110 | 393 | struct zebra_neigh *nbr = NULL; |
b2998086 PR |
394 | |
395 | mac = THREAD_ARG(t); | |
396 | ||
397 | /* since this is asynchronous we need sanity checks*/ | |
398 | zvrf = vrf_info_lookup(mac->zevpn->vrf_id); | |
399 | if (!zvrf) | |
cc9f21da | 400 | return; |
b2998086 | 401 | |
8b5fdf2e | 402 | zevpn = zebra_evpn_lookup(mac->zevpn->vni); |
b2998086 | 403 | if (!zevpn) |
cc9f21da | 404 | return; |
b2998086 PR |
405 | |
406 | mac = zebra_evpn_mac_lookup(zevpn, &mac->macaddr); | |
407 | if (!mac) | |
cc9f21da | 408 | return; |
b2998086 | 409 | |
b16e8004 DS |
410 | if (IS_ZEBRA_DEBUG_VXLAN) { |
411 | char mac_buf[MAC_BUF_SIZE]; | |
412 | ||
b2998086 | 413 | zlog_debug( |
ef7b8be4 DL |
414 | "%s: duplicate addr mac %pEA flags %slearn count %u host count %u auto recovery expired", |
415 | __func__, &mac->macaddr, | |
b16e8004 DS |
416 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
417 | sizeof(mac_buf)), | |
418 | mac->dad_count, listcount(mac->neigh_list)); | |
419 | } | |
b2998086 PR |
420 | |
421 | /* Remove all IPs as duplicate associcated with this MAC */ | |
422 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) { | |
423 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { | |
424 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) | |
425 | ZEBRA_NEIGH_SET_INACTIVE(nbr); | |
426 | else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) | |
427 | zebra_evpn_rem_neigh_install( | |
428 | zevpn, nbr, false /*was_static*/); | |
429 | } | |
24268cd0 | 430 | |
24268cd0 PR |
431 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); |
432 | nbr->dad_count = 0; | |
433 | nbr->detect_start_time.tv_sec = 0; | |
b2998086 PR |
434 | nbr->dad_dup_detect_time = 0; |
435 | } | |
436 | ||
437 | UNSET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE); | |
438 | mac->dad_count = 0; | |
439 | mac->detect_start_time.tv_sec = 0; | |
440 | mac->detect_start_time.tv_usec = 0; | |
441 | mac->dad_dup_detect_time = 0; | |
442 | mac->dad_mac_auto_recovery_timer = NULL; | |
443 | ||
444 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
445 | /* Inform to BGP */ | |
446 | if (zebra_evpn_mac_send_add_to_client(zevpn->vni, &mac->macaddr, | |
447 | mac->flags, mac->loc_seq, | |
448 | mac->es)) | |
cc9f21da | 449 | return; |
b2998086 PR |
450 | |
451 | /* Process all neighbors associated with this MAC. */ | |
452 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0, | |
453 | 0 /*es_change*/); | |
454 | ||
455 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
456 | zebra_evpn_process_neigh_on_remote_mac_add(zevpn, mac); | |
457 | ||
458 | /* Install the entry. */ | |
459 | zebra_evpn_rem_mac_install(zevpn, mac, false /* was_static */); | |
24268cd0 | 460 | } |
24268cd0 PR |
461 | } |
462 | ||
d9d3455e | 463 | static void zebra_evpn_dup_addr_detect_for_mac(struct zebra_vrf *zvrf, |
3198b2b3 | 464 | struct zebra_mac *mac, |
d9d3455e PR |
465 | struct in_addr vtep_ip, |
466 | bool do_dad, bool *is_dup_detect, | |
467 | bool is_local) | |
24268cd0 | 468 | { |
72de4110 | 469 | struct zebra_neigh *nbr; |
24268cd0 PR |
470 | struct listnode *node = NULL; |
471 | struct timeval elapsed = {0, 0}; | |
24268cd0 PR |
472 | bool reset_params = false; |
473 | ||
b2ee2b71 | 474 | if (!(zebra_evpn_do_dup_addr_detect(zvrf) && do_dad)) |
24268cd0 PR |
475 | return; |
476 | ||
477 | /* MAC is detected as duplicate, | |
478 | * Local MAC event -> hold on advertising to BGP. | |
479 | * Remote MAC event -> hold on installing it. | |
480 | */ | |
481 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) { | |
b16e8004 DS |
482 | if (IS_ZEBRA_DEBUG_VXLAN) { |
483 | char mac_buf[MAC_BUF_SIZE]; | |
484 | ||
24268cd0 | 485 | zlog_debug( |
ef7b8be4 DL |
486 | "%s: duplicate addr MAC %pEA flags %sskip update to client, learn count %u recover time %u", |
487 | __func__, &mac->macaddr, | |
b16e8004 DS |
488 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
489 | sizeof(mac_buf)), | |
490 | mac->dad_count, zvrf->dad_freeze_time); | |
491 | } | |
24268cd0 PR |
492 | /* For duplicate MAC do not update |
493 | * client but update neigh due to | |
494 | * this MAC update. | |
495 | */ | |
496 | if (zvrf->dad_freeze) | |
497 | *is_dup_detect = true; | |
498 | ||
499 | return; | |
500 | } | |
501 | ||
502 | /* Check if detection time (M-secs) expired. | |
503 | * Reset learn count and detection start time. | |
504 | */ | |
505 | monotime_since(&mac->detect_start_time, &elapsed); | |
506 | reset_params = (elapsed.tv_sec > zvrf->dad_time); | |
507 | if (is_local && !reset_params) { | |
508 | /* RFC-7432: A PE/VTEP that detects a MAC mobility | |
509 | * event via LOCAL learning starts an M-second timer. | |
510 | * | |
511 | * NOTE: This is the START of the probe with count is | |
512 | * 0 during LOCAL learn event. | |
513 | * (mac->dad_count == 0 || elapsed.tv_sec >= zvrf->dad_time) | |
514 | */ | |
515 | reset_params = !mac->dad_count; | |
516 | } | |
517 | ||
518 | if (reset_params) { | |
b16e8004 DS |
519 | if (IS_ZEBRA_DEBUG_VXLAN) { |
520 | char mac_buf[MAC_BUF_SIZE]; | |
521 | ||
24268cd0 | 522 | zlog_debug( |
ef7b8be4 DL |
523 | "%s: duplicate addr MAC %pEA flags %sdetection time passed, reset learn count %u", |
524 | __func__, &mac->macaddr, | |
b16e8004 DS |
525 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
526 | sizeof(mac_buf)), | |
527 | mac->dad_count); | |
528 | } | |
24268cd0 PR |
529 | |
530 | mac->dad_count = 0; | |
531 | /* Start dup. addr detection (DAD) start time, | |
532 | * ONLY during LOCAL learn. | |
533 | */ | |
534 | if (is_local) | |
535 | monotime(&mac->detect_start_time); | |
536 | ||
537 | } else if (!is_local) { | |
538 | /* For REMOTE MAC, increment detection count | |
539 | * ONLY while in probe window, once window passed, | |
540 | * next local learn event should trigger DAD. | |
541 | */ | |
542 | mac->dad_count++; | |
543 | } | |
544 | ||
545 | /* For LOCAL MAC learn event, once count is reset above via either | |
546 | * initial/start detection time or passed the probe time, the count | |
547 | * needs to be incremented. | |
548 | */ | |
549 | if (is_local) | |
550 | mac->dad_count++; | |
551 | ||
552 | if (mac->dad_count >= zvrf->dad_max_moves) { | |
553 | flog_warn(EC_ZEBRA_DUP_MAC_DETECTED, | |
ef7b8be4 DL |
554 | "VNI %u: MAC %pEA detected as duplicate during %s VTEP %pI4", |
555 | mac->zevpn->vni, &mac->macaddr, | |
24268cd0 | 556 | is_local ? "local update, last" : |
9bcef951 | 557 | "remote update, from", &vtep_ip); |
24268cd0 PR |
558 | |
559 | SET_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE); | |
560 | ||
561 | /* Capture Duplicate detection time */ | |
562 | mac->dad_dup_detect_time = monotime(NULL); | |
563 | ||
564 | /* Mark all IPs/Neighs as duplicate | |
565 | * associcated with this MAC | |
566 | */ | |
567 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, nbr)) { | |
568 | ||
569 | /* Ony Mark IPs which are Local */ | |
570 | if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) | |
571 | continue; | |
572 | ||
573 | SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
574 | ||
575 | nbr->dad_dup_detect_time = monotime(NULL); | |
576 | ||
577 | flog_warn(EC_ZEBRA_DUP_IP_INHERIT_DETECTED, | |
ef7b8be4 DL |
578 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s update, inherit duplicate from MAC", |
579 | mac->zevpn->vni, &mac->macaddr, &nbr->ip, | |
24268cd0 PR |
580 | is_local ? "local" : "remote"); |
581 | } | |
582 | ||
583 | /* Start auto recovery timer for this MAC */ | |
584 | THREAD_OFF(mac->dad_mac_auto_recovery_timer); | |
585 | if (zvrf->dad_freeze && zvrf->dad_freeze_time) { | |
b16e8004 DS |
586 | if (IS_ZEBRA_DEBUG_VXLAN) { |
587 | char mac_buf[MAC_BUF_SIZE]; | |
588 | ||
24268cd0 | 589 | zlog_debug( |
ef7b8be4 DL |
590 | "%s: duplicate addr MAC %pEA flags %sauto recovery time %u start", |
591 | __func__, &mac->macaddr, | |
b16e8004 DS |
592 | zebra_evpn_zebra_mac_flag_dump( |
593 | mac, mac_buf, sizeof(mac_buf)), | |
594 | zvrf->dad_freeze_time); | |
595 | } | |
24268cd0 PR |
596 | |
597 | thread_add_timer(zrouter.master, | |
b2998086 | 598 | zebra_evpn_dad_mac_auto_recovery_exp, |
24268cd0 PR |
599 | mac, zvrf->dad_freeze_time, |
600 | &mac->dad_mac_auto_recovery_timer); | |
601 | } | |
602 | ||
603 | /* In case of local update, do not inform to client (BGPd), | |
604 | * upd_neigh for neigh sequence change. | |
605 | */ | |
606 | if (zvrf->dad_freeze) | |
607 | *is_dup_detect = true; | |
608 | } | |
609 | } | |
610 | ||
b2998086 PR |
611 | /* |
612 | * Print a specific MAC entry. | |
613 | */ | |
3198b2b3 | 614 | void zebra_evpn_print_mac(struct zebra_mac *mac, void *ctxt, json_object *json) |
24268cd0 | 615 | { |
b2998086 | 616 | struct vty *vty; |
72de4110 | 617 | struct zebra_neigh *n = NULL; |
b2998086 PR |
618 | struct listnode *node = NULL; |
619 | char buf1[ETHER_ADDR_STRLEN]; | |
620 | char buf2[INET6_ADDRSTRLEN]; | |
621 | struct zebra_vrf *zvrf; | |
622 | struct timeval detect_start_time = {0, 0}; | |
623 | char timebuf[MONOTIME_STRLEN]; | |
624 | char thread_buf[THREAD_TIMER_STRLEN]; | |
f1dbb1c7 DS |
625 | time_t uptime; |
626 | char up_str[MONOTIME_STRLEN]; | |
24268cd0 | 627 | |
b2998086 | 628 | zvrf = zebra_vrf_get_evpn(); |
b2998086 PR |
629 | vty = (struct vty *)ctxt; |
630 | prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1)); | |
24268cd0 | 631 | |
f1dbb1c7 DS |
632 | uptime = monotime(NULL); |
633 | uptime -= mac->uptime; | |
634 | ||
635 | frrtime_to_interval(uptime, up_str, sizeof(up_str)); | |
636 | ||
b2998086 PR |
637 | if (json) { |
638 | json_object *json_mac = json_object_new_object(); | |
24268cd0 | 639 | |
b2998086 PR |
640 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { |
641 | struct interface *ifp; | |
642 | vlanid_t vid; | |
24268cd0 | 643 | |
b2998086 PR |
644 | zebra_evpn_mac_get_access_info(mac, &ifp, &vid); |
645 | json_object_string_add(json_mac, "type", "local"); | |
646 | if (ifp) { | |
647 | json_object_string_add(json_mac, "intf", | |
648 | ifp->name); | |
649 | json_object_int_add(json_mac, "ifindex", | |
650 | ifp->ifindex); | |
651 | } | |
652 | if (vid) | |
653 | json_object_int_add(json_mac, "vlan", vid); | |
654 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
655 | json_object_string_add(json_mac, "type", "remote"); | |
08edf9c6 DA |
656 | json_object_string_addf(json_mac, "remoteVtep", "%pI4", |
657 | &mac->fwd_info.r_vtep_ip); | |
b2998086 PR |
658 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) |
659 | json_object_string_add(json_mac, "type", "auto"); | |
24268cd0 | 660 | |
b2998086 PR |
661 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) |
662 | json_object_boolean_true_add(json_mac, "stickyMac"); | |
24268cd0 | 663 | |
243b74ed AK |
664 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI)) |
665 | json_object_boolean_true_add(json_mac, "sviMac"); | |
666 | ||
b2998086 PR |
667 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) |
668 | json_object_boolean_true_add(json_mac, | |
669 | "defaultGateway"); | |
24268cd0 | 670 | |
b2998086 PR |
671 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW)) |
672 | json_object_boolean_true_add(json_mac, | |
673 | "remoteGatewayMac"); | |
24268cd0 | 674 | |
f1dbb1c7 | 675 | json_object_string_add(json_mac, "uptime", up_str); |
b2998086 PR |
676 | json_object_int_add(json_mac, "localSequence", mac->loc_seq); |
677 | json_object_int_add(json_mac, "remoteSequence", mac->rem_seq); | |
24268cd0 | 678 | |
b2998086 PR |
679 | json_object_int_add(json_mac, "detectionCount", mac->dad_count); |
680 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) | |
681 | json_object_boolean_true_add(json_mac, "isDuplicate"); | |
682 | else | |
683 | json_object_boolean_false_add(json_mac, "isDuplicate"); | |
24268cd0 | 684 | |
b2998086 PR |
685 | json_object_int_add(json_mac, "syncNeighCount", |
686 | mac->sync_neigh_cnt); | |
687 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE)) | |
688 | json_object_boolean_true_add(json_mac, "localInactive"); | |
689 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY)) | |
690 | json_object_boolean_true_add(json_mac, "peerProxy"); | |
691 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) | |
692 | json_object_boolean_true_add(json_mac, "peerActive"); | |
693 | if (mac->hold_timer) | |
694 | json_object_string_add( | |
695 | json_mac, "peerActiveHold", | |
696 | thread_timer_to_hhmmss(thread_buf, | |
697 | sizeof(thread_buf), | |
698 | mac->hold_timer)); | |
699 | if (mac->es) | |
700 | json_object_string_add(json_mac, "esi", | |
701 | mac->es->esi_str); | |
702 | /* print all the associated neigh */ | |
703 | if (!listcount(mac->neigh_list)) | |
704 | json_object_string_add(json_mac, "neighbors", "none"); | |
705 | else { | |
706 | json_object *json_active_nbrs = json_object_new_array(); | |
707 | json_object *json_inactive_nbrs = | |
708 | json_object_new_array(); | |
709 | json_object *json_nbrs = json_object_new_object(); | |
24268cd0 | 710 | |
b2998086 PR |
711 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, n)) { |
712 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) | |
713 | json_object_array_add( | |
714 | json_active_nbrs, | |
715 | json_object_new_string( | |
716 | ipaddr2str( | |
717 | &n->ip, buf2, | |
718 | sizeof(buf2)))); | |
719 | else | |
720 | json_object_array_add( | |
721 | json_inactive_nbrs, | |
722 | json_object_new_string( | |
723 | ipaddr2str( | |
724 | &n->ip, buf2, | |
725 | sizeof(buf2)))); | |
726 | } | |
24268cd0 | 727 | |
b2998086 PR |
728 | json_object_object_add(json_nbrs, "active", |
729 | json_active_nbrs); | |
730 | json_object_object_add(json_nbrs, "inactive", | |
731 | json_inactive_nbrs); | |
732 | json_object_object_add(json_mac, "neighbors", | |
733 | json_nbrs); | |
24268cd0 | 734 | } |
24268cd0 | 735 | |
b2998086 PR |
736 | json_object_object_add(json, buf1, json_mac); |
737 | } else { | |
738 | vty_out(vty, "MAC: %s\n", buf1); | |
24268cd0 | 739 | |
b2998086 PR |
740 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { |
741 | struct interface *ifp; | |
742 | vlanid_t vid; | |
24268cd0 | 743 | |
b2998086 | 744 | zebra_evpn_mac_get_access_info(mac, &ifp, &vid); |
24268cd0 | 745 | |
b2998086 PR |
746 | if (mac->es) |
747 | vty_out(vty, " ESI: %s\n", mac->es->esi_str); | |
24268cd0 | 748 | |
b2998086 PR |
749 | if (ifp) |
750 | vty_out(vty, " Intf: %s(%u)", ifp->name, | |
751 | ifp->ifindex); | |
752 | else | |
753 | vty_out(vty, " Intf: -"); | |
754 | vty_out(vty, " VLAN: %u", vid); | |
755 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
756 | if (mac->es) | |
757 | vty_out(vty, " Remote ES: %s", | |
758 | mac->es->esi_str); | |
759 | else | |
9bcef951 MS |
760 | vty_out(vty, " Remote VTEP: %pI4", |
761 | &mac->fwd_info.r_vtep_ip); | |
b2998086 PR |
762 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) { |
763 | vty_out(vty, " Auto Mac "); | |
764 | } | |
24268cd0 | 765 | |
b2998086 PR |
766 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) |
767 | vty_out(vty, " Sticky Mac "); | |
24268cd0 | 768 | |
243b74ed AK |
769 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI)) |
770 | vty_out(vty, " SVI-Mac "); | |
771 | ||
b2998086 PR |
772 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) |
773 | vty_out(vty, " Default-gateway Mac "); | |
774 | ||
775 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW)) | |
776 | vty_out(vty, " Remote-gateway Mac "); | |
777 | ||
778 | vty_out(vty, "\n"); | |
779 | vty_out(vty, " Sync-info: neigh#: %u", mac->sync_neigh_cnt); | |
780 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE)) | |
24268cd0 | 781 | vty_out(vty, " local-inactive"); |
b2998086 | 782 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY)) |
24268cd0 | 783 | vty_out(vty, " peer-proxy"); |
b2998086 | 784 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) |
24268cd0 | 785 | vty_out(vty, " peer-active"); |
b2998086 | 786 | if (mac->hold_timer) |
24268cd0 | 787 | vty_out(vty, " (ht: %s)", |
b2998086 PR |
788 | thread_timer_to_hhmmss(thread_buf, |
789 | sizeof(thread_buf), | |
790 | mac->hold_timer)); | |
791 | vty_out(vty, "\n"); | |
f1dbb1c7 | 792 | vty_out(vty, " Local Seq: %u Remote Seq: %u\n", mac->loc_seq, |
b2998086 | 793 | mac->rem_seq); |
f1dbb1c7 | 794 | vty_out(vty, " Uptime: %s\n", up_str); |
24268cd0 | 795 | |
b2998086 | 796 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) { |
24268cd0 | 797 | vty_out(vty, " Duplicate, detected at %s", |
b2998086 | 798 | time_to_string(mac->dad_dup_detect_time, |
24268cd0 | 799 | timebuf)); |
b2998086 PR |
800 | } else if (mac->dad_count) { |
801 | monotime_since(&mac->detect_start_time, | |
24268cd0 PR |
802 | &detect_start_time); |
803 | if (detect_start_time.tv_sec <= zvrf->dad_time) { | |
b2998086 | 804 | time_to_string(mac->detect_start_time.tv_sec, |
24268cd0 PR |
805 | timebuf); |
806 | vty_out(vty, | |
807 | " Duplicate detection started at %s, detection count %u\n", | |
b2998086 | 808 | timebuf, mac->dad_count); |
24268cd0 PR |
809 | } |
810 | } | |
24268cd0 | 811 | |
b2998086 PR |
812 | /* print all the associated neigh */ |
813 | vty_out(vty, " Neighbors:\n"); | |
814 | if (!listcount(mac->neigh_list)) | |
815 | vty_out(vty, " No Neighbors\n"); | |
816 | else { | |
817 | for (ALL_LIST_ELEMENTS_RO(mac->neigh_list, node, n)) { | |
818 | vty_out(vty, " %s %s\n", | |
819 | ipaddr2str(&n->ip, buf2, sizeof(buf2)), | |
820 | (IS_ZEBRA_NEIGH_ACTIVE(n) | |
821 | ? "Active" | |
822 | : "Inactive")); | |
823 | } | |
824 | } | |
24268cd0 | 825 | |
b2998086 | 826 | vty_out(vty, "\n"); |
24268cd0 PR |
827 | } |
828 | } | |
829 | ||
3198b2b3 | 830 | static char *zebra_evpn_print_mac_flags(struct zebra_mac *mac, char *flags_buf, |
700cae76 | 831 | size_t flags_buf_sz) |
24268cd0 | 832 | { |
b2998086 | 833 | snprintf(flags_buf, flags_buf_sz, "%s%s%s%s", |
00a7710c AK |
834 | mac->sync_neigh_cnt ? "N" : "", |
835 | (mac->flags & ZEBRA_MAC_ES_PEER_ACTIVE) ? "P" : "", | |
836 | (mac->flags & ZEBRA_MAC_ES_PEER_PROXY) ? "X" : "", | |
837 | (mac->flags & ZEBRA_MAC_LOCAL_INACTIVE) ? "I" : ""); | |
24268cd0 PR |
838 | |
839 | return flags_buf; | |
840 | } | |
841 | ||
842 | /* | |
b2998086 | 843 | * Print MAC hash entry - called for display of all MACs. |
24268cd0 | 844 | */ |
b2998086 | 845 | void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt) |
24268cd0 PR |
846 | { |
847 | struct vty *vty; | |
b2998086 | 848 | json_object *json_mac_hdr = NULL, *json_mac = NULL; |
3198b2b3 | 849 | struct zebra_mac *mac; |
24268cd0 | 850 | char buf1[ETHER_ADDR_STRLEN]; |
9bcef951 | 851 | char addr_buf[PREFIX_STRLEN]; |
b2998086 | 852 | struct mac_walk_ctx *wctx = ctxt; |
24268cd0 PR |
853 | char flags_buf[6]; |
854 | ||
855 | vty = wctx->vty; | |
b2998086 | 856 | json_mac_hdr = wctx->json; |
3198b2b3 | 857 | mac = (struct zebra_mac *)bucket->data; |
b2998086 PR |
858 | |
859 | prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1)); | |
860 | ||
861 | if (json_mac_hdr) | |
862 | json_mac = json_object_new_object(); | |
24268cd0 | 863 | |
b2998086 PR |
864 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { |
865 | struct interface *ifp; | |
866 | vlanid_t vid; | |
24268cd0 | 867 | |
b2998086 | 868 | if (wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP) |
24268cd0 PR |
869 | return; |
870 | ||
b2998086 PR |
871 | zebra_evpn_mac_get_access_info(mac, &ifp, &vid); |
872 | if (json_mac_hdr == NULL) { | |
873 | vty_out(vty, "%-17s %-6s %-5s %-30s", buf1, "local", | |
874 | zebra_evpn_print_mac_flags(mac, flags_buf, | |
875 | sizeof(flags_buf)), | |
876 | ifp ? ifp->name : "-"); | |
877 | } else { | |
878 | json_object_string_add(json_mac, "type", "local"); | |
879 | if (ifp) | |
880 | json_object_string_add(json_mac, "intf", | |
881 | ifp->name); | |
882 | } | |
883 | if (vid) { | |
884 | if (json_mac_hdr == NULL) | |
885 | vty_out(vty, " %-5u", vid); | |
886 | else | |
887 | json_object_int_add(json_mac, "vlan", vid); | |
888 | } else /* No vid? fill out the space */ | |
889 | if (json_mac_hdr == NULL) | |
890 | vty_out(vty, " %-5s", ""); | |
891 | if (json_mac_hdr == NULL) { | |
892 | vty_out(vty, " %u/%u", mac->loc_seq, mac->rem_seq); | |
893 | vty_out(vty, "\n"); | |
24268cd0 | 894 | } else { |
b2998086 PR |
895 | json_object_int_add(json_mac, "localSequence", |
896 | mac->loc_seq); | |
897 | json_object_int_add(json_mac, "remoteSequence", | |
898 | mac->rem_seq); | |
899 | json_object_int_add(json_mac, "detectionCount", | |
900 | mac->dad_count); | |
901 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) | |
902 | json_object_boolean_true_add(json_mac, | |
24268cd0 PR |
903 | "isDuplicate"); |
904 | else | |
b2998086 | 905 | json_object_boolean_false_add(json_mac, |
24268cd0 | 906 | "isDuplicate"); |
b2998086 | 907 | json_object_object_add(json_mac_hdr, buf1, json_mac); |
24268cd0 | 908 | } |
b2998086 | 909 | |
24268cd0 | 910 | wctx->count++; |
b2998086 PR |
911 | |
912 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
913 | ||
914 | if ((wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP) | |
915 | && !IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip, | |
916 | &wctx->r_vtep_ip)) | |
24268cd0 PR |
917 | return; |
918 | ||
b2998086 PR |
919 | if (json_mac_hdr == NULL) { |
920 | if ((wctx->flags & SHOW_REMOTE_MAC_FROM_VTEP) | |
921 | && (wctx->count == 0)) { | |
922 | vty_out(vty, "\nVNI %u\n\n", wctx->zevpn->vni); | |
923 | vty_out(vty, "%-17s %-6s %-5s%-30s %-5s %s\n", | |
924 | "MAC", "Type", "Flags", | |
925 | "Intf/Remote ES/VTEP", "VLAN", | |
926 | "Seq #'s"); | |
24268cd0 | 927 | } |
9bcef951 MS |
928 | if (mac->es == NULL) |
929 | inet_ntop(AF_INET, &mac->fwd_info.r_vtep_ip, | |
930 | addr_buf, sizeof(addr_buf)); | |
931 | ||
b2998086 PR |
932 | vty_out(vty, "%-17s %-6s %-5s %-30s %-5s %u/%u\n", buf1, |
933 | "remote", | |
934 | zebra_evpn_print_mac_flags(mac, flags_buf, | |
9bcef951 MS |
935 | sizeof(flags_buf)), |
936 | mac->es ? mac->es->esi_str : addr_buf, | |
b2998086 PR |
937 | "", mac->loc_seq, mac->rem_seq); |
938 | } else { | |
939 | json_object_string_add(json_mac, "type", "remote"); | |
08edf9c6 DA |
940 | json_object_string_addf(json_mac, "remoteVtep", "%pI4", |
941 | &mac->fwd_info.r_vtep_ip); | |
b2998086 PR |
942 | json_object_object_add(json_mac_hdr, buf1, json_mac); |
943 | json_object_int_add(json_mac, "localSequence", | |
944 | mac->loc_seq); | |
945 | json_object_int_add(json_mac, "remoteSequence", | |
946 | mac->rem_seq); | |
947 | json_object_int_add(json_mac, "detectionCount", | |
948 | mac->dad_count); | |
949 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) | |
950 | json_object_boolean_true_add(json_mac, | |
951 | "isDuplicate"); | |
952 | else | |
953 | json_object_boolean_false_add(json_mac, | |
954 | "isDuplicate"); | |
955 | } | |
24268cd0 | 956 | |
b2998086 PR |
957 | wctx->count++; |
958 | } | |
24268cd0 PR |
959 | } |
960 | ||
961 | /* | |
b2998086 | 962 | * Print MAC hash entry in detail - called for display of all MACs. |
24268cd0 | 963 | */ |
b2998086 | 964 | void zebra_evpn_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt) |
24268cd0 | 965 | { |
b2998086 PR |
966 | struct vty *vty; |
967 | json_object *json_mac_hdr = NULL; | |
3198b2b3 | 968 | struct zebra_mac *mac; |
b2998086 PR |
969 | struct mac_walk_ctx *wctx = ctxt; |
970 | char buf1[ETHER_ADDR_STRLEN]; | |
24268cd0 | 971 | |
b2998086 PR |
972 | vty = wctx->vty; |
973 | json_mac_hdr = wctx->json; | |
3198b2b3 | 974 | mac = (struct zebra_mac *)bucket->data; |
b2998086 | 975 | if (!mac) |
24268cd0 PR |
976 | return; |
977 | ||
b2998086 PR |
978 | wctx->count++; |
979 | prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1)); | |
24268cd0 | 980 | |
b2998086 | 981 | zebra_evpn_print_mac(mac, vty, json_mac_hdr); |
24268cd0 PR |
982 | } |
983 | ||
984 | /* | |
b2998086 | 985 | * Inform BGP about local MACIP. |
24268cd0 | 986 | */ |
7f7e49d1 MS |
987 | int zebra_evpn_macip_send_msg_to_client(vni_t vni, |
988 | const struct ethaddr *macaddr, | |
1a3bd37f | 989 | const struct ipaddr *ip, uint8_t flags, |
b2998086 PR |
990 | uint32_t seq, int state, |
991 | struct zebra_evpn_es *es, uint16_t cmd) | |
24268cd0 | 992 | { |
b2998086 PR |
993 | int ipa_len; |
994 | struct zserv *client = NULL; | |
995 | struct stream *s = NULL; | |
996 | esi_t *esi = es ? &es->esi : zero_esi; | |
24268cd0 | 997 | |
b2998086 PR |
998 | client = zserv_find_client(ZEBRA_ROUTE_BGP, 0); |
999 | /* BGP may not be running. */ | |
1000 | if (!client) | |
1001 | return 0; | |
24268cd0 | 1002 | |
b2998086 | 1003 | s = stream_new(ZEBRA_MAX_PACKET_SIZ); |
24268cd0 | 1004 | |
b2998086 PR |
1005 | zclient_create_header(s, cmd, zebra_vrf_get_evpn_id()); |
1006 | stream_putl(s, vni); | |
1007 | stream_put(s, macaddr->octet, ETH_ALEN); | |
1008 | if (ip) { | |
1009 | ipa_len = 0; | |
1010 | if (IS_IPADDR_V4(ip)) | |
1011 | ipa_len = IPV4_MAX_BYTELEN; | |
1012 | else if (IS_IPADDR_V6(ip)) | |
1013 | ipa_len = IPV6_MAX_BYTELEN; | |
24268cd0 | 1014 | |
b2998086 PR |
1015 | stream_putl(s, ipa_len); /* IP address length */ |
1016 | if (ipa_len) | |
1017 | stream_put(s, &ip->ip.addr, ipa_len); /* IP address */ | |
1018 | } else | |
1019 | stream_putl(s, 0); /* Just MAC. */ | |
24268cd0 | 1020 | |
b2998086 PR |
1021 | if (cmd == ZEBRA_MACIP_ADD) { |
1022 | stream_putc(s, flags); /* sticky mac/gateway mac */ | |
1023 | stream_putl(s, seq); /* sequence number */ | |
1024 | stream_put(s, esi, sizeof(esi_t)); | |
24268cd0 | 1025 | } else { |
b2998086 PR |
1026 | stream_putl(s, state); /* state - active/inactive */ |
1027 | } | |
24268cd0 | 1028 | |
24268cd0 | 1029 | |
b2998086 PR |
1030 | /* Write packet size. */ |
1031 | stream_putw_at(s, 0, stream_get_endp(s)); | |
24268cd0 | 1032 | |
bf902d4c DS |
1033 | if (IS_ZEBRA_DEBUG_VXLAN) { |
1034 | char flag_buf[MACIP_BUF_SIZE]; | |
1035 | ||
b2998086 | 1036 | zlog_debug( |
ef7b8be4 | 1037 | "Send MACIP %s f %s MAC %pEA IP %pIA seq %u L2-VNI %u ESI %s to %s", |
bf902d4c DS |
1038 | (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", |
1039 | zclient_evpn_dump_macip_flags(flags, flag_buf, | |
1040 | sizeof(flag_buf)), | |
ef7b8be4 | 1041 | macaddr, ip, seq, vni, |
b2998086 PR |
1042 | es ? es->esi_str : "-", |
1043 | zebra_route_string(client->proto)); | |
bf902d4c | 1044 | } |
24268cd0 | 1045 | |
b2998086 PR |
1046 | if (cmd == ZEBRA_MACIP_ADD) |
1047 | client->macipadd_cnt++; | |
1048 | else | |
1049 | client->macipdel_cnt++; | |
24268cd0 | 1050 | |
b2998086 PR |
1051 | return zserv_send_message(client, s); |
1052 | } | |
24268cd0 | 1053 | |
b2998086 PR |
1054 | static unsigned int mac_hash_keymake(const void *p) |
1055 | { | |
3198b2b3 | 1056 | const struct zebra_mac *pmac = p; |
b2998086 | 1057 | const void *pnt = (void *)pmac->macaddr.octet; |
24268cd0 | 1058 | |
b2998086 | 1059 | return jhash(pnt, ETH_ALEN, 0xa5a5a55a); |
24268cd0 PR |
1060 | } |
1061 | ||
1062 | /* | |
b2998086 | 1063 | * Compare two MAC addresses. |
24268cd0 | 1064 | */ |
b2998086 | 1065 | static bool mac_cmp(const void *p1, const void *p2) |
24268cd0 | 1066 | { |
3198b2b3 DS |
1067 | const struct zebra_mac *pmac1 = p1; |
1068 | const struct zebra_mac *pmac2 = p2; | |
24268cd0 | 1069 | |
b2998086 PR |
1070 | if (pmac1 == NULL && pmac2 == NULL) |
1071 | return true; | |
24268cd0 | 1072 | |
b2998086 PR |
1073 | if (pmac1 == NULL || pmac2 == NULL) |
1074 | return false; | |
24268cd0 | 1075 | |
b2998086 PR |
1076 | return (memcmp(pmac1->macaddr.octet, pmac2->macaddr.octet, ETH_ALEN) |
1077 | == 0); | |
1078 | } | |
24268cd0 | 1079 | |
b2998086 PR |
1080 | /* |
1081 | * Callback to allocate MAC hash entry. | |
1082 | */ | |
1083 | static void *zebra_evpn_mac_alloc(void *p) | |
1084 | { | |
3198b2b3 DS |
1085 | const struct zebra_mac *tmp_mac = p; |
1086 | struct zebra_mac *mac; | |
24268cd0 | 1087 | |
3198b2b3 | 1088 | mac = XCALLOC(MTYPE_MAC, sizeof(struct zebra_mac)); |
b2998086 | 1089 | *mac = *tmp_mac; |
24268cd0 | 1090 | |
b2998086 PR |
1091 | return ((void *)mac); |
1092 | } | |
24268cd0 | 1093 | |
b2998086 PR |
1094 | /* |
1095 | * Add MAC entry. | |
1096 | */ | |
3198b2b3 DS |
1097 | struct zebra_mac *zebra_evpn_mac_add(struct zebra_evpn *zevpn, |
1098 | const struct ethaddr *macaddr) | |
b2998086 | 1099 | { |
3198b2b3 DS |
1100 | struct zebra_mac tmp_mac; |
1101 | struct zebra_mac *mac = NULL; | |
24268cd0 | 1102 | |
6006b807 | 1103 | memset(&tmp_mac, 0, sizeof(tmp_mac)); |
b2998086 PR |
1104 | memcpy(&tmp_mac.macaddr, macaddr, ETH_ALEN); |
1105 | mac = hash_get(zevpn->mac_table, &tmp_mac, zebra_evpn_mac_alloc); | |
24268cd0 | 1106 | |
b2998086 PR |
1107 | mac->zevpn = zevpn; |
1108 | mac->dad_mac_auto_recovery_timer = NULL; | |
24268cd0 | 1109 | |
b2998086 PR |
1110 | mac->neigh_list = list_new(); |
1111 | mac->neigh_list->cmp = neigh_list_cmp; | |
24268cd0 | 1112 | |
f1dbb1c7 | 1113 | mac->uptime = monotime(NULL); |
b2998086 | 1114 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
b16e8004 | 1115 | char mac_buf[MAC_BUF_SIZE]; |
24268cd0 | 1116 | |
ef7b8be4 DL |
1117 | zlog_debug("%s: MAC %pEA flags %s", __func__, |
1118 | &mac->macaddr, | |
b16e8004 DS |
1119 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
1120 | sizeof(mac_buf))); | |
b2998086 PR |
1121 | } |
1122 | return mac; | |
24268cd0 PR |
1123 | } |
1124 | ||
1125 | /* | |
b2998086 | 1126 | * Delete MAC entry. |
24268cd0 | 1127 | */ |
3198b2b3 | 1128 | int zebra_evpn_mac_del(struct zebra_evpn *zevpn, struct zebra_mac *mac) |
24268cd0 | 1129 | { |
3198b2b3 | 1130 | struct zebra_mac *tmp_mac; |
24268cd0 | 1131 | |
b2998086 | 1132 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
b16e8004 | 1133 | char mac_buf[MAC_BUF_SIZE]; |
b2998086 | 1134 | |
ef7b8be4 DL |
1135 | zlog_debug("%s: MAC %pEA flags %s", __func__, |
1136 | &mac->macaddr, | |
b16e8004 DS |
1137 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
1138 | sizeof(mac_buf))); | |
24268cd0 PR |
1139 | } |
1140 | ||
b2998086 PR |
1141 | /* force de-ref any ES entry linked to the MAC */ |
1142 | zebra_evpn_es_mac_deref_entry(mac); | |
24268cd0 | 1143 | |
8b07f173 AK |
1144 | /* remove links to the destination access port */ |
1145 | zebra_evpn_mac_clear_fwd_info(mac); | |
1146 | ||
b2998086 PR |
1147 | /* Cancel proxy hold timer */ |
1148 | zebra_evpn_mac_stop_hold_timer(mac); | |
24268cd0 | 1149 | |
b2998086 PR |
1150 | /* Cancel auto recovery */ |
1151 | THREAD_OFF(mac->dad_mac_auto_recovery_timer); | |
24268cd0 | 1152 | |
d5fdae8f CS |
1153 | /* If the MAC is freed before the neigh we will end up |
1154 | * with a stale pointer against the neigh. | |
1155 | * The situation can arise when a MAC is in remote state | |
1156 | * and its associated neigh is local state. | |
1157 | * zebra_evpn_cfg_cleanup() cleans up remote neighs and MACs. | |
1158 | * Instead of deleting remote MAC, if its neigh list is non-empty | |
1159 | * (associated to local neighs), mark the MAC as AUTO. | |
1160 | */ | |
1161 | if (!list_isempty(mac->neigh_list)) { | |
1162 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1163 | zlog_debug( | |
1164 | "MAC %pEA (flags 0x%x vni %u) has non-empty neigh list " | |
1165 | "count %u, mark MAC as AUTO", | |
1166 | &mac->macaddr, mac->flags, zevpn->vni, | |
1167 | listcount(mac->neigh_list)); | |
1168 | ||
1169 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
1170 | return 0; | |
1171 | } | |
1172 | ||
b2998086 | 1173 | list_delete(&mac->neigh_list); |
24268cd0 | 1174 | |
b2998086 PR |
1175 | /* Free the VNI hash entry and allocated memory. */ |
1176 | tmp_mac = hash_release(zevpn->mac_table, mac); | |
1177 | XFREE(MTYPE_MAC, tmp_mac); | |
24268cd0 | 1178 | |
b2998086 PR |
1179 | return 0; |
1180 | } | |
24268cd0 | 1181 | |
b2998086 | 1182 | static bool zebra_evpn_check_mac_del_from_db(struct mac_walk_ctx *wctx, |
3198b2b3 | 1183 | struct zebra_mac *mac) |
b2998086 PR |
1184 | { |
1185 | if ((wctx->flags & DEL_LOCAL_MAC) && (mac->flags & ZEBRA_MAC_LOCAL)) | |
1186 | return true; | |
1187 | else if ((wctx->flags & DEL_REMOTE_MAC) | |
1188 | && (mac->flags & ZEBRA_MAC_REMOTE)) | |
1189 | return true; | |
1190 | else if ((wctx->flags & DEL_REMOTE_MAC_FROM_VTEP) | |
1191 | && (mac->flags & ZEBRA_MAC_REMOTE) | |
1192 | && IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip, &wctx->r_vtep_ip)) | |
1193 | return true; | |
1194 | else if ((wctx->flags & DEL_LOCAL_MAC) && (mac->flags & ZEBRA_MAC_AUTO) | |
1195 | && !listcount(mac->neigh_list)) { | |
1196 | if (IS_ZEBRA_DEBUG_VXLAN) { | |
b16e8004 | 1197 | char mac_buf[MAC_BUF_SIZE]; |
24268cd0 | 1198 | |
24268cd0 | 1199 | zlog_debug( |
ef7b8be4 DL |
1200 | "%s: Del MAC %pEA flags %s", __func__, |
1201 | &mac->macaddr, | |
b16e8004 DS |
1202 | zebra_evpn_zebra_mac_flag_dump( |
1203 | mac, mac_buf, sizeof(mac_buf))); | |
b2998086 PR |
1204 | } |
1205 | wctx->uninstall = 0; | |
24268cd0 | 1206 | |
b2998086 PR |
1207 | return true; |
1208 | } | |
24268cd0 | 1209 | |
b2998086 PR |
1210 | return false; |
1211 | } | |
24268cd0 | 1212 | |
b2998086 PR |
1213 | /* |
1214 | * Free MAC hash entry (callback) | |
1215 | */ | |
1216 | static void zebra_evpn_mac_del_hash_entry(struct hash_bucket *bucket, void *arg) | |
1217 | { | |
1218 | struct mac_walk_ctx *wctx = arg; | |
3198b2b3 | 1219 | struct zebra_mac *mac = bucket->data; |
24268cd0 | 1220 | |
b2998086 PR |
1221 | if (zebra_evpn_check_mac_del_from_db(wctx, mac)) { |
1222 | if (wctx->upd_client && (mac->flags & ZEBRA_MAC_LOCAL)) { | |
1223 | zebra_evpn_mac_send_del_to_client(wctx->zevpn->vni, | |
1224 | &mac->macaddr, | |
1225 | mac->flags, false); | |
1226 | } | |
1227 | if (wctx->uninstall) { | |
1228 | if (zebra_evpn_mac_is_static(mac)) | |
1229 | zebra_evpn_sync_mac_dp_install( | |
1230 | mac, false /* set_inactive */, | |
1231 | true /* force_clear_static */, | |
1232 | __func__); | |
24268cd0 | 1233 | |
b2998086 | 1234 | if (mac->flags & ZEBRA_MAC_REMOTE) |
f3722826 AK |
1235 | zebra_evpn_rem_mac_uninstall(wctx->zevpn, mac, |
1236 | false /*force*/); | |
24268cd0 | 1237 | } |
b2998086 PR |
1238 | |
1239 | zebra_evpn_mac_del(wctx->zevpn, mac); | |
24268cd0 PR |
1240 | } |
1241 | ||
24268cd0 PR |
1242 | return; |
1243 | } | |
1244 | ||
24268cd0 | 1245 | /* |
b2998086 | 1246 | * Delete all MAC entries for this EVPN. |
24268cd0 | 1247 | */ |
f6371c34 DS |
1248 | void zebra_evpn_mac_del_all(struct zebra_evpn *zevpn, int uninstall, |
1249 | int upd_client, uint32_t flags) | |
24268cd0 | 1250 | { |
b2998086 | 1251 | struct mac_walk_ctx wctx; |
24268cd0 | 1252 | |
b2998086 | 1253 | if (!zevpn->mac_table) |
24268cd0 PR |
1254 | return; |
1255 | ||
6006b807 | 1256 | memset(&wctx, 0, sizeof(wctx)); |
b2998086 PR |
1257 | wctx.zevpn = zevpn; |
1258 | wctx.uninstall = uninstall; | |
1259 | wctx.upd_client = upd_client; | |
1260 | wctx.flags = flags; | |
24268cd0 | 1261 | |
b2998086 PR |
1262 | hash_iterate(zevpn->mac_table, zebra_evpn_mac_del_hash_entry, &wctx); |
1263 | } | |
24268cd0 | 1264 | |
b2998086 PR |
1265 | /* |
1266 | * Look up MAC hash entry. | |
1267 | */ | |
3198b2b3 DS |
1268 | struct zebra_mac *zebra_evpn_mac_lookup(struct zebra_evpn *zevpn, |
1269 | const struct ethaddr *mac) | |
b2998086 | 1270 | { |
3198b2b3 DS |
1271 | struct zebra_mac tmp; |
1272 | struct zebra_mac *pmac; | |
24268cd0 | 1273 | |
b2998086 PR |
1274 | memset(&tmp, 0, sizeof(tmp)); |
1275 | memcpy(&tmp.macaddr, mac, ETH_ALEN); | |
1276 | pmac = hash_lookup(zevpn->mac_table, &tmp); | |
24268cd0 | 1277 | |
b2998086 PR |
1278 | return pmac; |
1279 | } | |
24268cd0 | 1280 | |
b2998086 PR |
1281 | /* |
1282 | * Inform BGP about local MAC addition. | |
1283 | */ | |
1a3bd37f | 1284 | int zebra_evpn_mac_send_add_to_client(vni_t vni, const struct ethaddr *macaddr, |
b2998086 PR |
1285 | uint32_t mac_flags, uint32_t seq, |
1286 | struct zebra_evpn_es *es) | |
1287 | { | |
1288 | uint8_t flags = 0; | |
24268cd0 | 1289 | |
b2998086 PR |
1290 | if (CHECK_FLAG(mac_flags, ZEBRA_MAC_LOCAL_INACTIVE)) { |
1291 | /* host reachability has not been verified locally */ | |
24268cd0 | 1292 | |
b2998086 PR |
1293 | /* if no ES peer is claiming reachability we can't advertise the |
1294 | * entry | |
1295 | */ | |
1296 | if (!CHECK_FLAG(mac_flags, ZEBRA_MAC_ES_PEER_ACTIVE)) | |
1297 | return 0; | |
24268cd0 | 1298 | |
b2998086 PR |
1299 | /* ES peers are claiming reachability; we will |
1300 | * advertise the entry but with a proxy flag | |
24268cd0 | 1301 | */ |
b2998086 PR |
1302 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT); |
1303 | } | |
24268cd0 | 1304 | |
b2998086 PR |
1305 | if (CHECK_FLAG(mac_flags, ZEBRA_MAC_STICKY)) |
1306 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); | |
1307 | if (CHECK_FLAG(mac_flags, ZEBRA_MAC_DEF_GW)) | |
1308 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW); | |
24268cd0 | 1309 | |
b2998086 PR |
1310 | return zebra_evpn_macip_send_msg_to_client(vni, macaddr, NULL, flags, |
1311 | seq, ZEBRA_NEIGH_ACTIVE, es, | |
1312 | ZEBRA_MACIP_ADD); | |
1313 | } | |
24268cd0 | 1314 | |
b2998086 PR |
1315 | /* |
1316 | * Inform BGP about local MAC deletion. | |
1317 | */ | |
1a3bd37f | 1318 | int zebra_evpn_mac_send_del_to_client(vni_t vni, const struct ethaddr *macaddr, |
b2998086 PR |
1319 | uint32_t flags, bool force) |
1320 | { | |
1321 | if (!force) { | |
1322 | if (CHECK_FLAG(flags, ZEBRA_MAC_LOCAL_INACTIVE) | |
1323 | && !CHECK_FLAG(flags, ZEBRA_MAC_ES_PEER_ACTIVE)) | |
1324 | /* the host was not advertised - nothing to delete */ | |
1325 | return 0; | |
24268cd0 PR |
1326 | } |
1327 | ||
b2998086 PR |
1328 | return zebra_evpn_macip_send_msg_to_client( |
1329 | vni, macaddr, NULL, 0 /* flags */, 0 /* seq */, | |
1330 | ZEBRA_NEIGH_ACTIVE, NULL, ZEBRA_MACIP_DEL); | |
24268cd0 PR |
1331 | } |
1332 | ||
1333 | /* | |
b2998086 | 1334 | * wrapper to create a MAC hash table |
24268cd0 | 1335 | */ |
b2998086 | 1336 | struct hash *zebra_mac_db_create(const char *desc) |
24268cd0 | 1337 | { |
da55bcbc | 1338 | return hash_create_size(8, mac_hash_keymake, mac_cmp, desc); |
24268cd0 PR |
1339 | } |
1340 | ||
b2998086 | 1341 | /* program sync mac flags in the dataplane */ |
3198b2b3 | 1342 | int zebra_evpn_sync_mac_dp_install(struct zebra_mac *mac, bool set_inactive, |
15400f95 | 1343 | bool force_clear_static, const char *caller) |
24268cd0 | 1344 | { |
b2998086 PR |
1345 | struct interface *ifp; |
1346 | bool sticky; | |
1347 | bool set_static; | |
f6371c34 | 1348 | struct zebra_evpn *zevpn = mac->zevpn; |
b2998086 PR |
1349 | vlanid_t vid; |
1350 | struct zebra_if *zif; | |
1351 | struct interface *br_ifp; | |
24268cd0 | 1352 | |
09de6e45 AK |
1353 | /* If the ES-EVI doesn't exist defer install. When the ES-EVI is |
1354 | * created we will attempt to install the mac entry again | |
1355 | */ | |
1356 | if (mac->es) { | |
1357 | struct zebra_evpn_es_evi *es_evi; | |
1358 | ||
1359 | es_evi = zebra_evpn_es_evi_find(mac->es, mac->zevpn); | |
1360 | if (!es_evi) { | |
1361 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
1362 | zlog_debug( | |
1363 | "%s: dp-install sync-mac vni %u mac %pEA es %s 0x%x %sskipped, no es-evi", | |
1364 | caller, zevpn->vni, &mac->macaddr, | |
1365 | mac->es ? mac->es->esi_str : "-", | |
1366 | mac->flags, | |
1367 | set_inactive ? "inactive " : ""); | |
1368 | return -1; | |
1369 | } | |
1370 | } | |
1371 | ||
b2998086 PR |
1372 | /* get the access vlan from the vxlan_device */ |
1373 | zebra_evpn_mac_get_access_info(mac, &ifp, &vid); | |
24268cd0 | 1374 | |
b2998086 | 1375 | if (!ifp) { |
b16e8004 DS |
1376 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1377 | char mac_buf[MAC_BUF_SIZE]; | |
1378 | ||
b2998086 | 1379 | zlog_debug( |
b16e8004 | 1380 | "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no access-port", |
15400f95 | 1381 | caller, zevpn->vni, &mac->macaddr, |
b16e8004 DS |
1382 | mac->es ? mac->es->esi_str : "-", |
1383 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1384 | sizeof(mac_buf)), | |
b2998086 | 1385 | set_inactive ? "inactive " : ""); |
b16e8004 | 1386 | } |
15400f95 | 1387 | return -1; |
b2998086 | 1388 | } |
24268cd0 | 1389 | |
b2998086 PR |
1390 | zif = ifp->info; |
1391 | br_ifp = zif->brslave_info.br_if; | |
1392 | if (!br_ifp) { | |
b16e8004 DS |
1393 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1394 | char mac_buf[MAC_BUF_SIZE]; | |
1395 | ||
b2998086 | 1396 | zlog_debug( |
b16e8004 | 1397 | "%s: dp-install sync-mac vni %u mac %pEA es %s %s%sskipped, no br", |
15400f95 | 1398 | caller, zevpn->vni, &mac->macaddr, |
b16e8004 DS |
1399 | mac->es ? mac->es->esi_str : "-", |
1400 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1401 | sizeof(mac_buf)), | |
b2998086 | 1402 | set_inactive ? "inactive " : ""); |
b16e8004 | 1403 | } |
15400f95 | 1404 | return -1; |
b2998086 | 1405 | } |
24268cd0 | 1406 | |
b2998086 PR |
1407 | sticky = !!CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY); |
1408 | if (force_clear_static) | |
1409 | set_static = false; | |
1410 | else | |
1411 | set_static = zebra_evpn_mac_is_static(mac); | |
24268cd0 | 1412 | |
15400f95 AK |
1413 | /* We can install a local mac that has been synced from the peer |
1414 | * over the VxLAN-overlay/network-port if fast failover is not | |
1415 | * supported and if the local ES is oper-down. | |
1416 | */ | |
1417 | if (mac->es && zebra_evpn_es_local_mac_via_network_port(mac->es)) { | |
b16e8004 DS |
1418 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1419 | char mac_buf[MAC_BUF_SIZE]; | |
1420 | ||
15400f95 | 1421 | zlog_debug( |
b16e8004 | 1422 | "dp-%s sync-nw-mac vni %u mac %pEA es %s %s%s", |
15400f95 AK |
1423 | set_static ? "install" : "uninstall", |
1424 | zevpn->vni, &mac->macaddr, | |
b16e8004 DS |
1425 | mac->es ? mac->es->esi_str : "-", |
1426 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1427 | sizeof(mac_buf)), | |
15400f95 | 1428 | set_inactive ? "inactive " : ""); |
b16e8004 | 1429 | } |
15400f95 AK |
1430 | if (set_static) |
1431 | /* XXX - old_static needs to be computed more | |
1432 | * accurately | |
1433 | */ | |
1434 | zebra_evpn_rem_mac_install(zevpn, mac, | |
1435 | true /* old_static */); | |
1436 | else | |
1437 | zebra_evpn_rem_mac_uninstall(zevpn, mac, | |
1438 | false /* force */); | |
1439 | ||
1440 | return 0; | |
1441 | } | |
1442 | ||
b16e8004 DS |
1443 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1444 | char mac_buf[MAC_BUF_SIZE]; | |
1445 | ||
1446 | zlog_debug("dp-install sync-mac vni %u mac %pEA es %s %s%s%s", | |
1447 | zevpn->vni, &mac->macaddr, | |
1448 | mac->es ? mac->es->esi_str : "-", | |
1449 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1450 | sizeof(mac_buf)), | |
1451 | set_static ? "static " : "", | |
1452 | set_inactive ? "inactive " : ""); | |
1453 | } | |
24268cd0 | 1454 | |
b2998086 PR |
1455 | dplane_local_mac_add(ifp, br_ifp, vid, &mac->macaddr, sticky, |
1456 | set_static, set_inactive); | |
15400f95 | 1457 | return 0; |
24268cd0 PR |
1458 | } |
1459 | ||
3198b2b3 DS |
1460 | void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac *mac, |
1461 | bool old_bgp_ready, | |
b2998086 | 1462 | bool new_bgp_ready) |
24268cd0 | 1463 | { |
b2998086 PR |
1464 | if (new_bgp_ready) |
1465 | zebra_evpn_mac_send_add_to_client(mac->zevpn->vni, | |
1466 | &mac->macaddr, mac->flags, | |
1467 | mac->loc_seq, mac->es); | |
1468 | else if (old_bgp_ready) | |
1469 | zebra_evpn_mac_send_del_to_client(mac->zevpn->vni, | |
1470 | &mac->macaddr, mac->flags, | |
1471 | true /* force */); | |
24268cd0 PR |
1472 | } |
1473 | ||
b2998086 PR |
1474 | /* MAC hold timer is used to age out peer-active flag. |
1475 | * | |
1476 | * During this wait time we expect the dataplane component or an | |
1477 | * external neighmgr daemon to probe existing hosts to independently | |
1478 | * establish their presence on the ES. | |
1479 | */ | |
cc9f21da | 1480 | static void zebra_evpn_mac_hold_exp_cb(struct thread *t) |
24268cd0 | 1481 | { |
3198b2b3 | 1482 | struct zebra_mac *mac; |
b2998086 PR |
1483 | bool old_bgp_ready; |
1484 | bool new_bgp_ready; | |
1485 | bool old_static; | |
1486 | bool new_static; | |
24268cd0 PR |
1487 | |
1488 | mac = THREAD_ARG(t); | |
b2998086 PR |
1489 | /* the purpose of the hold timer is to age out the peer-active |
1490 | * flag | |
1491 | */ | |
1492 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) | |
cc9f21da | 1493 | return; |
24268cd0 | 1494 | |
b2998086 PR |
1495 | old_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); |
1496 | old_static = zebra_evpn_mac_is_static(mac); | |
1497 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE); | |
1498 | new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
1499 | new_static = zebra_evpn_mac_is_static(mac); | |
24268cd0 | 1500 | |
b16e8004 DS |
1501 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1502 | char mac_buf[MAC_BUF_SIZE]; | |
1503 | ||
24268cd0 | 1504 | zlog_debug( |
ef7b8be4 DL |
1505 | "sync-mac vni %u mac %pEA es %s %shold expired", |
1506 | mac->zevpn->vni, &mac->macaddr, | |
b16e8004 DS |
1507 | mac->es ? mac->es->esi_str : "-", |
1508 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1509 | sizeof(mac_buf))); | |
1510 | } | |
24268cd0 | 1511 | |
b2998086 PR |
1512 | /* re-program the local mac in the dataplane if the mac is no |
1513 | * longer static | |
1514 | */ | |
1515 | if (old_static != new_static) | |
1516 | zebra_evpn_sync_mac_dp_install(mac, false /* set_inactive */, | |
1517 | false /* force_clear_static */, | |
1518 | __func__); | |
24268cd0 | 1519 | |
b2998086 PR |
1520 | /* inform bgp if needed */ |
1521 | if (old_bgp_ready != new_bgp_ready) | |
1522 | zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, | |
1523 | new_bgp_ready); | |
24268cd0 PR |
1524 | } |
1525 | ||
3198b2b3 | 1526 | static inline void zebra_evpn_mac_start_hold_timer(struct zebra_mac *mac) |
24268cd0 | 1527 | { |
b2998086 PR |
1528 | if (mac->hold_timer) |
1529 | return; | |
24268cd0 | 1530 | |
b16e8004 DS |
1531 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1532 | char mac_buf[MAC_BUF_SIZE]; | |
1533 | ||
24268cd0 | 1534 | zlog_debug( |
ef7b8be4 DL |
1535 | "sync-mac vni %u mac %pEA es %s %shold started", |
1536 | mac->zevpn->vni, &mac->macaddr, | |
b16e8004 DS |
1537 | mac->es ? mac->es->esi_str : "-", |
1538 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1539 | sizeof(mac_buf))); | |
1540 | } | |
b2998086 PR |
1541 | thread_add_timer(zrouter.master, zebra_evpn_mac_hold_exp_cb, mac, |
1542 | zmh_info->mac_hold_time, &mac->hold_timer); | |
24268cd0 PR |
1543 | } |
1544 | ||
3198b2b3 | 1545 | void zebra_evpn_mac_stop_hold_timer(struct zebra_mac *mac) |
24268cd0 | 1546 | { |
b2998086 PR |
1547 | if (!mac->hold_timer) |
1548 | return; | |
24268cd0 | 1549 | |
b16e8004 DS |
1550 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1551 | char mac_buf[MAC_BUF_SIZE]; | |
1552 | ||
b2998086 | 1553 | zlog_debug( |
ef7b8be4 DL |
1554 | "sync-mac vni %u mac %pEA es %s %shold stopped", |
1555 | mac->zevpn->vni, &mac->macaddr, | |
b16e8004 DS |
1556 | mac->es ? mac->es->esi_str : "-", |
1557 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, | |
1558 | sizeof(mac_buf))); | |
1559 | } | |
1560 | ||
b2998086 | 1561 | THREAD_OFF(mac->hold_timer); |
24268cd0 PR |
1562 | } |
1563 | ||
3198b2b3 | 1564 | void zebra_evpn_sync_mac_del(struct zebra_mac *mac) |
24268cd0 | 1565 | { |
b2998086 PR |
1566 | bool old_static; |
1567 | bool new_static; | |
24268cd0 | 1568 | |
b16e8004 DS |
1569 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1570 | char mac_buf[MAC_BUF_SIZE]; | |
1571 | ||
b2998086 | 1572 | zlog_debug( |
ef7b8be4 DL |
1573 | "sync-mac del vni %u mac %pEA es %s seq %d f %s", |
1574 | mac->zevpn->vni, &mac->macaddr, | |
b2998086 | 1575 | mac->es ? mac->es->esi_str : "-", mac->loc_seq, |
b16e8004 DS |
1576 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
1577 | sizeof(mac_buf))); | |
1578 | } | |
1579 | ||
b2998086 PR |
1580 | old_static = zebra_evpn_mac_is_static(mac); |
1581 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY); | |
1582 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE)) | |
1583 | zebra_evpn_mac_start_hold_timer(mac); | |
1584 | new_static = zebra_evpn_mac_is_static(mac); | |
24268cd0 | 1585 | |
b2998086 PR |
1586 | if (old_static != new_static) |
1587 | /* program the local mac in the kernel */ | |
1588 | zebra_evpn_sync_mac_dp_install(mac, false /* set_inactive */, | |
1589 | false /* force_clear_static */, | |
1590 | __func__); | |
24268cd0 PR |
1591 | } |
1592 | ||
f6371c34 | 1593 | static inline bool zebra_evpn_mac_is_bgp_seq_ok(struct zebra_evpn *zevpn, |
3198b2b3 DS |
1594 | struct zebra_mac *mac, |
1595 | uint32_t seq, uint16_t ipa_len, | |
1a3bd37f | 1596 | const struct ipaddr *ipaddr, |
16de1338 | 1597 | bool sync) |
24268cd0 | 1598 | { |
b2998086 | 1599 | char ipbuf[INET6_ADDRSTRLEN]; |
7d99ad7f | 1600 | char mac_buf[MAC_BUF_SIZE]; |
b2998086 | 1601 | uint32_t tmp_seq; |
16de1338 | 1602 | const char *n_type; |
24268cd0 | 1603 | |
16de1338 | 1604 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { |
b2998086 | 1605 | tmp_seq = mac->loc_seq; |
16de1338 AK |
1606 | n_type = "local"; |
1607 | } else { | |
b2998086 | 1608 | tmp_seq = mac->rem_seq; |
16de1338 AK |
1609 | n_type = "remote"; |
1610 | } | |
24268cd0 | 1611 | |
b2998086 PR |
1612 | if (seq < tmp_seq) { |
1613 | /* if the mac was never advertised to bgp we must accept | |
1614 | * whatever sequence number bgp sends | |
b2998086 | 1615 | */ |
7d99ad7f SW |
1616 | if (zebra_vxlan_accept_bgp_seq()) { |
1617 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC || | |
1618 | IS_ZEBRA_DEBUG_VXLAN) { | |
b2998086 | 1619 | zlog_debug( |
ef7b8be4 | 1620 | "%s-macip accept vni %u %s-mac %pEA%s%s lower seq %u f %s", |
16de1338 | 1621 | sync ? "sync" : "rem", zevpn->vni, |
7d99ad7f | 1622 | n_type, &mac->macaddr, |
b2998086 PR |
1623 | ipa_len ? " IP " : "", |
1624 | ipa_len ? ipaddr2str(ipaddr, ipbuf, | |
1625 | sizeof(ipbuf)) | |
1626 | : "", | |
b16e8004 DS |
1627 | tmp_seq, |
1628 | zebra_evpn_zebra_mac_flag_dump( | |
1629 | mac, mac_buf, sizeof(mac_buf))); | |
1630 | } | |
1631 | ||
b2998086 PR |
1632 | return true; |
1633 | } | |
24268cd0 | 1634 | |
b16e8004 | 1635 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC || IS_ZEBRA_DEBUG_VXLAN) { |
b2998086 | 1636 | zlog_debug( |
ef7b8be4 | 1637 | "%s-macip ignore vni %u %s-mac %pEA%s%s as existing has higher seq %u f %s", |
16de1338 | 1638 | sync ? "sync" : "rem", zevpn->vni, n_type, |
ef7b8be4 | 1639 | &mac->macaddr, |
b2998086 PR |
1640 | ipa_len ? " IP " : "", |
1641 | ipa_len ? ipaddr2str(ipaddr, ipbuf, | |
1642 | sizeof(ipbuf)) | |
1643 | : "", | |
b16e8004 DS |
1644 | tmp_seq, |
1645 | zebra_evpn_zebra_mac_flag_dump( | |
1646 | mac, mac_buf, sizeof(mac_buf))); | |
1647 | } | |
7d99ad7f | 1648 | |
b2998086 | 1649 | return false; |
24268cd0 PR |
1650 | } |
1651 | ||
b2998086 | 1652 | return true; |
24268cd0 PR |
1653 | } |
1654 | ||
3198b2b3 | 1655 | struct zebra_mac *zebra_evpn_proc_sync_mac_update( |
f6371c34 DS |
1656 | struct zebra_evpn *zevpn, const struct ethaddr *macaddr, |
1657 | uint16_t ipa_len, const struct ipaddr *ipaddr, uint8_t flags, | |
1658 | uint32_t seq, const esi_t *esi, struct sync_mac_ip_ctx *ctx) | |
24268cd0 | 1659 | { |
3198b2b3 | 1660 | struct zebra_mac *mac; |
b2998086 PR |
1661 | bool inform_bgp = false; |
1662 | bool inform_dataplane = false; | |
1663 | bool seq_change = false; | |
1664 | bool es_change = false; | |
1665 | uint32_t tmp_seq; | |
b2998086 PR |
1666 | char ipbuf[INET6_ADDRSTRLEN]; |
1667 | bool old_local = false; | |
1668 | bool old_bgp_ready; | |
1669 | bool new_bgp_ready; | |
24268cd0 | 1670 | |
b2998086 PR |
1671 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); |
1672 | if (!mac) { | |
1673 | /* if it is a new local path we need to inform both | |
1674 | * the control protocol and the data-plane | |
1675 | */ | |
1676 | inform_bgp = true; | |
1677 | inform_dataplane = true; | |
1678 | ctx->mac_created = true; | |
1679 | ctx->mac_inactive = true; | |
24268cd0 | 1680 | |
b2998086 PR |
1681 | /* create the MAC and associate it with the dest ES */ |
1682 | mac = zebra_evpn_mac_add(zevpn, macaddr); | |
1683 | zebra_evpn_es_mac_ref(mac, esi); | |
24268cd0 | 1684 | |
b2998086 PR |
1685 | /* local mac activated by an ES peer */ |
1686 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); | |
1687 | /* if mac-only route setup peer flags */ | |
1688 | if (!ipa_len) { | |
1689 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) | |
1690 | SET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_PROXY); | |
1691 | else | |
1692 | SET_FLAG(mac->flags, ZEBRA_MAC_ES_PEER_ACTIVE); | |
1693 | } | |
1694 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE); | |
1695 | old_bgp_ready = false; | |
1696 | new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
1697 | } else { | |
1698 | uint32_t old_flags; | |
1699 | uint32_t new_flags; | |
1700 | bool old_static; | |
1701 | bool new_static; | |
1702 | bool sticky; | |
1703 | bool remote_gw; | |
24268cd0 | 1704 | |
f1dbb1c7 DS |
1705 | mac->uptime = monotime(NULL); |
1706 | ||
b2998086 PR |
1707 | old_flags = mac->flags; |
1708 | sticky = !!CHECK_FLAG(old_flags, ZEBRA_MAC_STICKY); | |
1709 | remote_gw = !!CHECK_FLAG(old_flags, ZEBRA_MAC_REMOTE_DEF_GW); | |
1710 | if (sticky || remote_gw) { | |
1711 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
1712 | zlog_debug( | |
ef7b8be4 DL |
1713 | "Ignore sync-macip vni %u mac %pEA%s%s%s%s", |
1714 | zevpn->vni, macaddr, | |
b2998086 PR |
1715 | ipa_len ? " IP " : "", |
1716 | ipa_len ? ipaddr2str(ipaddr, ipbuf, | |
1717 | sizeof(ipbuf)) | |
1718 | : "", | |
1719 | sticky ? " sticky" : "", | |
1720 | remote_gw ? " remote_gw" : ""); | |
1721 | ctx->ignore_macip = true; | |
1722 | return NULL; | |
1723 | } | |
1724 | if (!zebra_evpn_mac_is_bgp_seq_ok(zevpn, mac, seq, ipa_len, | |
16de1338 | 1725 | ipaddr, true)) { |
b2998086 PR |
1726 | ctx->ignore_macip = true; |
1727 | return NULL; | |
1728 | } | |
24268cd0 | 1729 | |
b2998086 PR |
1730 | old_local = !!CHECK_FLAG(old_flags, ZEBRA_MAC_LOCAL); |
1731 | old_static = zebra_evpn_mac_is_static(mac); | |
24268cd0 | 1732 | |
b2998086 PR |
1733 | /* re-build the mac flags */ |
1734 | new_flags = 0; | |
1735 | SET_FLAG(new_flags, ZEBRA_MAC_LOCAL); | |
1736 | /* retain old local activity flag */ | |
1737 | if (old_flags & ZEBRA_MAC_LOCAL) { | |
1738 | new_flags |= (old_flags & ZEBRA_MAC_LOCAL_INACTIVE); | |
1739 | } else { | |
1740 | new_flags |= ZEBRA_MAC_LOCAL_INACTIVE; | |
1741 | ctx->mac_inactive = true; | |
1742 | } | |
1743 | if (ipa_len) { | |
1744 | /* if mac-ip route do NOT update the peer flags | |
1745 | * i.e. retain only flags as is | |
1746 | */ | |
1747 | new_flags |= (old_flags & ZEBRA_MAC_ALL_PEER_FLAGS); | |
1748 | } else { | |
1749 | /* if mac-only route update peer flags */ | |
1750 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) { | |
1751 | SET_FLAG(new_flags, ZEBRA_MAC_ES_PEER_PROXY); | |
1752 | /* if the mac was peer-active previously we | |
1753 | * need to keep the flag and start the | |
1754 | * holdtimer on it. the peer-active flag is | |
1755 | * cleared on holdtimer expiry. | |
1756 | */ | |
1757 | if (CHECK_FLAG(old_flags, | |
1758 | ZEBRA_MAC_ES_PEER_ACTIVE)) { | |
1759 | SET_FLAG(new_flags, | |
1760 | ZEBRA_MAC_ES_PEER_ACTIVE); | |
1761 | zebra_evpn_mac_start_hold_timer(mac); | |
1762 | } | |
1763 | } else { | |
1764 | SET_FLAG(new_flags, ZEBRA_MAC_ES_PEER_ACTIVE); | |
1765 | /* stop hold timer if a peer has verified | |
1766 | * reachability | |
1767 | */ | |
1768 | zebra_evpn_mac_stop_hold_timer(mac); | |
1769 | } | |
1770 | } | |
1771 | mac->rem_seq = 0; | |
8b07f173 | 1772 | zebra_evpn_mac_clear_fwd_info(mac); |
b2998086 | 1773 | mac->flags = new_flags; |
24268cd0 | 1774 | |
b16e8004 DS |
1775 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC && (old_flags != new_flags)) { |
1776 | char mac_buf[MAC_BUF_SIZE], omac_buf[MAC_BUF_SIZE]; | |
3198b2b3 | 1777 | struct zebra_mac omac; |
b16e8004 DS |
1778 | |
1779 | omac.flags = old_flags; | |
b2998086 | 1780 | zlog_debug( |
ef7b8be4 DL |
1781 | "sync-mac vni %u mac %pEA old_f %snew_f %s", |
1782 | zevpn->vni, macaddr, | |
b16e8004 DS |
1783 | zebra_evpn_zebra_mac_flag_dump( |
1784 | &omac, omac_buf, sizeof(omac_buf)), | |
1785 | zebra_evpn_zebra_mac_flag_dump( | |
1786 | mac, mac_buf, sizeof(mac_buf))); | |
1787 | } | |
24268cd0 | 1788 | |
b2998086 PR |
1789 | /* update es */ |
1790 | es_change = zebra_evpn_es_mac_ref(mac, esi); | |
1791 | /* if mac dest change - inform both sides */ | |
1792 | if (es_change) { | |
1793 | inform_bgp = true; | |
1794 | inform_dataplane = true; | |
1795 | ctx->mac_inactive = true; | |
1796 | } | |
8b07f173 | 1797 | |
b2998086 PR |
1798 | /* if peer-flag is being set notify dataplane that the |
1799 | * entry must not be expired because of local inactivity | |
1800 | */ | |
1801 | new_static = zebra_evpn_mac_is_static(mac); | |
1802 | if (old_static != new_static) | |
1803 | inform_dataplane = true; | |
24268cd0 | 1804 | |
b2998086 PR |
1805 | old_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(old_flags); |
1806 | new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
1807 | if (old_bgp_ready != new_bgp_ready) | |
1808 | inform_bgp = true; | |
1809 | } | |
24268cd0 | 1810 | |
24268cd0 | 1811 | |
b2998086 PR |
1812 | /* update sequence number; if that results in a new local sequence |
1813 | * inform bgp | |
1814 | */ | |
1815 | tmp_seq = MAX(mac->loc_seq, seq); | |
1816 | if (tmp_seq != mac->loc_seq) { | |
1817 | mac->loc_seq = tmp_seq; | |
1818 | seq_change = true; | |
1819 | inform_bgp = true; | |
1820 | } | |
24268cd0 | 1821 | |
b16e8004 DS |
1822 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
1823 | char mac_buf[MAC_BUF_SIZE]; | |
1824 | ||
ef7b8be4 DL |
1825 | zlog_debug("sync-mac %s vni %u mac %pEA es %s seq %d f %s%s%s", |
1826 | ctx->mac_created ? "created" : "updated", | |
1827 | zevpn->vni, macaddr, | |
b2998086 | 1828 | mac->es ? mac->es->esi_str : "-", mac->loc_seq, |
b16e8004 DS |
1829 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
1830 | sizeof(mac_buf)), | |
1831 | inform_bgp ? "inform_bgp" : "", | |
b2998086 | 1832 | inform_dataplane ? " inform_dp" : ""); |
b16e8004 | 1833 | } |
24268cd0 | 1834 | |
b2998086 PR |
1835 | if (inform_bgp) |
1836 | zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, | |
1837 | new_bgp_ready); | |
24268cd0 | 1838 | |
b2998086 PR |
1839 | /* neighs using the mac may need to be re-sent to |
1840 | * bgp with updated info | |
1841 | */ | |
1842 | if (seq_change || es_change || !old_local) | |
1843 | zebra_evpn_process_neigh_on_local_mac_change( | |
1844 | zevpn, mac, seq_change, es_change); | |
24268cd0 | 1845 | |
b2998086 PR |
1846 | if (inform_dataplane) { |
1847 | if (ipa_len) | |
1848 | /* if the mac is being created as a part of MAC-IP | |
1849 | * route wait for the neigh to be updated or | |
1850 | * created before programming the mac | |
1851 | */ | |
1852 | ctx->mac_dp_update_deferred = true; | |
1853 | else | |
1854 | /* program the local mac in the kernel. when the ES | |
1855 | * change we need to force the dataplane to reset | |
1856 | * the activity as we are yet to establish activity | |
1857 | * locally | |
1858 | */ | |
1859 | zebra_evpn_sync_mac_dp_install( | |
1860 | mac, ctx->mac_inactive, | |
1861 | false /* force_clear_static */, __func__); | |
1862 | } | |
24268cd0 | 1863 | |
b2998086 | 1864 | return mac; |
24268cd0 PR |
1865 | } |
1866 | ||
07b12758 | 1867 | /* update local forwarding info. return true if a dest-ES change |
b2998086 PR |
1868 | * is detected |
1869 | */ | |
3198b2b3 | 1870 | static bool zebra_evpn_local_mac_update_fwd_info(struct zebra_mac *mac, |
d9d3455e PR |
1871 | struct interface *ifp, |
1872 | vlanid_t vid) | |
24268cd0 | 1873 | { |
b2998086 PR |
1874 | struct zebra_if *zif = ifp->info; |
1875 | bool es_change; | |
47c58929 PG |
1876 | ns_id_t local_ns_id = NS_DEFAULT; |
1877 | struct zebra_vrf *zvrf; | |
00a7710c | 1878 | struct zebra_evpn_es *es; |
47c58929 | 1879 | |
096f7609 | 1880 | zvrf = ifp->vrf->info; |
47c58929 PG |
1881 | if (zvrf && zvrf->zns) |
1882 | local_ns_id = zvrf->zns->ns_id; | |
24268cd0 | 1883 | |
8b07f173 | 1884 | zebra_evpn_mac_clear_fwd_info(mac); |
24268cd0 | 1885 | |
00a7710c AK |
1886 | es = zif->es_info.es; |
1887 | if (es && (es->flags & ZEBRA_EVPNES_BYPASS)) | |
1888 | es = NULL; | |
1889 | es_change = zebra_evpn_es_mac_ref_entry(mac, es); | |
24268cd0 | 1890 | |
b2998086 PR |
1891 | if (!mac->es) { |
1892 | /* if es is set fwd_info is not-relevant/taped-out */ | |
1893 | mac->fwd_info.local.ifindex = ifp->ifindex; | |
47c58929 | 1894 | mac->fwd_info.local.ns_id = local_ns_id; |
b2998086 | 1895 | mac->fwd_info.local.vid = vid; |
8b07f173 | 1896 | zebra_evpn_mac_ifp_link(mac, ifp); |
24268cd0 PR |
1897 | } |
1898 | ||
b2998086 | 1899 | return es_change; |
24268cd0 PR |
1900 | } |
1901 | ||
24268cd0 | 1902 | /* Notify Local MACs to the clienti, skips GW MAC */ |
b2998086 PR |
1903 | static void zebra_evpn_send_mac_hash_entry_to_client(struct hash_bucket *bucket, |
1904 | void *arg) | |
24268cd0 PR |
1905 | { |
1906 | struct mac_walk_ctx *wctx = arg; | |
3198b2b3 | 1907 | struct zebra_mac *zmac = bucket->data; |
24268cd0 PR |
1908 | |
1909 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_DEF_GW)) | |
1910 | return; | |
1911 | ||
1912 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) | |
b2998086 PR |
1913 | zebra_evpn_mac_send_add_to_client(wctx->zevpn->vni, |
1914 | &zmac->macaddr, zmac->flags, | |
1915 | zmac->loc_seq, zmac->es); | |
24268cd0 PR |
1916 | } |
1917 | ||
1918 | /* Iterator to Notify Local MACs of a EVPN */ | |
f6371c34 | 1919 | void zebra_evpn_send_mac_list_to_client(struct zebra_evpn *zevpn) |
24268cd0 PR |
1920 | { |
1921 | struct mac_walk_ctx wctx; | |
1922 | ||
1923 | if (!zevpn->mac_table) | |
1924 | return; | |
1925 | ||
6006b807 | 1926 | memset(&wctx, 0, sizeof(wctx)); |
24268cd0 PR |
1927 | wctx.zevpn = zevpn; |
1928 | ||
b2998086 PR |
1929 | hash_iterate(zevpn->mac_table, zebra_evpn_send_mac_hash_entry_to_client, |
1930 | &wctx); | |
24268cd0 PR |
1931 | } |
1932 | ||
3198b2b3 | 1933 | void zebra_evpn_rem_mac_del(struct zebra_evpn *zevpn, struct zebra_mac *mac) |
24268cd0 | 1934 | { |
b2998086 PR |
1935 | zebra_evpn_process_neigh_on_remote_mac_del(zevpn, mac); |
1936 | /* the remote sequence number in the auto mac entry | |
1937 | * needs to be reset to 0 as the mac entry may have | |
1938 | * been removed on all VTEPs (including | |
1939 | * the originating one) | |
1940 | */ | |
1941 | mac->rem_seq = 0; | |
24268cd0 | 1942 | |
b2998086 PR |
1943 | /* If all remote neighbors referencing a remote MAC |
1944 | * go away, we need to uninstall the MAC. | |
1945 | */ | |
1946 | if (remote_neigh_count(mac) == 0) { | |
f3722826 | 1947 | zebra_evpn_rem_mac_uninstall(zevpn, mac, false /*force*/); |
b2998086 PR |
1948 | zebra_evpn_es_mac_deref_entry(mac); |
1949 | UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE); | |
24268cd0 PR |
1950 | } |
1951 | ||
b2998086 PR |
1952 | if (list_isempty(mac->neigh_list)) |
1953 | zebra_evpn_mac_del(zevpn, mac); | |
1954 | else | |
1955 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
24268cd0 PR |
1956 | } |
1957 | ||
b2998086 PR |
1958 | /* Print Duplicate MAC */ |
1959 | void zebra_evpn_print_dad_mac_hash(struct hash_bucket *bucket, void *ctxt) | |
24268cd0 | 1960 | { |
3198b2b3 | 1961 | struct zebra_mac *mac; |
24268cd0 | 1962 | |
3198b2b3 | 1963 | mac = (struct zebra_mac *)bucket->data; |
b2998086 PR |
1964 | if (!mac) |
1965 | return; | |
24268cd0 | 1966 | |
b2998086 PR |
1967 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) |
1968 | zebra_evpn_print_mac_hash(bucket, ctxt); | |
24268cd0 PR |
1969 | } |
1970 | ||
b2998086 PR |
1971 | /* Print Duplicate MAC in detail */ |
1972 | void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket *bucket, | |
1973 | void *ctxt) | |
24268cd0 | 1974 | { |
3198b2b3 | 1975 | struct zebra_mac *mac; |
24268cd0 | 1976 | |
3198b2b3 | 1977 | mac = (struct zebra_mac *)bucket->data; |
b2998086 PR |
1978 | if (!mac) |
1979 | return; | |
24268cd0 | 1980 | |
b2998086 PR |
1981 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) |
1982 | zebra_evpn_print_mac_hash_detail(bucket, ctxt); | |
24268cd0 | 1983 | } |
19fdd1be | 1984 | |
f6371c34 DS |
1985 | int zebra_evpn_mac_remote_macip_add( |
1986 | struct zebra_evpn *zevpn, struct zebra_vrf *zvrf, | |
1987 | const struct ethaddr *macaddr, uint16_t ipa_len, | |
3198b2b3 DS |
1988 | const struct ipaddr *ipaddr, struct zebra_mac **macp, |
1989 | struct in_addr vtep_ip, uint8_t flags, uint32_t seq, const esi_t *esi) | |
19fdd1be | 1990 | { |
19fdd1be | 1991 | char buf1[INET6_ADDRSTRLEN]; |
19fdd1be PR |
1992 | bool sticky; |
1993 | bool remote_gw; | |
1994 | int update_mac = 0; | |
1995 | bool do_dad = false; | |
1996 | bool is_dup_detect = false; | |
1997 | esi_t *old_esi; | |
1998 | bool old_static = false; | |
3198b2b3 | 1999 | struct zebra_mac *mac; |
8e1337c5 AK |
2000 | bool old_es_present; |
2001 | bool new_es_present; | |
19fdd1be PR |
2002 | |
2003 | sticky = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY); | |
2004 | remote_gw = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW); | |
2005 | ||
2006 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
2007 | ||
2008 | /* Ignore if the mac is already present as a gateway mac */ | |
2009 | if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW) | |
2010 | && CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_GW)) { | |
2011 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2012 | zlog_debug( | |
ef7b8be4 DL |
2013 | "Ignore remote MACIP ADD VNI %u MAC %pEA%s%s as MAC is already configured as gateway MAC", |
2014 | zevpn->vni, macaddr, | |
19fdd1be PR |
2015 | ipa_len ? " IP " : "", |
2016 | ipa_len ? ipaddr2str(ipaddr, buf1, sizeof(buf1)) | |
2017 | : ""); | |
2018 | return -1; | |
2019 | } | |
2020 | ||
2021 | old_esi = (mac && mac->es) ? &mac->es->esi : zero_esi; | |
2022 | ||
2023 | /* check if the remote MAC is unknown or has a change. | |
2024 | * If so, that needs to be updated first. Note that client could | |
2025 | * install MAC and MACIP separately or just install the latter. | |
2026 | */ | |
2027 | if (!mac || !CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) | |
2028 | || sticky != !!CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY) | |
2029 | || remote_gw != !!CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW) | |
2030 | || !IPV4_ADDR_SAME(&mac->fwd_info.r_vtep_ip, &vtep_ip) | |
2031 | || memcmp(old_esi, esi, sizeof(esi_t)) || seq != mac->rem_seq) | |
2032 | update_mac = 1; | |
2033 | ||
2034 | if (update_mac) { | |
2035 | if (!mac) { | |
2036 | mac = zebra_evpn_mac_add(zevpn, macaddr); | |
19fdd1be PR |
2037 | zebra_evpn_es_mac_ref(mac, esi); |
2038 | ||
2039 | /* Is this MAC created for a MACIP? */ | |
2040 | if (ipa_len) | |
2041 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
2042 | } else { | |
19fdd1be PR |
2043 | /* When host moves but changes its (MAC,IP) |
2044 | * binding, BGP may install a MACIP entry that | |
2045 | * corresponds to "older" location of the host | |
2046 | * in transient situations (because {IP1,M1} | |
2047 | * is a different route from {IP1,M2}). Check | |
2048 | * the sequence number and ignore this update | |
2049 | * if appropriate. | |
2050 | */ | |
16de1338 AK |
2051 | if (!zebra_evpn_mac_is_bgp_seq_ok( |
2052 | zevpn, mac, seq, ipa_len, ipaddr, false)) | |
19fdd1be | 2053 | return -1; |
c1735c08 | 2054 | |
8e1337c5 | 2055 | old_es_present = !!mac->es; |
c1735c08 | 2056 | zebra_evpn_es_mac_ref(mac, esi); |
8e1337c5 AK |
2057 | new_es_present = !!mac->es; |
2058 | /* XXX - dataplane is curently not able to handle a MAC | |
2059 | * replace if the destination changes from L2-NHG to | |
2060 | * single VTEP and vice-versa. So delete the old entry | |
2061 | * and re-install | |
2062 | */ | |
2063 | if (old_es_present != new_es_present) | |
2064 | zebra_evpn_rem_mac_uninstall(zevpn, mac, false); | |
19fdd1be PR |
2065 | } |
2066 | ||
2067 | /* Check MAC's curent state is local (this is the case | |
2068 | * where MAC has moved from L->R) and check previous | |
2069 | * detection started via local learning. | |
2070 | * RFC-7432: A PE/VTEP that detects a MAC mobility | |
2071 | * event via local learning starts an M-second timer. | |
2072 | * | |
2073 | * VTEP-IP or seq. change alone is not considered | |
2074 | * for dup. detection. | |
2075 | * | |
2076 | * MAC is already marked duplicate set dad, then | |
2077 | * is_dup_detect will be set to not install the entry. | |
2078 | */ | |
2079 | if ((!CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) | |
2080 | && mac->dad_count) | |
2081 | || CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) | |
2082 | do_dad = true; | |
2083 | ||
2084 | /* Remove local MAC from BGP. */ | |
2085 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
2086 | /* force drop the sync flags */ | |
2087 | old_static = zebra_evpn_mac_is_static(mac); | |
b16e8004 DS |
2088 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
2089 | char mac_buf[MAC_BUF_SIZE]; | |
2090 | ||
19fdd1be | 2091 | zlog_debug( |
ef7b8be4 DL |
2092 | "sync-mac->remote vni %u mac %pEA es %s seq %d f %s", |
2093 | zevpn->vni, macaddr, | |
19fdd1be | 2094 | mac->es ? mac->es->esi_str : "-", |
b16e8004 DS |
2095 | mac->loc_seq, |
2096 | zebra_evpn_zebra_mac_flag_dump( | |
2097 | mac, mac_buf, sizeof(mac_buf))); | |
2098 | } | |
2099 | ||
19fdd1be PR |
2100 | zebra_evpn_mac_clear_sync_info(mac); |
2101 | zebra_evpn_mac_send_del_to_client(zevpn->vni, macaddr, | |
2102 | mac->flags, | |
2103 | false /* force */); | |
2104 | } | |
2105 | ||
2106 | /* Set "auto" and "remote" forwarding info. */ | |
8b07f173 | 2107 | zebra_evpn_mac_clear_fwd_info(mac); |
19fdd1be | 2108 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS); |
19fdd1be PR |
2109 | SET_FLAG(mac->flags, ZEBRA_MAC_REMOTE); |
2110 | mac->fwd_info.r_vtep_ip = vtep_ip; | |
2111 | ||
2112 | if (sticky) | |
2113 | SET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2114 | else | |
2115 | UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2116 | ||
2117 | if (remote_gw) | |
2118 | SET_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW); | |
2119 | else | |
2120 | UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE_DEF_GW); | |
2121 | ||
2122 | zebra_evpn_dup_addr_detect_for_mac( | |
2123 | zvrf, mac, mac->fwd_info.r_vtep_ip, do_dad, | |
2124 | &is_dup_detect, false); | |
2125 | ||
2126 | if (!is_dup_detect) { | |
2127 | zebra_evpn_process_neigh_on_remote_mac_add(zevpn, mac); | |
2128 | /* Install the entry. */ | |
2129 | zebra_evpn_rem_mac_install(zevpn, mac, old_static); | |
2130 | } | |
2131 | } | |
2132 | ||
2133 | /* Update seq number. */ | |
2134 | mac->rem_seq = seq; | |
2135 | ||
2136 | /* If there is no IP, return after clearing AUTO flag of MAC. */ | |
2137 | if (!ipa_len) { | |
2138 | UNSET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
2139 | return -1; | |
2140 | } | |
2141 | *macp = mac; | |
2142 | return 0; | |
2143 | } | |
d9d3455e | 2144 | |
f6371c34 DS |
2145 | int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf, |
2146 | struct zebra_evpn *zevpn, | |
d9d3455e | 2147 | struct interface *ifp, |
1a3bd37f | 2148 | const struct ethaddr *macaddr, vlanid_t vid, |
d9d3455e | 2149 | bool sticky, bool local_inactive, |
3198b2b3 | 2150 | bool dp_static, struct zebra_mac *mac) |
d9d3455e | 2151 | { |
d9d3455e PR |
2152 | bool mac_sticky = false; |
2153 | bool inform_client = false; | |
2154 | bool upd_neigh = false; | |
2155 | bool is_dup_detect = false; | |
2156 | struct in_addr vtep_ip = {.s_addr = 0}; | |
2157 | bool es_change = false; | |
2158 | bool new_bgp_ready; | |
2159 | /* assume inactive if not present or if not local */ | |
2160 | bool old_local_inactive = true; | |
2161 | bool old_bgp_ready = false; | |
2162 | bool inform_dataplane = false; | |
2163 | bool new_static = false; | |
2164 | ||
2bdd4461 | 2165 | assert(ifp); |
d9d3455e | 2166 | /* Check if we need to create or update or it is a NO-OP. */ |
00a7710c AK |
2167 | if (!mac) |
2168 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
d9d3455e PR |
2169 | if (!mac) { |
2170 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) | |
2171 | zlog_debug( | |
ef7b8be4 DL |
2172 | "ADD %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s", |
2173 | sticky ? "sticky " : "", macaddr, | |
d9d3455e PR |
2174 | ifp->name, ifp->ifindex, vid, zevpn->vni, |
2175 | local_inactive ? " local-inactive" : ""); | |
2176 | ||
2177 | mac = zebra_evpn_mac_add(zevpn, macaddr); | |
d9d3455e PR |
2178 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); |
2179 | es_change = zebra_evpn_local_mac_update_fwd_info(mac, ifp, vid); | |
2180 | if (sticky) | |
2181 | SET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2182 | inform_client = true; | |
2183 | } else { | |
b16e8004 DS |
2184 | if (IS_ZEBRA_DEBUG_VXLAN || IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
2185 | char mac_buf[MAC_BUF_SIZE]; | |
2186 | ||
d9d3455e | 2187 | zlog_debug( |
ef7b8be4 DL |
2188 | "UPD %sMAC %pEA intf %s(%u) VID %u -> VNI %u %scurFlags %s", |
2189 | sticky ? "sticky " : "", macaddr, | |
d9d3455e PR |
2190 | ifp->name, ifp->ifindex, vid, zevpn->vni, |
2191 | local_inactive ? "local-inactive " : "", | |
b16e8004 DS |
2192 | zebra_evpn_zebra_mac_flag_dump( |
2193 | mac, mac_buf, sizeof(mac_buf))); | |
2194 | } | |
d9d3455e PR |
2195 | |
2196 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)) { | |
2197 | struct interface *old_ifp; | |
2198 | vlanid_t old_vid; | |
2199 | bool old_static; | |
2200 | ||
2201 | zebra_evpn_mac_get_access_info(mac, &old_ifp, &old_vid); | |
2202 | old_bgp_ready = | |
2203 | zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
2204 | old_local_inactive = | |
2205 | !!(mac->flags & ZEBRA_MAC_LOCAL_INACTIVE); | |
2206 | old_static = zebra_evpn_mac_is_static(mac); | |
2207 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) | |
2208 | mac_sticky = true; | |
00a7710c AK |
2209 | es_change = zebra_evpn_local_mac_update_fwd_info( |
2210 | mac, ifp, vid); | |
d9d3455e PR |
2211 | |
2212 | /* | |
2213 | * Update any changes and if changes are relevant to | |
2214 | * BGP, note it. | |
2215 | */ | |
2216 | if (mac_sticky == sticky && old_ifp == ifp | |
2217 | && old_vid == vid | |
2218 | && old_local_inactive == local_inactive | |
00a7710c | 2219 | && dp_static == old_static && !es_change) { |
d9d3455e PR |
2220 | if (IS_ZEBRA_DEBUG_VXLAN) |
2221 | zlog_debug( | |
ef7b8be4 | 2222 | " Add/Update %sMAC %pEA intf %s(%u) VID %u -> VNI %u%s, " |
d9d3455e | 2223 | "entry exists and has not changed ", |
4e9a9863 | 2224 | sticky ? "sticky " : "", |
ef7b8be4 DL |
2225 | macaddr, ifp->name, |
2226 | ifp->ifindex, vid, zevpn->vni, | |
d9d3455e PR |
2227 | local_inactive |
2228 | ? " local_inactive" | |
2229 | : ""); | |
2230 | return 0; | |
2231 | } | |
2232 | if (mac_sticky != sticky) { | |
2233 | if (sticky) | |
2234 | SET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2235 | else | |
2236 | UNSET_FLAG(mac->flags, | |
2237 | ZEBRA_MAC_STICKY); | |
2238 | inform_client = true; | |
2239 | } | |
2240 | ||
d9d3455e PR |
2241 | /* If an es_change is detected we need to advertise |
2242 | * the route with a sequence that is one | |
2243 | * greater. This is need to indicate a mac-move | |
2244 | * to the ES peers | |
2245 | */ | |
2246 | if (es_change) { | |
00a7710c AK |
2247 | /* update the sequence number only if the entry |
2248 | * is locally active | |
2249 | */ | |
2250 | if (!local_inactive) | |
2251 | mac->loc_seq = mac->loc_seq + 1; | |
d9d3455e PR |
2252 | /* force drop the peer/sync info as it is |
2253 | * simply no longer relevant | |
2254 | */ | |
2255 | if (CHECK_FLAG(mac->flags, | |
2256 | ZEBRA_MAC_ALL_PEER_FLAGS)) { | |
2257 | zebra_evpn_mac_clear_sync_info(mac); | |
2258 | new_static = | |
2259 | zebra_evpn_mac_is_static(mac); | |
2260 | /* if we clear peer-flags we | |
2261 | * also need to notify the dataplane | |
2262 | * to drop the static flag | |
2263 | */ | |
2264 | if (old_static != new_static) | |
2265 | inform_dataplane = true; | |
2266 | } | |
2267 | } | |
2268 | } else if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE) | |
2269 | || CHECK_FLAG(mac->flags, ZEBRA_MAC_AUTO)) { | |
2270 | bool do_dad = false; | |
2271 | ||
2272 | /* | |
2273 | * MAC has either moved or was "internally" created due | |
2274 | * to a neighbor learn and is now actually learnt. If | |
2275 | * it was learnt as a remote sticky MAC, this is an | |
2276 | * operator error. | |
2277 | */ | |
2278 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_STICKY)) { | |
2279 | flog_warn( | |
2280 | EC_ZEBRA_STICKY_MAC_ALREADY_LEARNT, | |
ef7b8be4 DL |
2281 | "MAC %pEA already learnt as remote sticky MAC behind VTEP %pI4 VNI %u", |
2282 | macaddr, | |
9bcef951 | 2283 | &mac->fwd_info.r_vtep_ip, |
d9d3455e PR |
2284 | zevpn->vni); |
2285 | return 0; | |
2286 | } | |
2287 | ||
2288 | /* If an actual move, compute MAC's seq number */ | |
2289 | if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE)) { | |
2290 | mac->loc_seq = | |
2291 | MAX(mac->rem_seq + 1, mac->loc_seq); | |
2292 | vtep_ip = mac->fwd_info.r_vtep_ip; | |
2293 | /* Trigger DAD for remote MAC */ | |
2294 | do_dad = true; | |
2295 | } | |
2296 | ||
2297 | UNSET_FLAG(mac->flags, ZEBRA_MAC_REMOTE); | |
2298 | UNSET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
2299 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); | |
2300 | es_change = zebra_evpn_local_mac_update_fwd_info( | |
2301 | mac, ifp, vid); | |
2302 | if (sticky) | |
2303 | SET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2304 | else | |
2305 | UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2306 | /* | |
2307 | * We have to inform BGP of this MAC as well as process | |
2308 | * all neighbors. | |
2309 | */ | |
2310 | inform_client = true; | |
2311 | upd_neigh = true; | |
2312 | ||
2313 | zebra_evpn_dup_addr_detect_for_mac( | |
2314 | zvrf, mac, vtep_ip, do_dad, &is_dup_detect, | |
2315 | true); | |
2316 | if (is_dup_detect) { | |
2317 | inform_client = false; | |
2318 | upd_neigh = false; | |
839dfe29 | 2319 | es_change = false; |
d9d3455e PR |
2320 | } |
2321 | } | |
2322 | } | |
2323 | ||
2324 | /* if the dataplane thinks the entry is sync but it is | |
69711b3f AK |
2325 | * not sync in zebra (or vice-versa) we need to re-install |
2326 | * to fixup | |
d9d3455e | 2327 | */ |
69711b3f AK |
2328 | new_static = zebra_evpn_mac_is_static(mac); |
2329 | if (dp_static != new_static) | |
2330 | inform_dataplane = true; | |
d9d3455e PR |
2331 | |
2332 | if (local_inactive) | |
2333 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE); | |
2334 | else | |
2335 | UNSET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE); | |
2336 | ||
2337 | new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
2338 | /* if local-activity has changed we need update bgp | |
2339 | * even if bgp already knows about the mac | |
2340 | */ | |
2341 | if ((old_local_inactive != local_inactive) | |
2342 | || (new_bgp_ready != old_bgp_ready)) { | |
b16e8004 DS |
2343 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
2344 | char mac_buf[MAC_BUF_SIZE]; | |
2345 | ||
d9d3455e | 2346 | zlog_debug( |
ef7b8be4 DL |
2347 | "local mac vni %u mac %pEA es %s seq %d f %s%s", |
2348 | zevpn->vni, macaddr, | |
d9d3455e | 2349 | mac->es ? mac->es->esi_str : "", mac->loc_seq, |
b16e8004 DS |
2350 | zebra_evpn_zebra_mac_flag_dump(mac, mac_buf, |
2351 | sizeof(mac_buf)), | |
2352 | local_inactive ? "local-inactive" : ""); | |
2353 | } | |
2354 | ||
839dfe29 CS |
2355 | if (!is_dup_detect) |
2356 | inform_client = true; | |
d9d3455e PR |
2357 | } |
2358 | ||
2359 | if (es_change) { | |
2360 | inform_client = true; | |
2361 | upd_neigh = true; | |
2362 | } | |
2363 | ||
2364 | /* Inform dataplane if required. */ | |
2365 | if (inform_dataplane) | |
2366 | zebra_evpn_sync_mac_dp_install(mac, false /* set_inactive */, | |
2367 | false /* force_clear_static */, | |
2368 | __func__); | |
2369 | ||
2370 | /* Inform BGP if required. */ | |
2371 | if (inform_client) | |
2372 | zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, | |
2373 | new_bgp_ready); | |
2374 | ||
2375 | /* Process all neighbors associated with this MAC, if required. */ | |
2376 | if (upd_neigh) | |
2377 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, mac, 0, | |
2378 | es_change); | |
2379 | ||
2380 | return 0; | |
2381 | } | |
ad6ca5f4 | 2382 | |
3198b2b3 | 2383 | int zebra_evpn_del_local_mac(struct zebra_evpn *zevpn, struct zebra_mac *mac, |
00a7710c | 2384 | bool clear_static) |
ad6ca5f4 | 2385 | { |
ad6ca5f4 PR |
2386 | bool old_bgp_ready; |
2387 | bool new_bgp_ready; | |
b16e8004 | 2388 | |
46d6f5a2 | 2389 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
2390 | zlog_debug("DEL MAC %pEA VNI %u seq %u flags 0x%x nbr count %u", |
2391 | &mac->macaddr, zevpn->vni, mac->loc_seq, mac->flags, | |
46d6f5a2 | 2392 | listcount(mac->neigh_list)); |
ad6ca5f4 PR |
2393 | |
2394 | old_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
00a7710c | 2395 | if (!clear_static && zebra_evpn_mac_is_static(mac)) { |
ad6ca5f4 PR |
2396 | /* this is a synced entry and can only be removed when the |
2397 | * es-peers stop advertising it. | |
2398 | */ | |
8b07f173 | 2399 | zebra_evpn_mac_clear_fwd_info(mac); |
ad6ca5f4 | 2400 | |
b16e8004 DS |
2401 | if (IS_ZEBRA_DEBUG_EVPN_MH_MAC) { |
2402 | char mac_buf[MAC_BUF_SIZE]; | |
2403 | ||
ad6ca5f4 | 2404 | zlog_debug( |
ef7b8be4 DL |
2405 | "re-add sync-mac vni %u mac %pEA es %s seq %d f %s", |
2406 | zevpn->vni, &mac->macaddr, | |
ad6ca5f4 | 2407 | mac->es ? mac->es->esi_str : "-", mac->loc_seq, |
b16e8004 DS |
2408 | zebra_evpn_zebra_mac_flag_dump( |
2409 | mac, mac_buf, sizeof(mac_buf))); | |
2410 | } | |
ad6ca5f4 PR |
2411 | |
2412 | /* inform-bgp about change in local-activity if any */ | |
2413 | if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE)) { | |
2414 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL_INACTIVE); | |
2415 | new_bgp_ready = | |
2416 | zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
2417 | zebra_evpn_mac_send_add_del_to_client( | |
2418 | mac, old_bgp_ready, new_bgp_ready); | |
2419 | } | |
2420 | ||
1a4f9efd AK |
2421 | /* re-install the inactive entry in the kernel */ |
2422 | zebra_evpn_sync_mac_dp_install(mac, true /* set_inactive */, | |
ad6ca5f4 PR |
2423 | false /* force_clear_static */, |
2424 | __func__); | |
2425 | ||
2426 | return 0; | |
2427 | } | |
2428 | ||
00a7710c AK |
2429 | /* flush the peer info */ |
2430 | zebra_evpn_mac_clear_sync_info(mac); | |
2431 | ||
ad6ca5f4 PR |
2432 | /* Update all the neigh entries associated with this mac */ |
2433 | zebra_evpn_process_neigh_on_local_mac_del(zevpn, mac); | |
2434 | ||
2435 | /* Remove MAC from BGP. */ | |
46d6f5a2 | 2436 | zebra_evpn_mac_send_del_to_client(zevpn->vni, &mac->macaddr, mac->flags, |
ad6ca5f4 PR |
2437 | false /* force */); |
2438 | ||
2439 | zebra_evpn_es_mac_deref_entry(mac); | |
2440 | ||
8b07f173 AK |
2441 | /* remove links to the destination access port */ |
2442 | zebra_evpn_mac_clear_fwd_info(mac); | |
2443 | ||
ad6ca5f4 PR |
2444 | /* |
2445 | * If there are no neigh associated with the mac delete the mac | |
2446 | * else mark it as AUTO for forward reference | |
2447 | */ | |
2448 | if (!listcount(mac->neigh_list)) { | |
2449 | zebra_evpn_mac_del(zevpn, mac); | |
2450 | } else { | |
2451 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_LOCAL_FLAGS); | |
2452 | UNSET_FLAG(mac->flags, ZEBRA_MAC_STICKY); | |
2453 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
2454 | } | |
2455 | ||
2456 | return 0; | |
2457 | } | |
7bce3535 | 2458 | |
5ff58d0a | 2459 | void zebra_evpn_mac_gw_macip_add(struct interface *ifp, |
2460 | struct zebra_evpn *zevpn, | |
2461 | const struct ipaddr *ip, | |
2462 | struct zebra_mac **macp, | |
2463 | const struct ethaddr *macaddr, | |
2464 | vlanid_t vlan_id, bool def_gw) | |
7bce3535 | 2465 | { |
3198b2b3 | 2466 | struct zebra_mac *mac; |
47c58929 PG |
2467 | ns_id_t local_ns_id = NS_DEFAULT; |
2468 | struct zebra_vrf *zvrf; | |
2469 | ||
096f7609 | 2470 | zvrf = ifp->vrf->info; |
47c58929 PG |
2471 | if (zvrf && zvrf->zns) |
2472 | local_ns_id = zvrf->zns->ns_id; | |
7bce3535 | 2473 | |
b83d220a | 2474 | if (!*macp) { |
2475 | mac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
2476 | if (!mac) | |
2477 | mac = zebra_evpn_mac_add(zevpn, macaddr); | |
2478 | *macp = mac; | |
2479 | } else | |
2480 | mac = *macp; | |
7bce3535 PR |
2481 | |
2482 | /* Set "local" forwarding info. */ | |
8b07f173 | 2483 | zebra_evpn_mac_clear_fwd_info(mac); |
7bce3535 PR |
2484 | SET_FLAG(mac->flags, ZEBRA_MAC_LOCAL); |
2485 | SET_FLAG(mac->flags, ZEBRA_MAC_AUTO); | |
e4c3ece6 AK |
2486 | if (def_gw) |
2487 | SET_FLAG(mac->flags, ZEBRA_MAC_DEF_GW); | |
5ff58d0a | 2488 | else |
2489 | SET_FLAG(mac->flags, ZEBRA_MAC_SVI); | |
7bce3535 | 2490 | mac->fwd_info.local.ifindex = ifp->ifindex; |
47c58929 | 2491 | mac->fwd_info.local.ns_id = local_ns_id; |
7bce3535 | 2492 | mac->fwd_info.local.vid = vlan_id; |
7bce3535 | 2493 | } |
243b74ed | 2494 | |
f6371c34 | 2495 | void zebra_evpn_mac_svi_del(struct interface *ifp, struct zebra_evpn *zevpn) |
243b74ed | 2496 | { |
3198b2b3 | 2497 | struct zebra_mac *mac; |
243b74ed | 2498 | struct ethaddr macaddr; |
e4c3ece6 | 2499 | bool old_bgp_ready; |
243b74ed AK |
2500 | |
2501 | if (!zebra_evpn_mh_do_adv_svi_mac()) | |
2502 | return; | |
2503 | ||
2504 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
2505 | mac = zebra_evpn_mac_lookup(zevpn, &macaddr); | |
2506 | if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI)) { | |
2507 | if (IS_ZEBRA_DEBUG_EVPN_MH_ES) | |
2508 | zlog_debug("SVI %s mac free", ifp->name); | |
2509 | ||
e4c3ece6 | 2510 | old_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); |
243b74ed | 2511 | UNSET_FLAG(mac->flags, ZEBRA_MAC_SVI); |
e4c3ece6 AK |
2512 | zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, |
2513 | false); | |
243b74ed AK |
2514 | zebra_evpn_deref_ip2mac(mac->zevpn, mac); |
2515 | } | |
2516 | } | |
2517 | ||
f6371c34 | 2518 | void zebra_evpn_mac_svi_add(struct interface *ifp, struct zebra_evpn *zevpn) |
243b74ed | 2519 | { |
3198b2b3 | 2520 | struct zebra_mac *mac = NULL; |
243b74ed AK |
2521 | struct ethaddr macaddr; |
2522 | struct zebra_if *zif = ifp->info; | |
e4c3ece6 AK |
2523 | bool old_bgp_ready; |
2524 | bool new_bgp_ready; | |
243b74ed | 2525 | |
e4c3ece6 AK |
2526 | if (!zebra_evpn_mh_do_adv_svi_mac() |
2527 | || !zebra_evpn_send_to_client_ok(zevpn)) | |
243b74ed AK |
2528 | return; |
2529 | ||
2530 | memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN); | |
2531 | ||
2532 | /* dup check */ | |
2533 | mac = zebra_evpn_mac_lookup(zevpn, &macaddr); | |
2534 | if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI)) | |
2535 | return; | |
2536 | ||
2537 | /* add/update mac */ | |
2538 | if (IS_ZEBRA_DEBUG_EVPN_MH_ES) | |
2539 | zlog_debug("SVI %s mac add", zif->ifp->name); | |
2540 | ||
e4c3ece6 AK |
2541 | old_bgp_ready = (mac && zebra_evpn_mac_is_ready_for_bgp(mac->flags)) |
2542 | ? true | |
2543 | : false; | |
2544 | ||
e4c3ece6 | 2545 | zebra_evpn_mac_gw_macip_add(ifp, zevpn, NULL, &mac, &macaddr, 0, false); |
e4c3ece6 AK |
2546 | |
2547 | new_bgp_ready = zebra_evpn_mac_is_ready_for_bgp(mac->flags); | |
2548 | zebra_evpn_mac_send_add_del_to_client(mac, old_bgp_ready, | |
2549 | new_bgp_ready); | |
243b74ed | 2550 | } |