]> git.proxmox.com Git - mirror_frr.git/blobdiff - vtysh/vtysh_config.c
Merge remote-tracking branch 'origin/master' into EIGRP
[mirror_frr.git] / vtysh / vtysh_config.c
index fcad333b9f67f9bdf286a16afb8f5b1e6402f08a..06e856934100e571eddcc7177c41deca37e879e3 100644 (file)
@@ -27,9 +27,11 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 #include "vtysh/vtysh.h"
 #include "vtysh/vtysh_user.h"
 
-vector configvec;
+DEFINE_MGROUP(MVTYSH, "vtysh")
+DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG,      "Vtysh configuration")
+DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CONFIG_LINE, "Vtysh configuration line")
 
-extern int vtysh_writeconfig_integrated;
+vector configvec;
 
 struct config
 {
@@ -142,7 +144,7 @@ config_add_line_uniq (struct list *config, const char *line)
   listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line));
 }
 
-static void
+void
 vtysh_config_parse_line (const char *line)
 {
   char c;
@@ -169,10 +171,21 @@ vtysh_config_parse_line (const char *line)
       /* Store line to current configuration. */
       if (config)
        {
-         if (config->index == RMAP_NODE ||
-                  config->index == INTERFACE_NODE ||
-                  config->index == VRF_NODE ||
-                  config->index == VTY_NODE)
+         if (strncmp (line, " link-params", strlen (" link-params")) == 0)
+           {
+             config_add_line (config->line, line);
+             config->index = LINK_PARAMS_NODE;
+           }
+         else if (config->index == LINK_PARAMS_NODE &&
+             strncmp (line, "  exit-link-params", strlen ("  exit")) == 0)
+           {
+             config_add_line (config->line, line);
+             config->index = INTERFACE_NODE;
+           }
+         else if (config->index == RMAP_NODE ||
+             config->index == INTERFACE_NODE ||
+             config->index == NS_NODE ||
+             config->index == VTY_NODE)
            config_add_line_uniq (config->line, line);
          else
            config_add_line (config->line, line);
@@ -183,6 +196,8 @@ vtysh_config_parse_line (const char *line)
     default:
       if (strncmp (line, "interface", strlen ("interface")) == 0)
        config = config_get (INTERFACE_NODE, line);
+      else if (strncmp (line, "logical-router", strlen ("ns")) == 0)
+       config = config_get (NS_NODE, line);
       else if (strncmp (line, "vrf", strlen ("vrf")) == 0)
        config = config_get (VRF_NODE, line);
       else if (strncmp (line, "router-id", strlen ("router-id")) == 0)
@@ -191,10 +206,16 @@ vtysh_config_parse_line (const char *line)
        config = config_get (RIP_NODE, line);
       else if (strncmp (line, "router ripng", strlen ("router ripng")) == 0)
        config = config_get (RIPNG_NODE, line);
+      else if (strncmp (line, "router eigrp", strlen ("router eigrp")) == 0)
+        config = config_get (EIGRP_NODE, line);
       else if (strncmp (line, "router ospf", strlen ("router ospf")) == 0)
        config = config_get (OSPF_NODE, line);
       else if (strncmp (line, "router ospf6", strlen ("router ospf6")) == 0)
        config = config_get (OSPF6_NODE, line);
+      else if (strncmp (line, "mpls ldp", strlen ("mpls ldp")) == 0)
+       config = config_get (LDP_NODE, line);
+      else if (strncmp (line, "l2vpn", strlen ("l2vpn")) == 0)
+       config = config_get (LDP_L2VPN_NODE, line);
       else if (strncmp (line, "router bgp", strlen ("router bgp")) == 0)
        config = config_get (BGP_NODE, line);
       else if (strncmp (line, "router isis", strlen ("router isis")) == 0)
@@ -249,10 +270,13 @@ vtysh_config_parse_line (const char *line)
        config = config_get (PROTOCOL_NODE, line);
       else if (strncmp (line, "ipv6 nht", strlen ("ipv6 nht")) == 0)
        config = config_get (PROTOCOL_NODE, line);
+      else if (strncmp (line, "mpls", strlen ("mpls")) == 0)
+       config = config_get (MPLS_NODE, line);
       else
        {
          if (strncmp (line, "log", strlen ("log")) == 0
              || strncmp (line, "hostname", strlen ("hostname")) == 0
+             || strncmp (line, "frr", strlen ("frr")) == 0
             )
            config_add_line_uniq (config_top, line);
          else
@@ -263,29 +287,6 @@ vtysh_config_parse_line (const char *line)
     }
 }
 
-void
-vtysh_config_parse (char *line)
-{
-  char *begin;
-  char *pnt;
-  
-  begin = pnt = line;
-
-  while (*pnt != '\0')
-    {
-      if (*pnt == '\n')
-       {
-         *pnt++ = '\0';
-         vtysh_config_parse_line (begin);
-         begin = pnt;
-       }
-      else
-       {
-         pnt++;
-       }
-    }
-}
-
 /* Macro to check delimiter is needed between each configuration line
  * or not. */
 #define NO_DELIMITER(I)  \
@@ -293,7 +294,7 @@ vtysh_config_parse (char *line)
    || (I) == AS_LIST_NODE || (I) == COMMUNITY_LIST_NODE || \
    (I) == ACCESS_IPV6_NODE || (I) == PREFIX_IPV6_NODE \
    || (I) == SERVICE_NODE || (I) == FORWARDING_NODE || (I) == DEBUG_NODE \
-   || (I) == AAA_NODE || (I) == VRF_DEBUG_NODE)
+   || (I) == AAA_NODE || (I) == VRF_DEBUG_NODE || (I) == MPLS_NODE)
 
 /* Display configuration to file pointer. */
 void
@@ -318,7 +319,14 @@ vtysh_config_dump (FILE *fp)
     if ((master = vector_slot (configvec, i)) != NULL)
       {
        for (ALL_LIST_ELEMENTS (master, node, nnode, config))
-         {
+    {
+      /* Don't print empty sections for interface/vrf. Route maps on the
+       * other hand could have a legitimate empty section at the end.
+       */
+      if ((config->index == INTERFACE_NODE || (config->index == VRF_NODE))
+          && list_isempty (config->line))
+        continue;
+
            fprintf (fp, "%s\n", config->name);
            fflush (fp);
 
@@ -382,7 +390,6 @@ vtysh_read_config (const char *config_default_dir)
   FILE *confp = NULL;
   int ret;
 
-  host_config_set (config_default_dir);
   confp = fopen (config_default_dir, "r");
   if (confp == NULL)
     {
@@ -412,7 +419,9 @@ vtysh_config_write ()
       sprintf (line, "hostname %s", host.name);
       vtysh_config_parse_line(line);
     }
-  if (vtysh_writeconfig_integrated)
+  if (vtysh_write_integrated == WRITE_INTEGRATED_NO)
+    vtysh_config_parse_line ("no service integrated-vtysh-config");
+  if (vtysh_write_integrated == WRITE_INTEGRATED_YES)
     vtysh_config_parse_line ("service integrated-vtysh-config");
 
   user_config_write ();