From 2a0e69ae3c803dbc3640e52798779cde60f4def0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 19 Apr 2019 08:52:01 -0400 Subject: [PATCH] bgpd: Add 'show bgp listeners' command for diagnostics Add a command to display listen sockets and the vrf that they are associated with. Signed-off-by: Donald Sharp --- bgpd/bgp_network.c | 21 +++++++++++++++++++++ bgpd/bgp_network.h | 1 + bgpd/bgp_route.c | 14 ++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 8759a8844..037aeec28 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -57,8 +57,26 @@ struct bgp_listener { union sockunion su; struct thread *thread; struct bgp *bgp; + char *name; }; +void bgp_dump_listener_info(struct vty *vty) +{ + struct listnode *node; + struct bgp_listener *listener; + + vty_out(vty, "Name fd Address\n"); + vty_out(vty, "---------------------------\n"); + for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) { + char buf[SU_ADDRSTRLEN]; + + vty_out(vty, "%-16s %d %s\n", + listener->name ? listener->name : VRF_DEFAULT_NAME, + listener->fd, + sockunion2str(&listener->su, buf, sizeof(buf))); + } +} + /* * Set MD5 key for the socket, for the given IPv4 peer address. * If the password is NULL or zero-length, the option will be disabled. @@ -762,6 +780,7 @@ static int bgp_listener(int sock, struct sockaddr *sa, socklen_t salen, listener = XCALLOC(MTYPE_BGP_LISTENER, sizeof(*listener)); listener->fd = sock; + listener->name = XSTRDUP(MTYPE_BGP_LISTENER, bgp->name); /* this socket needs a change of ns. record bgp back pointer */ if (bgp->vrf_id != VRF_DEFAULT && vrf_is_backend_netns()) @@ -871,6 +890,7 @@ void bgp_close_vrf_socket(struct bgp *bgp) thread_cancel(listener->thread); close(listener->fd); listnode_delete(bm->listen_sockets, listener); + XFREE(MTYPE_BGP_LISTENER, listener->name); XFREE(MTYPE_BGP_LISTENER, listener); } } @@ -892,6 +912,7 @@ void bgp_close(void) thread_cancel(listener->thread); close(listener->fd); listnode_delete(bm->listen_sockets, listener); + XFREE(MTYPE_BGP_LISTENER, listener->name); XFREE(MTYPE_BGP_LISTENER, listener); } } diff --git a/bgpd/bgp_network.h b/bgpd/bgp_network.h index 59b18f937..018efbc08 100644 --- a/bgpd/bgp_network.h +++ b/bgpd/bgp_network.h @@ -23,6 +23,7 @@ #define BGP_SOCKET_SNDBUF_SIZE 65536 +extern void bgp_dump_listener_info(struct vty *vty); extern int bgp_socket(struct bgp *bgp, unsigned short port, const char *address); extern void bgp_close_vrf_socket(struct bgp *bgp); diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index bcd87eb01..c2c034d16 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -69,6 +69,7 @@ #include "bgpd/bgp_label.h" #include "bgpd/bgp_addpath.h" #include "bgpd/bgp_mac.h" +#include "bgpd/bgp_network.h" #if ENABLE_BGP_VNC #include "bgpd/rfapi/rfapi_backend.h" @@ -12766,6 +12767,18 @@ static void show_bgp_peerhash_entry(struct hash_bucket *bucket, void *arg) sockunion2str(&peer->su, buf, sizeof(buf))); } +DEFUN (show_bgp_listeners, + show_bgp_listeners_cmd, + "show bgp listeners", + SHOW_STR + BGP_STR + "Display Listen Sockets and who created them\n") +{ + bgp_dump_listener_info(vty); + + return CMD_SUCCESS; +} + DEFUN (show_bgp_peerhash, show_bgp_peerhash_cmd, "show bgp peerhash", @@ -13155,6 +13168,7 @@ void bgp_route_init(void) /* show bgp ipv4 flowspec detailed */ install_element(VIEW_NODE, &show_ip_bgp_flowspec_routes_detailed_cmd); + install_element(VIEW_NODE, &show_bgp_listeners_cmd); install_element(VIEW_NODE, &show_bgp_peerhash_cmd); } -- 2.39.5