Skip to content

Commit

Permalink
zebra: Display local MAC cache
Browse files Browse the repository at this point in the history
Add vtysh handler and backend function to display the local
MAC cache.

Signed-off-by: Vivek Venkatraman <[email protected]>
  • Loading branch information
vivek-cumulus authored and sougata-github-nvidia committed Dec 3, 2024
1 parent 732c135 commit 489a332
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
57 changes: 57 additions & 0 deletions zebra/zebra_l2_bridge_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,27 @@
#include "zebra/zebra_evpn_vxlan.h"
#include "zebra/zebra_router.h"

static void zebra_l2_brvlan_print_mac_hash(struct hash_bucket *bucket,
void *ctxt)
{
struct zebra_l2_brvlan_mac_ctx *ctx;
struct vty *vty;
struct zebra_l2_brvlan_mac *bmac;
char buf[ETHER_ADDR_STRLEN];
struct interface *ifp;

ctx = (struct zebra_l2_brvlan_mac_ctx *)ctxt;
vty = (struct vty *)(ctx->arg);
bmac = (struct zebra_l2_brvlan_mac *)bucket->data;

prefix_mac2str(&bmac->macaddr, buf, sizeof(buf));
ifp = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT),
bmac->ifindex);

vty_out(vty, "%-17s %-7u %s\n", buf, bmac->ifindex,
ifp ? ifp->name : "-");
}

static unsigned int zebra_l2_bridge_vlan_hash_keymake(const void *p)
{
const struct zebra_l2_bridge_vlan *bvlan;
Expand All @@ -63,6 +84,42 @@ static unsigned int zebra_l2_bridge_vlan_hash_keymake(const void *p)
return jhash(&bvlan->vid, sizeof(bvlan->vid), 0);
}

void zebra_l2_brvlan_print_macs(struct vty *vty, struct interface *br_if,
vlanid_t vid, bool uj)
{
struct zebra_if *zif;
struct zebra_l2_bridge_if *br;
uint32_t num_macs;
struct zebra_l2_brvlan_mac_ctx ctx;

zif = (struct zebra_if *)br_if->info;
br = BRIDGE_FROM_ZEBRA_IF(zif);
if (!br) {
return;
}
if (!br->mac_table[vid]) {
vty_out(vty,
"%% bridge %s VID %u does not have a MAC hash table\n",
br_if->name, vid);
return;
}
num_macs = hashcount(br->mac_table[vid]);
if (!num_macs) {
vty_out(vty, "bridge %s VID %u - No local MACs\n", br_if->name,
vid);
return;
}

vty_out(vty, "bridge %s VID %u - Number of local MACs: %u\n",
br_if->name, vid, num_macs);
vty_out(vty, "%-17s %-7s %-30s\n", "MAC", "IfIndex", "Interface");
memset(&ctx, 0, sizeof(ctx));
ctx.br_if = br_if;
ctx.vid = vid;
ctx.arg = vty;
hash_iterate(br->mac_table[vid], zebra_l2_brvlan_print_mac_hash, &ctx);
}

static bool zebra_l2_bridge_vlan_hash_cmp(const void *p1, const void *p2)
{
const struct zebra_l2_bridge_vlan *bv1;
Expand Down
2 changes: 2 additions & 0 deletions zebra/zebra_l2_bridge_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ extern int
zebra_l2_bridge_if_vlan_access_bd_deref(struct zebra_evpn_access_bd *bd);
extern int
zebra_l2_bridge_if_vlan_access_bd_ref(struct zebra_evpn_access_bd *bd);
extern void zebra_l2_brvlan_print_macs(struct vty *vty, struct interface *br_if,
vlanid_t vid, bool uj);
extern int zebra_l2_bridge_if_del(struct interface *ifp);
extern int zebra_l2_bridge_if_add(struct interface *ifp);
extern int zebra_l2_bridge_if_cleanup(struct interface *ifp);
Expand Down
35 changes: 35 additions & 0 deletions zebra/zebra_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -3513,6 +3513,40 @@ DEFUN (show_evpn_neigh_vni_vtep,
return CMD_SUCCESS;
}

DEFPY(show_evpn_local_mac, show_evpn_local_mac_cmd,
"show evpn local-mac IFNAME$if_name (1-4094)$vid [json$json]",
SHOW_STR
"EVPN\n"
"Local MAC addresses\n"
"Interface Name\n"
"VLAN ID\n" JSON_STR)
{
struct vrf *vrf = NULL;
struct interface *ifp = NULL;
bool found = false;
bool uj = use_json(argc, argv);

if (!if_name || !vid) {
return CMD_WARNING;
}

RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
ifp = if_lookup_by_name(if_name, vrf->vrf_id);
if (ifp) {
found = true;
break;
}
}

if (!found) {
vty_out(vty, "%% Can't find interface %s\n", if_name);
return CMD_WARNING;
}

zebra_l2_brvlan_print_macs(vty, ifp, vid, uj);
return CMD_SUCCESS;
}

/* policy routing contexts */
DEFUN (show_pbr_ipset,
show_pbr_ipset_cmd,
Expand Down Expand Up @@ -4447,6 +4481,7 @@ void zebra_vty_init(void)
install_element(VIEW_NODE, &show_evpn_neigh_vni_vtep_cmd);
install_element(VIEW_NODE, &show_evpn_neigh_vni_dad_cmd);
install_element(VIEW_NODE, &show_evpn_neigh_vni_all_dad_cmd);
install_element(VIEW_NODE, &show_evpn_local_mac_cmd);
install_element(ENABLE_NODE, &clear_evpn_dup_addr_cmd);
install_element(CONFIG_NODE, &evpn_accept_bgp_seq_cmd);
install_element(CONFIG_NODE, &no_evpn_accept_bgp_seq_cmd);
Expand Down

0 comments on commit 489a332

Please sign in to comment.