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
,
64 static void zvni_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
);
65 static void zvni_print_neigh_hash(struct hash_backet
*backet
, void *ctxt
);
66 static void zvni_print_neigh_hash_all_vni(struct hash_backet
*backet
,
68 static void zl3vni_print_nh(zebra_neigh_t
*n
, struct vty
*vty
,
70 static void zl3vni_print_rmac(zebra_mac_t
*zrmac
, struct vty
*vty
,
72 static void zvni_print_mac(zebra_mac_t
*mac
, void *ctxt
);
73 static void zvni_print_mac_hash(struct hash_backet
*backet
, void *ctxt
);
74 static void zvni_print_mac_hash_all_vni(struct hash_backet
*backet
, void *ctxt
);
75 static void zvni_print(zebra_vni_t
*zvni
, void **ctxt
);
76 static void zvni_print_hash(struct hash_backet
*backet
, void *ctxt
[]);
78 static int zvni_macip_send_msg_to_client(vni_t vni
,
79 struct ethaddr
*macaddr
,
80 struct ipaddr
*ip
, u_char flags
,
82 static unsigned int neigh_hash_keymake(void *p
);
83 static int neigh_cmp(const void *p1
, const void *p2
);
84 static void *zvni_neigh_alloc(void *p
);
85 static zebra_neigh_t
*zvni_neigh_add(zebra_vni_t
*zvni
, struct ipaddr
*ip
,
87 static int zvni_neigh_del(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
88 static int zvni_neigh_del_hash_entry(struct hash_backet
*backet
, void *arg
);
89 static void zvni_neigh_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
90 struct in_addr
*r_vtep_ip
);
91 static void zvni_neigh_del_all(zebra_vni_t
*zvni
,
92 int uninstall
, int upd_client
, u_int32_t flags
);
93 static zebra_neigh_t
*zvni_neigh_lookup(zebra_vni_t
*zvni
, struct ipaddr
*ip
);
94 static int zvni_neigh_send_add_to_client(vni_t vni
,
96 struct ethaddr
*macaddr
, u_char flags
);
97 static int zvni_neigh_send_del_to_client(vni_t vni
,
99 struct ethaddr
*macaddr
, u_char flags
);
100 static int zvni_neigh_install(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
101 static int zvni_neigh_uninstall(zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
102 static zebra_vni_t
*zvni_from_svi(struct interface
*ifp
,
103 struct interface
*br_if
);
104 static struct interface
*zvni_map_to_svi(vlanid_t vid
,
105 struct interface
*br_if
);
107 /* l3-vni next-hop neigh related APIs */
108 static zebra_neigh_t
*zl3vni_nh_lookup(zebra_l3vni_t
*zl3vni
,
110 static void *zl3vni_nh_alloc(void *p
);
111 static zebra_neigh_t
*zl3vni_nh_add(zebra_l3vni_t
*zl3vni
,
112 struct ipaddr
*vtep_ip
,
113 struct ethaddr
*rmac
);
114 static int zl3vni_nh_del(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
115 static int zl3vni_nh_install(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
116 static int zl3vni_nh_uninstall(zebra_l3vni_t
*zl3vni
, zebra_neigh_t
*n
);
118 /* l3-vni rmac related APIs */
119 static void zl3vni_print_rmac_hash(struct hash_backet
*, void *);
120 static zebra_mac_t
*zl3vni_rmac_lookup(zebra_l3vni_t
*zl3vni
,
121 struct ethaddr
*rmac
);
122 static void *zl3vni_rmac_alloc(void *p
);
123 static zebra_mac_t
*zl3vni_rmac_add(zebra_l3vni_t
*zl3vni
,
124 struct ethaddr
*rmac
);
125 static int zl3vni_rmac_del(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
);
126 static int zl3vni_rmac_install(zebra_l3vni_t
*zl3vni
, zebra_mac_t
*zrmac
);
127 static int zl3vni_rmac_uninstall(zebra_l3vni_t
*zl3vni
,
130 /* l3-vni related APIs*/
131 static int is_vni_l3(vni_t
);
132 static zebra_l3vni_t
*zl3vni_lookup(vni_t vni
);
133 static void *zl3vni_alloc(void *p
);
134 static zebra_l3vni_t
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
);
135 static int zl3vni_del(zebra_l3vni_t
*zl3vni
);
136 static zebra_l3vni_t
*zl3vni_from_vrf(vrf_id_t
);
137 static struct interface
*zl3vni_map_to_svi_if(zebra_l3vni_t
*zl3vni
);
138 static struct interface
*zl3vni_map_to_vxlan_if(zebra_l3vni_t
*zl3vni
);
139 static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t
*zl3vni
);
140 static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t
*zl3vni
);
142 static unsigned int mac_hash_keymake(void *p
);
143 static int mac_cmp(const void *p1
, const void *p2
);
144 static void *zvni_mac_alloc(void *p
);
145 static zebra_mac_t
*zvni_mac_add(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
146 static int zvni_mac_del(zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
147 static int zvni_mac_del_hash_entry(struct hash_backet
*backet
, void *arg
);
148 static void zvni_mac_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
149 struct in_addr
*r_vtep_ip
);
150 static void zvni_mac_del_all(zebra_vni_t
*zvni
,
151 int uninstall
, int upd_client
, u_int32_t flags
);
152 static zebra_mac_t
*zvni_mac_lookup(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
153 static int zvni_mac_send_add_to_client(vni_t vni
,
154 struct ethaddr
*macaddr
, u_char flags
);
155 static int zvni_mac_send_del_to_client(vni_t vni
,
156 struct ethaddr
*macaddr
, u_char flags
);
157 static zebra_vni_t
*zvni_map_vlan(struct interface
*ifp
,
158 struct interface
*br_if
, vlanid_t vid
);
159 static int zvni_mac_install(zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
160 static int zvni_mac_uninstall(zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
);
161 static void zvni_install_mac_hash(struct hash_backet
*backet
, void *ctxt
);
163 static unsigned int vni_hash_keymake(void *p
);
164 static int vni_hash_cmp(const void *p1
, const void *p2
);
165 static void *zvni_alloc(void *p
);
166 static zebra_vni_t
*zvni_lookup(vni_t vni
);
167 static zebra_vni_t
*zvni_add(vni_t vni
);
168 static int zvni_del(zebra_vni_t
*zvni
);
169 static int zvni_send_add_to_client(zebra_vni_t
*zvni
);
170 static int zvni_send_del_to_client(vni_t vni
);
171 static void zvni_build_hash_table();
172 static int zvni_vtep_match(struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
);
173 static zebra_vtep_t
*zvni_vtep_find(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
174 static zebra_vtep_t
*zvni_vtep_add(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
175 static int zvni_vtep_del(zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
);
176 static int zvni_vtep_del_all(zebra_vni_t
*zvni
, int uninstall
);
177 static int zvni_vtep_install(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
178 static int zvni_vtep_uninstall(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
179 static int zvni_del_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
);
180 static int zvni_add_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
);
181 static int zvni_gw_macip_add(struct interface
*ifp
, zebra_vni_t
*zvni
,
182 struct ethaddr
*macaddr
, struct ipaddr
*ip
);
183 static int zvni_gw_macip_del(struct interface
*ifp
, zebra_vni_t
*zvni
,
185 struct interface
*zebra_get_vrr_intf_for_svi(struct interface
*ifp
);
186 static int advertise_gw_macip_enabled(zebra_vni_t
*zvni
);
187 static void zvni_deref_ip2mac(zebra_vni_t
*zvni
, zebra_mac_t
*mac
,
190 /* Private functions */
193 * Return number of valid MACs in a VNI's MAC hash table - all
194 * remote MACs and non-internal (auto) local MACs count.
196 static u_int32_t
num_valid_macs(zebra_vni_t
*zvni
)
199 u_int32_t num_macs
= 0;
201 struct hash_backet
*hb
;
204 hash
= zvni
->mac_table
;
207 for (i
= 0; i
< hash
->size
; i
++) {
208 for (hb
= hash
->index
[i
]; hb
; hb
= hb
->next
) {
209 mac
= (zebra_mac_t
*)hb
->data
;
210 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
211 || !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
))
219 static int advertise_gw_macip_enabled(zebra_vni_t
*zvni
)
221 struct zebra_vrf
*zvrf
;
223 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
224 if (zvrf
&& zvrf
->advertise_gw_macip
)
227 if (zvni
&& zvni
->advertise_gw_macip
)
234 * Helper function to determine maximum width of neighbor IP address for
235 * display - just because we're dealing with IPv6 addresses that can
238 static void zvni_find_neigh_addr_width(struct hash_backet
*backet
, void *ctxt
)
241 char buf
[INET6_ADDRSTRLEN
];
242 struct neigh_walk_ctx
*wctx
= ctxt
;
245 n
= (zebra_neigh_t
*)backet
->data
;
249 ipaddr2str(&n
->ip
, buf
, sizeof(buf
)), width
= strlen(buf
);
250 if (width
> wctx
->addr_width
)
251 wctx
->addr_width
= width
;
255 * Print a specific neighbor entry.
257 static void zvni_print_neigh(zebra_neigh_t
*n
, void *ctxt
, json_object
*json
)
260 char buf1
[ETHER_ADDR_STRLEN
];
261 char buf2
[INET6_ADDRSTRLEN
];
263 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
264 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
265 vty
= (struct vty
*)ctxt
;
267 vty_out(vty
, "IP: %s\n",
268 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
269 vty_out(vty
, " MAC: %s",
270 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
272 json_object_string_add(json
, "ip", buf2
);
273 json_object_string_add(json
, "mac", buf1
);
275 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
277 vty_out(vty
, " Remote VTEP: %s",
278 inet_ntoa(n
->r_vtep_ip
));
280 json_object_string_add(json
, "remoteVtep",
281 inet_ntoa(n
->r_vtep_ip
));
283 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
286 vty_out(vty
, " State: %s",
287 IS_ZEBRA_NEIGH_ACTIVE(n
) ? "Active"
291 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
)) {
293 vty_out(vty
, " Default-gateway");
295 json_object_boolean_true_add(json
, "defaultGateway");
302 * Print neighbor hash entry - called for display of all neighbors.
304 static void zvni_print_neigh_hash(struct hash_backet
*backet
, void *ctxt
)
307 json_object
*json_vni
= NULL
, *json_row
= NULL
;
309 char buf1
[ETHER_ADDR_STRLEN
];
310 char buf2
[INET6_ADDRSTRLEN
];
311 struct neigh_walk_ctx
*wctx
= ctxt
;
314 json_vni
= wctx
->json
;
315 n
= (zebra_neigh_t
*)backet
->data
;
320 json_row
= json_object_new_object();
322 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
));
323 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
));
324 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)
325 && !(wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)) {
326 if (json_vni
== NULL
) {
327 vty_out(vty
, "%*s %-6s %-17s\n", -wctx
->addr_width
,
328 buf2
, "local", buf1
);
330 json_object_string_add(json_row
, "type", "local");
331 json_object_string_add(json_row
, "mac", buf1
);
335 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
) {
336 if (IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
)) {
337 if (json_vni
== NULL
) {
338 if (wctx
->count
== 0)
340 "%*s %-6s %-17s %-21s\n",
343 "MAC", "Remote VTEP");
344 vty_out(vty
, "%*s %-6s %-17s %-21s\n",
345 -wctx
->addr_width
, buf2
,
347 inet_ntoa(n
->r_vtep_ip
));
349 json_object_string_add(json_row
, "type",
351 json_object_string_add(json_row
, "mac",
353 json_object_string_add(
354 json_row
, "remoteVtep",
355 inet_ntoa(n
->r_vtep_ip
));
360 if (json_vni
== NULL
) {
361 vty_out(vty
, "%*s %-6s %-17s %-21s\n",
362 -wctx
->addr_width
, buf2
, "remote", buf1
,
363 inet_ntoa(n
->r_vtep_ip
));
365 json_object_string_add(json_row
, "type",
367 json_object_string_add(json_row
, "mac", buf1
);
368 json_object_string_add(json_row
, "remoteVtep",
369 inet_ntoa(n
->r_vtep_ip
));
376 json_object_object_add(json_vni
, buf2
, json_row
);
380 * Print neighbors for all VNI.
382 static void zvni_print_neigh_hash_all_vni(struct hash_backet
*backet
,
386 json_object
*json
= NULL
, *json_vni
= NULL
;
389 struct neigh_walk_ctx wctx
;
390 char vni_str
[VNI_STR_LEN
];
392 vty
= (struct vty
*)args
[0];
393 json
= (json_object
*)args
[1];
395 zvni
= (zebra_vni_t
*)backet
->data
;
398 vty_out(vty
, "{}\n");
401 num_neigh
= hashcount(zvni
->neigh_table
);
404 "\nVNI %u #ARP (IPv4 and IPv6, local and remote) %u\n\n",
405 zvni
->vni
, num_neigh
);
407 json_vni
= json_object_new_object();
408 json_object_int_add(json_vni
, "numArpNd", num_neigh
);
409 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
413 json_object_object_add(json
, vni_str
, json_vni
);
417 /* Since we have IPv6 addresses to deal with which can vary widely in
418 * size, we try to be a bit more elegant in display by first computing
421 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
424 wctx
.addr_width
= 15;
425 wctx
.json
= json_vni
;
426 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
429 vty_out(vty
, "%*s %-6s %-17s %-21s\n", -wctx
.addr_width
, "IP",
430 "Type", "MAC", "Remote VTEP");
431 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
434 json_object_object_add(json
, vni_str
, json_vni
);
437 /* print a specific next hop for an l3vni */
438 static void zl3vni_print_nh(zebra_neigh_t
*n
,
442 char buf1
[ETHER_ADDR_STRLEN
];
443 char buf2
[INET6_ADDRSTRLEN
];
444 struct listnode
*node
= NULL
;
445 struct prefix
*p
= NULL
;
446 json_object
*json_hosts
= NULL
;
449 vty_out(vty
, "Ip: %s\n",
450 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
451 vty_out(vty
, " RMAC: %s\n",
452 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
453 vty_out(vty
, " Refcount: %d\n", listcount(n
->host_list
));
454 vty_out(vty
, " Prefixes:\n");
455 for (ALL_LIST_ELEMENTS_RO(n
->host_list
, node
, p
))
456 vty_out(vty
, " %s\n",
457 prefix2str(p
, buf2
, sizeof(buf2
)));
459 json_hosts
= json_object_new_array();
460 json_object_string_add(json
, "ip",
461 ipaddr2str(&(n
->ip
), buf2
,
463 json_object_string_add(json
, "routerMac",
464 prefix_mac2str(&n
->emac
, buf2
,
466 json_object_int_add(json
, "refCount", listcount(n
->host_list
));
467 for (ALL_LIST_ELEMENTS_RO(n
->host_list
, node
, p
))
468 json_object_array_add(json_hosts
,
469 json_object_new_string(
472 json_object_object_add(json
, "prefixList", json_hosts
);
476 /* Print a specific RMAC entry */
477 static void zl3vni_print_rmac(zebra_mac_t
*zrmac
,
481 char buf1
[ETHER_ADDR_STRLEN
];
482 char buf2
[PREFIX_STRLEN
];
483 struct listnode
*node
= NULL
;
484 struct prefix
*p
= NULL
;
485 json_object
*json_hosts
= NULL
;
488 vty_out(vty
, "MAC: %s\n",
489 prefix_mac2str(&zrmac
->macaddr
, buf1
, sizeof(buf1
)));
490 vty_out(vty
, " Remote VTEP: %s\n",
491 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
492 vty_out(vty
, " Refcount: %d\n", listcount(zrmac
->host_list
));
493 vty_out(vty
, " Prefixes:\n");
494 for (ALL_LIST_ELEMENTS_RO(zrmac
->host_list
, node
, p
))
495 vty_out(vty
, " %s\n",
496 prefix2str(p
, buf2
, sizeof(buf2
)));
498 json_hosts
= json_object_new_array();
499 json_object_string_add(json
, "routerMac",
500 prefix_mac2str(&zrmac
->macaddr
,
503 json_object_string_add(json
, "vtepIp",
504 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
505 json_object_int_add(json
, "refCount",
506 listcount(zrmac
->host_list
));
507 for (ALL_LIST_ELEMENTS_RO(zrmac
->host_list
, node
, p
))
508 json_object_array_add(json_hosts
,
509 json_object_new_string(
512 json_object_object_add(json
, "prefixList", json_hosts
);
517 * Print a specific MAC entry.
519 static void zvni_print_mac(zebra_mac_t
*mac
, void *ctxt
)
522 zebra_neigh_t
*n
= NULL
;
523 struct listnode
*node
= NULL
;
525 char buf2
[INET6_ADDRSTRLEN
];
527 vty
= (struct vty
*)ctxt
;
528 vty_out(vty
, "MAC: %s",
529 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
)));
530 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
531 struct zebra_ns
*zns
;
532 struct interface
*ifp
;
535 ifindex
= mac
->fwd_info
.local
.ifindex
;
536 zns
= zebra_ns_lookup(NS_DEFAULT
);
537 ifp
= if_lookup_by_index_per_ns(zns
, ifindex
);
538 if (!ifp
) // unexpected
540 vty_out(vty
, " Intf: %s(%u)", ifp
->name
, ifindex
);
541 if (mac
->fwd_info
.local
.vid
)
542 vty_out(vty
, " VLAN: %u", mac
->fwd_info
.local
.vid
);
543 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
544 vty_out(vty
, " Remote VTEP: %s",
545 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
546 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)) {
547 vty_out(vty
, " Auto Mac ");
550 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
))
551 vty_out(vty
, " Sticky Mac ");
553 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
))
554 vty_out(vty
, " Default-gateway Mac ");
557 /* print all the associated neigh */
558 vty_out(vty
, " Neighbors:\n");
559 if (!listcount(mac
->neigh_list
))
560 vty_out(vty
, " No Neighbors\n");
562 for (ALL_LIST_ELEMENTS_RO(mac
->neigh_list
, node
, n
)) {
563 vty_out(vty
, " %s %s\n",
564 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)),
565 CHECK_FLAG(n
->flags
, ZEBRA_MAC_LOCAL
)
566 ? (IS_ZEBRA_NEIGH_ACTIVE(n
)
577 * Print MAC hash entry - called for display of all MACs.
579 static void zvni_print_mac_hash(struct hash_backet
*backet
, void *ctxt
)
582 json_object
*json_mac_hdr
= NULL
, *json_mac
= NULL
;
585 struct mac_walk_ctx
*wctx
= ctxt
;
588 json_mac_hdr
= wctx
->json
;
589 mac
= (zebra_mac_t
*)backet
->data
;
593 prefix_mac2str(&mac
->macaddr
, buf1
, sizeof(buf1
));
596 json_mac
= json_object_new_object();
598 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)
599 && !(wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)) {
600 struct zebra_ns
*zns
;
602 struct interface
*ifp
;
605 zns
= zebra_ns_lookup(NS_DEFAULT
);
606 ifindex
= mac
->fwd_info
.local
.ifindex
;
607 ifp
= if_lookup_by_index_per_ns(zns
, ifindex
);
608 if (!ifp
) // unexpected
610 vid
= mac
->fwd_info
.local
.vid
;
611 if (json_mac_hdr
== NULL
)
612 vty_out(vty
, "%-17s %-6s %-21s", buf1
, "local",
615 json_object_string_add(json_mac
, "type", "local");
616 json_object_string_add(json_mac
, "intf", ifp
->name
);
619 if (json_mac_hdr
== NULL
)
620 vty_out(vty
, " %-5u", vid
);
622 json_object_int_add(json_mac
, "vlan", vid
);
624 if (json_mac_hdr
== NULL
)
627 json_object_object_add(json_mac_hdr
, buf1
, json_mac
);
629 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
630 if (wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
) {
631 if (IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
633 if (wctx
->count
== 0) {
634 if (json_mac_hdr
== NULL
) {
635 vty_out(vty
, "\nVNI %u\n\n",
638 "%-17s %-6s %-21s %-5s\n",
644 if (json_mac_hdr
== NULL
)
645 vty_out(vty
, "%-17s %-6s %-21s\n", buf1
,
647 inet_ntoa(mac
->fwd_info
650 json_object_string_add(json_mac
, "type",
652 json_object_string_add(
653 json_mac
, "remoteVtep",
654 inet_ntoa(mac
->fwd_info
656 json_object_object_add(json_mac_hdr
,
662 if (json_mac_hdr
== NULL
)
663 vty_out(vty
, "%-17s %-6s %-21s\n", buf1
,
665 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
667 json_object_string_add(json_mac
, "type",
669 json_object_string_add(
670 json_mac
, "remoteVtep",
671 inet_ntoa(mac
->fwd_info
.r_vtep_ip
));
672 json_object_object_add(json_mac_hdr
, buf1
,
681 * Print MACs for all VNI.
683 static void zvni_print_mac_hash_all_vni(struct hash_backet
*backet
, void *ctxt
)
686 json_object
*json
= NULL
, *json_vni
= NULL
;
687 json_object
*json_mac
= NULL
;
690 struct mac_walk_ctx
*wctx
= ctxt
;
691 char vni_str
[VNI_STR_LEN
];
693 vty
= (struct vty
*)wctx
->vty
;
694 json
= (struct json_object
*)wctx
->json
;
696 zvni
= (zebra_vni_t
*)backet
->data
;
699 vty_out(vty
, "{}\n");
704 /*We are iterating over a new VNI, set the count to 0*/
707 num_macs
= num_valid_macs(zvni
);
712 json_vni
= json_object_new_object();
713 json_mac
= json_object_new_object();
714 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
717 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
)) {
719 vty_out(vty
, "\nVNI %u #MACs (local and remote) %u\n\n",
720 zvni
->vni
, num_macs
);
721 vty_out(vty
, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
722 "Intf/Remote VTEP", "VLAN");
724 json_object_int_add(json_vni
, "numMacs", num_macs
);
726 /* assign per-vni to wctx->json object to fill macs
727 * under the vni. Re-assign primary json object to fill
728 * next vni information.
730 wctx
->json
= json_mac
;
731 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, wctx
);
735 json_object_object_add(json_vni
, "macs", json_mac
);
736 json_object_object_add(json
, vni_str
, json_vni
);
740 static void zl3vni_print_nh_hash(struct hash_backet
*backet
,
743 struct nh_walk_ctx
*wctx
= NULL
;
744 struct vty
*vty
= NULL
;
745 struct json_object
*json_vni
= NULL
;
746 struct json_object
*json_nh
= NULL
;
747 zebra_neigh_t
*n
= NULL
;
748 char buf1
[ETHER_ADDR_STRLEN
];
749 char buf2
[INET6_ADDRSTRLEN
];
751 wctx
= (struct nh_walk_ctx
*)ctx
;
753 json_vni
= wctx
->json
;
755 json_nh
= json_object_new_object();
756 n
= (zebra_neigh_t
*)backet
->data
;
761 vty_out(vty
, "%-15s %-17s\n",
762 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
763 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)));
765 json_object_string_add(json_nh
, "nexthopIp",
766 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
767 json_object_string_add(json_nh
, "routerMac",
768 prefix_mac2str(&n
->emac
, buf1
,
770 json_object_object_add(json_vni
,
771 ipaddr2str(&(n
->ip
), buf2
, sizeof(buf2
)),
776 static void zl3vni_print_nh_hash_all_vni(struct hash_backet
*backet
,
779 struct vty
*vty
= NULL
;
780 json_object
*json
= NULL
;
781 json_object
*json_vni
= NULL
;
782 zebra_l3vni_t
*zl3vni
= NULL
;
784 struct nh_walk_ctx wctx
;
785 char vni_str
[VNI_STR_LEN
];
787 vty
= (struct vty
*)args
[0];
788 json
= (struct json_object
*)args
[1];
790 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
793 vty_out(vty
, "{}\n");
797 num_nh
= hashcount(zl3vni
->nh_table
);
802 json_vni
= json_object_new_object();
803 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
807 vty_out(vty
, "\nVNI %u #Next-Hops %u\n\n",
808 zl3vni
->vni
, num_nh
);
809 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
811 json_object_int_add(json_vni
, "numNextHops", num_nh
);
813 memset(&wctx
, 0, sizeof(struct nh_walk_ctx
));
815 wctx
.json
= json_vni
;
816 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
818 json_object_object_add(json
, vni_str
, json_vni
);
821 static void zl3vni_print_rmac_hash_all_vni(struct hash_backet
*backet
,
824 struct vty
*vty
= NULL
;
825 json_object
*json
= NULL
;
826 json_object
*json_vni
= NULL
;
827 zebra_l3vni_t
*zl3vni
= NULL
;
829 struct rmac_walk_ctx wctx
;
830 char vni_str
[VNI_STR_LEN
];
832 vty
= (struct vty
*)args
[0];
833 json
= (struct json_object
*)args
[1];
835 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
838 vty_out(vty
, "{}\n");
842 num_rmacs
= hashcount(zl3vni
->rmac_table
);
847 json_vni
= json_object_new_object();
848 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
852 vty_out(vty
, "\nVNI %u #RMACs %u\n\n",
853 zl3vni
->vni
, num_rmacs
);
854 vty_out(vty
, "%-17s %-21s\n", "RMAC", "Remote VTEP");
856 json_object_int_add(json_vni
, "numRmacs", num_rmacs
);
858 /* assign per-vni to wctx->json object to fill macs
859 * under the vni. Re-assign primary json object to fill
860 * next vni information.
862 memset(&wctx
, 0, sizeof(struct rmac_walk_ctx
));
864 wctx
.json
= json_vni
;
865 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
867 json_object_object_add(json
, vni_str
, json_vni
);
870 static void zl3vni_print_rmac_hash(struct hash_backet
*backet
,
873 zebra_mac_t
*zrmac
= NULL
;
874 struct rmac_walk_ctx
*wctx
= NULL
;
875 struct vty
*vty
= NULL
;
876 struct json_object
*json
= NULL
;
877 struct json_object
*json_rmac
= NULL
;
878 char buf
[ETHER_ADDR_STRLEN
];
880 wctx
= (struct rmac_walk_ctx
*)ctx
;
884 json_rmac
= json_object_new_object();
885 zrmac
= (zebra_mac_t
*)backet
->data
;
890 vty_out(vty
, "%-17s %-21s\n",
891 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
892 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
894 json_object_string_add(json_rmac
, "routerMac",
895 prefix_mac2str(&zrmac
->macaddr
, buf
,
897 json_object_string_add(json_rmac
, "vtepIp",
898 inet_ntoa(zrmac
->fwd_info
.r_vtep_ip
));
899 json_object_object_add(json
,
900 prefix_mac2str(&zrmac
->macaddr
, buf
,
906 /* print a specific L3 VNI entry */
907 static void zl3vni_print(zebra_l3vni_t
*zl3vni
, void **ctx
)
909 char buf
[ETHER_ADDR_STRLEN
];
910 struct vty
*vty
= NULL
;
911 json_object
*json
= NULL
;
912 zebra_vni_t
*zvni
= NULL
;
913 json_object
*json_vni_list
= NULL
;
914 struct listnode
*node
= NULL
, *nnode
= NULL
;
920 vty_out(vty
, "VNI: %u\n", zl3vni
->vni
);
921 vty_out(vty
, " Type: %s\n", "L3");
922 vty_out(vty
, " Tenant VRF: %s\n",
923 zl3vni_vrf_name(zl3vni
));
924 vty_out(vty
, " Local Vtep Ip: %s\n",
925 inet_ntoa(zl3vni
->local_vtep_ip
));
926 vty_out(vty
, " Vxlan-Intf: %s\n",
927 zl3vni_vxlan_if_name(zl3vni
));
928 vty_out(vty
, " SVI-If: %s\n",
929 zl3vni_svi_if_name(zl3vni
));
930 vty_out(vty
, " State: %s\n",
931 zl3vni_state2str(zl3vni
));
932 vty_out(vty
, " Router MAC: %s\n",
933 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
934 vty_out(vty
, " L2 VNIs: ");
935 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zvni
))
936 vty_out(vty
, "%u ", zvni
->vni
);
939 json_vni_list
= json_object_new_array();
940 json_object_int_add(json
, "vni", zl3vni
->vni
);
941 json_object_string_add(json
, "type", "L3");
942 json_object_string_add(json
, "localVtepIp",
943 inet_ntoa(zl3vni
->local_vtep_ip
));
944 json_object_string_add(json
, "vxlanIntf",
945 zl3vni_vxlan_if_name(zl3vni
));
946 json_object_string_add(json
, "sviIntf",
947 zl3vni_svi_if_name(zl3vni
));
948 json_object_string_add(json
, "state",
949 zl3vni_state2str(zl3vni
));
950 json_object_string_add(json
, "vrf",
951 zl3vni_vrf_name(zl3vni
));
952 json_object_string_add(json
, "routerMac",
953 zl3vni_rmac2str(zl3vni
, buf
,
955 for (ALL_LIST_ELEMENTS(zl3vni
->l2vnis
, node
, nnode
, zvni
)) {
956 json_object_array_add(json_vni_list
,
957 json_object_new_int(zvni
->vni
));
959 json_object_object_add(json
, "l2Vnis", json_vni_list
);
964 * Print a specific VNI entry.
966 static void zvni_print(zebra_vni_t
*zvni
, void **ctxt
)
972 json_object
*json
= NULL
;
973 json_object
*json_vtep_list
= NULL
;
974 json_object
*json_ip_str
= NULL
;
980 vty_out(vty
, "VNI: %u\n", zvni
->vni
);
981 vty_out(vty
, " Type: %s\n", "L2");
982 vty_out(vty
, " Tenant VRF: %s\n", vrf_id_to_name(zvni
->vrf_id
));
984 json_object_int_add(json
, "vni", zvni
->vni
);
985 json_object_string_add(json
, "type", "L2");
986 json_object_string_add(json
, "vrf",
987 vrf_id_to_name(zvni
->vrf_id
));
990 if (!zvni
->vxlan_if
) { // unexpected
992 vty_out(vty
, " VxLAN interface: unknown\n");
995 num_macs
= num_valid_macs(zvni
);
996 num_neigh
= hashcount(zvni
->neigh_table
);
998 vty_out(vty
, " VxLAN interface: %s\n",
999 zvni
->vxlan_if
->name
);
1000 vty_out(vty
, " VxLAN ifIndex: %u\n", zvni
->vxlan_if
->ifindex
);
1001 vty_out(vty
," Local VTEP IP: %s\n",
1002 inet_ntoa(zvni
->local_vtep_ip
));
1004 json_object_string_add(json
, "vxlanInterface",
1005 zvni
->vxlan_if
->name
);
1006 json_object_int_add(json
, "ifindex", zvni
->vxlan_if
->ifindex
);
1007 json_object_string_add(json
, "vtepIp",
1008 inet_ntoa(zvni
->local_vtep_ip
));
1009 json_object_string_add(json
, "advertiseGatewayMacip",
1010 zvni
->advertise_gw_macip
? "Yes" : "No");
1011 json_object_int_add(json
, "numMacs", num_macs
);
1012 json_object_int_add(json
, "numArpNd", num_neigh
);
1016 vty_out(vty
, " No remote VTEPs known for this VNI\n");
1019 vty_out(vty
, " Remote VTEPs for this VNI:\n");
1021 json_vtep_list
= json_object_new_array();
1022 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1024 vty_out(vty
, " %s\n",
1025 inet_ntoa(zvtep
->vtep_ip
));
1027 json_ip_str
= json_object_new_string(
1028 inet_ntoa(zvtep
->vtep_ip
));
1029 json_object_array_add(json_vtep_list
,
1034 json_object_object_add(json
, "numRemoteVteps",
1039 " Number of MACs (local and remote) known for this VNI: %u\n",
1042 " Number of ARPs (IPv4 and IPv6, local and remote) "
1043 "known for this VNI: %u\n",
1045 vty_out(vty
, " Advertise-gw-macip: %s\n",
1046 zvni
->advertise_gw_macip
? "Yes" : "No");
1050 /* print a L3 VNI hash entry */
1051 static void zl3vni_print_hash(struct hash_backet
*backet
,
1054 struct vty
*vty
= NULL
;
1055 json_object
*json
= NULL
;
1056 json_object
*json_vni
= NULL
;
1057 zebra_l3vni_t
*zl3vni
= NULL
;
1059 vty
= (struct vty
*)ctx
[0];
1060 json
= (json_object
*)ctx
[1];
1062 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
1068 "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
1070 zl3vni_vxlan_if_name(zl3vni
),
1071 hashcount(zl3vni
->rmac_table
),
1072 hashcount(zl3vni
->nh_table
),
1074 zl3vni_vrf_name(zl3vni
));
1076 char vni_str
[VNI_STR_LEN
];
1078 snprintf(vni_str
, VNI_STR_LEN
, "%u", zl3vni
->vni
);
1079 json_vni
= json_object_new_object();
1080 json_object_int_add(json_vni
, "vni", zl3vni
->vni
);
1081 json_object_string_add(json_vni
, "vxlanIf",
1082 zl3vni_vxlan_if_name(zl3vni
));
1083 json_object_int_add(json_vni
, "numMacs",
1084 hashcount(zl3vni
->rmac_table
));
1085 json_object_int_add(json_vni
, "numArpNd",
1086 hashcount(zl3vni
->nh_table
));
1087 json_object_string_add(json_vni
, "numRemoteVteps", "n/a");
1088 json_object_string_add(json_vni
, "type", "L3");
1089 json_object_string_add(json_vni
, "tenantVrf",
1090 zl3vni_vrf_name(zl3vni
));
1091 json_object_object_add(json
, vni_str
, json_vni
);
1097 * Print a VNI hash entry - called for display of all VNIs.
1099 static void zvni_print_hash(struct hash_backet
*backet
, void *ctxt
[])
1103 zebra_vtep_t
*zvtep
;
1104 u_int32_t num_vteps
= 0;
1105 u_int32_t num_macs
= 0;
1106 u_int32_t num_neigh
= 0;
1107 json_object
*json
= NULL
;
1108 json_object
*json_vni
= NULL
;
1109 json_object
*json_ip_str
= NULL
;
1110 json_object
*json_vtep_list
= NULL
;
1115 zvni
= (zebra_vni_t
*)backet
->data
;
1119 zvtep
= zvni
->vteps
;
1122 zvtep
= zvtep
->next
;
1125 num_macs
= num_valid_macs(zvni
);
1126 num_neigh
= hashcount(zvni
->neigh_table
);
1129 "%-10u %-4s %-21s %-8u %-8u %-15u %-37s\n",
1131 zvni
->vxlan_if
? zvni
->vxlan_if
->name
: "unknown",
1132 num_macs
, num_neigh
, num_vteps
,
1133 vrf_id_to_name(zvni
->vrf_id
));
1135 char vni_str
[VNI_STR_LEN
];
1136 snprintf(vni_str
, VNI_STR_LEN
, "%u", zvni
->vni
);
1137 json_vni
= json_object_new_object();
1138 json_object_int_add(json_vni
, "vni", zvni
->vni
);
1139 json_object_string_add(json_vni
, "type", "L2");
1140 json_object_string_add(json_vni
, "vxlanIf",
1141 zvni
->vxlan_if
? zvni
->vxlan_if
->name
1143 json_object_int_add(json_vni
, "numMacs", num_macs
);
1144 json_object_int_add(json_vni
, "numArpNd", num_neigh
);
1145 json_object_int_add(json_vni
, "numRemoteVteps", num_vteps
);
1146 json_object_string_add(json_vni
, "tenantVrf",
1147 vrf_id_to_name(zvni
->vrf_id
));
1149 json_vtep_list
= json_object_new_array();
1150 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
1151 json_ip_str
= json_object_new_string(
1152 inet_ntoa(zvtep
->vtep_ip
));
1153 json_object_array_add(json_vtep_list
,
1156 json_object_object_add(json_vni
, "remoteVteps",
1159 json_object_object_add(json
, vni_str
, json_vni
);
1164 * Inform BGP about local MACIP.
1166 static int zvni_macip_send_msg_to_client(vni_t vni
,
1167 struct ethaddr
*macaddr
,
1168 struct ipaddr
*ip
, u_char flags
,
1171 char buf
[ETHER_ADDR_STRLEN
];
1172 char buf2
[INET6_ADDRSTRLEN
];
1174 struct zserv
*client
= NULL
;
1175 struct stream
*s
= NULL
;
1177 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
1178 /* BGP may not be running. */
1185 zclient_create_header(s
, cmd
, VRF_DEFAULT
);
1186 stream_putl(s
, vni
);
1187 stream_put(s
, macaddr
->octet
, ETH_ALEN
);
1190 if (IS_IPADDR_V4(ip
))
1191 ipa_len
= IPV4_MAX_BYTELEN
;
1192 else if (IS_IPADDR_V6(ip
))
1193 ipa_len
= IPV6_MAX_BYTELEN
;
1195 stream_putl(s
, ipa_len
); /* IP address length */
1197 stream_put(s
, &ip
->ip
.addr
, ipa_len
); /* IP address */
1199 stream_putl(s
, 0); /* Just MAC. */
1201 stream_putc(s
, flags
); /* sticky mac/gateway mac */
1204 /* Write packet size. */
1205 stream_putw_at(s
, 0, stream_get_endp(s
));
1207 if (IS_ZEBRA_DEBUG_VXLAN
)
1209 "Send MACIP %s flags 0x%x MAC %s IP %s L2-VNI %u to %s",
1210 (cmd
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
1211 flags
, prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1212 ipaddr2str(ip
, buf2
, sizeof(buf2
)), vni
,
1213 zebra_route_string(client
->proto
));
1215 if (cmd
== ZEBRA_MACIP_ADD
)
1216 client
->macipadd_cnt
++;
1218 client
->macipdel_cnt
++;
1220 return zebra_server_send_message(client
);
1224 * Make hash key for neighbors.
1226 static unsigned int neigh_hash_keymake(void *p
)
1228 zebra_neigh_t
*n
= p
;
1229 struct ipaddr
*ip
= &n
->ip
;
1231 if (IS_IPADDR_V4(ip
))
1232 return jhash_1word(ip
->ipaddr_v4
.s_addr
, 0);
1234 return jhash2(ip
->ipaddr_v6
.s6_addr32
,
1235 ZEBRA_NUM_OF(ip
->ipaddr_v6
.s6_addr32
), 0);
1239 * Compare two neighbor hash structures.
1241 static int neigh_cmp(const void *p1
, const void *p2
)
1243 const zebra_neigh_t
*n1
= p1
;
1244 const zebra_neigh_t
*n2
= p2
;
1246 if (n1
== NULL
&& n2
== NULL
)
1249 if (n1
== NULL
|| n2
== NULL
)
1252 return (memcmp(&n1
->ip
, &n2
->ip
, sizeof(struct ipaddr
)) == 0);
1256 * Callback to allocate neighbor hash entry.
1258 static void *zvni_neigh_alloc(void *p
)
1260 const zebra_neigh_t
*tmp_n
= p
;
1263 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
1270 * Add neighbor entry.
1272 static zebra_neigh_t
*zvni_neigh_add(zebra_vni_t
*zvni
, struct ipaddr
*ip
,
1273 struct ethaddr
*mac
)
1275 zebra_neigh_t tmp_n
;
1276 zebra_neigh_t
*n
= NULL
;
1277 zebra_mac_t
*zmac
= NULL
;
1279 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
1280 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
1281 n
= hash_get(zvni
->neigh_table
, &tmp_n
, zvni_neigh_alloc
);
1284 memcpy(&n
->emac
, mac
, ETH_ALEN
);
1285 n
->state
= ZEBRA_NEIGH_INACTIVE
;
1287 /* Associate the neigh to mac */
1288 zmac
= zvni_mac_lookup(zvni
, mac
);
1290 listnode_add_sort(zmac
->neigh_list
, n
);
1296 * Delete neighbor entry.
1298 static int zvni_neigh_del(zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
1300 zebra_neigh_t
*tmp_n
;
1301 zebra_mac_t
*zmac
= NULL
;
1303 zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
1305 listnode_delete(zmac
->neigh_list
, n
);
1307 /* Free the VNI hash entry and allocated memory. */
1308 tmp_n
= hash_release(zvni
->neigh_table
, n
);
1310 XFREE(MTYPE_NEIGH
, tmp_n
);
1316 * Free neighbor hash entry (callback)
1318 static int zvni_neigh_del_hash_entry(struct hash_backet
*backet
, void *arg
)
1320 struct neigh_walk_ctx
*wctx
= arg
;
1321 zebra_neigh_t
*n
= backet
->data
;
1323 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
))
1324 || ((wctx
->flags
& DEL_REMOTE_NEIGH
)
1325 && (n
->flags
& ZEBRA_NEIGH_REMOTE
))
1326 || ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
)
1327 && (n
->flags
& ZEBRA_NEIGH_REMOTE
)
1328 && IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))) {
1329 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
1330 zvni_neigh_send_del_to_client(wctx
->zvni
->vni
, &n
->ip
,
1333 if (wctx
->uninstall
)
1334 zvni_neigh_uninstall(wctx
->zvni
, n
);
1336 return zvni_neigh_del(wctx
->zvni
, n
);
1343 * Delete all neighbor entries from specific VTEP for a particular VNI.
1345 static void zvni_neigh_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
1346 struct in_addr
*r_vtep_ip
)
1348 struct neigh_walk_ctx wctx
;
1350 if (!zvni
->neigh_table
)
1353 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1355 wctx
.uninstall
= uninstall
;
1356 wctx
.flags
= DEL_REMOTE_NEIGH_FROM_VTEP
;
1357 wctx
.r_vtep_ip
= *r_vtep_ip
;
1359 hash_iterate(zvni
->neigh_table
,
1360 (void (*)(struct hash_backet
*,
1361 void *))zvni_neigh_del_hash_entry
,
1366 * Delete all neighbor entries for this VNI.
1368 static void zvni_neigh_del_all(zebra_vni_t
*zvni
,
1369 int uninstall
, int upd_client
, u_int32_t flags
)
1371 struct neigh_walk_ctx wctx
;
1373 if (!zvni
->neigh_table
)
1376 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
1378 wctx
.uninstall
= uninstall
;
1379 wctx
.upd_client
= upd_client
;
1382 hash_iterate(zvni
->neigh_table
,
1383 (void (*)(struct hash_backet
*,
1384 void *))zvni_neigh_del_hash_entry
,
1389 * Look up neighbor hash entry.
1391 static zebra_neigh_t
*zvni_neigh_lookup(zebra_vni_t
*zvni
, struct ipaddr
*ip
)
1396 memset(&tmp
, 0, sizeof(tmp
));
1397 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
1398 n
= hash_lookup(zvni
->neigh_table
, &tmp
);
1403 /* Process all neigh associated to a mac upon local mac add event */
1404 static void zvni_process_neigh_on_local_mac_add(zebra_vni_t
*zvni
,
1407 zebra_neigh_t
*n
= NULL
;
1408 struct listnode
*node
= NULL
;
1409 char buf
[ETHER_ADDR_STRLEN
];
1410 char buf2
[INET6_ADDRSTRLEN
];
1412 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1413 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1414 /* MAC is learnt locally, program all inactive neigh
1415 * pointing to this mac */
1416 if (IS_ZEBRA_NEIGH_INACTIVE(n
)) {
1417 if (IS_ZEBRA_DEBUG_VXLAN
)
1419 "neigh %s (MAC %s) on L2-VNI %u is now ACTIVE",
1420 ipaddr2str(&n
->ip
, buf2
,
1422 prefix_mac2str(&n
->emac
, buf
,
1426 ZEBRA_NEIGH_SET_ACTIVE(n
);
1427 zvni_neigh_send_add_to_client(
1428 zvni
->vni
, &n
->ip
, &n
->emac
, n
->flags
);
1430 if (IS_ZEBRA_DEBUG_VXLAN
)
1432 "neigh %s (MAC %s) on VNI %u should NOT be ACTIVE",
1433 ipaddr2str(&n
->ip
, buf2
,
1435 prefix_mac2str(&n
->emac
, buf
,
1439 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1440 /* TODO: assume the neigh has moved too ?? */
1445 /* Process all neigh associated to a mac upon local mac del event */
1446 static void zvni_process_neigh_on_local_mac_del(zebra_vni_t
*zvni
,
1449 zebra_neigh_t
*n
= NULL
;
1450 struct listnode
*node
= NULL
;
1451 char buf
[ETHER_ADDR_STRLEN
];
1452 char buf2
[INET6_ADDRSTRLEN
];
1454 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1455 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1456 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1457 if (IS_ZEBRA_DEBUG_VXLAN
)
1459 "neigh %s (MAC %s) on L2-VNI %u is now INACTIVE",
1460 ipaddr2str(&n
->ip
, buf2
,
1462 prefix_mac2str(&n
->emac
, buf
,
1466 ZEBRA_NEIGH_SET_INACTIVE(n
);
1467 zvni_neigh_send_del_to_client(
1468 zvni
->vni
, &n
->ip
, &n
->emac
, 0);
1470 } else if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
1471 if (IS_ZEBRA_DEBUG_VXLAN
)
1473 "local MAC %s getting deleted on VNI %u has remote neigh %s",
1474 prefix_mac2str(&n
->emac
, buf
,
1477 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1482 /* process all neigh associated to a mac entry upon remote mac add */
1483 static void zvni_process_neigh_on_remote_mac_add(zebra_vni_t
*zvni
,
1486 zebra_neigh_t
*n
= NULL
;
1487 struct listnode
*node
= NULL
;
1488 char buf
[ETHER_ADDR_STRLEN
];
1489 char buf2
[INET6_ADDRSTRLEN
];
1491 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1492 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1493 if (IS_ZEBRA_NEIGH_ACTIVE(n
)) {
1494 if (IS_ZEBRA_DEBUG_VXLAN
)
1496 "neigh %s (MAC %s) on L2-VNI %u is now INACTIVE",
1497 ipaddr2str(&n
->ip
, buf2
,
1499 prefix_mac2str(&n
->emac
, buf
,
1503 ZEBRA_NEIGH_SET_INACTIVE(n
);
1504 zvni_neigh_send_del_to_client(
1505 zvni
->vni
, &n
->ip
, &n
->emac
, 0);
1511 /* process all neigh associated to mac entry upon remote mac del */
1512 static void zvni_process_neigh_on_remote_mac_del(zebra_vni_t
*zvni
,
1515 zebra_neigh_t
*n
= NULL
;
1516 struct listnode
*node
= NULL
;
1517 char buf
[ETHER_ADDR_STRLEN
];
1518 char buf2
[INET6_ADDRSTRLEN
];
1520 for (ALL_LIST_ELEMENTS_RO(zmac
->neigh_list
, node
, n
)) {
1521 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
1522 if (IS_ZEBRA_DEBUG_VXLAN
)
1524 "remote MAC %s getting deleted on VNI %u has local neigh %s",
1525 prefix_mac2str(&n
->emac
, buf
,
1528 ipaddr2str(&n
->ip
, buf2
, sizeof(buf2
)));
1534 * Inform BGP about local neighbor addition.
1536 static int zvni_neigh_send_add_to_client(vni_t vni
,
1538 struct ethaddr
*macaddr
,
1543 if (CHECK_FLAG(neigh_flags
, ZEBRA_NEIGH_DEF_GW
))
1544 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
1546 return zvni_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
,
1551 * Inform BGP about local neighbor deletion.
1553 static int zvni_neigh_send_del_to_client(vni_t vni
,
1555 struct ethaddr
*macaddr
, u_char flags
)
1557 return zvni_macip_send_msg_to_client(vni
, macaddr
, ip
, flags
,
1562 * Install remote neighbor into the kernel.
1564 static int zvni_neigh_install(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 zif
= zvni
->vxlan_if
->info
;
1576 vxl
= &zif
->l2info
.vxl
;
1578 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1582 return kernel_add_neigh(vlan_if
, &n
->ip
, &n
->emac
);
1586 * Uninstall remote neighbor from the kernel.
1588 static int zvni_neigh_uninstall(zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
1590 struct zebra_if
*zif
;
1591 struct zebra_l2info_vxlan
*vxl
;
1592 struct interface
*vlan_if
;
1594 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
1597 if (!zvni
->vxlan_if
) {
1598 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
1603 zif
= zvni
->vxlan_if
->info
;
1606 vxl
= &zif
->l2info
.vxl
;
1607 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
1611 return kernel_del_neigh(vlan_if
, &n
->ip
);
1615 * Install neighbor hash entry - called upon access VLAN change.
1617 static void zvni_install_neigh_hash(struct hash_backet
*backet
, void *ctxt
)
1620 struct neigh_walk_ctx
*wctx
= ctxt
;
1622 n
= (zebra_neigh_t
*)backet
->data
;
1626 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
1627 zvni_neigh_install(wctx
->zvni
, n
);
1630 /* Get the VRR interface for SVI if any */
1631 struct interface
*zebra_get_vrr_intf_for_svi(struct interface
*ifp
)
1633 struct zebra_vrf
*zvrf
= NULL
;
1634 struct interface
*tmp_if
= NULL
;
1635 struct zebra_if
*zif
= NULL
;
1637 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1640 FOR_ALL_INTERFACES (zvrf
->vrf
, tmp_if
) {
1645 if (!IS_ZEBRA_IF_MACVLAN(tmp_if
))
1648 if (zif
->link
== ifp
)
1655 static int zvni_del_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
)
1657 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1658 struct connected
*c
= NULL
;
1659 struct ethaddr macaddr
;
1661 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1663 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1666 memset(&ip
, 0, sizeof(struct ipaddr
));
1667 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
1670 if (c
->address
->family
== AF_INET
) {
1671 ip
.ipa_type
= IPADDR_V4
;
1672 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
1673 sizeof(struct in_addr
));
1674 } else if (c
->address
->family
== AF_INET6
) {
1675 ip
.ipa_type
= IPADDR_V6
;
1676 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
1677 sizeof(struct in6_addr
));
1682 zvni_gw_macip_del(ifp
, zvni
, &ip
);
1688 static int zvni_add_macip_for_intf(struct interface
*ifp
, zebra_vni_t
*zvni
)
1690 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1691 struct connected
*c
= NULL
;
1692 struct ethaddr macaddr
;
1694 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1696 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1699 memset(&ip
, 0, sizeof(struct ipaddr
));
1700 if (!CHECK_FLAG(c
->conf
, ZEBRA_IFC_REAL
))
1703 if (c
->address
->family
== AF_INET
) {
1704 ip
.ipa_type
= IPADDR_V4
;
1705 memcpy(&(ip
.ipaddr_v4
), &(c
->address
->u
.prefix4
),
1706 sizeof(struct in_addr
));
1707 } else if (c
->address
->family
== AF_INET6
) {
1708 ip
.ipa_type
= IPADDR_V6
;
1709 memcpy(&(ip
.ipaddr_v6
), &(c
->address
->u
.prefix6
),
1710 sizeof(struct in6_addr
));
1715 zvni_gw_macip_add(ifp
, zvni
, &macaddr
, &ip
);
1721 static int zvni_advertise_subnet(zebra_vni_t
*zvni
,
1722 struct interface
*ifp
,
1725 struct listnode
*cnode
= NULL
, *cnnode
= NULL
;
1726 struct connected
*c
= NULL
;
1727 struct ethaddr macaddr
;
1729 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
1731 for (ALL_LIST_ELEMENTS(ifp
->connected
, cnode
, cnnode
, c
)) {
1734 memcpy(&p
, c
->address
, sizeof(struct prefix
));
1736 /* skip link local address */
1737 if (IN6_IS_ADDR_LINKLOCAL(&p
.u
.prefix6
))
1742 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
1743 ZEBRA_IP_PREFIX_ROUTE_ADD
);
1745 ip_prefix_send_to_client(ifp
->vrf_id
, &p
,
1746 ZEBRA_IP_PREFIX_ROUTE_DEL
);
1752 * zvni_gw_macip_add_to_client
1754 static int zvni_gw_macip_add(struct interface
*ifp
, zebra_vni_t
*zvni
,
1755 struct ethaddr
*macaddr
, struct ipaddr
*ip
)
1757 char buf
[ETHER_ADDR_STRLEN
];
1758 char buf2
[INET6_ADDRSTRLEN
];
1759 zebra_neigh_t
*n
= NULL
;
1760 zebra_mac_t
*mac
= NULL
;
1761 struct zebra_if
*zif
= NULL
;
1762 struct zebra_l2info_vxlan
*vxl
= NULL
;
1764 zif
= zvni
->vxlan_if
->info
;
1768 vxl
= &zif
->l2info
.vxl
;
1770 mac
= zvni_mac_lookup(zvni
, macaddr
);
1772 mac
= zvni_mac_add(zvni
, macaddr
);
1774 zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
1775 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1776 ifp
->name
, ifp
->ifindex
, vxl
->access_vlan
);
1781 /* Set "local" forwarding info. */
1782 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
1783 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
1784 SET_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
);
1785 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
1786 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
1787 mac
->fwd_info
.local
.vid
= vxl
->access_vlan
;
1789 n
= zvni_neigh_lookup(zvni
, ip
);
1791 n
= zvni_neigh_add(zvni
, ip
, macaddr
);
1794 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
1795 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
1796 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1797 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
1802 /* Set "local" forwarding info. */
1803 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
1804 SET_FLAG(n
->flags
, ZEBRA_NEIGH_DEF_GW
);
1805 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
1806 n
->ifindex
= ifp
->ifindex
;
1808 /* Only advertise in BGP if the knob is enabled */
1809 if (!advertise_gw_macip_enabled(zvni
))
1812 if (IS_ZEBRA_DEBUG_VXLAN
)
1814 "SVI %s(%u) L2-VNI %u, sending GW MAC %s IP %s add to BGP",
1815 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
1816 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
1817 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
1819 zvni_neigh_send_add_to_client(zvni
->vni
, ip
, macaddr
,
1826 * zvni_gw_macip_del_from_client
1828 static int zvni_gw_macip_del(struct interface
*ifp
, zebra_vni_t
*zvni
,
1831 char buf1
[ETHER_ADDR_STRLEN
];
1832 char buf2
[INET6_ADDRSTRLEN
];
1833 zebra_neigh_t
*n
= NULL
;
1834 zebra_mac_t
*mac
= NULL
;
1836 /* If the neigh entry is not present nothing to do*/
1837 n
= zvni_neigh_lookup(zvni
, ip
);
1841 /* mac entry should be present */
1842 mac
= zvni_mac_lookup(zvni
, &n
->emac
);
1844 zlog_err("MAC %s doesnt exists for neigh %s on VNI %u",
1845 prefix_mac2str(&n
->emac
, buf1
, sizeof(buf1
)),
1846 ipaddr2str(ip
, buf2
, sizeof(buf2
)), zvni
->vni
);
1850 /* If the entry is not local nothing to do*/
1851 if (!CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
))
1854 /* only need to delete the entry from bgp if we sent it before */
1855 if (advertise_gw_macip_enabled(zvni
)) {
1856 if (IS_ZEBRA_DEBUG_VXLAN
)
1857 zlog_debug("%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP",
1858 ifp
->vrf_id
, ifp
->name
,
1859 ifp
->ifindex
, zvni
->vni
,
1860 prefix_mac2str(&(n
->emac
),
1863 ipaddr2str(ip
, buf2
, sizeof(buf2
)));
1865 /* Remove neighbor from BGP. */
1866 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
, &n
->emac
,
1867 ZEBRA_MACIP_TYPE_GW
);
1870 /* Delete this neighbor entry. */
1871 zvni_neigh_del(zvni
, n
);
1873 /* see if the mac needs to be deleted as well*/
1875 zvni_deref_ip2mac(zvni
, mac
, 0);
1880 static void zvni_gw_macip_del_for_vni_hash(struct hash_backet
*backet
,
1883 zebra_vni_t
*zvni
= NULL
;
1884 struct zebra_if
*zif
= NULL
;
1885 struct zebra_l2info_vxlan zl2_info
;
1886 struct interface
*vlan_if
= NULL
;
1887 struct interface
*vrr_if
= NULL
;
1888 struct interface
*ifp
;
1890 /* Add primary SVI MAC*/
1891 zvni
= (zebra_vni_t
*)backet
->data
;
1895 ifp
= zvni
->vxlan_if
;
1900 /* If down or not mapped to a bridge, we're done. */
1901 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
1904 zl2_info
= zif
->l2info
.vxl
;
1906 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
, zif
->brslave_info
.br_if
);
1910 /* Del primary MAC-IP */
1911 zvni_del_macip_for_intf(vlan_if
, zvni
);
1913 /* Del VRR MAC-IP - if any*/
1914 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1916 zvni_del_macip_for_intf(vrr_if
, zvni
);
1921 static void zvni_gw_macip_add_for_vni_hash(struct hash_backet
*backet
,
1924 zebra_vni_t
*zvni
= NULL
;
1925 struct zebra_if
*zif
= NULL
;
1926 struct zebra_l2info_vxlan zl2_info
;
1927 struct interface
*vlan_if
= NULL
;
1928 struct interface
*vrr_if
= NULL
;
1929 struct interface
*ifp
= NULL
;
1931 zvni
= (zebra_vni_t
*)backet
->data
;
1935 ifp
= zvni
->vxlan_if
;
1940 /* If down or not mapped to a bridge, we're done. */
1941 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
1943 zl2_info
= zif
->l2info
.vxl
;
1945 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
1946 zif
->brslave_info
.br_if
);
1950 /* Add primary SVI MAC-IP */
1951 zvni_add_macip_for_intf(vlan_if
, zvni
);
1953 /* Add VRR MAC-IP - if any*/
1954 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
1956 zvni_add_macip_for_intf(vrr_if
, zvni
);
1962 * Make hash key for MAC.
1964 static unsigned int mac_hash_keymake(void *p
)
1966 zebra_mac_t
*pmac
= p
;
1967 const void *pnt
= (void *)pmac
->macaddr
.octet
;
1969 return jhash(pnt
, ETH_ALEN
, 0xa5a5a55a);
1973 * Compare two MAC addresses.
1975 static int mac_cmp(const void *p1
, const void *p2
)
1977 const zebra_mac_t
*pmac1
= p1
;
1978 const zebra_mac_t
*pmac2
= p2
;
1980 if (pmac1
== NULL
&& pmac2
== NULL
)
1983 if (pmac1
== NULL
|| pmac2
== NULL
)
1986 return (memcmp(pmac1
->macaddr
.octet
, pmac2
->macaddr
.octet
,
1992 * Callback to allocate MAC hash entry.
1994 static void *zvni_mac_alloc(void *p
)
1996 const zebra_mac_t
*tmp_mac
= p
;
1999 mac
= XCALLOC(MTYPE_MAC
, sizeof(zebra_mac_t
));
2002 return ((void *)mac
);
2008 static zebra_mac_t
*zvni_mac_add(zebra_vni_t
*zvni
, struct ethaddr
*macaddr
)
2010 zebra_mac_t tmp_mac
;
2011 zebra_mac_t
*mac
= NULL
;
2013 memset(&tmp_mac
, 0, sizeof(zebra_mac_t
));
2014 memcpy(&tmp_mac
.macaddr
, macaddr
, ETH_ALEN
);
2015 mac
= hash_get(zvni
->mac_table
, &tmp_mac
, zvni_mac_alloc
);
2018 mac
->neigh_list
= list_new();
2019 mac
->neigh_list
->cmp
= (int (*)(void *, void *))neigh_cmp
;
2027 static int zvni_mac_del(zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
2029 zebra_mac_t
*tmp_mac
;
2031 list_delete_and_null(&mac
->neigh_list
);
2033 /* Free the VNI hash entry and allocated memory. */
2034 tmp_mac
= hash_release(zvni
->mac_table
, mac
);
2036 XFREE(MTYPE_MAC
, tmp_mac
);
2042 * Free MAC hash entry (callback)
2044 static int zvni_mac_del_hash_entry(struct hash_backet
*backet
, void *arg
)
2046 struct mac_walk_ctx
*wctx
= arg
;
2047 zebra_mac_t
*mac
= backet
->data
;
2049 if (((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_LOCAL
))
2050 || ((wctx
->flags
& DEL_REMOTE_MAC
)
2051 && (mac
->flags
& ZEBRA_MAC_REMOTE
))
2052 || ((wctx
->flags
& DEL_REMOTE_MAC_FROM_VTEP
)
2053 && (mac
->flags
& ZEBRA_MAC_REMOTE
)
2054 && IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
2055 &wctx
->r_vtep_ip
))) {
2056 if (wctx
->upd_client
&& (mac
->flags
& ZEBRA_MAC_LOCAL
)) {
2057 zvni_mac_send_del_to_client(
2058 wctx
->zvni
->vni
, &mac
->macaddr
,
2062 if (wctx
->uninstall
)
2063 zvni_mac_uninstall(wctx
->zvni
, mac
, 0);
2065 return zvni_mac_del(wctx
->zvni
, mac
);
2072 * Delete all MAC entries from specific VTEP for a particular VNI.
2074 static void zvni_mac_del_from_vtep(zebra_vni_t
*zvni
, int uninstall
,
2075 struct in_addr
*r_vtep_ip
)
2077 struct mac_walk_ctx wctx
;
2079 if (!zvni
->mac_table
)
2082 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
2084 wctx
.uninstall
= uninstall
;
2085 wctx
.flags
= DEL_REMOTE_MAC_FROM_VTEP
;
2086 wctx
.r_vtep_ip
= *r_vtep_ip
;
2088 hash_iterate(zvni
->mac_table
, (void (*)(struct hash_backet
*,
2089 void *))zvni_mac_del_hash_entry
,
2094 * Delete all MAC entries for this VNI.
2096 static void zvni_mac_del_all(zebra_vni_t
*zvni
,
2097 int uninstall
, int upd_client
, u_int32_t flags
)
2099 struct mac_walk_ctx wctx
;
2101 if (!zvni
->mac_table
)
2104 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
2106 wctx
.uninstall
= uninstall
;
2107 wctx
.upd_client
= upd_client
;
2110 hash_iterate(zvni
->mac_table
, (void (*)(struct hash_backet
*,
2111 void *))zvni_mac_del_hash_entry
,
2116 * Look up MAC hash entry.
2118 static zebra_mac_t
*zvni_mac_lookup(zebra_vni_t
*zvni
, struct ethaddr
*mac
)
2123 memset(&tmp
, 0, sizeof(tmp
));
2124 memcpy(&tmp
.macaddr
, mac
, ETH_ALEN
);
2125 pmac
= hash_lookup(zvni
->mac_table
, &tmp
);
2131 * Inform BGP about local MAC addition.
2133 static int zvni_mac_send_add_to_client(vni_t vni
,
2134 struct ethaddr
*macaddr
,
2139 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
2140 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2141 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
2142 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2144 return zvni_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
2149 * Inform BGP about local MAC deletion.
2151 static int zvni_mac_send_del_to_client(vni_t vni
,
2152 struct ethaddr
*macaddr
,
2157 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_STICKY
))
2158 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
2159 if (CHECK_FLAG(mac_flags
, ZEBRA_MAC_DEF_GW
))
2160 SET_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
);
2162 return zvni_macip_send_msg_to_client(vni
, macaddr
, NULL
, flags
,
2167 * Map port or (port, VLAN) to a VNI. This is invoked upon getting MAC
2168 * notifications, to see if they are of interest.
2170 static zebra_vni_t
*zvni_map_vlan(struct interface
*ifp
,
2171 struct interface
*br_if
, vlanid_t vid
)
2173 struct zebra_ns
*zns
;
2174 struct route_node
*rn
;
2175 struct interface
*tmp_if
= NULL
;
2176 struct zebra_if
*zif
;
2177 struct zebra_l2info_bridge
*br
;
2178 struct zebra_l2info_vxlan
*vxl
= NULL
;
2179 u_char bridge_vlan_aware
;
2183 /* Determine if bridge is VLAN-aware or not */
2186 br
= &zif
->l2info
.br
;
2187 bridge_vlan_aware
= br
->vlan_aware
;
2189 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2190 /* TODO: Optimize with a hash. */
2191 zns
= zebra_ns_lookup(NS_DEFAULT
);
2192 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2193 tmp_if
= (struct interface
*)rn
->info
;
2197 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2199 if (!if_is_operative(tmp_if
))
2201 vxl
= &zif
->l2info
.vxl
;
2203 if (zif
->brslave_info
.br_if
!= br_if
)
2206 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
2215 zvni
= zvni_lookup(vxl
->vni
);
2220 * Map SVI and associated bridge to a VNI. This is invoked upon getting
2221 * neighbor notifications, to see if they are of interest.
2223 static zebra_vni_t
*zvni_from_svi(struct interface
*ifp
,
2224 struct interface
*br_if
)
2226 struct zebra_ns
*zns
;
2227 struct route_node
*rn
;
2228 struct interface
*tmp_if
= NULL
;
2229 struct zebra_if
*zif
;
2230 struct zebra_l2info_bridge
*br
;
2231 struct zebra_l2info_vxlan
*vxl
= NULL
;
2232 u_char bridge_vlan_aware
;
2240 /* Make sure the linked interface is a bridge. */
2241 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
2244 /* Determine if bridge is VLAN-aware or not */
2247 br
= &zif
->l2info
.br
;
2248 bridge_vlan_aware
= br
->vlan_aware
;
2249 if (bridge_vlan_aware
) {
2250 struct zebra_l2info_vlan
*vl
;
2252 if (!IS_ZEBRA_IF_VLAN(ifp
))
2257 vl
= &zif
->l2info
.vl
;
2261 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
2262 /* TODO: Optimize with a hash. */
2263 zns
= zebra_ns_lookup(NS_DEFAULT
);
2264 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2265 tmp_if
= (struct interface
*)rn
->info
;
2269 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2271 if (!if_is_operative(tmp_if
))
2273 vxl
= &zif
->l2info
.vxl
;
2275 if (zif
->brslave_info
.br_if
!= br_if
)
2278 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
2287 zvni
= zvni_lookup(vxl
->vni
);
2291 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
2293 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
2294 * linked to the bridge
2295 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge inteface
2298 static struct interface
*zvni_map_to_svi(vlanid_t vid
, struct interface
*br_if
)
2300 struct zebra_ns
*zns
;
2301 struct route_node
*rn
;
2302 struct interface
*tmp_if
= NULL
;
2303 struct zebra_if
*zif
;
2304 struct zebra_l2info_bridge
*br
;
2305 struct zebra_l2info_vlan
*vl
;
2306 u_char bridge_vlan_aware
;
2309 /* Defensive check, caller expected to invoke only with valid bridge. */
2313 /* Determine if bridge is VLAN-aware or not */
2316 br
= &zif
->l2info
.br
;
2317 bridge_vlan_aware
= br
->vlan_aware
;
2319 /* Check oper status of the SVI. */
2320 if (!bridge_vlan_aware
)
2321 return if_is_operative(br_if
) ? br_if
: NULL
;
2323 /* Identify corresponding VLAN interface. */
2324 /* TODO: Optimize with a hash. */
2325 zns
= zebra_ns_lookup(NS_DEFAULT
);
2326 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2327 tmp_if
= (struct interface
*)rn
->info
;
2328 /* Check oper status of the SVI. */
2329 if (!tmp_if
|| !if_is_operative(tmp_if
))
2332 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VLAN
2333 || zif
->link
!= br_if
)
2335 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
2337 if (vl
->vid
== vid
) {
2343 return found
? tmp_if
: NULL
;
2347 * Install remote MAC into the kernel.
2349 static int zvni_mac_install(zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
2351 struct zebra_if
*zif
;
2352 struct zebra_l2info_vxlan
*vxl
;
2355 if (!(mac
->flags
& ZEBRA_MAC_REMOTE
))
2358 zif
= zvni
->vxlan_if
->info
;
2361 vxl
= &zif
->l2info
.vxl
;
2363 sticky
= CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
) ? 1 : 0;
2365 return kernel_add_mac(zvni
->vxlan_if
, vxl
->access_vlan
, &mac
->macaddr
,
2366 mac
->fwd_info
.r_vtep_ip
, sticky
);
2370 * Uninstall remote MAC from the kernel. In the scenario where the MAC
2371 * moves to remote, we have to uninstall any existing local entry first.
2373 static int zvni_mac_uninstall(zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
)
2375 struct zebra_if
*zif
;
2376 struct zebra_l2info_vxlan
*vxl
;
2377 struct in_addr vtep_ip
= {.s_addr
= 0};
2378 struct zebra_ns
*zns
;
2379 struct interface
*ifp
;
2381 if (!local
&& !(mac
->flags
& ZEBRA_MAC_REMOTE
))
2384 if (!zvni
->vxlan_if
) {
2385 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
2390 zif
= zvni
->vxlan_if
->info
;
2393 vxl
= &zif
->l2info
.vxl
;
2396 zns
= zebra_ns_lookup(NS_DEFAULT
);
2397 ifp
= if_lookup_by_index_per_ns(zns
,
2398 mac
->fwd_info
.local
.ifindex
);
2399 if (!ifp
) // unexpected
2402 ifp
= zvni
->vxlan_if
;
2403 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
2406 return kernel_del_mac(ifp
, vxl
->access_vlan
, &mac
->macaddr
, vtep_ip
,
2411 * Install MAC hash entry - called upon access VLAN change.
2413 static void zvni_install_mac_hash(struct hash_backet
*backet
, void *ctxt
)
2416 struct mac_walk_ctx
*wctx
= ctxt
;
2418 mac
= (zebra_mac_t
*)backet
->data
;
2422 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
2423 zvni_mac_install(wctx
->zvni
, mac
);
2427 * Decrement neighbor refcount of MAC; uninstall and free it if
2430 static void zvni_deref_ip2mac(zebra_vni_t
*zvni
, zebra_mac_t
*mac
,
2433 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
)
2434 || !list_isempty(mac
->neigh_list
))
2438 zvni_mac_uninstall(zvni
, mac
, 0);
2440 zvni_mac_del(zvni
, mac
);
2444 * Read and populate local MACs and neighbors corresponding to this VNI.
2446 static void zvni_read_mac_neigh(zebra_vni_t
*zvni
,
2447 struct interface
*ifp
)
2449 struct zebra_ns
*zns
;
2450 struct zebra_if
*zif
;
2451 struct interface
*vlan_if
;
2452 struct zebra_l2info_vxlan
*vxl
;
2453 struct interface
*vrr_if
;
2456 vxl
= &zif
->l2info
.vxl
;
2457 zns
= zebra_ns_lookup(NS_DEFAULT
);
2459 if (IS_ZEBRA_DEBUG_VXLAN
)
2461 "Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
2462 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
2463 zif
->brslave_info
.bridge_ifindex
);
2465 macfdb_read_for_bridge(zns
, ifp
, zif
->brslave_info
.br_if
);
2466 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
2469 /* Add SVI MAC-IP */
2470 zvni_add_macip_for_intf(vlan_if
, zvni
);
2472 /* Add VRR MAC-IP - if any*/
2473 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
2475 zvni_add_macip_for_intf(vrr_if
, zvni
);
2477 neigh_read_for_vlan(zns
, vlan_if
);
2482 * Hash function for VNI.
2484 static unsigned int vni_hash_keymake(void *p
)
2486 const zebra_vni_t
*zvni
= p
;
2488 return (jhash_1word(zvni
->vni
, 0));
2492 * Compare 2 VNI hash entries.
2494 static int vni_hash_cmp(const void *p1
, const void *p2
)
2496 const zebra_vni_t
*zvni1
= p1
;
2497 const zebra_vni_t
*zvni2
= p2
;
2499 return (zvni1
->vni
== zvni2
->vni
);
2503 * Callback to allocate VNI hash entry.
2505 static void *zvni_alloc(void *p
)
2507 const zebra_vni_t
*tmp_vni
= p
;
2510 zvni
= XCALLOC(MTYPE_ZVNI
, sizeof(zebra_vni_t
));
2511 zvni
->vni
= tmp_vni
->vni
;
2512 return ((void *)zvni
);
2516 * Look up VNI hash entry.
2518 static zebra_vni_t
*zvni_lookup(vni_t vni
)
2520 struct zebra_vrf
*zvrf
;
2521 zebra_vni_t tmp_vni
;
2522 zebra_vni_t
*zvni
= NULL
;
2524 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2526 memset(&tmp_vni
, 0, sizeof(zebra_vni_t
));
2528 zvni
= hash_lookup(zvrf
->vni_table
, &tmp_vni
);
2534 * Add VNI hash entry.
2536 static zebra_vni_t
*zvni_add(vni_t vni
)
2538 struct zebra_vrf
*zvrf
;
2539 zebra_vni_t tmp_zvni
;
2540 zebra_vni_t
*zvni
= NULL
;
2542 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2544 memset(&tmp_zvni
, 0, sizeof(zebra_vni_t
));
2546 zvni
= hash_get(zvrf
->vni_table
, &tmp_zvni
, zvni_alloc
);
2549 /* Create hash table for MAC */
2551 hash_create(mac_hash_keymake
, mac_cmp
, "Zebra VNI MAC Table");
2553 /* Create hash table for neighbors */
2554 zvni
->neigh_table
= hash_create(neigh_hash_keymake
, neigh_cmp
,
2555 "Zebra VNI Neighbor Table");
2561 * Delete VNI hash entry.
2563 static int zvni_del(zebra_vni_t
*zvni
)
2565 struct zebra_vrf
*zvrf
;
2566 zebra_vni_t
*tmp_zvni
;
2568 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
2571 zvni
->vxlan_if
= NULL
;
2573 /* Free the neighbor hash table. */
2574 hash_free(zvni
->neigh_table
);
2575 zvni
->neigh_table
= NULL
;
2577 /* Free the MAC hash table. */
2578 hash_free(zvni
->mac_table
);
2579 zvni
->mac_table
= NULL
;
2581 /* Free the VNI hash entry and allocated memory. */
2582 tmp_zvni
= hash_release(zvrf
->vni_table
, zvni
);
2584 XFREE(MTYPE_ZVNI
, tmp_zvni
);
2590 * Inform BGP about local VNI addition.
2592 static int zvni_send_add_to_client(zebra_vni_t
*zvni
)
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_ADD
, VRF_DEFAULT
);
2606 stream_putl(s
, zvni
->vni
);
2607 stream_put_in_addr(s
, &zvni
->local_vtep_ip
);
2608 stream_put(s
, &zvni
->vrf_id
, sizeof(vrf_id_t
)); /* tenant vrf */
2610 /* Write packet size. */
2611 stream_putw_at(s
, 0, stream_get_endp(s
));
2613 if (IS_ZEBRA_DEBUG_VXLAN
)
2614 zlog_debug("Send VNI_ADD %u %s tenant vrf %s to %s",
2615 zvni
->vni
, inet_ntoa(zvni
->local_vtep_ip
),
2616 vrf_id_to_name(zvni
->vrf_id
),
2617 zebra_route_string(client
->proto
));
2619 client
->vniadd_cnt
++;
2620 return zebra_server_send_message(client
);
2624 * Inform BGP about local VNI deletion.
2626 static int zvni_send_del_to_client(vni_t vni
)
2628 struct zserv
*client
;
2631 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
2632 /* BGP may not be running. */
2639 zclient_create_header(s
, ZEBRA_VNI_DEL
, VRF_DEFAULT
);
2640 stream_putl(s
, vni
);
2642 /* Write packet size. */
2643 stream_putw_at(s
, 0, stream_get_endp(s
));
2645 if (IS_ZEBRA_DEBUG_VXLAN
)
2646 zlog_debug("Send VNI_DEL %u to %s", vni
,
2647 zebra_route_string(client
->proto
));
2649 client
->vnidel_cnt
++;
2650 return zebra_server_send_message(client
);
2654 * Build the VNI hash table by going over the VxLAN interfaces. This
2655 * is called when EVPN (advertise-all-vni) is enabled.
2657 static void zvni_build_hash_table()
2659 struct zebra_ns
*zns
;
2660 struct route_node
*rn
;
2661 struct interface
*ifp
;
2663 /* Walk VxLAN interfaces and create VNI hash. */
2664 zns
= zebra_ns_lookup(NS_DEFAULT
);
2665 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
2667 struct zebra_if
*zif
;
2668 struct zebra_l2info_vxlan
*vxl
;
2670 ifp
= (struct interface
*)rn
->info
;
2674 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
2677 vxl
= &zif
->l2info
.vxl
;
2680 if (is_vni_l3(vni
)) {
2681 zebra_l3vni_t
*zl3vni
= NULL
;
2683 if (IS_ZEBRA_DEBUG_VXLAN
)
2684 zlog_debug("create L3-VNI hash for Intf %s(%u) L3-VNI %u",
2685 ifp
->name
, ifp
->ifindex
, vni
);
2687 zl3vni
= zl3vni_lookup(vni
);
2690 "Failed to locate L3-VNI hash at UP, IF %s(%u) VNI %u",
2691 ifp
->name
, ifp
->ifindex
, vni
);
2695 /* associate with vxlan_if */
2696 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
2697 zl3vni
->vxlan_if
= ifp
;
2700 * we need to associate with SVI.
2701 * we can associate with svi-if only after association
2702 * with vxlan-intf is complete
2704 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
2706 if (is_l3vni_oper_up(zl3vni
))
2707 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
2710 zebra_vni_t
*zvni
= NULL
;
2711 zebra_l3vni_t
*zl3vni
= NULL
;
2712 struct interface
*vlan_if
= NULL
;
2714 if (IS_ZEBRA_DEBUG_VXLAN
)
2716 "Create L2-VNI hash for intf %s(%u) L2-VNI %u local IP %s",
2717 ifp
->name
, ifp
->ifindex
, vni
,
2718 inet_ntoa(vxl
->vtep_ip
));
2720 /* VNI hash entry is not expected to exist. */
2721 zvni
= zvni_lookup(vni
);
2724 "VNI hash already present for IF %s(%u) L2-VNI %u",
2725 ifp
->name
, ifp
->ifindex
, vni
);
2729 zvni
= zvni_add(vni
);
2732 "Failed to add VNI hash, IF %s(%u) L2-VNI %u",
2733 ifp
->name
, ifp
->ifindex
, vni
);
2737 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
2738 zvni
->vxlan_if
= ifp
;
2739 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
2740 zif
->brslave_info
.br_if
);
2742 zvni
->vrf_id
= vlan_if
->vrf_id
;
2743 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
2745 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
2749 /* Inform BGP if intf is up and mapped to bridge. */
2750 if (if_is_operative(ifp
) && zif
->brslave_info
.br_if
)
2751 zvni_send_add_to_client(zvni
);
2757 * See if remote VTEP matches with prefix.
2759 static int zvni_vtep_match(struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
)
2761 return (IPV4_ADDR_SAME(vtep_ip
, &zvtep
->vtep_ip
));
2765 * Locate remote VTEP in VNI hash table.
2767 static zebra_vtep_t
*zvni_vtep_find(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2769 zebra_vtep_t
*zvtep
;
2774 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
) {
2775 if (zvni_vtep_match(vtep_ip
, zvtep
))
2783 * Add remote VTEP to VNI hash table.
2785 static zebra_vtep_t
*zvni_vtep_add(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2787 zebra_vtep_t
*zvtep
;
2789 zvtep
= XCALLOC(MTYPE_ZVNI_VTEP
, sizeof(zebra_vtep_t
));
2791 zlog_err("Failed to alloc VTEP entry, VNI %u", zvni
->vni
);
2795 zvtep
->vtep_ip
= *vtep_ip
;
2798 zvni
->vteps
->prev
= zvtep
;
2799 zvtep
->next
= zvni
->vteps
;
2800 zvni
->vteps
= zvtep
;
2806 * Remove remote VTEP from VNI hash table.
2808 static int zvni_vtep_del(zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
)
2811 zvtep
->next
->prev
= zvtep
->prev
;
2813 zvtep
->prev
->next
= zvtep
->next
;
2815 zvni
->vteps
= zvtep
->next
;
2817 zvtep
->prev
= zvtep
->next
= NULL
;
2818 XFREE(MTYPE_ZVNI_VTEP
, zvtep
);
2824 * Delete all remote VTEPs for this VNI (upon VNI delete). Also
2825 * uninstall from kernel if asked to.
2827 static int zvni_vtep_del_all(zebra_vni_t
*zvni
, int uninstall
)
2829 zebra_vtep_t
*zvtep
, *zvtep_next
;
2834 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep_next
) {
2835 zvtep_next
= zvtep
->next
;
2837 zvni_vtep_uninstall(zvni
, &zvtep
->vtep_ip
);
2838 zvni_vtep_del(zvni
, zvtep
);
2845 * Install remote VTEP into the kernel.
2847 static int zvni_vtep_install(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2849 return kernel_add_vtep(zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
2853 * Uninstall remote VTEP from the kernel.
2855 static int zvni_vtep_uninstall(zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
2857 if (!zvni
->vxlan_if
) {
2858 zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
2863 return kernel_del_vtep(zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
2867 * Cleanup VNI/VTEP and update kernel
2869 static void zvni_cleanup_all(struct hash_backet
*backet
, void *zvrf
)
2871 zebra_vni_t
*zvni
= NULL
;
2872 zebra_l3vni_t
*zl3vni
= NULL
;
2874 zvni
= (zebra_vni_t
*)backet
->data
;
2878 /* remove from l3-vni list */
2879 zl3vni
= zl3vni_from_vrf(zvni
->vrf_id
);
2881 listnode_delete(zl3vni
->l2vnis
, zvni
);
2883 /* Free up all neighbors and MACs, if any. */
2884 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
2885 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
2887 /* Free up all remote VTEPs, if any. */
2888 zvni_vtep_del_all(zvni
, 1);
2890 /* Delete the hash entry. */
2895 static void zl3vni_cleanup_all(struct hash_backet
*backet
,
2898 zebra_l3vni_t
*zl3vni
= NULL
;
2900 zl3vni
= (zebra_l3vni_t
*)backet
->data
;
2904 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
2907 static int is_host_present_in_host_list(struct list
*list
,
2908 struct prefix
*host
)
2910 struct listnode
*node
= NULL
;
2911 struct prefix
*p
= NULL
;
2913 for (ALL_LIST_ELEMENTS_RO(list
, node
, p
)) {
2914 if (prefix_same(p
, host
))
2920 static void host_list_add_host(struct list
*list
,
2921 struct prefix
*host
)
2923 struct prefix
*p
= NULL
;
2925 p
= XCALLOC(MTYPE_HOST_PREFIX
, sizeof(struct prefix
));
2926 memcpy(p
, host
, sizeof(struct prefix
));
2928 listnode_add_sort(list
, p
);
2931 static void host_list_delete_host(struct list
*list
,
2932 struct prefix
*host
)
2934 struct listnode
*node
= NULL
, *nnode
= NULL
, *node_to_del
= NULL
;
2935 struct prefix
*p
= NULL
;
2937 for (ALL_LIST_ELEMENTS(list
, node
, nnode
, p
)) {
2938 if (prefix_same(p
, host
)) {
2939 XFREE(MTYPE_HOST_PREFIX
, p
);
2945 list_delete_node(list
, node_to_del
);
2949 * Look up MAC hash entry.
2951 static zebra_mac_t
*zl3vni_rmac_lookup(zebra_l3vni_t
*zl3vni
,
2952 struct ethaddr
*rmac
)
2957 memset(&tmp
, 0, sizeof(tmp
));
2958 memcpy(&tmp
.macaddr
, rmac
, ETH_ALEN
);
2959 pmac
= hash_lookup(zl3vni
->rmac_table
, &tmp
);
2965 * Callback to allocate RMAC hash entry.
2967 static void *zl3vni_rmac_alloc(void *p
)
2969 const zebra_mac_t
*tmp_rmac
= p
;
2972 zrmac
= XCALLOC(MTYPE_MAC
, sizeof(zebra_mac_t
));
2975 return ((void *)zrmac
);
2979 * Add RMAC entry to l3-vni
2981 static zebra_mac_t
*zl3vni_rmac_add(zebra_l3vni_t
*zl3vni
,
2982 struct ethaddr
*rmac
)
2984 zebra_mac_t tmp_rmac
;
2985 zebra_mac_t
*zrmac
= NULL
;
2987 memset(&tmp_rmac
, 0, sizeof(zebra_mac_t
));
2988 memcpy(&tmp_rmac
.macaddr
, rmac
, ETH_ALEN
);
2989 zrmac
= hash_get(zl3vni
->rmac_table
, &tmp_rmac
, zl3vni_rmac_alloc
);
2992 zrmac
->host_list
= list_new();
2993 zrmac
->host_list
->cmp
= (int (*)(void *, void *))prefix_cmp
;
2995 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
);
2996 SET_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
);
3004 static int zl3vni_rmac_del(zebra_l3vni_t
*zl3vni
,
3007 zebra_mac_t
*tmp_rmac
;
3009 if (zrmac
->host_list
)
3010 list_delete_and_null(&zrmac
->host_list
);
3011 zrmac
->host_list
= NULL
;
3013 tmp_rmac
= hash_release(zl3vni
->rmac_table
, zrmac
);
3015 XFREE(MTYPE_MAC
, tmp_rmac
);
3021 * Install remote RMAC into the kernel.
3023 static int zl3vni_rmac_install(zebra_l3vni_t
*zl3vni
,
3026 struct zebra_if
*zif
= NULL
;
3027 struct zebra_l2info_vxlan
*vxl
= NULL
;
3029 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
)) ||
3030 !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
3033 zif
= zl3vni
->vxlan_if
->info
;
3037 vxl
= &zif
->l2info
.vxl
;
3039 return kernel_add_mac(zl3vni
->vxlan_if
, vxl
->access_vlan
,
3041 zrmac
->fwd_info
.r_vtep_ip
, 0);
3045 * Uninstall remote RMAC from the kernel.
3047 static int zl3vni_rmac_uninstall(zebra_l3vni_t
*zl3vni
,
3050 char buf
[ETHER_ADDR_STRLEN
];
3051 struct zebra_if
*zif
= NULL
;
3052 struct zebra_l2info_vxlan
*vxl
= NULL
;
3054 if (!(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE
)) ||
3055 !(CHECK_FLAG(zrmac
->flags
, ZEBRA_MAC_REMOTE_RMAC
)))
3058 if (!zl3vni
->vxlan_if
) {
3060 "RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
3061 prefix_mac2str(&zrmac
->macaddr
, buf
, sizeof(buf
)),
3062 zl3vni
->vni
, zl3vni
);
3066 zif
= zl3vni
->vxlan_if
->info
;
3070 vxl
= &zif
->l2info
.vxl
;
3072 return kernel_del_mac(zl3vni
->vxlan_if
, vxl
->access_vlan
,
3073 &zrmac
->macaddr
, zrmac
->fwd_info
.r_vtep_ip
, 0);
3076 /* handle rmac add */
3077 static int zl3vni_remote_rmac_add(zebra_l3vni_t
*zl3vni
,
3078 struct ethaddr
*rmac
,
3079 struct ipaddr
*vtep_ip
,
3080 struct prefix
*host_prefix
)
3082 char buf
[ETHER_ADDR_STRLEN
];
3083 char buf1
[INET6_ADDRSTRLEN
];
3084 zebra_mac_t
*zrmac
= NULL
;
3086 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3089 zrmac
= zl3vni_rmac_add(zl3vni
, rmac
);
3092 "Failed to add RMAC %s L3VNI %u Remote VTEP %s",
3093 prefix_mac2str(rmac
, buf
,
3095 zl3vni
->vni
, ipaddr2str(vtep_ip
, buf1
,
3099 memset(&zrmac
->fwd_info
, 0, sizeof(zrmac
->fwd_info
));
3100 zrmac
->fwd_info
.r_vtep_ip
= vtep_ip
->ipaddr_v4
;
3102 /* install rmac in kernel */
3103 zl3vni_rmac_install(zl3vni
, zrmac
);
3106 if (!is_host_present_in_host_list(zrmac
->host_list
, host_prefix
))
3107 host_list_add_host(zrmac
->host_list
, host_prefix
);
3112 /* handle rmac delete */
3113 static int zl3vni_remote_rmac_del(zebra_l3vni_t
*zl3vni
,
3114 struct ethaddr
*rmac
,
3115 struct prefix
*host_prefix
)
3117 zebra_mac_t
*zrmac
= NULL
;
3119 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3123 host_list_delete_host(zrmac
->host_list
, host_prefix
);
3124 if (list_isempty(zrmac
->host_list
)) {
3126 /* uninstall from kernel */
3127 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
3129 /* del the rmac entry */
3130 zl3vni_rmac_del(zl3vni
, zrmac
);
3136 * Look up nh hash entry on a l3-vni.
3138 static zebra_neigh_t
*zl3vni_nh_lookup(zebra_l3vni_t
*zl3vni
,
3144 memset(&tmp
, 0, sizeof(tmp
));
3145 memcpy(&tmp
.ip
, ip
, sizeof(struct ipaddr
));
3146 n
= hash_lookup(zl3vni
->nh_table
, &tmp
);
3153 * Callback to allocate NH hash entry on L3-VNI.
3155 static void *zl3vni_nh_alloc(void *p
)
3157 const zebra_neigh_t
*tmp_n
= p
;
3160 n
= XCALLOC(MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
3167 * Add neighbor entry.
3169 static zebra_neigh_t
*zl3vni_nh_add(zebra_l3vni_t
*zl3vni
,
3171 struct ethaddr
*mac
)
3173 zebra_neigh_t tmp_n
;
3174 zebra_neigh_t
*n
= NULL
;
3176 memset(&tmp_n
, 0, sizeof(zebra_neigh_t
));
3177 memcpy(&tmp_n
.ip
, ip
, sizeof(struct ipaddr
));
3178 n
= hash_get(zl3vni
->nh_table
, &tmp_n
, zl3vni_nh_alloc
);
3181 n
->host_list
= list_new();
3182 n
->host_list
->cmp
= (int (*)(void *, void *))prefix_cmp
;
3184 memcpy(&n
->emac
, mac
, ETH_ALEN
);
3185 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
3186 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE_NH
);
3192 * Delete neighbor entry.
3194 static int zl3vni_nh_del(zebra_l3vni_t
*zl3vni
,
3197 zebra_neigh_t
*tmp_n
;
3200 list_delete_and_null(&n
->host_list
);
3201 n
->host_list
= NULL
;
3203 tmp_n
= hash_release(zl3vni
->nh_table
, n
);
3205 XFREE(MTYPE_NEIGH
, tmp_n
);
3211 * Install remote nh as neigh into the kernel.
3213 static int zl3vni_nh_install(zebra_l3vni_t
*zl3vni
,
3216 if (!is_l3vni_oper_up(zl3vni
))
3219 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
) ||
3220 !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
3223 return kernel_add_neigh(zl3vni
->svi_if
, &n
->ip
, &n
->emac
);
3227 * Uninstall remote nh from the kernel.
3229 static int zl3vni_nh_uninstall(zebra_l3vni_t
*zl3vni
,
3232 if (!is_l3vni_oper_up(zl3vni
))
3235 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
) ||
3236 !(n
->flags
& ZEBRA_NEIGH_REMOTE_NH
))
3239 return kernel_del_neigh(zl3vni
->svi_if
, &n
->ip
);
3242 /* add remote vtep as a neigh entry */
3243 static int zl3vni_remote_nh_add(zebra_l3vni_t
*zl3vni
,
3244 struct ipaddr
*vtep_ip
,
3245 struct ethaddr
*rmac
,
3246 struct prefix
*host_prefix
)
3248 char buf
[ETHER_ADDR_STRLEN
];
3249 char buf1
[INET6_ADDRSTRLEN
];
3250 zebra_neigh_t
*nh
= NULL
;
3252 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
3254 nh
= zl3vni_nh_add(zl3vni
, vtep_ip
, rmac
);
3258 "Failed to add NH as Neigh (IP %s MAC %s L3-VNI %u)",
3259 ipaddr2str(vtep_ip
, buf1
,
3261 prefix_mac2str(rmac
, buf
,
3267 /* install the nh neigh in kernel */
3268 zl3vni_nh_install(zl3vni
, nh
);
3271 if (!is_host_present_in_host_list(nh
->host_list
, host_prefix
))
3272 host_list_add_host(nh
->host_list
, host_prefix
);
3277 /* handle nh neigh delete */
3278 static int zl3vni_remote_nh_del(zebra_l3vni_t
*zl3vni
,
3279 struct ipaddr
*vtep_ip
,
3280 struct prefix
*host_prefix
)
3282 zebra_neigh_t
*nh
= NULL
;
3284 nh
= zl3vni_nh_lookup(zl3vni
, vtep_ip
);
3288 host_list_delete_host(nh
->host_list
, host_prefix
);
3289 if (list_isempty(nh
->host_list
)) {
3291 /* uninstall from kernel */
3292 zl3vni_nh_uninstall(zl3vni
, nh
);
3294 /* delete the nh entry */
3295 zl3vni_nh_del(zl3vni
, nh
);
3301 /* handle neigh update from kernel - the only thing of interest is to
3302 * readd stale entries.
3304 static int zl3vni_local_nh_add_update(zebra_l3vni_t
*zl3vni
,
3305 struct ipaddr
*ip
, u_int16_t state
)
3308 zebra_neigh_t
*n
= NULL
;
3310 n
= zl3vni_nh_lookup(zl3vni
, ip
);
3314 /* all next hop neigh are remote and installed by frr.
3315 * If the kernel has aged this entry, re-install.
3317 if (state
& NUD_STALE
)
3318 zl3vni_nh_install(zl3vni
, n
);
3323 /* handle neigh delete from kernel */
3324 static int zl3vni_local_nh_del(zebra_l3vni_t
*zl3vni
,
3327 zebra_neigh_t
*n
= NULL
;
3329 n
= zl3vni_nh_lookup(zl3vni
, ip
);
3333 /* all next hop neigh are remote and installed by frr.
3334 * If we get an age out notification for these neigh entries, we have to
3337 zl3vni_nh_install(zl3vni
, n
);
3343 * Hash function for L3 VNI.
3345 static unsigned int l3vni_hash_keymake(void *p
)
3347 const zebra_l3vni_t
*zl3vni
= p
;
3349 return jhash_1word(zl3vni
->vni
, 0);
3353 * Compare 2 L3 VNI hash entries.
3355 static int l3vni_hash_cmp(const void *p1
, const void *p2
)
3357 const zebra_l3vni_t
*zl3vni1
= p1
;
3358 const zebra_l3vni_t
*zl3vni2
= p2
;
3360 return (zl3vni1
->vni
== zl3vni2
->vni
);
3364 * Callback to allocate L3 VNI hash entry.
3366 static void *zl3vni_alloc(void *p
)
3368 zebra_l3vni_t
*zl3vni
= NULL
;
3369 const zebra_l3vni_t
*tmp_l3vni
= p
;
3371 zl3vni
= XCALLOC(MTYPE_ZL3VNI
, sizeof(zebra_l3vni_t
));
3372 zl3vni
->vni
= tmp_l3vni
->vni
;
3373 return ((void *)zl3vni
);
3377 * Look up L3 VNI hash entry.
3379 static zebra_l3vni_t
*zl3vni_lookup(vni_t vni
)
3381 struct zebra_ns
*zns
;
3382 zebra_l3vni_t tmp_l3vni
;
3383 zebra_l3vni_t
*zl3vni
= NULL
;
3385 zns
= zebra_ns_lookup(NS_DEFAULT
);
3387 memset(&tmp_l3vni
, 0, sizeof(zebra_l3vni_t
));
3388 tmp_l3vni
.vni
= vni
;
3389 zl3vni
= hash_lookup(zns
->l3vni_table
, &tmp_l3vni
);
3395 * Add L3 VNI hash entry.
3397 static zebra_l3vni_t
*zl3vni_add(vni_t vni
, vrf_id_t vrf_id
)
3399 zebra_l3vni_t tmp_zl3vni
;
3400 struct zebra_ns
*zns
= NULL
;
3401 zebra_l3vni_t
*zl3vni
= NULL
;
3403 zns
= zebra_ns_lookup(NS_DEFAULT
);
3406 memset(&tmp_zl3vni
, 0, sizeof(zebra_l3vni_t
));
3407 tmp_zl3vni
.vni
= vni
;
3409 zl3vni
= hash_get(zns
->l3vni_table
, &tmp_zl3vni
, zl3vni_alloc
);
3412 zl3vni
->vrf_id
= vrf_id
;
3413 zl3vni
->svi_if
= NULL
;
3414 zl3vni
->vxlan_if
= NULL
;
3415 zl3vni
->l2vnis
= list_new();
3416 zl3vni
->l2vnis
->cmp
= (int (*)(void *, void *))vni_hash_cmp
;
3418 /* Create hash table for remote RMAC */
3419 zl3vni
->rmac_table
=
3420 hash_create(mac_hash_keymake
, mac_cmp
,
3421 "Zebra L3-VNI RMAC-Table");
3423 /* Create hash table for neighbors */
3424 zl3vni
->nh_table
= hash_create(neigh_hash_keymake
, neigh_cmp
,
3425 "Zebra L3-VNI next-hop table");
3431 * Delete L3 VNI hash entry.
3433 static int zl3vni_del(zebra_l3vni_t
*zl3vni
)
3435 struct zebra_ns
*zns
;
3436 zebra_l3vni_t
*tmp_zl3vni
;
3438 zns
= zebra_ns_lookup(NS_DEFAULT
);
3441 /* free the list of l2vnis */
3442 list_delete_and_null(&zl3vni
->l2vnis
);
3443 zl3vni
->l2vnis
= NULL
;
3445 /* Free the rmac table */
3446 hash_free(zl3vni
->rmac_table
);
3447 zl3vni
->rmac_table
= NULL
;
3449 /* Free the nh table */
3450 hash_free(zl3vni
->nh_table
);
3451 zl3vni
->nh_table
= NULL
;
3453 /* Free the VNI hash entry and allocated memory. */
3454 tmp_zl3vni
= hash_release(zns
->l3vni_table
, zl3vni
);
3456 XFREE(MTYPE_ZL3VNI
, tmp_zl3vni
);
3461 static int is_vni_l3(vni_t vni
)
3463 zebra_l3vni_t
*zl3vni
= NULL
;
3465 zl3vni
= zl3vni_lookup(vni
);
3471 static struct interface
*zl3vni_map_to_vxlan_if(zebra_l3vni_t
*zl3vni
)
3473 struct zebra_ns
*zns
= NULL
;
3474 struct route_node
*rn
= NULL
;
3475 struct interface
*ifp
= NULL
;
3477 /* loop through all vxlan-interface */
3478 zns
= zebra_ns_lookup(NS_DEFAULT
);
3479 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
3481 struct zebra_if
*zif
= NULL
;
3482 struct zebra_l2info_vxlan
*vxl
= NULL
;
3484 ifp
= (struct interface
*)rn
->info
;
3489 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
3492 vxl
= &zif
->l2info
.vxl
;
3493 if (vxl
->vni
== zl3vni
->vni
) {
3494 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
3502 static struct interface
*zl3vni_map_to_svi_if(zebra_l3vni_t
*zl3vni
)
3504 struct zebra_if
*zif
= NULL
; /* zebra_if for vxlan_if */
3505 struct zebra_l2info_vxlan
*vxl
= NULL
; /* l2 info for vxlan_if */
3507 if (!zl3vni
->vxlan_if
)
3510 zif
= zl3vni
->vxlan_if
->info
;
3514 vxl
= &zif
->l2info
.vxl
;
3516 return zvni_map_to_svi(vxl
->access_vlan
, zif
->brslave_info
.br_if
);
3519 static zebra_l3vni_t
*zl3vni_from_vrf(vrf_id_t vrf_id
)
3521 struct zebra_vrf
*zvrf
= NULL
;
3523 zvrf
= zebra_vrf_lookup_by_id(vrf_id
);
3527 return zl3vni_lookup(zvrf
->l3vni
);
3531 * Map SVI and associated bridge to a VNI. This is invoked upon getting
3532 * neighbor notifications, to see if they are of interest.
3534 static zebra_l3vni_t
*zl3vni_from_svi(struct interface
*ifp
,
3535 struct interface
*br_if
)
3539 u_char bridge_vlan_aware
= 0;
3540 zebra_l3vni_t
*zl3vni
= NULL
;
3541 struct zebra_ns
*zns
= NULL
;
3542 struct route_node
*rn
= NULL
;
3543 struct zebra_if
*zif
= NULL
;
3544 struct interface
*tmp_if
= NULL
;
3545 struct zebra_l2info_bridge
*br
= NULL
;
3546 struct zebra_l2info_vxlan
*vxl
= NULL
;
3551 /* Make sure the linked interface is a bridge. */
3552 if (!IS_ZEBRA_IF_BRIDGE(br_if
))
3555 /* Determine if bridge is VLAN-aware or not */
3558 br
= &zif
->l2info
.br
;
3559 bridge_vlan_aware
= br
->vlan_aware
;
3560 if (bridge_vlan_aware
) {
3561 struct zebra_l2info_vlan
*vl
;
3563 if (!IS_ZEBRA_IF_VLAN(ifp
))
3568 vl
= &zif
->l2info
.vl
;
3572 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
3573 /* TODO: Optimize with a hash. */
3574 zns
= zebra_ns_lookup(NS_DEFAULT
);
3575 for (rn
= route_top(zns
->if_table
); rn
; rn
= route_next(rn
)) {
3576 tmp_if
= (struct interface
*)rn
->info
;
3580 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
3582 if (!if_is_operative(tmp_if
))
3584 vxl
= &zif
->l2info
.vxl
;
3586 if (zif
->brslave_info
.br_if
!= br_if
)
3589 if (!bridge_vlan_aware
|| vxl
->access_vlan
== vid
) {
3598 zl3vni
= zl3vni_lookup(vxl
->vni
);
3603 * Inform BGP about l3-vni.
3605 static int zl3vni_send_add_to_client(zebra_l3vni_t
*zl3vni
)
3607 struct stream
*s
= NULL
;
3608 struct zserv
*client
= NULL
;
3609 struct ethaddr rmac
;
3610 char buf
[ETHER_ADDR_STRLEN
];
3612 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
3613 /* BGP may not be running. */
3618 memset(&rmac
, 0, sizeof(struct ethaddr
));
3619 zl3vni_get_rmac(zl3vni
, &rmac
);
3624 zclient_create_header(s
, ZEBRA_L3VNI_ADD
,
3625 zl3vni_vrf_id(zl3vni
));
3626 stream_putl(s
, zl3vni
->vni
);
3627 stream_put(s
, &rmac
, sizeof(struct ethaddr
));
3628 stream_put_in_addr(s
, &zl3vni
->local_vtep_ip
);
3630 /* Write packet size. */
3631 stream_putw_at(s
, 0, stream_get_endp(s
));
3633 if (IS_ZEBRA_DEBUG_VXLAN
)
3634 zlog_debug("Send L3_VNI_ADD %u VRF %s RMAC %s local-ip %s to %s",
3635 zl3vni
->vni
, vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
3636 prefix_mac2str(&rmac
, buf
, sizeof(buf
)),
3637 inet_ntoa(zl3vni
->local_vtep_ip
),
3638 zebra_route_string(client
->proto
));
3640 client
->l3vniadd_cnt
++;
3641 return zebra_server_send_message(client
);
3645 * Inform BGP about local l3-VNI deletion.
3647 static int zl3vni_send_del_to_client(zebra_l3vni_t
*zl3vni
)
3649 struct stream
*s
= NULL
;
3650 struct zserv
*client
= NULL
;
3652 client
= zebra_find_client(ZEBRA_ROUTE_BGP
, 0);
3653 /* BGP may not be running. */
3660 zclient_create_header(s
, ZEBRA_L3VNI_DEL
,
3661 zl3vni_vrf_id(zl3vni
));
3662 stream_putl(s
, zl3vni
->vni
);
3664 /* Write packet size. */
3665 stream_putw_at(s
, 0, stream_get_endp(s
));
3667 if (IS_ZEBRA_DEBUG_VXLAN
)
3668 zlog_debug("Send L3_VNI_DEL %u VRF %s to %s",
3670 vrf_id_to_name(zl3vni_vrf_id(zl3vni
)),
3671 zebra_route_string(client
->proto
));
3673 client
->l3vnidel_cnt
++;
3674 return zebra_server_send_message(client
);
3677 static void zebra_vxlan_process_l3vni_oper_up(zebra_l3vni_t
*zl3vni
)
3679 if (IS_ZEBRA_DEBUG_VXLAN
)
3680 zlog_debug("L3-VNI %u is UP - send add to BGP",
3683 /* send l3vni add to BGP */
3684 zl3vni_send_add_to_client(zl3vni
);
3687 static void zebra_vxlan_process_l3vni_oper_down(zebra_l3vni_t
*zl3vni
)
3689 if (IS_ZEBRA_DEBUG_VXLAN
)
3690 zlog_debug("L3-VNI %u is Down - Send del to BGP",
3693 /* send l3-vni del to BGP*/
3694 zl3vni_send_del_to_client(zl3vni
);
3697 static void zvni_add_to_l3vni_list(struct hash_backet
*backet
,
3700 zebra_vni_t
*zvni
= (zebra_vni_t
*) backet
->data
;
3701 zebra_l3vni_t
*zl3vni
= (zebra_l3vni_t
*) ctxt
;
3703 if (zvni
->vrf_id
== zl3vni_vrf_id(zl3vni
))
3704 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
3708 * handle transition of vni from l2 to l3 and vice versa
3710 static int zebra_vxlan_handle_vni_transition(struct zebra_vrf
*zvrf
,
3713 zebra_vni_t
*zvni
= NULL
;
3715 /* There is a possibility that VNI notification was already received
3716 * from kernel and we programmed it as L2-VNI
3717 * In such a case we need to delete this L2-VNI first, so
3718 * that it can be reprogrammed as L3-VNI in the system. It is also
3719 * possible that the vrf-vni mapping is removed from FRR while the vxlan
3720 * interface is still present in kernel. In this case to keep it
3721 * symmetric, we will delete the l3-vni and reprogram it as l2-vni
3724 /* Locate hash entry */
3725 zvni
= zvni_lookup(vni
);
3729 if (IS_ZEBRA_DEBUG_VXLAN
)
3730 zlog_debug("Del L2-VNI %u - transition to L3-VNI",
3733 /* Delete VNI from BGP. */
3734 zvni_send_del_to_client(zvni
->vni
);
3736 /* Free up all neighbors and MAC, if any. */
3737 zvni_neigh_del_all(zvni
, 0, 0, DEL_ALL_NEIGH
);
3738 zvni_mac_del_all(zvni
, 0, 0, DEL_ALL_MAC
);
3740 /* Free up all remote VTEPs, if any. */
3741 zvni_vtep_del_all(zvni
, 0);
3743 /* Delete the hash entry. */
3744 if (zvni_del(zvni
)) {
3745 zlog_err("Failed to del VNI hash %p, VNI %u",
3750 /* TODO_MITESH: This needs to be thought through. We don't have
3751 * enough information at this point to reprogram the vni as
3752 * l2-vni. One way is to store the required info in l3-vni and
3753 * used it solely for this purpose
3760 /* delete and uninstall rmac hash entry */
3761 static void zl3vni_del_rmac_hash_entry(struct hash_backet
*backet
,
3764 zebra_mac_t
*zrmac
= NULL
;
3765 zebra_l3vni_t
*zl3vni
= NULL
;
3767 zrmac
= (zebra_mac_t
*)backet
->data
;
3768 zl3vni
= (zebra_l3vni_t
*)ctx
;
3769 zl3vni_rmac_uninstall(zl3vni
, zrmac
);
3770 zl3vni_rmac_del(zl3vni
, zrmac
);
3773 /* delete and uninstall nh hash entry */
3774 static void zl3vni_del_nh_hash_entry(struct hash_backet
*backet
,
3777 zebra_neigh_t
*n
= NULL
;
3778 zebra_l3vni_t
*zl3vni
= NULL
;
3780 n
= (zebra_neigh_t
*)backet
->data
;
3781 zl3vni
= (zebra_l3vni_t
*)ctx
;
3782 zl3vni_nh_uninstall(zl3vni
, n
);
3783 zl3vni_nh_del(zl3vni
, n
);
3786 static int ip_prefix_send_to_client(vrf_id_t vrf_id
,
3790 struct zserv
*client
= NULL
;
3791 struct stream
*s
= NULL
;
3792 char buf
[PREFIX_STRLEN
];
3794 client
= zebra_find_client(ZEBRA_ROUTE_BGP
);
3795 /* BGP may not be running. */
3802 zserv_create_header(s
, cmd
, vrf_id
);
3803 stream_put(s
, p
, sizeof(struct prefix
));
3805 /* Write packet size. */
3806 stream_putw_at(s
, 0, stream_get_endp(s
));
3808 if (IS_ZEBRA_DEBUG_VXLAN
)
3810 "Send ip prefix %s %s on vrf %s",
3811 prefix2str(p
, buf
, sizeof(buf
)),
3812 (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
) ? "ADD" : "DEL",
3813 vrf_id_to_name(vrf_id
));
3815 if (cmd
== ZEBRA_IP_PREFIX_ROUTE_ADD
)
3816 client
->prefixadd_cnt
++;
3818 client
->prefixdel_cnt
++;
3820 return zebra_server_send_message(client
);
3823 /* re-add remote rmac if needed */
3824 static int zebra_vxlan_readd_remote_rmac(zebra_l3vni_t
*zl3vni
,
3825 struct ethaddr
*rmac
)
3827 char buf
[ETHER_ADDR_STRLEN
];
3828 zebra_mac_t
*zrmac
= NULL
;
3830 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3834 if (IS_ZEBRA_DEBUG_VXLAN
)
3835 zlog_debug("Del remote RMAC %s L3VNI %u - readd",
3836 prefix_mac2str(rmac
, buf
, sizeof(buf
)),
3839 zl3vni_rmac_install(zl3vni
, zrmac
);
3843 /* Public functions */
3845 /* handle evpn route in vrf table */
3846 void zebra_vxlan_evpn_vrf_route_add(vrf_id_t vrf_id
,
3847 struct ethaddr
*rmac
,
3848 struct ipaddr
*vtep_ip
,
3849 struct prefix
*host_prefix
)
3851 zebra_l3vni_t
*zl3vni
= NULL
;
3853 zl3vni
= zl3vni_from_vrf(vrf_id
);
3854 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
3857 /* add the next hop neighbor */
3858 zl3vni_remote_nh_add(zl3vni
, vtep_ip
, rmac
, host_prefix
);
3861 zl3vni_remote_rmac_add(zl3vni
, rmac
, vtep_ip
, host_prefix
);
3864 /* handle evpn vrf route delete */
3865 void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id
,
3866 struct ethaddr
*rmac
,
3867 struct ipaddr
*vtep_ip
,
3868 struct prefix
*host_prefix
)
3870 zebra_l3vni_t
*zl3vni
= NULL
;
3872 zl3vni
= zl3vni_from_vrf(vrf_id
);
3876 /* delete the next hop entry */
3877 zl3vni_remote_nh_del(zl3vni
, vtep_ip
, host_prefix
);
3879 /* delete the rmac entry */
3880 zl3vni_remote_rmac_del(zl3vni
, rmac
, host_prefix
);
3883 void zebra_vxlan_print_specific_rmac_l3vni(struct vty
*vty
,
3885 struct ethaddr
*rmac
,
3888 zebra_l3vni_t
*zl3vni
= NULL
;
3889 zebra_mac_t
*zrmac
= NULL
;
3890 json_object
*json
= NULL
;
3892 if (!is_evpn_enabled()) {
3894 vty_out(vty
, "{}\n");
3899 json
= json_object_new_object();
3901 zl3vni
= zl3vni_lookup(l3vni
);
3904 vty_out(vty
, "{}\n");
3906 vty_out(vty
, "%% L3-VNI %u doesnt exist\n",
3911 zrmac
= zl3vni_rmac_lookup(zl3vni
, rmac
);
3914 vty_out(vty
, "{}\n");
3917 "%% Requested RMAC doesnt exist in L3-VNI %u",
3922 zl3vni_print_rmac(zrmac
, vty
, json
);
3925 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3926 json
, JSON_C_TO_STRING_PRETTY
));
3927 json_object_free(json
);
3931 void zebra_vxlan_print_rmacs_l3vni(struct vty
*vty
,
3935 zebra_l3vni_t
*zl3vni
;
3936 u_int32_t num_rmacs
;
3937 struct rmac_walk_ctx wctx
;
3938 json_object
*json
= NULL
;
3940 if (!is_evpn_enabled())
3943 zl3vni
= zl3vni_lookup(l3vni
);
3946 vty_out(vty
, "{}\n");
3948 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
3951 num_rmacs
= hashcount(zl3vni
->rmac_table
);
3956 json
= json_object_new_object();
3958 memset(&wctx
, 0, sizeof(struct rmac_walk_ctx
));
3963 "Number of Remote RMACs known for this VNI: %u\n",
3965 vty_out(vty
, "%-17s %-21s\n", "MAC", "Remote VTEP");
3967 json_object_int_add(json
, "numRmacs", num_rmacs
);
3969 hash_iterate(zl3vni
->rmac_table
, zl3vni_print_rmac_hash
, &wctx
);
3972 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
3973 json
, JSON_C_TO_STRING_PRETTY
));
3974 json_object_free(json
);
3978 void zebra_vxlan_print_rmacs_all_l3vni(struct vty
*vty
,
3981 struct zebra_ns
*zns
= NULL
;
3982 json_object
*json
= NULL
;
3985 if (!is_evpn_enabled()) {
3987 vty_out(vty
, "{}\n");
3991 zns
= zebra_ns_lookup(NS_DEFAULT
);
3994 vty_out(vty
, "{}\n");
3999 json
= json_object_new_object();
4003 hash_iterate(zns
->l3vni_table
,
4004 (void (*)(struct hash_backet
*,
4005 void *))zl3vni_print_rmac_hash_all_vni
,
4009 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4010 json
, JSON_C_TO_STRING_PRETTY
));
4011 json_object_free(json
);
4015 void zebra_vxlan_print_specific_nh_l3vni(struct vty
*vty
,
4020 zebra_l3vni_t
*zl3vni
= NULL
;
4021 zebra_neigh_t
*n
= NULL
;
4022 json_object
*json
= NULL
;
4024 if (!is_evpn_enabled()) {
4026 vty_out(vty
, "{}\n");
4031 json
= json_object_new_object();
4033 zl3vni
= zl3vni_lookup(l3vni
);
4036 vty_out(vty
, "{}\n");
4038 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
4042 n
= zl3vni_nh_lookup(zl3vni
, ip
);
4045 vty_out(vty
, "{}\n");
4048 "%% Requested next-hop not present for L3-VNI %u",
4053 zl3vni_print_nh(n
, vty
, json
);
4056 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4057 json
, JSON_C_TO_STRING_PRETTY
));
4058 json_object_free(json
);
4062 void zebra_vxlan_print_nh_l3vni(struct vty
*vty
,
4067 struct nh_walk_ctx wctx
;
4068 json_object
*json
= NULL
;
4069 zebra_l3vni_t
*zl3vni
= NULL
;
4071 if (!is_evpn_enabled())
4074 zl3vni
= zl3vni_lookup(l3vni
);
4077 vty_out(vty
, "{}\n");
4079 vty_out(vty
, "%% L3-VNI %u does not exist\n", l3vni
);
4083 num_nh
= hashcount(zl3vni
->nh_table
);
4088 json
= json_object_new_object();
4094 "Number of NH Neighbors known for this VNI: %u\n",
4096 vty_out(vty
, "%-15s %-17s\n", "IP", "RMAC");
4098 json_object_int_add(json
, "numNextHops", num_nh
);
4100 hash_iterate(zl3vni
->nh_table
, zl3vni_print_nh_hash
, &wctx
);
4103 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4104 json
, JSON_C_TO_STRING_PRETTY
));
4105 json_object_free(json
);
4109 void zebra_vxlan_print_nh_all_l3vni(struct vty
*vty
,
4112 struct zebra_ns
*zns
= NULL
;
4113 json_object
*json
= NULL
;
4116 if (!is_evpn_enabled()) {
4118 vty_out(vty
, "{}\n");
4122 zns
= zebra_ns_lookup(NS_DEFAULT
);
4127 json
= json_object_new_object();
4131 hash_iterate(zns
->l3vni_table
,
4132 (void (*)(struct hash_backet
*,
4133 void *))zl3vni_print_nh_hash_all_vni
,
4137 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4138 json
, JSON_C_TO_STRING_PRETTY
));
4139 json_object_free(json
);
4145 * Display L3 VNI information (VTY command handler).
4147 void zebra_vxlan_print_l3vni(struct vty
*vty
, vni_t vni
, u_char use_json
)
4150 json_object
*json
= NULL
;
4151 zebra_l3vni_t
*zl3vni
= NULL
;
4153 if (!is_evpn_enabled()) {
4155 vty_out(vty
, "{}\n");
4159 zl3vni
= zl3vni_lookup(vni
);
4162 vty_out(vty
, "{}\n");
4164 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4169 json
= json_object_new_object();
4173 zl3vni_print(zl3vni
, (void *)args
);
4176 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4177 json
, JSON_C_TO_STRING_PRETTY
));
4178 json_object_free(json
);
4182 void zebra_vxlan_print_vrf_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4183 json_object
*json_vrfs
)
4185 char buf
[ETHER_ADDR_STRLEN
];
4186 zebra_l3vni_t
*zl3vni
= NULL
;
4188 zl3vni
= zl3vni_lookup(zvrf
->l3vni
);
4193 vty_out(vty
, "%-37s %-10u %-20s %-20s %-5s %-18s\n",
4196 zl3vni_vxlan_if_name(zl3vni
),
4197 zl3vni_svi_if_name(zl3vni
),
4198 zl3vni_state2str(zl3vni
),
4199 zl3vni_rmac2str(zl3vni
, buf
, sizeof(buf
)));
4201 json_object
*json_vrf
= NULL
;
4202 json_vrf
= json_object_new_object();
4203 json_object_string_add(json_vrf
, "vrf",
4205 json_object_int_add(json_vrf
, "vni", zl3vni
->vni
);
4206 json_object_string_add(json_vrf
, "vxlanIntf",
4207 zl3vni_vxlan_if_name(zl3vni
));
4208 json_object_string_add(json_vrf
, "sviIntf",
4209 zl3vni_svi_if_name(zl3vni
));
4210 json_object_string_add(json_vrf
, "state",
4211 zl3vni_state2str(zl3vni
));
4212 json_object_string_add(json_vrf
, "routerMac",
4213 zl3vni_rmac2str(zl3vni
, buf
,
4215 json_object_array_add(json_vrfs
, json_vrf
);
4220 * Display Neighbors for a VNI (VTY command handler).
4222 void zebra_vxlan_print_neigh_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4223 vni_t vni
, u_char use_json
)
4226 u_int32_t num_neigh
;
4227 struct neigh_walk_ctx wctx
;
4228 json_object
*json
= NULL
;
4230 if (!is_evpn_enabled())
4232 zvni
= zvni_lookup(vni
);
4235 vty_out(vty
, "{}\n");
4237 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4240 num_neigh
= hashcount(zvni
->neigh_table
);
4245 json
= json_object_new_object();
4247 /* Since we have IPv6 addresses to deal with which can vary widely in
4248 * size, we try to be a bit more elegant in display by first computing
4249 * the maximum width.
4251 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
4254 wctx
.addr_width
= 15;
4256 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
4260 "Number of ARPs (local and remote) known for this VNI: %u\n",
4262 vty_out(vty
, "%*s %-6s %-17s %-21s\n", -wctx
.addr_width
, "IP",
4263 "Type", "MAC", "Remote VTEP");
4265 json_object_int_add(json
, "numArpNd", num_neigh
);
4267 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
4269 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4270 json
, JSON_C_TO_STRING_PRETTY
));
4271 json_object_free(json
);
4276 * Display neighbors across all VNIs (VTY command handler).
4278 void zebra_vxlan_print_neigh_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4281 json_object
*json
= NULL
;
4284 if (!is_evpn_enabled())
4288 json
= json_object_new_object();
4292 hash_iterate(zvrf
->vni_table
,
4293 (void (*)(struct hash_backet
*,
4294 void *))zvni_print_neigh_hash_all_vni
,
4297 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4298 json
, JSON_C_TO_STRING_PRETTY
));
4299 json_object_free(json
);
4304 * Display specific neighbor for a VNI, if present (VTY command handler).
4306 void zebra_vxlan_print_specific_neigh_vni(struct vty
*vty
,
4307 struct zebra_vrf
*zvrf
, vni_t vni
,
4308 struct ipaddr
*ip
, u_char use_json
)
4312 json_object
*json
= NULL
;
4314 if (!is_evpn_enabled())
4316 zvni
= zvni_lookup(vni
);
4319 vty_out(vty
, "{}\n");
4321 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4324 n
= zvni_neigh_lookup(zvni
, ip
);
4328 "%% Requested neighbor does not exist in VNI %u\n",
4333 json
= json_object_new_object();
4335 zvni_print_neigh(n
, vty
, json
);
4338 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4339 json
, JSON_C_TO_STRING_PRETTY
));
4340 json_object_free(json
);
4345 * Display neighbors for a VNI from specific VTEP (VTY command handler).
4346 * By definition, these are remote neighbors.
4348 void zebra_vxlan_print_neigh_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4349 vni_t vni
, struct in_addr vtep_ip
,
4353 u_int32_t num_neigh
;
4354 struct neigh_walk_ctx wctx
;
4355 json_object
*json
= NULL
;
4357 if (!is_evpn_enabled())
4359 zvni
= zvni_lookup(vni
);
4362 vty_out(vty
, "{}\n");
4364 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4367 num_neigh
= hashcount(zvni
->neigh_table
);
4371 memset(&wctx
, 0, sizeof(struct neigh_walk_ctx
));
4374 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
4375 wctx
.r_vtep_ip
= vtep_ip
;
4377 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
4380 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4381 json
, JSON_C_TO_STRING_PRETTY
));
4382 json_object_free(json
);
4387 * Display MACs for a VNI (VTY command handler).
4389 void zebra_vxlan_print_macs_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4390 vni_t vni
, u_char use_json
)
4394 struct mac_walk_ctx wctx
;
4395 json_object
*json
= NULL
;
4396 json_object
*json_mac
= NULL
;
4398 if (!is_evpn_enabled())
4400 zvni
= zvni_lookup(vni
);
4403 vty_out(vty
, "{}\n");
4405 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4408 num_macs
= num_valid_macs(zvni
);
4413 json
= json_object_new_object();
4414 json_mac
= json_object_new_object();
4417 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4420 wctx
.json
= json_mac
;
4424 "Number of MACs (local and remote) known for this VNI: %u\n",
4426 vty_out(vty
, "%-17s %-6s %-21s %-5s\n", "MAC", "Type",
4427 "Intf/Remote VTEP", "VLAN");
4429 json_object_int_add(json
, "numMacs", num_macs
);
4431 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
4434 json_object_object_add(json
, "macs", json_mac
);
4435 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4436 json
, JSON_C_TO_STRING_PRETTY
));
4437 json_object_free(json
);
4442 * Display MACs for all VNIs (VTY command handler).
4444 void zebra_vxlan_print_macs_all_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4447 struct mac_walk_ctx wctx
;
4448 json_object
*json
= NULL
;
4450 if (!is_evpn_enabled()) {
4452 vty_out(vty
, "{}\n");
4456 json
= json_object_new_object();
4458 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4461 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
4464 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4465 json
, JSON_C_TO_STRING_PRETTY
));
4466 json_object_free(json
);
4471 * Display MACs for all VNIs (VTY command handler).
4473 void zebra_vxlan_print_macs_all_vni_vtep(struct vty
*vty
,
4474 struct zebra_vrf
*zvrf
,
4475 struct in_addr vtep_ip
,
4478 struct mac_walk_ctx wctx
;
4479 json_object
*json
= NULL
;
4481 if (!is_evpn_enabled())
4485 json
= json_object_new_object();
4487 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4489 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
4490 wctx
.r_vtep_ip
= vtep_ip
;
4492 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
4495 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4496 json
, JSON_C_TO_STRING_PRETTY
));
4497 json_object_free(json
);
4502 * Display specific MAC for a VNI, if present (VTY command handler).
4504 void zebra_vxlan_print_specific_mac_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4505 vni_t vni
, struct ethaddr
*macaddr
)
4510 if (!is_evpn_enabled())
4512 zvni
= zvni_lookup(vni
);
4514 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4517 mac
= zvni_mac_lookup(zvni
, macaddr
);
4519 vty_out(vty
, "%% Requested MAC does not exist in VNI %u\n",
4524 zvni_print_mac(mac
, vty
);
4528 * Display MACs for a VNI from specific VTEP (VTY command handler).
4530 void zebra_vxlan_print_macs_vni_vtep(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4531 vni_t vni
, struct in_addr vtep_ip
,
4536 struct mac_walk_ctx wctx
;
4537 json_object
*json
= NULL
;
4538 json_object
*json_mac
= NULL
;
4540 if (!is_evpn_enabled())
4542 zvni
= zvni_lookup(vni
);
4545 vty_out(vty
, "{}\n");
4547 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4550 num_macs
= num_valid_macs(zvni
);
4555 json
= json_object_new_object();
4556 json_mac
= json_object_new_object();
4559 memset(&wctx
, 0, sizeof(struct mac_walk_ctx
));
4562 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
4563 wctx
.r_vtep_ip
= vtep_ip
;
4564 wctx
.json
= json_mac
;
4565 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
4568 json_object_int_add(json
, "numMacs", wctx
.count
);
4570 json_object_object_add(json
, "macs", json_mac
);
4571 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4572 json
, JSON_C_TO_STRING_PRETTY
));
4573 json_object_free(json
);
4579 * Display VNI information (VTY command handler).
4581 void zebra_vxlan_print_vni(struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
,
4584 json_object
*json
= NULL
;
4587 if (!is_evpn_enabled())
4591 json
= json_object_new_object();
4595 if (is_vni_l3(vni
)) {
4596 zebra_l3vni_t
*zl3vni
= NULL
;
4598 zl3vni
= zl3vni_lookup(vni
);
4601 vty_out(vty
, "{}\n");
4603 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4607 zl3vni_print(zl3vni
, (void *)args
);
4611 zvni
= zvni_lookup(vni
);
4614 vty_out(vty
, "{}\n");
4616 vty_out(vty
, "%% VNI %u does not exist\n", vni
);
4620 zvni_print(zvni
, (void *)args
);
4624 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4625 json
, JSON_C_TO_STRING_PRETTY
));
4626 json_object_free(json
);
4630 /* Display all global details for EVPN */
4631 void zebra_vxlan_print_evpn(struct vty
*vty
, u_char uj
)
4635 json_object
*json
= NULL
;
4636 struct zebra_ns
*zns
= NULL
;
4637 struct zebra_vrf
*zvrf
= NULL
;
4639 if (!is_evpn_enabled())
4642 zns
= zebra_ns_lookup(NS_DEFAULT
);
4646 zvrf
= vrf_info_lookup(VRF_DEFAULT
);
4650 num_l3vnis
= hashcount(zns
->l3vni_table
);
4651 num_l2vnis
= hashcount(zvrf
->vni_table
);
4654 json
= json_object_new_object();
4655 json_object_string_add(json
, "advertiseGatewayMacip",
4656 zvrf
->advertise_gw_macip
? "Yes" : "No");
4657 json_object_int_add(json
, "numL2Vnis", num_l2vnis
);
4658 json_object_int_add(json
, "numL3Vnis", num_l3vnis
);
4660 vty_out(vty
, "L2 VNIs: %u\n", num_l2vnis
);
4661 vty_out(vty
, "L3 VNIs: %u\n", num_l3vnis
);
4662 vty_out(vty
, "Advertise gateway mac-ip: %s\n",
4663 zvrf
->advertise_gw_macip
? "Yes" : "No");
4667 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4668 json
, JSON_C_TO_STRING_PRETTY
));
4669 json_object_free(json
);
4674 * Display VNI hash table (VTY command handler).
4676 void zebra_vxlan_print_vnis(struct vty
*vty
, struct zebra_vrf
*zvrf
,
4679 json_object
*json
= NULL
;
4680 struct zebra_ns
*zns
= NULL
;
4683 if (!is_evpn_enabled())
4686 zns
= zebra_ns_lookup(NS_DEFAULT
);
4692 json
= json_object_new_object();
4695 "%-10s %-4s %-21s %-8s %-8s %-15s %-37s\n",
4696 "VNI", "Type", "VxLAN IF", "# MACs",
4697 "# ARPs", "# Remote VTEPs", "Tenant VRF");
4702 /* Display all L2-VNIs */
4703 hash_iterate(zvrf
->vni_table
,
4704 (void (*)(struct hash_backet
*, void *))zvni_print_hash
,
4707 /* Display all L3-VNIs */
4708 hash_iterate(zns
->l3vni_table
,
4709 (void (*)(struct hash_backet
*, void *))zl3vni_print_hash
,
4713 vty_out(vty
, "%s\n", json_object_to_json_string_ext(
4714 json
, JSON_C_TO_STRING_PRETTY
));
4715 json_object_free(json
);
4720 * Handle neighbor delete (on a VLAN device / L3 interface) from the
4721 * kernel. This may result in either the neighbor getting deleted from
4722 * our database or being re-added to the kernel (if it is a valid
4725 int zebra_vxlan_local_neigh_del(struct interface
*ifp
,
4726 struct interface
*link_if
, struct ipaddr
*ip
)
4728 char buf
[INET6_ADDRSTRLEN
];
4729 char buf2
[ETHER_ADDR_STRLEN
];
4730 zebra_neigh_t
*n
= NULL
;
4731 zebra_vni_t
*zvni
= NULL
;
4732 zebra_mac_t
*zmac
= NULL
;
4733 zebra_l3vni_t
*zl3vni
= NULL
;
4735 /* check if this is a remote neigh entry corresponding to remote
4738 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4740 return zl3vni_local_nh_del(zl3vni
, ip
);
4742 /* We are only interested in neighbors on an SVI that resides on top
4743 * of a VxLAN bridge.
4745 zvni
= zvni_from_svi(ifp
, link_if
);
4749 if (!zvni
->vxlan_if
) {
4751 "VNI %u hash %p doesn't have intf upon local neighbor DEL",
4756 if (IS_ZEBRA_DEBUG_VXLAN
)
4757 zlog_debug("Del neighbor %s intf %s(%u) -> L2-VNI %u",
4758 ipaddr2str(ip
, buf
, sizeof(buf
)),
4759 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
4761 /* If entry doesn't exist, nothing to do. */
4762 n
= zvni_neigh_lookup(zvni
, ip
);
4766 zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
4768 if (IS_ZEBRA_DEBUG_VXLAN
)
4770 "Trying to del a neigh %s without a mac %s on VNI %u",
4771 ipaddr2str(ip
, buf
, sizeof(buf
)),
4772 prefix_mac2str(&n
->emac
, buf2
, sizeof(buf2
)),
4778 /* If it is a remote entry, the kernel has aged this out or someone has
4779 * deleted it, it needs to be re-installed as Quagga is the owner.
4781 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)) {
4782 zvni_neigh_install(zvni
, n
);
4786 /* Remove neighbor from BGP. */
4787 if (IS_ZEBRA_NEIGH_ACTIVE(n
))
4788 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
, &n
->emac
,
4791 /* Delete this neighbor entry. */
4792 zvni_neigh_del(zvni
, n
);
4794 /* see if the AUTO mac needs to be deleted */
4795 if (CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
)
4796 && !listcount(zmac
->neigh_list
))
4797 zvni_mac_del(zvni
, zmac
);
4803 * Handle neighbor add or update (on a VLAN device / L3 interface)
4806 int zebra_vxlan_local_neigh_add_update(struct interface
*ifp
,
4807 struct interface
*link_if
,
4809 struct ethaddr
*macaddr
, u_int16_t state
,
4812 char buf
[ETHER_ADDR_STRLEN
];
4813 char buf2
[INET6_ADDRSTRLEN
];
4814 zebra_vni_t
*zvni
= NULL
;
4815 zebra_neigh_t
*n
= NULL
;
4816 zebra_mac_t
*zmac
= NULL
, *old_zmac
= NULL
;
4817 zebra_l3vni_t
*zl3vni
= NULL
;
4819 /* check if this is a remote neigh entry corresponding to remote
4822 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
4824 return zl3vni_local_nh_add_update(zl3vni
, ip
, state
);
4826 /* We are only interested in neighbors on an SVI that resides on top
4827 * of a VxLAN bridge.
4829 zvni
= zvni_from_svi(ifp
, link_if
);
4833 if (IS_ZEBRA_DEBUG_VXLAN
)
4835 "Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x %s-> L2-VNI %u",
4836 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4837 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
4838 ifp
->ifindex
, state
, ext_learned
? "ext-learned " : "",
4841 /* create a dummy MAC if the MAC is not already present */
4842 zmac
= zvni_mac_lookup(zvni
, macaddr
);
4844 if (IS_ZEBRA_DEBUG_VXLAN
)
4846 "AUTO MAC %s created for neigh %s on VNI %u",
4847 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4848 ipaddr2str(ip
, buf2
, sizeof(buf2
)), zvni
->vni
);
4850 zmac
= zvni_mac_add(zvni
, macaddr
);
4852 zlog_warn("Failed to add MAC %s VNI %u",
4853 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4858 memset(&zmac
->fwd_info
, 0, sizeof(zmac
->fwd_info
));
4859 memset(&zmac
->flags
, 0, sizeof(u_int32_t
));
4860 SET_FLAG(zmac
->flags
, ZEBRA_MAC_AUTO
);
4863 /* If same entry already exists, it might be a change or it might be a
4864 * move from remote to local.
4866 n
= zvni_neigh_lookup(zvni
, ip
);
4868 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
)) {
4869 if (memcmp(n
->emac
.octet
, macaddr
->octet
,
4872 /* Update any params and return - client doesn't
4873 * care about a purely local change.
4875 n
->ifindex
= ifp
->ifindex
;
4879 /* If the MAC has changed,
4880 * need to issue a delete first
4881 * as this means a different MACIP route.
4882 * Also, need to do some unlinking/relinking.
4884 zvni_neigh_send_del_to_client(zvni
->vni
, &n
->ip
,
4886 old_zmac
= zvni_mac_lookup(zvni
, &n
->emac
);
4888 listnode_delete(old_zmac
->neigh_list
, n
);
4889 zvni_deref_ip2mac(zvni
, old_zmac
, 0);
4892 /* Set "local" forwarding info. */
4893 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4894 n
->ifindex
= ifp
->ifindex
;
4895 memcpy(&n
->emac
, macaddr
, ETH_ALEN
);
4897 /* Link to new MAC */
4898 listnode_add_sort(zmac
->neigh_list
, n
);
4899 } else if (ext_learned
)
4900 /* The neighbor is remote and that is the notification we got.
4903 /* TODO: Evaluate if we need to do anything here. */
4906 /* Neighbor has moved from remote to local. */
4908 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
4909 n
->r_vtep_ip
.s_addr
= 0;
4910 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4911 n
->ifindex
= ifp
->ifindex
;
4914 n
= zvni_neigh_add(zvni
, ip
, macaddr
);
4917 "Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
4918 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4919 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4920 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
4923 /* Set "local" forwarding info. */
4924 SET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
4925 n
->ifindex
= ifp
->ifindex
;
4928 /* Before we program this in BGP, we need to check if MAC is locally
4930 if (!CHECK_FLAG(zmac
->flags
, ZEBRA_MAC_LOCAL
)) {
4931 if (IS_ZEBRA_DEBUG_VXLAN
)
4933 "Skipping neigh %s add to client as MAC %s is not local on VNI %u",
4934 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4935 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4942 if (IS_ZEBRA_DEBUG_VXLAN
)
4943 zlog_debug("neigh %s (MAC %s) is now ACTIVE on L2-VNI %u",
4944 ipaddr2str(ip
, buf2
, sizeof(buf2
)),
4945 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
4947 ZEBRA_NEIGH_SET_ACTIVE(n
);
4949 return zvni_neigh_send_add_to_client(zvni
->vni
, ip
, macaddr
, n
->flags
);
4954 * Handle message from client to delete a remote MACIP for a VNI.
4956 int zebra_vxlan_remote_macip_del(struct zserv
*client
, u_short length
,
4957 struct zebra_vrf
*zvrf
)
4961 struct ethaddr macaddr
;
4963 struct in_addr vtep_ip
;
4967 u_short l
= 0, ipa_len
;
4968 char buf
[ETHER_ADDR_STRLEN
];
4969 char buf1
[INET6_ADDRSTRLEN
];
4970 struct interface
*ifp
= NULL
;
4971 struct zebra_if
*zif
= NULL
;
4973 memset(&macaddr
, 0, sizeof(struct ethaddr
));
4974 memset(&ip
, 0, sizeof(struct ipaddr
));
4975 memset(&vtep_ip
, 0, sizeof(struct in_addr
));
4979 while (l
< length
) {
4980 /* Obtain each remote MACIP and process. */
4981 /* Message contains VNI, followed by MAC followed by IP (if any)
4982 * followed by remote VTEP IP.
4986 memset(&ip
, 0, sizeof(ip
));
4987 STREAM_GETL(s
, vni
);
4988 STREAM_GET(&macaddr
.octet
, s
, ETH_ALEN
);
4989 STREAM_GETL(s
, ipa_len
);
4991 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
4993 STREAM_GET(&ip
.ip
.addr
, s
, ipa_len
);
4995 l
+= 4 + ETH_ALEN
+ 4 + ipa_len
;
4996 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
4997 l
+= IPV4_MAX_BYTELEN
;
4999 if (IS_ZEBRA_DEBUG_VXLAN
)
5001 "Recv MACIP Del MAC %s IP %s VNI %u Remote VTEP %s from %s",
5002 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
5003 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
,
5005 zebra_route_string(client
->proto
));
5007 /* Locate VNI hash entry - expected to exist. */
5008 zvni
= zvni_lookup(vni
);
5010 if (IS_ZEBRA_DEBUG_VXLAN
)
5012 "Failed to locate VNI hash upon remote MACIP DEL, "
5017 ifp
= zvni
->vxlan_if
;
5020 "VNI %u hash %p doesn't have intf upon remote MACIP DEL",
5026 /* If down or not mapped to a bridge, we're done. */
5027 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5030 /* The remote VTEP specified is normally expected to exist, but
5032 * possible that the peer may delete the VTEP before deleting
5034 * referring to the VTEP, in which case the handler (see
5036 * would have already deleted the MACs.
5038 if (!zvni_vtep_find(zvni
, &vtep_ip
))
5041 mac
= zvni_mac_lookup(zvni
, &macaddr
);
5043 n
= zvni_neigh_lookup(zvni
, &ip
);
5047 "Failed to locate MAC %s for neigh %s VNI %u",
5048 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
5049 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
);
5053 /* If the remote mac or neighbor doesn't exist there is nothing
5055 * to do. Otherwise, uninstall the entry and then remove it.
5060 /* Ignore the delete if this mac is a gateway mac-ip */
5061 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) &&
5062 CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
)) {
5063 zlog_err("%u: Ignore Del for MAC %s neigh %s on VNI %u as it is configured as a default gateway",
5065 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
5066 ipaddr2str(&ip
, buf1
, sizeof(buf1
)),
5071 /* Uninstall remote neighbor or MAC. */
5073 /* When the MAC changes for an IP, it is possible the
5075 * update the new MAC before trying to delete the "old"
5077 * (as these are two different MACIP routes). Do the
5079 * if the MAC matches.
5081 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
5082 && (memcmp(n
->emac
.octet
, macaddr
.octet
,
5085 zvni_neigh_uninstall(zvni
, n
);
5086 zvni_neigh_del(zvni
, n
);
5087 zvni_deref_ip2mac(zvni
, mac
, 1);
5090 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
5091 zvni_process_neigh_on_remote_mac_del(zvni
,
5094 if (list_isempty(mac
->neigh_list
)) {
5095 zvni_mac_uninstall(zvni
, mac
, 0);
5096 zvni_mac_del(zvni
, mac
);
5098 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5108 * Handle message from client to add a remote MACIP for a VNI. This
5109 * could be just the add of a MAC address or the add of a neighbor
5112 int zebra_vxlan_remote_macip_add(struct zserv
*client
, u_short length
,
5113 struct zebra_vrf
*zvrf
)
5117 struct ethaddr macaddr
;
5119 struct in_addr vtep_ip
;
5121 zebra_vtep_t
*zvtep
;
5122 zebra_mac_t
*mac
, *old_mac
;
5124 u_short l
= 0, ipa_len
;
5125 int update_mac
= 0, update_neigh
= 0;
5126 char buf
[ETHER_ADDR_STRLEN
];
5127 char buf1
[INET6_ADDRSTRLEN
];
5130 struct interface
*ifp
= NULL
;
5131 struct zebra_if
*zif
= NULL
;
5133 memset(&macaddr
, 0, sizeof(struct ethaddr
));
5134 memset(&ip
, 0, sizeof(struct ipaddr
));
5135 memset(&vtep_ip
, 0, sizeof(struct in_addr
));
5137 if (!EVPN_ENABLED(zvrf
)) {
5138 zlog_warn("%s: EVPN Not turned on yet we have received a remote_macip add zapi callback",
5139 __PRETTY_FUNCTION__
);
5145 while (l
< length
) {
5146 /* Obtain each remote MACIP and process. */
5147 /* Message contains VNI, followed by MAC followed by IP (if any)
5148 * followed by remote VTEP IP.
5150 update_mac
= update_neigh
= 0;
5153 memset(&ip
, 0, sizeof(ip
));
5154 STREAM_GETL(s
, vni
);
5155 STREAM_GET(&macaddr
.octet
, s
, ETH_ALEN
);
5156 STREAM_GETL(s
, ipa_len
);
5158 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
5160 STREAM_GET(&ip
.ip
.addr
, s
, ipa_len
);
5162 l
+= 4 + ETH_ALEN
+ 4 + ipa_len
;
5163 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5164 l
+= IPV4_MAX_BYTELEN
;
5166 /* Get flags - sticky mac and/or gateway mac */
5167 flags
= stream_getc(s
);
5168 sticky
= CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_STICKY
);
5171 if (IS_ZEBRA_DEBUG_VXLAN
)
5173 "Recv MACIP Add MAC %s IP %s VNI %u Remote VTEP %s with flags 0x%x from %s",
5174 prefix_mac2str(&macaddr
, buf
, sizeof(buf
)),
5175 ipaddr2str(&ip
, buf1
, sizeof(buf1
)), vni
,
5176 inet_ntoa(vtep_ip
), flags
,
5177 zebra_route_string(client
->proto
));
5179 /* Locate VNI hash entry - expected to exist. */
5180 zvni
= zvni_lookup(vni
);
5183 "Failed to locate VNI hash upon remote MACIP ADD, VNI %u",
5187 ifp
= zvni
->vxlan_if
;
5190 "VNI %u hash %p doesn't have intf upon remote MACIP add",
5196 /* If down or not mapped to a bridge, we're done. */
5197 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5200 /* The remote VTEP specified should normally exist, but it is
5202 * that when peering comes up, peer may advertise MACIP routes
5204 * advertising type-3 routes.
5206 zvtep
= zvni_vtep_find(zvni
, &vtep_ip
);
5208 if (zvni_vtep_add(zvni
, &vtep_ip
) == NULL
) {
5210 "Failed to add remote VTEP, VNI %u zvni %p",
5215 zvni_vtep_install(zvni
, &vtep_ip
);
5218 mac
= zvni_mac_lookup(zvni
, &macaddr
);
5220 /* Ignore the update if the mac is already present
5222 if (mac
&& CHECK_FLAG(mac
->flags
, ZEBRA_MAC_DEF_GW
) &&
5223 CHECK_FLAG(flags
, ZEBRA_MACIP_TYPE_GW
)) {
5224 if (IS_ZEBRA_DEBUG_VXLAN
)
5225 zlog_debug("%u:Ignore MAC %s IP %s on VNI %u as MAC is already configured as gateway mac",
5227 prefix_mac2str(&macaddr
,
5229 ipaddr2str(&ip
, buf1
,
5230 sizeof(buf1
)), vni
);
5234 /* check if the remote MAC is unknown or has a change.
5235 * If so, that needs to be updated first. Note that client could
5236 * install MAC and MACIP separately or just install the latter.
5238 if (!mac
|| !CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)
5239 || (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
) ? 1 : 0)
5241 || !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &vtep_ip
))
5246 mac
= zvni_mac_add(zvni
, &macaddr
);
5249 "Failed to add MAC %s VNI %u Remote VTEP %s",
5250 prefix_mac2str(&macaddr
, buf
,
5252 vni
, inet_ntoa(vtep_ip
));
5256 /* Is this MAC created for a MACIP? */
5258 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5261 /* Set "auto" and "remote" forwarding info. */
5262 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5263 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
5264 SET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
5265 mac
->fwd_info
.r_vtep_ip
= vtep_ip
;
5268 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5270 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5272 zvni_process_neigh_on_remote_mac_add(zvni
, mac
);
5274 /* Install the entry. */
5275 zvni_mac_install(zvni
, mac
);
5278 /* If there is no IP, continue - after clearing AUTO flag of
5281 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5285 /* Check if the remote neighbor itself is unknown or has a
5287 * If so, create or update and then install the entry.
5289 n
= zvni_neigh_lookup(zvni
, &ip
);
5290 if (!n
|| !CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
)
5291 || (memcmp(&n
->emac
, &macaddr
, sizeof(macaddr
)) != 0)
5292 || !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
))
5297 n
= zvni_neigh_add(zvni
, &ip
, &macaddr
);
5300 "Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s",
5301 ipaddr2str(&ip
, buf1
,
5303 prefix_mac2str(&macaddr
, buf
,
5305 vni
, inet_ntoa(vtep_ip
));
5309 } else if (memcmp(&n
->emac
, &macaddr
, sizeof(macaddr
))
5311 /* MAC change, update neigh list for old and new
5313 old_mac
= zvni_mac_lookup(zvni
, &n
->emac
);
5315 listnode_delete(old_mac
->neigh_list
, n
);
5316 zvni_deref_ip2mac(zvni
, old_mac
, 1);
5318 listnode_add_sort(mac
->neigh_list
, n
);
5319 memcpy(&n
->emac
, &macaddr
, ETH_ALEN
);
5322 /* Set "remote" forwarding info. */
5323 UNSET_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
);
5324 /* TODO: Handle MAC change. */
5325 n
->r_vtep_ip
= vtep_ip
;
5326 SET_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
);
5328 /* Install the entry. */
5329 zvni_neigh_install(zvni
, n
);
5338 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
5339 * us, this must involve a multihoming scenario. Treat this as implicit delete
5340 * of any prior local MAC.
5342 int zebra_vxlan_check_del_local_mac(struct interface
*ifp
,
5343 struct interface
*br_if
,
5344 struct ethaddr
*macaddr
, vlanid_t vid
)
5346 struct zebra_if
*zif
;
5347 struct zebra_l2info_vxlan
*vxl
;
5351 char buf
[ETHER_ADDR_STRLEN
];
5355 vxl
= &zif
->l2info
.vxl
;
5358 /* Check if EVPN is enabled. */
5359 if (!is_evpn_enabled())
5362 /* Locate hash entry; it is expected to exist. */
5363 zvni
= zvni_lookup(vni
);
5367 /* If entry doesn't exist, nothing to do. */
5368 mac
= zvni_mac_lookup(zvni
, macaddr
);
5372 /* Is it a local entry? */
5373 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
5376 if (IS_ZEBRA_DEBUG_VXLAN
)
5378 "Add/update remote MAC %s intf %s(%u) VNI %u - del local",
5379 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
5380 ifp
->name
, ifp
->ifindex
, vni
);
5382 /* Remove MAC from BGP. */
5383 zvni_mac_send_del_to_client(zvni
->vni
, macaddr
, mac
->flags
);
5386 * If there are no neigh associated with the mac delete the mac
5387 * else mark it as AUTO for forward reference
5389 if (!listcount(mac
->neigh_list
)) {
5390 zvni_mac_del(zvni
, mac
);
5392 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5393 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5400 * Handle remote MAC delete by kernel; readd the remote MAC if we have it.
5401 * This can happen because the remote MAC entries are also added as "dynamic",
5402 * so the kernel can ageout the entry.
5404 int zebra_vxlan_check_readd_remote_mac(struct interface
*ifp
,
5405 struct interface
*br_if
,
5406 struct ethaddr
*macaddr
, vlanid_t vid
)
5408 struct zebra_if
*zif
= NULL
;
5409 struct zebra_l2info_vxlan
*vxl
= NULL
;
5411 zebra_vni_t
*zvni
= NULL
;
5412 zebra_l3vni_t
*zl3vni
= NULL
;
5413 zebra_mac_t
*mac
= NULL
;
5414 char buf
[ETHER_ADDR_STRLEN
];
5418 vxl
= &zif
->l2info
.vxl
;
5421 /* Check if EVPN is enabled. */
5422 if (!is_evpn_enabled())
5425 /* check if this is a remote RMAC and readd simillar to remote macs */
5426 zl3vni
= zl3vni_lookup(vni
);
5428 return zebra_vxlan_readd_remote_rmac(zl3vni
, macaddr
);
5430 /* Locate hash entry; it is expected to exist. */
5431 zvni
= zvni_lookup(vni
);
5435 /* If entry doesn't exist, nothing to do. */
5436 mac
= zvni_mac_lookup(zvni
, macaddr
);
5440 /* Is it a remote entry? */
5441 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
5444 if (IS_ZEBRA_DEBUG_VXLAN
)
5445 zlog_debug("Del remote MAC %s intf %s(%u) VNI %u - readd",
5446 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5449 zvni_mac_install(zvni
, mac
);
5454 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
5456 int zebra_vxlan_local_mac_del(struct interface
*ifp
, struct interface
*br_if
,
5457 struct ethaddr
*macaddr
, vlanid_t vid
)
5461 char buf
[ETHER_ADDR_STRLEN
];
5463 /* We are interested in MACs only on ports or (port, VLAN) that
5466 zvni
= zvni_map_vlan(ifp
, br_if
, vid
);
5469 if (!zvni
->vxlan_if
) {
5470 zlog_err("VNI %u hash %p doesn't have intf upon local MAC DEL",
5475 if (IS_ZEBRA_DEBUG_VXLAN
)
5476 zlog_debug("Del MAC %s intf %s(%u) VID %u -> VNI %u",
5477 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5478 ifp
->ifindex
, vid
, zvni
->vni
);
5480 /* If entry doesn't exist, nothing to do. */
5481 mac
= zvni_mac_lookup(zvni
, macaddr
);
5485 /* Is it a local entry? */
5486 if (!CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
5489 /* Remove MAC from BGP. */
5490 zvni_mac_send_del_to_client(zvni
->vni
, macaddr
, mac
->flags
);
5492 /* Update all the neigh entries associated with this mac */
5493 zvni_process_neigh_on_local_mac_del(zvni
, mac
);
5496 * If there are no neigh associated with the mac delete the mac
5497 * else mark it as AUTO for forward reference
5499 if (!listcount(mac
->neigh_list
)) {
5500 zvni_mac_del(zvni
, mac
);
5502 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5503 SET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5510 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
5512 int zebra_vxlan_local_mac_add_update(struct interface
*ifp
,
5513 struct interface
*br_if
,
5514 struct ethaddr
*macaddr
, vlanid_t vid
,
5519 char buf
[ETHER_ADDR_STRLEN
];
5523 /* We are interested in MACs only on ports or (port, VLAN) that
5526 zvni
= zvni_map_vlan(ifp
, br_if
, vid
);
5528 if (IS_ZEBRA_DEBUG_VXLAN
)
5530 "Add/Update %sMAC %s intf %s(%u) VID %u, could not find VNI",
5531 sticky
? "sticky " : "",
5532 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
5533 ifp
->name
, ifp
->ifindex
, vid
);
5537 if (!zvni
->vxlan_if
) {
5538 zlog_err("VNI %u hash %p doesn't have intf upon local MAC ADD",
5543 if (IS_ZEBRA_DEBUG_VXLAN
)
5545 "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u",
5546 sticky
? "sticky " : "",
5547 prefix_mac2str(macaddr
, buf
, sizeof(buf
)), ifp
->name
,
5548 ifp
->ifindex
, vid
, zvni
->vni
);
5550 /* If same entry already exists, nothing to do. */
5551 mac
= zvni_mac_lookup(zvni
, macaddr
);
5553 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
)) {
5554 mac_sticky
= CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)
5560 * return if nothing has changed.
5561 * inform bgp if sticky flag has changed
5562 * update locally and do not inform bgp if local
5563 * parameters like interface has changed
5565 if (mac_sticky
== sticky
5566 && mac
->fwd_info
.local
.ifindex
== ifp
->ifindex
5567 && mac
->fwd_info
.local
.vid
== vid
) {
5568 if (IS_ZEBRA_DEBUG_VXLAN
)
5570 "Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, "
5571 "entry exists and has not changed ",
5572 sticky
? "sticky " : "",
5573 prefix_mac2str(macaddr
, buf
,
5575 ifp
->name
, ifp
->ifindex
, vid
,
5578 } else if (mac_sticky
!= sticky
) {
5581 add
= 0; /* This is an update of local
5584 } else if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
)) {
5586 * If we have already learned the MAC as a remote sticky
5588 * this is a operator error and we must log a warning
5590 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
)) {
5592 "MAC %s is already learnt as a remote sticky mac behind VTEP %s VNI %d",
5593 prefix_mac2str(macaddr
, buf
,
5595 inet_ntoa(mac
->fwd_info
.r_vtep_ip
),
5603 mac
= zvni_mac_add(zvni
, macaddr
);
5605 zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
5606 prefix_mac2str(macaddr
, buf
, sizeof(buf
)),
5607 ifp
->name
, ifp
->ifindex
, vid
);
5612 /* Set "local" forwarding info. */
5613 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
);
5614 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_AUTO
);
5615 SET_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
);
5616 memset(&mac
->fwd_info
, 0, sizeof(mac
->fwd_info
));
5617 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
5618 mac
->fwd_info
.local
.vid
= vid
;
5621 SET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5623 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_STICKY
);
5625 /* Inform BGP if required. */
5627 zvni_process_neigh_on_local_mac_add(zvni
, mac
);
5628 return zvni_mac_send_add_to_client(zvni
->vni
, macaddr
,
5636 * Handle message from client to delete a remote VTEP for a VNI.
5638 int zebra_vxlan_remote_vtep_del(struct zserv
*client
, u_short length
,
5639 struct zebra_vrf
*zvrf
)
5644 struct in_addr vtep_ip
;
5646 zebra_vtep_t
*zvtep
;
5647 struct interface
*ifp
;
5648 struct zebra_if
*zif
;
5650 if (!is_evpn_enabled()) {
5651 zlog_warn("%s: EVPN is not enabled yet we have received a vtep del command",
5652 __PRETTY_FUNCTION__
);
5656 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
5657 zlog_err("Recv MACIP DEL for non-default VRF %u",
5664 while (l
< length
) {
5665 /* Obtain each remote VTEP and process. */
5666 STREAM_GETL(s
, vni
);
5668 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5669 l
+= IPV4_MAX_BYTELEN
;
5671 if (IS_ZEBRA_DEBUG_VXLAN
)
5672 zlog_debug("Recv VTEP_DEL %s VNI %u from %s",
5673 inet_ntoa(vtep_ip
), vni
,
5674 zebra_route_string(client
->proto
));
5676 /* Locate VNI hash entry - expected to exist. */
5677 zvni
= zvni_lookup(vni
);
5679 if (IS_ZEBRA_DEBUG_VXLAN
)
5681 "Failed to locate VNI hash upon remote VTEP DEL, "
5687 ifp
= zvni
->vxlan_if
;
5690 "VNI %u hash %p doesn't have intf upon remote VTEP DEL",
5696 /* If down or not mapped to a bridge, we're done. */
5697 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5700 /* If the remote VTEP does not exist, there's nothing more to
5702 * Otherwise, uninstall any remote MACs pointing to this VTEP
5704 * then, the VTEP entry itself and remove it.
5706 zvtep
= zvni_vtep_find(zvni
, &vtep_ip
);
5710 zvni_neigh_del_from_vtep(zvni
, 1, &vtep_ip
);
5711 zvni_mac_del_from_vtep(zvni
, 1, &vtep_ip
);
5712 zvni_vtep_uninstall(zvni
, &vtep_ip
);
5713 zvni_vtep_del(zvni
, zvtep
);
5721 * Handle message from client to add a remote VTEP for a VNI.
5723 int zebra_vxlan_remote_vtep_add(struct zserv
*client
, u_short length
,
5724 struct zebra_vrf
*zvrf
)
5729 struct in_addr vtep_ip
;
5731 struct interface
*ifp
;
5732 struct zebra_if
*zif
;
5734 if (!is_evpn_enabled()) {
5735 zlog_warn("%s: EVPN not enabled yet we received a vtep_add zapi call",
5736 __PRETTY_FUNCTION__
);
5740 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
5741 zlog_err("Recv MACIP ADD for non-default VRF %u",
5748 while (l
< length
) {
5749 /* Obtain each remote VTEP and process. */
5750 STREAM_GETL(s
, vni
);
5752 STREAM_GET(&vtep_ip
.s_addr
, s
, IPV4_MAX_BYTELEN
);
5753 l
+= IPV4_MAX_BYTELEN
;
5755 if (IS_ZEBRA_DEBUG_VXLAN
)
5756 zlog_debug("Recv VTEP_ADD %s VNI %u from %s",
5757 inet_ntoa(vtep_ip
), vni
,
5758 zebra_route_string(client
->proto
));
5760 /* Locate VNI hash entry - expected to exist. */
5761 zvni
= zvni_lookup(vni
);
5764 "Failed to locate VNI hash upon remote VTEP ADD, VNI %u",
5769 ifp
= zvni
->vxlan_if
;
5772 "VNI %u hash %p doesn't have intf upon remote VTEP ADD",
5779 /* If down or not mapped to a bridge, we're done. */
5780 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
5783 /* If the remote VTEP already exists,
5784 there's nothing more to do. */
5785 if (zvni_vtep_find(zvni
, &vtep_ip
))
5788 if (zvni_vtep_add(zvni
, &vtep_ip
) == NULL
) {
5790 "Failed to add remote VTEP, VNI %u zvni %p",
5795 zvni_vtep_install(zvni
, &vtep_ip
);
5803 * Add/Del gateway macip to evpn
5805 * 1. SVI interface on a vlan aware bridge
5806 * 2. SVI interface on a vlan unaware bridge
5807 * 3. vrr interface (MACVLAN) associated to a SVI
5808 * We advertise macip routes for an interface if it is associated to VxLan vlan
5810 int zebra_vxlan_add_del_gw_macip(struct interface
*ifp
, struct prefix
*p
,
5814 struct ethaddr macaddr
;
5815 zebra_vni_t
*zvni
= NULL
;
5817 memset(&ip
, 0, sizeof(struct ipaddr
));
5818 memset(&macaddr
, 0, sizeof(struct ethaddr
));
5820 /* Check if EVPN is enabled. */
5821 if (!is_evpn_enabled())
5824 if (IS_ZEBRA_IF_MACVLAN(ifp
)) {
5825 struct interface
*svi_if
=
5826 NULL
; /* SVI corresponding to the MACVLAN */
5827 struct zebra_if
*ifp_zif
=
5828 NULL
; /* Zebra daemon specific info for MACVLAN */
5829 struct zebra_if
*svi_if_zif
=
5830 NULL
; /* Zebra daemon specific info for SVI*/
5832 ifp_zif
= ifp
->info
;
5837 * for a MACVLAN interface the link represents the svi_if
5839 svi_if
= if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT
),
5840 ifp_zif
->link_ifindex
);
5842 zlog_err("MACVLAN %s(%u) without link information",
5843 ifp
->name
, ifp
->ifindex
);
5847 if (IS_ZEBRA_IF_VLAN(svi_if
)) {
5849 * If it is a vlan aware bridge then the link gives the
5850 * bridge information
5852 struct interface
*svi_if_link
= NULL
;
5854 svi_if_zif
= svi_if
->info
;
5856 svi_if_link
= if_lookup_by_index_per_ns(
5857 zebra_ns_lookup(NS_DEFAULT
),
5858 svi_if_zif
->link_ifindex
);
5859 zvni
= zvni_from_svi(svi_if
, svi_if_link
);
5861 } else if (IS_ZEBRA_IF_BRIDGE(svi_if
)) {
5863 * If it is a vlan unaware bridge then svi is the bridge
5866 zvni
= zvni_from_svi(svi_if
, svi_if
);
5868 } else if (IS_ZEBRA_IF_VLAN(ifp
)) {
5869 struct zebra_if
*svi_if_zif
=
5870 NULL
; /* Zebra daemon specific info for SVI */
5871 struct interface
*svi_if_link
=
5872 NULL
; /* link info for the SVI = bridge info */
5874 svi_if_zif
= ifp
->info
;
5875 svi_if_link
= if_lookup_by_index_per_ns(
5876 zebra_ns_lookup(NS_DEFAULT
), svi_if_zif
->link_ifindex
);
5877 if (svi_if_zif
&& svi_if_link
)
5878 zvni
= zvni_from_svi(ifp
, svi_if_link
);
5879 } else if (IS_ZEBRA_IF_BRIDGE(ifp
)) {
5880 zvni
= zvni_from_svi(ifp
, ifp
);
5886 if (!zvni
->vxlan_if
) {
5887 zlog_err("VNI %u hash %p doesn't have intf upon MACVLAN up",
5893 memcpy(&macaddr
.octet
, ifp
->hw_addr
, ETH_ALEN
);
5895 if (p
->family
== AF_INET
) {
5896 ip
.ipa_type
= IPADDR_V4
;
5897 memcpy(&(ip
.ipaddr_v4
), &(p
->u
.prefix4
),
5898 sizeof(struct in_addr
));
5899 } else if (p
->family
== AF_INET6
) {
5900 ip
.ipa_type
= IPADDR_V6
;
5901 memcpy(&(ip
.ipaddr_v6
), &(p
->u
.prefix6
),
5902 sizeof(struct in6_addr
));
5907 zvni_gw_macip_add(ifp
, zvni
, &macaddr
, &ip
);
5909 zvni_gw_macip_del(ifp
, zvni
, &ip
);
5915 * Handle SVI interface going down.
5916 * SVI can be associated to either L3-VNI or L2-VNI.
5917 * For L2-VNI: At this point, this is a NOP since
5918 * the kernel deletes the neighbor entries on this SVI (if any).
5919 * We only need to update the vrf corresponding to zvni.
5920 * For L3-VNI: L3-VNI is operationally down, update mac-ip routes and delete
5923 int zebra_vxlan_svi_down(struct interface
*ifp
, struct interface
*link_if
)
5925 zebra_l3vni_t
*zl3vni
= NULL
;
5927 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
5930 /* process l3-vni down */
5931 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
5933 /* remove association with svi-if */
5934 zl3vni
->svi_if
= NULL
;
5936 zebra_vni_t
*zvni
= NULL
;
5938 /* since we dont have svi corresponding to zvni, we associate it
5939 * to default vrf. Note: the corresponding neigh entries on the
5940 * SVI would have already been deleted */
5941 zvni
= zvni_from_svi(ifp
, link_if
);
5943 zvni
->vrf_id
= VRF_DEFAULT
;
5945 /* update the tenant vrf in BGP */
5946 zvni_send_add_to_client(zvni
);
5953 * Handle SVI interface coming up.
5954 * SVI can be associated to L3-VNI (l3vni vxlan interface) or L2-VNI (l2-vni
5956 * For L2-VNI: we need to install any remote neighbors entried (used for
5958 * For L3-VNI: SVI will be used to get the rmac to be used with L3-VNI
5960 int zebra_vxlan_svi_up(struct interface
*ifp
, struct interface
*link_if
)
5962 zebra_vni_t
*zvni
= NULL
;
5963 zebra_l3vni_t
*zl3vni
= NULL
;
5965 zl3vni
= zl3vni_from_svi(ifp
, link_if
);
5968 /* associate with svi */
5969 zl3vni
->svi_if
= ifp
;
5971 /* process oper-up */
5972 if (is_l3vni_oper_up(zl3vni
))
5973 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
5976 /* process SVI up for l2-vni */
5977 struct neigh_walk_ctx n_wctx
;
5979 zvni
= zvni_from_svi(ifp
, link_if
);
5983 if (!zvni
->vxlan_if
) {
5984 zlog_err("VNI %u hash %p doesn't have intf upon SVI up",
5989 if (IS_ZEBRA_DEBUG_VXLAN
)
5990 zlog_debug("SVI %s(%u) VNI %u VRF %s is UP, installing neighbors",
5991 ifp
->name
, ifp
->ifindex
, zvni
->vni
,
5992 vrf_id_to_name(ifp
->vrf_id
));
5994 /* update the vrf information for l2-vni and inform bgp */
5995 zvni
->vrf_id
= ifp
->vrf_id
;
5996 zvni_send_add_to_client(zvni
);
5998 /* Install any remote neighbors for this VNI. */
5999 memset(&n_wctx
, 0, sizeof(struct neigh_walk_ctx
));
6001 hash_iterate(zvni
->neigh_table
,
6002 zvni_install_neigh_hash
,
6010 * Handle VxLAN interface down
6012 int zebra_vxlan_if_down(struct interface
*ifp
)
6015 struct zebra_if
*zif
= NULL
;
6016 struct zebra_l2info_vxlan
*vxl
= NULL
;
6018 /* Check if EVPN is enabled. */
6019 if (!is_evpn_enabled())
6024 vxl
= &zif
->l2info
.vxl
;
6028 if (is_vni_l3(vni
)) {
6030 /* process-if-down for l3-vni */
6031 zebra_l3vni_t
*zl3vni
= NULL
;
6033 if (IS_ZEBRA_DEBUG_VXLAN
)
6034 zlog_debug("Intf %s(%u) L3-VNI %u is DOWN",
6035 ifp
->name
, ifp
->ifindex
, vni
);
6037 zl3vni
= zl3vni_lookup(vni
);
6040 "Failed to locate L3-VNI hash at DOWN, IF %s(%u) VNI %u",
6041 ifp
->name
, ifp
->ifindex
, vni
);
6045 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6048 /* process if-down for l2-vni */
6051 if (IS_ZEBRA_DEBUG_VXLAN
)
6052 zlog_debug("Intf %s(%u) L2-VNI %u is DOWN",
6053 ifp
->name
, ifp
->ifindex
, vni
);
6055 /* Locate hash entry; it is expected to exist. */
6056 zvni
= zvni_lookup(vni
);
6059 "Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
6060 ifp
->name
, ifp
->ifindex
, vni
);
6064 assert(zvni
->vxlan_if
== ifp
);
6066 /* Delete this VNI from BGP. */
6067 zvni_send_del_to_client(zvni
->vni
);
6069 /* Free up all neighbors and MACs, if any. */
6070 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
6071 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
6073 /* Free up all remote VTEPs, if any. */
6074 zvni_vtep_del_all(zvni
, 1);
6080 * Handle VxLAN interface up - update BGP if required.
6082 int zebra_vxlan_if_up(struct interface
*ifp
)
6085 struct zebra_if
*zif
= NULL
;
6086 struct zebra_l2info_vxlan
*vxl
= NULL
;
6088 /* Check if EVPN is enabled. */
6089 if (!is_evpn_enabled())
6094 vxl
= &zif
->l2info
.vxl
;
6097 if (is_vni_l3(vni
)) {
6099 /* Handle L3-VNI add */
6100 zebra_l3vni_t
*zl3vni
= NULL
;
6102 if (IS_ZEBRA_DEBUG_VXLAN
)
6103 zlog_debug("Intf %s(%u) L3-VNI %u is UP",
6104 ifp
->name
, ifp
->ifindex
, vni
);
6106 zl3vni
= zl3vni_lookup(vni
);
6109 "Failed to locate L3-VNI hash at UP, IF %s(%u) VNI %u",
6110 ifp
->name
, ifp
->ifindex
, vni
);
6114 /* we need to associate with SVI, if any, we can associate with
6115 * svi-if only after association with vxlan-intf is complete
6117 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6119 if (is_l3vni_oper_up(zl3vni
))
6120 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6122 /* Handle L2-VNI add */
6124 zebra_vni_t
*zvni
= NULL
;
6125 zebra_l3vni_t
*zl3vni
= NULL
;
6126 struct interface
*vlan_if
= NULL
;
6128 if (IS_ZEBRA_DEBUG_VXLAN
)
6129 zlog_debug("Intf %s(%u) L2-VNI %u is UP",
6130 ifp
->name
, ifp
->ifindex
, vni
);
6132 /* Locate hash entry; it is expected to exist. */
6133 zvni
= zvni_lookup(vni
);
6136 "Failed to locate VNI hash at UP, IF %s(%u) VNI %u",
6137 ifp
->name
, ifp
->ifindex
, vni
);
6141 assert(zvni
->vxlan_if
== ifp
);
6142 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
6143 zif
->brslave_info
.br_if
);
6145 zvni
->vrf_id
= vlan_if
->vrf_id
;
6146 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
6148 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
6151 /* If part of a bridge, inform BGP about this VNI. */
6152 /* Also, read and populate local MACs and neighbors. */
6153 if (zif
->brslave_info
.br_if
) {
6154 zvni_send_add_to_client(zvni
);
6155 zvni_read_mac_neigh(zvni
, ifp
);
6163 * Handle VxLAN interface delete. Locate and remove entry in hash table
6164 * and update BGP, if required.
6166 int zebra_vxlan_if_del(struct interface
*ifp
)
6169 struct zebra_if
*zif
= NULL
;
6170 struct zebra_l2info_vxlan
*vxl
= NULL
;
6172 /* Check if EVPN is enabled. */
6173 if (!is_evpn_enabled())
6178 vxl
= &zif
->l2info
.vxl
;
6181 if (is_vni_l3(vni
)) {
6183 /* process if-del for l3-vni */
6184 zebra_l3vni_t
*zl3vni
= NULL
;
6186 if (IS_ZEBRA_DEBUG_VXLAN
)
6187 zlog_debug("Del L3-VNI %u intf %s(%u)",
6188 vni
, ifp
->name
, ifp
->ifindex
);
6190 zl3vni
= zl3vni_lookup(vni
);
6193 "Failed to locate L3-VNI hash at del, IF %s(%u) VNI %u",
6194 ifp
->name
, ifp
->ifindex
, vni
);
6198 /* process oper-down for l3-vni */
6199 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6201 /* remove the association with vxlan_if */
6202 memset(&zl3vni
->local_vtep_ip
, 0, sizeof(struct in_addr
));
6203 zl3vni
->vxlan_if
= NULL
;
6206 /* process if-del for l2-vni*/
6207 zebra_vni_t
*zvni
= NULL
;
6208 zebra_l3vni_t
*zl3vni
= NULL
;
6210 if (IS_ZEBRA_DEBUG_VXLAN
)
6211 zlog_debug("Del L2-VNI %u intf %s(%u)",
6212 vni
, ifp
->name
, ifp
->ifindex
);
6214 /* Locate hash entry; it is expected to exist. */
6215 zvni
= zvni_lookup(vni
);
6218 "Failed to locate VNI hash at del, IF %s(%u) VNI %u",
6219 ifp
->name
, ifp
->ifindex
, vni
);
6223 /* remove from l3-vni list */
6224 zl3vni
= zl3vni_from_vrf(zvni
->vrf_id
);
6226 listnode_delete(zl3vni
->l2vnis
, zvni
);
6228 /* Delete VNI from BGP. */
6229 zvni_send_del_to_client(zvni
->vni
);
6231 /* Free up all neighbors and MAC, if any. */
6232 zvni_neigh_del_all(zvni
, 0, 0, DEL_ALL_NEIGH
);
6233 zvni_mac_del_all(zvni
, 0, 0, DEL_ALL_MAC
);
6235 /* Free up all remote VTEPs, if any. */
6236 zvni_vtep_del_all(zvni
, 0);
6238 /* Delete the hash entry. */
6239 if (zvni_del(zvni
)) {
6240 zlog_err("Failed to del VNI hash %p, IF %s(%u) VNI %u",
6241 zvni
, ifp
->name
, ifp
->ifindex
, zvni
->vni
);
6250 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
6252 int zebra_vxlan_if_update(struct interface
*ifp
, u_int16_t chgflags
)
6255 struct zebra_if
*zif
= NULL
;
6256 struct zebra_l2info_vxlan
*vxl
= NULL
;
6258 /* Check if EVPN is enabled. */
6259 if (!is_evpn_enabled())
6264 vxl
= &zif
->l2info
.vxl
;
6267 if (is_vni_l3(vni
)) {
6268 zebra_l3vni_t
*zl3vni
= NULL
;
6270 zl3vni
= zl3vni_lookup(vni
);
6273 "Failed to find L3-VNI hash on update, IF %s(%u) VNI %u",
6274 ifp
->name
, ifp
->ifindex
, vni
);
6278 if (IS_ZEBRA_DEBUG_VXLAN
)
6280 "Update L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x",
6281 vni
, ifp
->name
, ifp
->ifindex
,
6282 vxl
->access_vlan
, inet_ntoa(vxl
->vtep_ip
),
6283 zif
->brslave_info
.bridge_ifindex
, chgflags
);
6285 /* Removed from bridge? Cleanup and return */
6286 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6287 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
6288 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6292 /* access-vlan change - process oper down, associate with new
6293 * svi_if and then process oper up again
6295 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6296 if (if_is_operative(ifp
)) {
6297 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6298 zl3vni
->svi_if
= NULL
;
6299 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6300 if (is_l3vni_oper_up(zl3vni
))
6301 zebra_vxlan_process_l3vni_oper_up(
6306 /* if we have a valid new master, process l3-vni oper up */
6307 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) {
6308 if (is_l3vni_oper_up(zl3vni
))
6309 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6312 zebra_vni_t
*zvni
= NULL
;
6314 /* Update VNI hash. */
6315 zvni
= zvni_lookup(vni
);
6318 "Failed to find L2-VNI hash on update, IF %s(%u) VNI %u",
6319 ifp
->name
, ifp
->ifindex
, vni
);
6323 if (IS_ZEBRA_DEBUG_VXLAN
)
6325 "Update L2-VNI %u intf %s(%u) VLAN %u local IP %s master %u chg 0x%x",
6326 vni
, ifp
->name
, ifp
->ifindex
,
6327 vxl
->access_vlan
, inet_ntoa(vxl
->vtep_ip
),
6328 zif
->brslave_info
.bridge_ifindex
, chgflags
);
6330 /* Removed from bridge? Cleanup and return */
6331 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6332 && (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
)) {
6333 /* Delete from client, remove all remote VTEPs */
6334 /* Also, free up all MACs and neighbors. */
6335 zvni_send_del_to_client(zvni
->vni
);
6336 zvni_neigh_del_all(zvni
, 1, 0, DEL_ALL_NEIGH
);
6337 zvni_mac_del_all(zvni
, 1, 0, DEL_ALL_MAC
);
6338 zvni_vtep_del_all(zvni
, 1);
6342 /* Handle other changes. */
6343 if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6344 /* Remove all existing local neigh and MACs for this VNI
6345 * (including from BGP)
6347 zvni_neigh_del_all(zvni
, 0, 1, DEL_LOCAL_MAC
);
6348 zvni_mac_del_all(zvni
, 0, 1, DEL_LOCAL_MAC
);
6351 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
6352 zvni
->vxlan_if
= ifp
;
6354 /* Take further actions needed.
6355 * Note that if we are here, there is a change of interest.
6357 /* If down or not mapped to a bridge, we're done. */
6358 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6361 /* Inform BGP, if there is a change of interest. */
6363 & (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
))
6364 zvni_send_add_to_client(zvni
);
6366 /* If there is a valid new master or a VLAN mapping change,
6367 * read and populate local MACs and neighbors.
6368 * Also, reinstall any remote MACs and neighbors
6369 * for this VNI (based on new VLAN).
6371 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
6372 zvni_read_mac_neigh(zvni
, ifp
);
6373 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
) {
6374 struct mac_walk_ctx m_wctx
;
6375 struct neigh_walk_ctx n_wctx
;
6377 zvni_read_mac_neigh(zvni
, ifp
);
6379 memset(&m_wctx
, 0, sizeof(struct mac_walk_ctx
));
6381 hash_iterate(zvni
->mac_table
,
6382 zvni_install_mac_hash
,
6385 memset(&n_wctx
, 0, sizeof(struct neigh_walk_ctx
));
6387 hash_iterate(zvni
->neigh_table
, zvni_install_neigh_hash
,
6396 * Handle VxLAN interface add.
6398 int zebra_vxlan_if_add(struct interface
*ifp
)
6401 struct zebra_if
*zif
= NULL
;
6402 struct zebra_l2info_vxlan
*vxl
= NULL
;
6404 /* Check if EVPN is enabled. */
6405 if (!is_evpn_enabled())
6410 vxl
= &zif
->l2info
.vxl
;
6413 if (is_vni_l3(vni
)) {
6415 /* process if-add for l3-vni*/
6416 zebra_l3vni_t
*zl3vni
= NULL
;
6418 if (IS_ZEBRA_DEBUG_VXLAN
)
6420 "Add L3-VNI %u intf %s(%u) VLAN %u local IP %s master %u",
6421 vni
, ifp
->name
, ifp
->ifindex
,
6422 vxl
->access_vlan
, inet_ntoa(vxl
->vtep_ip
),
6423 zif
->brslave_info
.bridge_ifindex
);
6426 * we expect the l3-vni has entry to be present here.
6427 * The only place l3-vni is created in zebra is vrf-vni mapping
6428 * command. This might change when we have the switchd support
6429 * for l3-vxlan interface.
6431 zl3vni
= zl3vni_lookup(vni
);
6434 "Failed to locate L3-VNI hash at del, IF %s(%u) VNI %u",
6435 ifp
->name
, ifp
->ifindex
, vni
);
6439 /* associate with vxlan_if */
6440 zl3vni
->local_vtep_ip
= vxl
->vtep_ip
;
6441 zl3vni
->vxlan_if
= ifp
;
6443 /* Associate with SVI, if any. We can associate with svi-if only
6444 * after association with vxlan_if is complete */
6445 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6447 if (is_l3vni_oper_up(zl3vni
))
6448 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6451 /* process if-add for l2-vni */
6452 zebra_vni_t
*zvni
= NULL
;
6453 zebra_l3vni_t
*zl3vni
= NULL
;
6454 struct interface
*vlan_if
= NULL
;
6456 /* Create or update VNI hash. */
6457 zvni
= zvni_lookup(vni
);
6459 zvni
= zvni_add(vni
);
6462 "Failed to add VNI hash, IF %s(%u) VNI %u",
6463 ifp
->name
, ifp
->ifindex
, vni
);
6468 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
6469 zvni
->vxlan_if
= ifp
;
6470 vlan_if
= zvni_map_to_svi(vxl
->access_vlan
,
6471 zif
->brslave_info
.br_if
);
6473 zvni
->vrf_id
= vlan_if
->vrf_id
;
6474 zl3vni
= zl3vni_from_vrf(vlan_if
->vrf_id
);
6476 listnode_add_sort(zl3vni
->l2vnis
, zvni
);
6479 if (IS_ZEBRA_DEBUG_VXLAN
)
6481 "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s master %u",
6483 vlan_if
? vrf_id_to_name(vlan_if
->vrf_id
) :
6485 ifp
->name
, ifp
->ifindex
,
6486 vxl
->access_vlan
, inet_ntoa(vxl
->vtep_ip
),
6487 zif
->brslave_info
.bridge_ifindex
);
6489 /* If down or not mapped to a bridge, we're done. */
6490 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6494 zvni_send_add_to_client(zvni
);
6496 /* Read and populate local MACs and neighbors */
6497 zvni_read_mac_neigh(zvni
, ifp
);
6503 int zebra_vxlan_process_vrf_vni_cmd(struct zebra_vrf
*zvrf
,
6505 char *err
, int err_str_sz
,
6508 zebra_l3vni_t
*zl3vni
= NULL
;
6509 struct zebra_vrf
*zvrf_default
= NULL
;
6511 zvrf_default
= zebra_vrf_lookup_by_id(VRF_DEFAULT
);
6515 if (IS_ZEBRA_DEBUG_VXLAN
)
6516 zlog_debug("vrf %s vni %u %s",
6519 add
? "ADD" : "DEL");
6523 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
6525 /* check if the vni is already present under zvrf */
6527 snprintf(err
, err_str_sz
,
6528 "VNI is already configured under the vrf");
6532 /* check if this VNI is already present in the system */
6533 zl3vni
= zl3vni_lookup(vni
);
6535 snprintf(err
, err_str_sz
,
6536 "VNI is already configured as L3-VNI");
6540 /* add the L3-VNI to the global table */
6541 zl3vni
= zl3vni_add(vni
, zvrf_id(zvrf
));
6543 snprintf(err
, err_str_sz
,
6544 "Could not add L3-VNI");
6548 /* associate the vrf with vni */
6551 /* associate with vxlan-intf;
6552 * we need to associate with the vxlan-intf first
6554 zl3vni
->vxlan_if
= zl3vni_map_to_vxlan_if(zl3vni
);
6556 /* associate with corresponding SVI interface, we can associate
6557 * with svi-if only after vxlan interface association is
6560 zl3vni
->svi_if
= zl3vni_map_to_svi_if(zl3vni
);
6562 /* formulate l2vni list */
6563 hash_iterate(zvrf_default
->vni_table
,
6564 zvni_add_to_l3vni_list
, zl3vni
);
6566 if (is_l3vni_oper_up(zl3vni
))
6567 zebra_vxlan_process_l3vni_oper_up(zl3vni
);
6570 zl3vni
= zl3vni_lookup(vni
);
6572 snprintf(err
, err_str_sz
, "VNI doesn't exist");
6576 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6578 /* delete and uninstall all rmacs */
6579 hash_iterate(zl3vni
->rmac_table
,
6580 zl3vni_del_rmac_hash_entry
,
6583 /* delete and uninstall all next-hops */
6584 hash_iterate(zl3vni
->nh_table
,
6585 zl3vni_del_nh_hash_entry
,
6591 zebra_vxlan_handle_vni_transition(zvrf
, vni
, add
);
6596 int zebra_vxlan_vrf_delete(struct zebra_vrf
*zvrf
)
6598 zebra_l3vni_t
*zl3vni
= NULL
;
6600 zl3vni
= zl3vni_from_vrf(zvrf_id(zvrf
));
6604 zebra_vxlan_process_l3vni_oper_down(zl3vni
);
6606 zebra_vxlan_handle_vni_transition(zvrf
, zl3vni
->vni
, 0);
6612 * Handle message from client to enable/disable advertisement of g/w macip
6615 int zebra_vxlan_advertise_subnet(struct zserv
*client
, u_short length
,
6616 struct zebra_vrf
*zvrf
)
6621 zebra_vni_t
*zvni
= NULL
;
6622 struct interface
*ifp
= NULL
;
6623 struct zebra_if
*zif
= NULL
;
6624 struct zebra_l2info_vxlan zl2_info
;
6625 struct interface
*vlan_if
= NULL
;
6627 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6628 zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
6634 advertise
= stream_getc(s
);
6635 vni
= stream_get3(s
);
6637 zvni
= zvni_lookup(vni
);
6641 if (zvni
->advertise_subnet
== advertise
)
6644 if (IS_ZEBRA_DEBUG_VXLAN
)
6646 "EVPN subnet Adv %s on VNI %d , currently %s",
6647 advertise
? "enabled" : "disabled", vni
,
6648 zvni
->advertise_subnet
? "enabled" : "disabled");
6651 zvni
->advertise_subnet
= advertise
;
6653 ifp
= zvni
->vxlan_if
;
6659 /* If down or not mapped to a bridge, we're done. */
6660 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6663 zl2_info
= zif
->l2info
.vxl
;
6665 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
6666 zif
->brslave_info
.br_if
);
6670 if (zvni
->advertise_subnet
)
6671 zvni_advertise_subnet(zvni
, vlan_if
, 1);
6673 zvni_advertise_subnet(zvni
, vlan_if
, 0);
6679 * Handle message from client to enable/disable advertisement of g/w macip
6682 int zebra_vxlan_advertise_gw_macip(struct zserv
*client
, u_short length
,
6683 struct zebra_vrf
*zvrf
)
6688 zebra_vni_t
*zvni
= NULL
;
6689 struct interface
*ifp
= NULL
;
6691 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6692 zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
6698 STREAM_GETC(s
, advertise
);
6699 STREAM_GET(&vni
, s
, 3);
6702 if (IS_ZEBRA_DEBUG_VXLAN
)
6703 zlog_debug("EVPN gateway macip Adv %s, currently %s",
6704 advertise
? "enabled" : "disabled",
6705 advertise_gw_macip_enabled(NULL
)
6709 if (zvrf
->advertise_gw_macip
== advertise
)
6712 zvrf
->advertise_gw_macip
= advertise
;
6714 if (advertise_gw_macip_enabled(zvni
))
6715 hash_iterate(zvrf
->vni_table
,
6716 zvni_gw_macip_add_for_vni_hash
, NULL
);
6718 hash_iterate(zvrf
->vni_table
,
6719 zvni_gw_macip_del_for_vni_hash
, NULL
);
6722 struct zebra_if
*zif
= NULL
;
6723 struct zebra_l2info_vxlan zl2_info
;
6724 struct interface
*vlan_if
= NULL
;
6725 struct interface
*vrr_if
= NULL
;
6727 if (IS_ZEBRA_DEBUG_VXLAN
)
6729 "EVPN gateway macip Adv %s on VNI %d , currently %s",
6730 advertise
? "enabled" : "disabled", vni
,
6731 advertise_gw_macip_enabled(zvni
)
6735 zvni
= zvni_lookup(vni
);
6739 if (zvni
->advertise_gw_macip
== advertise
)
6742 zvni
->advertise_gw_macip
= advertise
;
6744 ifp
= zvni
->vxlan_if
;
6750 /* If down or not mapped to a bridge, we're done. */
6751 if (!if_is_operative(ifp
) || !zif
->brslave_info
.br_if
)
6754 zl2_info
= zif
->l2info
.vxl
;
6756 vlan_if
= zvni_map_to_svi(zl2_info
.access_vlan
,
6757 zif
->brslave_info
.br_if
);
6761 if (advertise_gw_macip_enabled(zvni
)) {
6762 /* Add primary SVI MAC-IP */
6763 zvni_add_macip_for_intf(vlan_if
, zvni
);
6765 /* Add VRR MAC-IP - if any*/
6766 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
6768 zvni_add_macip_for_intf(vrr_if
, zvni
);
6770 /* Del primary MAC-IP */
6771 zvni_del_macip_for_intf(vlan_if
, zvni
);
6773 /* Del VRR MAC-IP - if any*/
6774 vrr_if
= zebra_get_vrr_intf_for_svi(vlan_if
);
6776 zvni_del_macip_for_intf(vrr_if
, zvni
);
6786 * Handle message from client to learn (or stop learning) about VNIs and MACs.
6787 * When enabled, the VNI hash table will be built and MAC FDB table read;
6788 * when disabled, the entries should be deleted and remote VTEPs and MACs
6789 * uninstalled from the kernel.
6791 int zebra_vxlan_advertise_all_vni(struct zserv
*client
,
6792 u_short length
, struct zebra_vrf
*zvrf
)
6794 struct stream
*s
= NULL
;
6796 struct zebra_ns
*zns
= NULL
;
6798 if (zvrf_id(zvrf
) != VRF_DEFAULT
) {
6799 zlog_err("EVPN VNI Adv for non-default VRF %u",
6805 STREAM_GETC(s
, advertise
);
6807 if (IS_ZEBRA_DEBUG_VXLAN
)
6808 zlog_debug("EVPN VNI Adv %s, currently %s",
6809 advertise
? "enabled" : "disabled",
6810 is_evpn_enabled() ? "enabled" : "disabled");
6812 if (zvrf
->advertise_all_vni
== advertise
)
6815 zvrf
->advertise_all_vni
= advertise
;
6816 if (is_evpn_enabled()) {
6817 /* Build VNI hash table and inform BGP. */
6818 zvni_build_hash_table();
6820 /* Add all SVI (L3 GW) MACs to BGP*/
6821 hash_iterate(zvrf
->vni_table
, zvni_gw_macip_add_for_vni_hash
,
6824 /* Read the MAC FDB */
6825 macfdb_read(zvrf
->zns
);
6827 /* Read neighbors */
6828 neigh_read(zvrf
->zns
);
6830 /* Cleanup VTEPs for all VNIs - uninstall from
6831 * kernel and free entries.
6833 hash_iterate(zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
6835 /* cleanup all l3vnis */
6836 zns
= zebra_ns_lookup(NS_DEFAULT
);
6840 hash_iterate(zns
->l3vni_table
, zl3vni_cleanup_all
, NULL
);
6848 * Allocate VNI hash table for this VRF and do other initialization.
6849 * NOTE: Currently supported only for default VRF.
6851 void zebra_vxlan_init_tables(struct zebra_vrf
*zvrf
)
6855 zvrf
->vni_table
= hash_create(vni_hash_keymake
, vni_hash_cmp
,
6856 "Zebra VRF VNI Table");
6859 /* Close all VNI handling */
6860 void zebra_vxlan_close_tables(struct zebra_vrf
*zvrf
)
6864 hash_iterate(zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
6865 hash_free(zvrf
->vni_table
);
6868 /* init the l3vni table */
6869 void zebra_vxlan_ns_init(struct zebra_ns
*zns
)
6871 zns
->l3vni_table
= hash_create(l3vni_hash_keymake
, l3vni_hash_cmp
,
6872 "Zebra VRF L3 VNI table");
6875 /* free l3vni table */
6876 void zebra_vxlan_ns_disable(struct zebra_ns
*zns
)
6878 hash_free(zns
->l3vni_table
);
6881 /* get the l3vni svi ifindex */
6882 ifindex_t
get_l3vni_svi_ifindex(vrf_id_t vrf_id
)
6884 zebra_l3vni_t
*zl3vni
= NULL
;
6886 zl3vni
= zl3vni_from_vrf(vrf_id
);
6887 if (!zl3vni
|| !is_l3vni_oper_up(zl3vni
))
6890 return zl3vni
->svi_if
->ifindex
;