From 91e5b43ab4d532cfbc38e71621c87fe98fb63130 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Sun, 8 Jul 2018 21:39:37 -0300 Subject: [PATCH] lib, vtysh: fix inconsistent interface commands in vtysh The definition of the interface commands in vtysh.c were outdated. Currently, all daemons that call if_cmd_init() will have the "no interface IFNAME" command and the "[no] description" commands as well, so there's no need to define exceptions for these commands anymore. To fix this, make extract.pl parse the if.c file so that vtysh can get the interface commands from there automatically. Only the "interface IFNAME [vrf NAME]" must be kept in vtysh.c because it changes the vty node and thus needs special treatment. Finally, make pimd and pbrd display interface descriptions on "sh run" when they are configured. Signed-off-by: Renato Westphal --- lib/if.c | 16 ++++++++-------- pbrd/pbr_vty.c | 3 +++ pimd/pim_vty.c | 5 +++++ vtysh/Makefile.am | 2 +- vtysh/extract.pl.in | 3 +++ vtysh/vtysh.c | 29 ----------------------------- 6 files changed, 20 insertions(+), 38 deletions(-) diff --git a/lib/if.c b/lib/if.c index e31ccd8563..dd7d210381 100644 --- a/lib/if.c +++ b/lib/if.c @@ -626,7 +626,7 @@ static struct interface *if_sunwzebra_get(char *name, vrf_id_t vrf_id) } #endif /* SUNOS_5 */ -DEFUN (interface, +DEFUN_NOSH (interface, interface_cmd, "interface IFNAME [vrf NAME]", "Select an interface to configure\n" @@ -669,13 +669,13 @@ DEFUN (interface, return CMD_SUCCESS; } -DEFUN_NOSH (no_interface, - no_interface_cmd, - "no interface IFNAME [vrf NAME]", - NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n" - VRF_CMD_HELP_STR) +DEFUN (no_interface, + no_interface_cmd, + "no interface IFNAME [vrf NAME]", + NO_STR + "Delete a pseudo interface's configuration\n" + "Interface's name\n" + VRF_CMD_HELP_STR) { int idx_vrf = 4; const char *ifname = argv[2]->arg; diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index 44e14c5477..a4b87f99d9 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -580,6 +580,9 @@ static int pbr_interface_config_write(struct vty *vty) vty_frame(vty, "interface %s vrf %s\n", ifp->name, vrf->name); + if (ifp->desc) + vty_out(vty, " description %s\n", ifp->desc); + pbr_map_write_interfaces(vty, ifp); vty_endframe(vty, "!\n"); diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c index f4d833c26f..88be195bee 100644 --- a/pimd/pim_vty.c +++ b/pimd/pim_vty.c @@ -258,6 +258,11 @@ int pim_interface_config_write(struct vty *vty) ifp->name, vrf->name); ++writes; + if (ifp->desc) { + vty_out(vty, " description %s\n", ifp->desc); + ++writes; + } + if (ifp->info) { struct pim_interface *pim_ifp = ifp->info; diff --git a/vtysh/Makefile.am b/vtysh/Makefile.am index 6d0b4a8fdb..9f81b42e32 100644 --- a/vtysh/Makefile.am +++ b/vtysh/Makefile.am @@ -154,7 +154,7 @@ vtysh_cmd_FILES = $(vtysh_scan) \ $(top_srcdir)/lib/keychain.c $(top_srcdir)/lib/routemap.c \ $(top_srcdir)/lib/filter.c $(top_srcdir)/lib/plist.c \ $(top_srcdir)/lib/distribute.c $(top_srcdir)/lib/if_rmap.c \ - $(top_srcdir)/lib/vrf.c \ + $(top_srcdir)/lib/vrf.c $(top_srcdir)/lib/if.c \ $(top_srcdir)/lib/vty.c $(top_srcdir)/zebra/debug.c \ $(top_srcdir)/lib/logicalrouter.c \ $(top_srcdir)/lib/nexthop_group.c \ diff --git a/vtysh/extract.pl.in b/vtysh/extract.pl.in index b93314c967..92b5686a94 100755 --- a/vtysh/extract.pl.in +++ b/vtysh/extract.pl.in @@ -87,6 +87,9 @@ foreach (@ARGV) { elsif ($file =~ /lib\/vrf\.c$/) { $protocol = "VTYSH_VRF"; } + elsif ($file =~ /lib\/if\.c$/) { + $protocol = "VTYSH_INTERFACE"; + } elsif ($file =~ /lib\/logicalrouter\.c$/) { $protocol = "VTYSH_ALL"; } diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 4e24bef929..229337d82f 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2018,18 +2018,6 @@ DEFUNSH(VTYSH_ZEBRA, vtysh_pseudowire, vtysh_pseudowire_cmd, return CMD_SUCCESS; } -/* TODO Implement "no interface command in isisd. */ -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_RIPNGD | VTYSH_OSPFD | VTYSH_OSPF6D - | VTYSH_EIGRPD, - vtysh_no_interface_cmd, "no interface IFNAME", NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n") - -DEFSH(VTYSH_ZEBRA, vtysh_no_interface_vrf_cmd, "no interface IFNAME vrf NAME", - NO_STR - "Delete a pseudo interface's configuration\n" - "Interface's name\n" VRF_CMD_HELP_STR) - DEFUNSH(VTYSH_ZEBRA, vtysh_logicalrouter, vtysh_logicalrouter_cmd, "logical-router (1-65535) ns NAME", "Enable a logical-router\n" @@ -2119,19 +2107,6 @@ DEFUNSH(VTYSH_VRF, vtysh_quit_nexthop_group, vtysh_quit_nexthop_group_cmd, return vtysh_exit_nexthop_group(self, vty, argc, argv); } -/* - * TODO Implement interface description commands in ripngd, ospf6d - * and isisd. - */ -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD, - vtysh_interface_desc_cmd, "description LINE...", - "Interface specific description\n" - "Characters describing this interface\n") - -DEFSH(VTYSH_ZEBRA | VTYSH_RIPD | VTYSH_OSPFD | VTYSH_EIGRPD, - vtysh_no_interface_desc_cmd, "no description", - NO_STR "Interface specific description\n") - DEFUNSH(VTYSH_INTERFACE, vtysh_exit_interface, vtysh_exit_interface_cmd, "exit", "Exit current mode and down to previous mode\n") { @@ -3584,8 +3559,6 @@ void vtysh_init_vty(void) install_element(PBRMAP_NODE, &vtysh_end_all_cmd); install_element(VTY_NODE, &vtysh_end_all_cmd); - install_element(INTERFACE_NODE, &vtysh_interface_desc_cmd); - install_element(INTERFACE_NODE, &vtysh_no_interface_desc_cmd); install_element(INTERFACE_NODE, &vtysh_end_all_cmd); install_element(INTERFACE_NODE, &vtysh_exit_interface_cmd); install_element(LINK_PARAMS_NODE, &exit_link_params_cmd); @@ -3689,8 +3662,6 @@ void vtysh_init_vty(void) install_element(KEYCHAIN_NODE, &key_chain_cmd); install_element(KEYCHAIN_KEY_NODE, &key_chain_cmd); install_element(CONFIG_NODE, &vtysh_interface_cmd); - install_element(CONFIG_NODE, &vtysh_no_interface_cmd); - install_element(CONFIG_NODE, &vtysh_no_interface_vrf_cmd); install_element(CONFIG_NODE, &vtysh_pseudowire_cmd); install_element(INTERFACE_NODE, &vtysh_link_params_cmd); install_element(ENABLE_NODE, &vtysh_show_running_config_cmd); -- 2.39.5