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