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