summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2020-12-04 15:04:09 +0200
committerDonatas Abraitis <donatas.abraitis@gmail.com>2020-12-17 10:06:35 +0200
commitcb75bb31732e29c990563f33335ca1a9357007ea (patch)
treecd78ce3c5dec497c1b476818adadf1870311cb0e
parent91653aefd487fb35ffca8f2d8db35b8c2b03fd6c (diff)
bgpd: Strip neighbors's description to 20 chars in show bgp summary
Also make sure we do not show descriptions with whitespace characters, just take the first splitted by whitespace. ``` root@exit1-debian-9:~/frr# vtysh -c 'show run' | grep description neighbor 192.168.0.2 description 12346789012345678901234567890 root@exit1-debian-9:~/frr# vtysh -c 'show ip bgp summary' | grep 192.168.0.2 192.168.0.2 4 65030 0 0 0 0 0 never Idle (Admin) 0 1234678901234567890 ``` ``` root@exit1-debian-9:~/frr# vtysh -c 'show run' | grep description neighbor 192.168.0.2 description one two root@exit1-debian-9:~/frr# vtysh -c 'show ip bgp summary' | grep 192.168.0.2 192.168.0.2 4 65030 0 0 0 0 0 never Idle (Admin) 0 one ``` Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
-rw-r--r--bgpd/bgp_vty.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c
index b77c4b2297..0fcc8c835e 100644
--- a/bgpd/bgp_vty.c
+++ b/bgpd/bgp_vty.c
@@ -10499,6 +10499,25 @@ static void bgp_show_failed_summary(struct vty *vty, struct bgp *bgp,
}
}
+/* If the peer's description includes whitespaces
+ * 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 stripped[BUFSIZ];
+ char *pnt;
+ 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);
+
+ return stripped;
+}
/* Show BGP peer's summary information. */
static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
@@ -11075,7 +11094,9 @@ static int bgp_show_summary(struct vty *vty, struct bgp *bgp, int afi, int safi,
vty_out(vty, " %8u", 0);
}
if (peer->desc)
- vty_out(vty, " %s", peer->desc);
+ vty_out(vty, " %s",
+ bgp_peer_description_stripped(
+ peer->desc, 20));
else
vty_out(vty, " N/A");
vty_out(vty, "\n");