#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
{
listnode_add_sort (config, XSTRDUP (MTYPE_VTYSH_CONFIG_LINE, line));
}
-static void
+void
vtysh_config_parse_line (const char *line)
{
char c;
/* 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);
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)
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)
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
}
}
-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) \
|| (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
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);
FILE *confp = NULL;
int ret;
- host_config_set (config_default_dir);
confp = fopen (config_default_dir, "r");
if (confp == NULL)
{
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 ();