]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: add "show modules" CLI command
authorDavid Lamparter <equinox@opensourcerouting.org>
Sun, 12 Feb 2017 22:23:02 +0000 (23:23 +0100)
committerDavid Lamparter <equinox@opensourcerouting.org>
Fri, 24 Mar 2017 12:02:33 +0000 (13:02 +0100)
(for simplicity, this is stuffed in with memory_vty.c)

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
configure.ac
lib/memory_vty.c

index 2a8cab34f122ff515eb9da8ae75e03b493bd5d89..b94b8bb16c8a5c76c2eb6fd3fd317262ae77c3e3 100755 (executable)
@@ -1354,13 +1354,49 @@ int main(void);
    AC_DEFINE_UNQUOTED(AS_TR_CPP(SNMP_${SNMP_METHOD}),,SNMP method to interface with snmpd)
 fi
 
-dnl ------
-dnl dlopen
-dnl ------
+dnl ---------------
+dnl dlopen & dlinfo
+dnl ---------------
 AC_SEARCH_LIBS(dlopen, [dl dld], [], [
   AC_MSG_ERROR([unable to find the dlopen()])
 ])
 
+AC_CHECK_HEADERS([link.h])
+
+AC_MSG_CHECKING([for dlinfo(RTLD_DI_ORIGIN)])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <stdlib.h>
+#ifdef HAVE_LINK_H
+#include <link.h>
+#endif
+#include <dlfcn.h>
+]], [[
+  char origin[1];
+  dlinfo (NULL, RTLD_DI_ORIGIN, &origin);
+]])], [
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_DLINFO_ORIGIN, 1, [Have dlinfo RTLD_DI_ORIGIN])
+], [
+  AC_MSG_RESULT(no)
+])
+
+AC_MSG_CHECKING([for dlinfo(RTLD_DI_LINKMAP)])
+AC_LINK_IFELSE([AC_LANG_PROGRAM([[
+#include <stdlib.h>
+#ifdef HAVE_LINK_H
+#include <link.h>
+#endif
+#include <dlfcn.h>
+]], [[
+  struct link_map *lm = NULL;
+  dlinfo (NULL, RTLD_DI_LINKMAP, &lm);
+]])], [
+  AC_MSG_RESULT(yes)
+  AC_DEFINE(HAVE_DLINFO_LINKMAP, 1, [Have dlinfo RTLD_DI_LINKMAP])
+], [
+  AC_MSG_RESULT(no)
+])
+
 
 dnl ---------------------------
 dnl sockaddr and netinet checks
index 149b32913002da7cb7cacb330072c45871a5d963..01a41fe02e03ad60b0686e9a9d672a93672b6ea6 100644 (file)
@@ -1,23 +1,22 @@
 /*
- * Memory management routine
- * Copyright (C) 1998 Kunihiro Ishiguro
+ * Memory and dynamic module VTY routine
  *
- * This file is part of GNU Zebra.
+ * Copyright (C) 1998 Kunihiro Ishiguro
+ * Copyright (C) 2016-2017  David Lamparter for NetDEF, Inc.
  *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
  *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.  
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA
  */
 
 #include <zebra.h>
 #if (defined(GNU_LINUX) && defined(HAVE_MALLINFO))
 #include <malloc.h>
 #endif /* HAVE_MALLINFO */
+#include <dlfcn.h>
+#include <link.h>
 
 #include "log.h"
 #include "memory.h"
+#include "module.h"
 #include "memory_vty.h"
 
 /* Looking up memory status from vty interface. */
@@ -110,10 +112,55 @@ DEFUN (show_memory,
   return CMD_SUCCESS;
 }
 
+DEFUN (show_modules,
+       show_modules_cmd,
+       "show modules",
+       "Show running system information\n"
+       "Loaded modules\n")
+{
+  struct frrmod_runtime *plug = frrmod_list;
+
+  vty_out (vty, "%-12s %-25s %s%s%s",
+                "Plugin Name", "Version", "Description",
+                VTY_NEWLINE, VTY_NEWLINE);
+  while (plug)
+    {
+      const struct frrmod_info *i = plug->info;
+
+      vty_out (vty, "%-12s %-25s %s%s", i->name, i->version, i->description,
+                    VTY_NEWLINE);
+      if (plug->dl_handle)
+        {
+#ifdef HAVE_DLINFO_ORIGIN
+          char origin[MAXPATHLEN] = "";
+          dlinfo (plug->dl_handle, RTLD_DI_ORIGIN, &origin);
+# ifdef HAVE_DLINFO_LINKMAP
+          const char *name;
+          struct link_map *lm = NULL;
+          dlinfo (plug->dl_handle, RTLD_DI_LINKMAP, &lm);
+          if (lm)
+            {
+              name = strrchr(lm->l_name, '/');
+              name = name ? name + 1 : lm->l_name;
+              vty_out (vty, "\tfrom: %s/%s%s", origin, name, VTY_NEWLINE);
+            }
+# else
+          vty_out (vty, "\tfrom: %s %s", origin, plug->load_name, VTY_NEWLINE);
+# endif
+#else
+          vty_out (vty, "\tfrom: %s%s", plug->load_name, VTY_NEWLINE);
+#endif
+        }
+      plug = plug->next;
+    }
+  return CMD_SUCCESS;
+}
+
 void
 memory_init (void)
 {
   install_element (VIEW_NODE, &show_memory_cmd);
+  install_element (VIEW_NODE, &show_modules_cmd);
 }
 
 /* Stats querying from users */