From c319e19dbd2462440d718cfd32db061b306e006c Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Wed, 11 Apr 2018 11:23:23 -0400 Subject: [PATCH 1/2] vtysh, zebra: print exit-vrf at end of vrf context Need to explicitly exit this context otherwise we risk ambiguities between global and vrf context commands Signed-off-by: Quentin Young --- vtysh/vtysh.c | 2 +- vtysh/vtysh_config.c | 6 ++++++ zebra/zebra_vrf.c | 11 +++++------ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 2400908183..7316477891 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -671,7 +671,7 @@ int vtysh_mark_file(const char *filename) } else if ((prev_node == BGP_EVPN_VNI_NODE) && (tried == 1)) { fprintf(outputfile, "exit-vni\n"); - } else if (prev_node == VRF_NODE) { + } else if (prev_node == VRF_NODE && (tried == 1)) { fprintf(outputfile, "exit-vrf\n"); } else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1)) { diff --git a/vtysh/vtysh_config.c b/vtysh/vtysh_config.c index 3748fef54c..6f3b6a8267 100644 --- a/vtysh/vtysh_config.c +++ b/vtysh/vtysh_config.c @@ -185,6 +185,12 @@ void vtysh_config_parse_line(void *arg, const char *line) == 0) { config_add_line(config->line, line); config->index = INTERFACE_NODE; + } else if (config->index == VRF_NODE + && strncmp(line, " exit-vrf", + strlen(" exit-vrf")) + == 0) { + config_add_line(config->line, line); + config->index = CONFIG_NODE; } else if (config->index == RMAP_NODE || config->index == INTERFACE_NODE || config->index == LOGICALROUTER_NODE diff --git a/zebra/zebra_vrf.c b/zebra/zebra_vrf.c index 76dc5657d4..18d53292b1 100644 --- a/zebra/zebra_vrf.c +++ b/zebra/zebra_vrf.c @@ -524,10 +524,8 @@ static int vrf_config_write(struct vty *vty) if (zvrf->l3vni) vty_out(vty, "vni %u\n", zvrf->l3vni); vty_out(vty, "!\n"); - } - - if (vrf_is_user_cfged(vrf)) { - vty_out(vty, "vrf %s\n", zvrf_name(zvrf)); + } else { + vty_frame(vty, "vrf %s\n", zvrf_name(zvrf)); if (zvrf->l3vni) vty_out(vty, " vni %u%s\n", zvrf->l3vni, is_l3vni_for_prefix_routes_only( @@ -535,14 +533,15 @@ static int vrf_config_write(struct vty *vty) ? " prefix-routes-only" : ""); zebra_ns_config_write(vty, (struct ns *)vrf->ns_ctxt); + } static_config(vty, zvrf, AFI_IP, SAFI_UNICAST, "ip route"); static_config(vty, zvrf, AFI_IP, SAFI_MULTICAST, "ip mroute"); static_config(vty, zvrf, AFI_IP6, SAFI_UNICAST, "ipv6 route"); - if (vrf->vrf_id != VRF_DEFAULT) - vty_out(vty, "!\n"); + if (zvrf_id(zvrf) != VRF_DEFAULT) + vty_endframe(vty, " exit-vrf\n!\n"); } return 0; } From 371fdacc47fae79bce2efa787a4c86585fcb5ef0 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 12 Apr 2018 16:44:03 -0400 Subject: [PATCH 2/2] vtysh: remove exit-vrf for vtysh -m How It's Made: - vtysh -m is for frr-reload.py to know when a context ends. This is done by executing commands against the CLI graph, checking for walkup, and putting the appropriate context exit if walkup is necessary. Thus the default case for walking up from a vrf context is fine, and doesn't need a specific exit-vrf command. Remove that. - exit-vrf needs to be explicitly printed at the end of vrf config printing. We already do this. - vtysh's special snowflake config prettiness logic needs to know that exit-vrf goes with the vrf block and needs to be explicitly told not place this in alphabetical order in that block. We also already do this. Signed-off-by: Quentin Young --- vtysh/vtysh.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 7316477891..ec212233f6 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -671,8 +671,6 @@ int vtysh_mark_file(const char *filename) } else if ((prev_node == BGP_EVPN_VNI_NODE) && (tried == 1)) { fprintf(outputfile, "exit-vni\n"); - } else if (prev_node == VRF_NODE && (tried == 1)) { - fprintf(outputfile, "exit-vrf\n"); } else if ((prev_node == KEYCHAIN_KEY_NODE) && (tried == 1)) { fprintf(outputfile, "exit\n");