]> git.puffer.fish Git - mirror/frr.git/commitdiff
*: make DEFUN installations file-local
authorDavid Lamparter <equinox@opensourcerouting.org>
Wed, 16 Nov 2016 06:00:52 +0000 (15:00 +0900)
committerDavid Lamparter <equinox@opensourcerouting.org>
Thu, 1 Dec 2016 16:25:56 +0000 (17:25 +0100)
This moves all install_element calls into the file where the DEFUNs are
located.  This fixes several small related bugs:

- ospf6d wasn't installing a "no interface FOO" command
- zebra had a useless copy of "interface FOO"
- pimd's copy of "interface FOO" was not setting qobj_index, which means
  "description LINE" commands would fail with an error

The next commit will do the actual act of making "foo_cmd" static.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
18 files changed:
isisd/isis_circuit.c
ldpd/ldp_vty_conf.c
lib/command.c
lib/command.h
lib/if.c
lib/if.h
lib/thread.c
lib/thread.h
lib/vty.c
lib/workqueue.c
lib/workqueue.h
ospf6d/ospf6_interface.c
ospfd/ospf_vty.c
pimd/pim_cmd.c
ripd/rip_interface.c
ripngd/ripng_interface.c
vtysh/vtysh.c
zebra/interface.c

index c5812a658d89ba5c816c087951d58d87c6144cc6..8479d7f31a4f7f5941de66b62267ebef6e47d15c 100644 (file)
@@ -1418,12 +1418,7 @@ isis_circuit_init ()
 
   /* Install interface node */
   install_node (&interface_node, isis_interface_config_write);
-  install_element (CONFIG_NODE, &interface_cmd);
-  install_element (CONFIG_NODE, &no_interface_cmd);
-
-  install_default (INTERFACE_NODE);
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
+  if_cmd_init ();
 
   isis_vty_init ();
 }
index e5acada1809e30070f7877754427c58856646a1f..f2b21d81752bc068c05492379a577bbc85ca6dd0 100644 (file)
@@ -1618,14 +1618,7 @@ ldp_vty_if_init(void)
 {
        /* Install interface node. */
        install_node (&interface_node, interface_config_write);
-
-       install_element(CONFIG_NODE, &interface_cmd);
-       install_element(CONFIG_NODE, &no_interface_cmd);
-       install_default(INTERFACE_NODE);
-
-       /* "description" commands. */
-       install_element(INTERFACE_NODE, &interface_desc_cmd);
-       install_element(INTERFACE_NODE, &no_interface_desc_cmd);
+       if_cmd_init ();
 }
 
 struct iface *
index 3c429ce1a750f5912fe7c03b9a0d04d3d9c8a37c..8e935acf92fa34dad0d9f5c31085b1058b3bc2c0 100644 (file)
@@ -1050,6 +1050,13 @@ DEFUN (config_exit,
        config_exit_cmd,
        "exit",
        "Exit current mode and down to previous mode\n")
+{
+  cmd_exit (vty);
+  return CMD_SUCCESS;
+}
+
+void
+cmd_exit (struct vty *vty)
 {
   switch (vty->node)
     {
@@ -1118,7 +1125,6 @@ DEFUN (config_exit,
     default:
       break;
     }
-  return CMD_SUCCESS;
 }
 
 /* ALIAS_FIXME */
@@ -1264,17 +1270,12 @@ permute (struct graph_node *start, struct vty *vty)
   list_delete_node (position, listtail(position));
 }
 
-/* Help display function for all node. */
-DEFUN (config_list,
-       config_list_cmd,
-       "list [permutations]",
-       "Print command list\n"
-       "Print all possible command permutations\n")
+int
+cmd_list_cmds (struct vty *vty, int do_permute)
 {
   struct cmd_node *node = vector_slot (cmdvec, vty->node);
 
-  if ((strmatch (argv[0]->text, "list") && argc == 2) ||
-      (strmatch (argv[0]->text, "show") && argc == 3))
+  if (do_permute)
     permute (vector_slot (node->cmdgraph->nodes, 0), vty);
   else
   {
@@ -1289,13 +1290,23 @@ DEFUN (config_list,
   return CMD_SUCCESS;
 }
 
+/* Help display function for all node. */
+DEFUN (config_list,
+       config_list_cmd,
+       "list [permutations]",
+       "Print command list\n"
+       "Print all possible command permutations\n")
+{
+  return cmd_list_cmds (vty, argc == 2);
+}
+
 DEFUN (show_commandtree,
        show_commandtree_cmd,
        "show commandtree [permutations]",
        SHOW_STR
        "Show command tree\n")
 {
-  return config_list (self, vty, argc, argv);
+  return cmd_list_cmds (vty, argc == 3);
 }
 
 /* Write current configuration into file. */
@@ -2352,10 +2363,8 @@ cmd_init (int terminal)
       install_element (ENABLE_NODE, &config_logmsg_cmd);
       install_default (CONFIG_NODE);
 
-      install_element (VIEW_NODE, &show_thread_cpu_cmd);
-      install_element (ENABLE_NODE, &clear_thread_cpu_cmd);
-
-      install_element (VIEW_NODE, &show_work_queues_cmd);
+      thread_cmd_init ();
+      workqueue_cmd_init ();
     }
 
   install_element (CONFIG_NODE, &hostname_cmd);
index f120063ea9d5893a9a7292f2d971dc925162e914..a170a9549dd1a4f9de5a8856a3ebbfad8e5823f6 100644 (file)
@@ -414,6 +414,8 @@ extern int cmd_execute_command (vector, struct vty *, const struct cmd_element *
 extern int cmd_execute_command_strict (vector, struct vty *, const struct cmd_element **);
 extern void cmd_init (int);
 extern void cmd_terminate (void);
+extern void cmd_exit (struct vty *vty);
+extern int cmd_list_cmds (struct vty *vty, int do_permute);
 
 /* memory management for cmd_element */
 void
@@ -430,11 +432,6 @@ struct cmd_token *
 copy_cmd_token (struct cmd_token *);
 
 /* Export typical functions. */
-extern struct cmd_element config_end_cmd;
-extern struct cmd_element config_exit_cmd;
-extern struct cmd_element config_quit_cmd;
-extern struct cmd_element config_help_cmd;
-extern struct cmd_element config_list_cmd;
 extern const char *host_config_get (void);
 extern void host_config_set (const char *);
 
index dadf35574eb0aa748a25afe76abe60d2f6feb13e..c323ae9da21b600c46b65f86732ecee8c6dd1acf 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -832,6 +832,17 @@ DEFUN_NOSH (no_interface,
   return CMD_SUCCESS;
 }
 
+void
+if_cmd_init (void)
+{
+  install_element (CONFIG_NODE, &interface_cmd);
+  install_element (CONFIG_NODE, &no_interface_cmd);
+
+  install_default (INTERFACE_NODE);
+  install_element (INTERFACE_NODE, &interface_desc_cmd);
+  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
+}
+
 DEFUN (vrf,
        vrf_cmd,
        "vrf NAME",
@@ -890,6 +901,13 @@ DEFUN_NOSH (no_vrf,
   return CMD_SUCCESS;
 }
 
+void
+vrf_cmd_init (void)
+{
+  install_element (CONFIG_NODE, &vrf_cmd);
+  install_element (CONFIG_NODE, &no_vrf_cmd);
+  install_default (VRF_NODE);
+}
 
 /* For debug purpose. */
 DEFUN (show_address,
index 7fdd46d3f25f249fe7340994838b86b4ab1841b2..cf6f3bc006ee060ba5a51230731cd8b5d7615326 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -445,11 +445,14 @@ extern int if_is_pointopoint (struct interface *);
 extern int if_is_multicast (struct interface *);
 extern void if_add_hook (int, int (*)(struct interface *));
 extern void if_init (struct list **);
+extern void if_cmd_init (void);
 extern void if_terminate (struct list **);
 extern void if_dump_all (void);
 extern const char *if_flag_dump(unsigned long);
 extern const char *if_link_type_str (enum zebra_link_type);
 
+extern void vrf_cmd_init (void);
+
 /* Please use ifindex2ifname instead of if_indextoname where possible;
    ifindex2ifname uses internal interface info, whereas if_indextoname must
    make a system call. */
@@ -483,19 +486,4 @@ struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *);
 struct if_link_params *if_link_params_get (struct interface *);
 void if_link_params_free (struct interface *);
 
-/* Exported variables. */
-extern struct cmd_element interface_desc_cmd;
-extern struct cmd_element no_interface_desc_cmd;
-extern struct cmd_element interface_cmd;
-extern struct cmd_element no_interface_cmd;
-extern struct cmd_element interface_vrf_cmd;
-extern struct cmd_element no_interface_vrf_cmd;
-extern struct cmd_element interface_pseudo_cmd;
-extern struct cmd_element no_interface_pseudo_cmd;
-extern struct cmd_element show_address_cmd;
-extern struct cmd_element show_address_vrf_cmd;
-extern struct cmd_element show_address_vrf_all_cmd;
-extern struct cmd_element vrf_cmd;
-extern struct cmd_element no_vrf_cmd;
-
 #endif /* _ZEBRA_IF_H */
index ce93530ff14370c48d46f5adf18e21263a3671ab..eac7f3250b8cc251854e23215e2709c1499d8339 100644 (file)
@@ -423,6 +423,13 @@ DEFUN (clear_thread_cpu,
   return CMD_SUCCESS;
 }
 
+void
+thread_cmd_init (void)
+{
+  install_element (VIEW_NODE, &show_thread_cpu_cmd);
+  install_element (ENABLE_NODE, &clear_thread_cpu_cmd);
+}
+
 static int
 thread_timer_cmp(void *a, void *b)
 {
index e41e96dec21023cf4fb4966465bbf431f6bbe16d..5c6b96a32decd76d3732c14e269b47cd6a884171 100644 (file)
@@ -244,8 +244,7 @@ extern void thread_set_yield_time (struct thread *, unsigned long);
 
 /* Internal libzebra exports */
 extern void thread_getrusage (RUSAGE_T *);
-extern struct cmd_element show_thread_cpu_cmd;
-extern struct cmd_element clear_thread_cpu_cmd;
+extern void thread_cmd_init (void);
 
 /* replacements for the system gettimeofday(), clock_gettime() and
  * time() functions, providing support for non-decrementing clock on
index 54399b023852387df459f56a424a16994d5fe312..d5ecb1db5bf166ac564ccca86c84eb6bde08b8d7 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -715,7 +715,7 @@ static void
 vty_down_level (struct vty *vty)
 {
   vty_out (vty, "%s", VTY_NEWLINE);
-  (*config_exit_cmd.func)(NULL, vty, 0, NULL);
+  cmd_exit (vty);
   vty_prompt (vty);
   vty->cp = 0;
 }
index 549bb2360aa433aa91a1973832356db547a653e4..51017b34ea71186695c6b479368b079beb684c79 100644 (file)
@@ -222,6 +222,12 @@ DEFUN (show_work_queues,
   return CMD_SUCCESS;
 }
 
+void
+workqueue_cmd_init (void)
+{
+  install_element (VIEW_NODE, &show_work_queues_cmd);
+}
+
 /* 'plug' a queue: Stop it from being scheduled,
  * ie: prevent the queue from draining.
  */
index eaf85749077923d8763d5b48ede1591c8b210560..548f96d8b00e67b81972854cbe38729107b7e2b5 100644 (file)
@@ -129,5 +129,7 @@ bool work_queue_is_scheduled (struct work_queue *);
 
 /* Helpers, exported for thread.c and command.c */
 extern int work_queue_run (struct thread *);
-extern struct cmd_element show_work_queues_cmd;
+
+extern void workqueue_cmd_init (void);
+
 #endif /* _QUAGGA_WORK_QUEUE_H */
index 8ea4b169574efac1f6101702445c186644f3430a..74c9ac739fc8f9f235a076a2ddb0a8354b9a2ce1 100644 (file)
@@ -1845,15 +1845,12 @@ ospf6_interface_init (void)
 {
   /* Install interface node. */
   install_node (&interface_node, config_write_ospf6_interface);
+  if_cmd_init ();
 
   install_element (VIEW_NODE, &show_ipv6_ospf6_interface_prefix_cmd);
   install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_cmd);
   install_element (VIEW_NODE, &show_ipv6_ospf6_interface_ifname_prefix_cmd);
 
-  install_element (CONFIG_NODE, &interface_cmd);
-  install_default (INTERFACE_NODE);
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
   install_element (INTERFACE_NODE, &ipv6_ospf6_cost_cmd);
   install_element (INTERFACE_NODE, &no_ipv6_ospf6_cost_cmd);
   install_element (INTERFACE_NODE, &ipv6_ospf6_ifmtu_cmd);
index 8662eb4259b8d8a03c0337801dd00566231dccfd..8173835d947ba90518145c462a603d7248226ded 100644 (file)
@@ -9250,14 +9250,7 @@ ospf_vty_if_init (void)
 {
   /* Install interface node. */
   install_node (&interface_node, config_write_interface);
-
-  install_element (CONFIG_NODE, &interface_cmd);
-  install_element (CONFIG_NODE, &no_interface_cmd);
-  install_default (INTERFACE_NODE);
-
-  /* "description" commands. */
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
+  if_cmd_init ();
 
   /* "ip ospf authentication" commands. */
   install_element (INTERFACE_NODE, &ip_ospf_authentication_args_addr_cmd);
index afc42a95618fbfd82101d7b4711be6f22c9e3da1..8d7579aafcaf686e579644320e0bfe9786bdeeff 100644 (file)
@@ -1527,47 +1527,6 @@ static void clear_interfaces()
   clear_pim_interfaces();
 }
 
-DEFUN (pim_interface,
-       pim_interface_cmd,
-       "interface IFNAME",
-       "Select an interface to configure\n"
-       "Interface's name\n")
-{
-  int idx_ifname = 1;
-  struct interface *ifp;
-  const char *ifname = argv[idx_ifname]->arg;
-  size_t sl;
-
-  sl = strlen(ifname);
-  if (sl > INTERFACE_NAMSIZ) {
-    vty_out(vty, "%% Interface name %s is invalid: length exceeds "
-           "%d characters%s",
-           ifname, INTERFACE_NAMSIZ, VTY_NEWLINE);
-    return CMD_WARNING;
-  }
-
-  ifp = if_lookup_by_name_len(ifname, sl);
-  if (!ifp) {
-    vty_out(vty, "%% Interface %s does not exist%s", ifname, VTY_NEWLINE);
-
-    /* Returning here would prevent pimd from booting when there are
-       interface commands in pimd.conf, since all interfaces are
-       unknown at pimd boot time (the zebra daemon has not been
-       contacted for interface discovery). */
-    
-    ifp = if_get_by_name_len(ifname, sl);
-    if (!ifp) {
-      vty_out(vty, "%% Could not create interface %s%s", ifname, VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-  }
-
-  vty->index = ifp;
-  vty->node = INTERFACE_NODE;
-
-  return CMD_SUCCESS;
-}
-
 DEFUN (clear_ip_interfaces,
        clear_ip_interfaces_cmd,
        "clear ip interfaces",
@@ -4832,6 +4791,7 @@ void pim_cmd_init()
 {
   install_node (&pim_global_node, pim_global_config_write);       /* PIM_NODE */
   install_node (&interface_node, pim_interface_config_write); /* INTERFACE_NODE */
+  if_cmd_init ();
 
   install_element (CONFIG_NODE, &ip_multicast_routing_cmd);
   install_element (CONFIG_NODE, &no_ip_multicast_routing_cmd);
@@ -4839,14 +4799,7 @@ void pim_cmd_init()
   install_element (CONFIG_NODE, &no_ip_pim_rp_cmd);
   install_element (CONFIG_NODE, &ip_ssmpingd_cmd);
   install_element (CONFIG_NODE, &no_ip_ssmpingd_cmd); 
-#if 0
-  install_element (CONFIG_NODE, &interface_cmd); /* from if.h */
-#else
-  install_element (CONFIG_NODE, &pim_interface_cmd);
-#endif
-  install_element (CONFIG_NODE, &no_interface_cmd); /* from if.h */
-
-  install_default (INTERFACE_NODE);
+
   install_element (INTERFACE_NODE, &interface_ip_igmp_cmd);
   install_element (INTERFACE_NODE, &interface_no_ip_igmp_cmd); 
   install_element (INTERFACE_NODE, &interface_ip_igmp_join_cmd);
index 8c5092d78754f2bf6cd27ef7b6a636be2c683d1c..f2ce7e760d816b1a9a059b49b00ea7d3163d7e66 100644 (file)
@@ -2004,13 +2004,9 @@ rip_if_init (void)
 
   /* Install interface node. */
   install_node (&interface_node, rip_interface_config_write);
+  if_cmd_init ();
 
   /* Install commands. */
-  install_element (CONFIG_NODE, &interface_cmd);
-  install_element (CONFIG_NODE, &no_interface_cmd);
-  install_default (INTERFACE_NODE);
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
   install_element (RIP_NODE, &rip_network_cmd);
   install_element (RIP_NODE, &no_rip_network_cmd);
   install_element (RIP_NODE, &rip_neighbor_cmd);
index 7bee7625d1d482731cd1583a7cd7ea99547b3d3f..393ca2e7a6fcd5dbdf570a74bba924bca13e1d1c 100644 (file)
@@ -1190,13 +1190,7 @@ ripng_if_init ()
 
   /* Install interface node. */
   install_node (&interface_node, interface_config_write);
-  
-  /* Install commands. */
-  install_element (CONFIG_NODE, &interface_cmd);
-  install_element (CONFIG_NODE, &no_interface_cmd);
-  install_default (INTERFACE_NODE);
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
+  if_cmd_init ();
 
   install_element (RIPNG_NODE, &ripng_network_cmd);
   install_element (RIPNG_NODE, &no_ripng_network_cmd);
index b622fa97432b66d9ec23fa32e28c04bbbb9d2d70..0a83b56be0f30e94ef26b01a698055ec60496f0a 100644 (file)
@@ -2796,6 +2796,15 @@ DEFUN (vtysh_start_zsh,
 }
 #endif
 
+DEFUN (config_list,
+       config_list_cmd,
+       "list [permutations]",
+       "Print command list\n"
+       "Print all possible command permutations\n")
+{
+  return cmd_list_cmds (vty, argc == 2);
+}
+
 static void
 vtysh_install_default (enum node_type node)
 {
index 91dbe52764129d9f5a69b4be824b041b30380684..e9cbd72af915d0a8703de74ce7d8f73eba42c3c3 100644 (file)
@@ -1223,32 +1223,6 @@ if_dump_vty (struct vty *vty, struct interface *ifp)
 #endif /* HAVE_NET_RT_IFLIST */
 }
 
-/* Wrapper hook point for zebra daemon so that ifindex can be set 
- * DEFUN macro not used as extract.pl HAS to ignore this
- * See also interface_cmd in lib/if.c
- */ 
-DEFUN_NOSH (zebra_interface,
-           zebra_interface_cmd,
-           "interface IFNAME",
-           "Select an interface to configure\n"
-           "Interface's name\n")
-{
-  int ret;
-  
-  /* Call lib interface() */
-  if ((ret = interface_cmd.func (self, vty, argc, argv)) != CMD_SUCCESS)
-    return ret;
-
-  VTY_DECLVAR_CONTEXT (interface, ifp);
-
-  if (ifp->ifindex == IFINDEX_INTERNAL)
-    /* Is this really necessary?  Shouldn't status be initialized to 0
-       in that case? */
-    UNSET_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE);
-
-  return ret;
-}
-
 static void
 interface_update_stats (void)
 {
@@ -1269,6 +1243,7 @@ struct cmd_node interface_node =
   1
 };
 
+#if 0
 /* Wrapper hook point for zebra daemon so that ifindex can be set 
  * DEFUN macro not used as extract.pl HAS to ignore this
  * See also interface_cmd in lib/if.c
@@ -1288,6 +1263,7 @@ DEFUN_NOSH (zebra_vrf,
 
   return ret;
 }
+#endif
 
 struct cmd_node vrf_node =
 {
@@ -2934,6 +2910,7 @@ zebra_if_init (void)
   install_node (&interface_node, if_config_write);
   install_node (&link_params_node, NULL);
   install_node (&vrf_node, vrf_config_write);
+  if_cmd_init ();
 
   install_element (VIEW_NODE, &show_interface_cmd);
   install_element (VIEW_NODE, &show_interface_vrf_all_cmd);
@@ -2942,11 +2919,6 @@ zebra_if_init (void)
 
   install_element (ENABLE_NODE, &show_interface_desc_cmd);
   install_element (ENABLE_NODE, &show_interface_desc_vrf_all_cmd);
-  install_element (CONFIG_NODE, &zebra_interface_cmd);
-  install_element (CONFIG_NODE, &no_interface_cmd);
-  install_default (INTERFACE_NODE);
-  install_element (INTERFACE_NODE, &interface_desc_cmd);
-  install_element (INTERFACE_NODE, &no_interface_desc_cmd);
   install_element (INTERFACE_NODE, &multicast_cmd);
   install_element (INTERFACE_NODE, &no_multicast_cmd);
   install_element (INTERFACE_NODE, &linkdetect_cmd);
@@ -2991,7 +2963,5 @@ zebra_if_init (void)
   install_element(LINK_PARAMS_NODE, &no_link_params_use_bw_cmd);
   install_element(LINK_PARAMS_NODE, &exit_link_params_cmd);
 
-  install_element (CONFIG_NODE, &zebra_vrf_cmd);
-  install_element (CONFIG_NODE, &no_vrf_cmd);
-  install_default (VRF_NODE);
+  vrf_cmd_init();
 }