Merge pull request #9592 from ton31337/fix/bgp_neighbor_strip_whitespace

bgpd: Do not strip peer's description by whitespace in `show bgp summary`
This commit is contained in:
Igor Ryzhov 2021-09-13 13:18:00 +03:00 committed by GitHub
commit 28e577efbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9974,21 +9974,12 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
} }
} }
/* If the peer's description includes whitespaces /* Strip peer's description to the given size. */
* then return the first occurrence. Also strip description
* to the given size if needed.
*/
static char *bgp_peer_description_stripped(char *desc, uint32_t size) static char *bgp_peer_description_stripped(char *desc, uint32_t size)
{ {
static char stripped[BUFSIZ]; static char stripped[BUFSIZ];
char *pnt;
uint32_t len = size > strlen(desc) ? strlen(desc) : size; uint32_t len = size > strlen(desc) ? strlen(desc) : size;
pnt = strchr(desc, ' ');
if (pnt)
len = size > (uint32_t)(pnt - desc) ? (uint32_t)(pnt - desc)
: size;
strlcpy(stripped, desc, len + 1); strlcpy(stripped, desc, len + 1);
return stripped; return stripped;
@ -10020,7 +10011,15 @@ static bool bgp_show_summary_is_peer_filtered(struct peer *peer,
return false; return false;
} }
/* Show BGP peer's summary information. */ /* Show BGP peer's summary information.
*
* Peer's description is stripped according to if `wide` option is given
* or not.
*
* When adding new columns to `show bgp summary` output, please make
* sure `Desc` is the lastest column to show because it can contain
* whitespaces and the whole output will be tricky.
*/
static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi, static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
struct peer *fpeer, int as_type, as_t as, struct peer *fpeer, int as_type, as_t as,
uint16_t show_flags) uint16_t show_flags)
@ -10685,6 +10684,9 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
vty_out(vty, " %8u", 0); vty_out(vty, " %8u", 0);
} }
/* Make sure `Desc` column is the lastest in
* the output.
*/
if (peer->desc) if (peer->desc)
vty_out(vty, " %s", vty_out(vty, " %s",
bgp_peer_description_stripped( bgp_peer_description_stripped(