Skip to content
Permalink
Browse files

bgpd: Add code to dump the forthcoming mac hash

Add a bit of code that allows us to dump the mac hash.  Future
commits will actually add entries to the mac hash and then operate
on it.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
  • Loading branch information...
donaldsharp committed Oct 12, 2018
1 parent 8cb687c commit 48ecf8f5109b1b1140859c01ec2a71fca88e1386
Showing with 150 additions and 0 deletions.
  1. +99 −0 bgpd/bgp_mac.c
  2. +27 −0 bgpd/bgp_mac.h
  3. +16 −0 bgpd/bgp_vty.c
  4. +3 −0 bgpd/bgpd.c
  5. +3 −0 bgpd/bgpd.h
  6. +2 −0 bgpd/subdir.am
@@ -0,0 +1,99 @@
/*
* BGPd - Mac hash code
* Copyright (C) 2018 Cumulus Networks, Inc.
* Donald Sharp
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <zebra.h>

#include <jhash.h>
#include <hash.h>
#include <prefix.h>
#include <memory.h>

#include "bgpd/bgpd.h"
#include "bgpd/bgp_mac.h"
#include "bgpd/bgp_memory.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_debug.h"

DEFINE_MTYPE_STATIC(BGPD, BSM, "Mac Hash Entry");

struct bgp_self_mac {
struct ethaddr macaddr;
struct list *ifp_list;
};

static unsigned int bgp_mac_hash_key_make(void *data)
{
struct bgp_self_mac *bsm = data;

return jhash(&bsm->macaddr, ETH_ALEN, 0xa5a5dead);
}

static bool bgp_mac_hash_cmp(const void *d1, const void *d2)
{
const struct bgp_self_mac *bsm1 = d1;
const struct bgp_self_mac *bsm2 = d2;

if (memcmp(&bsm1->macaddr, &bsm2->macaddr, ETH_ALEN) == 0)
return true;

return false;
}

void bgp_mac_init(void)
{
bm->self_mac_hash = hash_create(bgp_mac_hash_key_make, bgp_mac_hash_cmp,
"BGP MAC Hash");
}

static void bgp_mac_hash_free(void *data)
{
struct bgp_self_mac *bsm = data;

list_delete(&bsm->ifp_list);
XFREE(MTYPE_BSM, bsm);
}

void bgp_mac_finish(void)
{
hash_clean(bm->self_mac_hash, bgp_mac_hash_free);
hash_free(bm->self_mac_hash);
}

static void bgp_mac_show_mac_entry(struct hash_backet *backet, void *arg)
{
struct vty *vty = arg;
struct bgp_self_mac *bsm = backet->data;
struct listnode *node;
char *name;
char buf_mac[ETHER_ADDR_STRLEN];

vty_out(vty, "Mac Address: %s ",
prefix_mac2str(&bsm->macaddr, buf_mac, sizeof(buf_mac)));

for (ALL_LIST_ELEMENTS_RO(bsm->ifp_list, node, name))
vty_out(vty, "%s ", name);

vty_out(vty, "\n");
}

void bgp_mac_dump_table(struct vty *vty)
{
hash_iterate(bm->self_mac_hash, bgp_mac_show_mac_entry, vty);
}
@@ -0,0 +1,27 @@
/*
* BGPd - Mac hash header
* Copyright (C) 2018 Cumulus Networks, Inc.
* Donald Sharp
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; see the file COPYING; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef __BGP_MAC_H__
#define __BGP_MAC_H__

void bgp_mac_init(void);
void bgp_mac_finish(void);

void bgp_mac_dump_table(struct vty *vty);
#endif
@@ -37,6 +37,7 @@
#include "frrstr.h"

#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr_evpn.h"
#include "bgpd/bgp_advertise.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_aspath.h"
@@ -62,6 +63,7 @@
#include "bgpd/bgp_io.h"
#include "bgpd/bgp_evpn.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_mac.h"

static struct peer_group *listen_range_exists(struct bgp *bgp,
struct prefix *range, int exact);
@@ -7576,6 +7578,18 @@ DEFUN (show_bgp_vrfs,
return CMD_SUCCESS;
}

DEFUN (show_bgp_mac_hash,
show_bgp_mac_hash_cmd,
"show bgp mac hash",
SHOW_STR
BGP_STR
"Mac Address\n"
"Mac Address database\n")
{
bgp_mac_dump_table(vty);

return CMD_SUCCESS;
}

static void show_tip_entry(struct hash_backet *backet, void *args)
{
@@ -13835,6 +13849,8 @@ void bgp_vty_init(void)
/* "show bgp martian next-hop" */
install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);

install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);

/* "show [ip] bgp views" commands. */
install_element(VIEW_NODE, &show_bgp_views_cmd);

@@ -87,6 +87,7 @@
#include "bgpd/bgp_pbr.h"
#include "bgpd/bgp_addpath.h"
#include "bgpd/bgp_evpn_private.h"
#include "bgpd/bgp_mac.h"

DEFINE_MTYPE_STATIC(BGPD, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)");
DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information");
@@ -7775,6 +7776,7 @@ void bgp_master_init(struct thread_master *master)

bgp_process_queue_init();

bgp_mac_init();
/* init the rd id space.
assign 0th index in the bitfield,
so that we start with id 1
@@ -7964,4 +7966,5 @@ void bgp_terminate(void)
if (bm->t_rmap_update)
BGP_TIMER_OFF(bm->t_rmap_update);

bgp_mac_finish();
}
@@ -122,6 +122,9 @@ struct bgp_master {
/* Listener address */
char *address;

/* The Mac table */
struct hash *self_mac_hash;

/* BGP start time. */
time_t start_time;

@@ -72,6 +72,7 @@ bgpd_libbgp_a_SOURCES = \
bgpd/bgp_label.c \
bgpd/bgp_labelpool.c \
bgpd/bgp_lcommunity.c \
bgpd/bgp_mac.c \
bgpd/bgp_memory.c \
bgpd/bgp_mpath.c \
bgpd/bgp_mplsvpn.c \
@@ -145,6 +146,7 @@ noinst_HEADERS += \
bgpd/bgp_label.h \
bgpd/bgp_labelpool.h \
bgpd/bgp_lcommunity.h \
bgpd/bgp_mac.h \
bgpd/bgp_memory.h \
bgpd/bgp_mpath.h \
bgpd/bgp_mplsvpn.h \

0 comments on commit 48ecf8f

Please sign in to comment.
You can’t perform that action at this time.