]>
Commit | Line | Data |
---|---|---|
6336e12b | 1 | /* |
7cbae20a | 2 | * Zebra EVPN Neighbor code |
6336e12b PR |
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" | |
7cbae20a | 26 | #include "interface.h" |
6336e12b | 27 | #include "jhash.h" |
6336e12b PR |
28 | #include "memory.h" |
29 | #include "prefix.h" | |
6336e12b | 30 | #include "vlan.h" |
7cbae20a | 31 | #include "json.h" |
6336e12b | 32 | |
7cbae20a | 33 | #include "zebra/zserv.h" |
6336e12b | 34 | #include "zebra/debug.h" |
7cbae20a | 35 | #include "zebra/zebra_router.h" |
6336e12b | 36 | #include "zebra/rt.h" |
7cbae20a | 37 | #include "zebra/zebra_errors.h" |
6336e12b | 38 | #include "zebra/zebra_vrf.h" |
6336e12b | 39 | #include "zebra/zebra_evpn.h" |
6336e12b | 40 | #include "zebra/zebra_evpn_mh.h" |
7cbae20a PR |
41 | #include "zebra/zebra_evpn_neigh.h" |
42 | #include "zebra/zebra_evpn_mac.h" | |
43 | ||
44 | DEFINE_MTYPE_STATIC(ZEBRA, NEIGH, "EVI Neighbor"); | |
6336e12b | 45 | |
7cbae20a PR |
46 | /* |
47 | * Make hash key for neighbors. | |
48 | */ | |
49 | static unsigned int neigh_hash_keymake(const void *p) | |
6336e12b | 50 | { |
72de4110 | 51 | const struct zebra_neigh *n = p; |
7cbae20a | 52 | const struct ipaddr *ip = &n->ip; |
6336e12b | 53 | |
7cbae20a PR |
54 | if (IS_IPADDR_V4(ip)) |
55 | return jhash_1word(ip->ipaddr_v4.s_addr, 0); | |
6336e12b | 56 | |
7cbae20a PR |
57 | return jhash2(ip->ipaddr_v6.s6_addr32, |
58 | array_size(ip->ipaddr_v6.s6_addr32), 0); | |
59 | } | |
6336e12b | 60 | |
7cbae20a PR |
61 | /* |
62 | * Compare two neighbor hash structures. | |
63 | */ | |
64 | static bool neigh_cmp(const void *p1, const void *p2) | |
65 | { | |
72de4110 DS |
66 | const struct zebra_neigh *n1 = p1; |
67 | const struct zebra_neigh *n2 = p2; | |
6336e12b | 68 | |
7cbae20a PR |
69 | if (n1 == NULL && n2 == NULL) |
70 | return true; | |
6336e12b | 71 | |
7cbae20a PR |
72 | if (n1 == NULL || n2 == NULL) |
73 | return false; | |
6336e12b | 74 | |
60cda04d | 75 | return ipaddr_cmp(&n1->ip, &n2->ip) == 0; |
6336e12b | 76 | } |
6336e12b | 77 | |
7cbae20a | 78 | int neigh_list_cmp(void *p1, void *p2) |
6336e12b | 79 | { |
72de4110 DS |
80 | const struct zebra_neigh *n1 = p1; |
81 | const struct zebra_neigh *n2 = p2; | |
6336e12b | 82 | |
60cda04d | 83 | return ipaddr_cmp(&n1->ip, &n2->ip); |
7cbae20a | 84 | } |
6336e12b | 85 | |
7cbae20a PR |
86 | struct hash *zebra_neigh_db_create(const char *desc) |
87 | { | |
da55bcbc | 88 | return hash_create_size(8, neigh_hash_keymake, neigh_cmp, desc); |
6336e12b PR |
89 | } |
90 | ||
f6371c34 | 91 | uint32_t num_dup_detected_neighs(struct zebra_evpn *zevpn) |
6336e12b PR |
92 | { |
93 | unsigned int i; | |
94 | uint32_t num_neighs = 0; | |
95 | struct hash *hash; | |
96 | struct hash_bucket *hb; | |
72de4110 | 97 | struct zebra_neigh *nbr; |
6336e12b PR |
98 | |
99 | hash = zevpn->neigh_table; | |
100 | if (!hash) | |
101 | return num_neighs; | |
102 | for (i = 0; i < hash->size; i++) { | |
103 | for (hb = hash->index[i]; hb; hb = hb->next) { | |
72de4110 | 104 | nbr = (struct zebra_neigh *)hb->data; |
6336e12b PR |
105 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
106 | num_neighs++; | |
107 | } | |
108 | } | |
109 | ||
110 | return num_neighs; | |
111 | } | |
112 | ||
7cbae20a PR |
113 | /* |
114 | * Helper function to determine maximum width of neighbor IP address for | |
115 | * display - just because we're dealing with IPv6 addresses that can | |
116 | * widely vary. | |
117 | */ | |
118 | void zebra_evpn_find_neigh_addr_width(struct hash_bucket *bucket, void *ctxt) | |
6336e12b | 119 | { |
72de4110 | 120 | struct zebra_neigh *n; |
7cbae20a PR |
121 | char buf[INET6_ADDRSTRLEN]; |
122 | struct neigh_walk_ctx *wctx = ctxt; | |
123 | int width; | |
6336e12b | 124 | |
72de4110 | 125 | n = (struct zebra_neigh *)bucket->data; |
6336e12b | 126 | |
7cbae20a PR |
127 | ipaddr2str(&n->ip, buf, sizeof(buf)); |
128 | width = strlen(buf); | |
129 | if (width > wctx->addr_width) | |
130 | wctx->addr_width = width; | |
131 | } | |
6336e12b | 132 | |
7cbae20a PR |
133 | /* |
134 | * Count of remote neighbors referencing this MAC. | |
135 | */ | |
3198b2b3 | 136 | int remote_neigh_count(struct zebra_mac *zmac) |
7cbae20a | 137 | { |
72de4110 | 138 | struct zebra_neigh *n = NULL; |
7cbae20a PR |
139 | struct listnode *node = NULL; |
140 | int count = 0; | |
141 | ||
142 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
143 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) | |
144 | count++; | |
145 | } | |
146 | ||
147 | return count; | |
6336e12b PR |
148 | } |
149 | ||
7cbae20a PR |
150 | /* |
151 | * Install remote neighbor into the kernel. | |
152 | */ | |
72de4110 DS |
153 | int zebra_evpn_rem_neigh_install(struct zebra_evpn *zevpn, |
154 | struct zebra_neigh *n, bool was_static) | |
6336e12b | 155 | { |
7cbae20a PR |
156 | struct interface *vlan_if; |
157 | int flags; | |
158 | int ret = 0; | |
6336e12b | 159 | |
7cbae20a PR |
160 | if (!(n->flags & ZEBRA_NEIGH_REMOTE)) |
161 | return 0; | |
6336e12b | 162 | |
7cbae20a PR |
163 | vlan_if = zevpn_map_to_svi(zevpn); |
164 | if (!vlan_if) | |
165 | return -1; | |
6336e12b | 166 | |
7cbae20a PR |
167 | flags = DPLANE_NTF_EXT_LEARNED; |
168 | if (n->flags & ZEBRA_NEIGH_ROUTER_FLAG) | |
169 | flags |= DPLANE_NTF_ROUTER; | |
170 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
171 | ||
172 | dplane_rem_neigh_add(vlan_if, &n->ip, &n->emac, flags, was_static); | |
173 | ||
174 | return ret; | |
6336e12b PR |
175 | } |
176 | ||
7cbae20a PR |
177 | /* |
178 | * Install neighbor hash entry - called upon access VLAN change. | |
6336e12b | 179 | */ |
7cbae20a | 180 | void zebra_evpn_install_neigh_hash(struct hash_bucket *bucket, void *ctxt) |
6336e12b | 181 | { |
72de4110 | 182 | struct zebra_neigh *n; |
7cbae20a | 183 | struct neigh_walk_ctx *wctx = ctxt; |
6336e12b | 184 | |
72de4110 | 185 | n = (struct zebra_neigh *)bucket->data; |
6336e12b | 186 | |
7cbae20a PR |
187 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) |
188 | zebra_evpn_rem_neigh_install(wctx->zevpn, n, | |
189 | false /*was_static*/); | |
6336e12b PR |
190 | } |
191 | ||
7cbae20a PR |
192 | /* |
193 | * Callback to allocate neighbor hash entry. | |
194 | */ | |
195 | static void *zebra_evpn_neigh_alloc(void *p) | |
6336e12b | 196 | { |
72de4110 DS |
197 | const struct zebra_neigh *tmp_n = p; |
198 | struct zebra_neigh *n; | |
6336e12b | 199 | |
72de4110 | 200 | n = XCALLOC(MTYPE_NEIGH, sizeof(struct zebra_neigh)); |
7cbae20a | 201 | *n = *tmp_n; |
6336e12b | 202 | |
7cbae20a PR |
203 | return ((void *)n); |
204 | } | |
205 | ||
72de4110 | 206 | static void zebra_evpn_local_neigh_ref_mac(struct zebra_neigh *n, |
1a3bd37f | 207 | const struct ethaddr *macaddr, |
3198b2b3 | 208 | struct zebra_mac *mac, |
7cbae20a PR |
209 | bool send_mac_update) |
210 | { | |
7cbae20a PR |
211 | bool old_static; |
212 | bool new_static; | |
213 | ||
214 | memcpy(&n->emac, macaddr, ETH_ALEN); | |
215 | n->mac = mac; | |
216 | ||
217 | /* Link to new MAC */ | |
218 | if (!mac) | |
6336e12b PR |
219 | return; |
220 | ||
7cbae20a PR |
221 | listnode_add_sort(mac->neigh_list, n); |
222 | if (n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) { | |
223 | old_static = zebra_evpn_mac_is_static(mac); | |
224 | ++mac->sync_neigh_cnt; | |
225 | new_static = zebra_evpn_mac_is_static(mac); | |
226 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
6336e12b | 227 | zlog_debug( |
ef7b8be4 DL |
228 | "sync-neigh ref mac vni %u ip %pIA mac %pEA ref %d", |
229 | n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a PR |
230 | mac->sync_neigh_cnt); |
231 | if ((old_static != new_static) && send_mac_update) | |
232 | /* program the local mac in the kernel */ | |
233 | zebra_evpn_sync_mac_dp_install( | |
234 | mac, false /*set_inactive*/, | |
235 | false /*force_clear_static*/, __func__); | |
236 | } | |
237 | } | |
6336e12b | 238 | |
7cbae20a | 239 | /* sync-path that is active on an ES peer */ |
72de4110 | 240 | static void zebra_evpn_sync_neigh_dp_install(struct zebra_neigh *n, |
33064a62 PR |
241 | bool set_inactive, |
242 | bool force_clear_static, | |
243 | const char *caller) | |
7cbae20a | 244 | { |
7cbae20a PR |
245 | struct zebra_ns *zns; |
246 | struct interface *ifp; | |
247 | bool set_static; | |
248 | bool set_router; | |
6336e12b | 249 | |
7cbae20a PR |
250 | zns = zebra_ns_lookup(NS_DEFAULT); |
251 | ifp = if_lookup_by_index_per_ns(zns, n->ifindex); | |
252 | if (!ifp) { | |
253 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
254 | zlog_debug( | |
ef7b8be4 DL |
255 | "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %d f 0x%x skipped", |
256 | caller, n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a | 257 | n->ifindex, n->flags); |
6336e12b PR |
258 | return; |
259 | } | |
260 | ||
7cbae20a PR |
261 | if (force_clear_static) |
262 | set_static = false; | |
263 | else | |
264 | set_static = zebra_evpn_neigh_is_static(n); | |
6336e12b | 265 | |
7cbae20a | 266 | set_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); |
6336e12b | 267 | |
7cbae20a PR |
268 | /* XXX - this will change post integration with the new kernel */ |
269 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) | |
270 | set_inactive = true; | |
6336e12b | 271 | |
7cbae20a | 272 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
6336e12b | 273 | zlog_debug( |
ef7b8be4 DL |
274 | "%s: dp-install sync-neigh vni %u ip %pIA mac %pEA if %s(%d) f 0x%x%s%s%s", |
275 | caller, n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a PR |
276 | ifp->name, n->ifindex, n->flags, |
277 | set_router ? " router" : "", | |
278 | set_static ? " static" : "", | |
279 | set_inactive ? " inactive" : ""); | |
280 | dplane_local_neigh_add(ifp, &n->ip, &n->emac, set_router, set_static, | |
281 | set_inactive); | |
6336e12b PR |
282 | } |
283 | ||
284 | /* | |
7cbae20a | 285 | * Inform BGP about local neighbor addition. |
6336e12b | 286 | */ |
1a3bd37f MS |
287 | int zebra_evpn_neigh_send_add_to_client(vni_t vni, const struct ipaddr *ip, |
288 | const struct ethaddr *macaddr, | |
3198b2b3 DS |
289 | struct zebra_mac *zmac, |
290 | uint32_t neigh_flags, uint32_t seq) | |
6336e12b | 291 | { |
7cbae20a | 292 | uint8_t flags = 0; |
6336e12b | 293 | |
7cbae20a PR |
294 | if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) { |
295 | /* host reachability has not been verified locally */ | |
6336e12b | 296 | |
7cbae20a PR |
297 | /* if no ES peer is claiming reachability we can't advertise |
298 | * the entry | |
299 | */ | |
300 | if (!CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
301 | return 0; | |
6336e12b | 302 | |
7cbae20a PR |
303 | /* ES peers are claiming reachability; we will |
304 | * advertise the entry but with a proxy flag | |
305 | */ | |
306 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT); | |
6336e12b PR |
307 | } |
308 | ||
7cbae20a PR |
309 | if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_DEF_GW)) |
310 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_GW); | |
311 | /* Set router flag (R-bit) based on local neigh entry add */ | |
312 | if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_ROUTER_FLAG)) | |
313 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); | |
314 | if (CHECK_FLAG(neigh_flags, ZEBRA_NEIGH_SVI_IP)) | |
315 | SET_FLAG(flags, ZEBRA_MACIP_TYPE_SVI_IP); | |
6336e12b | 316 | |
00a7710c AK |
317 | return zebra_evpn_macip_send_msg_to_client(vni, macaddr, ip, flags, seq, |
318 | ZEBRA_NEIGH_ACTIVE, zmac->es, | |
319 | ZEBRA_MACIP_ADD); | |
6336e12b PR |
320 | } |
321 | ||
322 | /* | |
7cbae20a | 323 | * Inform BGP about local neighbor deletion. |
6336e12b | 324 | */ |
7cbae20a PR |
325 | int zebra_evpn_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip, |
326 | struct ethaddr *macaddr, uint32_t flags, | |
327 | int state, bool force) | |
6336e12b | 328 | { |
7cbae20a PR |
329 | if (!force) { |
330 | if (CHECK_FLAG(flags, ZEBRA_NEIGH_LOCAL_INACTIVE) | |
331 | && !CHECK_FLAG(flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
332 | /* the neigh was not advertised - nothing to delete */ | |
333 | return 0; | |
6336e12b PR |
334 | } |
335 | ||
7cbae20a PR |
336 | return zebra_evpn_macip_send_msg_to_client( |
337 | vni, macaddr, ip, flags, 0, state, NULL, ZEBRA_MACIP_DEL); | |
6336e12b PR |
338 | } |
339 | ||
72de4110 | 340 | static void zebra_evpn_neigh_send_add_del_to_client(struct zebra_neigh *n, |
33064a62 PR |
341 | bool old_bgp_ready, |
342 | bool new_bgp_ready) | |
6336e12b | 343 | { |
7cbae20a PR |
344 | if (new_bgp_ready) |
345 | zebra_evpn_neigh_send_add_to_client(n->zevpn->vni, &n->ip, | |
346 | &n->emac, n->mac, n->flags, | |
347 | n->loc_seq); | |
348 | else if (old_bgp_ready) | |
349 | zebra_evpn_neigh_send_del_to_client(n->zevpn->vni, &n->ip, | |
350 | &n->emac, n->flags, | |
351 | n->state, true /*force*/); | |
6336e12b PR |
352 | } |
353 | ||
7cbae20a PR |
354 | /* if the static flag associated with the neigh changes we need |
355 | * to update the sync-neigh references against the MAC | |
356 | * and inform the dataplane about the static flag changes. | |
6336e12b | 357 | */ |
72de4110 | 358 | void zebra_evpn_sync_neigh_static_chg(struct zebra_neigh *n, bool old_n_static, |
7cbae20a PR |
359 | bool new_n_static, bool defer_n_dp, |
360 | bool defer_mac_dp, const char *caller) | |
6336e12b | 361 | { |
3198b2b3 | 362 | struct zebra_mac *mac = n->mac; |
7cbae20a PR |
363 | bool old_mac_static; |
364 | bool new_mac_static; | |
6336e12b | 365 | |
7cbae20a PR |
366 | if (old_n_static == new_n_static) |
367 | return; | |
6336e12b | 368 | |
7cbae20a PR |
369 | /* update the neigh sync references in the dataplane. if |
370 | * the neigh is in the middle of updates the caller can | |
371 | * request for a defer | |
372 | */ | |
373 | if (!defer_n_dp) | |
374 | zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */, | |
375 | false /* force_clear_static */, | |
376 | __func__); | |
6336e12b | 377 | |
7cbae20a PR |
378 | if (!mac) |
379 | return; | |
6336e12b | 380 | |
7cbae20a PR |
381 | /* update the mac sync ref cnt */ |
382 | old_mac_static = zebra_evpn_mac_is_static(mac); | |
383 | if (new_n_static) { | |
384 | ++mac->sync_neigh_cnt; | |
385 | } else if (old_n_static) { | |
386 | if (mac->sync_neigh_cnt) | |
387 | --mac->sync_neigh_cnt; | |
6336e12b | 388 | } |
7cbae20a | 389 | new_mac_static = zebra_evpn_mac_is_static(mac); |
6336e12b | 390 | |
7cbae20a PR |
391 | /* update the mac sync references in the dataplane */ |
392 | if ((old_mac_static != new_mac_static) && !defer_mac_dp) | |
393 | zebra_evpn_sync_mac_dp_install(mac, false /* set_inactive */, | |
394 | false /* force_clear_static */, | |
395 | __func__); | |
6336e12b | 396 | |
7cbae20a PR |
397 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
398 | zlog_debug( | |
ef7b8be4 DL |
399 | "sync-neigh ref-chg vni %u ip %pIA mac %pEA f 0x%x %d%s%s%s%s by %s", |
400 | n->zevpn->vni, &n->ip, &n->emac, n->flags, | |
401 | mac->sync_neigh_cnt, | |
7cbae20a PR |
402 | old_n_static ? " old_n_static" : "", |
403 | new_n_static ? " new_n_static" : "", | |
404 | old_mac_static ? " old_mac_static" : "", | |
405 | new_mac_static ? " new_mac_static" : "", caller); | |
6336e12b PR |
406 | } |
407 | ||
7cbae20a PR |
408 | /* Neigh hold timer is used to age out peer-active flag. |
409 | * | |
410 | * During this wait time we expect the dataplane component or an | |
411 | * external neighmgr daemon to probe existing hosts to independently | |
412 | * establish their presence on the ES. | |
6336e12b | 413 | */ |
cc9f21da | 414 | static void zebra_evpn_neigh_hold_exp_cb(struct thread *t) |
6336e12b | 415 | { |
72de4110 | 416 | struct zebra_neigh *n; |
7cbae20a PR |
417 | bool old_bgp_ready; |
418 | bool new_bgp_ready; | |
419 | bool old_n_static; | |
420 | bool new_n_static; | |
7cbae20a PR |
421 | |
422 | n = THREAD_ARG(t); | |
423 | /* the purpose of the hold timer is to age out the peer-active | |
424 | * flag | |
425 | */ | |
426 | if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
cc9f21da | 427 | return; |
6336e12b | 428 | |
7cbae20a PR |
429 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); |
430 | old_n_static = zebra_evpn_neigh_is_static(n); | |
431 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
432 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
433 | new_n_static = zebra_evpn_neigh_is_static(n); | |
6336e12b | 434 | |
7cbae20a | 435 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
ef7b8be4 DL |
436 | zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold expired", |
437 | n->zevpn->vni, &n->ip, &n->emac, n->flags); | |
6336e12b | 438 | |
7cbae20a PR |
439 | /* re-program the local neigh in the dataplane if the neigh is no |
440 | * longer static | |
441 | */ | |
442 | if (old_n_static != new_n_static) | |
443 | zebra_evpn_sync_neigh_static_chg( | |
444 | n, old_n_static, new_n_static, false /*defer_n_dp*/, | |
445 | false /*defer_mac_dp*/, __func__); | |
6336e12b | 446 | |
7cbae20a PR |
447 | /* inform bgp if needed */ |
448 | if (old_bgp_ready != new_bgp_ready) | |
449 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
450 | new_bgp_ready); | |
6336e12b PR |
451 | } |
452 | ||
72de4110 | 453 | static inline void zebra_evpn_neigh_start_hold_timer(struct zebra_neigh *n) |
6336e12b | 454 | { |
7cbae20a PR |
455 | if (n->hold_timer) |
456 | return; | |
6336e12b | 457 | |
7cbae20a | 458 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
ef7b8be4 DL |
459 | zlog_debug("sync-neigh vni %u ip %pIA mac %pEA 0x%x hold start", |
460 | n->zevpn->vni, &n->ip, &n->emac, n->flags); | |
7cbae20a PR |
461 | thread_add_timer(zrouter.master, zebra_evpn_neigh_hold_exp_cb, n, |
462 | zmh_info->neigh_hold_time, &n->hold_timer); | |
463 | } | |
6336e12b | 464 | |
72de4110 | 465 | static void zebra_evpn_local_neigh_deref_mac(struct zebra_neigh *n, |
7cbae20a PR |
466 | bool send_mac_update) |
467 | { | |
3198b2b3 | 468 | struct zebra_mac *mac = n->mac; |
f6371c34 | 469 | struct zebra_evpn *zevpn = n->zevpn; |
7cbae20a PR |
470 | bool old_static; |
471 | bool new_static; | |
6336e12b | 472 | |
7cbae20a PR |
473 | n->mac = NULL; |
474 | if (!mac) | |
475 | return; | |
6336e12b | 476 | |
7cbae20a PR |
477 | if ((n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) && mac->sync_neigh_cnt) { |
478 | old_static = zebra_evpn_mac_is_static(mac); | |
479 | --mac->sync_neigh_cnt; | |
480 | new_static = zebra_evpn_mac_is_static(mac); | |
481 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
6336e12b | 482 | zlog_debug( |
ef7b8be4 DL |
483 | "sync-neigh deref mac vni %u ip %pIA mac %pEA ref %d", |
484 | n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a PR |
485 | mac->sync_neigh_cnt); |
486 | if ((old_static != new_static) && send_mac_update) | |
487 | /* program the local mac in the kernel */ | |
488 | zebra_evpn_sync_mac_dp_install( | |
489 | mac, false /* set_inactive */, | |
490 | false /* force_clear_static */, __func__); | |
6336e12b PR |
491 | } |
492 | ||
7cbae20a PR |
493 | listnode_delete(mac->neigh_list, n); |
494 | zebra_evpn_deref_ip2mac(zevpn, mac); | |
6336e12b PR |
495 | } |
496 | ||
72de4110 DS |
497 | bool zebra_evpn_neigh_is_bgp_seq_ok(struct zebra_evpn *zevpn, |
498 | struct zebra_neigh *n, | |
1a3bd37f | 499 | const struct ethaddr *macaddr, uint32_t seq, |
16de1338 | 500 | bool sync) |
6336e12b | 501 | { |
7cbae20a | 502 | uint32_t tmp_seq; |
16de1338 | 503 | const char *n_type; |
6336e12b | 504 | |
16de1338 | 505 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { |
7cbae20a | 506 | tmp_seq = n->loc_seq; |
16de1338 AK |
507 | n_type = "local"; |
508 | } else { | |
7cbae20a | 509 | tmp_seq = n->rem_seq; |
16de1338 AK |
510 | n_type = "remote"; |
511 | } | |
6336e12b | 512 | |
7cbae20a PR |
513 | if (seq < tmp_seq) { |
514 | /* if the neigh was never advertised to bgp we must accept | |
515 | * whatever sequence number bgp sends | |
516 | * XXX - check with Vivek | |
517 | */ | |
518 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) | |
519 | && !zebra_evpn_neigh_is_ready_for_bgp(n)) { | |
16de1338 AK |
520 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH |
521 | || IS_ZEBRA_DEBUG_VXLAN) | |
7cbae20a | 522 | zlog_debug( |
ef7b8be4 | 523 | "%s-macip accept vni %u %s mac %pEA IP %pIA lower seq %u f 0x%x", |
16de1338 | 524 | sync ? "sync" : "remote", zevpn->vni, |
ef7b8be4 | 525 | n_type, macaddr, &n->ip, |
7cbae20a PR |
526 | tmp_seq, n->flags); |
527 | return true; | |
528 | } | |
6336e12b | 529 | |
16de1338 | 530 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH || IS_ZEBRA_DEBUG_VXLAN) |
7cbae20a | 531 | zlog_debug( |
ef7b8be4 | 532 | "%s-macip ignore vni %u %s mac %pEA IP %pIA as existing has higher seq %u f 0x%x", |
16de1338 | 533 | sync ? "sync" : "remote", zevpn->vni, n_type, |
ef7b8be4 | 534 | macaddr, &n->ip, tmp_seq, n->flags); |
7cbae20a | 535 | return false; |
6336e12b | 536 | } |
7cbae20a PR |
537 | |
538 | return true; | |
6336e12b PR |
539 | } |
540 | ||
541 | /* | |
7cbae20a | 542 | * Add neighbor entry. |
6336e12b | 543 | */ |
72de4110 DS |
544 | static struct zebra_neigh *zebra_evpn_neigh_add(struct zebra_evpn *zevpn, |
545 | const struct ipaddr *ip, | |
546 | const struct ethaddr *mac, | |
547 | struct zebra_mac *zmac, | |
548 | uint32_t n_flags) | |
6336e12b | 549 | { |
72de4110 DS |
550 | struct zebra_neigh tmp_n; |
551 | struct zebra_neigh *n = NULL; | |
6336e12b | 552 | |
72de4110 | 553 | memset(&tmp_n, 0, sizeof(struct zebra_neigh)); |
7cbae20a PR |
554 | memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr)); |
555 | n = hash_get(zevpn->neigh_table, &tmp_n, zebra_evpn_neigh_alloc); | |
556 | assert(n); | |
6336e12b | 557 | |
7cbae20a PR |
558 | n->state = ZEBRA_NEIGH_INACTIVE; |
559 | n->zevpn = zevpn; | |
560 | n->dad_ip_auto_recovery_timer = NULL; | |
561 | n->flags = n_flags; | |
a05111ba | 562 | n->uptime = monotime(NULL); |
6336e12b | 563 | |
7cbae20a PR |
564 | if (!zmac) |
565 | zmac = zebra_evpn_mac_lookup(zevpn, mac); | |
566 | zebra_evpn_local_neigh_ref_mac(n, mac, zmac, | |
567 | false /* send_mac_update */); | |
6336e12b | 568 | |
7cbae20a | 569 | return n; |
6336e12b PR |
570 | } |
571 | ||
572 | /* | |
7cbae20a | 573 | * Delete neighbor entry. |
6336e12b | 574 | */ |
72de4110 | 575 | int zebra_evpn_neigh_del(struct zebra_evpn *zevpn, struct zebra_neigh *n) |
6336e12b | 576 | { |
72de4110 | 577 | struct zebra_neigh *tmp_n; |
6336e12b | 578 | |
7cbae20a PR |
579 | if (n->mac) |
580 | listnode_delete(n->mac->neigh_list, n); | |
6336e12b | 581 | |
7cbae20a PR |
582 | /* Cancel auto recovery */ |
583 | THREAD_OFF(n->dad_ip_auto_recovery_timer); | |
6336e12b | 584 | |
2b9e207e AK |
585 | /* Cancel proxy hold timer */ |
586 | zebra_evpn_neigh_stop_hold_timer(n); | |
587 | ||
7cbae20a PR |
588 | /* Free the VNI hash entry and allocated memory. */ |
589 | tmp_n = hash_release(zevpn->neigh_table, n); | |
590 | XFREE(MTYPE_NEIGH, tmp_n); | |
6336e12b PR |
591 | |
592 | return 0; | |
593 | } | |
594 | ||
72de4110 | 595 | void zebra_evpn_sync_neigh_del(struct zebra_neigh *n) |
6336e12b | 596 | { |
7cbae20a PR |
597 | bool old_n_static; |
598 | bool new_n_static; | |
6336e12b | 599 | |
7cbae20a | 600 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
ef7b8be4 DL |
601 | zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x", |
602 | n->zevpn->vni, &n->ip, &n->emac, n->flags); | |
6336e12b | 603 | |
7cbae20a PR |
604 | old_n_static = zebra_evpn_neigh_is_static(n); |
605 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
606 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
607 | zebra_evpn_neigh_start_hold_timer(n); | |
608 | new_n_static = zebra_evpn_neigh_is_static(n); | |
6336e12b | 609 | |
7cbae20a PR |
610 | if (old_n_static != new_n_static) |
611 | zebra_evpn_sync_neigh_static_chg( | |
612 | n, old_n_static, new_n_static, false /*defer-dp*/, | |
613 | false /*defer_mac_dp*/, __func__); | |
614 | } | |
6336e12b | 615 | |
72de4110 DS |
616 | struct zebra_neigh *zebra_evpn_proc_sync_neigh_update( |
617 | struct zebra_evpn *zevpn, struct zebra_neigh *n, uint16_t ipa_len, | |
618 | const struct ipaddr *ipaddr, uint8_t flags, uint32_t seq, | |
619 | const esi_t *esi, struct sync_mac_ip_ctx *ctx) | |
7cbae20a PR |
620 | { |
621 | struct interface *ifp = NULL; | |
622 | bool is_router; | |
3198b2b3 | 623 | struct zebra_mac *mac = ctx->mac; |
7cbae20a PR |
624 | uint32_t tmp_seq; |
625 | bool old_router = false; | |
626 | bool old_bgp_ready = false; | |
627 | bool new_bgp_ready; | |
628 | bool inform_dataplane = false; | |
629 | bool inform_bgp = false; | |
630 | bool old_mac_static; | |
631 | bool new_mac_static; | |
632 | bool set_dp_inactive = false; | |
7cbae20a PR |
633 | bool created; |
634 | ifindex_t ifindex = 0; | |
6336e12b | 635 | |
7cbae20a PR |
636 | /* locate l3-svi */ |
637 | ifp = zevpn_map_to_svi(zevpn); | |
638 | if (ifp) | |
639 | ifindex = ifp->ifindex; | |
6336e12b | 640 | |
7cbae20a PR |
641 | is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); |
642 | old_mac_static = zebra_evpn_mac_is_static(mac); | |
6336e12b | 643 | |
7cbae20a PR |
644 | if (!n) { |
645 | uint32_t n_flags = 0; | |
6336e12b | 646 | |
7cbae20a PR |
647 | /* New neighbor - create */ |
648 | SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL); | |
649 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) | |
650 | SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
651 | else | |
652 | SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
653 | SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
6336e12b | 654 | |
7cbae20a PR |
655 | n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, mac, |
656 | n_flags); | |
657 | n->ifindex = ifindex; | |
658 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
6336e12b | 659 | |
7cbae20a PR |
660 | created = true; |
661 | inform_dataplane = true; | |
662 | inform_bgp = true; | |
663 | set_dp_inactive = true; | |
664 | } else { | |
665 | bool mac_change; | |
666 | uint32_t old_flags = n->flags; | |
667 | bool old_n_static; | |
668 | bool new_n_static; | |
6336e12b | 669 | |
7cbae20a PR |
670 | created = false; |
671 | old_n_static = zebra_evpn_neigh_is_static(n); | |
672 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
673 | old_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 674 | |
7cbae20a PR |
675 | mac_change = !!memcmp(&n->emac, &mac->macaddr, ETH_ALEN); |
676 | ||
677 | /* deref and clear old info */ | |
678 | if (mac_change) { | |
679 | if (old_bgp_ready) { | |
680 | zebra_evpn_neigh_send_del_to_client( | |
681 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
682 | n->state, false /*force*/); | |
683 | old_bgp_ready = false; | |
6336e12b | 684 | } |
bc3cd39b DS |
685 | zebra_evpn_local_neigh_deref_mac(n, |
686 | false /*send_mac_update*/); | |
6336e12b | 687 | } |
7cbae20a PR |
688 | /* clear old fwd info */ |
689 | n->rem_seq = 0; | |
690 | n->r_vtep_ip.s_addr = 0; | |
6336e12b | 691 | |
7cbae20a PR |
692 | /* setup new flags */ |
693 | n->flags = 0; | |
694 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
695 | /* retain activity flag if the neigh was | |
696 | * previously local | |
6336e12b | 697 | */ |
7cbae20a PR |
698 | if (old_flags & ZEBRA_NEIGH_LOCAL) { |
699 | n->flags |= (old_flags & ZEBRA_NEIGH_LOCAL_INACTIVE); | |
700 | } else { | |
701 | inform_dataplane = true; | |
702 | set_dp_inactive = true; | |
703 | n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE; | |
6336e12b PR |
704 | } |
705 | ||
7cbae20a PR |
706 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) |
707 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
708 | else | |
709 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
6336e12b | 710 | |
7cbae20a PR |
711 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) { |
712 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
713 | /* if the neigh was peer-active previously we | |
714 | * need to keep the flag and start the | |
715 | * holdtimer on it. the peer-active flag is | |
716 | * cleared on holdtimer expiry. | |
717 | */ | |
718 | if (CHECK_FLAG(old_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) { | |
719 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
720 | zebra_evpn_neigh_start_hold_timer(n); | |
721 | } | |
722 | } else { | |
723 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
724 | /* stop hold timer if a peer has verified | |
725 | * reachability | |
726 | */ | |
727 | zebra_evpn_neigh_stop_hold_timer(n); | |
6336e12b | 728 | } |
7cbae20a | 729 | ZEBRA_NEIGH_SET_ACTIVE(n); |
6336e12b | 730 | |
7cbae20a | 731 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH && (old_flags != n->flags)) |
6336e12b | 732 | zlog_debug( |
ef7b8be4 DL |
733 | "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x", |
734 | n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a | 735 | old_flags, n->flags); |
6336e12b | 736 | |
7cbae20a PR |
737 | new_n_static = zebra_evpn_neigh_is_static(n); |
738 | if (mac_change) { | |
739 | set_dp_inactive = true; | |
740 | n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE; | |
741 | inform_dataplane = true; | |
742 | zebra_evpn_local_neigh_ref_mac( | |
743 | n, &mac->macaddr, mac, | |
744 | false /*send_mac_update*/); | |
745 | } else if (old_n_static != new_n_static) { | |
746 | inform_dataplane = true; | |
747 | /* if static flags have changed without a mac change | |
748 | * we need to create the correct sync-refs against | |
749 | * the existing mac | |
6336e12b | 750 | */ |
7cbae20a PR |
751 | zebra_evpn_sync_neigh_static_chg( |
752 | n, old_n_static, new_n_static, | |
753 | true /*defer_dp*/, true /*defer_mac_dp*/, | |
754 | __func__); | |
6336e12b | 755 | } |
6336e12b | 756 | |
7cbae20a PR |
757 | /* Update the forwarding info. */ |
758 | if (n->ifindex != ifindex) { | |
759 | n->ifindex = ifindex; | |
760 | inform_dataplane = true; | |
6336e12b | 761 | } |
a05111ba DS |
762 | |
763 | n->uptime = monotime(NULL); | |
6336e12b PR |
764 | } |
765 | ||
7cbae20a PR |
766 | /* update the neigh seq. we don't bother with the mac seq as |
767 | * sync_mac_update already took care of that | |
768 | */ | |
769 | tmp_seq = MAX(n->loc_seq, seq); | |
770 | if (tmp_seq != n->loc_seq) { | |
771 | n->loc_seq = tmp_seq; | |
772 | inform_bgp = true; | |
773 | } | |
6336e12b | 774 | |
7cbae20a PR |
775 | /* Mark Router flag (R-bit) */ |
776 | if (is_router) | |
777 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
778 | else | |
779 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 780 | |
7cbae20a PR |
781 | if (old_router != is_router) |
782 | inform_dataplane = true; | |
6336e12b | 783 | |
7cbae20a PR |
784 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); |
785 | if (old_bgp_ready != new_bgp_ready) | |
786 | inform_bgp = true; | |
6336e12b | 787 | |
7cbae20a PR |
788 | new_mac_static = zebra_evpn_mac_is_static(mac); |
789 | if ((old_mac_static != new_mac_static) || ctx->mac_dp_update_deferred) | |
790 | zebra_evpn_sync_mac_dp_install(mac, ctx->mac_inactive, | |
791 | false /* force_clear_static */, | |
792 | __func__); | |
6336e12b | 793 | |
7cbae20a PR |
794 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
795 | zlog_debug( | |
ef7b8be4 | 796 | "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s", |
7cbae20a | 797 | created ? "created" : "updated", n->zevpn->vni, |
ef7b8be4 | 798 | &n->ip, &n->emac, |
7cbae20a PR |
799 | ifp ? ifp->name : "", ifindex, n->loc_seq, n->flags, |
800 | inform_bgp ? " inform_bgp" : "", | |
801 | inform_dataplane ? " inform_dp" : ""); | |
6336e12b | 802 | |
7cbae20a PR |
803 | if (inform_dataplane) |
804 | zebra_evpn_sync_neigh_dp_install(n, set_dp_inactive, | |
805 | false /* force_clear_static */, | |
806 | __func__); | |
6336e12b | 807 | |
7cbae20a PR |
808 | if (inform_bgp) |
809 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
810 | new_bgp_ready); | |
6336e12b | 811 | |
7cbae20a PR |
812 | return n; |
813 | } | |
6336e12b | 814 | |
7cbae20a PR |
815 | /* |
816 | * Uninstall remote neighbor from the kernel. | |
817 | */ | |
f6371c34 | 818 | static int zebra_evpn_neigh_uninstall(struct zebra_evpn *zevpn, |
72de4110 | 819 | struct zebra_neigh *n) |
7cbae20a PR |
820 | { |
821 | struct interface *vlan_if; | |
6336e12b | 822 | |
7cbae20a PR |
823 | if (!(n->flags & ZEBRA_NEIGH_REMOTE)) |
824 | return 0; | |
6336e12b | 825 | |
7cbae20a PR |
826 | vlan_if = zevpn_map_to_svi(zevpn); |
827 | if (!vlan_if) | |
828 | return -1; | |
6336e12b | 829 | |
7cbae20a PR |
830 | ZEBRA_NEIGH_SET_INACTIVE(n); |
831 | n->loc_seq = 0; | |
6336e12b | 832 | |
7cbae20a | 833 | dplane_rem_neigh_delete(vlan_if, &n->ip); |
6336e12b PR |
834 | |
835 | return 0; | |
836 | } | |
837 | ||
7cbae20a PR |
838 | /* |
839 | * Free neighbor hash entry (callback) | |
840 | */ | |
841 | static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket *bucket, | |
842 | void *arg) | |
6336e12b | 843 | { |
7cbae20a | 844 | struct neigh_walk_ctx *wctx = arg; |
72de4110 | 845 | struct zebra_neigh *n = bucket->data; |
6336e12b | 846 | |
7cbae20a PR |
847 | if (((wctx->flags & DEL_LOCAL_NEIGH) && (n->flags & ZEBRA_NEIGH_LOCAL)) |
848 | || ((wctx->flags & DEL_REMOTE_NEIGH) | |
849 | && (n->flags & ZEBRA_NEIGH_REMOTE)) | |
850 | || ((wctx->flags & DEL_REMOTE_NEIGH_FROM_VTEP) | |
851 | && (n->flags & ZEBRA_NEIGH_REMOTE) | |
852 | && IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) { | |
853 | if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL)) | |
854 | zebra_evpn_neigh_send_del_to_client( | |
855 | wctx->zevpn->vni, &n->ip, &n->emac, n->flags, | |
856 | n->state, false /*force*/); | |
6336e12b | 857 | |
7cbae20a PR |
858 | if (wctx->uninstall) { |
859 | if (zebra_evpn_neigh_is_static(n)) | |
860 | zebra_evpn_sync_neigh_dp_install( | |
861 | n, false /* set_inactive */, | |
862 | true /* force_clear_static */, | |
863 | __func__); | |
864 | if ((n->flags & ZEBRA_NEIGH_REMOTE)) | |
865 | zebra_evpn_neigh_uninstall(wctx->zevpn, n); | |
6336e12b PR |
866 | } |
867 | ||
7cbae20a PR |
868 | zebra_evpn_neigh_del(wctx->zevpn, n); |
869 | } | |
6336e12b | 870 | |
7cbae20a PR |
871 | return; |
872 | } | |
6336e12b | 873 | |
7cbae20a PR |
874 | /* |
875 | * Delete all neighbor entries for this EVPN. | |
876 | */ | |
f6371c34 | 877 | void zebra_evpn_neigh_del_all(struct zebra_evpn *zevpn, int uninstall, |
7cbae20a PR |
878 | int upd_client, uint32_t flags) |
879 | { | |
880 | struct neigh_walk_ctx wctx; | |
6336e12b | 881 | |
7cbae20a PR |
882 | if (!zevpn->neigh_table) |
883 | return; | |
6336e12b | 884 | |
7cbae20a PR |
885 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); |
886 | wctx.zevpn = zevpn; | |
887 | wctx.uninstall = uninstall; | |
888 | wctx.upd_client = upd_client; | |
889 | wctx.flags = flags; | |
6336e12b | 890 | |
7cbae20a PR |
891 | hash_iterate(zevpn->neigh_table, zebra_evpn_neigh_del_hash_entry, |
892 | &wctx); | |
893 | } | |
6336e12b | 894 | |
7cbae20a PR |
895 | /* |
896 | * Look up neighbor hash entry. | |
897 | */ | |
72de4110 DS |
898 | struct zebra_neigh *zebra_evpn_neigh_lookup(struct zebra_evpn *zevpn, |
899 | const struct ipaddr *ip) | |
7cbae20a | 900 | { |
72de4110 DS |
901 | struct zebra_neigh tmp; |
902 | struct zebra_neigh *n; | |
6336e12b | 903 | |
7cbae20a PR |
904 | memset(&tmp, 0, sizeof(tmp)); |
905 | memcpy(&tmp.ip, ip, sizeof(struct ipaddr)); | |
906 | n = hash_lookup(zevpn->neigh_table, &tmp); | |
6336e12b | 907 | |
7cbae20a PR |
908 | return n; |
909 | } | |
6336e12b | 910 | |
7cbae20a PR |
911 | /* |
912 | * Process all neighbors associated with a MAC upon the MAC being learnt | |
913 | * locally or undergoing any other change (such as sequence number). | |
914 | */ | |
f6371c34 | 915 | void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn *zevpn, |
3198b2b3 | 916 | struct zebra_mac *zmac, |
7cbae20a PR |
917 | bool seq_change, |
918 | bool es_change) | |
919 | { | |
72de4110 | 920 | struct zebra_neigh *n = NULL; |
7cbae20a PR |
921 | struct listnode *node = NULL; |
922 | struct zebra_vrf *zvrf = NULL; | |
6336e12b | 923 | |
096f7609 | 924 | zvrf = zevpn->vxlan_if->vrf->info; |
6336e12b | 925 | |
7cbae20a | 926 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
927 | zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u", |
928 | &zmac->macaddr, seq_change ? "CHANGE" : "ADD", | |
929 | zevpn->vni); | |
6336e12b | 930 | |
7cbae20a PR |
931 | /* Walk all neighbors and mark any inactive local neighbors as |
932 | * active and/or update sequence number upon a move, and inform BGP. | |
933 | * The action for remote neighbors is TBD. | |
934 | * NOTE: We can't simply uninstall remote neighbors as the kernel may | |
935 | * accidentally end up deleting a just-learnt local neighbor. | |
936 | */ | |
937 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
938 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
939 | if (IS_ZEBRA_NEIGH_INACTIVE(n) || seq_change | |
940 | || es_change) { | |
941 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
942 | n->loc_seq = zmac->loc_seq; | |
b2ee2b71 AK |
943 | if (!(zebra_evpn_do_dup_addr_detect(zvrf) |
944 | && zvrf->dad_freeze | |
7cbae20a PR |
945 | && !!CHECK_FLAG(n->flags, |
946 | ZEBRA_NEIGH_DUPLICATE))) | |
947 | zebra_evpn_neigh_send_add_to_client( | |
948 | zevpn->vni, &n->ip, &n->emac, | |
949 | n->mac, n->flags, n->loc_seq); | |
950 | } | |
6336e12b | 951 | } |
7cbae20a PR |
952 | } |
953 | } | |
6336e12b | 954 | |
7cbae20a PR |
955 | /* |
956 | * Process all neighbors associated with a local MAC upon the MAC being | |
957 | * deleted. | |
958 | */ | |
f6371c34 | 959 | void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn *zevpn, |
3198b2b3 | 960 | struct zebra_mac *zmac) |
7cbae20a | 961 | { |
72de4110 | 962 | struct zebra_neigh *n = NULL; |
7cbae20a | 963 | struct listnode *node = NULL; |
6336e12b | 964 | |
7cbae20a | 965 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
966 | zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u", |
967 | &zmac->macaddr, zevpn->vni); | |
6336e12b | 968 | |
7cbae20a PR |
969 | /* Walk all local neighbors and mark as inactive and inform |
970 | * BGP, if needed. | |
971 | * TBD: There is currently no handling for remote neighbors. We | |
972 | * don't expect them to exist, if they do, do we install the MAC | |
973 | * as a remote MAC and the neighbor as remote? | |
974 | */ | |
975 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
976 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
977 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) { | |
978 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
979 | n->loc_seq = 0; | |
980 | zebra_evpn_neigh_send_del_to_client( | |
981 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
982 | ZEBRA_NEIGH_ACTIVE, false /*force*/); | |
983 | } | |
984 | } | |
6336e12b | 985 | } |
6336e12b PR |
986 | } |
987 | ||
7cbae20a PR |
988 | /* |
989 | * Process all neighbors associated with a MAC upon the MAC being remotely | |
990 | * learnt. | |
991 | */ | |
f6371c34 | 992 | void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn *zevpn, |
3198b2b3 | 993 | struct zebra_mac *zmac) |
6336e12b | 994 | { |
72de4110 | 995 | struct zebra_neigh *n = NULL; |
7cbae20a | 996 | struct listnode *node = NULL; |
6336e12b | 997 | |
7cbae20a | 998 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
999 | zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u", |
1000 | &zmac->macaddr, zevpn->vni); | |
6336e12b | 1001 | |
7cbae20a PR |
1002 | /* Walk all local neighbors and mark as inactive and inform |
1003 | * BGP, if needed. | |
1004 | */ | |
1005 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
1006 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
1007 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) { | |
1008 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
1009 | n->loc_seq = 0; | |
1010 | zebra_evpn_neigh_send_del_to_client( | |
1011 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
1012 | ZEBRA_NEIGH_ACTIVE, false /* force */); | |
1013 | } | |
1014 | } | |
1015 | } | |
6336e12b PR |
1016 | } |
1017 | ||
7cbae20a PR |
1018 | /* |
1019 | * Process all neighbors associated with a remote MAC upon the MAC being | |
1020 | * deleted. | |
1021 | */ | |
f6371c34 | 1022 | void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn *zevpn, |
3198b2b3 | 1023 | struct zebra_mac *zmac) |
6336e12b | 1024 | { |
7cbae20a | 1025 | /* NOTE: Currently a NO-OP. */ |
6336e12b PR |
1026 | } |
1027 | ||
7cbae20a | 1028 | static inline void zebra_evpn_local_neigh_update_log( |
72de4110 DS |
1029 | const char *pfx, struct zebra_neigh *n, bool is_router, |
1030 | bool local_inactive, bool old_bgp_ready, bool new_bgp_ready, | |
1031 | bool inform_dataplane, bool inform_bgp, const char *sfx) | |
7cbae20a | 1032 | { |
7cbae20a | 1033 | if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
6336e12b PR |
1034 | return; |
1035 | ||
ef7b8be4 DL |
1036 | zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx, |
1037 | n->zevpn->vni, &n->ip, &n->emac, n->flags, | |
7cbae20a PR |
1038 | is_router ? " router" : "", |
1039 | local_inactive ? " local-inactive" : "", | |
1040 | old_bgp_ready ? " old_bgp_ready" : "", | |
1041 | new_bgp_ready ? " new_bgp_ready" : "", | |
1042 | inform_dataplane ? " inform_dp" : "", | |
1043 | inform_bgp ? " inform_bgp" : "", sfx); | |
1044 | } | |
1045 | ||
1046 | /* As part Duplicate Address Detection (DAD) for IP mobility | |
1047 | * MAC binding changes, ensure to inherit duplicate flag | |
1048 | * from MAC. | |
1049 | */ | |
036daaca | 1050 | static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf, |
3198b2b3 DS |
1051 | struct zebra_mac *old_zmac, |
1052 | struct zebra_mac *new_zmac, | |
72de4110 | 1053 | struct zebra_neigh *nbr) |
7cbae20a PR |
1054 | { |
1055 | bool is_old_mac_dup = false; | |
1056 | bool is_new_mac_dup = false; | |
6336e12b | 1057 | |
b2ee2b71 | 1058 | if (!zebra_evpn_do_dup_addr_detect(zvrf)) |
7cbae20a PR |
1059 | return 0; |
1060 | /* Check old or new MAC is detected as duplicate | |
1061 | * mark this neigh as duplicate | |
1062 | */ | |
1063 | if (old_zmac) | |
1064 | is_old_mac_dup = | |
1065 | CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE); | |
1066 | if (new_zmac) | |
1067 | is_new_mac_dup = | |
1068 | CHECK_FLAG(new_zmac->flags, ZEBRA_MAC_DUPLICATE); | |
1069 | /* Old and/or new MAC can be in duplicate state, | |
1070 | * based on that IP/Neigh Inherits the flag. | |
1071 | * If New MAC is marked duplicate, inherit to the IP. | |
1072 | * If old MAC is duplicate but new MAC is not, clear | |
1073 | * duplicate flag for IP and reset detection params | |
1074 | * and let IP DAD retrigger. | |
6336e12b | 1075 | */ |
7cbae20a PR |
1076 | if (is_new_mac_dup && !CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { |
1077 | SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1078 | /* Capture Duplicate detection time */ | |
1079 | nbr->dad_dup_detect_time = monotime(NULL); | |
1080 | /* Mark neigh inactive */ | |
1081 | ZEBRA_NEIGH_SET_INACTIVE(nbr); | |
6336e12b | 1082 | |
7cbae20a PR |
1083 | return 1; |
1084 | } else if (is_old_mac_dup && !is_new_mac_dup) { | |
1085 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1086 | nbr->dad_count = 0; | |
1087 | nbr->detect_start_time.tv_sec = 0; | |
1088 | nbr->detect_start_time.tv_usec = 0; | |
1089 | } | |
1090 | return 0; | |
6336e12b PR |
1091 | } |
1092 | ||
cc9f21da | 1093 | static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) |
6336e12b | 1094 | { |
7cbae20a | 1095 | struct zebra_vrf *zvrf = NULL; |
72de4110 | 1096 | struct zebra_neigh *nbr = NULL; |
f6371c34 | 1097 | struct zebra_evpn *zevpn = NULL; |
6336e12b | 1098 | |
7cbae20a | 1099 | nbr = THREAD_ARG(t); |
6336e12b | 1100 | |
7cbae20a PR |
1101 | /* since this is asynchronous we need sanity checks*/ |
1102 | zvrf = vrf_info_lookup(nbr->zevpn->vrf_id); | |
1103 | if (!zvrf) | |
cc9f21da | 1104 | return; |
6336e12b | 1105 | |
8b5fdf2e | 1106 | zevpn = zebra_evpn_lookup(nbr->zevpn->vni); |
7cbae20a | 1107 | if (!zevpn) |
cc9f21da | 1108 | return; |
6336e12b | 1109 | |
7cbae20a PR |
1110 | nbr = zebra_evpn_neigh_lookup(zevpn, &nbr->ip); |
1111 | if (!nbr) | |
cc9f21da | 1112 | return; |
7cbae20a PR |
1113 | |
1114 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1115 | zlog_debug( | |
ef7b8be4 DL |
1116 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired", |
1117 | __func__, &nbr->emac, &nbr->ip, nbr->flags, | |
7cbae20a | 1118 | nbr->dad_count, zevpn->vni); |
6336e12b | 1119 | |
7cbae20a PR |
1120 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); |
1121 | nbr->dad_count = 0; | |
1122 | nbr->detect_start_time.tv_sec = 0; | |
1123 | nbr->detect_start_time.tv_usec = 0; | |
1124 | nbr->dad_dup_detect_time = 0; | |
1125 | nbr->dad_ip_auto_recovery_timer = NULL; | |
1126 | ZEBRA_NEIGH_SET_ACTIVE(nbr); | |
6336e12b | 1127 | |
7cbae20a PR |
1128 | /* Send to BGP */ |
1129 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) { | |
1130 | zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip, | |
1131 | &nbr->emac, nbr->mac, | |
1132 | nbr->flags, nbr->loc_seq); | |
1133 | } else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { | |
1134 | zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); | |
1135 | } | |
7cbae20a | 1136 | } |
6336e12b | 1137 | |
72de4110 DS |
1138 | static void zebra_evpn_dup_addr_detect_for_neigh( |
1139 | struct zebra_vrf *zvrf, struct zebra_neigh *nbr, struct in_addr vtep_ip, | |
1140 | bool do_dad, bool *is_dup_detect, bool is_local) | |
7cbae20a PR |
1141 | { |
1142 | ||
1143 | struct timeval elapsed = {0, 0}; | |
7cbae20a | 1144 | bool reset_params = false; |
6336e12b | 1145 | |
b2ee2b71 | 1146 | if (!zebra_evpn_do_dup_addr_detect(zvrf)) |
7cbae20a PR |
1147 | return; |
1148 | ||
1149 | /* IP is detected as duplicate or inherit dup | |
1150 | * state, hold on to install as remote entry | |
1151 | * only if freeze is enabled. | |
1152 | */ | |
1153 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { | |
6336e12b PR |
1154 | if (IS_ZEBRA_DEBUG_VXLAN) |
1155 | zlog_debug( | |
ef7b8be4 DL |
1156 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u", |
1157 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a PR |
1158 | nbr->flags, nbr->dad_count, |
1159 | zvrf->dad_freeze_time); | |
6336e12b | 1160 | |
7cbae20a PR |
1161 | if (zvrf->dad_freeze) |
1162 | *is_dup_detect = true; | |
6336e12b | 1163 | |
7cbae20a PR |
1164 | /* warn-only action, neigh will be installed. |
1165 | * freeze action, it wil not be installed. | |
6336e12b | 1166 | */ |
7cbae20a PR |
1167 | return; |
1168 | } | |
6336e12b | 1169 | |
7cbae20a PR |
1170 | if (!do_dad) |
1171 | return; | |
6336e12b | 1172 | |
7cbae20a PR |
1173 | /* Check if detection time (M-secs) expired. |
1174 | * Reset learn count and detection start time. | |
1175 | * During remote mac add, count should already be 1 | |
1176 | * via local learning. | |
1177 | */ | |
1178 | monotime_since(&nbr->detect_start_time, &elapsed); | |
1179 | reset_params = (elapsed.tv_sec > zvrf->dad_time); | |
6336e12b | 1180 | |
7cbae20a PR |
1181 | if (is_local && !reset_params) { |
1182 | /* RFC-7432: A PE/VTEP that detects a MAC mobility | |
1183 | * event via LOCAL learning starts an M-second timer. | |
1184 | * | |
1185 | * NOTE: This is the START of the probe with count is | |
1186 | * 0 during LOCAL learn event. | |
1187 | */ | |
1188 | reset_params = !nbr->dad_count; | |
6336e12b PR |
1189 | } |
1190 | ||
7cbae20a PR |
1191 | if (reset_params) { |
1192 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1193 | zlog_debug( | |
ef7b8be4 DL |
1194 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u", |
1195 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a PR |
1196 | nbr->flags, nbr->dad_count); |
1197 | /* Reset learn count but do not start detection | |
1198 | * during REMOTE learn event. | |
1199 | */ | |
1200 | nbr->dad_count = 0; | |
1201 | /* Start dup. addr detection (DAD) start time, | |
1202 | * ONLY during LOCAL learn. | |
1203 | */ | |
1204 | if (is_local) | |
1205 | monotime(&nbr->detect_start_time); | |
6336e12b | 1206 | |
7cbae20a PR |
1207 | } else if (!is_local) { |
1208 | /* For REMOTE IP/Neigh, increment detection count | |
1209 | * ONLY while in probe window, once window passed, | |
1210 | * next local learn event should trigger DAD. | |
1211 | */ | |
1212 | nbr->dad_count++; | |
6336e12b PR |
1213 | } |
1214 | ||
7cbae20a PR |
1215 | /* For LOCAL IP/Neigh learn event, once count is reset above via either |
1216 | * initial/start detection time or passed the probe time, the count | |
1217 | * needs to be incremented. | |
1218 | */ | |
1219 | if (is_local) | |
1220 | nbr->dad_count++; | |
6336e12b | 1221 | |
7cbae20a PR |
1222 | if (nbr->dad_count >= zvrf->dad_max_moves) { |
1223 | flog_warn( | |
1224 | EC_ZEBRA_DUP_IP_DETECTED, | |
ef7b8be4 DL |
1225 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4", |
1226 | nbr->zevpn->vni, &nbr->emac, &nbr->ip, | |
7cbae20a | 1227 | is_local ? "local update, last" : "remote update, from", |
9bcef951 | 1228 | &vtep_ip); |
6336e12b | 1229 | |
7cbae20a | 1230 | SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); |
6336e12b | 1231 | |
7cbae20a PR |
1232 | /* Capture Duplicate detection time */ |
1233 | nbr->dad_dup_detect_time = monotime(NULL); | |
6336e12b | 1234 | |
7cbae20a PR |
1235 | /* Start auto recovery timer for this IP */ |
1236 | THREAD_OFF(nbr->dad_ip_auto_recovery_timer); | |
1237 | if (zvrf->dad_freeze && zvrf->dad_freeze_time) { | |
1238 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1239 | zlog_debug( | |
ef7b8be4 DL |
1240 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start", |
1241 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a | 1242 | nbr->flags, zvrf->dad_freeze_time); |
6336e12b | 1243 | |
7cbae20a PR |
1244 | thread_add_timer(zrouter.master, |
1245 | zebra_evpn_dad_ip_auto_recovery_exp, | |
1246 | nbr, zvrf->dad_freeze_time, | |
1247 | &nbr->dad_ip_auto_recovery_timer); | |
1248 | } | |
1249 | if (zvrf->dad_freeze) | |
1250 | *is_dup_detect = true; | |
1251 | } | |
6336e12b PR |
1252 | } |
1253 | ||
f6371c34 DS |
1254 | int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, |
1255 | struct interface *ifp, | |
1a3bd37f MS |
1256 | const struct ipaddr *ip, |
1257 | const struct ethaddr *macaddr, bool is_router, | |
1258 | bool local_inactive, bool dp_static) | |
6336e12b | 1259 | { |
7cbae20a | 1260 | struct zebra_vrf *zvrf; |
72de4110 | 1261 | struct zebra_neigh *n = NULL; |
3198b2b3 | 1262 | struct zebra_mac *zmac = NULL, *old_zmac = NULL; |
7cbae20a PR |
1263 | uint32_t old_mac_seq = 0, mac_new_seq = 0; |
1264 | bool upd_mac_seq = false; | |
1265 | bool neigh_mac_change = false; | |
1266 | bool neigh_on_hold = false; | |
1267 | bool neigh_was_remote = false; | |
1268 | bool do_dad = false; | |
1269 | struct in_addr vtep_ip = {.s_addr = 0}; | |
1270 | bool inform_dataplane = false; | |
1271 | bool created = false; | |
1272 | bool new_static = false; | |
1273 | bool old_bgp_ready = false; | |
1274 | bool new_bgp_ready; | |
6336e12b | 1275 | |
7cbae20a PR |
1276 | /* Check if the MAC exists. */ |
1277 | zmac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
1278 | if (!zmac) { | |
1279 | /* create a dummy MAC if the MAC is not already present */ | |
6336e12b | 1280 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
1281 | zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u", |
1282 | macaddr, ip, zevpn->vni); | |
6336e12b | 1283 | |
7cbae20a | 1284 | zmac = zebra_evpn_mac_add(zevpn, macaddr); |
8b07f173 | 1285 | zebra_evpn_mac_clear_fwd_info(zmac); |
7cbae20a PR |
1286 | memset(&zmac->flags, 0, sizeof(uint32_t)); |
1287 | SET_FLAG(zmac->flags, ZEBRA_MAC_AUTO); | |
1288 | } else { | |
1289 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) { | |
1290 | /* | |
1291 | * We don't change the MAC to local upon a neighbor | |
1292 | * learn event, we wait for the explicit local MAC | |
1293 | * learn. However, we have to compute its sequence | |
1294 | * number in preparation for when it actually turns | |
1295 | * local. | |
1296 | */ | |
1297 | upd_mac_seq = true; | |
1298 | } | |
1299 | } | |
6336e12b | 1300 | |
096f7609 | 1301 | zvrf = zevpn->vxlan_if->vrf->info; |
7cbae20a PR |
1302 | if (!zvrf) { |
1303 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1304 | zlog_debug(" Unable to find vrf for: %d", | |
096f7609 | 1305 | zevpn->vxlan_if->vrf->vrf_id); |
7cbae20a PR |
1306 | return -1; |
1307 | } | |
6336e12b | 1308 | |
7cbae20a PR |
1309 | /* Check if the neighbor exists. */ |
1310 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
1311 | if (!n) { | |
1312 | /* New neighbor - create */ | |
1313 | n = zebra_evpn_neigh_add(zevpn, ip, macaddr, zmac, 0); | |
97511d01 | 1314 | |
7cbae20a PR |
1315 | /* Set "local" forwarding info. */ |
1316 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
1317 | n->ifindex = ifp->ifindex; | |
1318 | created = true; | |
6336e12b | 1319 | } else { |
7cbae20a PR |
1320 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { |
1321 | bool mac_different; | |
1322 | bool cur_is_router; | |
1323 | bool old_local_inactive; | |
6336e12b | 1324 | |
7cbae20a PR |
1325 | old_local_inactive = !!CHECK_FLAG( |
1326 | n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
6336e12b | 1327 | |
7cbae20a | 1328 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); |
6336e12b | 1329 | |
7cbae20a PR |
1330 | /* Note any changes and see if of interest to BGP. */ |
1331 | mac_different = !!memcmp(&n->emac, macaddr, ETH_ALEN); | |
1332 | cur_is_router = | |
1333 | !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1334 | new_static = zebra_evpn_neigh_is_static(n); | |
1335 | if (!mac_different && is_router == cur_is_router | |
1336 | && old_local_inactive == local_inactive | |
1337 | && dp_static != new_static) { | |
1338 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1339 | zlog_debug( | |
1340 | " Ignoring entry mac is the same and is_router == cur_is_router"); | |
1341 | n->ifindex = ifp->ifindex; | |
1342 | return 0; | |
1343 | } | |
6336e12b | 1344 | |
7cbae20a PR |
1345 | old_zmac = n->mac; |
1346 | if (!mac_different) { | |
1347 | /* XXX - cleanup this code duplication */ | |
1348 | bool is_neigh_freezed = false; | |
6336e12b | 1349 | |
7cbae20a PR |
1350 | /* Only the router flag has changed. */ |
1351 | if (is_router) | |
1352 | SET_FLAG(n->flags, | |
1353 | ZEBRA_NEIGH_ROUTER_FLAG); | |
1354 | else | |
1355 | UNSET_FLAG(n->flags, | |
1356 | ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 1357 | |
7cbae20a PR |
1358 | if (local_inactive) |
1359 | SET_FLAG(n->flags, | |
1360 | ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1361 | else | |
1362 | UNSET_FLAG(n->flags, | |
1363 | ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1364 | new_bgp_ready = | |
1365 | zebra_evpn_neigh_is_ready_for_bgp(n); | |
6336e12b | 1366 | |
7c0e4dc6 AK |
1367 | if (dp_static != new_static) |
1368 | inform_dataplane = true; | |
1369 | ||
7cbae20a PR |
1370 | /* Neigh is in freeze state and freeze action |
1371 | * is enabled, do not send update to client. | |
1372 | */ | |
1373 | is_neigh_freezed = | |
b2ee2b71 | 1374 | (zebra_evpn_do_dup_addr_detect(zvrf) |
7cbae20a PR |
1375 | && zvrf->dad_freeze |
1376 | && CHECK_FLAG(n->flags, | |
1377 | ZEBRA_NEIGH_DUPLICATE)); | |
6336e12b | 1378 | |
7cbae20a PR |
1379 | zebra_evpn_local_neigh_update_log( |
1380 | "local", n, is_router, local_inactive, | |
1381 | old_bgp_ready, new_bgp_ready, false, | |
1382 | false, "flag-update"); | |
6336e12b | 1383 | |
7c0e4dc6 AK |
1384 | if (inform_dataplane) |
1385 | zebra_evpn_sync_neigh_dp_install( | |
1386 | n, false /* set_inactive */, | |
1387 | false /* force_clear_static */, | |
1388 | __func__); | |
1389 | ||
7cbae20a PR |
1390 | /* if the neigh can no longer be advertised |
1391 | * remove it from bgp | |
1392 | */ | |
1393 | if (!is_neigh_freezed) { | |
1394 | zebra_evpn_neigh_send_add_del_to_client( | |
1395 | n, old_bgp_ready, | |
1396 | new_bgp_ready); | |
1397 | } else { | |
1398 | if (IS_ZEBRA_DEBUG_VXLAN | |
1399 | && IS_ZEBRA_NEIGH_ACTIVE(n)) | |
1400 | zlog_debug( | |
1401 | " Neighbor active and frozen"); | |
1402 | } | |
1403 | return 0; | |
1404 | } | |
6336e12b | 1405 | |
7cbae20a PR |
1406 | /* The MAC has changed, need to issue a delete |
1407 | * first as this means a different MACIP route. | |
1408 | * Also, need to do some unlinking/relinking. | |
1409 | * We also need to update the MAC's sequence number | |
1410 | * in different situations. | |
1411 | */ | |
1412 | if (old_bgp_ready) { | |
1413 | zebra_evpn_neigh_send_del_to_client( | |
1414 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
1415 | n->state, false /*force*/); | |
1416 | old_bgp_ready = false; | |
1417 | } | |
1418 | if (old_zmac) { | |
1419 | old_mac_seq = CHECK_FLAG(old_zmac->flags, | |
1420 | ZEBRA_MAC_REMOTE) | |
1421 | ? old_zmac->rem_seq | |
1422 | : old_zmac->loc_seq; | |
1423 | neigh_mac_change = upd_mac_seq = true; | |
1424 | zebra_evpn_local_neigh_deref_mac( | |
1425 | n, true /* send_mac_update */); | |
1426 | } | |
6336e12b | 1427 | |
7cbae20a PR |
1428 | /* if mac changes abandon peer flags and tell |
1429 | * dataplane to clear the static flag | |
1430 | */ | |
1431 | if (zebra_evpn_neigh_clear_sync_info(n)) | |
1432 | inform_dataplane = true; | |
1433 | /* Update the forwarding info. */ | |
1434 | n->ifindex = ifp->ifindex; | |
1435 | ||
1436 | /* Link to new MAC */ | |
1437 | zebra_evpn_local_neigh_ref_mac( | |
1438 | n, macaddr, zmac, true /* send_mac_update */); | |
1439 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1440 | /* | |
1441 | * Neighbor has moved from remote to local. Its | |
1442 | * MAC could have also changed as part of the move. | |
1443 | */ | |
1444 | if (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN) | |
1445 | != 0) { | |
1446 | old_zmac = n->mac; | |
1447 | if (old_zmac) { | |
1448 | old_mac_seq = | |
1449 | CHECK_FLAG(old_zmac->flags, | |
1450 | ZEBRA_MAC_REMOTE) | |
1451 | ? old_zmac->rem_seq | |
1452 | : old_zmac->loc_seq; | |
1453 | neigh_mac_change = upd_mac_seq = true; | |
1454 | zebra_evpn_local_neigh_deref_mac( | |
1455 | n, true /* send_update */); | |
1456 | } | |
6336e12b | 1457 | |
7cbae20a PR |
1458 | /* Link to new MAC */ |
1459 | zebra_evpn_local_neigh_ref_mac( | |
1460 | n, macaddr, zmac, true /*send_update*/); | |
1461 | } | |
1462 | /* Based on Mobility event Scenario-B from the | |
1463 | * draft, neigh's previous state was remote treat this | |
1464 | * event for DAD. | |
1465 | */ | |
1466 | neigh_was_remote = true; | |
1467 | vtep_ip = n->r_vtep_ip; | |
1468 | /* Mark appropriately */ | |
1469 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
1470 | n->r_vtep_ip.s_addr = INADDR_ANY; | |
1471 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
1472 | n->ifindex = ifp->ifindex; | |
6336e12b PR |
1473 | } |
1474 | } | |
1475 | ||
7cbae20a PR |
1476 | /* If MAC was previously remote, or the neighbor had a different |
1477 | * MAC earlier, recompute the sequence number. | |
1478 | */ | |
1479 | if (upd_mac_seq) { | |
1480 | uint32_t seq1, seq2; | |
6336e12b | 1481 | |
7cbae20a PR |
1482 | seq1 = CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE) |
1483 | ? zmac->rem_seq + 1 | |
1484 | : zmac->loc_seq; | |
1485 | seq2 = neigh_mac_change ? old_mac_seq + 1 : 0; | |
1486 | mac_new_seq = zmac->loc_seq < MAX(seq1, seq2) ? MAX(seq1, seq2) | |
1487 | : zmac->loc_seq; | |
1488 | } | |
6336e12b | 1489 | |
7cbae20a PR |
1490 | if (local_inactive) |
1491 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1492 | else | |
1493 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1494 | ||
1495 | /* Mark Router flag (R-bit) */ | |
1496 | if (is_router) | |
1497 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1498 | else | |
1499 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1500 | ||
7c0e4dc6 AK |
1501 | /* if zebra and dataplane don't agree this is a sync entry |
1502 | * re-install in the dataplane */ | |
1503 | new_static = zebra_evpn_neigh_is_static(n); | |
1504 | if (dp_static != new_static) | |
1505 | inform_dataplane = true; | |
7cbae20a PR |
1506 | |
1507 | /* Check old and/or new MAC detected as duplicate mark | |
1508 | * the neigh as duplicate | |
1509 | */ | |
1510 | if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_zmac, zmac, n)) { | |
1511 | flog_warn( | |
1512 | EC_ZEBRA_DUP_IP_INHERIT_DETECTED, | |
ef7b8be4 DL |
1513 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC", |
1514 | zevpn->vni, macaddr, &n->ip); | |
7cbae20a | 1515 | } |
6336e12b | 1516 | |
7cbae20a PR |
1517 | /* For IP Duplicate Address Detection (DAD) is trigger, |
1518 | * when the event is extended mobility based on scenario-B | |
1519 | * from the draft, IP/Neigh's MAC binding changed and | |
1520 | * neigh's previous state was remote. | |
1521 | */ | |
1522 | if (neigh_mac_change && neigh_was_remote) | |
1523 | do_dad = true; | |
6336e12b | 1524 | |
7cbae20a PR |
1525 | zebra_evpn_dup_addr_detect_for_neigh(zvrf, n, vtep_ip, do_dad, |
1526 | &neigh_on_hold, true); | |
6336e12b | 1527 | |
7cbae20a PR |
1528 | if (inform_dataplane) |
1529 | zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */, | |
1530 | false /* force_clear_static */, | |
1531 | __func__); | |
6336e12b | 1532 | |
7cbae20a PR |
1533 | /* Before we program this in BGP, we need to check if MAC is locally |
1534 | * learnt. If not, force neighbor to be inactive and reset its seq. | |
1535 | */ | |
1536 | if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) { | |
1537 | zebra_evpn_local_neigh_update_log( | |
1538 | "local", n, is_router, local_inactive, false, false, | |
1539 | inform_dataplane, false, "auto-mac"); | |
1540 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
1541 | n->loc_seq = 0; | |
1542 | zmac->loc_seq = mac_new_seq; | |
1543 | return 0; | |
1544 | } | |
6336e12b | 1545 | |
7cbae20a PR |
1546 | zebra_evpn_local_neigh_update_log("local", n, is_router, local_inactive, |
1547 | false, false, inform_dataplane, true, | |
1548 | created ? "created" : "updated"); | |
6336e12b | 1549 | |
7cbae20a PR |
1550 | /* If the MAC's sequence number has changed, inform the MAC and all |
1551 | * neighbors associated with the MAC to BGP, else just inform this | |
1552 | * neighbor. | |
1553 | */ | |
1554 | if (upd_mac_seq && zmac->loc_seq != mac_new_seq) { | |
1555 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1556 | zlog_debug( | |
ef7b8be4 DL |
1557 | "Seq changed for MAC %pEA VNI %u - old %u new %u", |
1558 | macaddr, zevpn->vni, | |
1559 | zmac->loc_seq, mac_new_seq); | |
7cbae20a PR |
1560 | zmac->loc_seq = mac_new_seq; |
1561 | if (zebra_evpn_mac_send_add_to_client(zevpn->vni, macaddr, | |
1562 | zmac->flags, | |
1563 | zmac->loc_seq, zmac->es)) | |
1564 | return -1; | |
1565 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, zmac, 1, | |
1566 | 0 /*es_change*/); | |
1567 | return 0; | |
1568 | } | |
6336e12b | 1569 | |
7cbae20a | 1570 | n->loc_seq = zmac->loc_seq; |
6336e12b | 1571 | |
7cbae20a PR |
1572 | if (!neigh_on_hold) { |
1573 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
1574 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
1575 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
1576 | new_bgp_ready); | |
1577 | } else { | |
1578 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1579 | zlog_debug(" Neighbor on hold not sending"); | |
1580 | } | |
1581 | return 0; | |
1582 | } | |
6336e12b | 1583 | |
f6371c34 DS |
1584 | int zebra_evpn_remote_neigh_update(struct zebra_evpn *zevpn, |
1585 | struct interface *ifp, | |
1a3bd37f MS |
1586 | const struct ipaddr *ip, |
1587 | const struct ethaddr *macaddr, | |
7cbae20a PR |
1588 | uint16_t state) |
1589 | { | |
72de4110 | 1590 | struct zebra_neigh *n = NULL; |
3198b2b3 | 1591 | struct zebra_mac *zmac = NULL; |
6336e12b | 1592 | |
7cbae20a PR |
1593 | /* If the neighbor is unknown, there is no further action. */ |
1594 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
1595 | if (!n) | |
1596 | return 0; | |
6336e12b | 1597 | |
7cbae20a PR |
1598 | /* If a remote entry, see if it needs to be refreshed */ |
1599 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1600 | #ifdef GNU_LINUX | |
1601 | if (state & NUD_STALE) | |
1602 | zebra_evpn_rem_neigh_install(zevpn, n, | |
1603 | false /*was_static*/); | |
1604 | #endif | |
6336e12b | 1605 | } else { |
7cbae20a PR |
1606 | /* We got a "remote" neighbor notification for an entry |
1607 | * we think is local. This can happen in a multihoming | |
1608 | * scenario - but only if the MAC is already "remote". | |
1609 | * Just mark our entry as "remote". | |
6336e12b | 1610 | */ |
7cbae20a PR |
1611 | zmac = zebra_evpn_mac_lookup(zevpn, macaddr); |
1612 | if (!zmac || !CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) { | |
1613 | zlog_debug( | |
ef7b8be4 DL |
1614 | "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local", |
1615 | &n->ip, macaddr, zevpn->vni); | |
7cbae20a PR |
1616 | return -1; |
1617 | } | |
6336e12b | 1618 | |
7cbae20a PR |
1619 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS); |
1620 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
1621 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
1622 | n->r_vtep_ip = zmac->fwd_info.r_vtep_ip; | |
6336e12b PR |
1623 | } |
1624 | ||
7cbae20a | 1625 | return 0; |
6336e12b PR |
1626 | } |
1627 | ||
7cbae20a PR |
1628 | /* Notify Neighbor entries to the Client, skips the GW entry */ |
1629 | static void | |
1630 | zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket *bucket, | |
1631 | void *arg) | |
6336e12b | 1632 | { |
7cbae20a | 1633 | struct mac_walk_ctx *wctx = arg; |
72de4110 | 1634 | struct zebra_neigh *zn = bucket->data; |
3198b2b3 | 1635 | struct zebra_mac *zmac = NULL; |
6336e12b | 1636 | |
7cbae20a | 1637 | if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_DEF_GW)) |
6336e12b | 1638 | return; |
6336e12b | 1639 | |
7cbae20a PR |
1640 | if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_LOCAL) |
1641 | && IS_ZEBRA_NEIGH_ACTIVE(zn)) { | |
1642 | zmac = zebra_evpn_mac_lookup(wctx->zevpn, &zn->emac); | |
1643 | if (!zmac) | |
1644 | return; | |
6336e12b | 1645 | |
7cbae20a PR |
1646 | zebra_evpn_neigh_send_add_to_client(wctx->zevpn->vni, &zn->ip, |
1647 | &zn->emac, zn->mac, | |
1648 | zn->flags, zn->loc_seq); | |
1649 | } | |
6336e12b PR |
1650 | } |
1651 | ||
7cbae20a | 1652 | /* Iterator of a specific EVPN */ |
f6371c34 | 1653 | void zebra_evpn_send_neigh_to_client(struct zebra_evpn *zevpn) |
6336e12b | 1654 | { |
7cbae20a | 1655 | struct neigh_walk_ctx wctx; |
6336e12b | 1656 | |
7cbae20a PR |
1657 | memset(&wctx, 0, sizeof(struct neigh_walk_ctx)); |
1658 | wctx.zevpn = zevpn; | |
6336e12b | 1659 | |
7cbae20a PR |
1660 | hash_iterate(zevpn->neigh_table, |
1661 | zebra_evpn_send_neigh_hash_entry_to_client, &wctx); | |
6336e12b PR |
1662 | } |
1663 | ||
7cbae20a | 1664 | void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt) |
6336e12b | 1665 | { |
7cbae20a | 1666 | struct neigh_walk_ctx *wctx = ctxt; |
72de4110 | 1667 | struct zebra_neigh *nbr; |
f6371c34 | 1668 | struct zebra_evpn *zevpn; |
7cbae20a | 1669 | char buf[INET6_ADDRSTRLEN]; |
6336e12b | 1670 | |
72de4110 | 1671 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
1672 | if (!nbr) |
1673 | return; | |
6336e12b | 1674 | |
7cbae20a | 1675 | zevpn = wctx->zevpn; |
6336e12b | 1676 | |
7cbae20a PR |
1677 | if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
1678 | return; | |
6336e12b | 1679 | |
7cbae20a PR |
1680 | if (IS_ZEBRA_DEBUG_VXLAN) { |
1681 | ipaddr2str(&nbr->ip, buf, sizeof(buf)); | |
1682 | zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u", | |
1683 | __func__, buf, nbr->flags, nbr->loc_seq); | |
1684 | } | |
6336e12b PR |
1685 | |
1686 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1687 | nbr->dad_count = 0; | |
1688 | nbr->detect_start_time.tv_sec = 0; | |
1689 | nbr->detect_start_time.tv_usec = 0; | |
1690 | nbr->dad_dup_detect_time = 0; | |
7cbae20a | 1691 | THREAD_OFF(nbr->dad_ip_auto_recovery_timer); |
6336e12b | 1692 | |
6336e12b | 1693 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) { |
7cbae20a PR |
1694 | zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip, |
1695 | &nbr->emac, nbr->mac, | |
1696 | nbr->flags, nbr->loc_seq); | |
1697 | } else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { | |
6336e12b PR |
1698 | zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); |
1699 | } | |
6336e12b PR |
1700 | } |
1701 | ||
7cbae20a PR |
1702 | /* |
1703 | * Print a specific neighbor entry. | |
1704 | */ | |
72de4110 DS |
1705 | void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt, |
1706 | json_object *json) | |
6336e12b | 1707 | { |
7cbae20a PR |
1708 | struct vty *vty; |
1709 | char buf1[ETHER_ADDR_STRLEN]; | |
1710 | char buf2[INET6_ADDRSTRLEN]; | |
1711 | const char *type_str; | |
1712 | const char *state_str; | |
1713 | bool flags_present = false; | |
1714 | struct zebra_vrf *zvrf = NULL; | |
1715 | struct timeval detect_start_time = {0, 0}; | |
1716 | char timebuf[MONOTIME_STRLEN]; | |
1717 | char thread_buf[THREAD_TIMER_STRLEN]; | |
a05111ba DS |
1718 | time_t uptime; |
1719 | char up_str[MONOTIME_STRLEN]; | |
6336e12b | 1720 | |
7cbae20a PR |
1721 | zvrf = zebra_vrf_get_evpn(); |
1722 | if (!zvrf) | |
1723 | return; | |
6336e12b | 1724 | |
a05111ba DS |
1725 | uptime = monotime(NULL); |
1726 | uptime -= n->uptime; | |
1727 | ||
1728 | frrtime_to_interval(uptime, up_str, sizeof(up_str)); | |
1729 | ||
7cbae20a PR |
1730 | ipaddr2str(&n->ip, buf2, sizeof(buf2)); |
1731 | prefix_mac2str(&n->emac, buf1, sizeof(buf1)); | |
1732 | type_str = CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) ? "local" : "remote"; | |
1733 | state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive"; | |
1734 | vty = (struct vty *)ctxt; | |
1735 | if (json == NULL) { | |
1736 | bool sync_info = false; | |
6336e12b | 1737 | |
7cbae20a PR |
1738 | vty_out(vty, "IP: %s\n", |
1739 | ipaddr2str(&n->ip, buf2, sizeof(buf2))); | |
1740 | vty_out(vty, " Type: %s\n", type_str); | |
1741 | vty_out(vty, " State: %s\n", state_str); | |
a05111ba | 1742 | vty_out(vty, " Uptime: %s\n", up_str); |
7cbae20a PR |
1743 | vty_out(vty, " MAC: %s\n", |
1744 | prefix_mac2str(&n->emac, buf1, sizeof(buf1))); | |
1745 | vty_out(vty, " Sync-info:"); | |
1746 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) { | |
1747 | vty_out(vty, " local-inactive"); | |
1748 | sync_info = true; | |
1749 | } | |
1750 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) { | |
1751 | vty_out(vty, " peer-proxy"); | |
1752 | sync_info = true; | |
1753 | } | |
1754 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) { | |
1755 | vty_out(vty, " peer-active"); | |
1756 | sync_info = true; | |
1757 | } | |
1758 | if (n->hold_timer) { | |
1759 | vty_out(vty, " (ht: %s)", | |
1760 | thread_timer_to_hhmmss(thread_buf, | |
1761 | sizeof(thread_buf), | |
1762 | n->hold_timer)); | |
1763 | sync_info = true; | |
1764 | } | |
1765 | if (!sync_info) | |
1766 | vty_out(vty, " -"); | |
1767 | vty_out(vty, "\n"); | |
1768 | } else { | |
a05111ba | 1769 | json_object_string_add(json, "uptime", up_str); |
7cbae20a PR |
1770 | json_object_string_add(json, "ip", buf2); |
1771 | json_object_string_add(json, "type", type_str); | |
1772 | json_object_string_add(json, "state", state_str); | |
1773 | json_object_string_add(json, "mac", buf1); | |
1774 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) | |
1775 | json_object_boolean_true_add(json, "localInactive"); | |
1776 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) | |
1777 | json_object_boolean_true_add(json, "peerProxy"); | |
1778 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
1779 | json_object_boolean_true_add(json, "peerActive"); | |
1780 | if (n->hold_timer) | |
1781 | json_object_string_add( | |
1782 | json, "peerActiveHold", | |
1783 | thread_timer_to_hhmmss(thread_buf, | |
1784 | sizeof(thread_buf), | |
1785 | n->hold_timer)); | |
6336e12b | 1786 | } |
7cbae20a PR |
1787 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { |
1788 | if (n->mac->es) { | |
1789 | if (json) | |
1790 | json_object_string_add(json, "remoteEs", | |
1791 | n->mac->es->esi_str); | |
1792 | else | |
1793 | vty_out(vty, " Remote ES: %s\n", | |
1794 | n->mac->es->esi_str); | |
1795 | } else { | |
1796 | if (json) | |
08edf9c6 DA |
1797 | json_object_string_addf(json, "remoteVtep", |
1798 | "%pI4", &n->r_vtep_ip); | |
7cbae20a | 1799 | else |
9bcef951 MS |
1800 | vty_out(vty, " Remote VTEP: %pI4\n", |
1801 | &n->r_vtep_ip); | |
7cbae20a | 1802 | } |
6336e12b | 1803 | } |
7cbae20a PR |
1804 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) { |
1805 | if (!json) { | |
1806 | vty_out(vty, " Flags: Default-gateway"); | |
1807 | flags_present = true; | |
1808 | } else | |
1809 | json_object_boolean_true_add(json, "defaultGateway"); | |
6336e12b | 1810 | } |
7cbae20a PR |
1811 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)) { |
1812 | if (!json) { | |
1813 | vty_out(vty, | |
1814 | flags_present ? " ,Router" : " Flags: Router"); | |
1815 | flags_present = true; | |
1816 | } | |
1817 | } | |
1818 | if (json == NULL) { | |
1819 | if (flags_present) | |
1820 | vty_out(vty, "\n"); | |
1821 | vty_out(vty, " Local Seq: %u Remote Seq: %u\n", n->loc_seq, | |
1822 | n->rem_seq); | |
6336e12b | 1823 | |
7cbae20a PR |
1824 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) { |
1825 | vty_out(vty, " Duplicate, detected at %s", | |
1826 | time_to_string(n->dad_dup_detect_time, | |
1827 | timebuf)); | |
1828 | } else if (n->dad_count) { | |
1829 | monotime_since(&n->detect_start_time, | |
1830 | &detect_start_time); | |
1831 | if (detect_start_time.tv_sec <= zvrf->dad_time) { | |
1832 | time_to_string(n->detect_start_time.tv_sec, | |
1833 | timebuf); | |
1834 | vty_out(vty, | |
1835 | " Duplicate detection started at %s, detection count %u\n", | |
1836 | timebuf, n->dad_count); | |
1837 | } | |
1838 | } | |
1839 | } else { | |
1840 | json_object_int_add(json, "localSequence", n->loc_seq); | |
1841 | json_object_int_add(json, "remoteSequence", n->rem_seq); | |
1842 | json_object_int_add(json, "detectionCount", n->dad_count); | |
1843 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1844 | json_object_boolean_true_add(json, "isDuplicate"); | |
1845 | else | |
1846 | json_object_boolean_false_add(json, "isDuplicate"); | |
1847 | } | |
6336e12b PR |
1848 | } |
1849 | ||
7cbae20a | 1850 | void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx) |
6336e12b | 1851 | { |
7cbae20a PR |
1852 | vty_out(vty, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n"); |
1853 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx->addr_width, | |
1854 | "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP", | |
1855 | "Seq #'s"); | |
6336e12b PR |
1856 | } |
1857 | ||
72de4110 DS |
1858 | static char *zebra_evpn_print_neigh_flags(struct zebra_neigh *n, |
1859 | char *flags_buf, | |
1860 | uint32_t flags_buf_sz) | |
6336e12b | 1861 | { |
7cbae20a PR |
1862 | snprintf(flags_buf, flags_buf_sz, "%s%s%s", |
1863 | (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ? | |
1864 | "P" : "", | |
1865 | (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ? | |
1866 | "X" : "", | |
1867 | (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ? | |
1868 | "I" : ""); | |
6336e12b | 1869 | |
7cbae20a | 1870 | return flags_buf; |
6336e12b PR |
1871 | } |
1872 | ||
7cbae20a PR |
1873 | /* |
1874 | * Print neighbor hash entry - called for display of all neighbors. | |
1875 | */ | |
1876 | void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt) | |
6336e12b | 1877 | { |
7cbae20a PR |
1878 | struct vty *vty; |
1879 | json_object *json_evpn = NULL, *json_row = NULL; | |
72de4110 | 1880 | struct zebra_neigh *n; |
7cbae20a PR |
1881 | char buf1[ETHER_ADDR_STRLEN]; |
1882 | char buf2[INET6_ADDRSTRLEN]; | |
9bcef951 | 1883 | char addr_buf[PREFIX_STRLEN]; |
7cbae20a PR |
1884 | struct neigh_walk_ctx *wctx = ctxt; |
1885 | const char *state_str; | |
1886 | char flags_buf[6]; | |
6336e12b | 1887 | |
7cbae20a PR |
1888 | vty = wctx->vty; |
1889 | json_evpn = wctx->json; | |
72de4110 | 1890 | n = (struct zebra_neigh *)bucket->data; |
6336e12b | 1891 | |
7cbae20a PR |
1892 | if (json_evpn) |
1893 | json_row = json_object_new_object(); | |
6336e12b | 1894 | |
7cbae20a PR |
1895 | prefix_mac2str(&n->emac, buf1, sizeof(buf1)); |
1896 | ipaddr2str(&n->ip, buf2, sizeof(buf2)); | |
1897 | state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive"; | |
1898 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
1899 | if (wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1900 | return; | |
6336e12b | 1901 | |
7cbae20a PR |
1902 | if (json_evpn == NULL) { |
1903 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n", | |
1904 | -wctx->addr_width, buf2, "local", | |
1905 | zebra_evpn_print_neigh_flags(n, flags_buf, | |
1906 | sizeof(flags_buf)), state_str, buf1, | |
1907 | "", n->loc_seq, n->rem_seq); | |
1908 | } else { | |
1909 | json_object_string_add(json_row, "type", "local"); | |
1910 | json_object_string_add(json_row, "state", state_str); | |
1911 | json_object_string_add(json_row, "mac", buf1); | |
1912 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) | |
1913 | json_object_boolean_true_add(json_row, | |
1914 | "defaultGateway"); | |
1915 | json_object_int_add(json_row, "localSequence", | |
1916 | n->loc_seq); | |
1917 | json_object_int_add(json_row, "remoteSequence", | |
1918 | n->rem_seq); | |
1919 | json_object_int_add(json_row, "detectionCount", | |
1920 | n->dad_count); | |
1921 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1922 | json_object_boolean_true_add(json_row, | |
1923 | "isDuplicate"); | |
1924 | else | |
1925 | json_object_boolean_false_add(json_row, | |
1926 | "isDuplicate"); | |
1927 | } | |
1928 | wctx->count++; | |
1929 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1930 | if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1931 | && !IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip)) | |
6336e12b PR |
1932 | return; |
1933 | ||
7cbae20a PR |
1934 | if (json_evpn == NULL) { |
1935 | if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1936 | && (wctx->count == 0)) | |
1937 | zebra_evpn_print_neigh_hdr(vty, wctx); | |
9bcef951 MS |
1938 | |
1939 | if (n->mac->es == NULL) | |
1940 | inet_ntop(AF_INET, &n->r_vtep_ip, | |
1941 | addr_buf, sizeof(addr_buf)); | |
1942 | ||
7cbae20a PR |
1943 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n", |
1944 | -wctx->addr_width, buf2, "remote", | |
1945 | zebra_evpn_print_neigh_flags(n, flags_buf, | |
1946 | sizeof(flags_buf)), state_str, buf1, | |
9bcef951 | 1947 | n->mac->es ? n->mac->es->esi_str : addr_buf, |
7cbae20a PR |
1948 | n->loc_seq, n->rem_seq); |
1949 | } else { | |
1950 | json_object_string_add(json_row, "type", "remote"); | |
1951 | json_object_string_add(json_row, "state", state_str); | |
1952 | json_object_string_add(json_row, "mac", buf1); | |
1953 | if (n->mac->es) | |
1954 | json_object_string_add(json_row, "remoteEs", | |
1955 | n->mac->es->esi_str); | |
1956 | else | |
08edf9c6 DA |
1957 | json_object_string_addf(json_row, "remoteVtep", |
1958 | "%pI4", &n->r_vtep_ip); | |
7cbae20a PR |
1959 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) |
1960 | json_object_boolean_true_add(json_row, | |
1961 | "defaultGateway"); | |
1962 | json_object_int_add(json_row, "localSequence", | |
1963 | n->loc_seq); | |
1964 | json_object_int_add(json_row, "remoteSequence", | |
1965 | n->rem_seq); | |
1966 | json_object_int_add(json_row, "detectionCount", | |
1967 | n->dad_count); | |
1968 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1969 | json_object_boolean_true_add(json_row, | |
1970 | "isDuplicate"); | |
1971 | else | |
1972 | json_object_boolean_false_add(json_row, | |
1973 | "isDuplicate"); | |
1974 | } | |
1975 | wctx->count++; | |
6336e12b | 1976 | } |
6336e12b | 1977 | |
7cbae20a PR |
1978 | if (json_evpn) |
1979 | json_object_object_add(json_evpn, buf2, json_row); | |
6336e12b PR |
1980 | } |
1981 | ||
7cbae20a PR |
1982 | /* |
1983 | * Print neighbor hash entry in detail - called for display of all neighbors. | |
1984 | */ | |
1985 | void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt) | |
6336e12b | 1986 | { |
7cbae20a PR |
1987 | struct vty *vty; |
1988 | json_object *json_evpn = NULL, *json_row = NULL; | |
72de4110 | 1989 | struct zebra_neigh *n; |
7cbae20a PR |
1990 | char buf[INET6_ADDRSTRLEN]; |
1991 | struct neigh_walk_ctx *wctx = ctxt; | |
6336e12b | 1992 | |
7cbae20a PR |
1993 | vty = wctx->vty; |
1994 | json_evpn = wctx->json; | |
72de4110 | 1995 | n = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
1996 | if (!n) |
1997 | return; | |
6336e12b | 1998 | |
7cbae20a PR |
1999 | ipaddr2str(&n->ip, buf, sizeof(buf)); |
2000 | if (json_evpn) | |
2001 | json_row = json_object_new_object(); | |
6336e12b | 2002 | |
7cbae20a | 2003 | zebra_evpn_print_neigh(n, vty, json_row); |
6336e12b | 2004 | |
7cbae20a PR |
2005 | if (json_evpn) |
2006 | json_object_object_add(json_evpn, buf, json_row); | |
6336e12b PR |
2007 | } |
2008 | ||
7cbae20a | 2009 | void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt) |
6336e12b | 2010 | { |
72de4110 | 2011 | struct zebra_neigh *nbr; |
6336e12b | 2012 | |
72de4110 | 2013 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
2014 | if (!nbr) |
2015 | return; | |
6336e12b | 2016 | |
7cbae20a PR |
2017 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
2018 | zebra_evpn_print_neigh_hash(bucket, ctxt); | |
6336e12b PR |
2019 | } |
2020 | ||
7cbae20a PR |
2021 | void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket, |
2022 | void *ctxt) | |
6336e12b | 2023 | { |
72de4110 | 2024 | struct zebra_neigh *nbr; |
6336e12b | 2025 | |
72de4110 | 2026 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
2027 | if (!nbr) |
2028 | return; | |
6336e12b | 2029 | |
7cbae20a PR |
2030 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
2031 | zebra_evpn_print_neigh_hash_detail(bucket, ctxt); | |
6336e12b | 2032 | } |
036daaca | 2033 | |
f6371c34 | 2034 | void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn, |
272e11bf | 2035 | struct zebra_vrf *zvrf, |
1a3bd37f | 2036 | const struct ipaddr *ipaddr, |
3198b2b3 DS |
2037 | struct zebra_mac *mac, |
2038 | struct in_addr vtep_ip, uint8_t flags, | |
2039 | uint32_t seq) | |
036daaca | 2040 | { |
72de4110 | 2041 | struct zebra_neigh *n; |
036daaca | 2042 | int update_neigh = 0; |
3198b2b3 | 2043 | struct zebra_mac *old_mac = NULL; |
036daaca PR |
2044 | bool old_static = false; |
2045 | bool do_dad = false; | |
2046 | bool is_dup_detect = false; | |
2047 | bool is_router; | |
2048 | ||
2bdd4461 | 2049 | assert(mac); |
036daaca PR |
2050 | is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); |
2051 | ||
2052 | /* Check if the remote neighbor itself is unknown or has a | |
2053 | * change. If so, create or update and then install the entry. | |
2054 | */ | |
2055 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
2056 | if (!n || !CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE) | |
2057 | || is_router != !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG) | |
2058 | || (memcmp(&n->emac, &mac->macaddr, sizeof(struct ethaddr)) != 0) | |
2059 | || !IPV4_ADDR_SAME(&n->r_vtep_ip, &vtep_ip) || seq != n->rem_seq) | |
2060 | update_neigh = 1; | |
2061 | ||
2062 | if (update_neigh) { | |
2063 | if (!n) { | |
2064 | n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, | |
2065 | mac, 0); | |
036daaca | 2066 | } else { |
036daaca PR |
2067 | /* When host moves but changes its (MAC,IP) |
2068 | * binding, BGP may install a MACIP entry that | |
2069 | * corresponds to "older" location of the host | |
2070 | * in transient situations (because {IP1,M1} | |
2071 | * is a different route from {IP1,M2}). Check | |
2072 | * the sequence number and ignore this update | |
2073 | * if appropriate. | |
2074 | */ | |
16de1338 AK |
2075 | |
2076 | if (!zebra_evpn_neigh_is_bgp_seq_ok( | |
2077 | zevpn, n, &mac->macaddr, seq, false)) | |
036daaca | 2078 | return; |
036daaca PR |
2079 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { |
2080 | old_static = zebra_evpn_neigh_is_static(n); | |
2081 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
2082 | zlog_debug( | |
ef7b8be4 DL |
2083 | "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x", |
2084 | n->zevpn->vni, &n->ip, &n->emac, | |
036daaca | 2085 | seq, n->flags); |
036daaca | 2086 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) |
fb8f609d AK |
2087 | zebra_evpn_neigh_send_del_to_client( |
2088 | zevpn->vni, &n->ip, &n->emac, | |
2089 | n->flags, n->state, | |
2090 | false /*force*/); | |
bda6be1c | 2091 | zebra_evpn_neigh_clear_sync_info(n); |
036daaca PR |
2092 | } |
2093 | if (memcmp(&n->emac, &mac->macaddr, | |
2094 | sizeof(struct ethaddr)) | |
2095 | != 0) { | |
2096 | /* update neigh list for macs */ | |
2097 | old_mac = | |
2098 | zebra_evpn_mac_lookup(zevpn, &n->emac); | |
2099 | if (old_mac) { | |
2100 | listnode_delete(old_mac->neigh_list, n); | |
2101 | n->mac = NULL; | |
2102 | zebra_evpn_deref_ip2mac(zevpn, old_mac); | |
2103 | } | |
2104 | n->mac = mac; | |
2105 | listnode_add_sort(mac->neigh_list, n); | |
2106 | memcpy(&n->emac, &mac->macaddr, ETH_ALEN); | |
2107 | ||
2108 | /* Check Neigh's curent state is local | |
2109 | * (this is the case where neigh/host has moved | |
2110 | * from L->R) and check previous detction | |
2111 | * started via local learning. | |
2112 | * | |
2113 | * RFC-7432: A PE/VTEP that detects a MAC | |
2114 | * mobilit event via local learning starts | |
2115 | * an M-second timer. | |
2116 | * VTEP-IP or seq. change along is not | |
2117 | * considered for dup. detection. | |
2118 | * | |
2119 | * Mobilty event scenario-B IP-MAC binding | |
2120 | * changed. | |
2121 | */ | |
2122 | if ((!CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) | |
2123 | && n->dad_count) | |
2124 | do_dad = true; | |
2125 | } | |
2126 | } | |
2127 | ||
2128 | /* Set "remote" forwarding info. */ | |
2129 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS); | |
2130 | n->r_vtep_ip = vtep_ip; | |
2131 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
2132 | ||
2133 | /* Set router flag (R-bit) to this Neighbor entry */ | |
2134 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG)) | |
2135 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2136 | else | |
2137 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2138 | ||
2139 | /* Check old or new MAC detected as duplicate, | |
2140 | * inherit duplicate flag to this neigh. | |
2141 | */ | |
2142 | if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) { | |
2143 | flog_warn( | |
2144 | EC_ZEBRA_DUP_IP_INHERIT_DETECTED, | |
ef7b8be4 DL |
2145 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC", |
2146 | zevpn->vni, &mac->macaddr, &n->ip); | |
036daaca PR |
2147 | } |
2148 | ||
2149 | /* Check duplicate address detection for IP */ | |
2150 | zebra_evpn_dup_addr_detect_for_neigh( | |
2151 | zvrf, n, n->r_vtep_ip, do_dad, &is_dup_detect, false); | |
2152 | /* Install the entry. */ | |
2153 | if (!is_dup_detect) | |
2154 | zebra_evpn_rem_neigh_install(zevpn, n, old_static); | |
2155 | } | |
2156 | ||
036daaca PR |
2157 | /* Update seq number. */ |
2158 | n->rem_seq = seq; | |
2159 | } | |
224315f3 | 2160 | |
f6371c34 DS |
2161 | int zebra_evpn_neigh_gw_macip_add(struct interface *ifp, |
2162 | struct zebra_evpn *zevpn, struct ipaddr *ip, | |
3198b2b3 | 2163 | struct zebra_mac *mac) |
224315f3 | 2164 | { |
72de4110 | 2165 | struct zebra_neigh *n; |
224315f3 | 2166 | |
2bdd4461 | 2167 | assert(mac); |
224315f3 PR |
2168 | |
2169 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
97511d01 | 2170 | if (!n) |
224315f3 | 2171 | n = zebra_evpn_neigh_add(zevpn, ip, &mac->macaddr, mac, 0); |
224315f3 PR |
2172 | |
2173 | /* Set "local" forwarding info. */ | |
2174 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
2175 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
2176 | memcpy(&n->emac, &mac->macaddr, ETH_ALEN); | |
2177 | n->ifindex = ifp->ifindex; | |
2178 | ||
2179 | /* Only advertise in BGP if the knob is enabled */ | |
2180 | if (advertise_gw_macip_enabled(zevpn)) { | |
2181 | ||
224315f3 PR |
2182 | SET_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW); |
2183 | /* Set Router flag (R-bit) */ | |
2184 | if (ip->ipa_type == IPADDR_V6) | |
2185 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2186 | ||
2187 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2188 | zlog_debug( | |
ef7b8be4 | 2189 | "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x", |
224315f3 | 2190 | ifp->name, ifp->ifindex, zevpn->vni, |
ef7b8be4 | 2191 | &mac->macaddr, ip, n->flags); |
224315f3 PR |
2192 | |
2193 | zebra_evpn_neigh_send_add_to_client( | |
2194 | zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq); | |
2195 | } else if (advertise_svi_macip_enabled(zevpn)) { | |
2196 | ||
2197 | SET_FLAG(n->flags, ZEBRA_NEIGH_SVI_IP); | |
2198 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2199 | zlog_debug( | |
ef7b8be4 | 2200 | "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x", |
224315f3 | 2201 | ifp->name, ifp->ifindex, zevpn->vni, |
ef7b8be4 | 2202 | &mac->macaddr, ip, n->flags); |
224315f3 PR |
2203 | |
2204 | zebra_evpn_neigh_send_add_to_client( | |
2205 | zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq); | |
2206 | } | |
2207 | ||
2208 | return 0; | |
2209 | } | |
32fe7dfd | 2210 | |
f6371c34 | 2211 | void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn *zevpn, |
72de4110 DS |
2212 | struct zebra_vrf *zvrf, |
2213 | struct zebra_neigh *n, | |
3198b2b3 | 2214 | struct zebra_mac *mac, |
1a3bd37f | 2215 | const struct ipaddr *ipaddr) |
32fe7dfd | 2216 | { |
32fe7dfd PR |
2217 | if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE) |
2218 | && CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE) | |
2219 | && (memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN) == 0)) { | |
2220 | struct interface *vlan_if; | |
2221 | ||
2222 | vlan_if = zevpn_map_to_svi(zevpn); | |
2223 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2224 | zlog_debug( | |
ef7b8be4 DL |
2225 | "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry", |
2226 | __func__, ipaddr, n->flags, | |
2227 | vlan_if ? vlan_if->name : "Unknown"); | |
32fe7dfd PR |
2228 | if (vlan_if) |
2229 | neigh_read_specific_ip(ipaddr, vlan_if); | |
2230 | } | |
2231 | ||
2232 | /* When the MAC changes for an IP, it is possible the | |
2233 | * client may update the new MAC before trying to delete the | |
2234 | * "old" neighbor (as these are two different MACIP routes). | |
2235 | * Do the delete only if the MAC matches. | |
2236 | */ | |
2237 | if (!memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN)) { | |
2238 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
2239 | zebra_evpn_sync_neigh_del(n); | |
2240 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
2241 | zebra_evpn_neigh_uninstall(zevpn, n); | |
2242 | zebra_evpn_neigh_del(zevpn, n); | |
2243 | zebra_evpn_deref_ip2mac(zevpn, mac); | |
2244 | } | |
2245 | } | |
2246 | } | |
33064a62 | 2247 | |
f6371c34 | 2248 | int zebra_evpn_neigh_del_ip(struct zebra_evpn *zevpn, const struct ipaddr *ip) |
33064a62 | 2249 | { |
72de4110 | 2250 | struct zebra_neigh *n; |
3198b2b3 | 2251 | struct zebra_mac *zmac; |
33064a62 PR |
2252 | bool old_bgp_ready; |
2253 | bool new_bgp_ready; | |
33064a62 PR |
2254 | struct zebra_vrf *zvrf; |
2255 | ||
2256 | /* If entry doesn't exist, nothing to do. */ | |
2257 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
2258 | if (!n) | |
2259 | return 0; | |
2260 | ||
2261 | zmac = zebra_evpn_mac_lookup(zevpn, &n->emac); | |
2262 | if (!zmac) { | |
2263 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2264 | zlog_debug( | |
ef7b8be4 DL |
2265 | "Trying to del a neigh %pIA without a mac %pEA on VNI %u", |
2266 | ip, &n->emac, | |
33064a62 PR |
2267 | zevpn->vni); |
2268 | ||
2269 | return 0; | |
2270 | } | |
2271 | ||
2272 | /* If it is a remote entry, the kernel has aged this out or someone has | |
32367e7a | 2273 | * deleted it, it needs to be re-installed as FRR is the owner. |
33064a62 PR |
2274 | */ |
2275 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
2276 | zebra_evpn_rem_neigh_install(zevpn, n, false /*was_static*/); | |
2277 | return 0; | |
2278 | } | |
2279 | ||
2280 | /* if this is a sync entry it cannot be dropped re-install it in | |
2281 | * the dataplane | |
2282 | */ | |
2283 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
2284 | if (zebra_evpn_neigh_is_static(n)) { | |
2285 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
ef7b8be4 DL |
2286 | zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x", |
2287 | n->zevpn->vni, &n->ip, &n->emac, | |
33064a62 PR |
2288 | n->flags); |
2289 | ||
2290 | if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) | |
2291 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
2292 | /* inform-bgp about change in local-activity if any */ | |
2293 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
2294 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
2295 | new_bgp_ready); | |
2296 | ||
2297 | /* re-install the entry in the kernel */ | |
2298 | zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */, | |
2299 | false /* force_clear_static */, | |
2300 | __func__); | |
2301 | ||
2302 | return 0; | |
2303 | } | |
2304 | ||
096f7609 | 2305 | zvrf = zevpn->vxlan_if->vrf->info; |
33064a62 PR |
2306 | if (!zvrf) { |
2307 | zlog_debug("%s: VNI %u vrf lookup failed.", __func__, | |
2308 | zevpn->vni); | |
2309 | return -1; | |
2310 | } | |
2311 | ||
2312 | /* In case of feeze action, if local neigh is in duplicate state, | |
2313 | * Mark the Neigh as inactive before sending delete request to BGPd, | |
2314 | * If BGPd has remote entry, it will re-install | |
2315 | */ | |
2316 | if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
2317 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
2318 | ||
2319 | /* Remove neighbor from BGP. */ | |
2320 | zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac, | |
2321 | n->flags, n->state, | |
2322 | false /* force */); | |
2323 | ||
2324 | /* Delete this neighbor entry. */ | |
2325 | zebra_evpn_neigh_del(zevpn, n); | |
2326 | ||
2327 | /* see if the AUTO mac needs to be deleted */ | |
2328 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_AUTO) | |
243b74ed | 2329 | && !zebra_evpn_mac_in_use(zmac)) |
33064a62 PR |
2330 | zebra_evpn_mac_del(zevpn, zmac); |
2331 | ||
2332 | return 0; | |
2333 | } |