From 0a73975d3ccfeef68677fb8710d53b26a4f0657e Mon Sep 17 00:00:00 2001 From: Akhilesh Samineni Date: Fri, 15 Feb 2019 22:20:51 +0530 Subject: [PATCH] bgpd: Incorrect number of peers count in "show bgp ipv6 summary" output Fix : Now the peers count displays the number of neighbors activated per afi/safi. Signed-off-by: Akhilesh Samineni --- bgpd/bgp_vty.c | 4 ++-- bgpd/bgpd.c | 8 ++++++++ bgpd/bgpd.h | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index a6adeea66d..25f4b842e7 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7811,7 +7811,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, json, "ribMemory", ents * sizeof(struct bgp_node)); - ents = listcount(bgp->peer); + ents = bgp->af_peer_count[afi][safi]; json_object_int_add(json, "peerCount", ents); json_object_int_add(json, "peerMemory", ents * sizeof(struct peer)); @@ -7851,7 +7851,7 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, bgp_node))); /* Peer related usage */ - ents = listcount(bgp->peer); + ents = bgp->af_peer_count[afi][safi]; vty_out(vty, "Peers %ld, using %s of memory\n", ents, mtype_memstr( diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index da2c97f6f4..3d7a0f32c0 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -669,6 +669,7 @@ struct peer_af *peer_af_create(struct peer *peer, afi_t afi, safi_t safi) { struct peer_af *af; int afid; + struct bgp *bgp; if (!peer) return NULL; @@ -677,6 +678,7 @@ struct peer_af *peer_af_create(struct peer *peer, afi_t afi, safi_t safi) if (afid >= BGP_AF_MAX) return NULL; + bgp = peer->bgp; assert(peer->peer_af_array[afid] == NULL); /* Allocate new peer af */ @@ -693,6 +695,7 @@ struct peer_af *peer_af_create(struct peer *peer, afi_t afi, safi_t safi) af->safi = safi; af->afid = afid; af->peer = peer; + bgp->af_peer_count[afi][safi]++; return af; } @@ -715,6 +718,7 @@ int peer_af_delete(struct peer *peer, afi_t afi, safi_t safi) { struct peer_af *af; int afid; + struct bgp *bgp; if (!peer) return -1; @@ -727,6 +731,7 @@ int peer_af_delete(struct peer *peer, afi_t afi, safi_t safi) if (!af) return -1; + bgp = peer->bgp; bgp_stop_announce_route_timer(af); if (PAF_SUBGRP(af)) { @@ -738,6 +743,9 @@ int peer_af_delete(struct peer *peer, afi_t afi, safi_t safi) update_subgroup_remove_peer(af->subgroup, af); + if (bgp->af_peer_count[afi][safi]) + bgp->af_peer_count[afi][safi]--; + peer->peer_af_array[afid] = NULL; XFREE(MTYPE_BGP_PEER_AF, af); return 0; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index d20f841a2f..7cddd7e118 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -369,6 +369,9 @@ struct bgp { #define BGP_CONFIG_VRF_TO_VRF_EXPORT (1 << 8) #define BGP_DEFAULT_NAME "default" + /* BGP per AF peer count */ + uint32_t af_peer_count[AFI_MAX][SAFI_MAX]; + /* Route table for next-hop lookup cache. */ struct bgp_table *nexthop_cache_table[AFI_MAX]; -- 2.39.5