mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-14 23:53:28 +00:00
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>
This commit is contained in:
parent
8cb687c2cb
commit
48ecf8f510
99
bgpd/bgp_mac.c
Normal file
99
bgpd/bgp_mac.c
Normal file
@ -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);
|
||||||
|
}
|
27
bgpd/bgp_mac.h
Normal file
27
bgpd/bgp_mac.h
Normal file
@ -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 "frrstr.h"
|
||||||
|
|
||||||
#include "bgpd/bgpd.h"
|
#include "bgpd/bgpd.h"
|
||||||
|
#include "bgpd/bgp_attr_evpn.h"
|
||||||
#include "bgpd/bgp_advertise.h"
|
#include "bgpd/bgp_advertise.h"
|
||||||
#include "bgpd/bgp_attr.h"
|
#include "bgpd/bgp_attr.h"
|
||||||
#include "bgpd/bgp_aspath.h"
|
#include "bgpd/bgp_aspath.h"
|
||||||
@ -62,6 +63,7 @@
|
|||||||
#include "bgpd/bgp_io.h"
|
#include "bgpd/bgp_io.h"
|
||||||
#include "bgpd/bgp_evpn.h"
|
#include "bgpd/bgp_evpn.h"
|
||||||
#include "bgpd/bgp_addpath.h"
|
#include "bgpd/bgp_addpath.h"
|
||||||
|
#include "bgpd/bgp_mac.h"
|
||||||
|
|
||||||
static struct peer_group *listen_range_exists(struct bgp *bgp,
|
static struct peer_group *listen_range_exists(struct bgp *bgp,
|
||||||
struct prefix *range, int exact);
|
struct prefix *range, int exact);
|
||||||
@ -7576,6 +7578,18 @@ DEFUN (show_bgp_vrfs,
|
|||||||
return CMD_SUCCESS;
|
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)
|
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" */
|
/* "show bgp martian next-hop" */
|
||||||
install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
|
install_element(VIEW_NODE, &show_bgp_martian_nexthop_db_cmd);
|
||||||
|
|
||||||
|
install_element(VIEW_NODE, &show_bgp_mac_hash_cmd);
|
||||||
|
|
||||||
/* "show [ip] bgp views" commands. */
|
/* "show [ip] bgp views" commands. */
|
||||||
install_element(VIEW_NODE, &show_bgp_views_cmd);
|
install_element(VIEW_NODE, &show_bgp_views_cmd);
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@
|
|||||||
#include "bgpd/bgp_pbr.h"
|
#include "bgpd/bgp_pbr.h"
|
||||||
#include "bgpd/bgp_addpath.h"
|
#include "bgpd/bgp_addpath.h"
|
||||||
#include "bgpd/bgp_evpn_private.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, PEER_TX_SHUTDOWN_MSG, "Peer shutdown message (TX)");
|
||||||
DEFINE_MTYPE_STATIC(BGPD, BGP_EVPN_INFO, "BGP EVPN instance information");
|
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_process_queue_init();
|
||||||
|
|
||||||
|
bgp_mac_init();
|
||||||
/* init the rd id space.
|
/* init the rd id space.
|
||||||
assign 0th index in the bitfield,
|
assign 0th index in the bitfield,
|
||||||
so that we start with id 1
|
so that we start with id 1
|
||||||
@ -7964,4 +7966,5 @@ void bgp_terminate(void)
|
|||||||
if (bm->t_rmap_update)
|
if (bm->t_rmap_update)
|
||||||
BGP_TIMER_OFF(bm->t_rmap_update);
|
BGP_TIMER_OFF(bm->t_rmap_update);
|
||||||
|
|
||||||
|
bgp_mac_finish();
|
||||||
}
|
}
|
||||||
|
@ -122,6 +122,9 @@ struct bgp_master {
|
|||||||
/* Listener address */
|
/* Listener address */
|
||||||
char *address;
|
char *address;
|
||||||
|
|
||||||
|
/* The Mac table */
|
||||||
|
struct hash *self_mac_hash;
|
||||||
|
|
||||||
/* BGP start time. */
|
/* BGP start time. */
|
||||||
time_t start_time;
|
time_t start_time;
|
||||||
|
|
||||||
|
@ -72,6 +72,7 @@ bgpd_libbgp_a_SOURCES = \
|
|||||||
bgpd/bgp_label.c \
|
bgpd/bgp_label.c \
|
||||||
bgpd/bgp_labelpool.c \
|
bgpd/bgp_labelpool.c \
|
||||||
bgpd/bgp_lcommunity.c \
|
bgpd/bgp_lcommunity.c \
|
||||||
|
bgpd/bgp_mac.c \
|
||||||
bgpd/bgp_memory.c \
|
bgpd/bgp_memory.c \
|
||||||
bgpd/bgp_mpath.c \
|
bgpd/bgp_mpath.c \
|
||||||
bgpd/bgp_mplsvpn.c \
|
bgpd/bgp_mplsvpn.c \
|
||||||
@ -145,6 +146,7 @@ noinst_HEADERS += \
|
|||||||
bgpd/bgp_label.h \
|
bgpd/bgp_label.h \
|
||||||
bgpd/bgp_labelpool.h \
|
bgpd/bgp_labelpool.h \
|
||||||
bgpd/bgp_lcommunity.h \
|
bgpd/bgp_lcommunity.h \
|
||||||
|
bgpd/bgp_mac.h \
|
||||||
bgpd/bgp_memory.h \
|
bgpd/bgp_memory.h \
|
||||||
bgpd/bgp_mpath.h \
|
bgpd/bgp_mpath.h \
|
||||||
bgpd/bgp_mplsvpn.h \
|
bgpd/bgp_mplsvpn.h \
|
||||||
|
Loading…
Reference in New Issue
Block a user