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