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
, ZVNI
, "VNI hash");
51 DEFINE_MTYPE_STATIC(ZEBRA
, ZVNI_VTEP
, "VNI remote VTEP");
52 DEFINE_MTYPE_STATIC(ZEBRA
, MAC
, "VNI MAC");
53 DEFINE_MTYPE_STATIC(ZEBRA
, NEIGH
, "VNI Neighbor");
58 /* static function declarations */
60 zvni_print_neigh (zebra_neigh_t
*n
, void *ctxt
);
62 zvni_print_neigh_hash (struct hash_backet
*backet
, void *ctxt
);
64 zvni_print_neigh_hash_all_vni (struct hash_backet
*backet
, void *ctxt
);
66 zvni_print_mac (zebra_mac_t
*mac
, void *ctxt
);
68 zvni_print_mac_hash (struct hash_backet
*backet
, void *ctxt
);
70 zvni_print_mac_hash_all_vni (struct hash_backet
*backet
, void *ctxt
);
72 zvni_print (zebra_vni_t
*zvni
, void *ctxt
);
74 zvni_print_hash (struct hash_backet
*backet
, void *ctxt
);
77 zvni_macip_send_msg_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
78 struct ethaddr
*macaddr
,
79 struct ipaddr
*ip
, u_char sticky
,
82 neigh_hash_keymake (void *p
);
84 neigh_cmp (const void *p1
, const void *p2
);
86 zvni_neigh_alloc (void *p
);
87 static zebra_neigh_t
*
88 zvni_neigh_add (zebra_vni_t
*zvni
, struct ipaddr
*ip
);
90 zvni_neigh_del (zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
92 zvni_neigh_del_hash_entry (struct hash_backet
*backet
, void *arg
);
94 zvni_neigh_del_from_vtep (zebra_vni_t
*zvni
, int uninstall
,
95 struct in_addr
*r_vtep_ip
);
97 zvni_neigh_del_all (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
,
98 int uninstall
, int upd_client
, u_int32_t flags
);
99 static zebra_neigh_t
*
100 zvni_neigh_lookup (zebra_vni_t
*zvni
, struct ipaddr
*ip
);
102 zvni_neigh_send_add_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
103 struct ipaddr
*ip
, struct ethaddr
*macaddr
);
105 zvni_neigh_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
106 struct ipaddr
*ip
, struct ethaddr
*macaddr
);
108 zvni_neigh_install (zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
110 zvni_neigh_uninstall (zebra_vni_t
*zvni
, zebra_neigh_t
*n
);
112 zvni_map_svi (struct interface
*ifp
, struct interface
*br_if
);
113 static struct interface
*
114 zvni_map_to_svi (struct zebra_vrf
*zvrf
, vlanid_t vid
,
115 struct interface
*br_if
);
118 mac_hash_keymake (void *p
);
120 mac_cmp (const void *p1
, const void *p2
);
122 zvni_mac_alloc (void *p
);
124 zvni_mac_add (zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
126 zvni_mac_del (zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
128 zvni_mac_del_hash_entry (struct hash_backet
*backet
, void *arg
);
130 zvni_mac_del_from_vtep (zebra_vni_t
*zvni
, int uninstall
,
131 struct in_addr
*r_vtep_ip
);
133 zvni_mac_del_all (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
,
134 int uninstall
, int upd_client
, u_int32_t flags
);
136 zvni_mac_lookup (zebra_vni_t
*zvni
, struct ethaddr
*macaddr
);
138 zvni_mac_send_add_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
139 struct ethaddr
*macaddr
, u_char sticky
);
141 zvni_mac_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
142 struct ethaddr
*macaddr
, u_char sticky
);
144 zvni_map_vlan (struct interface
*ifp
, struct interface
*br_if
, vlanid_t vid
);
146 zvni_mac_install (zebra_vni_t
*zvni
, zebra_mac_t
*mac
);
148 zvni_mac_uninstall (zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
);
150 zvni_install_mac_hash (struct hash_backet
*backet
, void *ctxt
);
153 vni_hash_keymake (void *p
);
155 vni_hash_cmp (const void *p1
, const void *p2
);
157 zvni_alloc (void *p
);
159 zvni_lookup (struct zebra_vrf
*zvrf
, vni_t vni
);
161 zvni_add (struct zebra_vrf
*zvrf
, vni_t vni
);
163 zvni_del (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
);
165 zvni_send_add_to_client (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
);
167 zvni_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
);
169 zvni_build_hash_table (struct zebra_vrf
*zvrf
);
171 zvni_vtep_match (struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
);
172 static zebra_vtep_t
*
173 zvni_vtep_find (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
174 static zebra_vtep_t
*
175 zvni_vtep_add (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
177 zvni_vtep_del (zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
);
179 zvni_vtep_del_all (zebra_vni_t
*zvni
, int uninstall
);
181 zvni_vtep_install (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
183 zvni_vtep_uninstall (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
);
186 /* Private functions */
189 * Helper function to determine maximum width of neighbor IP address for
190 * display - just because we're dealing with IPv6 addresses that can
194 zvni_find_neigh_addr_width (struct hash_backet
*backet
, void *ctxt
)
197 char buf
[INET6_ADDRSTRLEN
];
198 struct neigh_walk_ctx
*wctx
= ctxt
;
201 n
= (zebra_neigh_t
*) backet
->data
;
205 ipaddr2str (&n
->ip
, buf
, sizeof(buf
)),
206 width
= strlen (buf
);
207 if (width
> wctx
->addr_width
)
208 wctx
->addr_width
= width
;
212 * Print a specific neighbor entry.
215 zvni_print_neigh (zebra_neigh_t
*n
, void *ctxt
)
218 char buf1
[ETHER_ADDR_STRLEN
];
219 char buf2
[INET6_ADDRSTRLEN
];
221 ipaddr2str (&n
->ip
, buf2
, sizeof(buf2
)),
222 vty
= (struct vty
*) ctxt
;
223 vty_out(vty
, "IP: %s%s",
224 ipaddr2str (&n
->ip
, buf2
, sizeof(buf2
)), VTY_NEWLINE
);
225 vty_out(vty
, " MAC: %s", prefix_mac2str (&n
->emac
, buf1
, sizeof (buf1
)));
226 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
227 vty_out(vty
, " Remote VTEP: %s", inet_ntoa (n
->r_vtep_ip
));
228 vty_out(vty
, "%s", VTY_NEWLINE
);
232 * Print neighbor hash entry - called for display of all neighbors.
235 zvni_print_neigh_hash (struct hash_backet
*backet
, void *ctxt
)
239 char buf1
[ETHER_ADDR_STRLEN
];
240 char buf2
[INET6_ADDRSTRLEN
];
241 struct neigh_walk_ctx
*wctx
= ctxt
;
244 n
= (zebra_neigh_t
*) backet
->data
;
248 prefix_mac2str (&n
->emac
, buf1
, sizeof (buf1
));
249 ipaddr2str (&n
->ip
, buf2
, sizeof(buf2
));
250 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_LOCAL
) &&
251 !(wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
))
253 vty_out(vty
, "%*s %-6s %-17s %s",
254 -wctx
->addr_width
, buf2
, "local", buf1
, VTY_NEWLINE
);
259 if (wctx
->flags
& SHOW_REMOTE_NEIGH_FROM_VTEP
)
261 if (IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
))
263 if (wctx
->count
== 0)
264 vty_out(vty
, "%*s %-6s %-17s %-21s%s",
265 -wctx
->addr_width
, "Neighbor", "Type", "MAC",
266 "Remote VTEP", VTY_NEWLINE
);
267 vty_out(vty
, "%*s %-6s %-17s %-21s%s",
268 -wctx
->addr_width
, buf2
, "remote", buf1
,
269 inet_ntoa (n
->r_vtep_ip
), VTY_NEWLINE
);
275 vty_out(vty
, "%*s %-6s %-17s %-21s%s",
276 -wctx
->addr_width
, buf2
, "remote", buf1
,
277 inet_ntoa (n
->r_vtep_ip
), VTY_NEWLINE
);
284 * Print neighbors for all VNI.
287 zvni_print_neigh_hash_all_vni (struct hash_backet
*backet
, void *ctxt
)
292 struct neigh_walk_ctx wctx
;
294 vty
= (struct vty
*) ctxt
;
295 zvni
= (zebra_vni_t
*) backet
->data
;
299 num_neigh
= hashcount(zvni
->neigh_table
);
300 vty_out(vty
, "%sVNI %u #ARP (IPv4 and IPv6, local and remote) %u%s%s",
301 VTY_NEWLINE
, zvni
->vni
, num_neigh
, VTY_NEWLINE
, VTY_NEWLINE
);
305 /* Since we have IPv6 addresses to deal with which can vary widely in
306 * size, we try to be a bit more elegant in display by first computing
309 memset (&wctx
, 0, sizeof (struct neigh_walk_ctx
));
312 wctx
.addr_width
= 15;
313 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
315 vty_out(vty
, "%*s %-6s %-17s %-21s%s",
316 -wctx
.addr_width
, "IP", "Type", "MAC",
317 "Remote VTEP", VTY_NEWLINE
);
318 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
322 * Print a specific MAC entry.
325 zvni_print_mac (zebra_mac_t
*mac
, void *ctxt
)
330 vty
= (struct vty
*) ctxt
;
331 vty_out(vty
, "MAC: %s%s",
332 prefix_mac2str (&mac
->macaddr
, buf1
, sizeof (buf1
)), VTY_NEWLINE
);
333 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
))
335 struct zebra_ns
*zns
;
336 struct interface
*ifp
;
339 ifindex
= mac
->fwd_info
.local
.ifindex
;
340 zns
= zebra_ns_lookup (NS_DEFAULT
);
341 ifp
= if_lookup_by_index_per_ns (zns
, ifindex
);
342 if (!ifp
) // unexpected
344 vty_out(vty
, " Intf: %s(%u)", ifp
->name
, ifindex
);
345 if (mac
->fwd_info
.local
.vid
)
346 vty_out(vty
, " VLAN: %u", mac
->fwd_info
.local
.vid
);
350 vty_out(vty
, " Remote VTEP: %s",
351 inet_ntoa (mac
->fwd_info
.r_vtep_ip
));
353 vty_out(vty
, " ARP ref: %u", mac
->neigh_refcnt
);
354 vty_out(vty
, "%s", VTY_NEWLINE
);
358 * Print MAC hash entry - called for display of all MACs.
361 zvni_print_mac_hash (struct hash_backet
*backet
, void *ctxt
)
366 struct mac_walk_ctx
*wctx
= ctxt
;
369 mac
= (zebra_mac_t
*) backet
->data
;
373 prefix_mac2str (&mac
->macaddr
, buf1
, sizeof (buf1
));
374 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_LOCAL
) &&
375 !(wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
))
377 struct zebra_ns
*zns
;
379 struct interface
*ifp
;
382 zns
= zebra_ns_lookup (NS_DEFAULT
);
383 ifindex
= mac
->fwd_info
.local
.ifindex
;
384 ifp
= if_lookup_by_index_per_ns (zns
, ifindex
);
385 if (!ifp
) // unexpected
387 vid
= mac
->fwd_info
.local
.vid
;
388 vty_out(vty
, "%-17s %-6s %-21s",
389 buf1
, "local", ifp
->name
);
391 vty_out(vty
, " %-5u", vid
);
392 vty_out(vty
, "%s", VTY_NEWLINE
);
397 if (wctx
->flags
& SHOW_REMOTE_MAC_FROM_VTEP
)
399 if (IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
,
402 if (wctx
->count
== 0)
404 vty_out(vty
, "%sVNI %u%s%s",
405 VTY_NEWLINE
, wctx
->zvni
->vni
,VTY_NEWLINE
, VTY_NEWLINE
);
406 vty_out(vty
, "%-17s %-6s %-21s %-5s%s",
407 "MAC", "Type", "Intf/Remote VTEP",
408 "VLAN", VTY_NEWLINE
);
410 vty_out(vty
, "%-17s %-6s %-21s%s",
412 inet_ntoa (mac
->fwd_info
.r_vtep_ip
),
419 vty_out(vty
, "%-17s %-6s %-21s%s",
421 inet_ntoa (mac
->fwd_info
.r_vtep_ip
), VTY_NEWLINE
);
429 * Print MACs for all VNI.
432 zvni_print_mac_hash_all_vni (struct hash_backet
*backet
, void *ctxt
)
437 struct mac_walk_ctx
*wctx
= ctxt
;
439 vty
= (struct vty
*) wctx
->vty
;
441 zvni
= (zebra_vni_t
*) backet
->data
;
446 /*We are iterating over a new VNI, set the count to 0*/
449 num_macs
= hashcount(zvni
->mac_table
);
452 if (!CHECK_FLAG(wctx
->flags
, SHOW_REMOTE_MAC_FROM_VTEP
))
454 vty_out(vty
, "%sVNI %u #MACs (local and remote) %u%s%s",
455 VTY_NEWLINE
, zvni
->vni
, num_macs
, VTY_NEWLINE
, VTY_NEWLINE
);
456 vty_out(vty
, "%-17s %-6s %-21s %-5s%s",
457 "MAC", "Type", "Intf/Remote VTEP", "VLAN", VTY_NEWLINE
);
460 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, wctx
);
464 * Print a specific VNI entry.
467 zvni_print (zebra_vni_t
*zvni
, void *ctxt
)
474 vty
= (struct vty
*) ctxt
;
476 vty_out(vty
, "VNI: %u%s", zvni
->vni
, VTY_NEWLINE
);
479 vty_out(vty
, " VxLAN interface: unknown%s", VTY_NEWLINE
);
482 vty_out(vty
, " VxLAN interface: %s ifIndex: %u VTEP IP: %s%s",
483 zvni
->vxlan_if
->name
, zvni
->vxlan_if
->ifindex
,
484 inet_ntoa(zvni
->local_vtep_ip
), VTY_NEWLINE
);
488 vty_out(vty
, " No remote VTEPs known for this VNI%s", VTY_NEWLINE
);
492 vty_out(vty
, " Remote VTEPs for this VNI:%s", VTY_NEWLINE
);
493 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
)
494 vty_out(vty
, " %s%s",
495 inet_ntoa (zvtep
->vtep_ip
), VTY_NEWLINE
);
497 num_macs
= hashcount(zvni
->mac_table
);
498 vty_out(vty
, " Number of MACs (local and remote) known for this VNI: %u%s",
499 num_macs
, VTY_NEWLINE
);
500 num_neigh
= hashcount(zvni
->neigh_table
);
501 vty_out(vty
, " Number of ARPs (IPv4 and IPv6, local and remote) "
502 "known for this VNI: %u%s", num_neigh
, VTY_NEWLINE
);
506 * Print a VNI hash entry - called for display of all VNIs.
509 zvni_print_hash (struct hash_backet
*backet
, void *ctxt
)
514 u_int32_t num_vteps
= 0;
515 u_int32_t num_macs
= 0;
516 u_int32_t num_neigh
= 0;
518 vty
= (struct vty
*) ctxt
;
519 zvni
= (zebra_vni_t
*) backet
->data
;
530 num_macs
= hashcount(zvni
->mac_table
);
531 num_neigh
= hashcount(zvni
->neigh_table
);
532 vty_out(vty
, "%-10u %-21s %-15s %-8u %-8u %-15u%s",
534 zvni
->vxlan_if
? zvni
->vxlan_if
->name
: "unknown",
535 inet_ntoa(zvni
->local_vtep_ip
),
536 num_macs
, num_neigh
, num_vteps
, VTY_NEWLINE
);
540 * Inform BGP about local MACIP.
543 zvni_macip_send_msg_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
544 struct ethaddr
*macaddr
,
545 struct ipaddr
*ip
, u_char sticky
,
548 struct zserv
*client
;
551 char buf
[ETHER_ADDR_STRLEN
];
552 char buf2
[INET6_ADDRSTRLEN
];
554 client
= zebra_find_client (ZEBRA_ROUTE_BGP
);
555 /* BGP may not be running. */
562 zserv_create_header (s
, cmd
, zvrf_id (zvrf
));
563 stream_putl (s
, vni
);
564 stream_put (s
, macaddr
->octet
, ETHER_ADDR_LEN
);
568 if (IS_IPADDR_V4(ip
))
569 ipa_len
= IPV4_MAX_BYTELEN
;
570 else if (IS_IPADDR_V6(ip
))
571 ipa_len
= IPV6_MAX_BYTELEN
;
573 stream_putl (s
, ipa_len
); /* IP address length */
575 stream_put (s
, &ip
->ip
.addr
, ipa_len
); /* IP address */
578 stream_putl (s
, 0); /* Just MAC. */
580 stream_putc (s
, sticky
); /* Sticky MAC? */
582 /* Write packet size. */
583 stream_putw_at (s
, 0, stream_get_endp (s
));
585 if (IS_ZEBRA_DEBUG_VXLAN
)
586 zlog_debug ("%u:Send MACIP %s %sMAC %s IP %s VNI %u to %s",
587 zvrf_id (zvrf
), (cmd
== ZEBRA_MACIP_ADD
) ? "Add" : "Del",
588 sticky
? "sticky " : "",
589 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
590 ipaddr2str (ip
, buf2
, sizeof(buf2
)), vni
,
591 zebra_route_string (client
->proto
));
593 if (cmd
== ZEBRA_MACIP_ADD
)
594 client
->macipadd_cnt
++;
596 client
->macipdel_cnt
++;
598 return zebra_server_send_message(client
);
602 * Make hash key for neighbors.
605 neigh_hash_keymake (void *p
)
607 zebra_neigh_t
*n
= p
;
608 struct ipaddr
*ip
= &n
->ip
;
610 if (IS_IPADDR_V4(ip
))
611 return jhash_1word (ip
->ipaddr_v4
.s_addr
, 0);
613 return jhash2 (ip
->ipaddr_v6
.s6_addr32
,
614 ZEBRA_NUM_OF(ip
->ipaddr_v6
.s6_addr32
), 0);
618 * Compare two neighbor hash structures.
621 neigh_cmp (const void *p1
, const void *p2
)
623 const zebra_neigh_t
*n1
= p1
;
624 const zebra_neigh_t
*n2
= p2
;
626 if (n1
== NULL
&& n2
== NULL
)
629 if (n1
== NULL
|| n2
== NULL
)
632 return (memcmp(&n1
->ip
, &n2
->ip
, sizeof (struct ipaddr
)) == 0);
636 * Callback to allocate neighbor hash entry.
639 zvni_neigh_alloc (void *p
)
641 const zebra_neigh_t
*tmp_n
= p
;
644 n
= XCALLOC (MTYPE_NEIGH
, sizeof(zebra_neigh_t
));
651 * Add neighbor entry.
653 static zebra_neigh_t
*
654 zvni_neigh_add (zebra_vni_t
*zvni
, struct ipaddr
*ip
)
657 zebra_neigh_t
*n
= NULL
;
659 memset (&tmp_n
, 0, sizeof (zebra_neigh_t
));
660 memcpy (&tmp_n
.ip
, ip
, sizeof (struct ipaddr
));
661 n
= hash_get (zvni
->neigh_table
, &tmp_n
, zvni_neigh_alloc
);
668 * Delete neighbor entry.
671 zvni_neigh_del (zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
673 zebra_neigh_t
*tmp_n
;
675 /* Free the VNI hash entry and allocated memory. */
676 tmp_n
= hash_release (zvni
->neigh_table
, n
);
678 XFREE(MTYPE_NEIGH
, tmp_n
);
684 * Free neighbor hash entry (callback)
687 zvni_neigh_del_hash_entry (struct hash_backet
*backet
, void *arg
)
689 struct neigh_walk_ctx
*wctx
= arg
;
690 zebra_neigh_t
*n
= backet
->data
;
692 if (((wctx
->flags
& DEL_LOCAL_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_LOCAL
)) ||
693 ((wctx
->flags
& DEL_REMOTE_NEIGH
) && (n
->flags
& ZEBRA_NEIGH_REMOTE
)) ||
694 ((wctx
->flags
& DEL_REMOTE_NEIGH_FROM_VTEP
) &&
695 (n
->flags
& ZEBRA_NEIGH_REMOTE
) &&
696 IPV4_ADDR_SAME(&n
->r_vtep_ip
, &wctx
->r_vtep_ip
)
699 if (wctx
->upd_client
&& (n
->flags
& ZEBRA_NEIGH_LOCAL
))
700 zvni_neigh_send_del_to_client (wctx
->zvrf
, wctx
->zvni
->vni
, &n
->ip
,
704 zvni_neigh_uninstall (wctx
->zvni
, n
);
706 return zvni_neigh_del (wctx
->zvni
, n
);
713 * Delete all neighbor entries from specific VTEP for a particular VNI.
716 zvni_neigh_del_from_vtep (zebra_vni_t
*zvni
, int uninstall
,
717 struct in_addr
*r_vtep_ip
)
719 struct neigh_walk_ctx wctx
;
721 if (!zvni
->neigh_table
)
724 memset (&wctx
, 0, sizeof (struct neigh_walk_ctx
));
726 wctx
.uninstall
= uninstall
;
727 wctx
.flags
= DEL_REMOTE_NEIGH_FROM_VTEP
;
728 wctx
.r_vtep_ip
= *r_vtep_ip
;
730 hash_iterate (zvni
->neigh_table
,
731 (void (*) (struct hash_backet
*, void *))
732 zvni_neigh_del_hash_entry
, &wctx
);
736 * Delete all neighbor entries for this VNI.
739 zvni_neigh_del_all (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
,
740 int uninstall
, int upd_client
, u_int32_t flags
)
742 struct neigh_walk_ctx wctx
;
744 if (!zvni
->neigh_table
)
747 memset (&wctx
, 0, sizeof (struct neigh_walk_ctx
));
750 wctx
.uninstall
= uninstall
;
751 wctx
.upd_client
= upd_client
;
754 hash_iterate (zvni
->neigh_table
,
755 (void (*) (struct hash_backet
*, void *))
756 zvni_neigh_del_hash_entry
, &wctx
);
760 * Look up neighbor hash entry.
762 static zebra_neigh_t
*
763 zvni_neigh_lookup (zebra_vni_t
*zvni
, struct ipaddr
*ip
)
768 memset (&tmp
, 0, sizeof(tmp
));
769 memcpy (&tmp
.ip
, ip
, sizeof (struct ipaddr
));
770 n
= hash_lookup (zvni
->neigh_table
, &tmp
);
776 * Inform BGP about local neighbor addition.
779 zvni_neigh_send_add_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
780 struct ipaddr
*ip
, struct ethaddr
*macaddr
)
782 return zvni_macip_send_msg_to_client (zvrf
, vni
, macaddr
, ip
, 0,
787 * Inform BGP about local neighbor deletion.
790 zvni_neigh_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
791 struct ipaddr
*ip
, struct ethaddr
*macaddr
)
793 return zvni_macip_send_msg_to_client (zvrf
, vni
, macaddr
, ip
, 0,
798 * Install remote neighbor into the kernel.
801 zvni_neigh_install (zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
803 struct zebra_vrf
*zvrf
;
804 struct zebra_if
*zif
;
805 struct zebra_l2info_vxlan
*vxl
;
806 struct interface
*vlan_if
;
808 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
811 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
813 zif
= zvni
->vxlan_if
->info
;
816 vxl
= &zif
->l2info
.vxl
;
818 vlan_if
= zvni_map_to_svi (zvrf
, vxl
->access_vlan
,
819 zif
->brslave_info
.br_if
);
823 return kernel_add_neigh (vlan_if
, &n
->ip
, &n
->emac
);
827 * Uninstall remote neighbor from the kernel.
830 zvni_neigh_uninstall (zebra_vni_t
*zvni
, zebra_neigh_t
*n
)
832 struct zebra_vrf
*zvrf
;
833 struct zebra_if
*zif
;
834 struct zebra_l2info_vxlan
*vxl
;
835 struct interface
*vlan_if
;
837 if (!(n
->flags
& ZEBRA_NEIGH_REMOTE
))
840 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
844 zlog_err ("VNI %u hash %p couldn't be uninstalled - no intf",
849 zif
= zvni
->vxlan_if
->info
;
852 vxl
= &zif
->l2info
.vxl
;
853 vlan_if
= zvni_map_to_svi (zvrf
, vxl
->access_vlan
,
854 zif
->brslave_info
.br_if
);
858 return kernel_del_neigh (vlan_if
, &n
->ip
);
862 * Install neighbor hash entry - called upon access VLAN change.
865 zvni_install_neigh_hash (struct hash_backet
*backet
, void *ctxt
)
868 struct neigh_walk_ctx
*wctx
= ctxt
;
870 n
= (zebra_neigh_t
*) backet
->data
;
874 if (CHECK_FLAG(n
->flags
, ZEBRA_NEIGH_REMOTE
))
875 zvni_neigh_install (wctx
->zvni
, n
);
879 * Make hash key for MAC.
882 mac_hash_keymake (void *p
)
884 zebra_mac_t
*pmac
= p
;
885 char *pnt
= (char *) pmac
->macaddr
.octet
;
886 unsigned int key
= 0;
900 * Compare two MAC addresses.
903 mac_cmp (const void *p1
, const void *p2
)
905 const zebra_mac_t
*pmac1
= p1
;
906 const zebra_mac_t
*pmac2
= p2
;
908 if (pmac1
== NULL
&& pmac2
== NULL
)
911 if (pmac1
== NULL
|| pmac2
== NULL
)
914 return(memcmp(pmac1
->macaddr
.octet
, pmac2
->macaddr
.octet
, ETHER_ADDR_LEN
) == 0);
918 * Callback to allocate MAC hash entry.
921 zvni_mac_alloc (void *p
)
923 const zebra_mac_t
*tmp_mac
= p
;
926 mac
= XCALLOC (MTYPE_MAC
, sizeof(zebra_mac_t
));
929 return ((void *)mac
);
936 zvni_mac_add (zebra_vni_t
*zvni
, struct ethaddr
*macaddr
)
939 zebra_mac_t
*mac
= NULL
;
941 memset (&tmp_mac
, 0, sizeof (zebra_mac_t
));
942 memcpy(&tmp_mac
.macaddr
, macaddr
, ETHER_ADDR_LEN
);
943 mac
= hash_get (zvni
->mac_table
, &tmp_mac
, zvni_mac_alloc
);
953 zvni_mac_del (zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
955 zebra_mac_t
*tmp_mac
;
957 /* Free the VNI hash entry and allocated memory. */
958 tmp_mac
= hash_release (zvni
->mac_table
, mac
);
960 XFREE(MTYPE_MAC
, tmp_mac
);
966 * Free MAC hash entry (callback)
969 zvni_mac_del_hash_entry (struct hash_backet
*backet
, void *arg
)
971 struct mac_walk_ctx
*wctx
= arg
;
972 zebra_mac_t
*mac
= backet
->data
;
975 if (((wctx
->flags
& DEL_LOCAL_MAC
) && (mac
->flags
& ZEBRA_MAC_LOCAL
)) ||
976 ((wctx
->flags
& DEL_REMOTE_MAC
) && (mac
->flags
& ZEBRA_MAC_REMOTE
)) ||
977 ((wctx
->flags
& DEL_REMOTE_MAC_FROM_VTEP
) &&
978 (mac
->flags
& ZEBRA_MAC_REMOTE
) &&
979 IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &wctx
->r_vtep_ip
)
982 if (wctx
->upd_client
&& (mac
->flags
& ZEBRA_MAC_LOCAL
))
984 sticky
= CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0;
985 zvni_mac_send_del_to_client (wctx
->zvrf
, wctx
->zvni
->vni
,
986 &mac
->macaddr
, sticky
);
990 zvni_mac_uninstall (wctx
->zvni
, mac
, 0);
992 return zvni_mac_del (wctx
->zvni
, mac
);
999 * Delete all MAC entries from specific VTEP for a particular VNI.
1002 zvni_mac_del_from_vtep (zebra_vni_t
*zvni
, int uninstall
,
1003 struct in_addr
*r_vtep_ip
)
1005 struct mac_walk_ctx wctx
;
1007 if (!zvni
->mac_table
)
1010 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
1012 wctx
.uninstall
= uninstall
;
1013 wctx
.flags
= DEL_REMOTE_MAC_FROM_VTEP
;
1014 wctx
.r_vtep_ip
= *r_vtep_ip
;
1016 hash_iterate (zvni
->mac_table
,
1017 (void (*) (struct hash_backet
*, void *))
1018 zvni_mac_del_hash_entry
, &wctx
);
1022 * Delete all MAC entries for this VNI.
1025 zvni_mac_del_all (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
,
1026 int uninstall
, int upd_client
, u_int32_t flags
)
1028 struct mac_walk_ctx wctx
;
1030 if (!zvni
->mac_table
)
1033 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
1036 wctx
.uninstall
= uninstall
;
1037 wctx
.upd_client
= upd_client
;
1040 hash_iterate (zvni
->mac_table
,
1041 (void (*) (struct hash_backet
*, void *))
1042 zvni_mac_del_hash_entry
, &wctx
);
1046 * Look up MAC hash entry.
1048 static zebra_mac_t
*
1049 zvni_mac_lookup (zebra_vni_t
*zvni
, struct ethaddr
*mac
)
1054 memset(&tmp
, 0, sizeof(tmp
));
1055 memcpy(&tmp
.macaddr
, mac
, ETHER_ADDR_LEN
);
1056 pmac
= hash_lookup (zvni
->mac_table
, &tmp
);
1062 * Inform BGP about local MAC addition.
1065 zvni_mac_send_add_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
1066 struct ethaddr
*macaddr
, u_char sticky
)
1068 return zvni_macip_send_msg_to_client (zvrf
, vni
, macaddr
, NULL
,
1069 sticky
, ZEBRA_MACIP_ADD
);
1073 * Inform BGP about local MAC deletion.
1076 zvni_mac_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
,
1077 struct ethaddr
*macaddr
, u_char sticky
)
1079 return zvni_macip_send_msg_to_client (zvrf
, vni
, macaddr
, NULL
,
1080 sticky
, ZEBRA_MACIP_DEL
);
1084 * Map port or (port, VLAN) to a VNI. This is invoked upon getting MAC
1085 * notifications, to see if there are of interest.
1086 * TODO: Need to make this as a hash table.
1088 static zebra_vni_t
*
1089 zvni_map_vlan (struct interface
*ifp
, struct interface
*br_if
, vlanid_t vid
)
1091 struct zebra_vrf
*zvrf
;
1092 struct listnode
*node
;
1093 struct interface
*tmp_if
;
1094 struct zebra_if
*zif
;
1095 struct zebra_l2info_bridge
*br
;
1096 struct zebra_l2info_vxlan
*vxl
;
1097 u_char bridge_vlan_aware
;
1100 /* Locate VRF corresponding to interface. */
1101 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1104 /* Determine if bridge is VLAN-aware or not */
1107 br
= &zif
->l2info
.br
;
1108 bridge_vlan_aware
= br
->vlan_aware
;
1110 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1111 /* TODO: Optimize with a hash. */
1112 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (zvrf_id (zvrf
)), node
, tmp_if
))
1115 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1117 if (!if_is_operative (tmp_if
))
1119 vxl
= &zif
->l2info
.vxl
;
1121 if (zif
->brslave_info
.br_if
!= br_if
)
1124 if (!bridge_vlan_aware
)
1127 if (vxl
->access_vlan
== vid
)
1134 zvni
= zvni_lookup (zvrf
, vxl
->vni
);
1139 * Map SVI and associated bridge to a VNI. This is invoked upon getting
1140 * neighbor notifications, to see if they are of interest.
1141 * TODO: Need to make this as a hash table.
1143 static zebra_vni_t
*
1144 zvni_map_svi (struct interface
*ifp
, struct interface
*br_if
)
1146 struct zebra_vrf
*zvrf
;
1147 struct listnode
*node
;
1148 struct interface
*tmp_if
;
1149 struct zebra_if
*zif
;
1150 struct zebra_l2info_bridge
*br
;
1151 struct zebra_l2info_vxlan
*vxl
;
1152 u_char bridge_vlan_aware
;
1156 /* Make sure the linked interface is a bridge. */
1157 if (!IS_ZEBRA_IF_BRIDGE (br_if
))
1160 /* Locate VRF corresponding to interface. */
1161 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
1164 /* Determine if bridge is VLAN-aware or not */
1167 br
= &zif
->l2info
.br
;
1168 bridge_vlan_aware
= br
->vlan_aware
;
1169 if (bridge_vlan_aware
)
1171 struct zebra_l2info_vlan
*vl
;
1173 if (!IS_ZEBRA_IF_VLAN(ifp
))
1178 vl
= &zif
->l2info
.vl
;
1182 /* See if this interface (or interface plus VLAN Id) maps to a VxLAN */
1183 /* TODO: Optimize with a hash. */
1184 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (zvrf_id (zvrf
)), node
, tmp_if
))
1187 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1189 if (!if_is_operative (tmp_if
))
1191 vxl
= &zif
->l2info
.vxl
;
1193 if (zif
->brslave_info
.br_if
!= br_if
)
1196 if (!bridge_vlan_aware
)
1199 if (vxl
->access_vlan
== vid
)
1206 zvni
= zvni_lookup (zvrf
, vxl
->vni
);
1210 /* Map to SVI on bridge corresponding to specified VLAN. This can be one
1212 * (a) In the case of a VLAN-aware bridge, the SVI is a L3 VLAN interface
1213 * linked to the bridge
1214 * (b) In the case of a VLAN-unaware bridge, the SVI is the bridge inteface
1217 static struct interface
*
1218 zvni_map_to_svi (struct zebra_vrf
*zvrf
, vlanid_t vid
,
1219 struct interface
*br_if
)
1221 struct listnode
*node
;
1222 struct interface
*tmp_if
;
1223 struct zebra_if
*zif
;
1224 struct zebra_l2info_bridge
*br
;
1225 struct zebra_l2info_vlan
*vl
;
1226 u_char bridge_vlan_aware
;
1228 /* Determine if bridge is VLAN-aware or not */
1231 br
= &zif
->l2info
.br
;
1232 bridge_vlan_aware
= br
->vlan_aware
;
1234 /* Check oper status of the SVI. */
1235 if (!bridge_vlan_aware
)
1236 return if_is_operative (br_if
) ? br_if
: NULL
;
1238 /* Identify corresponding VLAN interface. */
1239 /* TODO: Optimize with a hash. */
1240 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (zvrf_id (zvrf
)), node
, tmp_if
))
1242 /* Check oper status of the SVI. */
1243 if (!if_is_operative (tmp_if
))
1247 zif
->zif_type
!= ZEBRA_IF_VLAN
||
1250 vl
= (struct zebra_l2info_vlan
*)&zif
->l2info
.vl
;
1260 * Install remote MAC into the kernel.
1263 zvni_mac_install (zebra_vni_t
*zvni
, zebra_mac_t
*mac
)
1265 struct zebra_if
*zif
;
1266 struct zebra_l2info_vxlan
*vxl
;
1269 if (!(mac
->flags
& ZEBRA_MAC_REMOTE
))
1272 zif
= zvni
->vxlan_if
->info
;
1275 vxl
= &zif
->l2info
.vxl
;
1277 sticky
= CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0;
1279 return kernel_add_mac (zvni
->vxlan_if
, vxl
->access_vlan
,
1280 &mac
->macaddr
, mac
->fwd_info
.r_vtep_ip
, sticky
);
1284 * Uninstall remote MAC from the kernel. In the scenario where the MAC
1285 * moves to remote, we have to uninstall any existing local entry first.
1288 zvni_mac_uninstall (zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int local
)
1290 struct zebra_if
*zif
;
1291 struct zebra_l2info_vxlan
*vxl
;
1292 struct in_addr vtep_ip
= { .s_addr
= 0 };
1293 struct zebra_ns
*zns
;
1294 struct interface
*ifp
;
1296 if (!local
&& !(mac
->flags
& ZEBRA_MAC_REMOTE
))
1299 if (!zvni
->vxlan_if
)
1301 zlog_err ("VNI %u hash %p couldn't be uninstalled - no intf",
1306 zif
= zvni
->vxlan_if
->info
;
1309 vxl
= &zif
->l2info
.vxl
;
1313 zns
= zebra_ns_lookup (NS_DEFAULT
);
1314 ifp
= if_lookup_by_index_per_ns (zns
, mac
->fwd_info
.local
.ifindex
);
1315 if (!ifp
) // unexpected
1320 ifp
= zvni
->vxlan_if
;
1321 vtep_ip
= mac
->fwd_info
.r_vtep_ip
;
1324 return kernel_del_mac (ifp
, vxl
->access_vlan
,
1325 &mac
->macaddr
, vtep_ip
, local
);
1329 * Install MAC hash entry - called upon access VLAN change.
1332 zvni_install_mac_hash (struct hash_backet
*backet
, void *ctxt
)
1335 struct mac_walk_ctx
*wctx
= ctxt
;
1337 mac
= (zebra_mac_t
*) backet
->data
;
1341 if (CHECK_FLAG(mac
->flags
, ZEBRA_MAC_REMOTE
))
1342 zvni_mac_install (wctx
->zvni
, mac
);
1346 * Decrement neighbor refcount of MAC; uninstall and free it if
1350 zvni_deref_ip2mac (zebra_vni_t
*zvni
, zebra_mac_t
*mac
, int uninstall
)
1352 if (mac
->neigh_refcnt
)
1353 mac
->neigh_refcnt
--;
1355 if (!CHECK_FLAG (mac
->flags
, ZEBRA_MAC_AUTO
) ||
1356 mac
->neigh_refcnt
> 0)
1360 zvni_mac_uninstall (zvni
, mac
, 0);
1362 zvni_mac_del (zvni
, mac
);
1366 * Read and populate local MACs and neighbors corresponding to this VNI.
1369 zvni_read_mac_neigh (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
,
1370 struct interface
*ifp
)
1372 struct zebra_if
*zif
;
1373 struct interface
*vlan_if
;
1374 struct zebra_l2info_vxlan
*vxl
;
1377 vxl
= &zif
->l2info
.vxl
;
1379 if (IS_ZEBRA_DEBUG_VXLAN
)
1380 zlog_debug ("%u:Reading MAC FDB and Neighbors for intf %s(%u) VNI %u master %u",
1381 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, zvni
->vni
,
1382 zif
->brslave_info
.bridge_ifindex
);
1384 macfdb_read_for_bridge (zvrf
->zns
, ifp
, zif
->brslave_info
.br_if
);
1385 vlan_if
= zvni_map_to_svi (zvrf
, vxl
->access_vlan
,
1386 zif
->brslave_info
.br_if
);
1388 neigh_read_for_vlan (zvrf
->zns
, vlan_if
);
1392 * Hash function for VNI.
1395 vni_hash_keymake (void *p
)
1397 const zebra_vni_t
*zvni
= p
;
1399 return (jhash_1word(zvni
->vni
, 0));
1403 * Compare 2 VNI hash entries.
1406 vni_hash_cmp (const void *p1
, const void *p2
)
1408 const zebra_vni_t
*zvni1
= p1
;
1409 const zebra_vni_t
*zvni2
= p2
;
1411 return (zvni1
->vni
== zvni2
->vni
);
1415 * Callback to allocate VNI hash entry.
1418 zvni_alloc (void *p
)
1420 const zebra_vni_t
*tmp_vni
= p
;
1423 zvni
= XCALLOC (MTYPE_ZVNI
, sizeof(zebra_vni_t
));
1424 zvni
->vni
= tmp_vni
->vni
;
1425 return ((void *)zvni
);
1429 * Look up VNI hash entry.
1431 static zebra_vni_t
*
1432 zvni_lookup (struct zebra_vrf
*zvrf
, vni_t vni
)
1434 zebra_vni_t tmp_vni
;
1435 zebra_vni_t
*zvni
= NULL
;
1437 memset (&tmp_vni
, 0, sizeof (zebra_vni_t
));
1439 zvni
= hash_lookup (zvrf
->vni_table
, &tmp_vni
);
1445 * Add VNI hash entry.
1447 static zebra_vni_t
*
1448 zvni_add (struct zebra_vrf
*zvrf
, vni_t vni
)
1450 zebra_vni_t tmp_zvni
;
1451 zebra_vni_t
*zvni
= NULL
;
1453 memset (&tmp_zvni
, 0, sizeof (zebra_vni_t
));
1455 zvni
= hash_get (zvrf
->vni_table
, &tmp_zvni
, zvni_alloc
);
1458 /* Create hash table for MAC */
1459 zvni
->mac_table
= hash_create(mac_hash_keymake
,
1461 "Zebra VNI MAC Table");
1463 /* Create hash table for neighbors */
1464 zvni
->neigh_table
= hash_create(neigh_hash_keymake
,
1466 "Zebra VNI Neighbor Table");
1472 * Delete VNI hash entry.
1475 zvni_del (struct zebra_vrf
*zvrf
, zebra_vni_t
*zvni
)
1477 zebra_vni_t
*tmp_zvni
;
1479 zvni
->vxlan_if
= NULL
;
1481 /* Free the neighbor hash table. */
1482 hash_free(zvni
->neigh_table
);
1483 zvni
->neigh_table
= NULL
;
1485 /* Free the MAC hash table. */
1486 hash_free(zvni
->mac_table
);
1487 zvni
->mac_table
= NULL
;
1489 /* Free the VNI hash entry and allocated memory. */
1490 tmp_zvni
= hash_release (zvrf
->vni_table
, zvni
);
1492 XFREE(MTYPE_ZVNI
, tmp_zvni
);
1498 * Inform BGP about local VNI addition.
1501 zvni_send_add_to_client (struct zebra_vrf
*zvrf
,
1504 struct zserv
*client
;
1507 client
= zebra_find_client (ZEBRA_ROUTE_BGP
);
1508 /* BGP may not be running. */
1515 zserv_create_header (s
, ZEBRA_VNI_ADD
, zvrf_id (zvrf
));
1516 stream_putl (s
, zvni
->vni
);
1517 stream_put_in_addr (s
, &zvni
->local_vtep_ip
);
1519 /* Write packet size. */
1520 stream_putw_at (s
, 0, stream_get_endp (s
));
1522 if (IS_ZEBRA_DEBUG_VXLAN
)
1523 zlog_debug ("%u:Send VNI_ADD %u %s to %s",
1524 zvrf_id (zvrf
), zvni
->vni
,
1525 inet_ntoa(zvni
->local_vtep_ip
),
1526 zebra_route_string (client
->proto
));
1528 client
->vniadd_cnt
++;
1529 return zebra_server_send_message(client
);
1533 * Inform BGP about local VNI deletion.
1536 zvni_send_del_to_client (struct zebra_vrf
*zvrf
, vni_t vni
)
1538 struct zserv
*client
;
1541 client
= zebra_find_client (ZEBRA_ROUTE_BGP
);
1542 /* BGP may not be running. */
1549 zserv_create_header (s
, ZEBRA_VNI_DEL
, zvrf_id (zvrf
));
1550 stream_putl (s
, vni
);
1552 /* Write packet size. */
1553 stream_putw_at (s
, 0, stream_get_endp (s
));
1555 if (IS_ZEBRA_DEBUG_VXLAN
)
1556 zlog_debug ("%u:Send VNI_DEL %u to %s", zvrf_id (zvrf
), vni
,
1557 zebra_route_string (client
->proto
));
1559 client
->vnidel_cnt
++;
1560 return zebra_server_send_message(client
);
1564 * Build the VNI hash table by going over the VxLAN interfaces. This
1565 * is called when EVPN (advertise-all-vni) is enabled.
1568 zvni_build_hash_table (struct zebra_vrf
*zvrf
)
1570 struct listnode
*node
;
1571 struct interface
*ifp
;
1573 /* Walk VxLAN interfaces and create VNI hash. */
1574 for (ALL_LIST_ELEMENTS_RO (vrf_iflist (zvrf_id (zvrf
)), node
, ifp
))
1576 struct zebra_if
*zif
;
1577 struct zebra_l2info_vxlan
*vxl
;
1582 if (!zif
|| zif
->zif_type
!= ZEBRA_IF_VXLAN
)
1584 vxl
= &zif
->l2info
.vxl
;
1588 if (IS_ZEBRA_DEBUG_VXLAN
)
1589 zlog_debug ("%u:Create VNI hash for intf %s(%u) VNI %u local IP %s",
1590 zvrf_id (zvrf
), ifp
->name
, ifp
->ifindex
, vni
,
1591 inet_ntoa (vxl
->vtep_ip
));
1593 /* VNI hash entry is not expected to exist. */
1594 zvni
= zvni_lookup (zvrf
, vni
);
1597 zlog_err ("VNI hash already present for VRF %d IF %s(%u) VNI %u",
1598 zvrf_id (zvrf
), ifp
->name
, ifp
->ifindex
, vni
);
1602 zvni
= zvni_add (zvrf
, vni
);
1605 zlog_err ("Failed to add VNI hash, VRF %d IF %s(%u) VNI %u",
1606 zvrf_id (zvrf
), ifp
->name
, ifp
->ifindex
, vni
);
1610 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
1611 zvni
->vxlan_if
= ifp
;
1613 /* Inform BGP if interface is up and mapped to bridge. */
1614 if (if_is_operative (ifp
) &&
1615 zif
->brslave_info
.br_if
)
1616 zvni_send_add_to_client (zvrf
, zvni
);
1621 * See if remote VTEP matches with prefix.
1624 zvni_vtep_match (struct in_addr
*vtep_ip
, zebra_vtep_t
*zvtep
)
1626 return (IPV4_ADDR_SAME (vtep_ip
, &zvtep
->vtep_ip
));
1630 * Locate remote VTEP in VNI hash table.
1632 static zebra_vtep_t
*
1633 zvni_vtep_find (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
1635 zebra_vtep_t
*zvtep
;
1640 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep
->next
)
1642 if (zvni_vtep_match (vtep_ip
, zvtep
))
1650 * Add remote VTEP to VNI hash table.
1652 static zebra_vtep_t
*
1653 zvni_vtep_add (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
1655 zebra_vtep_t
*zvtep
;
1657 zvtep
= XCALLOC (MTYPE_ZVNI_VTEP
, sizeof(zebra_vtep_t
));
1660 zlog_err ("Failed to alloc VTEP entry, VNI %u", zvni
->vni
);
1664 zvtep
->vtep_ip
= *vtep_ip
;
1667 zvni
->vteps
->prev
= zvtep
;
1668 zvtep
->next
= zvni
->vteps
;
1669 zvni
->vteps
= zvtep
;
1675 * Remove remote VTEP from VNI hash table.
1678 zvni_vtep_del (zebra_vni_t
*zvni
, zebra_vtep_t
*zvtep
)
1681 zvtep
->next
->prev
= zvtep
->prev
;
1683 zvtep
->prev
->next
= zvtep
->next
;
1685 zvni
->vteps
= zvtep
->next
;
1687 zvtep
->prev
= zvtep
->next
= NULL
;
1688 XFREE (MTYPE_ZVNI_VTEP
, zvtep
);
1694 * Delete all remote VTEPs for this VNI (upon VNI delete). Also
1695 * uninstall from kernel if asked to.
1698 zvni_vtep_del_all (zebra_vni_t
*zvni
, int uninstall
)
1700 zebra_vtep_t
*zvtep
, *zvtep_next
;
1705 for (zvtep
= zvni
->vteps
; zvtep
; zvtep
= zvtep_next
)
1707 zvtep_next
= zvtep
->next
;
1709 zvni_vtep_uninstall (zvni
, &zvtep
->vtep_ip
);
1710 zvni_vtep_del (zvni
, zvtep
);
1717 * Install remote VTEP into the kernel.
1720 zvni_vtep_install (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
1722 return kernel_add_vtep (zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
1726 * Uninstall remote VTEP from the kernel.
1729 zvni_vtep_uninstall (zebra_vni_t
*zvni
, struct in_addr
*vtep_ip
)
1731 if (!zvni
->vxlan_if
)
1733 zlog_err ("VNI %u hash %p couldn't be uninstalled - no intf",
1738 return kernel_del_vtep (zvni
->vni
, zvni
->vxlan_if
, vtep_ip
);
1742 * Cleanup VNI/VTEP and update kernel
1745 zvni_cleanup_all (struct hash_backet
*backet
, void *zvrf
)
1749 zvni
= (zebra_vni_t
*) backet
->data
;
1753 /* Free up all neighbors and MACs, if any. */
1754 zvni_neigh_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_NEIGH
);
1755 zvni_mac_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_MAC
);
1757 /* Free up all remote VTEPs, if any. */
1758 zvni_vtep_del_all (zvni
, 1);
1760 /* Delete the hash entry. */
1761 zvni_del (zvrf
, zvni
);
1765 /* Public functions */
1768 * Display Neighbors for a VNI (VTY command handler).
1771 zebra_vxlan_print_neigh_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
)
1774 u_int32_t num_neigh
;
1775 struct neigh_walk_ctx wctx
;
1777 if (!EVPN_ENABLED(zvrf
))
1779 zvni
= zvni_lookup (zvrf
, vni
);
1782 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1785 num_neigh
= hashcount(zvni
->neigh_table
);
1789 /* Since we have IPv6 addresses to deal with which can vary widely in
1790 * size, we try to be a bit more elegant in display by first computing
1791 * the maximum width.
1793 memset (&wctx
, 0, sizeof (struct neigh_walk_ctx
));
1796 wctx
.addr_width
= 15;
1797 hash_iterate(zvni
->neigh_table
, zvni_find_neigh_addr_width
, &wctx
);
1799 vty_out(vty
, "Number of ARPs (local and remote) known for this VNI: %u%s",
1800 num_neigh
, VTY_NEWLINE
);
1801 vty_out(vty
, "%*s %-6s %-17s %-21s%s",
1802 -wctx
.addr_width
, "IP", "Type", "MAC",
1803 "Remote VTEP", VTY_NEWLINE
);
1805 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
1809 * Display neighbors across all VNIs (VTY command handler).
1812 zebra_vxlan_print_neigh_all_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
)
1814 if (!EVPN_ENABLED(zvrf
))
1816 hash_iterate(zvrf
->vni_table
, zvni_print_neigh_hash_all_vni
, vty
);
1820 * Display specific neighbor for a VNI, if present (VTY command handler).
1823 zebra_vxlan_print_specific_neigh_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
,
1824 vni_t vni
, struct ipaddr
*ip
)
1829 if (!EVPN_ENABLED(zvrf
))
1831 zvni
= zvni_lookup (zvrf
, vni
);
1834 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1837 n
= zvni_neigh_lookup (zvni
, ip
);
1840 vty_out (vty
, "%% Requested neighbor does not exist in VNI %u%s",
1845 zvni_print_neigh (n
, vty
);
1849 * Display neighbors for a VNI from specific VTEP (VTY command handler).
1850 * By definition, these are remote neighbors.
1853 zebra_vxlan_print_neigh_vni_vtep (struct vty
*vty
, struct zebra_vrf
*zvrf
,
1854 vni_t vni
, struct in_addr vtep_ip
)
1857 u_int32_t num_neigh
;
1858 struct neigh_walk_ctx wctx
;
1860 if (!EVPN_ENABLED(zvrf
))
1862 zvni
= zvni_lookup (zvrf
, vni
);
1865 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1868 num_neigh
= hashcount(zvni
->neigh_table
);
1872 memset (&wctx
, 0, sizeof (struct neigh_walk_ctx
));
1875 wctx
.flags
= SHOW_REMOTE_NEIGH_FROM_VTEP
;
1876 wctx
.r_vtep_ip
= vtep_ip
;
1878 hash_iterate(zvni
->neigh_table
, zvni_print_neigh_hash
, &wctx
);
1882 * Display MACs for a VNI (VTY command handler).
1885 zebra_vxlan_print_macs_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
)
1889 struct mac_walk_ctx wctx
;
1891 if (!EVPN_ENABLED(zvrf
))
1893 zvni
= zvni_lookup (zvrf
, vni
);
1896 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1899 num_macs
= hashcount(zvni
->mac_table
);
1903 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
1907 vty_out(vty
, "Number of MACs (local and remote) known for this VNI: %u%s",
1908 num_macs
, VTY_NEWLINE
);
1909 vty_out(vty
, "%-17s %-6s %-21s %-5s%s",
1910 "MAC", "Type", "Intf/Remote VTEP", "VLAN", VTY_NEWLINE
);
1912 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
1916 * Display MACs for all VNIs (VTY command handler).
1919 zebra_vxlan_print_macs_all_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
)
1921 struct mac_walk_ctx wctx
;
1923 if (!EVPN_ENABLED(zvrf
))
1925 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
1927 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
1931 * Display MACs for all VNIs (VTY command handler).
1934 zebra_vxlan_print_macs_all_vni_vtep (struct vty
*vty
, struct zebra_vrf
*zvrf
,
1935 struct in_addr vtep_ip
)
1937 struct mac_walk_ctx wctx
;
1939 if (!EVPN_ENABLED(zvrf
))
1941 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
1943 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
1944 wctx
.r_vtep_ip
= vtep_ip
;
1945 hash_iterate(zvrf
->vni_table
, zvni_print_mac_hash_all_vni
, &wctx
);
1949 * Display specific MAC for a VNI, if present (VTY command handler).
1952 zebra_vxlan_print_specific_mac_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
,
1953 vni_t vni
, struct ethaddr
*macaddr
)
1958 if (!EVPN_ENABLED(zvrf
))
1960 zvni
= zvni_lookup (zvrf
, vni
);
1963 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1966 mac
= zvni_mac_lookup (zvni
, macaddr
);
1969 vty_out (vty
, "%% Requested MAC does not exist in VNI %u%s",
1974 zvni_print_mac (mac
, vty
);
1978 * Display MACs for a VNI from specific VTEP (VTY command handler).
1981 zebra_vxlan_print_macs_vni_vtep (struct vty
*vty
, struct zebra_vrf
*zvrf
,
1982 vni_t vni
, struct in_addr vtep_ip
)
1986 struct mac_walk_ctx wctx
;
1988 if (!EVPN_ENABLED(zvrf
))
1990 zvni
= zvni_lookup (zvrf
, vni
);
1993 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
1996 num_macs
= hashcount(zvni
->mac_table
);
1999 memset (&wctx
, 0, sizeof (struct mac_walk_ctx
));
2002 wctx
.flags
= SHOW_REMOTE_MAC_FROM_VTEP
;
2003 wctx
.r_vtep_ip
= vtep_ip
;
2004 hash_iterate(zvni
->mac_table
, zvni_print_mac_hash
, &wctx
);
2009 * Display VNI information (VTY command handler).
2012 zebra_vxlan_print_vni (struct vty
*vty
, struct zebra_vrf
*zvrf
, vni_t vni
)
2016 if (!EVPN_ENABLED(zvrf
))
2018 zvni
= zvni_lookup (zvrf
, vni
);
2021 vty_out (vty
, "%% VNI %u does not exist%s", vni
, VTY_NEWLINE
);
2024 zvni_print (zvni
, (void *)vty
);
2028 * Display VNI hash table (VTY command handler).
2031 zebra_vxlan_print_vnis (struct vty
*vty
, struct zebra_vrf
*zvrf
)
2035 if (!EVPN_ENABLED(zvrf
))
2037 num_vnis
= hashcount(zvrf
->vni_table
);
2040 vty_out(vty
, "Number of VNIs: %u%s", num_vnis
, VTY_NEWLINE
);
2041 vty_out(vty
, "%-10s %-21s %-15s %-8s %-8s %-15s%s",
2042 "VNI", "VxLAN IF", "VTEP IP", "# MACs", "# ARPs",
2043 "# Remote VTEPs", VTY_NEWLINE
);
2044 hash_iterate(zvrf
->vni_table
, zvni_print_hash
, vty
);
2048 * Handle neighbor delete (on a VLAN device / L3 interface) from the
2049 * kernel. This may result in either the neighbor getting deleted from
2050 * our database or being re-added to the kernel (if it is a valid
2054 zebra_vxlan_local_neigh_del (struct interface
*ifp
,
2055 struct interface
*link_if
,
2060 struct zebra_vrf
*zvrf
;
2061 char buf
[INET6_ADDRSTRLEN
];
2063 /* We are only interested in neighbors on an SVI that resides on top
2064 * of a VxLAN bridge.
2066 zvni
= zvni_map_svi (ifp
, link_if
);
2069 if (!zvni
->vxlan_if
)
2071 zlog_err ("VNI %u hash %p doesn't have intf upon local neighbor DEL",
2076 if (IS_ZEBRA_DEBUG_VXLAN
)
2077 zlog_debug ("%u:Del neighbor %s intf %s(%u) -> VNI %u",
2078 ifp
->vrf_id
, ipaddr2str (ip
, buf
, sizeof(buf
)),
2079 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
2081 /* If entry doesn't exist, nothing to do. */
2082 n
= zvni_neigh_lookup (zvni
, ip
);
2086 /* If it is a remote entry, the kernel has aged this out or someone has
2087 * deleted it, it needs to be re-installed as Quagga is the owner.
2089 if (CHECK_FLAG (n
->flags
, ZEBRA_NEIGH_REMOTE
))
2091 zvni_neigh_install (zvni
, n
);
2095 /* Locate VRF corresponding to interface. */
2096 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
2099 /* Remove neighbor from BGP. */
2100 zvni_neigh_send_del_to_client (zvrf
, zvni
->vni
, &n
->ip
, &n
->emac
);
2102 /* Delete this neighbor entry. */
2103 zvni_neigh_del (zvni
, n
);
2109 * Handle neighbor add or update (on a VLAN device / L3 interface)
2113 zebra_vxlan_local_neigh_add_update (struct interface
*ifp
,
2114 struct interface
*link_if
,
2116 struct ethaddr
*macaddr
,
2122 struct zebra_vrf
*zvrf
;
2123 char buf
[ETHER_ADDR_STRLEN
];
2124 char buf2
[INET6_ADDRSTRLEN
];
2125 int send_upd
= 1, send_del
= 0;
2127 /* We are only interested in neighbors on an SVI that resides on top
2128 * of a VxLAN bridge.
2130 zvni
= zvni_map_svi (ifp
, link_if
);
2134 /* Locate VRF corresponding to interface. */
2135 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
2138 if (IS_ZEBRA_DEBUG_VXLAN
)
2139 zlog_debug ("%u:Add/Update neighbor %s MAC %s intf %s(%u) state 0x%x "
2141 ifp
->vrf_id
, ipaddr2str (ip
, buf2
, sizeof(buf2
)),
2142 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2143 ifp
->name
, ifp
->ifindex
, state
,
2144 ext_learned
? "ext-learned " : "", zvni
->vni
);
2146 /* If same entry already exists, it might be a change or it might be a
2147 * move from remote to local.
2149 n
= zvni_neigh_lookup (zvni
, ip
);
2152 if (CHECK_FLAG (n
->flags
, ZEBRA_NEIGH_LOCAL
))
2154 if (memcmp (n
->emac
.octet
, macaddr
->octet
, ETHER_ADDR_LEN
) == 0)
2156 if (n
->ifindex
== ifp
->ifindex
)
2157 /* we're not interested in whatever has changed. */
2159 /* client doesn't care about a purely local change. */
2163 /* If the MAC has changed, issue a delete first as this means a
2164 * different MACIP route.
2168 else if (ext_learned
)
2169 /* The neighbor is remote and that is the notification we got. */
2171 /* TODO: Evaluate if we need to do anything here. */
2175 /* Neighbor has moved from remote to local. */
2177 UNSET_FLAG (n
->flags
, ZEBRA_NEIGH_REMOTE
);
2178 n
->r_vtep_ip
.s_addr
= 0;
2183 n
= zvni_neigh_add (zvni
, ip
);
2186 zlog_err ("%u:Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
2187 ifp
->vrf_id
, ipaddr2str (ip
, buf2
, sizeof(buf2
)),
2188 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2189 ifp
->name
, ifp
->ifindex
, zvni
->vni
);
2194 /* Issue delete for older info, if needed. */
2196 zvni_neigh_send_del_to_client (zvrf
, zvni
->vni
, &n
->ip
, &n
->emac
);
2198 /* Set "local" forwarding info. */
2199 SET_FLAG (n
->flags
, ZEBRA_NEIGH_LOCAL
);
2200 memcpy (&n
->emac
, macaddr
, ETHER_ADDR_LEN
);
2201 n
->ifindex
= ifp
->ifindex
;
2203 /* Inform BGP if required. */
2205 return zvni_neigh_send_add_to_client (zvrf
, zvni
->vni
, ip
, macaddr
);
2211 * Handle message from client to delete a remote MACIP for a VNI.
2213 int zebra_vxlan_remote_macip_del (struct zserv
*client
, int sock
,
2214 u_short length
, struct zebra_vrf
*zvrf
)
2218 struct ethaddr macaddr
;
2220 struct in_addr vtep_ip
;
2224 u_short l
= 0, ipa_len
;
2225 char buf
[ETHER_ADDR_STRLEN
];
2226 char buf1
[INET6_ADDRSTRLEN
];
2232 /* Obtain each remote MACIP and process. */
2233 /* Message contains VNI, followed by MAC followed by IP (if any)
2234 * followed by remote VTEP IP.
2238 memset (&ip
, 0, sizeof (ip
));
2239 vni
= (vni_t
) stream_getl (s
);
2240 stream_get (&macaddr
.octet
, s
, ETHER_ADDR_LEN
);
2241 ipa_len
= stream_getl (s
);
2244 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
: IPADDR_V6
;
2245 stream_get (&ip
.ip
.addr
, s
, ipa_len
);
2247 l
+= 4 + ETHER_ADDR_LEN
+ 4 + ipa_len
;
2248 vtep_ip
.s_addr
= stream_get_ipv4(s
);
2249 l
+= IPV4_MAX_BYTELEN
;
2251 if (IS_ZEBRA_DEBUG_VXLAN
)
2252 zlog_debug ("%u:Recv MACIP Del MAC %s IP %s VNI %u Remote VTEP %s from %s",
2254 prefix_mac2str (&macaddr
, buf
, sizeof (buf
)),
2255 ipaddr2str (&ip
, buf1
, sizeof (buf1
)),
2256 vni
, inet_ntoa (vtep_ip
),
2257 zebra_route_string (client
->proto
));
2259 /* Locate VNI hash entry - expected to exist. */
2260 zvni
= zvni_lookup (zvrf
, vni
);
2263 if (IS_ZEBRA_DEBUG_VXLAN
)
2264 zlog_debug ("Failed to locate VNI hash upon remote MACIP DEL, "
2265 "VRF %d VNI %u", zvrf_id (zvrf
), vni
);
2268 if (!zvni
->vxlan_if
)
2270 zlog_err ("VNI %u hash %p doesn't have intf upon remote MACIP DEL",
2275 /* The remote VTEP specified is normally expected to exist, but it is
2276 * possible that the peer may delete the VTEP before deleting any MACs
2277 * referring to the VTEP, in which case the handler (see remote_vtep_del)
2278 * would have already deleted the MACs.
2280 if (!zvni_vtep_find (zvni
, &vtep_ip
))
2283 /* If the local VxLAN interface is not up (should be a transient
2284 * event), there's nothing more to do.
2286 if (!if_is_operative (zvni
->vxlan_if
))
2289 mac
= zvni_mac_lookup (zvni
, &macaddr
);
2291 n
= zvni_neigh_lookup (zvni
, &ip
);
2295 zlog_err ("failed to locate MAC %s for neigh %s in VRF %u VNI %u",
2296 prefix_mac2str (&macaddr
, buf
, sizeof (buf
)),
2297 ipaddr2str (&ip
, buf1
, sizeof (buf1
)),
2298 zvrf_id (zvrf
), vni
);
2302 /* If the remote mac or neighbor doesn't exist there is nothing more
2303 * to do. Otherwise, uninstall the entry and then remove it.
2308 /* Uninstall remote neighbor or MAC. */
2311 /* When the MAC changes for an IP, it is possible the client may
2312 * update the new MAC before trying to delete the "old" neighbor
2313 * (as these are two different MACIP routes). Do the delete only
2314 * if the MAC matches.
2316 if (CHECK_FLAG (n
->flags
, ZEBRA_NEIGH_REMOTE
) &&
2317 (memcmp (n
->emac
.octet
, macaddr
.octet
, ETHER_ADDR_LEN
) == 0))
2319 zvni_neigh_uninstall (zvni
, n
);
2320 zvni_neigh_del (zvni
, n
);
2321 zvni_deref_ip2mac (zvni
, mac
, 1);
2326 if (CHECK_FLAG (mac
->flags
, ZEBRA_MAC_REMOTE
))
2328 if (!mac
->neigh_refcnt
)
2330 zvni_mac_uninstall (zvni
, mac
, 0);
2331 zvni_mac_del (zvni
, mac
);
2334 SET_FLAG (mac
->flags
, ZEBRA_MAC_AUTO
);
2343 * Handle message from client to add a remote MACIP for a VNI. This
2344 * could be just the add of a MAC address or the add of a neighbor
2348 zebra_vxlan_remote_macip_add (struct zserv
*client
, int sock
,
2349 u_short length
, struct zebra_vrf
*zvrf
)
2353 struct ethaddr macaddr
;
2355 struct in_addr vtep_ip
;
2357 zebra_vtep_t
*zvtep
;
2358 zebra_mac_t
*mac
, *old_mac
;
2360 u_short l
= 0, ipa_len
;
2361 int update_mac
= 0, update_neigh
= 0;
2362 char buf
[ETHER_ADDR_STRLEN
];
2363 char buf1
[INET6_ADDRSTRLEN
];
2366 assert (EVPN_ENABLED (zvrf
));
2372 /* Obtain each remote MACIP and process. */
2373 /* Message contains VNI, followed by MAC followed by IP (if any)
2374 * followed by remote VTEP IP.
2376 update_mac
= update_neigh
= 0;
2379 memset (&ip
, 0, sizeof (ip
));
2380 vni
= (vni_t
) stream_getl (s
);
2381 stream_get (&macaddr
.octet
, s
, ETHER_ADDR_LEN
);
2382 ipa_len
= stream_getl (s
);
2385 ip
.ipa_type
= (ipa_len
== IPV4_MAX_BYTELEN
) ? IPADDR_V4
: IPADDR_V6
;
2386 stream_get (&ip
.ip
.addr
, s
, ipa_len
);
2388 l
+= 4 + ETHER_ADDR_LEN
+ 4 + ipa_len
;
2389 vtep_ip
.s_addr
= stream_get_ipv4 (s
);
2390 l
+= IPV4_MAX_BYTELEN
;
2392 /* Get 'sticky' flag. */
2393 sticky
= stream_getc(s
);
2396 if (IS_ZEBRA_DEBUG_VXLAN
)
2397 zlog_debug ("%u:Recv MACIP Add %sMAC %s IP %s VNI %u Remote VTEP %s from %s",
2399 sticky
? "sticky " : "",
2400 prefix_mac2str (&macaddr
, buf
, sizeof (buf
)),
2401 ipaddr2str (&ip
, buf1
, sizeof (buf1
)),
2402 vni
, inet_ntoa (vtep_ip
),
2403 zebra_route_string (client
->proto
));
2405 /* Locate VNI hash entry - expected to exist. */
2406 zvni
= zvni_lookup (zvrf
, vni
);
2409 zlog_err ("Failed to locate VNI hash upon remote MACIP ADD, VRF %d VNI %u",
2410 zvrf_id (zvrf
), vni
);
2413 if (!zvni
->vxlan_if
)
2415 zlog_err ("VNI %u hash %p doesn't have intf upon remote MACIP add",
2419 /* If the local VxLAN interface is not up (should be a transient
2420 * event), there's nothing more to do.
2422 if (!if_is_operative (zvni
->vxlan_if
))
2425 /* The remote VTEP specified should normally exist, but it is possible
2426 * that when peering comes up, peer may advertise MACIP routes before
2427 * advertising type-3 routes.
2429 zvtep
= zvni_vtep_find (zvni
, &vtep_ip
);
2432 if (zvni_vtep_add (zvni
, &vtep_ip
) == NULL
)
2434 zlog_err ("Failed to add remote VTEP, VRF %d VNI %u zvni %p",
2435 zvrf_id (zvrf
), vni
, zvni
);
2439 zvni_vtep_install (zvni
, &vtep_ip
);
2442 /* First, check if the remote MAC is unknown or has a change. If so,
2443 * that needs to be updated first. Note that client could install
2444 * MAC and MACIP separately or just install the latter.
2446 mac
= zvni_mac_lookup (zvni
, &macaddr
);
2447 if (!mac
|| !CHECK_FLAG (mac
->flags
, ZEBRA_MAC_REMOTE
) ||
2448 (CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0) != sticky
||
2449 !IPV4_ADDR_SAME(&mac
->fwd_info
.r_vtep_ip
, &vtep_ip
))
2456 mac
= zvni_mac_add (zvni
, &macaddr
);
2459 zlog_warn ("%u:Failed to add MAC %s VNI %u Remote VTEP %s",
2461 prefix_mac2str (&macaddr
, buf
, sizeof (buf
)),
2462 vni
, inet_ntoa (vtep_ip
));
2466 /* Is this MAC created for a MACIP? */
2468 SET_FLAG (mac
->flags
, ZEBRA_MAC_AUTO
);
2470 else if (CHECK_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
))
2472 /* Moving from local to remote, issue delete. */
2473 zvni_mac_uninstall (zvni
, mac
, 1);
2476 /* Set "auto" and "remote" forwarding info. */
2477 UNSET_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
);
2478 memset (&mac
->fwd_info
, 0, sizeof (mac
->fwd_info
));
2479 SET_FLAG (mac
->flags
, ZEBRA_MAC_REMOTE
);
2480 mac
->fwd_info
.r_vtep_ip
= vtep_ip
;
2483 SET_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
);
2485 UNSET_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
);
2487 /* Install the entry. */
2488 zvni_mac_install (zvni
, mac
);
2491 /* If there is no IP, continue - after clearing AUTO flag of MAC. */
2494 UNSET_FLAG (mac
->flags
, ZEBRA_MAC_AUTO
);
2498 /* Check if the remote neighbor itself is unknown or has a change.
2499 * If so, create or update and then install the entry.
2501 n
= zvni_neigh_lookup (zvni
, &ip
);
2502 if (!n
|| !CHECK_FLAG (n
->flags
, ZEBRA_NEIGH_REMOTE
) ||
2503 (memcmp(&n
->emac
, &macaddr
, sizeof (macaddr
)) != 0) ||
2504 !IPV4_ADDR_SAME(&n
->r_vtep_ip
, &vtep_ip
))
2511 n
= zvni_neigh_add (zvni
, &ip
);
2514 zlog_warn ("%u:Failed to add Neigh %s MAC %s VNI %u Remote VTEP %s",
2515 zvrf_id (zvrf
), ipaddr2str (&ip
, buf1
, sizeof (buf1
)),
2516 prefix_mac2str (&macaddr
, buf
, sizeof (buf
)),
2517 vni
, inet_ntoa (vtep_ip
));
2521 /* New neighbor referring to this MAC. */
2522 mac
->neigh_refcnt
++;
2524 else if (memcmp(&n
->emac
, &macaddr
, sizeof (macaddr
)) != 0)
2526 /* MAC change, update ref counts for old and new MAC. */
2527 old_mac
= zvni_mac_lookup (zvni
, &n
->emac
);
2529 zvni_deref_ip2mac (zvni
, old_mac
, 1);
2530 mac
->neigh_refcnt
++;
2533 /* Set "remote" forwarding info. */
2534 UNSET_FLAG (n
->flags
, ZEBRA_NEIGH_LOCAL
);
2535 /* TODO: Handle MAC change. */
2536 memcpy (&n
->emac
, &macaddr
, ETHER_ADDR_LEN
);
2537 n
->r_vtep_ip
= vtep_ip
;
2538 SET_FLAG (n
->flags
, ZEBRA_NEIGH_REMOTE
);
2540 /* Install the entry. */
2541 zvni_neigh_install (zvni
, n
);
2549 * Handle notification of MAC add/update over VxLAN. If the kernel is notifying
2550 * us, this must involve a multihoming scenario. Treat this as implicit delete
2551 * of any prior local MAC.
2554 zebra_vxlan_check_del_local_mac (struct interface
*ifp
,
2555 struct interface
*br_if
,
2556 struct ethaddr
*macaddr
,
2559 struct zebra_if
*zif
;
2560 struct zebra_vrf
*zvrf
;
2561 struct zebra_l2info_vxlan
*vxl
;
2565 char buf
[ETHER_ADDR_STRLEN
];
2570 vxl
= &zif
->l2info
.vxl
;
2573 /* Locate VRF corresponding to interface. */
2574 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
2577 /* If EVPN is not enabled, nothing to do. */
2578 if (!EVPN_ENABLED(zvrf
))
2581 /* Locate hash entry; it is expected to exist. */
2582 zvni
= zvni_lookup (zvrf
, vni
);
2586 /* If entry doesn't exist, nothing to do. */
2587 mac
= zvni_mac_lookup (zvni
, macaddr
);
2591 /* Is it a local entry? */
2592 if (!CHECK_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
))
2595 if (IS_ZEBRA_DEBUG_VXLAN
)
2596 zlog_debug ("%u:Add/update remote MAC %s intf %s(%u) VNI %u - del local",
2597 ifp
->vrf_id
, prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2598 ifp
->name
, ifp
->ifindex
, vni
);
2600 /* Remove MAC from BGP. */
2601 sticky
= CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0;
2602 zvni_mac_send_del_to_client (zvrf
, zvni
->vni
, macaddr
, sticky
);
2604 /* Delete this MAC entry. */
2605 zvni_mac_del (zvni
, mac
);
2611 * Handle remote MAC delete by kernel; readd the remote MAC if we have it.
2612 * This can happen because the remote MAC entries are also added as "dynamic",
2613 * so the kernel can ageout the entry.
2616 zebra_vxlan_check_readd_remote_mac (struct interface
*ifp
,
2617 struct interface
*br_if
,
2618 struct ethaddr
*macaddr
,
2621 struct zebra_if
*zif
;
2622 struct zebra_vrf
*zvrf
;
2623 struct zebra_l2info_vxlan
*vxl
;
2627 char buf
[ETHER_ADDR_STRLEN
];
2631 vxl
= &zif
->l2info
.vxl
;
2634 /* Locate VRF corresponding to interface. */
2635 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
2638 /* If EVPN is not enabled, nothing to do. */
2639 if (!EVPN_ENABLED(zvrf
))
2642 /* Locate hash entry; it is expected to exist. */
2643 zvni
= zvni_lookup (zvrf
, vni
);
2647 /* If entry doesn't exist, nothing to do. */
2648 mac
= zvni_mac_lookup (zvni
, macaddr
);
2652 /* Is it a remote entry? */
2653 if (!CHECK_FLAG (mac
->flags
, ZEBRA_MAC_REMOTE
))
2656 if (IS_ZEBRA_DEBUG_VXLAN
)
2657 zlog_debug ("%u:Del remote MAC %s intf %s(%u) VNI %u - readd",
2658 ifp
->vrf_id
, prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2659 ifp
->name
, ifp
->ifindex
, vni
);
2661 zvni_mac_install (zvni
, mac
);
2666 * Handle local MAC delete (on a port or VLAN corresponding to this VNI).
2669 zebra_vxlan_local_mac_del (struct interface
*ifp
, struct interface
*br_if
,
2670 struct ethaddr
*macaddr
, vlanid_t vid
)
2674 struct zebra_vrf
*zvrf
;
2675 char buf
[ETHER_ADDR_STRLEN
];
2678 /* We are interested in MACs only on ports or (port, VLAN) that
2681 zvni
= zvni_map_vlan (ifp
, br_if
, vid
);
2684 if (!zvni
->vxlan_if
)
2686 zlog_err ("VNI %u hash %p doesn't have intf upon local MAC DEL",
2691 if (IS_ZEBRA_DEBUG_VXLAN
)
2692 zlog_debug ("%u:Del MAC %s intf %s(%u) VID %u -> VNI %u",
2693 ifp
->vrf_id
, prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2694 ifp
->name
, ifp
->ifindex
, vid
, zvni
->vni
);
2696 /* If entry doesn't exist, nothing to do. */
2697 mac
= zvni_mac_lookup (zvni
, macaddr
);
2701 /* Is it a local entry? */
2702 if (!CHECK_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
))
2705 /* Locate VRF corresponding to interface. */
2706 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
2709 /* Remove MAC from BGP. */
2710 sticky
= CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0;
2711 zvni_mac_send_del_to_client (zvrf
, zvni
->vni
, macaddr
, sticky
);
2713 /* Delete this MAC entry. */
2714 zvni_mac_del (zvni
, mac
);
2720 * Handle local MAC add (on a port or VLAN corresponding to this VNI).
2723 zebra_vxlan_local_mac_add_update (struct interface
*ifp
, struct interface
*br_if
,
2724 struct ethaddr
*macaddr
, vlanid_t vid
,
2729 struct zebra_vrf
*zvrf
;
2730 char buf
[ETHER_ADDR_STRLEN
];
2734 /* We are interested in MACs only on ports or (port, VLAN) that
2737 zvni
= zvni_map_vlan (ifp
, br_if
, vid
);
2740 if (IS_ZEBRA_DEBUG_VXLAN
)
2741 zlog_debug ("%u:Add/Update %sMAC %s intf %s(%u) VID %u, could not find VNI",
2743 sticky
? "sticky " : "",
2744 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2745 ifp
->name
, ifp
->ifindex
, vid
);
2749 if (!zvni
->vxlan_if
)
2751 zlog_err ("VNI %u hash %p doesn't have intf upon local MAC ADD",
2756 if (IS_ZEBRA_DEBUG_VXLAN
)
2757 zlog_debug ("%u:Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u",
2759 sticky
? "sticky " : "",
2760 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2761 ifp
->name
, ifp
->ifindex
, vid
, zvni
->vni
);
2763 /* If same entry already exists, nothing to do. */
2764 mac
= zvni_mac_lookup (zvni
, macaddr
);
2767 if (CHECK_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
))
2769 mac_sticky
= CHECK_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
) ? 1: 0;
2771 if (mac_sticky
== sticky
&&
2772 mac
->fwd_info
.local
.ifindex
== ifp
->ifindex
&&
2773 mac
->fwd_info
.local
.vid
== vid
)
2775 if (IS_ZEBRA_DEBUG_VXLAN
)
2776 zlog_debug ("%u:Add/Update %sMAC %s intf %s(%u) VID %u -> VNI %u, "
2777 "entry exists and has not changed ",
2779 sticky
? "sticky " : "",
2780 prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2781 ifp
->name
, ifp
->ifindex
, vid
, zvni
->vni
);
2785 add
= 0; /* This is an update of local interface. */
2789 /* Locate VRF corresponding to interface. */
2790 zvrf
= vrf_info_lookup(zvni
->vxlan_if
->vrf_id
);
2795 mac
= zvni_mac_add (zvni
, macaddr
);
2798 zlog_err ("%u:Failed to add MAC %s intf %s(%u) VID %u",
2799 ifp
->vrf_id
, prefix_mac2str (macaddr
, buf
, sizeof (buf
)),
2800 ifp
->name
, ifp
->ifindex
, vid
);
2805 /* Set "local" forwarding info. */
2806 UNSET_FLAG (mac
->flags
, ZEBRA_MAC_REMOTE
);
2807 memset (&mac
->fwd_info
, 0, sizeof (mac
->fwd_info
));
2808 SET_FLAG (mac
->flags
, ZEBRA_MAC_LOCAL
);
2809 mac
->fwd_info
.local
.ifindex
= ifp
->ifindex
;
2810 mac
->fwd_info
.local
.vid
= vid
;
2813 SET_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
);
2815 UNSET_FLAG (mac
->flags
, ZEBRA_MAC_STICKY
);
2817 /* Inform BGP if required. */
2819 return zvni_mac_send_add_to_client (zvrf
, zvni
->vni
, macaddr
, sticky
);
2825 * Handle message from client to delete a remote VTEP for a VNI.
2827 int zebra_vxlan_remote_vtep_del (struct zserv
*client
, int sock
,
2828 u_short length
, struct zebra_vrf
*zvrf
)
2833 struct in_addr vtep_ip
;
2835 zebra_vtep_t
*zvtep
;
2841 /* Obtain each remote VTEP and process. */
2842 vni
= (vni_t
) stream_getl (s
);
2844 vtep_ip
.s_addr
= stream_get_ipv4 (s
);
2845 l
+= IPV4_MAX_BYTELEN
;
2847 if (IS_ZEBRA_DEBUG_VXLAN
)
2848 zlog_debug ("%u:Recv VTEP_DEL %s VNI %u from %s",
2849 zvrf_id (zvrf
), inet_ntoa (vtep_ip
),
2850 vni
, zebra_route_string (client
->proto
));
2852 /* Locate VNI hash entry - expected to exist. */
2853 zvni
= zvni_lookup (zvrf
, vni
);
2856 if (IS_ZEBRA_DEBUG_VXLAN
)
2857 zlog_debug ("Failed to locate VNI hash upon remote VTEP DEL, "
2858 "VRF %d VNI %u", zvrf_id (zvrf
), vni
);
2862 /* If the remote VTEP does not exist, there's nothing more to do.
2863 * Otherwise, uninstall any remote MACs pointing to this VTEP and
2864 * then, the VTEP entry itself and remove it.
2866 zvtep
= zvni_vtep_find (zvni
, &vtep_ip
);
2870 zvni_neigh_del_from_vtep (zvni
, 1, &vtep_ip
);
2871 zvni_mac_del_from_vtep (zvni
, 1, &vtep_ip
);
2872 zvni_vtep_uninstall (zvni
, &vtep_ip
);
2873 zvni_vtep_del (zvni
, zvtep
);
2880 * Handle message from client to add a remote VTEP for a VNI.
2882 int zebra_vxlan_remote_vtep_add (struct zserv
*client
, int sock
,
2883 u_short length
, struct zebra_vrf
*zvrf
)
2888 struct in_addr vtep_ip
;
2891 assert (EVPN_ENABLED (zvrf
));
2897 /* Obtain each remote VTEP and process. */
2898 vni
= (vni_t
) stream_getl (s
);
2900 vtep_ip
.s_addr
= stream_get_ipv4 (s
);
2901 l
+= IPV4_MAX_BYTELEN
;
2903 if (IS_ZEBRA_DEBUG_VXLAN
)
2904 zlog_debug ("%u:Recv VTEP_ADD %s VNI %u from %s",
2905 zvrf_id (zvrf
), inet_ntoa (vtep_ip
),
2906 vni
, zebra_route_string (client
->proto
));
2908 /* Locate VNI hash entry - expected to exist. */
2909 zvni
= zvni_lookup (zvrf
, vni
);
2912 zlog_err ("Failed to locate VNI hash upon remote VTEP ADD, VRF %d VNI %u",
2913 zvrf_id (zvrf
), vni
);
2916 if (!zvni
->vxlan_if
)
2918 zlog_err ("VNI %u hash %p doesn't have intf upon remote VTEP ADD",
2924 /* If the remote VTEP already exists, or the local VxLAN interface is
2925 * not up (should be a transient event), there's nothing more to do.
2926 * Otherwise, add and install the entry.
2928 if (zvni_vtep_find (zvni
, &vtep_ip
))
2931 if (!if_is_operative (zvni
->vxlan_if
))
2934 if (zvni_vtep_add (zvni
, &vtep_ip
) == NULL
)
2936 zlog_err ("Failed to add remote VTEP, VRF %d VNI %u zvni %p",
2937 zvrf_id (zvrf
), vni
, zvni
);
2941 zvni_vtep_install (zvni
, &vtep_ip
);
2948 * Handle SVI interface going down. At this point, this is a NOP since
2949 * the kernel deletes the neighbor entries on this SVI (if any).
2952 zebra_vxlan_svi_down (struct interface
*ifp
, struct interface
*link_if
)
2958 * Handle SVI interface coming up. This may or may not be of interest,
2959 * but if this is a SVI on a VxLAN bridge, we need to install any remote
2960 * neighbor entries (which will be used for EVPN ARP suppression).
2963 zebra_vxlan_svi_up (struct interface
*ifp
, struct interface
*link_if
)
2966 struct neigh_walk_ctx n_wctx
;
2968 zvni
= zvni_map_svi (ifp
, link_if
);
2972 if (!zvni
->vxlan_if
)
2974 zlog_err ("VNI %u hash %p doesn't have intf upon SVI up",
2979 if (IS_ZEBRA_DEBUG_VXLAN
)
2980 zlog_debug ("%u:SVI %s(%u) VNI %u is UP, installing neighbors",
2981 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, zvni
->vni
);
2983 /* Install any remote neighbors for this VNI. */
2984 memset (&n_wctx
, 0, sizeof (struct neigh_walk_ctx
));
2986 hash_iterate(zvni
->neigh_table
, zvni_install_neigh_hash
, &n_wctx
);
2992 * Handle VxLAN interface down - update BGP if required, and do
2996 zebra_vxlan_if_down (struct interface
*ifp
)
2998 struct zebra_if
*zif
;
2999 struct zebra_vrf
*zvrf
;
3001 struct zebra_l2info_vxlan
*vxl
;
3004 /* Locate VRF corresponding to interface. */
3005 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
3008 /* If EVPN is not enabled, nothing further to be done. */
3009 if (!EVPN_ENABLED(zvrf
))
3014 vxl
= &zif
->l2info
.vxl
;
3017 if (IS_ZEBRA_DEBUG_VXLAN
)
3018 zlog_debug ("%u:Intf %s(%u) VNI %u is DOWN",
3019 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3021 /* Locate hash entry; it is expected to exist. */
3022 zvni
= zvni_lookup (zvrf
, vni
);
3025 zlog_err ("Failed to locate VNI hash at DOWN, VRF %d IF %s(%u) VNI %u",
3026 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3030 assert (zvni
->vxlan_if
== ifp
);
3032 /* Delete this VNI from BGP. */
3033 zvni_send_del_to_client (zvrf
, zvni
->vni
);
3035 /* Free up all neighbors and MACs, if any. */
3036 zvni_neigh_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_NEIGH
);
3037 zvni_mac_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_MAC
);
3039 /* Free up all remote VTEPs, if any. */
3040 zvni_vtep_del_all (zvni
, 1);
3046 * Handle VxLAN interface up - update BGP if required.
3049 zebra_vxlan_if_up (struct interface
*ifp
)
3051 struct zebra_if
*zif
;
3052 struct zebra_vrf
*zvrf
;
3054 struct zebra_l2info_vxlan
*vxl
;
3057 /* Locate VRF corresponding to interface. */
3058 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
3061 /* If EVPN is not enabled, nothing further to be done. */
3062 if (!EVPN_ENABLED(zvrf
))
3067 vxl
= &zif
->l2info
.vxl
;
3070 if (IS_ZEBRA_DEBUG_VXLAN
)
3071 zlog_debug ("%u:Intf %s(%u) VNI %u is UP",
3072 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3074 /* Locate hash entry; it is expected to exist. */
3075 zvni
= zvni_lookup (zvrf
, vni
);
3078 zlog_err ("Failed to locate VNI hash at UP, VRF %d IF %s(%u) VNI %u",
3079 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3083 assert (zvni
->vxlan_if
== ifp
);
3085 /* If part of a bridge, inform BGP about this VNI. */
3086 /* Also, read and populate local MACs and neighbors. */
3087 if (zif
->brslave_info
.br_if
)
3089 zvni_send_add_to_client (zvrf
, zvni
);
3090 zvni_read_mac_neigh (zvrf
, zvni
, ifp
);
3097 * Handle VxLAN interface delete. Locate and remove entry in hash table
3098 * and update BGP, if required.
3101 zebra_vxlan_if_del (struct interface
*ifp
)
3103 struct zebra_if
*zif
;
3104 struct zebra_vrf
*zvrf
;
3106 struct zebra_l2info_vxlan
*vxl
;
3109 /* Locate VRF corresponding to interface. */
3110 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
3113 /* If EVPN is not enabled, nothing further to be done. */
3114 if (!EVPN_ENABLED(zvrf
))
3119 vxl
= &zif
->l2info
.vxl
;
3122 if (IS_ZEBRA_DEBUG_VXLAN
)
3123 zlog_debug ("%u:Del VNI %u intf %s(%u)",
3124 ifp
->vrf_id
, vni
, ifp
->name
, ifp
->ifindex
);
3126 /* Locate hash entry; it is expected to exist. */
3127 zvni
= zvni_lookup (zvrf
, vni
);
3130 zlog_err ("Failed to locate VNI hash at del, VRF %d IF %s(%u) VNI %u",
3131 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3135 /* Delete VNI from BGP. */
3136 zvni_send_del_to_client (zvrf
, zvni
->vni
);
3138 /* Free up all neighbors and MAC, if any. */
3139 zvni_neigh_del_all (zvrf
, zvni
, 0, 0, DEL_ALL_NEIGH
);
3140 zvni_mac_del_all (zvrf
, zvni
, 0, 0, DEL_ALL_MAC
);
3142 /* Free up all remote VTEPs, if any. */
3143 zvni_vtep_del_all (zvni
, 0);
3145 /* Delete the hash entry. */
3146 if (zvni_del (zvrf
, zvni
))
3148 zlog_err ("Failed to del VNI hash %p, VRF %d IF %s(%u) VNI %u",
3149 zvni
, ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, zvni
->vni
);
3157 * Handle VxLAN interface update - change to tunnel IP, master or VLAN.
3160 zebra_vxlan_if_update (struct interface
*ifp
, u_int16_t chgflags
)
3162 struct zebra_if
*zif
;
3163 struct zebra_vrf
*zvrf
;
3165 struct zebra_l2info_vxlan
*vxl
;
3168 /* Locate VRF corresponding to interface. */
3169 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
3172 /* If EVPN is not enabled, nothing further to be done. */
3173 if (!EVPN_ENABLED(zvrf
))
3178 vxl
= &zif
->l2info
.vxl
;
3181 /* Update VNI hash. */
3182 zvni
= zvni_lookup (zvrf
, vni
);
3185 zlog_err ("Failed to find VNI hash on update, VRF %d IF %s(%u) VNI %u",
3186 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3190 if (IS_ZEBRA_DEBUG_VXLAN
)
3191 zlog_debug ("%u:Update VNI %u intf %s(%u) VLAN %u local IP %s "
3192 "master %u chg 0x%x",
3193 ifp
->vrf_id
, vni
, ifp
->name
, ifp
->ifindex
,
3194 vxl
->access_vlan
, inet_ntoa (vxl
->vtep_ip
),
3195 zif
->brslave_info
.bridge_ifindex
, chgflags
);
3197 /* Removed from bridge? */
3198 if ((chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
) &&
3199 (zif
->brslave_info
.bridge_ifindex
== IFINDEX_INTERNAL
))
3201 /* Delete from client, remove all remote VTEPs */
3202 /* Also, free up all MACs and neighbors. */
3203 zvni_send_del_to_client (zvrf
, zvni
->vni
);
3204 zvni_neigh_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_NEIGH
);
3205 zvni_mac_del_all (zvrf
, zvni
, 1, 0, DEL_ALL_MAC
);
3206 zvni_vtep_del_all (zvni
, 1);
3208 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
)
3210 /* Remove all existing local neighbors and MACs for this VNI
3211 * (including from BGP)
3213 zvni_neigh_del_all (zvrf
, zvni
, 0, 1, DEL_LOCAL_MAC
);
3214 zvni_mac_del_all (zvrf
, zvni
, 0, 1, DEL_LOCAL_MAC
);
3217 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
3218 zvni
->vxlan_if
= ifp
;
3220 /* Take further actions needed. Note that if we are here, there is a
3221 * change of interest.
3223 /* If down or not mapped to a bridge, we're done. */
3224 if (!if_is_operative (ifp
) || !zif
->brslave_info
.br_if
)
3227 /* Inform BGP, if there is a change of interest. */
3228 if (chgflags
& (ZEBRA_VXLIF_MASTER_CHANGE
| ZEBRA_VXLIF_LOCAL_IP_CHANGE
))
3229 zvni_send_add_to_client (zvrf
, zvni
);
3231 /* If there is a valid new master or a VLAN mapping change, read and
3232 * populate local MACs and neighbors. Also, reinstall any remote MACs
3233 * and neighbors for this VNI (based on new VLAN).
3235 if (chgflags
& ZEBRA_VXLIF_MASTER_CHANGE
)
3236 zvni_read_mac_neigh (zvrf
, zvni
, ifp
);
3237 else if (chgflags
& ZEBRA_VXLIF_VLAN_CHANGE
)
3239 struct mac_walk_ctx m_wctx
;
3240 struct neigh_walk_ctx n_wctx
;
3242 zvni_read_mac_neigh (zvrf
, zvni
, ifp
);
3244 memset (&m_wctx
, 0, sizeof (struct mac_walk_ctx
));
3246 hash_iterate(zvni
->mac_table
, zvni_install_mac_hash
, &m_wctx
);
3248 memset (&n_wctx
, 0, sizeof (struct neigh_walk_ctx
));
3250 hash_iterate(zvni
->neigh_table
, zvni_install_neigh_hash
, &n_wctx
);
3257 * Handle VxLAN interface add.
3260 zebra_vxlan_if_add (struct interface
*ifp
)
3262 struct zebra_if
*zif
;
3263 struct zebra_vrf
*zvrf
;
3265 struct zebra_l2info_vxlan
*vxl
;
3268 /* Locate VRF corresponding to interface. */
3269 zvrf
= vrf_info_lookup(ifp
->vrf_id
);
3272 /* If EVPN is not enabled, nothing further to be done. */
3273 if (!EVPN_ENABLED(zvrf
))
3278 vxl
= &zif
->l2info
.vxl
;
3281 if (IS_ZEBRA_DEBUG_VXLAN
)
3282 zlog_debug ("%u:Add VNI %u intf %s(%u) VLAN %u local IP %s master %u",
3283 ifp
->vrf_id
, vni
, ifp
->name
, ifp
->ifindex
,
3284 vxl
->access_vlan
, inet_ntoa (vxl
->vtep_ip
),
3285 zif
->brslave_info
.bridge_ifindex
);
3287 /* Create or update VNI hash. */
3288 zvni
= zvni_lookup (zvrf
, vni
);
3291 zvni
= zvni_add (zvrf
, vni
);
3294 zlog_err ("Failed to add VNI hash, VRF %d IF %s(%u) VNI %u",
3295 ifp
->vrf_id
, ifp
->name
, ifp
->ifindex
, vni
);
3300 zvni
->local_vtep_ip
= vxl
->vtep_ip
;
3301 zvni
->vxlan_if
= ifp
;
3303 /* If down or not mapped to a bridge, we're done. */
3304 if (!if_is_operative (ifp
) || !zif
->brslave_info
.br_if
)
3308 zvni_send_add_to_client (zvrf
, zvni
);
3310 /* Read and populate local MACs and neighbors */
3311 zvni_read_mac_neigh (zvrf
, zvni
, ifp
);
3317 * Handle message from client to learn (or stop learning) about VNIs and MACs.
3318 * When enabled, the VNI hash table will be built and MAC FDB table read;
3319 * when disabled, the entries should be deleted and remote VTEPs and MACs
3320 * uninstalled from the kernel.
3322 int zebra_vxlan_advertise_all_vni (struct zserv
*client
, int sock
,
3323 u_short length
, struct zebra_vrf
*zvrf
)
3329 advertise
= stream_getc (s
);
3331 if (IS_ZEBRA_DEBUG_VXLAN
)
3332 zlog_debug ("%u:EVPN VNI Adv %s, currently %s",
3333 zvrf_id (zvrf
), advertise
? "enabled" : "disabled",
3334 EVPN_ENABLED(zvrf
) ? "enabled" : "disabled");
3336 if (zvrf
->advertise_all_vni
== advertise
)
3339 zvrf
->advertise_all_vni
= advertise
;
3340 if (EVPN_ENABLED(zvrf
))
3342 /* Build VNI hash table and inform BGP. */
3343 zvni_build_hash_table (zvrf
);
3345 /* Read the MAC FDB */
3346 macfdb_read (zvrf
->zns
);
3348 /* Read neighbors */
3349 neigh_read (zvrf
->zns
);
3353 /* Cleanup VTEPs for all VNIs - uninstall from
3354 * kernel and free entries.
3356 hash_iterate (zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);
3363 * Allocate VNI hash table for this VRF and do other initialization.
3364 * NOTE: Currently supported only for default VRF.
3367 zebra_vxlan_init_tables (struct zebra_vrf
*zvrf
)
3371 zvrf
->vni_table
= hash_create(vni_hash_keymake
,
3373 "Zebra VRF VNI Table");
3376 /* Close all VNI handling */
3378 zebra_vxlan_close_tables (struct zebra_vrf
*zvrf
)
3380 hash_iterate (zvrf
->vni_table
, zvni_cleanup_all
, zvrf
);