]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/command.c
Merge pull request #345 from chiragshah6/pim_dev
[mirror_frr.git] / lib / command.c
index 24272ccd1e8362f48dc0337560c5b3afaeee915d..993d6f905548a20de5e4e71c89db2ce7546e57f3 100644 (file)
@@ -30,6 +30,7 @@
 
 #include "memory.h"
 #include "log.h"
+#include "log_int.h"
 #include <lib/version.h>
 #include "thread.h"
 #include "vector.h"
@@ -40,6 +41,7 @@
 #include "vrf.h"
 #include "command_match.h"
 #include "qobj.h"
+#include "defaults.h"
 
 DEFINE_MTYPE(       LIB, HOST,       "Host config")
 DEFINE_MTYPE(       LIB, STRVEC,     "String vector")
@@ -1535,6 +1537,23 @@ DEFUN (show_version,
   return CMD_SUCCESS;
 }
 
+/* "Set" version ... ignore version tags */
+DEFUN (frr_version_defaults,
+       frr_version_defaults_cmd,
+       "frr <version|defaults> LINE...",
+       "FRRouting global parameters\n"
+       "version configuration was written by\n"
+       "set of configuration defaults used\n"
+       "version string\n")
+{
+  if (vty->type == VTY_TERM || vty->type == VTY_SHELL)
+    /* only print this when the user tries to do run it */
+    vty_out (vty, "%% NOTE: This command currently does nothing.%s"
+             "%% It is written to the configuration for future reference.%s",
+             VTY_NEWLINE, VTY_NEWLINE);
+  return CMD_SUCCESS;
+}
+
 /* Help display function for all node. */
 DEFUN (config_help,
        config_help_cmd,
@@ -1629,11 +1648,43 @@ DEFUN (show_commandtree,
        show_commandtree_cmd,
        "show commandtree [permutations]",
        SHOW_STR
-       "Show command tree\n")
+       "Show command tree\n"
+       "Permutations that we are interested in\n")
 {
   return cmd_list_cmds (vty, argc == 3);
 }
 
+static void
+vty_write_config (struct vty *vty)
+{
+  size_t i;
+  struct cmd_node *node;
+
+  if (vty->type == VTY_TERM)
+    {
+      vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
+               VTY_NEWLINE);
+      vty_out (vty, "!%s", VTY_NEWLINE);
+    }
+
+  vty_out (vty, "frr version %s%s", FRR_VER_SHORT, VTY_NEWLINE);
+  vty_out (vty, "frr defaults %s%s", DFLT_NAME, VTY_NEWLINE);
+  vty_out (vty, "!%s", VTY_NEWLINE);
+
+  for (i = 0; i < vector_active (cmdvec); i++)
+    if ((node = vector_slot (cmdvec, i)) && node->func
+        && (node->vtysh || vty->type != VTY_SHELL))
+      {
+        if ((*node->func) (vty))
+          vty_out (vty, "!%s", VTY_NEWLINE);
+      }
+
+  if (vty->type == VTY_TERM)
+    {
+      vty_out (vty, "end%s",VTY_NEWLINE);
+    }
+}
+
 /* Write current configuration into file. */
 
 DEFUN (config_write,
@@ -1645,9 +1696,7 @@ DEFUN (config_write,
        "Write configuration to terminal\n")
 {
   int idx_type = 1;
-  unsigned int i;
   int fd, dirfd;
-  struct cmd_node *node;
   char *config_file, *slash;
   char *config_file_tmp = NULL;
   char *config_file_sav = NULL;
@@ -1658,32 +1707,10 @@ DEFUN (config_write,
   // if command was 'write terminal' or 'show running-config'
   if (argc == 2 && (!strcmp(argv[idx_type]->text, "terminal") ||
                     !strcmp(argv[0]->text, "show")))
-  {
-    if (vty->type == VTY_SHELL_SERV)
-      {
-        for (i = 0; i < vector_active (cmdvec); i++)
-          if ((node = vector_slot (cmdvec, i)) && node->func && node->vtysh)
-            {
-              if ((*node->func) (vty))
-                vty_out (vty, "!%s", VTY_NEWLINE);
-            }
-      }
-    else
-      {
-        vty_out (vty, "%sCurrent configuration:%s", VTY_NEWLINE,
-                 VTY_NEWLINE);
-        vty_out (vty, "!%s", VTY_NEWLINE);
-
-        for (i = 0; i < vector_active (cmdvec); i++)
-          if ((node = vector_slot (cmdvec, i)) && node->func)
-            {
-              if ((*node->func) (vty))
-                vty_out (vty, "!%s", VTY_NEWLINE);
-            }
-        vty_out (vty, "end%s",VTY_NEWLINE);
-      }
-    return CMD_SUCCESS;
-  }
+    {
+      vty_write_config (vty);
+      return CMD_SUCCESS;
+    }
 
   if (host.noconfig)
     return CMD_SUCCESS;
@@ -1747,13 +1774,7 @@ DEFUN (config_write,
   vty_out (file_vty, "!\n! Zebra configuration saved from vty\n!   ");
   vty_time_print (file_vty, 1);
   vty_out (file_vty, "!\n");
-
-  for (i = 0; i < vector_active (cmdvec); i++)
-    if ((node = vector_slot (cmdvec, i)) && node->func)
-      {
-        if ((*node->func) (file_vty))
-          vty_out (file_vty, "!\n");
-      }
+  vty_write_config (file_vty);
   vty_close (file_vty);
 
   if (stat(config_file, &conf_stat) >= 0)
@@ -1815,7 +1836,9 @@ DEFUN (copy_runningconf_startupconf,
        "Copy running config to... \n"
        "Copy running config to startup config (same as write file)\n")
 {
-  return config_write (self, vty, argc, argv);
+  if (!host.noconfig)
+    vty_write_config (vty);
+  return CMD_SUCCESS;
 }
 /** -- **/
 
@@ -2162,7 +2185,7 @@ DEFUN (config_logmsg,
   if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
     return CMD_ERR_NO_MATCH;
 
-  zlog(NULL, level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : ""));
+  zlog(level, "%s", ((message = argv_concat(argv, argc, idx_message)) ? message : ""));
   if (message)
     XFREE(MTYPE_TMP, message);
 
@@ -2213,7 +2236,7 @@ DEFUN (show_logging,
   vty_out (vty, "%s", VTY_NEWLINE);
 
   vty_out (vty, "Protocol name: %s%s",
-           zlog_proto_names[zl->protocol], VTY_NEWLINE);
+           zl->protoname, VTY_NEWLINE);
   vty_out (vty, "Record priority: %s%s",
            (zl->record_priority ? "enabled" : "disabled"), VTY_NEWLINE);
   vty_out (vty, "Timestamp precision: %d%s",
@@ -2233,14 +2256,14 @@ DEFUN (config_log_stdout,
 
   if (argc == idx_log_level)
   {
-    zlog_set_level (NULL, ZLOG_DEST_STDOUT, zlog_default->default_lvl);
+    zlog_set_level (ZLOG_DEST_STDOUT, zlog_default->default_lvl);
     return CMD_SUCCESS;
   }
   int level;
 
   if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
     return CMD_ERR_NO_MATCH;
-  zlog_set_level (NULL, ZLOG_DEST_STDOUT, level);
+  zlog_set_level (ZLOG_DEST_STDOUT, level);
   return CMD_SUCCESS;
 }
 
@@ -2252,7 +2275,7 @@ DEFUN (no_config_log_stdout,
        "Cancel logging to stdout\n"
        LOG_LEVEL_DESC)
 {
-  zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
+  zlog_set_level (ZLOG_DEST_STDOUT, ZLOG_DISABLED);
   return CMD_SUCCESS;
 }
 
@@ -2267,14 +2290,14 @@ DEFUN (config_log_monitor,
 
   if (argc == idx_log_level)
   {
-    zlog_set_level (NULL, ZLOG_DEST_MONITOR, zlog_default->default_lvl);
+    zlog_set_level (ZLOG_DEST_MONITOR, zlog_default->default_lvl);
     return CMD_SUCCESS;
   }
   int level;
 
   if ((level = level_match(argv[idx_log_level]->arg)) == ZLOG_DISABLED)
     return CMD_ERR_NO_MATCH;
-  zlog_set_level (NULL, ZLOG_DEST_MONITOR, level);
+  zlog_set_level (ZLOG_DEST_MONITOR, level);
   return CMD_SUCCESS;
 }
 
@@ -2286,7 +2309,7 @@ DEFUN (no_config_log_monitor,
        "Disable terminal line (monitor) logging\n"
        LOG_LEVEL_DESC)
 {
-  zlog_set_level (NULL, ZLOG_DEST_MONITOR, ZLOG_DISABLED);
+  zlog_set_level (ZLOG_DEST_MONITOR, ZLOG_DISABLED);
   return CMD_SUCCESS;
 }
 
@@ -2321,7 +2344,7 @@ set_log_file(struct vty *vty, const char *fname, int loglevel)
   else
     fullpath = fname;
 
-  ret = zlog_set_file (NULL, fullpath, loglevel);
+  ret = zlog_set_file (fullpath, loglevel);
 
   if (p)
     XFREE (MTYPE_TMP, p);
@@ -2375,7 +2398,7 @@ DEFUN (no_config_log_file,
        "Logging file name\n"
        "Logging level\n")
 {
-  zlog_reset_file (NULL);
+  zlog_reset_file ();
 
   if (host.logfile)
     XFREE (MTYPE_HOST, host.logfile);
@@ -2398,12 +2421,12 @@ DEFUN (config_log_syslog,
     int level;
     if ((level = level_match (argv[idx_log_levels]->arg)) == ZLOG_DISABLED)
       return CMD_ERR_NO_MATCH;
-    zlog_set_level (NULL, ZLOG_DEST_SYSLOG, level);
+    zlog_set_level (ZLOG_DEST_SYSLOG, level);
     return CMD_SUCCESS;
   }
   else
   {
-    zlog_set_level (NULL, ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
+    zlog_set_level (ZLOG_DEST_SYSLOG, zlog_default->default_lvl);
     return CMD_SUCCESS;
   }
 }
@@ -2417,7 +2440,7 @@ DEFUN (no_config_log_syslog,
        LOG_FACILITY_DESC
        LOG_LEVEL_DESC)
 {
-  zlog_set_level (NULL, ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
+  zlog_set_level (ZLOG_DEST_SYSLOG, ZLOG_DISABLED);
   return CMD_SUCCESS;
 }
 
@@ -2692,6 +2715,7 @@ cmd_init (int terminal)
 
   install_element (CONFIG_NODE, &hostname_cmd);
   install_element (CONFIG_NODE, &no_hostname_cmd);
+  install_element (CONFIG_NODE, &frr_version_defaults_cmd);
 
   if (terminal > 0)
     {
@@ -2725,7 +2749,6 @@ cmd_init (int terminal)
 
       vrf_install_commands ();
     }
-  srandom(time(NULL));
 
 #ifdef DEV_BUILD
   grammar_sandbox_init();