2 * Zebra EVPN for VxLAN code
3 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 * This file is part of FRR.
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
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.
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
37 #include "zebra/rib.h"
39 #include "zebra/zebra_ns.h"
40 #include "zebra/zserv.h"
41 #include "zebra/debug.h"
42 #include "zebra/interface.h"
43 #include "zebra/zebra_vrf.h"
44 #include "zebra/rt_netlink.h"
45 #include "zebra/zebra_vxlan_private.h"
46 #include "zebra/zebra_vxlan.h"
47 #include "zebra/zebra_memory.h"
48 #include "zebra/zebra_l2.h"
50 DEFINE_MTYPE_STATIC(ZEBRA
, HOST_PREFIX
, "host prefix");
51 DEFINE_MTYPE_STATIC(ZEBRA
, ZVNI
, "VNI hash");
52 DEFINE_MTYPE_STATIC(ZEBRA
, ZL3VNI
, "L3 VNI hash");
53 DEFINE_MTYPE_STATIC(ZEBRA
, ZVNI_VTEP
, "VNI remote VTEP");
54 DEFINE_MTYPE_STATIC(ZEBRA
, MAC
, "VNI MAC");
55 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "VNI Neighbor");
60 /* static function declarations */
61 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
63 static void zvni_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
);
64 static void zvni_print_neigh_hash(struct hash_backet
*backet
, void *ctxt
);
65 static void zvni_print_neigh_hash_all_vni(struct hash_backet
*backet
,
67 static void zl3vni_print_nh(zebra_neigh_t
*n
, struct vty
*vty
,
69 static void zl3vni_print_rmac(zebra_mac_t
*zrmac
, struct vty
*vty
,
71 static void zvni_print_mac(zebra_mac_t
*mac
, void *ctxt
);
72 static void zvni_print_mac_hash(struct hash_backet
*backet
, void *ctxt
);
73 static void zvni_print_mac_hash_all_vni(struct hash_backet
*backet
, void *ctxt
);
74 static void zvni_print(zebra_vni_t
*zvni
, void **ctxt
);
75 static void zvni_print_hash(struct hash_backet
*backet
, void *ctxt
[]);
77 static int zvni_macip_send_msg_to_client(vni_t vni
, struct ethaddr
*macaddr
,
78 struct ipaddr
*ip
, u_char flags
,
80 static unsigned int neigh_hash_keymake(void *p
);
81 static int neigh_cmp(const void *p1
, const void *p2
);
82 static void *zvni_neigh_alloc(void *p
);
83 static zebra_neigh_t
*zvni_neigh_add(zebra_vni_t
*zvni
, struct ipaddr
*ip
,
85 static int zvni_neigh_del(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
86 static int zvni_neigh_del_hash_entry(struct hash_backet
*backet
, void *arg
);
87 static void zvni_neigh_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
88 struct in_addr
*r_vtep_ip
);
89 static void zvni_neigh_del_all(zebra_vni_t
*zvni
, int uninstall
, int upd_client
,
91 static zebra_neigh_t
*zvni_neigh_lookup(zebra_vni_t
*zvni
, struct ipaddr
*ip
);
92 static int zvni_neigh_send_add_to_client(vni_t vni
, struct ipaddr
*ip
,
93 struct ethaddr
*macaddr
, u_char flags
);
94 static int zvni_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
95 struct ethaddr
*macaddr
, u_char flags
);
96 static int zvni_neigh_install(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
97 static int zvni_neigh_uninstall(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
98 static zebra_vni_t
*zvni_from_svi(struct interface
*ifp
,
99 struct interface
*br_if
);
100 static struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
);
102 /* l3-vni next-hop neigh related APIs */
103 static zebra_neigh_t
*zl3vni_nh_lookup(zebra_l3vni_t
*zl3vni
,
105 static void *zl3vni_nh_alloc(void *p
);
106 static zebra_neigh_t
*zl3vni_nh_add(zebra_l3vni_t
*zl3vni
,
107 struct ipaddr
*vtep_ip
,
108 struct ethaddr
*rmac
);
109 static int zl3vni_nh_del(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
110 static int zl3vni_nh_install(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
111 static int zl3vni_nh_uninstall(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
113 /* l3-vni rmac related APIs */
114 static void zl3vni_print_rmac_hash(struct hash_backet
*, void *);
115 static zebra_mac_t
*zl3vni_rmac_lookup(zebra_l3vni_t
*zl3vni
,
116 struct ethaddr
*rmac
);
117 static void *zl3vni_rmac_alloc(void *p
);
118 static zebra_mac_t
*zl3vni_rmac_add(zebra_l3vni_t
*zl3vni
,
119 struct ethaddr
*rmac
);
120 static int zl3vni_rmac_del(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
);
121 static int zl3vni_rmac_install(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
);
122 static int zl3vni_rmac_uninstall(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
);
124 /* l3-vni related APIs*/
125 static zebra_l3vni_t
*zl3vni_lookup(vni_t vni
);
126 static void *zl3vni_alloc(void *p
);
127 static zebra_l3vni_t
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
128 static int zl3vni_del(zebra_l3vni_t
*zl3vni
);
129 static zebra_l3vni_t
*zl3vni_from_vrf(vrf_id_t
);
130 static struct interface
*zl3vni_map_to_svi_if(zebra_l3vni_t
*zl3vni
);
131 static struct interface
*zl3vni_map_to_vxlan_if(zebra_l3vni_t
*zl3vni
);
132 static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t
*zl3vni
);
133 static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t
*zl3vni
);
135 static unsigned int mac_hash_keymake(void *p
);
136 static int mac_cmp(const void *p1
, const void *p2
);
137 static void *zvni_mac_alloc(void *p
);
138 static zebra_mac_t
*zvni_mac_add(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
139 static int zvni_mac_del(zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
140 static int zvni_mac_del_hash_entry(struct hash_backet
*backet
, void *arg
);
141 static void zvni_mac_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
142 struct in_addr
*r_vtep_ip
);
143 static void zvni_mac_del_all(zebra_vni_t
*zvni
, int uninstall
, int upd_client
,
145 static zebra_mac_t
*zvni_mac_lookup(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
146 static int zvni_mac_send_add_to_client(vni_t vni
, struct ethaddr
*macaddr
,
148 static int zvni_mac_send_del_to_client(vni_t vni
, struct ethaddr
*macaddr
,
150 static zebra_vni_t
*zvni_map_vlan(struct interface
*ifp
,
151 struct interface
*br_if
, vlanid_t vid
);
152 static int zvni_mac_install(zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
153 static int zvni_mac_uninstall(zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
);
154 static void zvni_install_mac_hash(struct hash_backet
*backet
, void *ctxt
);
156 static unsigned int vni_hash_keymake(void *p
);
157 static int vni_hash_cmp(const void *p1
, const void *p2
);
158 static void *zvni_alloc(void *p
);
159 static zebra_vni_t
*zvni_lookup(vni_t vni
);
160 static zebra_vni_t
*zvni_add(vni_t vni
);
161 static int zvni_del(zebra_vni_t
*zvni
);
162 static int zvni_send_add_to_client(zebra_vni_t
*zvni
);
163 static int zvni_send_del_to_client(vni_t vni
);
164 static void zvni_build_hash_table();
165 static int zvni_vtep_match(struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
);
166 static zebra_vtep_t
*zvni_vtep_find(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
167 static zebra_vtep_t
*zvni_vtep_add(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
168 static int zvni_vtep_del(zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
);
169 static int zvni_vtep_del_all(zebra_vni_t
*zvni
, int uninstall
);
170 static int zvni_vtep_install(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
171 static int zvni_vtep_uninstall(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
172 static int zvni_del_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
);
173 static int zvni_add_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
);
174 static int zvni_gw_macip_add(struct interface
*ifp
, zebra_vni_t
*zvni
,
175 struct ethaddr
*macaddr
, struct ipaddr
*ip
);
176 static int zvni_gw_macip_del(struct interface
*ifp
, zebra_vni_t
*zvni
,
178 struct interface
*zebra_get_vrr_intf_for_svi(struct interface
*ifp
);
179 static int advertise_gw_macip_enabled(zebra_vni_t
*zvni
);
180 static void zvni_deref_ip2mac(zebra_vni_t
*zvni
, zebra_mac_t
*mac
,
183 /* Private functions */
186 * Return number of valid MACs in a VNI's MAC hash table - all
187 * remote MACs and non-internal (auto) local MACs count.
189 static u_int32_t
num_valid_macs(zebra_vni_t
*zvni
)
192 u_int32_t num_macs
= 0;
194 struct hash_backet
*hb
;
197 hash
= zvni
->mac_table
;
200 for (i
= 0; i
< hash
->size
; i
++) {
201 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
202 mac
= (zebra_mac_t
*)hb
->data
;
203 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
204 || !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
212 static int advertise_gw_macip_enabled(zebra_vni_t
*zvni
)
214 struct zebra_vrf
*zvrf
;
216 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
217 if (zvrf
&& zvrf
->advertise_gw_macip
)
220 if (zvni
&& zvni
->advertise_gw_macip
)
227 * Helper function to determine maximum width of neighbor IP address for
228 * display - just because we're dealing with IPv6 addresses that can
231 static void zvni_find_neigh_addr_width(struct hash_backet
*backet
, void *ctxt
)
234 char buf
[INET6_ADDRSTRLEN
];
235 struct neigh_walk_ctx
*wctx
= ctxt
;
238 n
= (zebra_neigh_t
*)backet
->data
;
242 ipaddr2str(&n
->ip
, buf
, sizeof(buf
)), width
= strlen(buf
);
243 if (width
> wctx
->addr_width
)
244 wctx
->addr_width
= width
;
248 * Print a specific neighbor entry.
250 static void zvni_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
)
253 char buf1
[ETHER_ADDR_STRLEN
];
254 char buf2
[INET6_ADDRSTRLEN
];
256 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
257 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
258 vty
= (struct vty
*)ctxt
;
260 vty_out(vty
, "IP: %s\n",
261 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
262 vty_out(vty
, " MAC: %s",
263 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
265 json_object_string_add(json
, "ip", buf2
);
266 json_object_string_add(json
, "mac", buf1
);
268 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
270 vty_out(vty
, " Remote VTEP: %s",
271 inet_ntoa(n
->r_vtep_ip
));
273 json_object_string_add(json
, "remoteVtep",
274 inet_ntoa(n
->r_vtep_ip
));
276 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
279 vty_out(vty
, " State: %s",
280 IS_ZEBRA_NEIGH_ACTIVE(n
) ? "Active"
284 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
286 vty_out(vty
, " Default-gateway");
288 json_object_boolean_true_add(json
, "defaultGateway");
295 * Print neighbor hash entry - called for display of all neighbors.
297 static void zvni_print_neigh_hash(struct hash_backet
*backet
, void *ctxt
)
300 json_object
*json_vni
= NULL
, *json_row
= NULL
;
302 char buf1
[ETHER_ADDR_STRLEN
];
303 char buf2
[INET6_ADDRSTRLEN
];
304 struct neigh_walk_ctx
*wctx
= ctxt
;
307 json_vni
= wctx
->json
;
308 n
= (zebra_neigh_t
*)backet
->data
;
313 json_row
= json_object_new_object();
315 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
316 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
317 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)
318 && !(wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)) {
319 if (json_vni
== NULL
) {
320 vty_out(vty
, "%*s %-6s %-17s\n", -wctx
->addr_width
,
321 buf2
, "local", buf1
);
323 json_object_string_add(json_row
, "type", "local");
324 json_object_string_add(json_row
, "mac", buf1
);
328 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
) {
329 if (IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
)) {
330 if (json_vni
== NULL
) {
331 if (wctx
->count
== 0)
333 "%*s %-6s %-17s %-21s\n",
336 "MAC", "Remote VTEP");
337 vty_out(vty
, "%*s %-6s %-17s %-21s\n",
338 -wctx
->addr_width
, buf2
,
340 inet_ntoa(n
->r_vtep_ip
));
342 json_object_string_add(json_row
, "type",
344 json_object_string_add(json_row
, "mac",
346 json_object_string_add(
347 json_row
, "remoteVtep",
348 inet_ntoa(n
->r_vtep_ip
));
353 if (json_vni
== NULL
) {
354 vty_out(vty
, "%*s %-6s %-17s %-21s\n",
355 -wctx
->addr_width
, buf2
, "remote", buf1
,
356 inet_ntoa(n
->r_vtep_ip
));
358 json_object_string_add(json_row
, "type",
360 json_object_string_add(json_row
, "mac", buf1
);
361 json_object_string_add(json_row
, "remoteVtep",
362 inet_ntoa(n
->r_vtep_ip
));
369 json_object_object_add(json_vni
, buf2
, json_row
);
373 * Print neighbors for all VNI.
375 static void zvni_print_neigh_hash_all_vni(struct hash_backet
*backet
,
379 json_object
*json
= NULL
, *json_vni
= NULL
;
382 struct neigh_walk_ctx wctx
;
383 char vni_str
[VNI_STR_LEN
];
385 vty
= (struct vty
*)args
[0];
386 json
= (json_object
*)args
[1];
388 zvni
= (zebra_vni_t
*)backet
->data
;
391 vty_out(vty
, "{}\n");
394 num_neigh
= hashcount(zvni
->neigh_table
);
397 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
398 zvni
->vni
, num_neigh
);
400 json_vni
= json_object_new_object();
401 json_object_int_add(json_vni
, "numArpNd", num_neigh
);
402 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
406 json_object_object_add(json
, vni_str
, json_vni
);
410 /* Since we have IPv6 addresses to deal with which can vary widely in
411 * size, we try to be a bit more elegant in display by first computing
414 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
417 wctx
.addr_width
= 15;
418 wctx
.json
= json_vni
;
419 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
422 vty_out(vty
, "%*s %-6s %-17s %-21s\n", -wctx
.addr_width
, "IP",
423 "Type", "MAC", "Remote VTEP");
424 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
427 json_object_object_add(json
, vni_str
, json_vni
);
430 /* print a specific next hop for an l3vni */
431 static void zl3vni_print_nh(zebra_neigh_t
*n
, struct vty
*vty
,
434 char buf1
[ETHER_ADDR_STRLEN
];
435 char buf2
[INET6_ADDRSTRLEN
];
436 struct listnode
*node
= NULL
;
437 struct prefix
*p
= NULL
;
438 json_object
*json_hosts
= NULL
;
441 vty_out(vty
, "Ip: %s\n",
442 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
443 vty_out(vty
, " RMAC: %s\n",
444 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
445 vty_out(vty
, " Refcount: %d\n", listcount(n
->host_list
));
446 vty_out(vty
, " Prefixes:\n");
447 for (ALL_LIST_ELEMENTS_RO(n
->host_list
, node
, p
))
448 vty_out(vty
, " %s\n",
449 prefix2str(p
, buf2
, sizeof(buf2
)));
451 json_hosts
= json_object_new_array();
452 json_object_string_add(
453 json
, "ip", ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)));
454 json_object_string_add(
456 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)));
457 json_object_int_add(json
, "refCount", listcount(n
->host_list
));
458 for (ALL_LIST_ELEMENTS_RO(n
->host_list
, node
, p
))
459 json_object_array_add(json_hosts
,
460 json_object_new_string(prefix2str(
461 p
, buf2
, sizeof(buf2
))));
462 json_object_object_add(json
, "prefixList", json_hosts
);
466 /* Print a specific RMAC entry */
467 static void zl3vni_print_rmac(zebra_mac_t
*zrmac
, struct vty
*vty
,
470 char buf1
[ETHER_ADDR_STRLEN
];
471 char buf2
[PREFIX_STRLEN
];
472 struct listnode
*node
= NULL
;
473 struct prefix
*p
= NULL
;
474 json_object
*json_hosts
= NULL
;
477 vty_out(vty
, "MAC: %s\n",
478 prefix_mac2str(&zrmac
->macaddr
, buf1
, sizeof(buf1
)));
479 vty_out(vty
, " Remote VTEP: %s\n",
480 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
481 vty_out(vty
, " Refcount: %d\n", listcount(zrmac
->host_list
));
482 vty_out(vty
, " Prefixes:\n");
483 for (ALL_LIST_ELEMENTS_RO(zrmac
->host_list
, node
, p
))
484 vty_out(vty
, " %s\n",
485 prefix2str(p
, buf2
, sizeof(buf2
)));
487 json_hosts
= json_object_new_array();
488 json_object_string_add(
490 prefix_mac2str(&zrmac
->macaddr
, buf1
, sizeof(buf1
)));
491 json_object_string_add(json
, "vtepIp",
492 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
493 json_object_int_add(json
, "refCount",
494 listcount(zrmac
->host_list
));
495 for (ALL_LIST_ELEMENTS_RO(zrmac
->host_list
, node
, p
))
496 json_object_array_add(json_hosts
,
497 json_object_new_string(prefix2str(
498 p
, buf2
, sizeof(buf2
))));
499 json_object_object_add(json
, "prefixList", json_hosts
);
504 * Print a specific MAC entry.
506 static void zvni_print_mac(zebra_mac_t
*mac
, void *ctxt
)
509 zebra_neigh_t
*n
= NULL
;
510 struct listnode
*node
= NULL
;
512 char buf2
[INET6_ADDRSTRLEN
];
514 vty
= (struct vty
*)ctxt
;
515 vty_out(vty
, "MAC: %s",
516 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
)));
517 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
518 struct zebra_ns
*zns
;
519 struct interface
*ifp
;
522 ifindex
= mac
->fwd_info
.local
.ifindex
;
523 zns
= zebra_ns_lookup(NS_DEFAULT
);
524 ifp
= if_lookup_by_index_per_ns(zns
, ifindex
);
525 if (!ifp
) // unexpected
527 vty_out(vty
, " Intf: %s(%u)", ifp
->name
, ifindex
);
528 if (mac
->fwd_info
.local
.vid
)
529 vty_out(vty
, " VLAN: %u", mac
->fwd_info
.local
.vid
);
530 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
531 vty_out(vty
, " Remote VTEP: %s",
532 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
533 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
534 vty_out(vty
, " Auto Mac ");
537 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
538 vty_out(vty
, " Sticky Mac ");
540 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
541 vty_out(vty
, " Default-gateway Mac ");
544 /* print all the associated neigh */
545 vty_out(vty
, " Neighbors:\n");
546 if (!listcount(mac
->neigh_list
))
547 vty_out(vty
, " No Neighbors\n");
549 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
550 vty_out(vty
, " %s %s\n",
551 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)),
552 CHECK_FLAG(n
->flags
, ZEBRA_MAC_LOCAL
)
553 ? (IS_ZEBRA_NEIGH_ACTIVE(n
)
564 * Print MAC hash entry - called for display of all MACs.
566 static void zvni_print_mac_hash(struct hash_backet
*backet
, void *ctxt
)
569 json_object
*json_mac_hdr
= NULL
, *json_mac
= NULL
;
572 struct mac_walk_ctx
*wctx
= ctxt
;
575 json_mac_hdr
= wctx
->json
;
576 mac
= (zebra_mac_t
*)backet
->data
;
580 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
583 json_mac
= json_object_new_object();
585 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
586 && !(wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)) {
587 struct zebra_ns
*zns
;
589 struct interface
*ifp
;
592 zns
= zebra_ns_lookup(NS_DEFAULT
);
593 ifindex
= mac
->fwd_info
.local
.ifindex
;
594 ifp
= if_lookup_by_index_per_ns(zns
, ifindex
);
595 if (!ifp
) // unexpected
597 vid
= mac
->fwd_info
.local
.vid
;
598 if (json_mac_hdr
== NULL
)
599 vty_out(vty
, "%-17s %-6s %-21s", buf1
, "local",
602 json_object_string_add(json_mac
, "type", "local");
603 json_object_string_add(json_mac
, "intf", ifp
->name
);
606 if (json_mac_hdr
== NULL
)
607 vty_out(vty
, " %-5u", vid
);
609 json_object_int_add(json_mac
, "vlan", vid
);
611 if (json_mac_hdr
== NULL
)
614 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
616 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
617 if (wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
) {
618 if (IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
620 if (wctx
->count
== 0) {
621 if (json_mac_hdr
== NULL
) {
622 vty_out(vty
, "\nVNI %u\n\n",
625 "%-17s %-6s %-21s %-5s\n",
631 if (json_mac_hdr
== NULL
)
632 vty_out(vty
, "%-17s %-6s %-21s\n", buf1
,
634 inet_ntoa(mac
->fwd_info
637 json_object_string_add(json_mac
, "type",
639 json_object_string_add(
640 json_mac
, "remoteVtep",
641 inet_ntoa(mac
->fwd_info
643 json_object_object_add(json_mac_hdr
,
649 if (json_mac_hdr
== NULL
)
650 vty_out(vty
, "%-17s %-6s %-21s\n", buf1
,
652 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
654 json_object_string_add(json_mac
, "type",
656 json_object_string_add(
657 json_mac
, "remoteVtep",
658 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
659 json_object_object_add(json_mac_hdr
, buf1
,
668 * Print MACs for all VNI.
670 static void zvni_print_mac_hash_all_vni(struct hash_backet
*backet
, void *ctxt
)
673 json_object
*json
= NULL
, *json_vni
= NULL
;
674 json_object
*json_mac
= NULL
;
677 struct mac_walk_ctx
*wctx
= ctxt
;
678 char vni_str
[VNI_STR_LEN
];
680 vty
= (struct vty
*)wctx
->vty
;
681 json
= (struct json_object
*)wctx
->json
;
683 zvni
= (zebra_vni_t
*)backet
->data
;
686 vty_out(vty
, "{}\n");
691 /*We are iterating over a new VNI, set the count to 0*/
694 num_macs
= num_valid_macs(zvni
);
699 json_vni
= json_object_new_object();
700 json_mac
= json_object_new_object();
701 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
704 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
706 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
707 zvni
->vni
, num_macs
);
708 vty_out(vty
, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
709 "Intf/Remote VTEP", "VLAN");
711 json_object_int_add(json_vni
, "numMacs", num_macs
);
713 /* assign per-vni to wctx->json object to fill macs
714 * under the vni. Re-assign primary json object to fill
715 * next vni information.
717 wctx
->json
= json_mac
;
718 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, wctx
);
722 json_object_object_add(json_vni
, "macs", json_mac
);
723 json_object_object_add(json
, vni_str
, json_vni
);
727 static void zl3vni_print_nh_hash(struct hash_backet
*backet
, void *ctx
)
729 struct nh_walk_ctx
*wctx
= NULL
;
730 struct vty
*vty
= NULL
;
731 struct json_object
*json_vni
= NULL
;
732 struct json_object
*json_nh
= NULL
;
733 zebra_neigh_t
*n
= NULL
;
734 char buf1
[ETHER_ADDR_STRLEN
];
735 char buf2
[INET6_ADDRSTRLEN
];
737 wctx
= (struct nh_walk_ctx
*)ctx
;
739 json_vni
= wctx
->json
;
741 json_nh
= json_object_new_object();
742 n
= (zebra_neigh_t
*)backet
->data
;
747 vty_out(vty
, "%-15s %-17s\n",
748 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
749 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
751 json_object_string_add(json_nh
, "nexthopIp",
752 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
753 json_object_string_add(
754 json_nh
, "routerMac",
755 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
756 json_object_object_add(json_vni
,
757 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
762 static void zl3vni_print_nh_hash_all_vni(struct hash_backet
*backet
,
765 struct vty
*vty
= NULL
;
766 json_object
*json
= NULL
;
767 json_object
*json_vni
= NULL
;
768 zebra_l3vni_t
*zl3vni
= NULL
;
770 struct nh_walk_ctx wctx
;
771 char vni_str
[VNI_STR_LEN
];
773 vty
= (struct vty
*)args
[0];
774 json
= (struct json_object
*)args
[1];
776 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
779 vty_out(vty
, "{}\n");
783 num_nh
= hashcount(zl3vni
->nh_table
);
788 json_vni
= json_object_new_object();
789 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
793 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n", zl3vni
->vni
, num_nh
);
794 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
796 json_object_int_add(json_vni
, "numNextHops", num_nh
);
798 memset(&wctx
, 0, sizeof(struct nh_walk_ctx
));
800 wctx
.json
= json_vni
;
801 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
803 json_object_object_add(json
, vni_str
, json_vni
);
806 static void zl3vni_print_rmac_hash_all_vni(struct hash_backet
*backet
,
809 struct vty
*vty
= NULL
;
810 json_object
*json
= NULL
;
811 json_object
*json_vni
= NULL
;
812 zebra_l3vni_t
*zl3vni
= NULL
;
814 struct rmac_walk_ctx wctx
;
815 char vni_str
[VNI_STR_LEN
];
817 vty
= (struct vty
*)args
[0];
818 json
= (struct json_object
*)args
[1];
820 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
823 vty_out(vty
, "{}\n");
827 num_rmacs
= hashcount(zl3vni
->rmac_table
);
832 json_vni
= json_object_new_object();
833 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
837 vty_out(vty
, "\nVNI %u #RMACs %u\n\n", zl3vni
->vni
, num_rmacs
);
838 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
840 json_object_int_add(json_vni
, "numRmacs", num_rmacs
);
842 /* assign per-vni to wctx->json object to fill macs
843 * under the vni. Re-assign primary json object to fill
844 * next vni information.
846 memset(&wctx
, 0, sizeof(struct rmac_walk_ctx
));
848 wctx
.json
= json_vni
;
849 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
851 json_object_object_add(json
, vni_str
, json_vni
);
854 static void zl3vni_print_rmac_hash(struct hash_backet
*backet
, void *ctx
)
856 zebra_mac_t
*zrmac
= NULL
;
857 struct rmac_walk_ctx
*wctx
= NULL
;
858 struct vty
*vty
= NULL
;
859 struct json_object
*json
= NULL
;
860 struct json_object
*json_rmac
= NULL
;
861 char buf
[ETHER_ADDR_STRLEN
];
863 wctx
= (struct rmac_walk_ctx
*)ctx
;
867 json_rmac
= json_object_new_object();
868 zrmac
= (zebra_mac_t
*)backet
->data
;
873 vty_out(vty
, "%-17s %-21s\n",
874 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
875 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
877 json_object_string_add(
878 json_rmac
, "routerMac",
879 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)));
880 json_object_string_add(json_rmac
, "vtepIp",
881 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
882 json_object_object_add(
883 json
, prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
888 /* print a specific L3 VNI entry */
889 static void zl3vni_print(zebra_l3vni_t
*zl3vni
, void **ctx
)
891 char buf
[ETHER_ADDR_STRLEN
];
892 struct vty
*vty
= NULL
;
893 json_object
*json
= NULL
;
894 zebra_vni_t
*zvni
= NULL
;
895 json_object
*json_vni_list
= NULL
;
896 struct listnode
*node
= NULL
, *nnode
= NULL
;
902 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
903 vty_out(vty
, " Type: %s\n", "L3");
904 vty_out(vty
, " Tenant VRF: %s\n", zl3vni_vrf_name(zl3vni
));
905 vty_out(vty
, " Local Vtep Ip: %s\n",
906 inet_ntoa(zl3vni
->local_vtep_ip
));
907 vty_out(vty
, " Vxlan-Intf: %s\n",
908 zl3vni_vxlan_if_name(zl3vni
));
909 vty_out(vty
, " SVI-If: %s\n", zl3vni_svi_if_name(zl3vni
));
910 vty_out(vty
, " State: %s\n", zl3vni_state2str(zl3vni
));
911 vty_out(vty
, " VNI Filter: %s\n",
912 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
913 ? "prefix-routes-only"
915 vty_out(vty
, " Router MAC: %s\n",
916 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
917 vty_out(vty
, " L2 VNIs: ");
918 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zvni
))
919 vty_out(vty
, "%u ", zvni
->vni
);
922 json_vni_list
= json_object_new_array();
923 json_object_int_add(json
, "vni", zl3vni
->vni
);
924 json_object_string_add(json
, "type", "L3");
925 json_object_string_add(json
, "localVtepIp",
926 inet_ntoa(zl3vni
->local_vtep_ip
));
927 json_object_string_add(json
, "vxlanIntf",
928 zl3vni_vxlan_if_name(zl3vni
));
929 json_object_string_add(json
, "sviIntf",
930 zl3vni_svi_if_name(zl3vni
));
931 json_object_string_add(json
, "state", zl3vni_state2str(zl3vni
));
932 json_object_string_add(json
, "vrf", zl3vni_vrf_name(zl3vni
));
933 json_object_string_add(
935 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
936 json_object_string_add(
938 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
939 ? "prefix-routes-only"
941 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zvni
)) {
942 json_object_array_add(json_vni_list
,
943 json_object_new_int(zvni
->vni
));
945 json_object_object_add(json
, "l2Vnis", json_vni_list
);
950 * Print a specific VNI entry.
952 static void zvni_print(zebra_vni_t
*zvni
, void **ctxt
)
958 json_object
*json
= NULL
;
959 json_object
*json_vtep_list
= NULL
;
960 json_object
*json_ip_str
= NULL
;
966 vty_out(vty
, "VNI: %u\n", zvni
->vni
);
967 vty_out(vty
, " Type: %s\n", "L2");
968 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zvni
->vrf_id
));
970 json_object_int_add(json
, "vni", zvni
->vni
);
971 json_object_string_add(json
, "type", "L2");
972 json_object_string_add(json
, "vrf",
973 vrf_id_to_name(zvni
->vrf_id
));
976 if (!zvni
->vxlan_if
) { // unexpected
978 vty_out(vty
, " VxLAN interface: unknown\n");
981 num_macs
= num_valid_macs(zvni
);
982 num_neigh
= hashcount(zvni
->neigh_table
);
984 vty_out(vty
, " VxLAN interface: %s\n", zvni
->vxlan_if
->name
);
985 vty_out(vty
, " VxLAN ifIndex: %u\n", zvni
->vxlan_if
->ifindex
);
986 vty_out(vty
, " Local VTEP IP: %s\n",
987 inet_ntoa(zvni
->local_vtep_ip
));
989 json_object_string_add(json
, "vxlanInterface",
990 zvni
->vxlan_if
->name
);
991 json_object_int_add(json
, "ifindex", zvni
->vxlan_if
->ifindex
);
992 json_object_string_add(json
, "vtepIp",
993 inet_ntoa(zvni
->local_vtep_ip
));
994 json_object_string_add(json
, "advertiseGatewayMacip",
995 zvni
->advertise_gw_macip
? "Yes" : "No");
996 json_object_int_add(json
, "numMacs", num_macs
);
997 json_object_int_add(json
, "numArpNd", num_neigh
);
1001 vty_out(vty
, " No remote VTEPs known for this VNI\n");
1004 vty_out(vty
, " Remote VTEPs for this VNI:\n");
1006 json_vtep_list
= json_object_new_array();
1007 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1009 vty_out(vty
, " %s\n",
1010 inet_ntoa(zvtep
->vtep_ip
));
1012 json_ip_str
= json_object_new_string(
1013 inet_ntoa(zvtep
->vtep_ip
));
1014 json_object_array_add(json_vtep_list
,
1019 json_object_object_add(json
, "numRemoteVteps",
1024 " Number of MACs (local and remote) known for this VNI: %u\n",
1027 " Number of ARPs (IPv4 and IPv6, local and remote) "
1028 "known for this VNI: %u\n",
1030 vty_out(vty
, " Advertise-gw-macip: %s\n",
1031 zvni
->advertise_gw_macip
? "Yes" : "No");
1035 /* print a L3 VNI hash entry */
1036 static void zl3vni_print_hash(struct hash_backet
*backet
, void *ctx
[])
1038 struct vty
*vty
= NULL
;
1039 json_object
*json
= NULL
;
1040 json_object
*json_vni
= NULL
;
1041 zebra_l3vni_t
*zl3vni
= NULL
;
1043 vty
= (struct vty
*)ctx
[0];
1044 json
= (json_object
*)ctx
[1];
1046 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
1051 vty_out(vty
, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
1052 zl3vni
->vni
, "L3", zl3vni_vxlan_if_name(zl3vni
),
1053 hashcount(zl3vni
->rmac_table
),
1054 hashcount(zl3vni
->nh_table
), "n/a",
1055 zl3vni_vrf_name(zl3vni
));
1057 char vni_str
[VNI_STR_LEN
];
1059 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
1060 json_vni
= json_object_new_object();
1061 json_object_int_add(json_vni
, "vni", zl3vni
->vni
);
1062 json_object_string_add(json_vni
, "vxlanIf",
1063 zl3vni_vxlan_if_name(zl3vni
));
1064 json_object_int_add(json_vni
, "numMacs",
1065 hashcount(zl3vni
->rmac_table
));
1066 json_object_int_add(json_vni
, "numArpNd",
1067 hashcount(zl3vni
->nh_table
));
1068 json_object_string_add(json_vni
, "numRemoteVteps", "n/a");
1069 json_object_string_add(json_vni
, "type", "L3");
1070 json_object_string_add(json_vni
, "tenantVrf",
1071 zl3vni_vrf_name(zl3vni
));
1072 json_object_object_add(json
, vni_str
, json_vni
);
1077 * Print a VNI hash entry - called for display of all VNIs.
1079 static void zvni_print_hash(struct hash_backet
*backet
, void *ctxt
[])
1083 zebra_vtep_t
*zvtep
;
1084 u_int32_t num_vteps
= 0;
1085 u_int32_t num_macs
= 0;
1086 u_int32_t num_neigh
= 0;
1087 json_object
*json
= NULL
;
1088 json_object
*json_vni
= NULL
;
1089 json_object
*json_ip_str
= NULL
;
1090 json_object
*json_vtep_list
= NULL
;
1095 zvni
= (zebra_vni_t
*)backet
->data
;
1099 zvtep
= zvni
->vteps
;
1102 zvtep
= zvtep
->next
;
1105 num_macs
= num_valid_macs(zvni
);
1106 num_neigh
= hashcount(zvni
->neigh_table
);
1108 vty_out(vty
, "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
1110 zvni
->vxlan_if
? zvni
->vxlan_if
->name
: "unknown",
1111 num_macs
, num_neigh
, num_vteps
,
1112 vrf_id_to_name(zvni
->vrf_id
));
1114 char vni_str
[VNI_STR_LEN
];
1115 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
1116 json_vni
= json_object_new_object();
1117 json_object_int_add(json_vni
, "vni", zvni
->vni
);
1118 json_object_string_add(json_vni
, "type", "L2");
1119 json_object_string_add(json_vni
, "vxlanIf",
1120 zvni
->vxlan_if
? zvni
->vxlan_if
->name
1122 json_object_int_add(json_vni
, "numMacs", num_macs
);
1123 json_object_int_add(json_vni
, "numArpNd", num_neigh
);
1124 json_object_int_add(json_vni
, "numRemoteVteps", num_vteps
);
1125 json_object_string_add(json_vni
, "tenantVrf",
1126 vrf_id_to_name(zvni
->vrf_id
));
1128 json_vtep_list
= json_object_new_array();
1129 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1130 json_ip_str
= json_object_new_string(
1131 inet_ntoa(zvtep
->vtep_ip
));
1132 json_object_array_add(json_vtep_list
,
1135 json_object_object_add(json_vni
, "remoteVteps",
1138 json_object_object_add(json
, vni_str
, json_vni
);
1143 * Inform BGP about local MACIP.
1145 static int zvni_macip_send_msg_to_client(vni_t vni
, struct ethaddr
*macaddr
,
1146 struct ipaddr
*ip
, u_char flags
,
1149 char buf
[ETHER_ADDR_STRLEN
];
1150 char buf2
[INET6_ADDRSTRLEN
];
1152 struct zserv
*client
= NULL
;
1153 struct stream
*s
= NULL
;
1155 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
1156 /* BGP may not be running. */
1163 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
1164 stream_putl(s
, vni
);
1165 stream_put(s
, macaddr
->octet
, ETH_ALEN
);
1168 if (IS_IPADDR_V4(ip
))
1169 ipa_len
= IPV4_MAX_BYTELEN
;
1170 else if (IS_IPADDR_V6(ip
))
1171 ipa_len
= IPV6_MAX_BYTELEN
;
1173 stream_putl(s
, ipa_len
); /* IP address length */
1175 stream_put(s
, &ip
->ip
.addr
, ipa_len
); /* IP address */
1177 stream_putl(s
, 0); /* Just MAC. */
1179 stream_putc(s
, flags
); /* sticky mac/gateway mac */
1182 /* Write packet size. */
1183 stream_putw_at(s
, 0, stream_get_endp(s
));
1185 if (IS_ZEBRA_DEBUG_VXLAN
)
1187 "Send MACIP %s flags 0x%x MAC %s IP %s L2-VNI %u to %s",
1188 (cmd
== ZEBRA_MACIP_ADD
) ? "Add" : "Del", flags
,
1189 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1190 ipaddr2str(ip
, buf2
, sizeof(buf2
)), vni
,
1191 zebra_route_string(client
->proto
));
1193 if (cmd
== ZEBRA_MACIP_ADD
)
1194 client
->macipadd_cnt
++;
1196 client
->macipdel_cnt
++;
1198 return zebra_server_send_message(client
);
1202 * Make hash key for neighbors.
1204 static unsigned int neigh_hash_keymake(void *p
)
1206 zebra_neigh_t
*n
= p
;
1207 struct ipaddr
*ip
= &n
->ip
;
1209 if (IS_IPADDR_V4(ip
))
1210 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
1212 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
1213 ZEBRA_NUM_OF(ip
->ipaddr_v6
.s6_addr32
), 0);
1217 * Compare two neighbor hash structures.
1219 static int neigh_cmp(const void *p1
, const void *p2
)
1221 const zebra_neigh_t
*n1
= p1
;
1222 const zebra_neigh_t
*n2
= p2
;
1224 if (n1
== NULL
&& n2
== NULL
)
1227 if (n1
== NULL
|| n2
== NULL
)
1230 return (memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
)) == 0);
1234 * Callback to allocate neighbor hash entry.
1236 static void *zvni_neigh_alloc(void *p
)
1238 const zebra_neigh_t
*tmp_n
= p
;
1241 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
1248 * Add neighbor entry.
1250 static zebra_neigh_t
*zvni_neigh_add(zebra_vni_t
*zvni
, struct ipaddr
*ip
,
1251 struct ethaddr
*mac
)
1253 zebra_neigh_t tmp_n
;
1254 zebra_neigh_t
*n
= NULL
;
1255 zebra_mac_t
*zmac
= NULL
;
1257 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
1258 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1259 n
= hash_get(zvni
->neigh_table
, &tmp_n
, zvni_neigh_alloc
);
1262 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1263 n
->state
= ZEBRA_NEIGH_INACTIVE
;
1265 /* Associate the neigh to mac */
1266 zmac
= zvni_mac_lookup(zvni
, mac
);
1268 listnode_add_sort(zmac
->neigh_list
, n
);
1274 * Delete neighbor entry.
1276 static int zvni_neigh_del(zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
1278 zebra_neigh_t
*tmp_n
;
1279 zebra_mac_t
*zmac
= NULL
;
1281 zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
1283 listnode_delete(zmac
->neigh_list
, n
);
1285 /* Free the VNI hash entry and allocated memory. */
1286 tmp_n
= hash_release(zvni
->neigh_table
, n
);
1288 XFREE(MTYPE_NEIGH
, tmp_n
);
1294 * Free neighbor hash entry (callback)
1296 static int zvni_neigh_del_hash_entry(struct hash_backet
*backet
, void *arg
)
1298 struct neigh_walk_ctx
*wctx
= arg
;
1299 zebra_neigh_t
*n
= backet
->data
;
1301 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
1302 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
1303 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
1304 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
1305 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
1306 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
1307 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
1308 zvni_neigh_send_del_to_client(wctx
->zvni
->vni
, &n
->ip
,
1311 if (wctx
->uninstall
)
1312 zvni_neigh_uninstall(wctx
->zvni
, n
);
1314 return zvni_neigh_del(wctx
->zvni
, n
);
1321 * Delete all neighbor entries from specific VTEP for a particular VNI.
1323 static void zvni_neigh_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
1324 struct in_addr
*r_vtep_ip
)
1326 struct neigh_walk_ctx wctx
;
1328 if (!zvni
->neigh_table
)
1331 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1333 wctx
.uninstall
= uninstall
;
1334 wctx
.flags
= DEL_REMOTE_NEIGH_FROM_VTEP
;
1335 wctx
.r_vtep_ip
= *r_vtep_ip
;
1337 hash_iterate(zvni
->neigh_table
,
1338 (void (*)(struct hash_backet
*,
1339 void *))zvni_neigh_del_hash_entry
,
1344 * Delete all neighbor entries for this VNI.
1346 static void zvni_neigh_del_all(zebra_vni_t
*zvni
, int uninstall
, int upd_client
,
1349 struct neigh_walk_ctx wctx
;
1351 if (!zvni
->neigh_table
)
1354 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1356 wctx
.uninstall
= uninstall
;
1357 wctx
.upd_client
= upd_client
;
1360 hash_iterate(zvni
->neigh_table
,
1361 (void (*)(struct hash_backet
*,
1362 void *))zvni_neigh_del_hash_entry
,
1367 * Look up neighbor hash entry.
1369 static zebra_neigh_t
*zvni_neigh_lookup(zebra_vni_t
*zvni
, struct ipaddr
*ip
)
1374 memset(&tmp
, 0, sizeof(tmp
));
1375 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1376 n
= hash_lookup(zvni
->neigh_table
, &tmp
);
1381 /* Process all neigh associated to a mac upon local mac add event */
1382 static void zvni_process_neigh_on_local_mac_add(zebra_vni_t
*zvni
,
1385 zebra_neigh_t
*n
= NULL
;
1386 struct listnode
*node
= NULL
;
1387 char buf
[ETHER_ADDR_STRLEN
];
1388 char buf2
[INET6_ADDRSTRLEN
];
1390 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1391 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1392 /* MAC is learnt locally, program all inactive neigh
1393 * pointing to this mac */
1394 if (IS_ZEBRA_NEIGH_INACTIVE(n
)) {
1395 if (IS_ZEBRA_DEBUG_VXLAN
)
1397 "neigh %s (MAC %s) on L2-VNI %u is now ACTIVE",
1398 ipaddr2str(&n
->ip
, buf2
,
1400 prefix_mac2str(&n
->emac
, buf
,
1404 ZEBRA_NEIGH_SET_ACTIVE(n
);
1405 zvni_neigh_send_add_to_client(
1406 zvni
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
1408 if (IS_ZEBRA_DEBUG_VXLAN
)
1410 "neigh %s (MAC %s) on VNI %u should NOT be ACTIVE",
1411 ipaddr2str(&n
->ip
, buf2
,
1413 prefix_mac2str(&n
->emac
, buf
,
1417 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1418 /* TODO: assume the neigh has moved too ?? */
1423 /* Process all neigh associated to a mac upon local mac del event */
1424 static void zvni_process_neigh_on_local_mac_del(zebra_vni_t
*zvni
,
1427 zebra_neigh_t
*n
= NULL
;
1428 struct listnode
*node
= NULL
;
1429 char buf
[ETHER_ADDR_STRLEN
];
1430 char buf2
[INET6_ADDRSTRLEN
];
1432 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1433 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1434 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1435 if (IS_ZEBRA_DEBUG_VXLAN
)
1437 "neigh %s (MAC %s) on L2-VNI %u is now INACTIVE",
1438 ipaddr2str(&n
->ip
, buf2
,
1440 prefix_mac2str(&n
->emac
, buf
,
1444 ZEBRA_NEIGH_SET_INACTIVE(n
);
1445 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
,
1448 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1449 if (IS_ZEBRA_DEBUG_VXLAN
)
1451 "local MAC %s getting deleted on VNI %u has remote neigh %s",
1452 prefix_mac2str(&n
->emac
, buf
,
1455 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1460 /* process all neigh associated to a mac entry upon remote mac add */
1461 static void zvni_process_neigh_on_remote_mac_add(zebra_vni_t
*zvni
,
1464 zebra_neigh_t
*n
= NULL
;
1465 struct listnode
*node
= NULL
;
1466 char buf
[ETHER_ADDR_STRLEN
];
1467 char buf2
[INET6_ADDRSTRLEN
];
1469 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1470 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1471 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1472 if (IS_ZEBRA_DEBUG_VXLAN
)
1474 "neigh %s (MAC %s) on L2-VNI %u is now INACTIVE",
1475 ipaddr2str(&n
->ip
, buf2
,
1477 prefix_mac2str(&n
->emac
, buf
,
1481 ZEBRA_NEIGH_SET_INACTIVE(n
);
1482 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
,
1489 /* process all neigh associated to mac entry upon remote mac del */
1490 static void zvni_process_neigh_on_remote_mac_del(zebra_vni_t
*zvni
,
1493 zebra_neigh_t
*n
= NULL
;
1494 struct listnode
*node
= NULL
;
1495 char buf
[ETHER_ADDR_STRLEN
];
1496 char buf2
[INET6_ADDRSTRLEN
];
1498 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1499 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1500 if (IS_ZEBRA_DEBUG_VXLAN
)
1502 "remote MAC %s getting deleted on VNI %u has local neigh %s",
1503 prefix_mac2str(&n
->emac
, buf
,
1506 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1512 * Inform BGP about local neighbor addition.
1514 static int zvni_neigh_send_add_to_client(vni_t vni
, struct ipaddr
*ip
,
1515 struct ethaddr
*macaddr
,
1520 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
1521 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1523 return zvni_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
,
1528 * Inform BGP about local neighbor deletion.
1530 static int zvni_neigh_send_del_to_client(vni_t vni
, struct ipaddr
*ip
,
1531 struct ethaddr
*macaddr
, u_char flags
)
1533 return zvni_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
,
1538 * Install remote neighbor into the kernel.
1540 static int zvni_neigh_install(zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
1542 struct zebra_if
*zif
;
1543 struct zebra_l2info_vxlan
*vxl
;
1544 struct interface
*vlan_if
;
1546 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
1549 zif
= zvni
->vxlan_if
->info
;
1552 vxl
= &zif
->l2info
.vxl
;
1554 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1558 return kernel_add_neigh(vlan_if
, &n
->ip
, &n
->emac
);
1562 * Uninstall remote neighbor from the kernel.
1564 static int zvni_neigh_uninstall(zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
1566 struct zebra_if
*zif
;
1567 struct zebra_l2info_vxlan
*vxl
;
1568 struct interface
*vlan_if
;
1570 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
1573 if (!zvni
->vxlan_if
) {
1574 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
1579 zif
= zvni
->vxlan_if
->info
;
1582 vxl
= &zif
->l2info
.vxl
;
1583 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1587 return kernel_del_neigh(vlan_if
, &n
->ip
);
1591 * Install neighbor hash entry - called upon access VLAN change.
1593 static void zvni_install_neigh_hash(struct hash_backet
*backet
, void *ctxt
)
1596 struct neigh_walk_ctx
*wctx
= ctxt
;
1598 n
= (zebra_neigh_t
*)backet
->data
;
1602 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
1603 zvni_neigh_install(wctx
->zvni
, n
);
1606 /* Get the VRR interface for SVI if any */
1607 struct interface
*zebra_get_vrr_intf_for_svi(struct interface
*ifp
)
1609 struct zebra_vrf
*zvrf
= NULL
;
1610 struct interface
*tmp_if
= NULL
;
1611 struct zebra_if
*zif
= NULL
;
1613 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1616 FOR_ALL_INTERFACES (zvrf
->vrf
, tmp_if
) {
1621 if (!IS_ZEBRA_IF_MACVLAN(tmp_if
))
1624 if (zif
->link
== ifp
)
1631 static int zvni_del_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
)
1633 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1634 struct connected
*c
= NULL
;
1635 struct ethaddr macaddr
;
1637 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1639 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1642 memset(&ip
, 0, sizeof(struct ipaddr
));
1643 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
1646 if (c
->address
->family
== AF_INET
) {
1647 ip
.ipa_type
= IPADDR_V4
;
1648 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
1649 sizeof(struct in_addr
));
1650 } else if (c
->address
->family
== AF_INET6
) {
1651 ip
.ipa_type
= IPADDR_V6
;
1652 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
1653 sizeof(struct in6_addr
));
1658 zvni_gw_macip_del(ifp
, zvni
, &ip
);
1664 static int zvni_add_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
)
1666 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1667 struct connected
*c
= NULL
;
1668 struct ethaddr macaddr
;
1670 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1672 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1675 memset(&ip
, 0, sizeof(struct ipaddr
));
1676 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
1679 if (c
->address
->family
== AF_INET
) {
1680 ip
.ipa_type
= IPADDR_V4
;
1681 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
1682 sizeof(struct in_addr
));
1683 } else if (c
->address
->family
== AF_INET6
) {
1684 ip
.ipa_type
= IPADDR_V6
;
1685 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
1686 sizeof(struct in6_addr
));
1691 zvni_gw_macip_add(ifp
, zvni
, &macaddr
, &ip
);
1697 static int zvni_advertise_subnet(zebra_vni_t
*zvni
, struct interface
*ifp
,
1700 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1701 struct connected
*c
= NULL
;
1702 struct ethaddr macaddr
;
1704 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1706 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1709 memcpy(&p
, c
->address
, sizeof(struct prefix
));
1711 /* skip link local address */
1712 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
1717 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
1718 ZEBRA_IP_PREFIX_ROUTE_ADD
);
1720 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
1721 ZEBRA_IP_PREFIX_ROUTE_DEL
);
1727 * zvni_gw_macip_add_to_client
1729 static int zvni_gw_macip_add(struct interface
*ifp
, zebra_vni_t
*zvni
,
1730 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
1732 char buf
[ETHER_ADDR_STRLEN
];
1733 char buf2
[INET6_ADDRSTRLEN
];
1734 zebra_neigh_t
*n
= NULL
;
1735 zebra_mac_t
*mac
= NULL
;
1736 struct zebra_if
*zif
= NULL
;
1737 struct zebra_l2info_vxlan
*vxl
= NULL
;
1739 zif
= zvni
->vxlan_if
->info
;
1743 vxl
= &zif
->l2info
.vxl
;
1745 mac
= zvni_mac_lookup(zvni
, macaddr
);
1747 mac
= zvni_mac_add(zvni
, macaddr
);
1749 zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
1750 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1751 ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
);
1756 /* Set "local" forwarding info. */
1757 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
1758 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
1759 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
1760 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
1761 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
1762 mac
->fwd_info
.local
.vid
= vxl
->access_vlan
;
1764 n
= zvni_neigh_lookup(zvni
, ip
);
1766 n
= zvni_neigh_add(zvni
, ip
, macaddr
);
1769 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
1770 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
1771 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1772 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
1777 /* Set "local" forwarding info. */
1778 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1779 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
1780 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
1781 n
->ifindex
= ifp
->ifindex
;
1783 /* Only advertise in BGP if the knob is enabled */
1784 if (!advertise_gw_macip_enabled(zvni
))
1787 if (IS_ZEBRA_DEBUG_VXLAN
)
1789 "SVI %s(%u) L2-VNI %u, sending GW MAC %s IP %s add to BGP",
1790 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
1791 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1792 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
1794 zvni_neigh_send_add_to_client(zvni
->vni
, ip
, macaddr
, n
->flags
);
1800 * zvni_gw_macip_del_from_client
1802 static int zvni_gw_macip_del(struct interface
*ifp
, zebra_vni_t
*zvni
,
1805 char buf1
[ETHER_ADDR_STRLEN
];
1806 char buf2
[INET6_ADDRSTRLEN
];
1807 zebra_neigh_t
*n
= NULL
;
1808 zebra_mac_t
*mac
= NULL
;
1810 /* If the neigh entry is not present nothing to do*/
1811 n
= zvni_neigh_lookup(zvni
, ip
);
1815 /* mac entry should be present */
1816 mac
= zvni_mac_lookup(zvni
, &n
->emac
);
1818 zlog_err("MAC %s doesnt exists for neigh %s on VNI %u",
1819 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)),
1820 ipaddr2str(ip
, buf2
, sizeof(buf2
)), zvni
->vni
);
1824 /* If the entry is not local nothing to do*/
1825 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
1828 /* only need to delete the entry from bgp if we sent it before */
1829 if (IS_ZEBRA_DEBUG_VXLAN
)
1831 "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP",
1832 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, zvni
->vni
,
1833 prefix_mac2str(&(n
->emac
), NULL
, ETHER_ADDR_STRLEN
),
1834 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
1836 /* Remove neighbor from BGP. */
1837 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
, &n
->emac
,
1838 ZEBRA_MACIP_TYPE_GW
);
1840 /* Delete this neighbor entry. */
1841 zvni_neigh_del(zvni
, n
);
1843 /* see if the mac needs to be deleted as well*/
1845 zvni_deref_ip2mac(zvni
, mac
, 0);
1850 static void zvni_gw_macip_del_for_vni_hash(struct hash_backet
*backet
,
1853 zebra_vni_t
*zvni
= NULL
;
1854 struct zebra_if
*zif
= NULL
;
1855 struct zebra_l2info_vxlan zl2_info
;
1856 struct interface
*vlan_if
= NULL
;
1857 struct interface
*vrr_if
= NULL
;
1858 struct interface
*ifp
;
1860 /* Add primary SVI MAC*/
1861 zvni
= (zebra_vni_t
*)backet
->data
;
1865 ifp
= zvni
->vxlan_if
;
1870 /* If down or not mapped to a bridge, we're done. */
1871 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
1874 zl2_info
= zif
->l2info
.vxl
;
1877 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
1881 /* Del primary MAC-IP */
1882 zvni_del_macip_for_intf(vlan_if
, zvni
);
1884 /* Del VRR MAC-IP - if any*/
1885 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1887 zvni_del_macip_for_intf(vrr_if
, zvni
);
1892 static void zvni_gw_macip_add_for_vni_hash(struct hash_backet
*backet
,
1895 zebra_vni_t
*zvni
= NULL
;
1896 struct zebra_if
*zif
= NULL
;
1897 struct zebra_l2info_vxlan zl2_info
;
1898 struct interface
*vlan_if
= NULL
;
1899 struct interface
*vrr_if
= NULL
;
1900 struct interface
*ifp
= NULL
;
1902 zvni
= (zebra_vni_t
*)backet
->data
;
1906 ifp
= zvni
->vxlan_if
;
1911 /* If down or not mapped to a bridge, we're done. */
1912 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
1914 zl2_info
= zif
->l2info
.vxl
;
1917 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
1921 /* Add primary SVI MAC-IP */
1922 zvni_add_macip_for_intf(vlan_if
, zvni
);
1924 /* Add VRR MAC-IP - if any*/
1925 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1927 zvni_add_macip_for_intf(vrr_if
, zvni
);
1933 * Make hash key for MAC.
1935 static unsigned int mac_hash_keymake(void *p
)
1937 zebra_mac_t
*pmac
= p
;
1938 const void *pnt
= (void *)pmac
->macaddr
.octet
;
1940 return jhash(pnt
, ETH_ALEN
, 0xa5a5a55a);
1944 * Compare two MAC addresses.
1946 static int mac_cmp(const void *p1
, const void *p2
)
1948 const zebra_mac_t
*pmac1
= p1
;
1949 const zebra_mac_t
*pmac2
= p2
;
1951 if (pmac1
== NULL
&& pmac2
== NULL
)
1954 if (pmac1
== NULL
|| pmac2
== NULL
)
1957 return (memcmp(pmac1
->macaddr
.octet
, pmac2
->macaddr
.octet
, ETH_ALEN
)
1962 * Callback to allocate MAC hash entry.
1964 static void *zvni_mac_alloc(void *p
)
1966 const zebra_mac_t
*tmp_mac
= p
;
1969 mac
= XCALLOC(MTYPE_MAC
, sizeof(zebra_mac_t
));
1972 return ((void *)mac
);
1978 static zebra_mac_t
*zvni_mac_add(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
)
1980 zebra_mac_t tmp_mac
;
1981 zebra_mac_t
*mac
= NULL
;
1983 memset(&tmp_mac
, 0, sizeof(zebra_mac_t
));
1984 memcpy(&tmp_mac
.macaddr
, macaddr
, ETH_ALEN
);
1985 mac
= hash_get(zvni
->mac_table
, &tmp_mac
, zvni_mac_alloc
);
1988 mac
->neigh_list
= list_new();
1989 mac
->neigh_list
->cmp
= (int (*)(void *, void *))neigh_cmp
;
1997 static int zvni_mac_del(zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
1999 zebra_mac_t
*tmp_mac
;
2001 list_delete_and_null(&mac
->neigh_list
);
2003 /* Free the VNI hash entry and allocated memory. */
2004 tmp_mac
= hash_release(zvni
->mac_table
, mac
);
2006 XFREE(MTYPE_MAC
, tmp_mac
);
2012 * Free MAC hash entry (callback)
2014 static int zvni_mac_del_hash_entry(struct hash_backet
*backet
, void *arg
)
2016 struct mac_walk_ctx
*wctx
= arg
;
2017 zebra_mac_t
*mac
= backet
->data
;
2019 if (((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_LOCAL
))
2020 || ((wctx
->flags
& DEL_REMOTE_MAC
)
2021 && (mac
->flags
& ZEBRA_MAC_REMOTE
))
2022 || ((wctx
->flags
& DEL_REMOTE_MAC_FROM_VTEP
)
2023 && (mac
->flags
& ZEBRA_MAC_REMOTE
)
2024 && IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
2025 &wctx
->r_vtep_ip
))) {
2026 if (wctx
->upd_client
&& (mac
->flags
& ZEBRA_MAC_LOCAL
)) {
2027 zvni_mac_send_del_to_client(wctx
->zvni
->vni
,
2028 &mac
->macaddr
, mac
->flags
);
2031 if (wctx
->uninstall
)
2032 zvni_mac_uninstall(wctx
->zvni
, mac
, 0);
2034 return zvni_mac_del(wctx
->zvni
, mac
);
2041 * Delete all MAC entries from specific VTEP for a particular VNI.
2043 static void zvni_mac_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
2044 struct in_addr
*r_vtep_ip
)
2046 struct mac_walk_ctx wctx
;
2048 if (!zvni
->mac_table
)
2051 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
2053 wctx
.uninstall
= uninstall
;
2054 wctx
.flags
= DEL_REMOTE_MAC_FROM_VTEP
;
2055 wctx
.r_vtep_ip
= *r_vtep_ip
;
2057 hash_iterate(zvni
->mac_table
, (void (*)(struct hash_backet
*,
2058 void *))zvni_mac_del_hash_entry
,
2063 * Delete all MAC entries for this VNI.
2065 static void zvni_mac_del_all(zebra_vni_t
*zvni
, int uninstall
, int upd_client
,
2068 struct mac_walk_ctx wctx
;
2070 if (!zvni
->mac_table
)
2073 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
2075 wctx
.uninstall
= uninstall
;
2076 wctx
.upd_client
= upd_client
;
2079 hash_iterate(zvni
->mac_table
, (void (*)(struct hash_backet
*,
2080 void *))zvni_mac_del_hash_entry
,
2085 * Look up MAC hash entry.
2087 static zebra_mac_t
*zvni_mac_lookup(zebra_vni_t
*zvni
, struct ethaddr
*mac
)
2092 memset(&tmp
, 0, sizeof(tmp
));
2093 memcpy(&tmp
.macaddr
, mac
, ETH_ALEN
);
2094 pmac
= hash_lookup(zvni
->mac_table
, &tmp
);
2100 * Inform BGP about local MAC addition.
2102 static int zvni_mac_send_add_to_client(vni_t vni
, struct ethaddr
*macaddr
,
2107 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
2108 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2109 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
2110 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2112 return zvni_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
2117 * Inform BGP about local MAC deletion.
2119 static int zvni_mac_send_del_to_client(vni_t vni
, struct ethaddr
*macaddr
,
2124 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
2125 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2126 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
2127 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2129 return zvni_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
2134 * Map port or (port, VLAN) to a VNI. This is invoked upon getting MAC
2135 * notifications, to see if they are of interest.
2137 static zebra_vni_t
*zvni_map_vlan(struct interface
*ifp
,
2138 struct interface
*br_if
, vlanid_t vid
)
2140 struct zebra_ns
*zns
;
2141 struct route_node
*rn
;
2142 struct interface
*tmp_if
= NULL
;
2143 struct zebra_if
*zif
;
2144 struct zebra_l2info_bridge
*br
;
2145 struct zebra_l2info_vxlan
*vxl
= NULL
;
2146 u_char bridge_vlan_aware
;
2150 /* Determine if bridge is VLAN-aware or not */
2153 br
= &zif
->l2info
.br
;
2154 bridge_vlan_aware
= br
->vlan_aware
;
2156 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2157 /* TODO: Optimize with a hash. */
2158 zns
= zebra_ns_lookup(NS_DEFAULT
);
2159 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2160 tmp_if
= (struct interface
*)rn
->info
;
2164 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2166 if (!if_is_operative(tmp_if
))
2168 vxl
= &zif
->l2info
.vxl
;
2170 if (zif
->brslave_info
.br_if
!= br_if
)
2173 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
2182 zvni
= zvni_lookup(vxl
->vni
);
2187 * Map SVI and associated bridge to a VNI. This is invoked upon getting
2188 * neighbor notifications, to see if they are of interest.
2190 static zebra_vni_t
*zvni_from_svi(struct interface
*ifp
,
2191 struct interface
*br_if
)
2193 struct zebra_ns
*zns
;
2194 struct route_node
*rn
;
2195 struct interface
*tmp_if
= NULL
;
2196 struct zebra_if
*zif
;
2197 struct zebra_l2info_bridge
*br
;
2198 struct zebra_l2info_vxlan
*vxl
= NULL
;
2199 u_char bridge_vlan_aware
;
2207 /* Make sure the linked interface is a bridge. */
2208 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
2211 /* Determine if bridge is VLAN-aware or not */
2214 br
= &zif
->l2info
.br
;
2215 bridge_vlan_aware
= br
->vlan_aware
;
2216 if (bridge_vlan_aware
) {
2217 struct zebra_l2info_vlan
*vl
;
2219 if (!IS_ZEBRA_IF_VLAN(ifp
))
2224 vl
= &zif
->l2info
.vl
;
2228 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2229 /* TODO: Optimize with a hash. */
2230 zns
= zebra_ns_lookup(NS_DEFAULT
);
2231 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2232 tmp_if
= (struct interface
*)rn
->info
;
2236 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2238 if (!if_is_operative(tmp_if
))
2240 vxl
= &zif
->l2info
.vxl
;
2242 if (zif
->brslave_info
.br_if
!= br_if
)
2245 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
2254 zvni
= zvni_lookup(vxl
->vni
);
2258 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
2260 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
2261 * linked to the bridge
2262 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge inteface
2265 static struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
2267 struct zebra_ns
*zns
;
2268 struct route_node
*rn
;
2269 struct interface
*tmp_if
= NULL
;
2270 struct zebra_if
*zif
;
2271 struct zebra_l2info_bridge
*br
;
2272 struct zebra_l2info_vlan
*vl
;
2273 u_char bridge_vlan_aware
;
2276 /* Defensive check, caller expected to invoke only with valid bridge. */
2280 /* Determine if bridge is VLAN-aware or not */
2283 br
= &zif
->l2info
.br
;
2284 bridge_vlan_aware
= br
->vlan_aware
;
2286 /* Check oper status of the SVI. */
2287 if (!bridge_vlan_aware
)
2288 return if_is_operative(br_if
) ? br_if
: NULL
;
2290 /* Identify corresponding VLAN interface. */
2291 /* TODO: Optimize with a hash. */
2292 zns
= zebra_ns_lookup(NS_DEFAULT
);
2293 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2294 tmp_if
= (struct interface
*)rn
->info
;
2295 /* Check oper status of the SVI. */
2296 if (!tmp_if
|| !if_is_operative(tmp_if
))
2299 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
2300 || zif
->link
!= br_if
)
2302 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
2304 if (vl
->vid
== vid
) {
2310 return found
? tmp_if
: NULL
;
2314 * Install remote MAC into the kernel.
2316 static int zvni_mac_install(zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
2318 struct zebra_if
*zif
;
2319 struct zebra_l2info_vxlan
*vxl
;
2322 if (!(mac
->flags
& ZEBRA_MAC_REMOTE
))
2325 zif
= zvni
->vxlan_if
->info
;
2328 vxl
= &zif
->l2info
.vxl
;
2330 sticky
= CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
) ? 1 : 0;
2332 return kernel_add_mac(zvni
->vxlan_if
, vxl
->access_vlan
, &mac
->macaddr
,
2333 mac
->fwd_info
.r_vtep_ip
, sticky
);
2337 * Uninstall remote MAC from the kernel. In the scenario where the MAC
2338 * moves to remote, we have to uninstall any existing local entry first.
2340 static int zvni_mac_uninstall(zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
)
2342 struct zebra_if
*zif
;
2343 struct zebra_l2info_vxlan
*vxl
;
2344 struct in_addr vtep_ip
= {.s_addr
= 0};
2345 struct zebra_ns
*zns
;
2346 struct interface
*ifp
;
2348 if (!local
&& !(mac
->flags
& ZEBRA_MAC_REMOTE
))
2351 if (!zvni
->vxlan_if
) {
2352 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
2357 zif
= zvni
->vxlan_if
->info
;
2360 vxl
= &zif
->l2info
.vxl
;
2363 zns
= zebra_ns_lookup(NS_DEFAULT
);
2364 ifp
= if_lookup_by_index_per_ns(zns
,
2365 mac
->fwd_info
.local
.ifindex
);
2366 if (!ifp
) // unexpected
2369 ifp
= zvni
->vxlan_if
;
2370 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
2373 return kernel_del_mac(ifp
, vxl
->access_vlan
, &mac
->macaddr
, vtep_ip
,
2378 * Install MAC hash entry - called upon access VLAN change.
2380 static void zvni_install_mac_hash(struct hash_backet
*backet
, void *ctxt
)
2383 struct mac_walk_ctx
*wctx
= ctxt
;
2385 mac
= (zebra_mac_t
*)backet
->data
;
2389 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
2390 zvni_mac_install(wctx
->zvni
, mac
);
2394 * Decrement neighbor refcount of MAC; uninstall and free it if
2397 static void zvni_deref_ip2mac(zebra_vni_t
*zvni
, zebra_mac_t
*mac
,
2400 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)
2401 || !list_isempty(mac
->neigh_list
))
2405 zvni_mac_uninstall(zvni
, mac
, 0);
2407 zvni_mac_del(zvni
, mac
);
2411 * Read and populate local MACs and neighbors corresponding to this VNI.
2413 static void zvni_read_mac_neigh(zebra_vni_t
*zvni
, struct interface
*ifp
)
2415 struct zebra_ns
*zns
;
2416 struct zebra_if
*zif
;
2417 struct interface
*vlan_if
;
2418 struct zebra_l2info_vxlan
*vxl
;
2419 struct interface
*vrr_if
;
2422 vxl
= &zif
->l2info
.vxl
;
2423 zns
= zebra_ns_lookup(NS_DEFAULT
);
2425 if (IS_ZEBRA_DEBUG_VXLAN
)
2427 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
2428 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
2429 zif
->brslave_info
.bridge_ifindex
);
2431 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
2432 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
2435 /* Add SVI MAC-IP */
2436 zvni_add_macip_for_intf(vlan_if
, zvni
);
2438 /* Add VRR MAC-IP - if any*/
2439 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
2441 zvni_add_macip_for_intf(vrr_if
, zvni
);
2443 neigh_read_for_vlan(zns
, vlan_if
);
2448 * Hash function for VNI.
2450 static unsigned int vni_hash_keymake(void *p
)
2452 const zebra_vni_t
*zvni
= p
;
2454 return (jhash_1word(zvni
->vni
, 0));
2458 * Compare 2 VNI hash entries.
2460 static int vni_hash_cmp(const void *p1
, const void *p2
)
2462 const zebra_vni_t
*zvni1
= p1
;
2463 const zebra_vni_t
*zvni2
= p2
;
2465 return (zvni1
->vni
== zvni2
->vni
);
2469 * Callback to allocate VNI hash entry.
2471 static void *zvni_alloc(void *p
)
2473 const zebra_vni_t
*tmp_vni
= p
;
2476 zvni
= XCALLOC(MTYPE_ZVNI
, sizeof(zebra_vni_t
));
2477 zvni
->vni
= tmp_vni
->vni
;
2478 return ((void *)zvni
);
2482 * Look up VNI hash entry.
2484 static zebra_vni_t
*zvni_lookup(vni_t vni
)
2486 struct zebra_vrf
*zvrf
;
2487 zebra_vni_t tmp_vni
;
2488 zebra_vni_t
*zvni
= NULL
;
2490 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2492 memset(&tmp_vni
, 0, sizeof(zebra_vni_t
));
2494 zvni
= hash_lookup(zvrf
->vni_table
, &tmp_vni
);
2500 * Add VNI hash entry.
2502 static zebra_vni_t
*zvni_add(vni_t vni
)
2504 struct zebra_vrf
*zvrf
;
2505 zebra_vni_t tmp_zvni
;
2506 zebra_vni_t
*zvni
= NULL
;
2508 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2510 memset(&tmp_zvni
, 0, sizeof(zebra_vni_t
));
2512 zvni
= hash_get(zvrf
->vni_table
, &tmp_zvni
, zvni_alloc
);
2515 /* Create hash table for MAC */
2517 hash_create(mac_hash_keymake
, mac_cmp
, "Zebra VNI MAC Table");
2519 /* Create hash table for neighbors */
2520 zvni
->neigh_table
= hash_create(neigh_hash_keymake
, neigh_cmp
,
2521 "Zebra VNI Neighbor Table");
2527 * Delete VNI hash entry.
2529 static int zvni_del(zebra_vni_t
*zvni
)
2531 struct zebra_vrf
*zvrf
;
2532 zebra_vni_t
*tmp_zvni
;
2534 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2537 zvni
->vxlan_if
= NULL
;
2539 /* Free the neighbor hash table. */
2540 hash_free(zvni
->neigh_table
);
2541 zvni
->neigh_table
= NULL
;
2543 /* Free the MAC hash table. */
2544 hash_free(zvni
->mac_table
);
2545 zvni
->mac_table
= NULL
;
2547 /* Free the VNI hash entry and allocated memory. */
2548 tmp_zvni
= hash_release(zvrf
->vni_table
, zvni
);
2550 XFREE(MTYPE_ZVNI
, tmp_zvni
);
2556 * Inform BGP about local VNI addition.
2558 static int zvni_send_add_to_client(zebra_vni_t
*zvni
)
2560 struct zserv
*client
;
2563 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
2564 /* BGP may not be running. */
2571 zclient_create_header(s
, ZEBRA_VNI_ADD
, VRF_DEFAULT
);
2572 stream_putl(s
, zvni
->vni
);
2573 stream_put_in_addr(s
, &zvni
->local_vtep_ip
);
2574 stream_put(s
, &zvni
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
2576 /* Write packet size. */
2577 stream_putw_at(s
, 0, stream_get_endp(s
));
2579 if (IS_ZEBRA_DEBUG_VXLAN
)
2580 zlog_debug("Send VNI_ADD %u %s tenant vrf %s to %s", zvni
->vni
,
2581 inet_ntoa(zvni
->local_vtep_ip
),
2582 vrf_id_to_name(zvni
->vrf_id
),
2583 zebra_route_string(client
->proto
));
2585 client
->vniadd_cnt
++;
2586 return zebra_server_send_message(client
);
2590 * Inform BGP about local VNI deletion.
2592 static int zvni_send_del_to_client(vni_t vni
)
2594 struct zserv
*client
;
2597 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
2598 /* BGP may not be running. */
2605 zclient_create_header(s
, ZEBRA_VNI_DEL
, VRF_DEFAULT
);
2606 stream_putl(s
, vni
);
2608 /* Write packet size. */
2609 stream_putw_at(s
, 0, stream_get_endp(s
));
2611 if (IS_ZEBRA_DEBUG_VXLAN
)
2612 zlog_debug("Send VNI_DEL %u to %s", vni
,
2613 zebra_route_string(client
->proto
));
2615 client
->vnidel_cnt
++;
2616 return zebra_server_send_message(client
);
2620 * Build the VNI hash table by going over the VxLAN interfaces. This
2621 * is called when EVPN (advertise-all-vni) is enabled.
2623 static void zvni_build_hash_table()
2625 struct zebra_ns
*zns
;
2626 struct route_node
*rn
;
2627 struct interface
*ifp
;
2629 /* Walk VxLAN interfaces and create VNI hash. */
2630 zns
= zebra_ns_lookup(NS_DEFAULT
);
2631 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2633 zebra_vni_t
*zvni
= NULL
;
2634 zebra_l3vni_t
*zl3vni
= NULL
;
2635 struct zebra_if
*zif
;
2636 struct zebra_l2info_vxlan
*vxl
;
2638 ifp
= (struct interface
*)rn
->info
;
2642 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2645 vxl
= &zif
->l2info
.vxl
;
2648 /* L3-VNI and L2-VNI are handled seperately */
2649 zl3vni
= zl3vni_lookup(vni
);
2652 if (IS_ZEBRA_DEBUG_VXLAN
)
2654 "create L3-VNI hash for Intf %s(%u) L3-VNI %u",
2655 ifp
->name
, ifp
->ifindex
, vni
);
2657 /* associate with vxlan_if */
2658 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
2659 zl3vni
->vxlan_if
= ifp
;
2662 * we need to associate with SVI.
2663 * we can associate with svi-if only after association
2664 * with vxlan-intf is complete
2666 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
2668 if (is_l3vni_oper_up(zl3vni
))
2669 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
2672 struct interface
*vlan_if
= NULL
;
2674 if (IS_ZEBRA_DEBUG_VXLAN
)
2676 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %s",
2677 ifp
->name
, ifp
->ifindex
, vni
,
2678 inet_ntoa(vxl
->vtep_ip
));
2680 /* VNI hash entry is not expected to exist. */
2681 zvni
= zvni_lookup(vni
);
2684 "VNI hash already present for IF %s(%u) L2-VNI %u",
2685 ifp
->name
, ifp
->ifindex
, vni
);
2689 zvni
= zvni_add(vni
);
2692 "Failed to add VNI hash, IF %s(%u) L2-VNI %u",
2693 ifp
->name
, ifp
->ifindex
, vni
);
2697 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
2698 zvni
->vxlan_if
= ifp
;
2699 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
2700 zif
->brslave_info
.br_if
);
2702 zvni
->vrf_id
= vlan_if
->vrf_id
;
2703 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
2705 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
2709 /* Inform BGP if intf is up and mapped to bridge. */
2710 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
2711 zvni_send_add_to_client(zvni
);
2717 * See if remote VTEP matches with prefix.
2719 static int zvni_vtep_match(struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
)
2721 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
2725 * Locate remote VTEP in VNI hash table.
2727 static zebra_vtep_t
*zvni_vtep_find(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2729 zebra_vtep_t
*zvtep
;
2734 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
2735 if (zvni_vtep_match(vtep_ip
, zvtep
))
2743 * Add remote VTEP to VNI hash table.
2745 static zebra_vtep_t
*zvni_vtep_add(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2747 zebra_vtep_t
*zvtep
;
2749 zvtep
= XCALLOC(MTYPE_ZVNI_VTEP
, sizeof(zebra_vtep_t
));
2751 zlog_err("Failed to alloc VTEP entry, VNI %u", zvni
->vni
);
2755 zvtep
->vtep_ip
= *vtep_ip
;
2758 zvni
->vteps
->prev
= zvtep
;
2759 zvtep
->next
= zvni
->vteps
;
2760 zvni
->vteps
= zvtep
;
2766 * Remove remote VTEP from VNI hash table.
2768 static int zvni_vtep_del(zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
)
2771 zvtep
->next
->prev
= zvtep
->prev
;
2773 zvtep
->prev
->next
= zvtep
->next
;
2775 zvni
->vteps
= zvtep
->next
;
2777 zvtep
->prev
= zvtep
->next
= NULL
;
2778 XFREE(MTYPE_ZVNI_VTEP
, zvtep
);
2784 * Delete all remote VTEPs for this VNI (upon VNI delete). Also
2785 * uninstall from kernel if asked to.
2787 static int zvni_vtep_del_all(zebra_vni_t
*zvni
, int uninstall
)
2789 zebra_vtep_t
*zvtep
, *zvtep_next
;
2794 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep_next
) {
2795 zvtep_next
= zvtep
->next
;
2797 zvni_vtep_uninstall(zvni
, &zvtep
->vtep_ip
);
2798 zvni_vtep_del(zvni
, zvtep
);
2805 * Install remote VTEP into the kernel.
2807 static int zvni_vtep_install(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2809 return kernel_add_vtep(zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
2813 * Uninstall remote VTEP from the kernel.
2815 static int zvni_vtep_uninstall(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2817 if (!zvni
->vxlan_if
) {
2818 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
2823 return kernel_del_vtep(zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
2827 * Cleanup VNI/VTEP and update kernel
2829 static void zvni_cleanup_all(struct hash_backet
*backet
, void *arg
)
2831 zebra_vni_t
*zvni
= NULL
;
2832 zebra_l3vni_t
*zl3vni
= NULL
;
2833 struct zebra_vrf
*zvrf
= (struct zebra_vrf
*)arg
;
2835 zvni
= (zebra_vni_t
*)backet
->data
;
2839 /* remove from l3-vni list */
2841 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
2843 listnode_delete(zl3vni
->l2vnis
, zvni
);
2845 /* Free up all neighbors and MACs, if any. */
2846 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
2847 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
2849 /* Free up all remote VTEPs, if any. */
2850 zvni_vtep_del_all(zvni
, 1);
2852 /* Delete the hash entry. */
2857 static void zl3vni_cleanup_all(struct hash_backet
*backet
, void *args
)
2859 zebra_l3vni_t
*zl3vni
= NULL
;
2861 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
2865 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
2868 static int is_host_present_in_host_list(struct list
*list
, struct prefix
*host
)
2870 struct listnode
*node
= NULL
;
2871 struct prefix
*p
= NULL
;
2873 for (ALL_LIST_ELEMENTS_RO(list
, node
, p
)) {
2874 if (prefix_same(p
, host
))
2880 static void host_list_add_host(struct list
*list
, struct prefix
*host
)
2882 struct prefix
*p
= NULL
;
2884 p
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct prefix
));
2885 memcpy(p
, host
, sizeof(struct prefix
));
2887 listnode_add_sort(list
, p
);
2890 static void host_list_delete_host(struct list
*list
, struct prefix
*host
)
2892 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
2893 struct prefix
*p
= NULL
;
2895 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, p
)) {
2896 if (prefix_same(p
, host
)) {
2897 XFREE(MTYPE_HOST_PREFIX
, p
);
2903 list_delete_node(list
, node_to_del
);
2907 * Look up MAC hash entry.
2909 static zebra_mac_t
*zl3vni_rmac_lookup(zebra_l3vni_t
*zl3vni
,
2910 struct ethaddr
*rmac
)
2915 memset(&tmp
, 0, sizeof(tmp
));
2916 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
2917 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
2923 * Callback to allocate RMAC hash entry.
2925 static void *zl3vni_rmac_alloc(void *p
)
2927 const zebra_mac_t
*tmp_rmac
= p
;
2930 zrmac
= XCALLOC(MTYPE_MAC
, sizeof(zebra_mac_t
));
2933 return ((void *)zrmac
);
2937 * Add RMAC entry to l3-vni
2939 static zebra_mac_t
*zl3vni_rmac_add(zebra_l3vni_t
*zl3vni
, struct ethaddr
*rmac
)
2941 zebra_mac_t tmp_rmac
;
2942 zebra_mac_t
*zrmac
= NULL
;
2944 memset(&tmp_rmac
, 0, sizeof(zebra_mac_t
));
2945 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
2946 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
2949 zrmac
->host_list
= list_new();
2950 zrmac
->host_list
->cmp
= (int (*)(void *, void *))prefix_cmp
;
2952 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
2953 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
2961 static int zl3vni_rmac_del(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
)
2963 zebra_mac_t
*tmp_rmac
;
2965 if (zrmac
->host_list
)
2966 list_delete_and_null(&zrmac
->host_list
);
2967 zrmac
->host_list
= NULL
;
2969 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
2971 XFREE(MTYPE_MAC
, tmp_rmac
);
2977 * Install remote RMAC into the kernel.
2979 static int zl3vni_rmac_install(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
)
2981 struct zebra_if
*zif
= NULL
;
2982 struct zebra_l2info_vxlan
*vxl
= NULL
;
2984 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
2985 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
2988 zif
= zl3vni
->vxlan_if
->info
;
2992 vxl
= &zif
->l2info
.vxl
;
2994 return kernel_add_mac(zl3vni
->vxlan_if
, vxl
->access_vlan
,
2995 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0);
2999 * Uninstall remote RMAC from the kernel.
3001 static int zl3vni_rmac_uninstall(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
)
3003 char buf
[ETHER_ADDR_STRLEN
];
3004 struct zebra_if
*zif
= NULL
;
3005 struct zebra_l2info_vxlan
*vxl
= NULL
;
3007 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
))
3008 || !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
3011 if (!zl3vni
->vxlan_if
) {
3013 "RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
3014 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
3015 zl3vni
->vni
, zl3vni
);
3019 zif
= zl3vni
->vxlan_if
->info
;
3023 vxl
= &zif
->l2info
.vxl
;
3025 return kernel_del_mac(zl3vni
->vxlan_if
, vxl
->access_vlan
,
3026 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0);
3029 /* handle rmac add */
3030 static int zl3vni_remote_rmac_add(zebra_l3vni_t
*zl3vni
, struct ethaddr
*rmac
,
3031 struct ipaddr
*vtep_ip
,
3032 struct prefix
*host_prefix
)
3034 char buf
[ETHER_ADDR_STRLEN
];
3035 char buf1
[INET6_ADDRSTRLEN
];
3036 zebra_mac_t
*zrmac
= NULL
;
3038 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3041 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
3044 "Failed to add RMAC %s L3VNI %u Remote VTEP %s",
3045 prefix_mac2str(rmac
, buf
, sizeof(buf
)),
3047 ipaddr2str(vtep_ip
, buf1
, sizeof(buf1
)));
3050 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
3051 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
3053 /* install rmac in kernel */
3054 zl3vni_rmac_install(zl3vni
, zrmac
);
3057 if (!is_host_present_in_host_list(zrmac
->host_list
, host_prefix
))
3058 host_list_add_host(zrmac
->host_list
, host_prefix
);
3063 /* handle rmac delete */
3064 static int zl3vni_remote_rmac_del(zebra_l3vni_t
*zl3vni
, struct ethaddr
*rmac
,
3065 struct prefix
*host_prefix
)
3067 zebra_mac_t
*zrmac
= NULL
;
3069 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3073 host_list_delete_host(zrmac
->host_list
, host_prefix
);
3074 if (list_isempty(zrmac
->host_list
)) {
3076 /* uninstall from kernel */
3077 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
3079 /* del the rmac entry */
3080 zl3vni_rmac_del(zl3vni
, zrmac
);
3086 * Look up nh hash entry on a l3-vni.
3088 static zebra_neigh_t
*zl3vni_nh_lookup(zebra_l3vni_t
*zl3vni
, struct ipaddr
*ip
)
3093 memset(&tmp
, 0, sizeof(tmp
));
3094 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
3095 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
3102 * Callback to allocate NH hash entry on L3-VNI.
3104 static void *zl3vni_nh_alloc(void *p
)
3106 const zebra_neigh_t
*tmp_n
= p
;
3109 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
3116 * Add neighbor entry.
3118 static zebra_neigh_t
*zl3vni_nh_add(zebra_l3vni_t
*zl3vni
, struct ipaddr
*ip
,
3119 struct ethaddr
*mac
)
3121 zebra_neigh_t tmp_n
;
3122 zebra_neigh_t
*n
= NULL
;
3124 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
3125 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
3126 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
3129 n
->host_list
= list_new();
3130 n
->host_list
->cmp
= (int (*)(void *, void *))prefix_cmp
;
3132 memcpy(&n
->emac
, mac
, ETH_ALEN
);
3133 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
3134 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
3140 * Delete neighbor entry.
3142 static int zl3vni_nh_del(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
)
3144 zebra_neigh_t
*tmp_n
;
3147 list_delete_and_null(&n
->host_list
);
3148 n
->host_list
= NULL
;
3150 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
3152 XFREE(MTYPE_NEIGH
, tmp_n
);
3158 * Install remote nh as neigh into the kernel.
3160 static int zl3vni_nh_install(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
)
3162 if (!is_l3vni_oper_up(zl3vni
))
3165 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
3166 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
3169 return kernel_add_neigh(zl3vni
->svi_if
, &n
->ip
, &n
->emac
);
3173 * Uninstall remote nh from the kernel.
3175 static int zl3vni_nh_uninstall(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
)
3177 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
)
3178 || !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
3181 if (!zl3vni
->svi_if
|| !if_is_operative(zl3vni
->svi_if
))
3184 return kernel_del_neigh(zl3vni
->svi_if
, &n
->ip
);
3187 /* add remote vtep as a neigh entry */
3188 static int zl3vni_remote_nh_add(zebra_l3vni_t
*zl3vni
, struct ipaddr
*vtep_ip
,
3189 struct ethaddr
*rmac
,
3190 struct prefix
*host_prefix
)
3192 char buf
[ETHER_ADDR_STRLEN
];
3193 char buf1
[INET6_ADDRSTRLEN
];
3194 zebra_neigh_t
*nh
= NULL
;
3196 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
3198 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
3202 "Failed to add NH as Neigh (IP %s MAC %s L3-VNI %u)",
3203 ipaddr2str(vtep_ip
, buf1
, sizeof(buf1
)),
3204 prefix_mac2str(rmac
, buf
, sizeof(buf
)),
3209 /* install the nh neigh in kernel */
3210 zl3vni_nh_install(zl3vni
, nh
);
3213 if (!is_host_present_in_host_list(nh
->host_list
, host_prefix
))
3214 host_list_add_host(nh
->host_list
, host_prefix
);
3219 /* handle nh neigh delete */
3220 static int zl3vni_remote_nh_del(zebra_l3vni_t
*zl3vni
, struct ipaddr
*vtep_ip
,
3221 struct prefix
*host_prefix
)
3223 zebra_neigh_t
*nh
= NULL
;
3225 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
3229 host_list_delete_host(nh
->host_list
, host_prefix
);
3230 if (list_isempty(nh
->host_list
)) {
3232 /* uninstall from kernel */
3233 zl3vni_nh_uninstall(zl3vni
, nh
);
3235 /* delete the nh entry */
3236 zl3vni_nh_del(zl3vni
, nh
);
3242 /* handle neigh update from kernel - the only thing of interest is to
3243 * readd stale entries.
3245 static int zl3vni_local_nh_add_update(zebra_l3vni_t
*zl3vni
, struct ipaddr
*ip
,
3249 zebra_neigh_t
*n
= NULL
;
3251 n
= zl3vni_nh_lookup(zl3vni
, ip
);
3255 /* all next hop neigh are remote and installed by frr.
3256 * If the kernel has aged this entry, re-install.
3258 if (state
& NUD_STALE
)
3259 zl3vni_nh_install(zl3vni
, n
);
3264 /* handle neigh delete from kernel */
3265 static int zl3vni_local_nh_del(zebra_l3vni_t
*zl3vni
, struct ipaddr
*ip
)
3267 zebra_neigh_t
*n
= NULL
;
3269 n
= zl3vni_nh_lookup(zl3vni
, ip
);
3273 /* all next hop neigh are remote and installed by frr.
3274 * If we get an age out notification for these neigh entries, we have to
3277 zl3vni_nh_install(zl3vni
, n
);
3283 * Hash function for L3 VNI.
3285 static unsigned int l3vni_hash_keymake(void *p
)
3287 const zebra_l3vni_t
*zl3vni
= p
;
3289 return jhash_1word(zl3vni
->vni
, 0);
3293 * Compare 2 L3 VNI hash entries.
3295 static int l3vni_hash_cmp(const void *p1
, const void *p2
)
3297 const zebra_l3vni_t
*zl3vni1
= p1
;
3298 const zebra_l3vni_t
*zl3vni2
= p2
;
3300 return (zl3vni1
->vni
== zl3vni2
->vni
);
3304 * Callback to allocate L3 VNI hash entry.
3306 static void *zl3vni_alloc(void *p
)
3308 zebra_l3vni_t
*zl3vni
= NULL
;
3309 const zebra_l3vni_t
*tmp_l3vni
= p
;
3311 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(zebra_l3vni_t
));
3312 zl3vni
->vni
= tmp_l3vni
->vni
;
3313 return ((void *)zl3vni
);
3317 * Look up L3 VNI hash entry.
3319 static zebra_l3vni_t
*zl3vni_lookup(vni_t vni
)
3321 struct zebra_ns
*zns
;
3322 zebra_l3vni_t tmp_l3vni
;
3323 zebra_l3vni_t
*zl3vni
= NULL
;
3325 zns
= zebra_ns_lookup(NS_DEFAULT
);
3327 memset(&tmp_l3vni
, 0, sizeof(zebra_l3vni_t
));
3328 tmp_l3vni
.vni
= vni
;
3329 zl3vni
= hash_lookup(zns
->l3vni_table
, &tmp_l3vni
);
3335 * Add L3 VNI hash entry.
3337 static zebra_l3vni_t
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
3339 zebra_l3vni_t tmp_zl3vni
;
3340 struct zebra_ns
*zns
= NULL
;
3341 zebra_l3vni_t
*zl3vni
= NULL
;
3343 zns
= zebra_ns_lookup(NS_DEFAULT
);
3346 memset(&tmp_zl3vni
, 0, sizeof(zebra_l3vni_t
));
3347 tmp_zl3vni
.vni
= vni
;
3349 zl3vni
= hash_get(zns
->l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
3352 zl3vni
->vrf_id
= vrf_id
;
3353 zl3vni
->svi_if
= NULL
;
3354 zl3vni
->vxlan_if
= NULL
;
3355 zl3vni
->l2vnis
= list_new();
3356 zl3vni
->l2vnis
->cmp
= (int (*)(void *, void *))vni_hash_cmp
;
3358 /* Create hash table for remote RMAC */
3359 zl3vni
->rmac_table
= hash_create(mac_hash_keymake
, mac_cmp
,
3360 "Zebra L3-VNI RMAC-Table");
3362 /* Create hash table for neighbors */
3363 zl3vni
->nh_table
= hash_create(neigh_hash_keymake
, neigh_cmp
,
3364 "Zebra L3-VNI next-hop table");
3370 * Delete L3 VNI hash entry.
3372 static int zl3vni_del(zebra_l3vni_t
*zl3vni
)
3374 struct zebra_ns
*zns
;
3375 zebra_l3vni_t
*tmp_zl3vni
;
3377 zns
= zebra_ns_lookup(NS_DEFAULT
);
3380 /* free the list of l2vnis */
3381 list_delete_and_null(&zl3vni
->l2vnis
);
3382 zl3vni
->l2vnis
= NULL
;
3384 /* Free the rmac table */
3385 hash_free(zl3vni
->rmac_table
);
3386 zl3vni
->rmac_table
= NULL
;
3388 /* Free the nh table */
3389 hash_free(zl3vni
->nh_table
);
3390 zl3vni
->nh_table
= NULL
;
3392 /* Free the VNI hash entry and allocated memory. */
3393 tmp_zl3vni
= hash_release(zns
->l3vni_table
, zl3vni
);
3395 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
3400 static struct interface
*zl3vni_map_to_vxlan_if(zebra_l3vni_t
*zl3vni
)
3402 struct zebra_ns
*zns
= NULL
;
3403 struct route_node
*rn
= NULL
;
3404 struct interface
*ifp
= NULL
;
3406 /* loop through all vxlan-interface */
3407 zns
= zebra_ns_lookup(NS_DEFAULT
);
3408 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
3410 struct zebra_if
*zif
= NULL
;
3411 struct zebra_l2info_vxlan
*vxl
= NULL
;
3413 ifp
= (struct interface
*)rn
->info
;
3418 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
3421 vxl
= &zif
->l2info
.vxl
;
3422 if (vxl
->vni
== zl3vni
->vni
) {
3423 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
3431 static struct interface
*zl3vni_map_to_svi_if(zebra_l3vni_t
*zl3vni
)
3433 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
3434 struct zebra_l2info_vxlan
*vxl
= NULL
; /* l2 info for vxlan_if */
3439 if (!zl3vni
->vxlan_if
)
3442 zif
= zl3vni
->vxlan_if
->info
;
3446 vxl
= &zif
->l2info
.vxl
;
3448 return zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
3451 static zebra_l3vni_t
*zl3vni_from_vrf(vrf_id_t vrf_id
)
3453 struct zebra_vrf
*zvrf
= NULL
;
3455 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
3459 return zl3vni_lookup(zvrf
->l3vni
);
3463 * Map SVI and associated bridge to a VNI. This is invoked upon getting
3464 * neighbor notifications, to see if they are of interest.
3466 static zebra_l3vni_t
*zl3vni_from_svi(struct interface
*ifp
,
3467 struct interface
*br_if
)
3471 u_char bridge_vlan_aware
= 0;
3472 zebra_l3vni_t
*zl3vni
= NULL
;
3473 struct zebra_ns
*zns
= NULL
;
3474 struct route_node
*rn
= NULL
;
3475 struct zebra_if
*zif
= NULL
;
3476 struct interface
*tmp_if
= NULL
;
3477 struct zebra_l2info_bridge
*br
= NULL
;
3478 struct zebra_l2info_vxlan
*vxl
= NULL
;
3483 /* Make sure the linked interface is a bridge. */
3484 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
3487 /* Determine if bridge is VLAN-aware or not */
3490 br
= &zif
->l2info
.br
;
3491 bridge_vlan_aware
= br
->vlan_aware
;
3492 if (bridge_vlan_aware
) {
3493 struct zebra_l2info_vlan
*vl
;
3495 if (!IS_ZEBRA_IF_VLAN(ifp
))
3500 vl
= &zif
->l2info
.vl
;
3504 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
3505 /* TODO: Optimize with a hash. */
3506 zns
= zebra_ns_lookup(NS_DEFAULT
);
3507 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
3508 tmp_if
= (struct interface
*)rn
->info
;
3512 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
3514 if (!if_is_operative(tmp_if
))
3516 vxl
= &zif
->l2info
.vxl
;
3518 if (zif
->brslave_info
.br_if
!= br_if
)
3521 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
3530 zl3vni
= zl3vni_lookup(vxl
->vni
);
3535 * Inform BGP about l3-vni.
3537 static int zl3vni_send_add_to_client(zebra_l3vni_t
*zl3vni
)
3539 struct stream
*s
= NULL
;
3540 struct zserv
*client
= NULL
;
3541 struct ethaddr rmac
;
3542 char buf
[ETHER_ADDR_STRLEN
];
3544 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
3545 /* BGP may not be running. */
3550 memset(&rmac
, 0, sizeof(struct ethaddr
));
3551 zl3vni_get_rmac(zl3vni
, &rmac
);
3556 zclient_create_header(s
, ZEBRA_L3VNI_ADD
, zl3vni_vrf_id(zl3vni
));
3557 stream_putl(s
, zl3vni
->vni
);
3558 stream_put(s
, &rmac
, sizeof(struct ethaddr
));
3559 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
3560 stream_put(s
, &zl3vni
->filter
, sizeof(int));
3562 /* Write packet size. */
3563 stream_putw_at(s
, 0, stream_get_endp(s
));
3565 if (IS_ZEBRA_DEBUG_VXLAN
)
3567 "Send L3_VNI_ADD %u VRF %s RMAC %s local-ip %s filter %s to %s",
3568 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
3569 prefix_mac2str(&rmac
, buf
, sizeof(buf
)),
3570 inet_ntoa(zl3vni
->local_vtep_ip
),
3571 CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
)
3572 ? "prefix-routes-only"
3574 zebra_route_string(client
->proto
));
3576 client
->l3vniadd_cnt
++;
3577 return zebra_server_send_message(client
);
3581 * Inform BGP about local l3-VNI deletion.
3583 static int zl3vni_send_del_to_client(zebra_l3vni_t
*zl3vni
)
3585 struct stream
*s
= NULL
;
3586 struct zserv
*client
= NULL
;
3588 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
3589 /* BGP may not be running. */
3596 zclient_create_header(s
, ZEBRA_L3VNI_DEL
, zl3vni_vrf_id(zl3vni
));
3597 stream_putl(s
, zl3vni
->vni
);
3599 /* Write packet size. */
3600 stream_putw_at(s
, 0, stream_get_endp(s
));
3602 if (IS_ZEBRA_DEBUG_VXLAN
)
3603 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s", zl3vni
->vni
,
3604 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
3605 zebra_route_string(client
->proto
));
3607 client
->l3vnidel_cnt
++;
3608 return zebra_server_send_message(client
);
3611 static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t
*zl3vni
)
3616 /* send l3vni add to BGP */
3617 zl3vni_send_add_to_client(zl3vni
);
3620 static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t
*zl3vni
)
3625 /* send l3-vni del to BGP*/
3626 zl3vni_send_del_to_client(zl3vni
);
3629 static void zvni_add_to_l3vni_list(struct hash_backet
*backet
, void *ctxt
)
3631 zebra_vni_t
*zvni
= (zebra_vni_t
*)backet
->data
;
3632 zebra_l3vni_t
*zl3vni
= (zebra_l3vni_t
*)ctxt
;
3634 if (zvni
->vrf_id
== zl3vni_vrf_id(zl3vni
))
3635 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
3639 * handle transition of vni from l2 to l3 and vice versa
3641 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
, vni_t vni
,
3644 zebra_vni_t
*zvni
= NULL
;
3646 /* There is a possibility that VNI notification was already received
3647 * from kernel and we programmed it as L2-VNI
3648 * In such a case we need to delete this L2-VNI first, so
3649 * that it can be reprogrammed as L3-VNI in the system. It is also
3650 * possible that the vrf-vni mapping is removed from FRR while the vxlan
3651 * interface is still present in kernel. In this case to keep it
3652 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
3655 /* Locate hash entry */
3656 zvni
= zvni_lookup(vni
);
3660 if (IS_ZEBRA_DEBUG_VXLAN
)
3661 zlog_debug("Del L2-VNI %u - transition to L3-VNI", vni
);
3663 /* Delete VNI from BGP. */
3664 zvni_send_del_to_client(zvni
->vni
);
3666 /* Free up all neighbors and MAC, if any. */
3667 zvni_neigh_del_all(zvni
, 0, 0, DEL_ALL_NEIGH
);
3668 zvni_mac_del_all(zvni
, 0, 0, DEL_ALL_MAC
);
3670 /* Free up all remote VTEPs, if any. */
3671 zvni_vtep_del_all(zvni
, 0);
3673 /* Delete the hash entry. */
3674 if (zvni_del(zvni
)) {
3675 zlog_err("Failed to del VNI hash %p, VNI %u", zvni
,
3680 /* TODO_MITESH: This needs to be thought through. We don't have
3681 * enough information at this point to reprogram the vni as
3682 * l2-vni. One way is to store the required info in l3-vni and
3683 * used it solely for this purpose
3690 /* delete and uninstall rmac hash entry */
3691 static void zl3vni_del_rmac_hash_entry(struct hash_backet
*backet
, void *ctx
)
3693 zebra_mac_t
*zrmac
= NULL
;
3694 zebra_l3vni_t
*zl3vni
= NULL
;
3696 zrmac
= (zebra_mac_t
*)backet
->data
;
3697 zl3vni
= (zebra_l3vni_t
*)ctx
;
3698 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
3699 zl3vni_rmac_del(zl3vni
, zrmac
);
3702 /* delete and uninstall nh hash entry */
3703 static void zl3vni_del_nh_hash_entry(struct hash_backet
*backet
, void *ctx
)
3705 zebra_neigh_t
*n
= NULL
;
3706 zebra_l3vni_t
*zl3vni
= NULL
;
3708 n
= (zebra_neigh_t
*)backet
->data
;
3709 zl3vni
= (zebra_l3vni_t
*)ctx
;
3710 zl3vni_nh_uninstall(zl3vni
, n
);
3711 zl3vni_nh_del(zl3vni
, n
);
3714 static int ip_prefix_send_to_client(vrf_id_t vrf_id
, struct prefix
*p
,
3717 struct zserv
*client
= NULL
;
3718 struct stream
*s
= NULL
;
3719 char buf
[PREFIX_STRLEN
];
3721 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
3722 /* BGP may not be running. */
3729 zclient_create_header(s
, cmd
, vrf_id
);
3730 stream_put(s
, p
, sizeof(struct prefix
));
3732 /* Write packet size. */
3733 stream_putw_at(s
, 0, stream_get_endp(s
));
3735 if (IS_ZEBRA_DEBUG_VXLAN
)
3736 zlog_debug("Send ip prefix %s %s on vrf %s",
3737 prefix2str(p
, buf
, sizeof(buf
)),
3738 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
3739 vrf_id_to_name(vrf_id
));
3741 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
3742 client
->prefixadd_cnt
++;
3744 client
->prefixdel_cnt
++;
3746 return zebra_server_send_message(client
);
3749 /* re-add remote rmac if needed */
3750 static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t
*zl3vni
,
3751 struct ethaddr
*rmac
)
3753 char buf
[ETHER_ADDR_STRLEN
];
3754 zebra_mac_t
*zrmac
= NULL
;
3756 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3760 if (IS_ZEBRA_DEBUG_VXLAN
)
3761 zlog_debug("Del remote RMAC %s L3VNI %u - readd",
3762 prefix_mac2str(rmac
, buf
, sizeof(buf
)), zl3vni
->vni
);
3764 zl3vni_rmac_install(zl3vni
, zrmac
);
3768 /* Public functions */
3770 int is_l3vni_for_prefix_routes_only(vni_t vni
)
3772 zebra_l3vni_t
*zl3vni
= NULL
;
3774 zl3vni
= zl3vni_lookup(vni
);
3778 return CHECK_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
) ? 1 : 0;
3781 /* handle evpn route in vrf table */
3782 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
, struct ethaddr
*rmac
,
3783 struct ipaddr
*vtep_ip
,
3784 struct prefix
*host_prefix
)
3786 zebra_l3vni_t
*zl3vni
= NULL
;
3788 zl3vni
= zl3vni_from_vrf(vrf_id
);
3789 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
3792 /* add the next hop neighbor */
3793 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
3796 zl3vni_remote_rmac_add(zl3vni
, rmac
, vtep_ip
, host_prefix
);
3799 /* handle evpn vrf route delete */
3800 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
, struct ethaddr
*rmac
,
3801 struct ipaddr
*vtep_ip
,
3802 struct prefix
*host_prefix
)
3804 zebra_l3vni_t
*zl3vni
= NULL
;
3806 zl3vni
= zl3vni_from_vrf(vrf_id
);
3810 /* delete the next hop entry */
3811 zl3vni_remote_nh_del(zl3vni
, vtep_ip
, host_prefix
);
3813 /* delete the rmac entry */
3814 zl3vni_remote_rmac_del(zl3vni
, rmac
, host_prefix
);
3817 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
, vni_t l3vni
,
3818 struct ethaddr
*rmac
,
3821 zebra_l3vni_t
*zl3vni
= NULL
;
3822 zebra_mac_t
*zrmac
= NULL
;
3823 json_object
*json
= NULL
;
3825 if (!is_evpn_enabled()) {
3827 vty_out(vty
, "{}\n");
3832 json
= json_object_new_object();
3834 zl3vni
= zl3vni_lookup(l3vni
);
3837 vty_out(vty
, "{}\n");
3839 vty_out(vty
, "%% L3-VNI %u doesnt exist\n", l3vni
);
3843 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3846 vty_out(vty
, "{}\n");
3849 "%% Requested RMAC doesnt exist in L3-VNI %u",
3854 zl3vni_print_rmac(zrmac
, vty
, json
);
3857 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3858 json
, JSON_C_TO_STRING_PRETTY
));
3859 json_object_free(json
);
3863 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
, vni_t l3vni
,
3866 zebra_l3vni_t
*zl3vni
;
3867 u_int32_t num_rmacs
;
3868 struct rmac_walk_ctx wctx
;
3869 json_object
*json
= NULL
;
3871 if (!is_evpn_enabled())
3874 zl3vni
= zl3vni_lookup(l3vni
);
3877 vty_out(vty
, "{}\n");
3879 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
3882 num_rmacs
= hashcount(zl3vni
->rmac_table
);
3887 json
= json_object_new_object();
3889 memset(&wctx
, 0, sizeof(struct rmac_walk_ctx
));
3893 vty_out(vty
, "Number of Remote RMACs known for this VNI: %u\n",
3895 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
3897 json_object_int_add(json
, "numRmacs", num_rmacs
);
3899 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
3902 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3903 json
, JSON_C_TO_STRING_PRETTY
));
3904 json_object_free(json
);
3908 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
, u_char use_json
)
3910 struct zebra_ns
*zns
= NULL
;
3911 json_object
*json
= NULL
;
3914 if (!is_evpn_enabled()) {
3916 vty_out(vty
, "{}\n");
3920 zns
= zebra_ns_lookup(NS_DEFAULT
);
3923 vty_out(vty
, "{}\n");
3928 json
= json_object_new_object();
3932 hash_iterate(zns
->l3vni_table
,
3933 (void (*)(struct hash_backet
*,
3934 void *))zl3vni_print_rmac_hash_all_vni
,
3938 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3939 json
, JSON_C_TO_STRING_PRETTY
));
3940 json_object_free(json
);
3944 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
, vni_t l3vni
,
3945 struct ipaddr
*ip
, u_char use_json
)
3947 zebra_l3vni_t
*zl3vni
= NULL
;
3948 zebra_neigh_t
*n
= NULL
;
3949 json_object
*json
= NULL
;
3951 if (!is_evpn_enabled()) {
3953 vty_out(vty
, "{}\n");
3958 json
= json_object_new_object();
3960 zl3vni
= zl3vni_lookup(l3vni
);
3963 vty_out(vty
, "{}\n");
3965 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
3969 n
= zl3vni_nh_lookup(zl3vni
, ip
);
3972 vty_out(vty
, "{}\n");
3975 "%% Requested next-hop not present for L3-VNI %u",
3980 zl3vni_print_nh(n
, vty
, json
);
3983 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3984 json
, JSON_C_TO_STRING_PRETTY
));
3985 json_object_free(json
);
3989 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
, vni_t l3vni
, u_char use_json
)
3992 struct nh_walk_ctx wctx
;
3993 json_object
*json
= NULL
;
3994 zebra_l3vni_t
*zl3vni
= NULL
;
3996 if (!is_evpn_enabled())
3999 zl3vni
= zl3vni_lookup(l3vni
);
4002 vty_out(vty
, "{}\n");
4004 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
4008 num_nh
= hashcount(zl3vni
->nh_table
);
4013 json
= json_object_new_object();
4018 vty_out(vty
, "Number of NH Neighbors known for this VNI: %u\n",
4020 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
4022 json_object_int_add(json
, "numNextHops", num_nh
);
4024 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
4027 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4028 json
, JSON_C_TO_STRING_PRETTY
));
4029 json_object_free(json
);
4033 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
, u_char use_json
)
4035 struct zebra_ns
*zns
= NULL
;
4036 json_object
*json
= NULL
;
4039 if (!is_evpn_enabled()) {
4041 vty_out(vty
, "{}\n");
4045 zns
= zebra_ns_lookup(NS_DEFAULT
);
4050 json
= json_object_new_object();
4054 hash_iterate(zns
->l3vni_table
,
4055 (void (*)(struct hash_backet
*,
4056 void *))zl3vni_print_nh_hash_all_vni
,
4060 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4061 json
, JSON_C_TO_STRING_PRETTY
));
4062 json_object_free(json
);
4068 * Display L3 VNI information (VTY command handler).
4070 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, u_char use_json
)
4073 json_object
*json
= NULL
;
4074 zebra_l3vni_t
*zl3vni
= NULL
;
4076 if (!is_evpn_enabled()) {
4078 vty_out(vty
, "{}\n");
4082 zl3vni
= zl3vni_lookup(vni
);
4085 vty_out(vty
, "{}\n");
4087 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4092 json
= json_object_new_object();
4096 zl3vni_print(zl3vni
, (void *)args
);
4099 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4100 json
, JSON_C_TO_STRING_PRETTY
));
4101 json_object_free(json
);
4105 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4106 json_object
*json_vrfs
)
4108 char buf
[ETHER_ADDR_STRLEN
];
4109 zebra_l3vni_t
*zl3vni
= NULL
;
4111 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
4116 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
4117 zvrf_name(zvrf
), zl3vni
->vni
,
4118 zl3vni_vxlan_if_name(zl3vni
),
4119 zl3vni_svi_if_name(zl3vni
), zl3vni_state2str(zl3vni
),
4120 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
4122 json_object
*json_vrf
= NULL
;
4123 json_vrf
= json_object_new_object();
4124 json_object_string_add(json_vrf
, "vrf", zvrf_name(zvrf
));
4125 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
4126 json_object_string_add(json_vrf
, "vxlanIntf",
4127 zl3vni_vxlan_if_name(zl3vni
));
4128 json_object_string_add(json_vrf
, "sviIntf",
4129 zl3vni_svi_if_name(zl3vni
));
4130 json_object_string_add(json_vrf
, "state",
4131 zl3vni_state2str(zl3vni
));
4132 json_object_string_add(
4133 json_vrf
, "routerMac",
4134 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
4135 json_object_array_add(json_vrfs
, json_vrf
);
4140 * Display Neighbors for a VNI (VTY command handler).
4142 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4143 vni_t vni
, u_char use_json
)
4146 u_int32_t num_neigh
;
4147 struct neigh_walk_ctx wctx
;
4148 json_object
*json
= NULL
;
4150 if (!is_evpn_enabled())
4152 zvni
= zvni_lookup(vni
);
4155 vty_out(vty
, "{}\n");
4157 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4160 num_neigh
= hashcount(zvni
->neigh_table
);
4165 json
= json_object_new_object();
4167 /* Since we have IPv6 addresses to deal with which can vary widely in
4168 * size, we try to be a bit more elegant in display by first computing
4169 * the maximum width.
4171 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
4174 wctx
.addr_width
= 15;
4176 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
4180 "Number of ARPs (local and remote) known for this VNI: %u\n",
4182 vty_out(vty
, "%*s %-6s %-17s %-21s\n", -wctx
.addr_width
, "IP",
4183 "Type", "MAC", "Remote VTEP");
4185 json_object_int_add(json
, "numArpNd", num_neigh
);
4187 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
4189 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4190 json
, JSON_C_TO_STRING_PRETTY
));
4191 json_object_free(json
);
4196 * Display neighbors across all VNIs (VTY command handler).
4198 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4201 json_object
*json
= NULL
;
4204 if (!is_evpn_enabled())
4208 json
= json_object_new_object();
4212 hash_iterate(zvrf
->vni_table
,
4213 (void (*)(struct hash_backet
*,
4214 void *))zvni_print_neigh_hash_all_vni
,
4217 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4218 json
, JSON_C_TO_STRING_PRETTY
));
4219 json_object_free(json
);
4224 * Display specific neighbor for a VNI, if present (VTY command handler).
4226 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
4227 struct zebra_vrf
*zvrf
, vni_t vni
,
4228 struct ipaddr
*ip
, u_char use_json
)
4232 json_object
*json
= NULL
;
4234 if (!is_evpn_enabled())
4236 zvni
= zvni_lookup(vni
);
4239 vty_out(vty
, "{}\n");
4241 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4244 n
= zvni_neigh_lookup(zvni
, ip
);
4248 "%% Requested neighbor does not exist in VNI %u\n",
4253 json
= json_object_new_object();
4255 zvni_print_neigh(n
, vty
, json
);
4258 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4259 json
, JSON_C_TO_STRING_PRETTY
));
4260 json_object_free(json
);
4265 * Display neighbors for a VNI from specific VTEP (VTY command handler).
4266 * By definition, these are remote neighbors.
4268 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4269 vni_t vni
, struct in_addr vtep_ip
,
4273 u_int32_t num_neigh
;
4274 struct neigh_walk_ctx wctx
;
4275 json_object
*json
= NULL
;
4277 if (!is_evpn_enabled())
4279 zvni
= zvni_lookup(vni
);
4282 vty_out(vty
, "{}\n");
4284 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4287 num_neigh
= hashcount(zvni
->neigh_table
);
4291 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
4294 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
4295 wctx
.r_vtep_ip
= vtep_ip
;
4297 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
4300 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4301 json
, JSON_C_TO_STRING_PRETTY
));
4302 json_object_free(json
);
4307 * Display MACs for a VNI (VTY command handler).
4309 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4310 vni_t vni
, u_char use_json
)
4314 struct mac_walk_ctx wctx
;
4315 json_object
*json
= NULL
;
4316 json_object
*json_mac
= NULL
;
4318 if (!is_evpn_enabled())
4320 zvni
= zvni_lookup(vni
);
4323 vty_out(vty
, "{}\n");
4325 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4328 num_macs
= num_valid_macs(zvni
);
4333 json
= json_object_new_object();
4334 json_mac
= json_object_new_object();
4337 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4340 wctx
.json
= json_mac
;
4344 "Number of MACs (local and remote) known for this VNI: %u\n",
4346 vty_out(vty
, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
4347 "Intf/Remote VTEP", "VLAN");
4349 json_object_int_add(json
, "numMacs", num_macs
);
4351 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
4354 json_object_object_add(json
, "macs", json_mac
);
4355 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4356 json
, JSON_C_TO_STRING_PRETTY
));
4357 json_object_free(json
);
4362 * Display MACs for all VNIs (VTY command handler).
4364 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4367 struct mac_walk_ctx wctx
;
4368 json_object
*json
= NULL
;
4370 if (!is_evpn_enabled()) {
4372 vty_out(vty
, "{}\n");
4376 json
= json_object_new_object();
4378 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4381 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
4384 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4385 json
, JSON_C_TO_STRING_PRETTY
));
4386 json_object_free(json
);
4391 * Display MACs for all VNIs (VTY command handler).
4393 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
4394 struct zebra_vrf
*zvrf
,
4395 struct in_addr vtep_ip
,
4398 struct mac_walk_ctx wctx
;
4399 json_object
*json
= NULL
;
4401 if (!is_evpn_enabled())
4405 json
= json_object_new_object();
4407 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4409 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
4410 wctx
.r_vtep_ip
= vtep_ip
;
4412 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
4415 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4416 json
, JSON_C_TO_STRING_PRETTY
));
4417 json_object_free(json
);
4422 * Display specific MAC for a VNI, if present (VTY command handler).
4424 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4425 vni_t vni
, struct ethaddr
*macaddr
)
4430 if (!is_evpn_enabled())
4432 zvni
= zvni_lookup(vni
);
4434 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4437 mac
= zvni_mac_lookup(zvni
, macaddr
);
4439 vty_out(vty
, "%% Requested MAC does not exist in VNI %u\n",
4444 zvni_print_mac(mac
, vty
);
4448 * Display MACs for a VNI from specific VTEP (VTY command handler).
4450 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4451 vni_t vni
, struct in_addr vtep_ip
,
4456 struct mac_walk_ctx wctx
;
4457 json_object
*json
= NULL
;
4458 json_object
*json_mac
= NULL
;
4460 if (!is_evpn_enabled())
4462 zvni
= zvni_lookup(vni
);
4465 vty_out(vty
, "{}\n");
4467 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4470 num_macs
= num_valid_macs(zvni
);
4475 json
= json_object_new_object();
4476 json_mac
= json_object_new_object();
4479 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4482 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
4483 wctx
.r_vtep_ip
= vtep_ip
;
4484 wctx
.json
= json_mac
;
4485 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
4488 json_object_int_add(json
, "numMacs", wctx
.count
);
4490 json_object_object_add(json
, "macs", json_mac
);
4491 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4492 json
, JSON_C_TO_STRING_PRETTY
));
4493 json_object_free(json
);
4499 * Display VNI information (VTY command handler).
4501 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
4504 json_object
*json
= NULL
;
4506 zebra_l3vni_t
*zl3vni
= NULL
;
4507 zebra_vni_t
*zvni
= NULL
;
4509 if (!is_evpn_enabled())
4513 json
= json_object_new_object();
4517 zl3vni
= zl3vni_lookup(vni
);
4519 zl3vni_print(zl3vni
, (void *)args
);
4521 zvni
= zvni_lookup(vni
);
4524 vty_out(vty
, "{}\n");
4526 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4530 zvni_print(zvni
, (void *)args
);
4534 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4535 json
, JSON_C_TO_STRING_PRETTY
));
4536 json_object_free(json
);
4540 /* Display all global details for EVPN */
4541 void zebra_vxlan_print_evpn(struct vty
*vty
, u_char uj
)
4546 json_object
*json
= NULL
;
4547 struct zebra_ns
*zns
= NULL
;
4548 struct zebra_vrf
*zvrf
= NULL
;
4550 if (!is_evpn_enabled())
4553 zns
= zebra_ns_lookup(NS_DEFAULT
);
4557 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
4561 num_l3vnis
= hashcount(zns
->l3vni_table
);
4562 num_l2vnis
= hashcount(zvrf
->vni_table
);
4563 num_vnis
= num_l2vnis
+ num_l3vnis
;
4566 json
= json_object_new_object();
4567 json_object_string_add(json
, "advertiseGatewayMacip",
4568 zvrf
->advertise_gw_macip
? "Yes" : "No");
4569 json_object_int_add(json
, "numVnis", num_vnis
);
4570 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
4571 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
4573 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
4574 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
4575 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
4576 zvrf
->advertise_gw_macip
? "Yes" : "No");
4580 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4581 json
, JSON_C_TO_STRING_PRETTY
));
4582 json_object_free(json
);
4587 * Display VNI hash table (VTY command handler).
4589 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4592 json_object
*json
= NULL
;
4593 struct zebra_ns
*zns
= NULL
;
4596 if (!is_evpn_enabled())
4599 zns
= zebra_ns_lookup(NS_DEFAULT
);
4605 json
= json_object_new_object();
4607 vty_out(vty
, "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n", "VNI",
4608 "Type", "VxLAN IF", "# MACs", "# ARPs",
4609 "# Remote VTEPs", "Tenant VRF");
4614 /* Display all L2-VNIs */
4615 hash_iterate(zvrf
->vni_table
,
4616 (void (*)(struct hash_backet
*, void *))zvni_print_hash
,
4619 /* Display all L3-VNIs */
4620 hash_iterate(zns
->l3vni_table
,
4621 (void (*)(struct hash_backet
*, void *))zl3vni_print_hash
,
4625 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4626 json
, JSON_C_TO_STRING_PRETTY
));
4627 json_object_free(json
);
4632 * Handle neighbor delete (on a VLAN device / L3 interface) from the
4633 * kernel. This may result in either the neighbor getting deleted from
4634 * our database or being re-added to the kernel (if it is a valid
4637 int zebra_vxlan_local_neigh_del(struct interface
*ifp
,
4638 struct interface
*link_if
, struct ipaddr
*ip
)
4640 char buf
[INET6_ADDRSTRLEN
];
4641 char buf2
[ETHER_ADDR_STRLEN
];
4642 zebra_neigh_t
*n
= NULL
;
4643 zebra_vni_t
*zvni
= NULL
;
4644 zebra_mac_t
*zmac
= NULL
;
4645 zebra_l3vni_t
*zl3vni
= NULL
;
4647 /* check if this is a remote neigh entry corresponding to remote
4650 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4652 return zl3vni_local_nh_del(zl3vni
, ip
);
4654 /* We are only interested in neighbors on an SVI that resides on top
4655 * of a VxLAN bridge.
4657 zvni
= zvni_from_svi(ifp
, link_if
);
4661 if (!zvni
->vxlan_if
) {
4663 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
4668 if (IS_ZEBRA_DEBUG_VXLAN
)
4669 zlog_debug("Del neighbor %s intf %s(%u) -> L2-VNI %u",
4670 ipaddr2str(ip
, buf
, sizeof(buf
)), ifp
->name
,
4671 ifp
->ifindex
, zvni
->vni
);
4673 /* If entry doesn't exist, nothing to do. */
4674 n
= zvni_neigh_lookup(zvni
, ip
);
4678 zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
4680 if (IS_ZEBRA_DEBUG_VXLAN
)
4682 "Trying to del a neigh %s without a mac %s on VNI %u",
4683 ipaddr2str(ip
, buf
, sizeof(buf
)),
4684 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)),
4690 /* If it is a remote entry, the kernel has aged this out or someone has
4691 * deleted it, it needs to be re-installed as Quagga is the owner.
4693 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
4694 zvni_neigh_install(zvni
, n
);
4698 /* Remove neighbor from BGP. */
4699 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
4700 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
, &n
->emac
, 0);
4702 /* Delete this neighbor entry. */
4703 zvni_neigh_del(zvni
, n
);
4705 /* see if the AUTO mac needs to be deleted */
4706 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
4707 && !listcount(zmac
->neigh_list
))
4708 zvni_mac_del(zvni
, zmac
);
4714 * Handle neighbor add or update (on a VLAN device / L3 interface)
4717 int zebra_vxlan_local_neigh_add_update(struct interface
*ifp
,
4718 struct interface
*link_if
,
4720 struct ethaddr
*macaddr
, u_int16_t state
,
4723 char buf
[ETHER_ADDR_STRLEN
];
4724 char buf2
[INET6_ADDRSTRLEN
];
4725 zebra_vni_t
*zvni
= NULL
;
4726 zebra_neigh_t
*n
= NULL
;
4727 zebra_mac_t
*zmac
= NULL
, *old_zmac
= NULL
;
4728 zebra_l3vni_t
*zl3vni
= NULL
;
4730 /* check if this is a remote neigh entry corresponding to remote
4733 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4735 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
4737 /* We are only interested in neighbors on an SVI that resides on top
4738 * of a VxLAN bridge.
4740 zvni
= zvni_from_svi(ifp
, link_if
);
4744 if (IS_ZEBRA_DEBUG_VXLAN
)
4746 "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x %s-> L2-VNI %u",
4747 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4748 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
4749 ifp
->ifindex
, state
, ext_learned
? "ext-learned " : "",
4752 /* create a dummy MAC if the MAC is not already present */
4753 zmac
= zvni_mac_lookup(zvni
, macaddr
);
4755 if (IS_ZEBRA_DEBUG_VXLAN
)
4756 zlog_debug("AUTO MAC %s created for neigh %s on VNI %u",
4757 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4758 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4761 zmac
= zvni_mac_add(zvni
, macaddr
);
4763 zlog_warn("Failed to add MAC %s VNI %u",
4764 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4769 memset(&zmac
->fwd_info
, 0, sizeof(zmac
->fwd_info
));
4770 memset(&zmac
->flags
, 0, sizeof(u_int32_t
));
4771 SET_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
);
4774 /* If same entry already exists, it might be a change or it might be a
4775 * move from remote to local.
4777 n
= zvni_neigh_lookup(zvni
, ip
);
4779 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
4780 if (memcmp(n
->emac
.octet
, macaddr
->octet
, ETH_ALEN
)
4782 /* Update any params and return - client doesn't
4783 * care about a purely local change.
4785 n
->ifindex
= ifp
->ifindex
;
4789 /* If the MAC has changed,
4790 * need to issue a delete first
4791 * as this means a different MACIP route.
4792 * Also, need to do some unlinking/relinking.
4794 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
,
4796 old_zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
4798 listnode_delete(old_zmac
->neigh_list
, n
);
4799 zvni_deref_ip2mac(zvni
, old_zmac
, 0);
4802 /* Set "local" forwarding info. */
4803 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4804 n
->ifindex
= ifp
->ifindex
;
4805 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
4807 /* Link to new MAC */
4808 listnode_add_sort(zmac
->neigh_list
, n
);
4809 } else if (ext_learned
)
4810 /* The neighbor is remote and that is the notification we got.
4813 /* TODO: Evaluate if we need to do anything here. */
4816 /* Neighbor has moved from remote to local. */
4818 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
4819 n
->r_vtep_ip
.s_addr
= 0;
4820 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4821 n
->ifindex
= ifp
->ifindex
;
4824 n
= zvni_neigh_add(zvni
, ip
, macaddr
);
4827 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
4828 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4829 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4830 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
4833 /* Set "local" forwarding info. */
4834 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4835 n
->ifindex
= ifp
->ifindex
;
4838 /* Before we program this in BGP, we need to check if MAC is locally
4840 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
4841 if (IS_ZEBRA_DEBUG_VXLAN
)
4843 "Skipping neigh %s add to client as MAC %s is not local on VNI %u",
4844 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4845 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4852 if (IS_ZEBRA_DEBUG_VXLAN
)
4853 zlog_debug("neigh %s (MAC %s) is now ACTIVE on L2-VNI %u",
4854 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4855 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4857 ZEBRA_NEIGH_SET_ACTIVE(n
);
4859 return zvni_neigh_send_add_to_client(zvni
->vni
, ip
, macaddr
, n
->flags
);
4864 * Handle message from client to delete a remote MACIP for a VNI.
4866 int zebra_vxlan_remote_macip_del(struct zserv
*client
, u_short length
,
4867 struct zebra_vrf
*zvrf
)
4871 struct ethaddr macaddr
;
4873 struct in_addr vtep_ip
;
4877 u_short l
= 0, ipa_len
;
4878 char buf
[ETHER_ADDR_STRLEN
];
4879 char buf1
[INET6_ADDRSTRLEN
];
4880 struct interface
*ifp
= NULL
;
4881 struct zebra_if
*zif
= NULL
;
4883 memset(&macaddr
, 0, sizeof(struct ethaddr
));
4884 memset(&ip
, 0, sizeof(struct ipaddr
));
4885 memset(&vtep_ip
, 0, sizeof(struct in_addr
));
4889 while (l
< length
) {
4890 /* Obtain each remote MACIP and process. */
4891 /* Message contains VNI, followed by MAC followed by IP (if any)
4892 * followed by remote VTEP IP.
4896 memset(&ip
, 0, sizeof(ip
));
4897 STREAM_GETL(s
, vni
);
4898 STREAM_GET(&macaddr
.octet
, s
, ETH_ALEN
);
4899 STREAM_GETL(s
, ipa_len
);
4901 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
4903 STREAM_GET(&ip
.ip
.addr
, s
, ipa_len
);
4905 l
+= 4 + ETH_ALEN
+ 4 + ipa_len
;
4906 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4907 l
+= IPV4_MAX_BYTELEN
;
4909 if (IS_ZEBRA_DEBUG_VXLAN
)
4911 "Recv MACIP Del MAC %s IP %s VNI %u Remote VTEP %s from %s",
4912 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
4913 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
,
4915 zebra_route_string(client
->proto
));
4917 /* Locate VNI hash entry - expected to exist. */
4918 zvni
= zvni_lookup(vni
);
4920 if (IS_ZEBRA_DEBUG_VXLAN
)
4922 "Failed to locate VNI hash upon remote MACIP DEL, "
4927 ifp
= zvni
->vxlan_if
;
4930 "VNI %u hash %p doesn't have intf upon remote MACIP DEL",
4936 /* If down or not mapped to a bridge, we're done. */
4937 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
4940 /* The remote VTEP specified is normally expected to exist, but
4942 * possible that the peer may delete the VTEP before deleting
4944 * referring to the VTEP, in which case the handler (see
4946 * would have already deleted the MACs.
4948 if (!zvni_vtep_find(zvni
, &vtep_ip
))
4951 mac
= zvni_mac_lookup(zvni
, &macaddr
);
4953 n
= zvni_neigh_lookup(zvni
, &ip
);
4956 zlog_err("Failed to locate MAC %s for neigh %s VNI %u",
4957 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
4958 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
);
4962 /* If the remote mac or neighbor doesn't exist there is nothing
4964 * to do. Otherwise, uninstall the entry and then remove it.
4969 /* Ignore the delete if this mac is a gateway mac-ip */
4970 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
4971 && CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
4973 "%u: Ignore Del for MAC %s neigh %s on VNI %u as it is configured as a default gateway",
4975 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
4976 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
);
4980 /* Uninstall remote neighbor or MAC. */
4982 /* When the MAC changes for an IP, it is possible the
4984 * update the new MAC before trying to delete the "old"
4986 * (as these are two different MACIP routes). Do the
4988 * if the MAC matches.
4990 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
4991 && (memcmp(n
->emac
.octet
, macaddr
.octet
, ETH_ALEN
)
4993 zvni_neigh_uninstall(zvni
, n
);
4994 zvni_neigh_del(zvni
, n
);
4995 zvni_deref_ip2mac(zvni
, mac
, 1);
4998 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
4999 zvni_process_neigh_on_remote_mac_del(zvni
, mac
);
5001 if (list_isempty(mac
->neigh_list
)) {
5002 zvni_mac_uninstall(zvni
, mac
, 0);
5003 zvni_mac_del(zvni
, mac
);
5005 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5015 * Handle message from client to add a remote MACIP for a VNI. This
5016 * could be just the add of a MAC address or the add of a neighbor
5019 int zebra_vxlan_remote_macip_add(struct zserv
*client
, u_short length
,
5020 struct zebra_vrf
*zvrf
)
5024 struct ethaddr macaddr
;
5026 struct in_addr vtep_ip
;
5028 zebra_vtep_t
*zvtep
;
5029 zebra_mac_t
*mac
, *old_mac
;
5031 u_short l
= 0, ipa_len
;
5032 int update_mac
= 0, update_neigh
= 0;
5033 char buf
[ETHER_ADDR_STRLEN
];
5034 char buf1
[INET6_ADDRSTRLEN
];
5037 struct interface
*ifp
= NULL
;
5038 struct zebra_if
*zif
= NULL
;
5040 memset(&macaddr
, 0, sizeof(struct ethaddr
));
5041 memset(&ip
, 0, sizeof(struct ipaddr
));
5042 memset(&vtep_ip
, 0, sizeof(struct in_addr
));
5044 if (!EVPN_ENABLED(zvrf
)) {
5046 "%s: EVPN Not turned on yet we have received a remote_macip add zapi callback",
5047 __PRETTY_FUNCTION__
);
5053 while (l
< length
) {
5054 /* Obtain each remote MACIP and process. */
5055 /* Message contains VNI, followed by MAC followed by IP (if any)
5056 * followed by remote VTEP IP.
5058 update_mac
= update_neigh
= 0;
5061 memset(&ip
, 0, sizeof(ip
));
5062 STREAM_GETL(s
, vni
);
5063 STREAM_GET(&macaddr
.octet
, s
, ETH_ALEN
);
5064 STREAM_GETL(s
, ipa_len
);
5066 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
5068 STREAM_GET(&ip
.ip
.addr
, s
, ipa_len
);
5070 l
+= 4 + ETH_ALEN
+ 4 + ipa_len
;
5071 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5072 l
+= IPV4_MAX_BYTELEN
;
5074 /* Get flags - sticky mac and/or gateway mac */
5075 flags
= stream_getc(s
);
5076 sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
5079 if (IS_ZEBRA_DEBUG_VXLAN
)
5081 "Recv MACIP Add MAC %s IP %s VNI %u Remote VTEP %s with flags 0x%x from %s",
5082 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
5083 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
,
5084 inet_ntoa(vtep_ip
), flags
,
5085 zebra_route_string(client
->proto
));
5087 /* Locate VNI hash entry - expected to exist. */
5088 zvni
= zvni_lookup(vni
);
5091 "Failed to locate VNI hash upon remote MACIP ADD, VNI %u",
5095 ifp
= zvni
->vxlan_if
;
5098 "VNI %u hash %p doesn't have intf upon remote MACIP add",
5104 /* If down or not mapped to a bridge, we're done. */
5105 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5108 /* The remote VTEP specified should normally exist, but it is
5110 * that when peering comes up, peer may advertise MACIP routes
5112 * advertising type-3 routes.
5114 zvtep
= zvni_vtep_find(zvni
, &vtep_ip
);
5116 if (zvni_vtep_add(zvni
, &vtep_ip
) == NULL
) {
5118 "Failed to add remote VTEP, VNI %u zvni %p",
5123 zvni_vtep_install(zvni
, &vtep_ip
);
5126 mac
= zvni_mac_lookup(zvni
, &macaddr
);
5128 /* Ignore the update if the mac is already present
5130 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)
5131 && CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
)) {
5132 if (IS_ZEBRA_DEBUG_VXLAN
)
5134 "%u:Ignore MAC %s IP %s on VNI %u as MAC is already configured as gateway mac",
5136 prefix_mac2str(&macaddr
, buf
,
5138 ipaddr2str(&ip
, buf1
, sizeof(buf1
)),
5143 /* check if the remote MAC is unknown or has a change.
5144 * If so, that needs to be updated first. Note that client could
5145 * install MAC and MACIP separately or just install the latter.
5147 if (!mac
|| !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
5148 || (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
) ? 1 : 0)
5150 || !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &vtep_ip
))
5155 mac
= zvni_mac_add(zvni
, &macaddr
);
5158 "Failed to add MAC %s VNI %u Remote VTEP %s",
5159 prefix_mac2str(&macaddr
, buf
,
5161 vni
, inet_ntoa(vtep_ip
));
5165 /* Is this MAC created for a MACIP? */
5167 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5170 /* Set "auto" and "remote" forwarding info. */
5171 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5172 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
5173 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
5174 mac
->fwd_info
.r_vtep_ip
= vtep_ip
;
5177 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5179 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5181 zvni_process_neigh_on_remote_mac_add(zvni
, mac
);
5183 /* Install the entry. */
5184 zvni_mac_install(zvni
, mac
);
5187 /* If there is no IP, continue - after clearing AUTO flag of
5190 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5194 /* Check if the remote neighbor itself is unknown or has a
5196 * If so, create or update and then install the entry.
5198 n
= zvni_neigh_lookup(zvni
, &ip
);
5199 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
5200 || (memcmp(&n
->emac
, &macaddr
, sizeof(macaddr
)) != 0)
5201 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
))
5206 n
= zvni_neigh_add(zvni
, &ip
, &macaddr
);
5209 "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s",
5210 ipaddr2str(&ip
, buf1
,
5212 prefix_mac2str(&macaddr
, buf
,
5214 vni
, inet_ntoa(vtep_ip
));
5218 } else if (memcmp(&n
->emac
, &macaddr
, sizeof(macaddr
))
5220 /* MAC change, update neigh list for old and new
5222 old_mac
= zvni_mac_lookup(zvni
, &n
->emac
);
5224 listnode_delete(old_mac
->neigh_list
, n
);
5225 zvni_deref_ip2mac(zvni
, old_mac
, 1);
5227 listnode_add_sort(mac
->neigh_list
, n
);
5228 memcpy(&n
->emac
, &macaddr
, ETH_ALEN
);
5231 /* Set "remote" forwarding info. */
5232 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
5233 /* TODO: Handle MAC change. */
5234 n
->r_vtep_ip
= vtep_ip
;
5235 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
5237 /* Install the entry. */
5238 zvni_neigh_install(zvni
, n
);
5247 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
5248 * us, this must involve a multihoming scenario. Treat this as implicit delete
5249 * of any prior local MAC.
5251 int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
5252 struct interface
*br_if
,
5253 struct ethaddr
*macaddr
, vlanid_t vid
)
5255 struct zebra_if
*zif
;
5256 struct zebra_l2info_vxlan
*vxl
;
5260 char buf
[ETHER_ADDR_STRLEN
];
5264 vxl
= &zif
->l2info
.vxl
;
5267 /* Check if EVPN is enabled. */
5268 if (!is_evpn_enabled())
5271 /* Locate hash entry; it is expected to exist. */
5272 zvni
= zvni_lookup(vni
);
5276 /* If entry doesn't exist, nothing to do. */
5277 mac
= zvni_mac_lookup(zvni
, macaddr
);
5281 /* Is it a local entry? */
5282 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
5285 if (IS_ZEBRA_DEBUG_VXLAN
)
5287 "Add/update remote MAC %s intf %s(%u) VNI %u - del local",
5288 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5291 /* Remove MAC from BGP. */
5292 zvni_mac_send_del_to_client(zvni
->vni
, macaddr
, mac
->flags
);
5295 * If there are no neigh associated with the mac delete the mac
5296 * else mark it as AUTO for forward reference
5298 if (!listcount(mac
->neigh_list
)) {
5299 zvni_mac_del(zvni
, mac
);
5301 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5302 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5309 * Handle remote MAC delete by kernel; readd the remote MAC if we have it.
5310 * This can happen because the remote MAC entries are also added as "dynamic",
5311 * so the kernel can ageout the entry.
5313 int zebra_vxlan_check_readd_remote_mac(struct interface
*ifp
,
5314 struct interface
*br_if
,
5315 struct ethaddr
*macaddr
, vlanid_t vid
)
5317 struct zebra_if
*zif
= NULL
;
5318 struct zebra_l2info_vxlan
*vxl
= NULL
;
5320 zebra_vni_t
*zvni
= NULL
;
5321 zebra_l3vni_t
*zl3vni
= NULL
;
5322 zebra_mac_t
*mac
= NULL
;
5323 char buf
[ETHER_ADDR_STRLEN
];
5327 vxl
= &zif
->l2info
.vxl
;
5330 /* Check if EVPN is enabled. */
5331 if (!is_evpn_enabled())
5334 /* check if this is a remote RMAC and readd simillar to remote macs */
5335 zl3vni
= zl3vni_lookup(vni
);
5337 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
5339 /* Locate hash entry; it is expected to exist. */
5340 zvni
= zvni_lookup(vni
);
5344 /* If entry doesn't exist, nothing to do. */
5345 mac
= zvni_mac_lookup(zvni
, macaddr
);
5349 /* Is it a remote entry? */
5350 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
5353 if (IS_ZEBRA_DEBUG_VXLAN
)
5354 zlog_debug("Del remote MAC %s intf %s(%u) VNI %u - readd",
5355 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5358 zvni_mac_install(zvni
, mac
);
5363 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
5365 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
5366 struct ethaddr
*macaddr
, vlanid_t vid
)
5370 char buf
[ETHER_ADDR_STRLEN
];
5372 /* We are interested in MACs only on ports or (port, VLAN) that
5375 zvni
= zvni_map_vlan(ifp
, br_if
, vid
);
5378 if (!zvni
->vxlan_if
) {
5379 zlog_err("VNI %u hash %p doesn't have intf upon local MAC DEL",
5384 if (IS_ZEBRA_DEBUG_VXLAN
)
5385 zlog_debug("Del MAC %s intf %s(%u) VID %u -> VNI %u",
5386 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5387 ifp
->ifindex
, vid
, zvni
->vni
);
5389 /* If entry doesn't exist, nothing to do. */
5390 mac
= zvni_mac_lookup(zvni
, macaddr
);
5394 /* Is it a local entry? */
5395 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
5398 /* Remove MAC from BGP. */
5399 zvni_mac_send_del_to_client(zvni
->vni
, macaddr
, mac
->flags
);
5401 /* Update all the neigh entries associated with this mac */
5402 zvni_process_neigh_on_local_mac_del(zvni
, mac
);
5405 * If there are no neigh associated with the mac delete the mac
5406 * else mark it as AUTO for forward reference
5408 if (!listcount(mac
->neigh_list
)) {
5409 zvni_mac_del(zvni
, mac
);
5411 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5412 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5419 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
5421 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
5422 struct interface
*br_if
,
5423 struct ethaddr
*macaddr
, vlanid_t vid
,
5428 char buf
[ETHER_ADDR_STRLEN
];
5432 /* We are interested in MACs only on ports or (port, VLAN) that
5435 zvni
= zvni_map_vlan(ifp
, br_if
, vid
);
5437 if (IS_ZEBRA_DEBUG_VXLAN
)
5439 "Add/Update %sMAC %s intf %s(%u) VID %u, could not find VNI",
5440 sticky
? "sticky " : "",
5441 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
5442 ifp
->name
, ifp
->ifindex
, vid
);
5446 if (!zvni
->vxlan_if
) {
5447 zlog_err("VNI %u hash %p doesn't have intf upon local MAC ADD",
5452 if (IS_ZEBRA_DEBUG_VXLAN
)
5453 zlog_debug("Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u",
5454 sticky
? "sticky " : "",
5455 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5456 ifp
->ifindex
, vid
, zvni
->vni
);
5458 /* If same entry already exists, nothing to do. */
5459 mac
= zvni_mac_lookup(zvni
, macaddr
);
5461 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
5462 mac_sticky
= CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)
5468 * return if nothing has changed.
5469 * inform bgp if sticky flag has changed
5470 * update locally and do not inform bgp if local
5471 * parameters like interface has changed
5473 if (mac_sticky
== sticky
5474 && mac
->fwd_info
.local
.ifindex
== ifp
->ifindex
5475 && mac
->fwd_info
.local
.vid
== vid
) {
5476 if (IS_ZEBRA_DEBUG_VXLAN
)
5478 "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, "
5479 "entry exists and has not changed ",
5480 sticky
? "sticky " : "",
5481 prefix_mac2str(macaddr
, buf
,
5483 ifp
->name
, ifp
->ifindex
, vid
,
5486 } else if (mac_sticky
!= sticky
) {
5489 add
= 0; /* This is an update of local
5492 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
5494 * If we have already learned the MAC as a remote sticky
5496 * this is a operator error and we must log a warning
5498 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)) {
5500 "MAC %s is already learnt as a remote sticky mac behind VTEP %s VNI %d",
5501 prefix_mac2str(macaddr
, buf
,
5503 inet_ntoa(mac
->fwd_info
.r_vtep_ip
),
5511 mac
= zvni_mac_add(zvni
, macaddr
);
5513 zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
5514 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
5515 ifp
->name
, ifp
->ifindex
, vid
);
5520 /* Set "local" forwarding info. */
5521 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
5522 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5523 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5524 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
5525 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
5526 mac
->fwd_info
.local
.vid
= vid
;
5529 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5531 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5533 /* Inform BGP if required. */
5535 zvni_process_neigh_on_local_mac_add(zvni
, mac
);
5536 return zvni_mac_send_add_to_client(zvni
->vni
, macaddr
,
5544 * Handle message from client to delete a remote VTEP for a VNI.
5546 int zebra_vxlan_remote_vtep_del(struct zserv
*client
, u_short length
,
5547 struct zebra_vrf
*zvrf
)
5552 struct in_addr vtep_ip
;
5554 zebra_vtep_t
*zvtep
;
5555 struct interface
*ifp
;
5556 struct zebra_if
*zif
;
5558 if (!is_evpn_enabled()) {
5560 "%s: EVPN is not enabled yet we have received a vtep del command",
5561 __PRETTY_FUNCTION__
);
5565 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
5566 zlog_err("Recv MACIP DEL for non-default VRF %u",
5573 while (l
< length
) {
5574 /* Obtain each remote VTEP and process. */
5575 STREAM_GETL(s
, vni
);
5577 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5578 l
+= IPV4_MAX_BYTELEN
;
5580 if (IS_ZEBRA_DEBUG_VXLAN
)
5581 zlog_debug("Recv VTEP_DEL %s VNI %u from %s",
5582 inet_ntoa(vtep_ip
), vni
,
5583 zebra_route_string(client
->proto
));
5585 /* Locate VNI hash entry - expected to exist. */
5586 zvni
= zvni_lookup(vni
);
5588 if (IS_ZEBRA_DEBUG_VXLAN
)
5590 "Failed to locate VNI hash upon remote VTEP DEL, "
5596 ifp
= zvni
->vxlan_if
;
5599 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
5605 /* If down or not mapped to a bridge, we're done. */
5606 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5609 /* If the remote VTEP does not exist, there's nothing more to
5611 * Otherwise, uninstall any remote MACs pointing to this VTEP
5613 * then, the VTEP entry itself and remove it.
5615 zvtep
= zvni_vtep_find(zvni
, &vtep_ip
);
5619 zvni_neigh_del_from_vtep(zvni
, 1, &vtep_ip
);
5620 zvni_mac_del_from_vtep(zvni
, 1, &vtep_ip
);
5621 zvni_vtep_uninstall(zvni
, &vtep_ip
);
5622 zvni_vtep_del(zvni
, zvtep
);
5630 * Handle message from client to add a remote VTEP for a VNI.
5632 int zebra_vxlan_remote_vtep_add(struct zserv
*client
, u_short length
,
5633 struct zebra_vrf
*zvrf
)
5638 struct in_addr vtep_ip
;
5640 struct interface
*ifp
;
5641 struct zebra_if
*zif
;
5643 if (!is_evpn_enabled()) {
5645 "%s: EVPN not enabled yet we received a vtep_add zapi call",
5646 __PRETTY_FUNCTION__
);
5650 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
5651 zlog_err("Recv MACIP ADD for non-default VRF %u",
5658 while (l
< length
) {
5659 /* Obtain each remote VTEP and process. */
5660 STREAM_GETL(s
, vni
);
5662 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5663 l
+= IPV4_MAX_BYTELEN
;
5665 if (IS_ZEBRA_DEBUG_VXLAN
)
5666 zlog_debug("Recv VTEP_ADD %s VNI %u from %s",
5667 inet_ntoa(vtep_ip
), vni
,
5668 zebra_route_string(client
->proto
));
5670 /* Locate VNI hash entry - expected to exist. */
5671 zvni
= zvni_lookup(vni
);
5674 "Failed to locate VNI hash upon remote VTEP ADD, VNI %u",
5679 ifp
= zvni
->vxlan_if
;
5682 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
5689 /* If down or not mapped to a bridge, we're done. */
5690 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5693 /* If the remote VTEP already exists,
5694 there's nothing more to do. */
5695 if (zvni_vtep_find(zvni
, &vtep_ip
))
5698 if (zvni_vtep_add(zvni
, &vtep_ip
) == NULL
) {
5699 zlog_err("Failed to add remote VTEP, VNI %u zvni %p",
5704 zvni_vtep_install(zvni
, &vtep_ip
);
5712 * Add/Del gateway macip to evpn
5714 * 1. SVI interface on a vlan aware bridge
5715 * 2. SVI interface on a vlan unaware bridge
5716 * 3. vrr interface (MACVLAN) associated to a SVI
5717 * We advertise macip routes for an interface if it is associated to VxLan vlan
5719 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, struct prefix
*p
,
5723 struct ethaddr macaddr
;
5724 zebra_vni_t
*zvni
= NULL
;
5726 memset(&ip
, 0, sizeof(struct ipaddr
));
5727 memset(&macaddr
, 0, sizeof(struct ethaddr
));
5729 /* Check if EVPN is enabled. */
5730 if (!is_evpn_enabled())
5733 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
5734 struct interface
*svi_if
=
5735 NULL
; /* SVI corresponding to the MACVLAN */
5736 struct zebra_if
*ifp_zif
=
5737 NULL
; /* Zebra daemon specific info for MACVLAN */
5738 struct zebra_if
*svi_if_zif
=
5739 NULL
; /* Zebra daemon specific info for SVI*/
5741 ifp_zif
= ifp
->info
;
5746 * for a MACVLAN interface the link represents the svi_if
5748 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5749 ifp_zif
->link_ifindex
);
5751 zlog_err("MACVLAN %s(%u) without link information",
5752 ifp
->name
, ifp
->ifindex
);
5756 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
5758 * If it is a vlan aware bridge then the link gives the
5759 * bridge information
5761 struct interface
*svi_if_link
= NULL
;
5763 svi_if_zif
= svi_if
->info
;
5765 svi_if_link
= if_lookup_by_index_per_ns(
5766 zebra_ns_lookup(NS_DEFAULT
),
5767 svi_if_zif
->link_ifindex
);
5768 zvni
= zvni_from_svi(svi_if
, svi_if_link
);
5770 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
5772 * If it is a vlan unaware bridge then svi is the bridge
5775 zvni
= zvni_from_svi(svi_if
, svi_if
);
5777 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
5778 struct zebra_if
*svi_if_zif
=
5779 NULL
; /* Zebra daemon specific info for SVI */
5780 struct interface
*svi_if_link
=
5781 NULL
; /* link info for the SVI = bridge info */
5783 svi_if_zif
= ifp
->info
;
5784 svi_if_link
= if_lookup_by_index_per_ns(
5785 zebra_ns_lookup(NS_DEFAULT
), svi_if_zif
->link_ifindex
);
5786 if (svi_if_zif
&& svi_if_link
)
5787 zvni
= zvni_from_svi(ifp
, svi_if_link
);
5788 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
5789 zvni
= zvni_from_svi(ifp
, ifp
);
5795 if (!zvni
->vxlan_if
) {
5796 zlog_err("VNI %u hash %p doesn't have intf upon MACVLAN up",
5802 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
5804 if (p
->family
== AF_INET
) {
5805 ip
.ipa_type
= IPADDR_V4
;
5806 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
5807 sizeof(struct in_addr
));
5808 } else if (p
->family
== AF_INET6
) {
5809 ip
.ipa_type
= IPADDR_V6
;
5810 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
5811 sizeof(struct in6_addr
));
5816 zvni_gw_macip_add(ifp
, zvni
, &macaddr
, &ip
);
5818 zvni_gw_macip_del(ifp
, zvni
, &ip
);
5824 * Handle SVI interface going down.
5825 * SVI can be associated to either L3-VNI or L2-VNI.
5826 * For L2-VNI: At this point, this is a NOP since
5827 * the kernel deletes the neighbor entries on this SVI (if any).
5828 * We only need to update the vrf corresponding to zvni.
5829 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
5832 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
5834 zebra_l3vni_t
*zl3vni
= NULL
;
5836 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
5839 /* process l3-vni down */
5840 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5842 /* remove association with svi-if */
5843 zl3vni
->svi_if
= NULL
;
5845 zebra_vni_t
*zvni
= NULL
;
5847 /* since we dont have svi corresponding to zvni, we associate it
5848 * to default vrf. Note: the corresponding neigh entries on the
5849 * SVI would have already been deleted */
5850 zvni
= zvni_from_svi(ifp
, link_if
);
5852 zvni
->vrf_id
= VRF_DEFAULT
;
5854 /* update the tenant vrf in BGP */
5855 zvni_send_add_to_client(zvni
);
5862 * Handle SVI interface coming up.
5863 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
5865 * For L2-VNI: we need to install any remote neighbors entried (used for
5867 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
5869 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
5871 zebra_vni_t
*zvni
= NULL
;
5872 zebra_l3vni_t
*zl3vni
= NULL
;
5874 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
5877 /* associate with svi */
5878 zl3vni
->svi_if
= ifp
;
5880 /* process oper-up */
5881 if (is_l3vni_oper_up(zl3vni
))
5882 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5885 /* process SVI up for l2-vni */
5886 struct neigh_walk_ctx n_wctx
;
5888 zvni
= zvni_from_svi(ifp
, link_if
);
5892 if (!zvni
->vxlan_if
) {
5893 zlog_err("VNI %u hash %p doesn't have intf upon SVI up",
5898 if (IS_ZEBRA_DEBUG_VXLAN
)
5900 "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
5901 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
5902 vrf_id_to_name(ifp
->vrf_id
));
5904 /* update the vrf information for l2-vni and inform bgp */
5905 zvni
->vrf_id
= ifp
->vrf_id
;
5906 zvni_send_add_to_client(zvni
);
5908 /* Install any remote neighbors for this VNI. */
5909 memset(&n_wctx
, 0, sizeof(struct neigh_walk_ctx
));
5911 hash_iterate(zvni
->neigh_table
, zvni_install_neigh_hash
,
5919 * Handle VxLAN interface down
5921 int zebra_vxlan_if_down(struct interface
*ifp
)
5924 struct zebra_if
*zif
= NULL
;
5925 struct zebra_l2info_vxlan
*vxl
= NULL
;
5926 zebra_l3vni_t
*zl3vni
= NULL
;
5929 /* Check if EVPN is enabled. */
5930 if (!is_evpn_enabled())
5935 vxl
= &zif
->l2info
.vxl
;
5938 zl3vni
= zl3vni_lookup(vni
);
5940 /* process-if-down for l3-vni */
5941 if (IS_ZEBRA_DEBUG_VXLAN
)
5942 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN", ifp
->name
,
5945 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5947 /* process if-down for l2-vni */
5948 if (IS_ZEBRA_DEBUG_VXLAN
)
5949 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN", ifp
->name
,
5952 /* Locate hash entry; it is expected to exist. */
5953 zvni
= zvni_lookup(vni
);
5956 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
5957 ifp
->name
, ifp
->ifindex
, vni
);
5961 assert(zvni
->vxlan_if
== ifp
);
5963 /* Delete this VNI from BGP. */
5964 zvni_send_del_to_client(zvni
->vni
);
5966 /* Free up all neighbors and MACs, if any. */
5967 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
5968 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
5970 /* Free up all remote VTEPs, if any. */
5971 zvni_vtep_del_all(zvni
, 1);
5977 * Handle VxLAN interface up - update BGP if required.
5979 int zebra_vxlan_if_up(struct interface
*ifp
)
5982 struct zebra_if
*zif
= NULL
;
5983 struct zebra_l2info_vxlan
*vxl
= NULL
;
5984 zebra_vni_t
*zvni
= NULL
;
5985 zebra_l3vni_t
*zl3vni
= NULL
;
5987 /* Check if EVPN is enabled. */
5988 if (!is_evpn_enabled())
5993 vxl
= &zif
->l2info
.vxl
;
5996 zl3vni
= zl3vni_lookup(vni
);
5999 if (IS_ZEBRA_DEBUG_VXLAN
)
6000 zlog_debug("Intf %s(%u) L3-VNI %u is UP", ifp
->name
,
6003 /* we need to associate with SVI, if any, we can associate with
6004 * svi-if only after association with vxlan-intf is complete
6006 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6008 if (is_l3vni_oper_up(zl3vni
))
6009 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6011 /* Handle L2-VNI add */
6012 struct interface
*vlan_if
= NULL
;
6014 if (IS_ZEBRA_DEBUG_VXLAN
)
6015 zlog_debug("Intf %s(%u) L2-VNI %u is UP", ifp
->name
,
6018 /* Locate hash entry; it is expected to exist. */
6019 zvni
= zvni_lookup(vni
);
6022 "Failed to locate VNI hash at UP, IF %s(%u) VNI %u",
6023 ifp
->name
, ifp
->ifindex
, vni
);
6027 assert(zvni
->vxlan_if
== ifp
);
6028 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
6029 zif
->brslave_info
.br_if
);
6031 zvni
->vrf_id
= vlan_if
->vrf_id
;
6032 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
6034 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
6037 /* If part of a bridge, inform BGP about this VNI. */
6038 /* Also, read and populate local MACs and neighbors. */
6039 if (zif
->brslave_info
.br_if
) {
6040 zvni_send_add_to_client(zvni
);
6041 zvni_read_mac_neigh(zvni
, ifp
);
6049 * Handle VxLAN interface delete. Locate and remove entry in hash table
6050 * and update BGP, if required.
6052 int zebra_vxlan_if_del(struct interface
*ifp
)
6055 struct zebra_if
*zif
= NULL
;
6056 struct zebra_l2info_vxlan
*vxl
= NULL
;
6057 zebra_vni_t
*zvni
= NULL
;
6058 zebra_l3vni_t
*zl3vni
= NULL
;
6060 /* Check if EVPN is enabled. */
6061 if (!is_evpn_enabled())
6066 vxl
= &zif
->l2info
.vxl
;
6069 zl3vni
= zl3vni_lookup(vni
);
6072 if (IS_ZEBRA_DEBUG_VXLAN
)
6073 zlog_debug("Del L3-VNI %u intf %s(%u)", vni
, ifp
->name
,
6076 /* process oper-down for l3-vni */
6077 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6079 /* remove the association with vxlan_if */
6080 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
6081 zl3vni
->vxlan_if
= NULL
;
6084 /* process if-del for l2-vni*/
6085 if (IS_ZEBRA_DEBUG_VXLAN
)
6086 zlog_debug("Del L2-VNI %u intf %s(%u)", vni
, ifp
->name
,
6089 /* Locate hash entry; it is expected to exist. */
6090 zvni
= zvni_lookup(vni
);
6093 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
6094 ifp
->name
, ifp
->ifindex
, vni
);
6098 /* remove from l3-vni list */
6099 zl3vni
= zl3vni_from_vrf(zvni
->vrf_id
);
6101 listnode_delete(zl3vni
->l2vnis
, zvni
);
6103 /* Delete VNI from BGP. */
6104 zvni_send_del_to_client(zvni
->vni
);
6106 /* Free up all neighbors and MAC, if any. */
6107 zvni_neigh_del_all(zvni
, 0, 0, DEL_ALL_NEIGH
);
6108 zvni_mac_del_all(zvni
, 0, 0, DEL_ALL_MAC
);
6110 /* Free up all remote VTEPs, if any. */
6111 zvni_vtep_del_all(zvni
, 0);
6113 /* Delete the hash entry. */
6114 if (zvni_del(zvni
)) {
6115 zlog_err("Failed to del VNI hash %p, IF %s(%u) VNI %u",
6116 zvni
, ifp
->name
, ifp
->ifindex
, zvni
->vni
);
6124 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
6126 int zebra_vxlan_if_update(struct interface
*ifp
, u_int16_t chgflags
)
6129 struct zebra_if
*zif
= NULL
;
6130 struct zebra_l2info_vxlan
*vxl
= NULL
;
6131 zebra_vni_t
*zvni
= NULL
;
6132 zebra_l3vni_t
*zl3vni
= NULL
;
6134 /* Check if EVPN is enabled. */
6135 if (!is_evpn_enabled())
6140 vxl
= &zif
->l2info
.vxl
;
6143 zl3vni
= zl3vni_lookup(vni
);
6146 if (IS_ZEBRA_DEBUG_VXLAN
)
6148 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x",
6149 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
6150 inet_ntoa(vxl
->vtep_ip
),
6151 zif
->brslave_info
.bridge_ifindex
, chgflags
);
6153 /* Removed from bridge? Cleanup and return */
6154 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6155 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
6156 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6160 /* access-vlan change - process oper down, associate with new
6161 * svi_if and then process oper up again
6163 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6164 if (if_is_operative(ifp
)) {
6165 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6166 zl3vni
->svi_if
= NULL
;
6167 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6168 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
6169 if (is_l3vni_oper_up(zl3vni
))
6170 zebra_vxlan_process_l3vni_oper_up(
6176 * local-ip change - process oper down, associate with new
6177 * local-ip and then process oper up again
6179 if (chgflags
& ZEBRA_VXLIF_LOCAL_IP_CHANGE
) {
6180 if (if_is_operative(ifp
)) {
6181 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6182 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
6183 if (is_l3vni_oper_up(zl3vni
))
6184 zebra_vxlan_process_l3vni_oper_up(
6189 /* Update local tunnel IP. */
6190 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
6192 /* if we have a valid new master, process l3-vni oper up */
6193 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
6194 if (if_is_operative(ifp
) && is_l3vni_oper_up(zl3vni
))
6195 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6199 /* Update VNI hash. */
6200 zvni
= zvni_lookup(vni
);
6203 "Failed to find L2-VNI hash on update, IF %s(%u) VNI %u",
6204 ifp
->name
, ifp
->ifindex
, vni
);
6208 if (IS_ZEBRA_DEBUG_VXLAN
)
6210 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x",
6211 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
6212 inet_ntoa(vxl
->vtep_ip
),
6213 zif
->brslave_info
.bridge_ifindex
, chgflags
);
6215 /* Removed from bridge? Cleanup and return */
6216 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6217 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
6218 /* Delete from client, remove all remote VTEPs */
6219 /* Also, free up all MACs and neighbors. */
6220 zvni_send_del_to_client(zvni
->vni
);
6221 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
6222 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
6223 zvni_vtep_del_all(zvni
, 1);
6227 /* Handle other changes. */
6228 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6229 /* Remove all existing local neigh and MACs for this VNI
6230 * (including from BGP)
6232 zvni_neigh_del_all(zvni
, 0, 1, DEL_LOCAL_MAC
);
6233 zvni_mac_del_all(zvni
, 0, 1, DEL_LOCAL_MAC
);
6236 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
6237 zvni
->vxlan_if
= ifp
;
6239 /* Take further actions needed.
6240 * Note that if we are here, there is a change of interest.
6242 /* If down or not mapped to a bridge, we're done. */
6243 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6246 /* Inform BGP, if there is a change of interest. */
6248 & (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
))
6249 zvni_send_add_to_client(zvni
);
6251 /* If there is a valid new master or a VLAN mapping change,
6252 * read and populate local MACs and neighbors.
6253 * Also, reinstall any remote MACs and neighbors
6254 * for this VNI (based on new VLAN).
6256 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6257 zvni_read_mac_neigh(zvni
, ifp
);
6258 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6259 struct mac_walk_ctx m_wctx
;
6260 struct neigh_walk_ctx n_wctx
;
6262 zvni_read_mac_neigh(zvni
, ifp
);
6264 memset(&m_wctx
, 0, sizeof(struct mac_walk_ctx
));
6266 hash_iterate(zvni
->mac_table
, zvni_install_mac_hash
,
6269 memset(&n_wctx
, 0, sizeof(struct neigh_walk_ctx
));
6271 hash_iterate(zvni
->neigh_table
, zvni_install_neigh_hash
,
6280 * Handle VxLAN interface add.
6282 int zebra_vxlan_if_add(struct interface
*ifp
)
6285 struct zebra_if
*zif
= NULL
;
6286 struct zebra_l2info_vxlan
*vxl
= NULL
;
6287 zebra_vni_t
*zvni
= NULL
;
6288 zebra_l3vni_t
*zl3vni
= NULL
;
6290 /* Check if EVPN is enabled. */
6291 if (!is_evpn_enabled())
6296 vxl
= &zif
->l2info
.vxl
;
6299 zl3vni
= zl3vni_lookup(vni
);
6302 /* process if-add for l3-vni*/
6303 if (IS_ZEBRA_DEBUG_VXLAN
)
6305 "Add L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u",
6306 vni
, ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
6307 inet_ntoa(vxl
->vtep_ip
),
6308 zif
->brslave_info
.bridge_ifindex
);
6310 /* associate with vxlan_if */
6311 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
6312 zl3vni
->vxlan_if
= ifp
;
6314 /* Associate with SVI, if any. We can associate with svi-if only
6315 * after association with vxlan_if is complete */
6316 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6318 if (is_l3vni_oper_up(zl3vni
))
6319 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6322 /* process if-add for l2-vni */
6323 struct interface
*vlan_if
= NULL
;
6325 /* Create or update VNI hash. */
6326 zvni
= zvni_lookup(vni
);
6328 zvni
= zvni_add(vni
);
6331 "Failed to add VNI hash, IF %s(%u) VNI %u",
6332 ifp
->name
, ifp
->ifindex
, vni
);
6337 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
6338 zvni
->vxlan_if
= ifp
;
6339 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
6340 zif
->brslave_info
.br_if
);
6342 zvni
->vrf_id
= vlan_if
->vrf_id
;
6343 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
6345 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
6348 if (IS_ZEBRA_DEBUG_VXLAN
)
6350 "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s master %u",
6352 vlan_if
? vrf_id_to_name(vlan_if
->vrf_id
)
6354 ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
,
6355 inet_ntoa(vxl
->vtep_ip
),
6356 zif
->brslave_info
.bridge_ifindex
);
6358 /* If down or not mapped to a bridge, we're done. */
6359 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6363 zvni_send_add_to_client(zvni
);
6365 /* Read and populate local MACs and neighbors */
6366 zvni_read_mac_neigh(zvni
, ifp
);
6372 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
, vni_t vni
,
6373 char *err
, int err_str_sz
, int filter
,
6376 zebra_l3vni_t
*zl3vni
= NULL
;
6377 struct zebra_vrf
*zvrf_default
= NULL
;
6379 zvrf_default
= zebra_vrf_lookup_by_id(VRF_DEFAULT
);
6383 if (IS_ZEBRA_DEBUG_VXLAN
)
6384 zlog_debug("vrf %s vni %u %s", zvrf_name(zvrf
), vni
,
6385 add
? "ADD" : "DEL");
6389 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
6391 /* check if the vni is already present under zvrf */
6393 snprintf(err
, err_str_sz
,
6394 "VNI is already configured under the vrf");
6398 /* check if this VNI is already present in the system */
6399 zl3vni
= zl3vni_lookup(vni
);
6401 snprintf(err
, err_str_sz
,
6402 "VNI is already configured as L3-VNI");
6406 /* add the L3-VNI to the global table */
6407 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
6409 snprintf(err
, err_str_sz
, "Could not add L3-VNI");
6413 /* associate the vrf with vni */
6416 /* set the filter in l3vni to denote if we are using l3vni only
6420 SET_FLAG(zl3vni
->filter
, PREFIX_ROUTES_ONLY
);
6422 /* associate with vxlan-intf;
6423 * we need to associate with the vxlan-intf first
6425 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
6427 /* associate with corresponding SVI interface, we can associate
6428 * with svi-if only after vxlan interface association is
6431 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6433 /* formulate l2vni list */
6434 hash_iterate(zvrf_default
->vni_table
, zvni_add_to_l3vni_list
,
6437 if (is_l3vni_oper_up(zl3vni
))
6438 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6441 zl3vni
= zl3vni_lookup(vni
);
6443 snprintf(err
, err_str_sz
, "VNI doesn't exist");
6447 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6449 /* delete and uninstall all rmacs */
6450 hash_iterate(zl3vni
->rmac_table
, zl3vni_del_rmac_hash_entry
,
6453 /* delete and uninstall all next-hops */
6454 hash_iterate(zl3vni
->nh_table
, zl3vni_del_nh_hash_entry
,
6460 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
6465 int zebra_vxlan_vrf_enable(struct zebra_vrf
*zvrf
)
6467 zebra_l3vni_t
*zl3vni
= NULL
;
6470 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6474 zl3vni
->vrf_id
= zvrf_id(zvrf
);
6475 if (is_l3vni_oper_up(zl3vni
))
6476 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6480 int zebra_vxlan_vrf_disable(struct zebra_vrf
*zvrf
)
6482 zebra_l3vni_t
*zl3vni
= NULL
;
6485 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6489 zl3vni
->vrf_id
= VRF_UNKNOWN
;
6490 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6494 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
6496 zebra_l3vni_t
*zl3vni
= NULL
;
6500 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
6506 zebra_vxlan_handle_vni_transition(zvrf
, vni
, 0);
6512 * Handle message from client to enable/disable advertisement of g/w macip
6515 int zebra_vxlan_advertise_subnet(struct zserv
*client
, u_short length
,
6516 struct zebra_vrf
*zvrf
)
6521 zebra_vni_t
*zvni
= NULL
;
6522 struct interface
*ifp
= NULL
;
6523 struct zebra_if
*zif
= NULL
;
6524 struct zebra_l2info_vxlan zl2_info
;
6525 struct interface
*vlan_if
= NULL
;
6527 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6528 zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
6534 advertise
= stream_getc(s
);
6535 vni
= stream_get3(s
);
6537 zvni
= zvni_lookup(vni
);
6541 if (zvni
->advertise_subnet
== advertise
)
6544 if (IS_ZEBRA_DEBUG_VXLAN
)
6545 zlog_debug("EVPN subnet Adv %s on VNI %d , currently %s",
6546 advertise
? "enabled" : "disabled", vni
,
6547 zvni
->advertise_subnet
? "enabled" : "disabled");
6550 zvni
->advertise_subnet
= advertise
;
6552 ifp
= zvni
->vxlan_if
;
6558 /* If down or not mapped to a bridge, we're done. */
6559 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6562 zl2_info
= zif
->l2info
.vxl
;
6565 zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
6569 if (zvni
->advertise_subnet
)
6570 zvni_advertise_subnet(zvni
, vlan_if
, 1);
6572 zvni_advertise_subnet(zvni
, vlan_if
, 0);
6578 * Handle message from client to enable/disable advertisement of g/w macip
6581 int zebra_vxlan_advertise_gw_macip(struct zserv
*client
, u_short length
,
6582 struct zebra_vrf
*zvrf
)
6587 zebra_vni_t
*zvni
= NULL
;
6588 struct interface
*ifp
= NULL
;
6590 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6591 zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
6597 STREAM_GETC(s
, advertise
);
6598 STREAM_GET(&vni
, s
, 3);
6601 if (IS_ZEBRA_DEBUG_VXLAN
)
6602 zlog_debug("EVPN gateway macip Adv %s, currently %s",
6603 advertise
? "enabled" : "disabled",
6604 advertise_gw_macip_enabled(NULL
)
6608 if (zvrf
->advertise_gw_macip
== advertise
)
6611 zvrf
->advertise_gw_macip
= advertise
;
6613 if (advertise_gw_macip_enabled(zvni
))
6614 hash_iterate(zvrf
->vni_table
,
6615 zvni_gw_macip_add_for_vni_hash
, NULL
);
6617 hash_iterate(zvrf
->vni_table
,
6618 zvni_gw_macip_del_for_vni_hash
, NULL
);
6621 struct zebra_if
*zif
= NULL
;
6622 struct zebra_l2info_vxlan zl2_info
;
6623 struct interface
*vlan_if
= NULL
;
6624 struct interface
*vrr_if
= NULL
;
6626 zvni
= zvni_lookup(vni
);
6630 if (IS_ZEBRA_DEBUG_VXLAN
)
6632 "EVPN gateway macip Adv %s on VNI %d , currently %s",
6633 advertise
? "enabled" : "disabled", vni
,
6634 advertise_gw_macip_enabled(zvni
) ? "enabled"
6637 if (zvni
->advertise_gw_macip
== advertise
)
6640 zvni
->advertise_gw_macip
= advertise
;
6642 ifp
= zvni
->vxlan_if
;
6648 /* If down or not mapped to a bridge, we're done. */
6649 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6652 zl2_info
= zif
->l2info
.vxl
;
6654 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
6655 zif
->brslave_info
.br_if
);
6659 if (advertise_gw_macip_enabled(zvni
)) {
6660 /* Add primary SVI MAC-IP */
6661 zvni_add_macip_for_intf(vlan_if
, zvni
);
6663 /* Add VRR MAC-IP - if any*/
6664 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
6666 zvni_add_macip_for_intf(vrr_if
, zvni
);
6668 /* Del primary MAC-IP */
6669 zvni_del_macip_for_intf(vlan_if
, zvni
);
6671 /* Del VRR MAC-IP - if any*/
6672 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
6674 zvni_del_macip_for_intf(vrr_if
, zvni
);
6684 * Handle message from client to learn (or stop learning) about VNIs and MACs.
6685 * When enabled, the VNI hash table will be built and MAC FDB table read;
6686 * when disabled, the entries should be deleted and remote VTEPs and MACs
6687 * uninstalled from the kernel.
6689 int zebra_vxlan_advertise_all_vni(struct zserv
*client
, u_short length
,
6690 struct zebra_vrf
*zvrf
)
6692 struct stream
*s
= NULL
;
6694 struct zebra_ns
*zns
= NULL
;
6696 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6697 zlog_err("EVPN VNI Adv for non-default VRF %u", zvrf_id(zvrf
));
6702 STREAM_GETC(s
, advertise
);
6704 if (IS_ZEBRA_DEBUG_VXLAN
)
6705 zlog_debug("EVPN VNI Adv %s, currently %s",
6706 advertise
? "enabled" : "disabled",
6707 is_evpn_enabled() ? "enabled" : "disabled");
6709 if (zvrf
->advertise_all_vni
== advertise
)
6712 zvrf
->advertise_all_vni
= advertise
;
6713 if (is_evpn_enabled()) {
6714 /* Build VNI hash table and inform BGP. */
6715 zvni_build_hash_table();
6717 /* Add all SVI (L3 GW) MACs to BGP*/
6718 hash_iterate(zvrf
->vni_table
, zvni_gw_macip_add_for_vni_hash
,
6721 /* Read the MAC FDB */
6722 macfdb_read(zvrf
->zns
);
6724 /* Read neighbors */
6725 neigh_read(zvrf
->zns
);
6727 /* Cleanup VTEPs for all VNIs - uninstall from
6728 * kernel and free entries.
6730 hash_iterate(zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
6732 /* cleanup all l3vnis */
6733 zns
= zebra_ns_lookup(NS_DEFAULT
);
6737 hash_iterate(zns
->l3vni_table
, zl3vni_cleanup_all
, NULL
);
6745 * Allocate VNI hash table for this VRF and do other initialization.
6746 * NOTE: Currently supported only for default VRF.
6748 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
6752 zvrf
->vni_table
= hash_create(vni_hash_keymake
, vni_hash_cmp
,
6753 "Zebra VRF VNI Table");
6756 /* Cleanup VNI info, but don't free the table. */
6757 void zebra_vxlan_cleanup_tables(struct zebra_vrf
*zvrf
)
6761 hash_iterate(zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
6764 /* Close all VNI handling */
6765 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
6769 hash_iterate(zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
6770 hash_free(zvrf
->vni_table
);
6773 /* init the l3vni table */
6774 void zebra_vxlan_ns_init(struct zebra_ns
*zns
)
6776 zns
->l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
6777 "Zebra VRF L3 VNI table");
6780 /* free l3vni table */
6781 void zebra_vxlan_ns_disable(struct zebra_ns
*zns
)
6783 hash_free(zns
->l3vni_table
);
6786 /* get the l3vni svi ifindex */
6787 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
6789 zebra_l3vni_t
*zl3vni
= NULL
;
6791 zl3vni
= zl3vni_from_vrf(vrf_id
);
6792 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
6795 return zl3vni
->svi_if
->ifindex
;