]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Add 'show bgp listeners' command for diagnostics
authorDonald Sharp <sharpd@cumulusnetworks.com>
Fri, 19 Apr 2019 12:52:01 +0000 (08:52 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Tue, 10 Mar 2020 13:59:56 +0000 (09:59 -0400)
Add a command to display listen sockets and the vrf that they
are associated with.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_network.c
bgpd/bgp_network.h
bgpd/bgp_route.c

index 8759a88444ef268af7d07f8cb1e63948edfe1bf5..037aeec28871f612334baf47cfb54fa9cba78ac2 100644 (file)
@@ -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);
        }
 }
index 59b18f9376fb761e176223ab91a4f810277d628b..018efbc08ee7274f31abbbed34f6ae20cf65a185 100644 (file)
@@ -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);
index bcd87eb01b3be51bc95bfc276a94735ab6f4668c..c2c034d164a311d8651fd337e34495a1789d2b7d 100644 (file)
@@ -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);
 }