]>
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 | |
6006b807 | 553 | memset(&tmp_n, 0, sizeof(tmp_n)); |
7cbae20a PR |
554 | memcpy(&tmp_n.ip, ip, sizeof(struct ipaddr)); |
555 | n = hash_get(zevpn->neigh_table, &tmp_n, zebra_evpn_neigh_alloc); | |
6336e12b | 556 | |
7cbae20a PR |
557 | n->state = ZEBRA_NEIGH_INACTIVE; |
558 | n->zevpn = zevpn; | |
559 | n->dad_ip_auto_recovery_timer = NULL; | |
560 | n->flags = n_flags; | |
a05111ba | 561 | n->uptime = monotime(NULL); |
6336e12b | 562 | |
7cbae20a PR |
563 | if (!zmac) |
564 | zmac = zebra_evpn_mac_lookup(zevpn, mac); | |
565 | zebra_evpn_local_neigh_ref_mac(n, mac, zmac, | |
566 | false /* send_mac_update */); | |
6336e12b | 567 | |
7cbae20a | 568 | return n; |
6336e12b PR |
569 | } |
570 | ||
571 | /* | |
7cbae20a | 572 | * Delete neighbor entry. |
6336e12b | 573 | */ |
72de4110 | 574 | int zebra_evpn_neigh_del(struct zebra_evpn *zevpn, struct zebra_neigh *n) |
6336e12b | 575 | { |
72de4110 | 576 | struct zebra_neigh *tmp_n; |
6336e12b | 577 | |
7cbae20a PR |
578 | if (n->mac) |
579 | listnode_delete(n->mac->neigh_list, n); | |
6336e12b | 580 | |
7cbae20a PR |
581 | /* Cancel auto recovery */ |
582 | THREAD_OFF(n->dad_ip_auto_recovery_timer); | |
6336e12b | 583 | |
2b9e207e AK |
584 | /* Cancel proxy hold timer */ |
585 | zebra_evpn_neigh_stop_hold_timer(n); | |
586 | ||
7cbae20a PR |
587 | /* Free the VNI hash entry and allocated memory. */ |
588 | tmp_n = hash_release(zevpn->neigh_table, n); | |
589 | XFREE(MTYPE_NEIGH, tmp_n); | |
6336e12b PR |
590 | |
591 | return 0; | |
592 | } | |
593 | ||
72de4110 | 594 | void zebra_evpn_sync_neigh_del(struct zebra_neigh *n) |
6336e12b | 595 | { |
7cbae20a PR |
596 | bool old_n_static; |
597 | bool new_n_static; | |
6336e12b | 598 | |
7cbae20a | 599 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
ef7b8be4 DL |
600 | zlog_debug("sync-neigh del vni %u ip %pIA mac %pEA f 0x%x", |
601 | n->zevpn->vni, &n->ip, &n->emac, n->flags); | |
6336e12b | 602 | |
7cbae20a PR |
603 | old_n_static = zebra_evpn_neigh_is_static(n); |
604 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
605 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
606 | zebra_evpn_neigh_start_hold_timer(n); | |
607 | new_n_static = zebra_evpn_neigh_is_static(n); | |
6336e12b | 608 | |
7cbae20a PR |
609 | if (old_n_static != new_n_static) |
610 | zebra_evpn_sync_neigh_static_chg( | |
611 | n, old_n_static, new_n_static, false /*defer-dp*/, | |
612 | false /*defer_mac_dp*/, __func__); | |
613 | } | |
6336e12b | 614 | |
72de4110 DS |
615 | struct zebra_neigh *zebra_evpn_proc_sync_neigh_update( |
616 | struct zebra_evpn *zevpn, struct zebra_neigh *n, uint16_t ipa_len, | |
617 | const struct ipaddr *ipaddr, uint8_t flags, uint32_t seq, | |
618 | const esi_t *esi, struct sync_mac_ip_ctx *ctx) | |
7cbae20a PR |
619 | { |
620 | struct interface *ifp = NULL; | |
621 | bool is_router; | |
3198b2b3 | 622 | struct zebra_mac *mac = ctx->mac; |
7cbae20a PR |
623 | uint32_t tmp_seq; |
624 | bool old_router = false; | |
625 | bool old_bgp_ready = false; | |
626 | bool new_bgp_ready; | |
627 | bool inform_dataplane = false; | |
628 | bool inform_bgp = false; | |
629 | bool old_mac_static; | |
630 | bool new_mac_static; | |
631 | bool set_dp_inactive = false; | |
7cbae20a PR |
632 | bool created; |
633 | ifindex_t ifindex = 0; | |
6336e12b | 634 | |
7cbae20a PR |
635 | /* locate l3-svi */ |
636 | ifp = zevpn_map_to_svi(zevpn); | |
637 | if (ifp) | |
638 | ifindex = ifp->ifindex; | |
6336e12b | 639 | |
7cbae20a PR |
640 | is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); |
641 | old_mac_static = zebra_evpn_mac_is_static(mac); | |
6336e12b | 642 | |
7cbae20a PR |
643 | if (!n) { |
644 | uint32_t n_flags = 0; | |
6336e12b | 645 | |
7cbae20a PR |
646 | /* New neighbor - create */ |
647 | SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL); | |
648 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) | |
649 | SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
650 | else | |
651 | SET_FLAG(n_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
652 | SET_FLAG(n_flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
6336e12b | 653 | |
7cbae20a PR |
654 | n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, mac, |
655 | n_flags); | |
656 | n->ifindex = ifindex; | |
657 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
6336e12b | 658 | |
7cbae20a PR |
659 | created = true; |
660 | inform_dataplane = true; | |
661 | inform_bgp = true; | |
662 | set_dp_inactive = true; | |
663 | } else { | |
664 | bool mac_change; | |
665 | uint32_t old_flags = n->flags; | |
666 | bool old_n_static; | |
667 | bool new_n_static; | |
6336e12b | 668 | |
7cbae20a PR |
669 | created = false; |
670 | old_n_static = zebra_evpn_neigh_is_static(n); | |
671 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
672 | old_router = !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 673 | |
7cbae20a PR |
674 | mac_change = !!memcmp(&n->emac, &mac->macaddr, ETH_ALEN); |
675 | ||
676 | /* deref and clear old info */ | |
677 | if (mac_change) { | |
678 | if (old_bgp_ready) { | |
679 | zebra_evpn_neigh_send_del_to_client( | |
680 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
681 | n->state, false /*force*/); | |
682 | old_bgp_ready = false; | |
6336e12b | 683 | } |
bc3cd39b DS |
684 | zebra_evpn_local_neigh_deref_mac(n, |
685 | false /*send_mac_update*/); | |
6336e12b | 686 | } |
7cbae20a PR |
687 | /* clear old fwd info */ |
688 | n->rem_seq = 0; | |
689 | n->r_vtep_ip.s_addr = 0; | |
6336e12b | 690 | |
7cbae20a PR |
691 | /* setup new flags */ |
692 | n->flags = 0; | |
693 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
694 | /* retain activity flag if the neigh was | |
695 | * previously local | |
6336e12b | 696 | */ |
7cbae20a PR |
697 | if (old_flags & ZEBRA_NEIGH_LOCAL) { |
698 | n->flags |= (old_flags & ZEBRA_NEIGH_LOCAL_INACTIVE); | |
699 | } else { | |
700 | inform_dataplane = true; | |
701 | set_dp_inactive = true; | |
702 | n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE; | |
6336e12b PR |
703 | } |
704 | ||
7cbae20a PR |
705 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_PROXY_ADVERT)) { |
706 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY); | |
707 | /* if the neigh was peer-active previously we | |
708 | * need to keep the flag and start the | |
709 | * holdtimer on it. the peer-active flag is | |
710 | * cleared on holdtimer expiry. | |
711 | */ | |
712 | if (CHECK_FLAG(old_flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) { | |
713 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
714 | zebra_evpn_neigh_start_hold_timer(n); | |
715 | } | |
716 | } else { | |
717 | SET_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE); | |
718 | /* stop hold timer if a peer has verified | |
719 | * reachability | |
720 | */ | |
721 | zebra_evpn_neigh_stop_hold_timer(n); | |
6336e12b | 722 | } |
7cbae20a | 723 | ZEBRA_NEIGH_SET_ACTIVE(n); |
6336e12b | 724 | |
7cbae20a | 725 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH && (old_flags != n->flags)) |
6336e12b | 726 | zlog_debug( |
ef7b8be4 DL |
727 | "sync-neigh vni %u ip %pIA mac %pEA old_f 0x%x new_f 0x%x", |
728 | n->zevpn->vni, &n->ip, &n->emac, | |
7cbae20a | 729 | old_flags, n->flags); |
6336e12b | 730 | |
7cbae20a PR |
731 | new_n_static = zebra_evpn_neigh_is_static(n); |
732 | if (mac_change) { | |
733 | set_dp_inactive = true; | |
734 | n->flags |= ZEBRA_NEIGH_LOCAL_INACTIVE; | |
735 | inform_dataplane = true; | |
736 | zebra_evpn_local_neigh_ref_mac( | |
737 | n, &mac->macaddr, mac, | |
738 | false /*send_mac_update*/); | |
739 | } else if (old_n_static != new_n_static) { | |
740 | inform_dataplane = true; | |
741 | /* if static flags have changed without a mac change | |
742 | * we need to create the correct sync-refs against | |
743 | * the existing mac | |
6336e12b | 744 | */ |
7cbae20a PR |
745 | zebra_evpn_sync_neigh_static_chg( |
746 | n, old_n_static, new_n_static, | |
747 | true /*defer_dp*/, true /*defer_mac_dp*/, | |
748 | __func__); | |
6336e12b | 749 | } |
6336e12b | 750 | |
7cbae20a PR |
751 | /* Update the forwarding info. */ |
752 | if (n->ifindex != ifindex) { | |
753 | n->ifindex = ifindex; | |
754 | inform_dataplane = true; | |
6336e12b | 755 | } |
a05111ba DS |
756 | |
757 | n->uptime = monotime(NULL); | |
6336e12b PR |
758 | } |
759 | ||
7cbae20a PR |
760 | /* update the neigh seq. we don't bother with the mac seq as |
761 | * sync_mac_update already took care of that | |
762 | */ | |
763 | tmp_seq = MAX(n->loc_seq, seq); | |
764 | if (tmp_seq != n->loc_seq) { | |
765 | n->loc_seq = tmp_seq; | |
766 | inform_bgp = true; | |
767 | } | |
6336e12b | 768 | |
7cbae20a PR |
769 | /* Mark Router flag (R-bit) */ |
770 | if (is_router) | |
771 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
772 | else | |
773 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 774 | |
7cbae20a PR |
775 | if (old_router != is_router) |
776 | inform_dataplane = true; | |
6336e12b | 777 | |
7cbae20a PR |
778 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); |
779 | if (old_bgp_ready != new_bgp_ready) | |
780 | inform_bgp = true; | |
6336e12b | 781 | |
7cbae20a PR |
782 | new_mac_static = zebra_evpn_mac_is_static(mac); |
783 | if ((old_mac_static != new_mac_static) || ctx->mac_dp_update_deferred) | |
784 | zebra_evpn_sync_mac_dp_install(mac, ctx->mac_inactive, | |
785 | false /* force_clear_static */, | |
786 | __func__); | |
6336e12b | 787 | |
7cbae20a PR |
788 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
789 | zlog_debug( | |
ef7b8be4 | 790 | "sync-neigh %s vni %u ip %pIA mac %pEA if %s(%d) seq %d f 0x%x%s%s", |
7cbae20a | 791 | created ? "created" : "updated", n->zevpn->vni, |
ef7b8be4 | 792 | &n->ip, &n->emac, |
7cbae20a PR |
793 | ifp ? ifp->name : "", ifindex, n->loc_seq, n->flags, |
794 | inform_bgp ? " inform_bgp" : "", | |
795 | inform_dataplane ? " inform_dp" : ""); | |
6336e12b | 796 | |
7cbae20a PR |
797 | if (inform_dataplane) |
798 | zebra_evpn_sync_neigh_dp_install(n, set_dp_inactive, | |
799 | false /* force_clear_static */, | |
800 | __func__); | |
6336e12b | 801 | |
7cbae20a PR |
802 | if (inform_bgp) |
803 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
804 | new_bgp_ready); | |
6336e12b | 805 | |
7cbae20a PR |
806 | return n; |
807 | } | |
6336e12b | 808 | |
7cbae20a PR |
809 | /* |
810 | * Uninstall remote neighbor from the kernel. | |
811 | */ | |
f6371c34 | 812 | static int zebra_evpn_neigh_uninstall(struct zebra_evpn *zevpn, |
72de4110 | 813 | struct zebra_neigh *n) |
7cbae20a PR |
814 | { |
815 | struct interface *vlan_if; | |
6336e12b | 816 | |
7cbae20a PR |
817 | if (!(n->flags & ZEBRA_NEIGH_REMOTE)) |
818 | return 0; | |
6336e12b | 819 | |
7cbae20a PR |
820 | vlan_if = zevpn_map_to_svi(zevpn); |
821 | if (!vlan_if) | |
822 | return -1; | |
6336e12b | 823 | |
7cbae20a PR |
824 | ZEBRA_NEIGH_SET_INACTIVE(n); |
825 | n->loc_seq = 0; | |
6336e12b | 826 | |
7cbae20a | 827 | dplane_rem_neigh_delete(vlan_if, &n->ip); |
6336e12b PR |
828 | |
829 | return 0; | |
830 | } | |
831 | ||
7cbae20a PR |
832 | /* |
833 | * Free neighbor hash entry (callback) | |
834 | */ | |
835 | static void zebra_evpn_neigh_del_hash_entry(struct hash_bucket *bucket, | |
836 | void *arg) | |
6336e12b | 837 | { |
7cbae20a | 838 | struct neigh_walk_ctx *wctx = arg; |
72de4110 | 839 | struct zebra_neigh *n = bucket->data; |
6336e12b | 840 | |
7cbae20a PR |
841 | if (((wctx->flags & DEL_LOCAL_NEIGH) && (n->flags & ZEBRA_NEIGH_LOCAL)) |
842 | || ((wctx->flags & DEL_REMOTE_NEIGH) | |
843 | && (n->flags & ZEBRA_NEIGH_REMOTE)) | |
844 | || ((wctx->flags & DEL_REMOTE_NEIGH_FROM_VTEP) | |
845 | && (n->flags & ZEBRA_NEIGH_REMOTE) | |
846 | && IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip))) { | |
847 | if (wctx->upd_client && (n->flags & ZEBRA_NEIGH_LOCAL)) | |
848 | zebra_evpn_neigh_send_del_to_client( | |
849 | wctx->zevpn->vni, &n->ip, &n->emac, n->flags, | |
850 | n->state, false /*force*/); | |
6336e12b | 851 | |
7cbae20a PR |
852 | if (wctx->uninstall) { |
853 | if (zebra_evpn_neigh_is_static(n)) | |
854 | zebra_evpn_sync_neigh_dp_install( | |
855 | n, false /* set_inactive */, | |
856 | true /* force_clear_static */, | |
857 | __func__); | |
858 | if ((n->flags & ZEBRA_NEIGH_REMOTE)) | |
859 | zebra_evpn_neigh_uninstall(wctx->zevpn, n); | |
6336e12b PR |
860 | } |
861 | ||
7cbae20a PR |
862 | zebra_evpn_neigh_del(wctx->zevpn, n); |
863 | } | |
6336e12b | 864 | |
7cbae20a PR |
865 | return; |
866 | } | |
6336e12b | 867 | |
7cbae20a PR |
868 | /* |
869 | * Delete all neighbor entries for this EVPN. | |
870 | */ | |
f6371c34 | 871 | void zebra_evpn_neigh_del_all(struct zebra_evpn *zevpn, int uninstall, |
7cbae20a PR |
872 | int upd_client, uint32_t flags) |
873 | { | |
874 | struct neigh_walk_ctx wctx; | |
6336e12b | 875 | |
7cbae20a PR |
876 | if (!zevpn->neigh_table) |
877 | return; | |
6336e12b | 878 | |
6006b807 | 879 | memset(&wctx, 0, sizeof(wctx)); |
7cbae20a PR |
880 | wctx.zevpn = zevpn; |
881 | wctx.uninstall = uninstall; | |
882 | wctx.upd_client = upd_client; | |
883 | wctx.flags = flags; | |
6336e12b | 884 | |
7cbae20a PR |
885 | hash_iterate(zevpn->neigh_table, zebra_evpn_neigh_del_hash_entry, |
886 | &wctx); | |
887 | } | |
6336e12b | 888 | |
7cbae20a PR |
889 | /* |
890 | * Look up neighbor hash entry. | |
891 | */ | |
72de4110 DS |
892 | struct zebra_neigh *zebra_evpn_neigh_lookup(struct zebra_evpn *zevpn, |
893 | const struct ipaddr *ip) | |
7cbae20a | 894 | { |
72de4110 DS |
895 | struct zebra_neigh tmp; |
896 | struct zebra_neigh *n; | |
6336e12b | 897 | |
7cbae20a PR |
898 | memset(&tmp, 0, sizeof(tmp)); |
899 | memcpy(&tmp.ip, ip, sizeof(struct ipaddr)); | |
900 | n = hash_lookup(zevpn->neigh_table, &tmp); | |
6336e12b | 901 | |
7cbae20a PR |
902 | return n; |
903 | } | |
6336e12b | 904 | |
7cbae20a PR |
905 | /* |
906 | * Process all neighbors associated with a MAC upon the MAC being learnt | |
907 | * locally or undergoing any other change (such as sequence number). | |
908 | */ | |
f6371c34 | 909 | void zebra_evpn_process_neigh_on_local_mac_change(struct zebra_evpn *zevpn, |
3198b2b3 | 910 | struct zebra_mac *zmac, |
7cbae20a PR |
911 | bool seq_change, |
912 | bool es_change) | |
913 | { | |
72de4110 | 914 | struct zebra_neigh *n = NULL; |
7cbae20a PR |
915 | struct listnode *node = NULL; |
916 | struct zebra_vrf *zvrf = NULL; | |
6336e12b | 917 | |
096f7609 | 918 | zvrf = zevpn->vxlan_if->vrf->info; |
6336e12b | 919 | |
7cbae20a | 920 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
921 | zlog_debug("Processing neighbors on local MAC %pEA %s, VNI %u", |
922 | &zmac->macaddr, seq_change ? "CHANGE" : "ADD", | |
923 | zevpn->vni); | |
6336e12b | 924 | |
7cbae20a PR |
925 | /* Walk all neighbors and mark any inactive local neighbors as |
926 | * active and/or update sequence number upon a move, and inform BGP. | |
927 | * The action for remote neighbors is TBD. | |
928 | * NOTE: We can't simply uninstall remote neighbors as the kernel may | |
929 | * accidentally end up deleting a just-learnt local neighbor. | |
930 | */ | |
931 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
932 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
933 | if (IS_ZEBRA_NEIGH_INACTIVE(n) || seq_change | |
934 | || es_change) { | |
935 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
936 | n->loc_seq = zmac->loc_seq; | |
b2ee2b71 AK |
937 | if (!(zebra_evpn_do_dup_addr_detect(zvrf) |
938 | && zvrf->dad_freeze | |
7cbae20a PR |
939 | && !!CHECK_FLAG(n->flags, |
940 | ZEBRA_NEIGH_DUPLICATE))) | |
941 | zebra_evpn_neigh_send_add_to_client( | |
942 | zevpn->vni, &n->ip, &n->emac, | |
943 | n->mac, n->flags, n->loc_seq); | |
944 | } | |
6336e12b | 945 | } |
7cbae20a PR |
946 | } |
947 | } | |
6336e12b | 948 | |
7cbae20a PR |
949 | /* |
950 | * Process all neighbors associated with a local MAC upon the MAC being | |
951 | * deleted. | |
952 | */ | |
f6371c34 | 953 | void zebra_evpn_process_neigh_on_local_mac_del(struct zebra_evpn *zevpn, |
3198b2b3 | 954 | struct zebra_mac *zmac) |
7cbae20a | 955 | { |
72de4110 | 956 | struct zebra_neigh *n = NULL; |
7cbae20a | 957 | struct listnode *node = NULL; |
6336e12b | 958 | |
7cbae20a | 959 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
960 | zlog_debug("Processing neighbors on local MAC %pEA DEL, VNI %u", |
961 | &zmac->macaddr, zevpn->vni); | |
6336e12b | 962 | |
7cbae20a PR |
963 | /* Walk all local neighbors and mark as inactive and inform |
964 | * BGP, if needed. | |
965 | * TBD: There is currently no handling for remote neighbors. We | |
966 | * don't expect them to exist, if they do, do we install the MAC | |
967 | * as a remote MAC and the neighbor as remote? | |
968 | */ | |
969 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
970 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
971 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) { | |
972 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
973 | n->loc_seq = 0; | |
974 | zebra_evpn_neigh_send_del_to_client( | |
975 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
976 | ZEBRA_NEIGH_ACTIVE, false /*force*/); | |
977 | } | |
978 | } | |
6336e12b | 979 | } |
6336e12b PR |
980 | } |
981 | ||
7cbae20a PR |
982 | /* |
983 | * Process all neighbors associated with a MAC upon the MAC being remotely | |
984 | * learnt. | |
985 | */ | |
f6371c34 | 986 | void zebra_evpn_process_neigh_on_remote_mac_add(struct zebra_evpn *zevpn, |
3198b2b3 | 987 | struct zebra_mac *zmac) |
6336e12b | 988 | { |
72de4110 | 989 | struct zebra_neigh *n = NULL; |
7cbae20a | 990 | struct listnode *node = NULL; |
6336e12b | 991 | |
7cbae20a | 992 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
993 | zlog_debug("Processing neighbors on remote MAC %pEA ADD, VNI %u", |
994 | &zmac->macaddr, zevpn->vni); | |
6336e12b | 995 | |
7cbae20a PR |
996 | /* Walk all local neighbors and mark as inactive and inform |
997 | * BGP, if needed. | |
998 | */ | |
999 | for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) { | |
1000 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
1001 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) { | |
1002 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
1003 | n->loc_seq = 0; | |
1004 | zebra_evpn_neigh_send_del_to_client( | |
1005 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
1006 | ZEBRA_NEIGH_ACTIVE, false /* force */); | |
1007 | } | |
1008 | } | |
1009 | } | |
6336e12b PR |
1010 | } |
1011 | ||
7cbae20a PR |
1012 | /* |
1013 | * Process all neighbors associated with a remote MAC upon the MAC being | |
1014 | * deleted. | |
1015 | */ | |
f6371c34 | 1016 | void zebra_evpn_process_neigh_on_remote_mac_del(struct zebra_evpn *zevpn, |
3198b2b3 | 1017 | struct zebra_mac *zmac) |
6336e12b | 1018 | { |
7cbae20a | 1019 | /* NOTE: Currently a NO-OP. */ |
6336e12b PR |
1020 | } |
1021 | ||
7cbae20a | 1022 | static inline void zebra_evpn_local_neigh_update_log( |
72de4110 DS |
1023 | const char *pfx, struct zebra_neigh *n, bool is_router, |
1024 | bool local_inactive, bool old_bgp_ready, bool new_bgp_ready, | |
1025 | bool inform_dataplane, bool inform_bgp, const char *sfx) | |
7cbae20a | 1026 | { |
7cbae20a | 1027 | if (!IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) |
6336e12b PR |
1028 | return; |
1029 | ||
ef7b8be4 DL |
1030 | zlog_debug("%s neigh vni %u ip %pIA mac %pEA f 0x%x%s%s%s%s%s%s %s", pfx, |
1031 | n->zevpn->vni, &n->ip, &n->emac, n->flags, | |
7cbae20a PR |
1032 | is_router ? " router" : "", |
1033 | local_inactive ? " local-inactive" : "", | |
1034 | old_bgp_ready ? " old_bgp_ready" : "", | |
1035 | new_bgp_ready ? " new_bgp_ready" : "", | |
1036 | inform_dataplane ? " inform_dp" : "", | |
1037 | inform_bgp ? " inform_bgp" : "", sfx); | |
1038 | } | |
1039 | ||
1040 | /* As part Duplicate Address Detection (DAD) for IP mobility | |
1041 | * MAC binding changes, ensure to inherit duplicate flag | |
1042 | * from MAC. | |
1043 | */ | |
036daaca | 1044 | static int zebra_evpn_ip_inherit_dad_from_mac(struct zebra_vrf *zvrf, |
3198b2b3 DS |
1045 | struct zebra_mac *old_zmac, |
1046 | struct zebra_mac *new_zmac, | |
72de4110 | 1047 | struct zebra_neigh *nbr) |
7cbae20a PR |
1048 | { |
1049 | bool is_old_mac_dup = false; | |
1050 | bool is_new_mac_dup = false; | |
6336e12b | 1051 | |
b2ee2b71 | 1052 | if (!zebra_evpn_do_dup_addr_detect(zvrf)) |
7cbae20a PR |
1053 | return 0; |
1054 | /* Check old or new MAC is detected as duplicate | |
1055 | * mark this neigh as duplicate | |
1056 | */ | |
1057 | if (old_zmac) | |
1058 | is_old_mac_dup = | |
1059 | CHECK_FLAG(old_zmac->flags, ZEBRA_MAC_DUPLICATE); | |
1060 | if (new_zmac) | |
1061 | is_new_mac_dup = | |
1062 | CHECK_FLAG(new_zmac->flags, ZEBRA_MAC_DUPLICATE); | |
1063 | /* Old and/or new MAC can be in duplicate state, | |
1064 | * based on that IP/Neigh Inherits the flag. | |
1065 | * If New MAC is marked duplicate, inherit to the IP. | |
1066 | * If old MAC is duplicate but new MAC is not, clear | |
1067 | * duplicate flag for IP and reset detection params | |
1068 | * and let IP DAD retrigger. | |
6336e12b | 1069 | */ |
7cbae20a PR |
1070 | if (is_new_mac_dup && !CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { |
1071 | SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1072 | /* Capture Duplicate detection time */ | |
1073 | nbr->dad_dup_detect_time = monotime(NULL); | |
1074 | /* Mark neigh inactive */ | |
1075 | ZEBRA_NEIGH_SET_INACTIVE(nbr); | |
6336e12b | 1076 | |
7cbae20a PR |
1077 | return 1; |
1078 | } else if (is_old_mac_dup && !is_new_mac_dup) { | |
1079 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1080 | nbr->dad_count = 0; | |
1081 | nbr->detect_start_time.tv_sec = 0; | |
1082 | nbr->detect_start_time.tv_usec = 0; | |
1083 | } | |
1084 | return 0; | |
6336e12b PR |
1085 | } |
1086 | ||
cc9f21da | 1087 | static void zebra_evpn_dad_ip_auto_recovery_exp(struct thread *t) |
6336e12b | 1088 | { |
7cbae20a | 1089 | struct zebra_vrf *zvrf = NULL; |
72de4110 | 1090 | struct zebra_neigh *nbr = NULL; |
f6371c34 | 1091 | struct zebra_evpn *zevpn = NULL; |
6336e12b | 1092 | |
7cbae20a | 1093 | nbr = THREAD_ARG(t); |
6336e12b | 1094 | |
7cbae20a PR |
1095 | /* since this is asynchronous we need sanity checks*/ |
1096 | zvrf = vrf_info_lookup(nbr->zevpn->vrf_id); | |
1097 | if (!zvrf) | |
cc9f21da | 1098 | return; |
6336e12b | 1099 | |
8b5fdf2e | 1100 | zevpn = zebra_evpn_lookup(nbr->zevpn->vni); |
7cbae20a | 1101 | if (!zevpn) |
cc9f21da | 1102 | return; |
6336e12b | 1103 | |
7cbae20a PR |
1104 | nbr = zebra_evpn_neigh_lookup(zevpn, &nbr->ip); |
1105 | if (!nbr) | |
cc9f21da | 1106 | return; |
7cbae20a PR |
1107 | |
1108 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1109 | zlog_debug( | |
ef7b8be4 DL |
1110 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x learn count %u vni %u auto recovery expired", |
1111 | __func__, &nbr->emac, &nbr->ip, nbr->flags, | |
7cbae20a | 1112 | nbr->dad_count, zevpn->vni); |
6336e12b | 1113 | |
7cbae20a PR |
1114 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); |
1115 | nbr->dad_count = 0; | |
1116 | nbr->detect_start_time.tv_sec = 0; | |
1117 | nbr->detect_start_time.tv_usec = 0; | |
1118 | nbr->dad_dup_detect_time = 0; | |
1119 | nbr->dad_ip_auto_recovery_timer = NULL; | |
1120 | ZEBRA_NEIGH_SET_ACTIVE(nbr); | |
6336e12b | 1121 | |
7cbae20a PR |
1122 | /* Send to BGP */ |
1123 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) { | |
1124 | zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip, | |
1125 | &nbr->emac, nbr->mac, | |
1126 | nbr->flags, nbr->loc_seq); | |
1127 | } else if (!!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { | |
1128 | zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); | |
1129 | } | |
7cbae20a | 1130 | } |
6336e12b | 1131 | |
72de4110 DS |
1132 | static void zebra_evpn_dup_addr_detect_for_neigh( |
1133 | struct zebra_vrf *zvrf, struct zebra_neigh *nbr, struct in_addr vtep_ip, | |
1134 | bool do_dad, bool *is_dup_detect, bool is_local) | |
7cbae20a PR |
1135 | { |
1136 | ||
1137 | struct timeval elapsed = {0, 0}; | |
7cbae20a | 1138 | bool reset_params = false; |
6336e12b | 1139 | |
b2ee2b71 | 1140 | if (!zebra_evpn_do_dup_addr_detect(zvrf)) |
7cbae20a PR |
1141 | return; |
1142 | ||
1143 | /* IP is detected as duplicate or inherit dup | |
1144 | * state, hold on to install as remote entry | |
1145 | * only if freeze is enabled. | |
1146 | */ | |
1147 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) { | |
6336e12b PR |
1148 | if (IS_ZEBRA_DEBUG_VXLAN) |
1149 | zlog_debug( | |
ef7b8be4 DL |
1150 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x skip installing, learn count %u recover time %u", |
1151 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a PR |
1152 | nbr->flags, nbr->dad_count, |
1153 | zvrf->dad_freeze_time); | |
6336e12b | 1154 | |
7cbae20a PR |
1155 | if (zvrf->dad_freeze) |
1156 | *is_dup_detect = true; | |
6336e12b | 1157 | |
7cbae20a PR |
1158 | /* warn-only action, neigh will be installed. |
1159 | * freeze action, it wil not be installed. | |
6336e12b | 1160 | */ |
7cbae20a PR |
1161 | return; |
1162 | } | |
6336e12b | 1163 | |
7cbae20a PR |
1164 | if (!do_dad) |
1165 | return; | |
6336e12b | 1166 | |
7cbae20a PR |
1167 | /* Check if detection time (M-secs) expired. |
1168 | * Reset learn count and detection start time. | |
1169 | * During remote mac add, count should already be 1 | |
1170 | * via local learning. | |
1171 | */ | |
1172 | monotime_since(&nbr->detect_start_time, &elapsed); | |
1173 | reset_params = (elapsed.tv_sec > zvrf->dad_time); | |
6336e12b | 1174 | |
7cbae20a PR |
1175 | if (is_local && !reset_params) { |
1176 | /* RFC-7432: A PE/VTEP that detects a MAC mobility | |
1177 | * event via LOCAL learning starts an M-second timer. | |
1178 | * | |
1179 | * NOTE: This is the START of the probe with count is | |
1180 | * 0 during LOCAL learn event. | |
1181 | */ | |
1182 | reset_params = !nbr->dad_count; | |
6336e12b PR |
1183 | } |
1184 | ||
7cbae20a PR |
1185 | if (reset_params) { |
1186 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1187 | zlog_debug( | |
ef7b8be4 DL |
1188 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x detection time passed, reset learn count %u", |
1189 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a PR |
1190 | nbr->flags, nbr->dad_count); |
1191 | /* Reset learn count but do not start detection | |
1192 | * during REMOTE learn event. | |
1193 | */ | |
1194 | nbr->dad_count = 0; | |
1195 | /* Start dup. addr detection (DAD) start time, | |
1196 | * ONLY during LOCAL learn. | |
1197 | */ | |
1198 | if (is_local) | |
1199 | monotime(&nbr->detect_start_time); | |
6336e12b | 1200 | |
7cbae20a PR |
1201 | } else if (!is_local) { |
1202 | /* For REMOTE IP/Neigh, increment detection count | |
1203 | * ONLY while in probe window, once window passed, | |
1204 | * next local learn event should trigger DAD. | |
1205 | */ | |
1206 | nbr->dad_count++; | |
6336e12b PR |
1207 | } |
1208 | ||
7cbae20a PR |
1209 | /* For LOCAL IP/Neigh learn event, once count is reset above via either |
1210 | * initial/start detection time or passed the probe time, the count | |
1211 | * needs to be incremented. | |
1212 | */ | |
1213 | if (is_local) | |
1214 | nbr->dad_count++; | |
6336e12b | 1215 | |
7cbae20a PR |
1216 | if (nbr->dad_count >= zvrf->dad_max_moves) { |
1217 | flog_warn( | |
1218 | EC_ZEBRA_DUP_IP_DETECTED, | |
ef7b8be4 DL |
1219 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during %s VTEP %pI4", |
1220 | nbr->zevpn->vni, &nbr->emac, &nbr->ip, | |
7cbae20a | 1221 | is_local ? "local update, last" : "remote update, from", |
9bcef951 | 1222 | &vtep_ip); |
6336e12b | 1223 | |
7cbae20a | 1224 | SET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); |
6336e12b | 1225 | |
7cbae20a PR |
1226 | /* Capture Duplicate detection time */ |
1227 | nbr->dad_dup_detect_time = monotime(NULL); | |
6336e12b | 1228 | |
7cbae20a PR |
1229 | /* Start auto recovery timer for this IP */ |
1230 | THREAD_OFF(nbr->dad_ip_auto_recovery_timer); | |
1231 | if (zvrf->dad_freeze && zvrf->dad_freeze_time) { | |
1232 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1233 | zlog_debug( | |
ef7b8be4 DL |
1234 | "%s: duplicate addr MAC %pEA IP %pIA flags 0x%x auto recovery time %u start", |
1235 | __func__, &nbr->emac, &nbr->ip, | |
7cbae20a | 1236 | nbr->flags, zvrf->dad_freeze_time); |
6336e12b | 1237 | |
7cbae20a PR |
1238 | thread_add_timer(zrouter.master, |
1239 | zebra_evpn_dad_ip_auto_recovery_exp, | |
1240 | nbr, zvrf->dad_freeze_time, | |
1241 | &nbr->dad_ip_auto_recovery_timer); | |
1242 | } | |
1243 | if (zvrf->dad_freeze) | |
1244 | *is_dup_detect = true; | |
1245 | } | |
6336e12b PR |
1246 | } |
1247 | ||
f6371c34 DS |
1248 | int zebra_evpn_local_neigh_update(struct zebra_evpn *zevpn, |
1249 | struct interface *ifp, | |
1a3bd37f MS |
1250 | const struct ipaddr *ip, |
1251 | const struct ethaddr *macaddr, bool is_router, | |
1252 | bool local_inactive, bool dp_static) | |
6336e12b | 1253 | { |
7cbae20a | 1254 | struct zebra_vrf *zvrf; |
72de4110 | 1255 | struct zebra_neigh *n = NULL; |
3198b2b3 | 1256 | struct zebra_mac *zmac = NULL, *old_zmac = NULL; |
7cbae20a PR |
1257 | uint32_t old_mac_seq = 0, mac_new_seq = 0; |
1258 | bool upd_mac_seq = false; | |
1259 | bool neigh_mac_change = false; | |
1260 | bool neigh_on_hold = false; | |
1261 | bool neigh_was_remote = false; | |
1262 | bool do_dad = false; | |
1263 | struct in_addr vtep_ip = {.s_addr = 0}; | |
1264 | bool inform_dataplane = false; | |
1265 | bool created = false; | |
1266 | bool new_static = false; | |
1267 | bool old_bgp_ready = false; | |
1268 | bool new_bgp_ready; | |
6336e12b | 1269 | |
7cbae20a PR |
1270 | /* Check if the MAC exists. */ |
1271 | zmac = zebra_evpn_mac_lookup(zevpn, macaddr); | |
1272 | if (!zmac) { | |
1273 | /* create a dummy MAC if the MAC is not already present */ | |
6336e12b | 1274 | if (IS_ZEBRA_DEBUG_VXLAN) |
ef7b8be4 DL |
1275 | zlog_debug("AUTO MAC %pEA created for neigh %pIA on VNI %u", |
1276 | macaddr, ip, zevpn->vni); | |
6336e12b | 1277 | |
7cbae20a | 1278 | zmac = zebra_evpn_mac_add(zevpn, macaddr); |
8b07f173 | 1279 | zebra_evpn_mac_clear_fwd_info(zmac); |
7cbae20a PR |
1280 | memset(&zmac->flags, 0, sizeof(uint32_t)); |
1281 | SET_FLAG(zmac->flags, ZEBRA_MAC_AUTO); | |
1282 | } else { | |
1283 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) { | |
1284 | /* | |
1285 | * We don't change the MAC to local upon a neighbor | |
1286 | * learn event, we wait for the explicit local MAC | |
1287 | * learn. However, we have to compute its sequence | |
1288 | * number in preparation for when it actually turns | |
1289 | * local. | |
1290 | */ | |
1291 | upd_mac_seq = true; | |
1292 | } | |
1293 | } | |
6336e12b | 1294 | |
096f7609 | 1295 | zvrf = zevpn->vxlan_if->vrf->info; |
7cbae20a PR |
1296 | if (!zvrf) { |
1297 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1298 | zlog_debug(" Unable to find vrf for: %d", | |
096f7609 | 1299 | zevpn->vxlan_if->vrf->vrf_id); |
7cbae20a PR |
1300 | return -1; |
1301 | } | |
6336e12b | 1302 | |
7cbae20a PR |
1303 | /* Check if the neighbor exists. */ |
1304 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
1305 | if (!n) { | |
1306 | /* New neighbor - create */ | |
1307 | n = zebra_evpn_neigh_add(zevpn, ip, macaddr, zmac, 0); | |
97511d01 | 1308 | |
7cbae20a PR |
1309 | /* Set "local" forwarding info. */ |
1310 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
1311 | n->ifindex = ifp->ifindex; | |
1312 | created = true; | |
6336e12b | 1313 | } else { |
7cbae20a PR |
1314 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { |
1315 | bool mac_different; | |
1316 | bool cur_is_router; | |
1317 | bool old_local_inactive; | |
6336e12b | 1318 | |
7cbae20a PR |
1319 | old_local_inactive = !!CHECK_FLAG( |
1320 | n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
6336e12b | 1321 | |
7cbae20a | 1322 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); |
6336e12b | 1323 | |
7cbae20a PR |
1324 | /* Note any changes and see if of interest to BGP. */ |
1325 | mac_different = !!memcmp(&n->emac, macaddr, ETH_ALEN); | |
1326 | cur_is_router = | |
1327 | !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1328 | new_static = zebra_evpn_neigh_is_static(n); | |
1329 | if (!mac_different && is_router == cur_is_router | |
1330 | && old_local_inactive == local_inactive | |
1331 | && dp_static != new_static) { | |
1332 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1333 | zlog_debug( | |
1334 | " Ignoring entry mac is the same and is_router == cur_is_router"); | |
1335 | n->ifindex = ifp->ifindex; | |
1336 | return 0; | |
1337 | } | |
6336e12b | 1338 | |
7cbae20a PR |
1339 | old_zmac = n->mac; |
1340 | if (!mac_different) { | |
1341 | /* XXX - cleanup this code duplication */ | |
1342 | bool is_neigh_freezed = false; | |
6336e12b | 1343 | |
7cbae20a PR |
1344 | /* Only the router flag has changed. */ |
1345 | if (is_router) | |
1346 | SET_FLAG(n->flags, | |
1347 | ZEBRA_NEIGH_ROUTER_FLAG); | |
1348 | else | |
1349 | UNSET_FLAG(n->flags, | |
1350 | ZEBRA_NEIGH_ROUTER_FLAG); | |
6336e12b | 1351 | |
7cbae20a PR |
1352 | if (local_inactive) |
1353 | SET_FLAG(n->flags, | |
1354 | ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1355 | else | |
1356 | UNSET_FLAG(n->flags, | |
1357 | ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1358 | new_bgp_ready = | |
1359 | zebra_evpn_neigh_is_ready_for_bgp(n); | |
6336e12b | 1360 | |
7c0e4dc6 AK |
1361 | if (dp_static != new_static) |
1362 | inform_dataplane = true; | |
1363 | ||
7cbae20a PR |
1364 | /* Neigh is in freeze state and freeze action |
1365 | * is enabled, do not send update to client. | |
1366 | */ | |
1367 | is_neigh_freezed = | |
b2ee2b71 | 1368 | (zebra_evpn_do_dup_addr_detect(zvrf) |
7cbae20a PR |
1369 | && zvrf->dad_freeze |
1370 | && CHECK_FLAG(n->flags, | |
1371 | ZEBRA_NEIGH_DUPLICATE)); | |
6336e12b | 1372 | |
7cbae20a PR |
1373 | zebra_evpn_local_neigh_update_log( |
1374 | "local", n, is_router, local_inactive, | |
1375 | old_bgp_ready, new_bgp_ready, false, | |
1376 | false, "flag-update"); | |
6336e12b | 1377 | |
7c0e4dc6 AK |
1378 | if (inform_dataplane) |
1379 | zebra_evpn_sync_neigh_dp_install( | |
1380 | n, false /* set_inactive */, | |
1381 | false /* force_clear_static */, | |
1382 | __func__); | |
1383 | ||
7cbae20a PR |
1384 | /* if the neigh can no longer be advertised |
1385 | * remove it from bgp | |
1386 | */ | |
1387 | if (!is_neigh_freezed) { | |
1388 | zebra_evpn_neigh_send_add_del_to_client( | |
1389 | n, old_bgp_ready, | |
1390 | new_bgp_ready); | |
1391 | } else { | |
1392 | if (IS_ZEBRA_DEBUG_VXLAN | |
1393 | && IS_ZEBRA_NEIGH_ACTIVE(n)) | |
1394 | zlog_debug( | |
1395 | " Neighbor active and frozen"); | |
1396 | } | |
1397 | return 0; | |
1398 | } | |
6336e12b | 1399 | |
7cbae20a PR |
1400 | /* The MAC has changed, need to issue a delete |
1401 | * first as this means a different MACIP route. | |
1402 | * Also, need to do some unlinking/relinking. | |
1403 | * We also need to update the MAC's sequence number | |
1404 | * in different situations. | |
1405 | */ | |
1406 | if (old_bgp_ready) { | |
1407 | zebra_evpn_neigh_send_del_to_client( | |
1408 | zevpn->vni, &n->ip, &n->emac, n->flags, | |
1409 | n->state, false /*force*/); | |
1410 | old_bgp_ready = false; | |
1411 | } | |
1412 | if (old_zmac) { | |
1413 | old_mac_seq = CHECK_FLAG(old_zmac->flags, | |
1414 | ZEBRA_MAC_REMOTE) | |
1415 | ? old_zmac->rem_seq | |
1416 | : old_zmac->loc_seq; | |
1417 | neigh_mac_change = upd_mac_seq = true; | |
1418 | zebra_evpn_local_neigh_deref_mac( | |
1419 | n, true /* send_mac_update */); | |
1420 | } | |
6336e12b | 1421 | |
7cbae20a PR |
1422 | /* if mac changes abandon peer flags and tell |
1423 | * dataplane to clear the static flag | |
1424 | */ | |
1425 | if (zebra_evpn_neigh_clear_sync_info(n)) | |
1426 | inform_dataplane = true; | |
1427 | /* Update the forwarding info. */ | |
1428 | n->ifindex = ifp->ifindex; | |
1429 | ||
1430 | /* Link to new MAC */ | |
1431 | zebra_evpn_local_neigh_ref_mac( | |
1432 | n, macaddr, zmac, true /* send_mac_update */); | |
1433 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1434 | /* | |
1435 | * Neighbor has moved from remote to local. Its | |
1436 | * MAC could have also changed as part of the move. | |
1437 | */ | |
1438 | if (memcmp(n->emac.octet, macaddr->octet, ETH_ALEN) | |
1439 | != 0) { | |
1440 | old_zmac = n->mac; | |
1441 | if (old_zmac) { | |
1442 | old_mac_seq = | |
1443 | CHECK_FLAG(old_zmac->flags, | |
1444 | ZEBRA_MAC_REMOTE) | |
1445 | ? old_zmac->rem_seq | |
1446 | : old_zmac->loc_seq; | |
1447 | neigh_mac_change = upd_mac_seq = true; | |
1448 | zebra_evpn_local_neigh_deref_mac( | |
1449 | n, true /* send_update */); | |
1450 | } | |
6336e12b | 1451 | |
7cbae20a PR |
1452 | /* Link to new MAC */ |
1453 | zebra_evpn_local_neigh_ref_mac( | |
1454 | n, macaddr, zmac, true /*send_update*/); | |
1455 | } | |
1456 | /* Based on Mobility event Scenario-B from the | |
1457 | * draft, neigh's previous state was remote treat this | |
1458 | * event for DAD. | |
1459 | */ | |
1460 | neigh_was_remote = true; | |
1461 | vtep_ip = n->r_vtep_ip; | |
1462 | /* Mark appropriately */ | |
1463 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
1464 | n->r_vtep_ip.s_addr = INADDR_ANY; | |
1465 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
1466 | n->ifindex = ifp->ifindex; | |
6336e12b PR |
1467 | } |
1468 | } | |
1469 | ||
7cbae20a PR |
1470 | /* If MAC was previously remote, or the neighbor had a different |
1471 | * MAC earlier, recompute the sequence number. | |
1472 | */ | |
1473 | if (upd_mac_seq) { | |
1474 | uint32_t seq1, seq2; | |
6336e12b | 1475 | |
7cbae20a PR |
1476 | seq1 = CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE) |
1477 | ? zmac->rem_seq + 1 | |
1478 | : zmac->loc_seq; | |
1479 | seq2 = neigh_mac_change ? old_mac_seq + 1 : 0; | |
1480 | mac_new_seq = zmac->loc_seq < MAX(seq1, seq2) ? MAX(seq1, seq2) | |
1481 | : zmac->loc_seq; | |
1482 | } | |
6336e12b | 1483 | |
7cbae20a PR |
1484 | if (local_inactive) |
1485 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1486 | else | |
1487 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
1488 | ||
1489 | /* Mark Router flag (R-bit) */ | |
1490 | if (is_router) | |
1491 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1492 | else | |
1493 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
1494 | ||
7c0e4dc6 AK |
1495 | /* if zebra and dataplane don't agree this is a sync entry |
1496 | * re-install in the dataplane */ | |
1497 | new_static = zebra_evpn_neigh_is_static(n); | |
1498 | if (dp_static != new_static) | |
1499 | inform_dataplane = true; | |
7cbae20a PR |
1500 | |
1501 | /* Check old and/or new MAC detected as duplicate mark | |
1502 | * the neigh as duplicate | |
1503 | */ | |
1504 | if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_zmac, zmac, n)) { | |
1505 | flog_warn( | |
1506 | EC_ZEBRA_DUP_IP_INHERIT_DETECTED, | |
ef7b8be4 DL |
1507 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during local update, inherit duplicate from MAC", |
1508 | zevpn->vni, macaddr, &n->ip); | |
7cbae20a | 1509 | } |
6336e12b | 1510 | |
7cbae20a PR |
1511 | /* For IP Duplicate Address Detection (DAD) is trigger, |
1512 | * when the event is extended mobility based on scenario-B | |
1513 | * from the draft, IP/Neigh's MAC binding changed and | |
1514 | * neigh's previous state was remote. | |
1515 | */ | |
1516 | if (neigh_mac_change && neigh_was_remote) | |
1517 | do_dad = true; | |
6336e12b | 1518 | |
7cbae20a PR |
1519 | zebra_evpn_dup_addr_detect_for_neigh(zvrf, n, vtep_ip, do_dad, |
1520 | &neigh_on_hold, true); | |
6336e12b | 1521 | |
7cbae20a PR |
1522 | if (inform_dataplane) |
1523 | zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */, | |
1524 | false /* force_clear_static */, | |
1525 | __func__); | |
6336e12b | 1526 | |
7cbae20a PR |
1527 | /* Before we program this in BGP, we need to check if MAC is locally |
1528 | * learnt. If not, force neighbor to be inactive and reset its seq. | |
1529 | */ | |
1530 | if (!CHECK_FLAG(zmac->flags, ZEBRA_MAC_LOCAL)) { | |
1531 | zebra_evpn_local_neigh_update_log( | |
1532 | "local", n, is_router, local_inactive, false, false, | |
1533 | inform_dataplane, false, "auto-mac"); | |
1534 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
1535 | n->loc_seq = 0; | |
1536 | zmac->loc_seq = mac_new_seq; | |
1537 | return 0; | |
1538 | } | |
6336e12b | 1539 | |
7cbae20a PR |
1540 | zebra_evpn_local_neigh_update_log("local", n, is_router, local_inactive, |
1541 | false, false, inform_dataplane, true, | |
1542 | created ? "created" : "updated"); | |
6336e12b | 1543 | |
7cbae20a PR |
1544 | /* If the MAC's sequence number has changed, inform the MAC and all |
1545 | * neighbors associated with the MAC to BGP, else just inform this | |
1546 | * neighbor. | |
1547 | */ | |
1548 | if (upd_mac_seq && zmac->loc_seq != mac_new_seq) { | |
1549 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1550 | zlog_debug( | |
ef7b8be4 DL |
1551 | "Seq changed for MAC %pEA VNI %u - old %u new %u", |
1552 | macaddr, zevpn->vni, | |
1553 | zmac->loc_seq, mac_new_seq); | |
7cbae20a PR |
1554 | zmac->loc_seq = mac_new_seq; |
1555 | if (zebra_evpn_mac_send_add_to_client(zevpn->vni, macaddr, | |
1556 | zmac->flags, | |
1557 | zmac->loc_seq, zmac->es)) | |
1558 | return -1; | |
1559 | zebra_evpn_process_neigh_on_local_mac_change(zevpn, zmac, 1, | |
1560 | 0 /*es_change*/); | |
1561 | return 0; | |
1562 | } | |
6336e12b | 1563 | |
7cbae20a | 1564 | n->loc_seq = zmac->loc_seq; |
6336e12b | 1565 | |
7cbae20a PR |
1566 | if (!neigh_on_hold) { |
1567 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
1568 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
1569 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
1570 | new_bgp_ready); | |
1571 | } else { | |
1572 | if (IS_ZEBRA_DEBUG_VXLAN) | |
1573 | zlog_debug(" Neighbor on hold not sending"); | |
1574 | } | |
1575 | return 0; | |
1576 | } | |
6336e12b | 1577 | |
f6371c34 DS |
1578 | int zebra_evpn_remote_neigh_update(struct zebra_evpn *zevpn, |
1579 | struct interface *ifp, | |
1a3bd37f MS |
1580 | const struct ipaddr *ip, |
1581 | const struct ethaddr *macaddr, | |
7cbae20a PR |
1582 | uint16_t state) |
1583 | { | |
72de4110 | 1584 | struct zebra_neigh *n = NULL; |
3198b2b3 | 1585 | struct zebra_mac *zmac = NULL; |
6336e12b | 1586 | |
7cbae20a PR |
1587 | /* If the neighbor is unknown, there is no further action. */ |
1588 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
1589 | if (!n) | |
1590 | return 0; | |
6336e12b | 1591 | |
7cbae20a PR |
1592 | /* If a remote entry, see if it needs to be refreshed */ |
1593 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1594 | #ifdef GNU_LINUX | |
1595 | if (state & NUD_STALE) | |
1596 | zebra_evpn_rem_neigh_install(zevpn, n, | |
1597 | false /*was_static*/); | |
1598 | #endif | |
6336e12b | 1599 | } else { |
7cbae20a PR |
1600 | /* We got a "remote" neighbor notification for an entry |
1601 | * we think is local. This can happen in a multihoming | |
1602 | * scenario - but only if the MAC is already "remote". | |
1603 | * Just mark our entry as "remote". | |
6336e12b | 1604 | */ |
7cbae20a PR |
1605 | zmac = zebra_evpn_mac_lookup(zevpn, macaddr); |
1606 | if (!zmac || !CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) { | |
1607 | zlog_debug( | |
ef7b8be4 DL |
1608 | "Ignore remote neigh %pIA (MAC %pEA) on L2-VNI %u - MAC unknown or local", |
1609 | &n->ip, macaddr, zevpn->vni); | |
7cbae20a PR |
1610 | return -1; |
1611 | } | |
6336e12b | 1612 | |
7cbae20a PR |
1613 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS); |
1614 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
1615 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
1616 | n->r_vtep_ip = zmac->fwd_info.r_vtep_ip; | |
6336e12b PR |
1617 | } |
1618 | ||
7cbae20a | 1619 | return 0; |
6336e12b PR |
1620 | } |
1621 | ||
7cbae20a PR |
1622 | /* Notify Neighbor entries to the Client, skips the GW entry */ |
1623 | static void | |
1624 | zebra_evpn_send_neigh_hash_entry_to_client(struct hash_bucket *bucket, | |
1625 | void *arg) | |
6336e12b | 1626 | { |
7cbae20a | 1627 | struct mac_walk_ctx *wctx = arg; |
72de4110 | 1628 | struct zebra_neigh *zn = bucket->data; |
3198b2b3 | 1629 | struct zebra_mac *zmac = NULL; |
6336e12b | 1630 | |
7cbae20a | 1631 | if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_DEF_GW)) |
6336e12b | 1632 | return; |
6336e12b | 1633 | |
7cbae20a PR |
1634 | if (CHECK_FLAG(zn->flags, ZEBRA_NEIGH_LOCAL) |
1635 | && IS_ZEBRA_NEIGH_ACTIVE(zn)) { | |
1636 | zmac = zebra_evpn_mac_lookup(wctx->zevpn, &zn->emac); | |
1637 | if (!zmac) | |
1638 | return; | |
6336e12b | 1639 | |
7cbae20a PR |
1640 | zebra_evpn_neigh_send_add_to_client(wctx->zevpn->vni, &zn->ip, |
1641 | &zn->emac, zn->mac, | |
1642 | zn->flags, zn->loc_seq); | |
1643 | } | |
6336e12b PR |
1644 | } |
1645 | ||
7cbae20a | 1646 | /* Iterator of a specific EVPN */ |
f6371c34 | 1647 | void zebra_evpn_send_neigh_to_client(struct zebra_evpn *zevpn) |
6336e12b | 1648 | { |
7cbae20a | 1649 | struct neigh_walk_ctx wctx; |
6336e12b | 1650 | |
6006b807 | 1651 | memset(&wctx, 0, sizeof(wctx)); |
7cbae20a | 1652 | wctx.zevpn = zevpn; |
6336e12b | 1653 | |
7cbae20a PR |
1654 | hash_iterate(zevpn->neigh_table, |
1655 | zebra_evpn_send_neigh_hash_entry_to_client, &wctx); | |
6336e12b PR |
1656 | } |
1657 | ||
7cbae20a | 1658 | void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt) |
6336e12b | 1659 | { |
7cbae20a | 1660 | struct neigh_walk_ctx *wctx = ctxt; |
72de4110 | 1661 | struct zebra_neigh *nbr; |
f6371c34 | 1662 | struct zebra_evpn *zevpn; |
7cbae20a | 1663 | char buf[INET6_ADDRSTRLEN]; |
6336e12b | 1664 | |
72de4110 | 1665 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
1666 | if (!nbr) |
1667 | return; | |
6336e12b | 1668 | |
7cbae20a | 1669 | zevpn = wctx->zevpn; |
6336e12b | 1670 | |
7cbae20a PR |
1671 | if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
1672 | return; | |
6336e12b | 1673 | |
7cbae20a PR |
1674 | if (IS_ZEBRA_DEBUG_VXLAN) { |
1675 | ipaddr2str(&nbr->ip, buf, sizeof(buf)); | |
1676 | zlog_debug("%s: clear neigh %s dup state, flags 0x%x seq %u", | |
1677 | __func__, buf, nbr->flags, nbr->loc_seq); | |
1678 | } | |
6336e12b PR |
1679 | |
1680 | UNSET_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE); | |
1681 | nbr->dad_count = 0; | |
1682 | nbr->detect_start_time.tv_sec = 0; | |
1683 | nbr->detect_start_time.tv_usec = 0; | |
1684 | nbr->dad_dup_detect_time = 0; | |
7cbae20a | 1685 | THREAD_OFF(nbr->dad_ip_auto_recovery_timer); |
6336e12b | 1686 | |
6336e12b | 1687 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_LOCAL)) { |
7cbae20a PR |
1688 | zebra_evpn_neigh_send_add_to_client(zevpn->vni, &nbr->ip, |
1689 | &nbr->emac, nbr->mac, | |
1690 | nbr->flags, nbr->loc_seq); | |
1691 | } else if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_REMOTE)) { | |
6336e12b PR |
1692 | zebra_evpn_rem_neigh_install(zevpn, nbr, false /*was_static*/); |
1693 | } | |
6336e12b PR |
1694 | } |
1695 | ||
7cbae20a PR |
1696 | /* |
1697 | * Print a specific neighbor entry. | |
1698 | */ | |
72de4110 DS |
1699 | void zebra_evpn_print_neigh(struct zebra_neigh *n, void *ctxt, |
1700 | json_object *json) | |
6336e12b | 1701 | { |
7cbae20a PR |
1702 | struct vty *vty; |
1703 | char buf1[ETHER_ADDR_STRLEN]; | |
1704 | char buf2[INET6_ADDRSTRLEN]; | |
1705 | const char *type_str; | |
1706 | const char *state_str; | |
1707 | bool flags_present = false; | |
1708 | struct zebra_vrf *zvrf = NULL; | |
1709 | struct timeval detect_start_time = {0, 0}; | |
1710 | char timebuf[MONOTIME_STRLEN]; | |
1711 | char thread_buf[THREAD_TIMER_STRLEN]; | |
a05111ba DS |
1712 | time_t uptime; |
1713 | char up_str[MONOTIME_STRLEN]; | |
6336e12b | 1714 | |
7cbae20a | 1715 | zvrf = zebra_vrf_get_evpn(); |
a05111ba DS |
1716 | uptime = monotime(NULL); |
1717 | uptime -= n->uptime; | |
1718 | ||
1719 | frrtime_to_interval(uptime, up_str, sizeof(up_str)); | |
1720 | ||
7cbae20a PR |
1721 | ipaddr2str(&n->ip, buf2, sizeof(buf2)); |
1722 | prefix_mac2str(&n->emac, buf1, sizeof(buf1)); | |
1723 | type_str = CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL) ? "local" : "remote"; | |
1724 | state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive"; | |
1725 | vty = (struct vty *)ctxt; | |
1726 | if (json == NULL) { | |
1727 | bool sync_info = false; | |
6336e12b | 1728 | |
7cbae20a PR |
1729 | vty_out(vty, "IP: %s\n", |
1730 | ipaddr2str(&n->ip, buf2, sizeof(buf2))); | |
1731 | vty_out(vty, " Type: %s\n", type_str); | |
1732 | vty_out(vty, " State: %s\n", state_str); | |
a05111ba | 1733 | vty_out(vty, " Uptime: %s\n", up_str); |
7cbae20a PR |
1734 | vty_out(vty, " MAC: %s\n", |
1735 | prefix_mac2str(&n->emac, buf1, sizeof(buf1))); | |
1736 | vty_out(vty, " Sync-info:"); | |
1737 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) { | |
1738 | vty_out(vty, " local-inactive"); | |
1739 | sync_info = true; | |
1740 | } | |
1741 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) { | |
1742 | vty_out(vty, " peer-proxy"); | |
1743 | sync_info = true; | |
1744 | } | |
1745 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) { | |
1746 | vty_out(vty, " peer-active"); | |
1747 | sync_info = true; | |
1748 | } | |
1749 | if (n->hold_timer) { | |
1750 | vty_out(vty, " (ht: %s)", | |
1751 | thread_timer_to_hhmmss(thread_buf, | |
1752 | sizeof(thread_buf), | |
1753 | n->hold_timer)); | |
1754 | sync_info = true; | |
1755 | } | |
1756 | if (!sync_info) | |
1757 | vty_out(vty, " -"); | |
1758 | vty_out(vty, "\n"); | |
1759 | } else { | |
a05111ba | 1760 | json_object_string_add(json, "uptime", up_str); |
7cbae20a PR |
1761 | json_object_string_add(json, "ip", buf2); |
1762 | json_object_string_add(json, "type", type_str); | |
1763 | json_object_string_add(json, "state", state_str); | |
1764 | json_object_string_add(json, "mac", buf1); | |
1765 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) | |
1766 | json_object_boolean_true_add(json, "localInactive"); | |
1767 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_PROXY)) | |
1768 | json_object_boolean_true_add(json, "peerProxy"); | |
1769 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ES_PEER_ACTIVE)) | |
1770 | json_object_boolean_true_add(json, "peerActive"); | |
1771 | if (n->hold_timer) | |
1772 | json_object_string_add( | |
1773 | json, "peerActiveHold", | |
1774 | thread_timer_to_hhmmss(thread_buf, | |
1775 | sizeof(thread_buf), | |
1776 | n->hold_timer)); | |
6336e12b | 1777 | } |
7cbae20a PR |
1778 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { |
1779 | if (n->mac->es) { | |
1780 | if (json) | |
1781 | json_object_string_add(json, "remoteEs", | |
1782 | n->mac->es->esi_str); | |
1783 | else | |
1784 | vty_out(vty, " Remote ES: %s\n", | |
1785 | n->mac->es->esi_str); | |
1786 | } else { | |
1787 | if (json) | |
08edf9c6 DA |
1788 | json_object_string_addf(json, "remoteVtep", |
1789 | "%pI4", &n->r_vtep_ip); | |
7cbae20a | 1790 | else |
9bcef951 MS |
1791 | vty_out(vty, " Remote VTEP: %pI4\n", |
1792 | &n->r_vtep_ip); | |
7cbae20a | 1793 | } |
6336e12b | 1794 | } |
7cbae20a PR |
1795 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) { |
1796 | if (!json) { | |
1797 | vty_out(vty, " Flags: Default-gateway"); | |
1798 | flags_present = true; | |
1799 | } else | |
1800 | json_object_boolean_true_add(json, "defaultGateway"); | |
6336e12b | 1801 | } |
7cbae20a PR |
1802 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG)) { |
1803 | if (!json) { | |
1804 | vty_out(vty, | |
1805 | flags_present ? " ,Router" : " Flags: Router"); | |
1806 | flags_present = true; | |
1807 | } | |
1808 | } | |
1809 | if (json == NULL) { | |
1810 | if (flags_present) | |
1811 | vty_out(vty, "\n"); | |
1812 | vty_out(vty, " Local Seq: %u Remote Seq: %u\n", n->loc_seq, | |
1813 | n->rem_seq); | |
6336e12b | 1814 | |
7cbae20a PR |
1815 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) { |
1816 | vty_out(vty, " Duplicate, detected at %s", | |
1817 | time_to_string(n->dad_dup_detect_time, | |
1818 | timebuf)); | |
1819 | } else if (n->dad_count) { | |
1820 | monotime_since(&n->detect_start_time, | |
1821 | &detect_start_time); | |
1822 | if (detect_start_time.tv_sec <= zvrf->dad_time) { | |
1823 | time_to_string(n->detect_start_time.tv_sec, | |
1824 | timebuf); | |
1825 | vty_out(vty, | |
1826 | " Duplicate detection started at %s, detection count %u\n", | |
1827 | timebuf, n->dad_count); | |
1828 | } | |
1829 | } | |
1830 | } else { | |
1831 | json_object_int_add(json, "localSequence", n->loc_seq); | |
1832 | json_object_int_add(json, "remoteSequence", n->rem_seq); | |
1833 | json_object_int_add(json, "detectionCount", n->dad_count); | |
1834 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1835 | json_object_boolean_true_add(json, "isDuplicate"); | |
1836 | else | |
1837 | json_object_boolean_false_add(json, "isDuplicate"); | |
1838 | } | |
6336e12b PR |
1839 | } |
1840 | ||
7cbae20a | 1841 | void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx) |
6336e12b | 1842 | { |
7cbae20a PR |
1843 | vty_out(vty, "Flags: I=local-inactive, P=peer-active, X=peer-proxy\n"); |
1844 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %s\n", -wctx->addr_width, | |
1845 | "Neighbor", "Type", "Flags", "State", "MAC", "Remote ES/VTEP", | |
1846 | "Seq #'s"); | |
6336e12b PR |
1847 | } |
1848 | ||
72de4110 DS |
1849 | static char *zebra_evpn_print_neigh_flags(struct zebra_neigh *n, |
1850 | char *flags_buf, | |
1851 | uint32_t flags_buf_sz) | |
6336e12b | 1852 | { |
7cbae20a PR |
1853 | snprintf(flags_buf, flags_buf_sz, "%s%s%s", |
1854 | (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE) ? | |
1855 | "P" : "", | |
1856 | (n->flags & ZEBRA_NEIGH_ES_PEER_PROXY) ? | |
1857 | "X" : "", | |
1858 | (n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE) ? | |
1859 | "I" : ""); | |
6336e12b | 1860 | |
7cbae20a | 1861 | return flags_buf; |
6336e12b PR |
1862 | } |
1863 | ||
7cbae20a PR |
1864 | /* |
1865 | * Print neighbor hash entry - called for display of all neighbors. | |
1866 | */ | |
1867 | void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt) | |
6336e12b | 1868 | { |
7cbae20a PR |
1869 | struct vty *vty; |
1870 | json_object *json_evpn = NULL, *json_row = NULL; | |
72de4110 | 1871 | struct zebra_neigh *n; |
7cbae20a PR |
1872 | char buf1[ETHER_ADDR_STRLEN]; |
1873 | char buf2[INET6_ADDRSTRLEN]; | |
9bcef951 | 1874 | char addr_buf[PREFIX_STRLEN]; |
7cbae20a PR |
1875 | struct neigh_walk_ctx *wctx = ctxt; |
1876 | const char *state_str; | |
1877 | char flags_buf[6]; | |
6336e12b | 1878 | |
7cbae20a PR |
1879 | vty = wctx->vty; |
1880 | json_evpn = wctx->json; | |
72de4110 | 1881 | n = (struct zebra_neigh *)bucket->data; |
6336e12b | 1882 | |
7cbae20a PR |
1883 | if (json_evpn) |
1884 | json_row = json_object_new_object(); | |
6336e12b | 1885 | |
7cbae20a PR |
1886 | prefix_mac2str(&n->emac, buf1, sizeof(buf1)); |
1887 | ipaddr2str(&n->ip, buf2, sizeof(buf2)); | |
1888 | state_str = IS_ZEBRA_NEIGH_ACTIVE(n) ? "active" : "inactive"; | |
1889 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
1890 | if (wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1891 | return; | |
6336e12b | 1892 | |
7cbae20a PR |
1893 | if (json_evpn == NULL) { |
1894 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n", | |
1895 | -wctx->addr_width, buf2, "local", | |
1896 | zebra_evpn_print_neigh_flags(n, flags_buf, | |
1897 | sizeof(flags_buf)), state_str, buf1, | |
1898 | "", n->loc_seq, n->rem_seq); | |
1899 | } else { | |
1900 | json_object_string_add(json_row, "type", "local"); | |
1901 | json_object_string_add(json_row, "state", state_str); | |
1902 | json_object_string_add(json_row, "mac", buf1); | |
1903 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) | |
1904 | json_object_boolean_true_add(json_row, | |
1905 | "defaultGateway"); | |
1906 | json_object_int_add(json_row, "localSequence", | |
1907 | n->loc_seq); | |
1908 | json_object_int_add(json_row, "remoteSequence", | |
1909 | n->rem_seq); | |
1910 | json_object_int_add(json_row, "detectionCount", | |
1911 | n->dad_count); | |
1912 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1913 | json_object_boolean_true_add(json_row, | |
1914 | "isDuplicate"); | |
1915 | else | |
1916 | json_object_boolean_false_add(json_row, | |
1917 | "isDuplicate"); | |
1918 | } | |
1919 | wctx->count++; | |
1920 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
1921 | if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1922 | && !IPV4_ADDR_SAME(&n->r_vtep_ip, &wctx->r_vtep_ip)) | |
6336e12b PR |
1923 | return; |
1924 | ||
7cbae20a PR |
1925 | if (json_evpn == NULL) { |
1926 | if ((wctx->flags & SHOW_REMOTE_NEIGH_FROM_VTEP) | |
1927 | && (wctx->count == 0)) | |
1928 | zebra_evpn_print_neigh_hdr(vty, wctx); | |
9bcef951 MS |
1929 | |
1930 | if (n->mac->es == NULL) | |
1931 | inet_ntop(AF_INET, &n->r_vtep_ip, | |
1932 | addr_buf, sizeof(addr_buf)); | |
1933 | ||
7cbae20a PR |
1934 | vty_out(vty, "%*s %-6s %-5s %-8s %-17s %-30s %u/%u\n", |
1935 | -wctx->addr_width, buf2, "remote", | |
1936 | zebra_evpn_print_neigh_flags(n, flags_buf, | |
1937 | sizeof(flags_buf)), state_str, buf1, | |
9bcef951 | 1938 | n->mac->es ? n->mac->es->esi_str : addr_buf, |
7cbae20a PR |
1939 | n->loc_seq, n->rem_seq); |
1940 | } else { | |
1941 | json_object_string_add(json_row, "type", "remote"); | |
1942 | json_object_string_add(json_row, "state", state_str); | |
1943 | json_object_string_add(json_row, "mac", buf1); | |
1944 | if (n->mac->es) | |
1945 | json_object_string_add(json_row, "remoteEs", | |
1946 | n->mac->es->esi_str); | |
1947 | else | |
08edf9c6 DA |
1948 | json_object_string_addf(json_row, "remoteVtep", |
1949 | "%pI4", &n->r_vtep_ip); | |
7cbae20a PR |
1950 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW)) |
1951 | json_object_boolean_true_add(json_row, | |
1952 | "defaultGateway"); | |
1953 | json_object_int_add(json_row, "localSequence", | |
1954 | n->loc_seq); | |
1955 | json_object_int_add(json_row, "remoteSequence", | |
1956 | n->rem_seq); | |
1957 | json_object_int_add(json_row, "detectionCount", | |
1958 | n->dad_count); | |
1959 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
1960 | json_object_boolean_true_add(json_row, | |
1961 | "isDuplicate"); | |
1962 | else | |
1963 | json_object_boolean_false_add(json_row, | |
1964 | "isDuplicate"); | |
1965 | } | |
1966 | wctx->count++; | |
6336e12b | 1967 | } |
6336e12b | 1968 | |
7cbae20a PR |
1969 | if (json_evpn) |
1970 | json_object_object_add(json_evpn, buf2, json_row); | |
6336e12b PR |
1971 | } |
1972 | ||
7cbae20a PR |
1973 | /* |
1974 | * Print neighbor hash entry in detail - called for display of all neighbors. | |
1975 | */ | |
1976 | void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt) | |
6336e12b | 1977 | { |
7cbae20a PR |
1978 | struct vty *vty; |
1979 | json_object *json_evpn = NULL, *json_row = NULL; | |
72de4110 | 1980 | struct zebra_neigh *n; |
7cbae20a PR |
1981 | char buf[INET6_ADDRSTRLEN]; |
1982 | struct neigh_walk_ctx *wctx = ctxt; | |
6336e12b | 1983 | |
7cbae20a PR |
1984 | vty = wctx->vty; |
1985 | json_evpn = wctx->json; | |
72de4110 | 1986 | n = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
1987 | if (!n) |
1988 | return; | |
6336e12b | 1989 | |
7cbae20a PR |
1990 | ipaddr2str(&n->ip, buf, sizeof(buf)); |
1991 | if (json_evpn) | |
1992 | json_row = json_object_new_object(); | |
6336e12b | 1993 | |
7cbae20a | 1994 | zebra_evpn_print_neigh(n, vty, json_row); |
6336e12b | 1995 | |
7cbae20a PR |
1996 | if (json_evpn) |
1997 | json_object_object_add(json_evpn, buf, json_row); | |
6336e12b PR |
1998 | } |
1999 | ||
7cbae20a | 2000 | void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt) |
6336e12b | 2001 | { |
72de4110 | 2002 | struct zebra_neigh *nbr; |
6336e12b | 2003 | |
72de4110 | 2004 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
2005 | if (!nbr) |
2006 | return; | |
6336e12b | 2007 | |
7cbae20a PR |
2008 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
2009 | zebra_evpn_print_neigh_hash(bucket, ctxt); | |
6336e12b PR |
2010 | } |
2011 | ||
7cbae20a PR |
2012 | void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket, |
2013 | void *ctxt) | |
6336e12b | 2014 | { |
72de4110 | 2015 | struct zebra_neigh *nbr; |
6336e12b | 2016 | |
72de4110 | 2017 | nbr = (struct zebra_neigh *)bucket->data; |
7cbae20a PR |
2018 | if (!nbr) |
2019 | return; | |
6336e12b | 2020 | |
7cbae20a PR |
2021 | if (CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) |
2022 | zebra_evpn_print_neigh_hash_detail(bucket, ctxt); | |
6336e12b | 2023 | } |
036daaca | 2024 | |
f6371c34 | 2025 | void zebra_evpn_neigh_remote_macip_add(struct zebra_evpn *zevpn, |
272e11bf | 2026 | struct zebra_vrf *zvrf, |
1a3bd37f | 2027 | const struct ipaddr *ipaddr, |
3198b2b3 DS |
2028 | struct zebra_mac *mac, |
2029 | struct in_addr vtep_ip, uint8_t flags, | |
2030 | uint32_t seq) | |
036daaca | 2031 | { |
72de4110 | 2032 | struct zebra_neigh *n; |
036daaca | 2033 | int update_neigh = 0; |
3198b2b3 | 2034 | struct zebra_mac *old_mac = NULL; |
036daaca PR |
2035 | bool old_static = false; |
2036 | bool do_dad = false; | |
2037 | bool is_dup_detect = false; | |
2038 | bool is_router; | |
2039 | ||
2bdd4461 | 2040 | assert(mac); |
036daaca PR |
2041 | is_router = !!CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG); |
2042 | ||
2043 | /* Check if the remote neighbor itself is unknown or has a | |
2044 | * change. If so, create or update and then install the entry. | |
2045 | */ | |
2046 | n = zebra_evpn_neigh_lookup(zevpn, ipaddr); | |
2047 | if (!n || !CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE) | |
2048 | || is_router != !!CHECK_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG) | |
2049 | || (memcmp(&n->emac, &mac->macaddr, sizeof(struct ethaddr)) != 0) | |
2050 | || !IPV4_ADDR_SAME(&n->r_vtep_ip, &vtep_ip) || seq != n->rem_seq) | |
2051 | update_neigh = 1; | |
2052 | ||
2053 | if (update_neigh) { | |
2054 | if (!n) { | |
2055 | n = zebra_evpn_neigh_add(zevpn, ipaddr, &mac->macaddr, | |
2056 | mac, 0); | |
036daaca | 2057 | } else { |
036daaca PR |
2058 | /* When host moves but changes its (MAC,IP) |
2059 | * binding, BGP may install a MACIP entry that | |
2060 | * corresponds to "older" location of the host | |
2061 | * in transient situations (because {IP1,M1} | |
2062 | * is a different route from {IP1,M2}). Check | |
2063 | * the sequence number and ignore this update | |
2064 | * if appropriate. | |
2065 | */ | |
16de1338 AK |
2066 | |
2067 | if (!zebra_evpn_neigh_is_bgp_seq_ok( | |
2068 | zevpn, n, &mac->macaddr, seq, false)) | |
036daaca | 2069 | return; |
036daaca PR |
2070 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { |
2071 | old_static = zebra_evpn_neigh_is_static(n); | |
2072 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
2073 | zlog_debug( | |
ef7b8be4 DL |
2074 | "sync->remote neigh vni %u ip %pIA mac %pEA seq %d f0x%x", |
2075 | n->zevpn->vni, &n->ip, &n->emac, | |
036daaca | 2076 | seq, n->flags); |
036daaca | 2077 | if (IS_ZEBRA_NEIGH_ACTIVE(n)) |
fb8f609d AK |
2078 | zebra_evpn_neigh_send_del_to_client( |
2079 | zevpn->vni, &n->ip, &n->emac, | |
2080 | n->flags, n->state, | |
2081 | false /*force*/); | |
bda6be1c | 2082 | zebra_evpn_neigh_clear_sync_info(n); |
036daaca PR |
2083 | } |
2084 | if (memcmp(&n->emac, &mac->macaddr, | |
2085 | sizeof(struct ethaddr)) | |
2086 | != 0) { | |
2087 | /* update neigh list for macs */ | |
2088 | old_mac = | |
2089 | zebra_evpn_mac_lookup(zevpn, &n->emac); | |
2090 | if (old_mac) { | |
2091 | listnode_delete(old_mac->neigh_list, n); | |
2092 | n->mac = NULL; | |
2093 | zebra_evpn_deref_ip2mac(zevpn, old_mac); | |
2094 | } | |
2095 | n->mac = mac; | |
2096 | listnode_add_sort(mac->neigh_list, n); | |
2097 | memcpy(&n->emac, &mac->macaddr, ETH_ALEN); | |
2098 | ||
2099 | /* Check Neigh's curent state is local | |
2100 | * (this is the case where neigh/host has moved | |
2101 | * from L->R) and check previous detction | |
2102 | * started via local learning. | |
2103 | * | |
2104 | * RFC-7432: A PE/VTEP that detects a MAC | |
2105 | * mobilit event via local learning starts | |
2106 | * an M-second timer. | |
2107 | * VTEP-IP or seq. change along is not | |
2108 | * considered for dup. detection. | |
2109 | * | |
2110 | * Mobilty event scenario-B IP-MAC binding | |
2111 | * changed. | |
2112 | */ | |
2113 | if ((!CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) | |
2114 | && n->dad_count) | |
2115 | do_dad = true; | |
2116 | } | |
2117 | } | |
2118 | ||
2119 | /* Set "remote" forwarding info. */ | |
2120 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_LOCAL_FLAGS); | |
2121 | n->r_vtep_ip = vtep_ip; | |
2122 | SET_FLAG(n->flags, ZEBRA_NEIGH_REMOTE); | |
2123 | ||
2124 | /* Set router flag (R-bit) to this Neighbor entry */ | |
2125 | if (CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_ROUTER_FLAG)) | |
2126 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2127 | else | |
2128 | UNSET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2129 | ||
2130 | /* Check old or new MAC detected as duplicate, | |
2131 | * inherit duplicate flag to this neigh. | |
2132 | */ | |
2133 | if (zebra_evpn_ip_inherit_dad_from_mac(zvrf, old_mac, mac, n)) { | |
2134 | flog_warn( | |
2135 | EC_ZEBRA_DUP_IP_INHERIT_DETECTED, | |
ef7b8be4 DL |
2136 | "VNI %u: MAC %pEA IP %pIA detected as duplicate during remote update, inherit duplicate from MAC", |
2137 | zevpn->vni, &mac->macaddr, &n->ip); | |
036daaca PR |
2138 | } |
2139 | ||
2140 | /* Check duplicate address detection for IP */ | |
2141 | zebra_evpn_dup_addr_detect_for_neigh( | |
2142 | zvrf, n, n->r_vtep_ip, do_dad, &is_dup_detect, false); | |
2143 | /* Install the entry. */ | |
2144 | if (!is_dup_detect) | |
2145 | zebra_evpn_rem_neigh_install(zevpn, n, old_static); | |
2146 | } | |
2147 | ||
036daaca PR |
2148 | /* Update seq number. */ |
2149 | n->rem_seq = seq; | |
2150 | } | |
224315f3 | 2151 | |
f6371c34 DS |
2152 | int zebra_evpn_neigh_gw_macip_add(struct interface *ifp, |
2153 | struct zebra_evpn *zevpn, struct ipaddr *ip, | |
3198b2b3 | 2154 | struct zebra_mac *mac) |
224315f3 | 2155 | { |
72de4110 | 2156 | struct zebra_neigh *n; |
224315f3 | 2157 | |
2bdd4461 | 2158 | assert(mac); |
224315f3 PR |
2159 | |
2160 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
97511d01 | 2161 | if (!n) |
224315f3 | 2162 | n = zebra_evpn_neigh_add(zevpn, ip, &mac->macaddr, mac, 0); |
224315f3 PR |
2163 | |
2164 | /* Set "local" forwarding info. */ | |
2165 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL); | |
2166 | ZEBRA_NEIGH_SET_ACTIVE(n); | |
2167 | memcpy(&n->emac, &mac->macaddr, ETH_ALEN); | |
2168 | n->ifindex = ifp->ifindex; | |
2169 | ||
2170 | /* Only advertise in BGP if the knob is enabled */ | |
2171 | if (advertise_gw_macip_enabled(zevpn)) { | |
2172 | ||
224315f3 PR |
2173 | SET_FLAG(n->flags, ZEBRA_NEIGH_DEF_GW); |
2174 | /* Set Router flag (R-bit) */ | |
2175 | if (ip->ipa_type == IPADDR_V6) | |
2176 | SET_FLAG(n->flags, ZEBRA_NEIGH_ROUTER_FLAG); | |
2177 | ||
2178 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2179 | zlog_debug( | |
ef7b8be4 | 2180 | "SVI %s(%u) L2-VNI %u, sending GW MAC %pEA IP %pIA add to BGP with flags 0x%x", |
224315f3 | 2181 | ifp->name, ifp->ifindex, zevpn->vni, |
ef7b8be4 | 2182 | &mac->macaddr, ip, n->flags); |
224315f3 PR |
2183 | |
2184 | zebra_evpn_neigh_send_add_to_client( | |
2185 | zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq); | |
2186 | } else if (advertise_svi_macip_enabled(zevpn)) { | |
2187 | ||
2188 | SET_FLAG(n->flags, ZEBRA_NEIGH_SVI_IP); | |
2189 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2190 | zlog_debug( | |
ef7b8be4 | 2191 | "SVI %s(%u) L2-VNI %u, sending SVI MAC %pEA IP %pIA add to BGP with flags 0x%x", |
224315f3 | 2192 | ifp->name, ifp->ifindex, zevpn->vni, |
ef7b8be4 | 2193 | &mac->macaddr, ip, n->flags); |
224315f3 PR |
2194 | |
2195 | zebra_evpn_neigh_send_add_to_client( | |
2196 | zevpn->vni, ip, &n->emac, n->mac, n->flags, n->loc_seq); | |
2197 | } | |
2198 | ||
2199 | return 0; | |
2200 | } | |
32fe7dfd | 2201 | |
f6371c34 | 2202 | void zebra_evpn_neigh_remote_uninstall(struct zebra_evpn *zevpn, |
72de4110 DS |
2203 | struct zebra_vrf *zvrf, |
2204 | struct zebra_neigh *n, | |
3198b2b3 | 2205 | struct zebra_mac *mac, |
1a3bd37f | 2206 | const struct ipaddr *ipaddr) |
32fe7dfd | 2207 | { |
32fe7dfd PR |
2208 | if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE) |
2209 | && CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE) | |
2210 | && (memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN) == 0)) { | |
2211 | struct interface *vlan_if; | |
2212 | ||
2213 | vlan_if = zevpn_map_to_svi(zevpn); | |
2214 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2215 | zlog_debug( | |
ef7b8be4 DL |
2216 | "%s: IP %pIA (flags 0x%x intf %s) is remote and duplicate, read kernel for local entry", |
2217 | __func__, ipaddr, n->flags, | |
2218 | vlan_if ? vlan_if->name : "Unknown"); | |
32fe7dfd PR |
2219 | if (vlan_if) |
2220 | neigh_read_specific_ip(ipaddr, vlan_if); | |
2221 | } | |
2222 | ||
2223 | /* When the MAC changes for an IP, it is possible the | |
2224 | * client may update the new MAC before trying to delete the | |
2225 | * "old" neighbor (as these are two different MACIP routes). | |
2226 | * Do the delete only if the MAC matches. | |
2227 | */ | |
2228 | if (!memcmp(n->emac.octet, mac->macaddr.octet, ETH_ALEN)) { | |
2229 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) { | |
2230 | zebra_evpn_sync_neigh_del(n); | |
2231 | } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
2232 | zebra_evpn_neigh_uninstall(zevpn, n); | |
2233 | zebra_evpn_neigh_del(zevpn, n); | |
2234 | zebra_evpn_deref_ip2mac(zevpn, mac); | |
2235 | } | |
2236 | } | |
2237 | } | |
33064a62 | 2238 | |
f6371c34 | 2239 | int zebra_evpn_neigh_del_ip(struct zebra_evpn *zevpn, const struct ipaddr *ip) |
33064a62 | 2240 | { |
72de4110 | 2241 | struct zebra_neigh *n; |
3198b2b3 | 2242 | struct zebra_mac *zmac; |
33064a62 PR |
2243 | bool old_bgp_ready; |
2244 | bool new_bgp_ready; | |
33064a62 PR |
2245 | struct zebra_vrf *zvrf; |
2246 | ||
2247 | /* If entry doesn't exist, nothing to do. */ | |
2248 | n = zebra_evpn_neigh_lookup(zevpn, ip); | |
2249 | if (!n) | |
2250 | return 0; | |
2251 | ||
2252 | zmac = zebra_evpn_mac_lookup(zevpn, &n->emac); | |
2253 | if (!zmac) { | |
2254 | if (IS_ZEBRA_DEBUG_VXLAN) | |
2255 | zlog_debug( | |
ef7b8be4 DL |
2256 | "Trying to del a neigh %pIA without a mac %pEA on VNI %u", |
2257 | ip, &n->emac, | |
33064a62 PR |
2258 | zevpn->vni); |
2259 | ||
2260 | return 0; | |
2261 | } | |
2262 | ||
2263 | /* If it is a remote entry, the kernel has aged this out or someone has | |
32367e7a | 2264 | * deleted it, it needs to be re-installed as FRR is the owner. |
33064a62 PR |
2265 | */ |
2266 | if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) { | |
2267 | zebra_evpn_rem_neigh_install(zevpn, n, false /*was_static*/); | |
2268 | return 0; | |
2269 | } | |
2270 | ||
2271 | /* if this is a sync entry it cannot be dropped re-install it in | |
2272 | * the dataplane | |
2273 | */ | |
2274 | old_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
2275 | if (zebra_evpn_neigh_is_static(n)) { | |
2276 | if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH) | |
ef7b8be4 DL |
2277 | zlog_debug("re-add sync neigh vni %u ip %pIA mac %pEA 0x%x", |
2278 | n->zevpn->vni, &n->ip, &n->emac, | |
33064a62 PR |
2279 | n->flags); |
2280 | ||
2281 | if (!CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE)) | |
2282 | SET_FLAG(n->flags, ZEBRA_NEIGH_LOCAL_INACTIVE); | |
2283 | /* inform-bgp about change in local-activity if any */ | |
2284 | new_bgp_ready = zebra_evpn_neigh_is_ready_for_bgp(n); | |
2285 | zebra_evpn_neigh_send_add_del_to_client(n, old_bgp_ready, | |
2286 | new_bgp_ready); | |
2287 | ||
2288 | /* re-install the entry in the kernel */ | |
2289 | zebra_evpn_sync_neigh_dp_install(n, false /* set_inactive */, | |
2290 | false /* force_clear_static */, | |
2291 | __func__); | |
2292 | ||
2293 | return 0; | |
2294 | } | |
2295 | ||
096f7609 | 2296 | zvrf = zevpn->vxlan_if->vrf->info; |
33064a62 PR |
2297 | if (!zvrf) { |
2298 | zlog_debug("%s: VNI %u vrf lookup failed.", __func__, | |
2299 | zevpn->vni); | |
2300 | return -1; | |
2301 | } | |
2302 | ||
2303 | /* In case of feeze action, if local neigh is in duplicate state, | |
2304 | * Mark the Neigh as inactive before sending delete request to BGPd, | |
2305 | * If BGPd has remote entry, it will re-install | |
2306 | */ | |
2307 | if (zvrf->dad_freeze && CHECK_FLAG(n->flags, ZEBRA_NEIGH_DUPLICATE)) | |
2308 | ZEBRA_NEIGH_SET_INACTIVE(n); | |
2309 | ||
2310 | /* Remove neighbor from BGP. */ | |
2311 | zebra_evpn_neigh_send_del_to_client(zevpn->vni, &n->ip, &n->emac, | |
2312 | n->flags, n->state, | |
2313 | false /* force */); | |
2314 | ||
2315 | /* Delete this neighbor entry. */ | |
2316 | zebra_evpn_neigh_del(zevpn, n); | |
2317 | ||
2318 | /* see if the AUTO mac needs to be deleted */ | |
2319 | if (CHECK_FLAG(zmac->flags, ZEBRA_MAC_AUTO) | |
243b74ed | 2320 | && !zebra_evpn_mac_in_use(zmac)) |
33064a62 PR |
2321 | zebra_evpn_mac_del(zevpn, zmac); |
2322 | ||
2323 | return 0; | |
2324 | } |