]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: register 'if_var_handlers' only once
authorRenato Westphal <renato@opensourcerouting.org>
Tue, 3 Oct 2017 01:06:00 +0000 (22:06 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Tue, 10 Oct 2017 12:01:24 +0000 (09:01 -0300)
There's no need to register 'if_var_handlers' for every VRF, we need
to do it only once.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
lib/if.c

index 1a44931fec0f5b5e4b7209f20b71b033ea80a00d..2bca93240c837846b102dabab97df36de2f26528 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -659,8 +659,30 @@ DEFUN_NOSH (no_interface,
        return CMD_SUCCESS;
 }
 
+static void if_autocomplete(vector comps, struct cmd_token *token)
+{
+       struct interface *ifp;
+       struct vrf *vrf = NULL;
+
+       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+               RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name) {
+                       vector_set(comps, XSTRDUP(MTYPE_COMPLETION, ifp->name));
+               }
+       }
+}
+
+static const struct cmd_variable_handler if_var_handlers[] = {
+       {/* "interface NAME" */
+        .varname = "interface",
+        .completions = if_autocomplete},
+       {.tokenname = "IFNAME", .completions = if_autocomplete},
+       {.tokenname = "INTERFACE", .completions = if_autocomplete},
+       {.completions = NULL}};
+
 void if_cmd_init(void)
 {
+       cmd_variable_handler_register(if_var_handlers);
+
        install_element(CONFIG_NODE, &interface_cmd);
        install_element(CONFIG_NODE, &no_interface_cmd);
 
@@ -1007,26 +1029,6 @@ ifaddr_ipv4_lookup (struct in_addr *addr, ifindex_t ifindex)
 }
 #endif /* ifaddr_ipv4_table */
 
-static void if_autocomplete(vector comps, struct cmd_token *token)
-{
-       struct interface *ifp;
-       struct listnode *ln;
-       struct vrf *vrf = NULL;
-
-       RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
-               for (ALL_LIST_ELEMENTS_RO(vrf->iflist, ln, ifp))
-                       vector_set(comps, XSTRDUP(MTYPE_COMPLETION, ifp->name));
-       }
-}
-
-static const struct cmd_variable_handler if_var_handlers[] = {
-       {/* "interface NAME" */
-        .varname = "interface",
-        .completions = if_autocomplete},
-       {.tokenname = "IFNAME", .completions = if_autocomplete},
-       {.tokenname = "INTERFACE", .completions = if_autocomplete},
-       {.completions = NULL}};
-
 /* Initialize interface list. */
 void if_init(struct list **intf_list)
 {
@@ -1036,8 +1038,6 @@ void if_init(struct list **intf_list)
 #endif /* ifaddr_ipv4_table */
 
        (*intf_list)->cmp = (int (*)(void *, void *))if_cmp_func;
-
-       cmd_variable_handler_register(if_var_handlers);
 }
 
 void if_terminate(struct list **intf_list)