]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib: distribute.c, smux.c, vty.c grammar refactor
authorQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 22 Sep 2016 20:17:48 +0000 (20:17 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Thu, 22 Sep 2016 20:17:48 +0000 (20:17 +0000)
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
lib/distribute.c
lib/smux.c
lib/vty.c

index d0d637fbb412f39a442114dac1d7ffae4fada78e..2a2647f23d4f5fc413cbc90df5ce5ea2f92447c6 100644 (file)
@@ -303,325 +303,71 @@ distribute_list_prefix_unset (const char *ifname, enum distribute_type type,
   return 1;
 }
 
-DEFUN (distribute_list_all,
-       distribute_list_all_cmd,
-       "distribute-list WORD (in|out)",
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-{
-  enum distribute_type type;
-
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s",
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  /* Get interface name corresponding distribute list. */
-  distribute_list_set (NULL, type, argv[0]);
-
-  return CMD_SUCCESS;
-}
-
-ALIAS (distribute_list_all,
-       ipv6_distribute_list_all_cmd,
-       "distribute-list WORD (in|out)",
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-
-DEFUN (no_distribute_list_all,
-       no_distribute_list_all_cmd,
-       "no distribute-list WORD (in|out)",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-{
-  int ret;
-  enum distribute_type type;
-
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s",
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  ret = distribute_list_unset (NULL, type, argv[0]);
-  if (! ret)
-    {
-      vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-  return CMD_SUCCESS;
-}
-
-ALIAS (no_distribute_list_all,
-       no_ipv6_distribute_list_all_cmd,
-       "no distribute-list WORD (in|out)",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-
 DEFUN (distribute_list,
        distribute_list_cmd,
-       "distribute-list WORD (in|out) WORD",
+       "distribute-list [prefix] WORD <in|out> [WORD]",
        "Filter networks in routing updates\n"
        "Access-list name\n"
        "Filter incoming routing updates\n"
        "Filter outgoing routing updates\n"
        "Interface name\n")
 {
-  enum distribute_type type;
+  int prefix = (argv[1]->type == WORD_TKN) ? 1 : 0;
 
   /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  /* Get interface name corresponding distribute list. */
-  distribute_list_set (argv[2], type, argv[0]);
-
-  return CMD_SUCCESS;
-}       
-
-ALIAS (distribute_list,
-       ipv6_distribute_list_cmd,
-       "distribute-list WORD (in|out) WORD",
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
+  enum distribute_type type = argv[2 + prefix]->arg[0] == 'i' ?
+    DISTRIBUTE_IN : DISTRIBUTE_OUT;
 
-DEFUN (no_distribute_list, no_distribute_list_cmd,
-       "no distribute-list WORD (in|out) WORD",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Access-list name\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
-{
-  int ret;
-  enum distribute_type type;
+  /* Set appropriate function call */
+  int (*distfn)(const char *, enum distribute_type, const char *) = prefix ? 
+    &distribute_list_prefix_set : &distribute_list_set;
+  
+  /* if interface is present, get name */
+  const char *ifname = NULL;
+  if (argv[argc - 1]->type == VARIABLE_TKN)
+    ifname = argv[argc - 1]->arg;
 
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", VTY_NEWLINE);
-      return CMD_WARNING;
-    }
+  /* Get interface name corresponding distribute list. */
+  distfn (ifname, type, argv[1 + prefix]->arg);
 
-  ret = distribute_list_unset (argv[2], type, argv[0]);
-  if (! ret)
-    {
-      vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
-      return CMD_WARNING;
-    }
   return CMD_SUCCESS;
-}       
+}
 
-ALIAS (no_distribute_list, no_ipv6_distribute_list_cmd,
-       "no distribute-list WORD (in|out) WORD",
+DEFUN (no_distribute_list,
+       no_distribute_list_cmd,
+       "no distribute-list [prefix] WORD <in|out> [WORD]",
        NO_STR
        "Filter networks in routing updates\n"
        "Access-list name\n"
        "Filter incoming routing updates\n"
        "Filter outgoing routing updates\n"
        "Interface name\n")
-
-DEFUN (distribute_list_prefix_all,
-       distribute_list_prefix_all_cmd,
-       "distribute-list prefix WORD (in|out)",
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
 {
-  enum distribute_type type;
+  int prefix = (argv[2]->type == WORD_TKN) ? 1 : 0;
 
   /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", 
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  /* Get interface name corresponding distribute list. */
-  distribute_list_prefix_set (NULL, type, argv[0]);
-
-  return CMD_SUCCESS;
-}       
-
-ALIAS (distribute_list_prefix_all,
-       ipv6_distribute_list_prefix_all_cmd,
-       "distribute-list prefix WORD (in|out)",
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
+  enum distribute_type type = argv[3 + prefix]->arg[0] == 'i' ?
+    DISTRIBUTE_IN : DISTRIBUTE_OUT;
 
-DEFUN (no_distribute_list_prefix_all,
-       no_distribute_list_prefix_all_cmd,
-       "no distribute-list prefix WORD (in|out)",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-{
-  int ret;
-  enum distribute_type type;
-
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", 
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  ret = distribute_list_prefix_unset (NULL, type, argv[0]);
-  if (! ret)
-    {
-      vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-  return CMD_SUCCESS;
-}       
-
-ALIAS (no_distribute_list_prefix_all,
-       no_ipv6_distribute_list_prefix_all_cmd,
-       "no distribute-list prefix WORD (in|out)",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n")
-
-DEFUN (distribute_list_prefix, distribute_list_prefix_cmd,
-       "distribute-list prefix WORD (in|out) WORD",
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
-{
-  enum distribute_type type;
-
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", 
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
+  /* Set appropriate function call */
+  int (*distfn)(const char *, enum distribute_type, const char *) = prefix ? 
+    &distribute_list_prefix_unset : &distribute_list_unset;
+  
+  /* if interface is present, get name */
+  const char *ifname = NULL;
+  if (argv[argc - 1]->type == VARIABLE_TKN)
+    ifname = argv[argc - 1]->arg;
 
   /* Get interface name corresponding distribute list. */
-  distribute_list_prefix_set (argv[2], type, argv[0]);
-
-  return CMD_SUCCESS;
-}       
-
-ALIAS (distribute_list_prefix, ipv6_distribute_list_prefix_cmd,
-       "distribute-list prefix WORD (in|out) WORD",
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
-
-DEFUN (no_distribute_list_prefix, no_distribute_list_prefix_cmd,
-       "no distribute-list prefix WORD (in|out) WORD",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
-{
-  int ret;
-  enum distribute_type type;
+  int ret = distfn (ifname, type, argv[2 + prefix]->arg);
 
-  /* Check of distribute list type. */
-  if (strncmp (argv[1], "i", 1) == 0)
-    type = DISTRIBUTE_IN;
-  else if (strncmp (argv[1], "o", 1) == 0)
-    type = DISTRIBUTE_OUT;
-  else
-    {
-      vty_out (vty, "distribute list direction must be [in|out]%s", 
-              VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
-  ret = distribute_list_prefix_unset (argv[2], type, argv[0]);
   if (! ret)
     {
       vty_out (vty, "distribute list doesn't exist%s", VTY_NEWLINE);
       return CMD_WARNING;
     }
   return CMD_SUCCESS;
-}       
-
-ALIAS (no_distribute_list_prefix, no_ipv6_distribute_list_prefix_cmd,
-       "no distribute-list prefix WORD (in|out) WORD",
-       NO_STR
-       "Filter networks in routing updates\n"
-       "Filter prefixes in routing updates\n"
-       "Name of an IP prefix-list\n"
-       "Filter incoming routing updates\n"
-       "Filter outgoing routing updates\n"
-       "Interface name\n")
+}
 
 int
 config_show_distribute (struct vty *vty)
@@ -770,25 +516,6 @@ distribute_list_init (int node)
   disthash = hash_create (distribute_hash_make,
                           (int (*) (const void *, const void *)) distribute_cmp);
 
-  if(node==RIP_NODE) {
-    install_element (node, &distribute_list_all_cmd);
-    install_element (node, &no_distribute_list_all_cmd);
-    install_element (node, &distribute_list_cmd);
-    install_element (node, &no_distribute_list_cmd);
-    install_element (node, &distribute_list_prefix_all_cmd);
-    install_element (node, &no_distribute_list_prefix_all_cmd);
-    install_element (node, &distribute_list_prefix_cmd);
-    install_element (node, &no_distribute_list_prefix_cmd);
-  } else if (node == RIPNG_NODE) {
-    /* WARNING: two identical commands installed do a crash, so be worry with
-     * aliases */
-    install_element (node, &ipv6_distribute_list_all_cmd);
-    install_element (node, &no_ipv6_distribute_list_all_cmd);
-    install_element (node, &ipv6_distribute_list_cmd);
-    install_element (node, &no_ipv6_distribute_list_cmd);
-    install_element (node, &ipv6_distribute_list_prefix_all_cmd);
-    install_element (node, &no_ipv6_distribute_list_prefix_all_cmd);
-    install_element (node, &ipv6_distribute_list_prefix_cmd);
-    install_element (node, &no_ipv6_distribute_list_prefix_cmd);
-  }
+  install_element (node, &distribute_list_cmd);
+  install_element (node, &no_distribute_list_cmd);
 }
index 5012e8d95eb4a48b24a740a92a1602cd507af31c..5727227248ca506f1d9a3ed101806abb7ffdfd27 100644 (file)
@@ -1370,7 +1370,7 @@ DEFUN (smux_peer,
        "SNMP MUX peer settings\n"
        "Object ID used in SMUX peering\n")
 {
-  if (smux_peer_oid (vty, argv[0], NULL) == 0)
+  if (smux_peer_oid (vty, argv[2]->arg, NULL) == 0)
     {
       smux_start();
       return CMD_SUCCESS;
@@ -1387,7 +1387,7 @@ DEFUN (smux_peer_password,
        "SMUX peering object ID\n"
        "SMUX peering password\n")
 {
-  if (smux_peer_oid (vty, argv[0], argv[1]) == 0)
+  if (smux_peer_oid (vty, argv[2]->arg, argv[3]->rg) == 0)
     {
       smux_start();
       return CMD_SUCCESS;
@@ -1398,32 +1398,17 @@ DEFUN (smux_peer_password,
 
 DEFUN (no_smux_peer,
        no_smux_peer_cmd,
-       "no smux peer",
+       "no smux peer [OID [PASSWORD]]",
        NO_STR
        "SNMP MUX protocol settings\n"
-       "SNMP MUX peer settings\n")
+       "SNMP MUX peer settings\n"
+       "SMUX peering object ID\n"
+       "SMUX peering password\n")
 {
   smux_stop();
   return smux_peer_default ();
 }
 
-ALIAS (no_smux_peer,
-       no_smux_peer_oid_cmd,
-       "no smux peer OID",
-       NO_STR
-       "SNMP MUX protocol settings\n"
-       "SNMP MUX peer settings\n"
-       "SMUX peering object ID\n")
-
-ALIAS (no_smux_peer,
-       no_smux_peer_oid_password_cmd,
-       "no smux peer OID PASSWORD",
-       NO_STR
-       "SNMP MUX protocol settings\n"
-       "SNMP MUX peer settings\n"
-       "SMUX peering object ID\n"
-       "SMUX peering password\n")
-
 static int
 config_write_smux (struct vty *vty)
 {
index 900183fe5500247fac17c9672c4772d0622bd3b6..a106d5d24d32995c252b457d8e224b52ca7cfe38 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -983,6 +983,8 @@ vty_describe_fold (struct vty *vty, int cmd_width,
   const char *cmd, *p;
   int pos;
 
+  cmd = token->text;
+
   if (desc_width <= 0)
     {
       vty_out (vty, "  %-*s  %s%s", cmd_width, cmd, token->desc, VTY_NEWLINE);
@@ -2742,7 +2744,7 @@ exec_timeout (struct vty *vty, const char *min_str, const char *sec_str)
 
 DEFUN (exec_timeout_min,
        exec_timeout_min_cmd,
-       "exec-timeout <0-35791>",
+       "exec-timeout (0-35791)",
        "Set timeout value\n"
        "Timeout value in minutes\n")
 {
@@ -2751,7 +2753,7 @@ DEFUN (exec_timeout_min,
 
 DEFUN (exec_timeout_sec,
        exec_timeout_sec_cmd,
-       "exec-timeout <0-35791> <0-2147483>",
+       "exec-timeout (0-35791) (0-2147483)",
        "Set the EXEC timeout\n"
        "Timeout in minutes\n"
        "Timeout in seconds\n")
@@ -2791,7 +2793,8 @@ DEFUN (no_vty_access_class,
        "Filter connections based on an IP access list\n"
        "IP access list\n")
 {
-  if (! vty_accesslist_name || (argc && strcmp(vty_accesslist_name, argv[2]->arg)))
+  const char *accesslist = (argc == 3) ? argv[2]->arg : NULL;
+  if (! vty_accesslist_name || (argc && strcmp(vty_accesslist_name, accesslist)))
     {
       vty_out (vty, "Access-class is not currently applied to vty%s",
                VTY_NEWLINE);
@@ -2831,8 +2834,10 @@ DEFUN (no_vty_ipv6_access_class,
        "Filter connections based on an IP access list\n"
        "IPv6 access list\n")
 {
+  const char *accesslist = (argc == 4) ? argv[3]->arg : NULL;
+
   if (! vty_ipv6_accesslist_name ||
-      (argc && strcmp(vty_ipv6_accesslist_name, argv[3]->arg)))
+      (argc && strcmp(vty_ipv6_accesslist_name, accesslist)))
     {
       vty_out (vty, "IPv6 access-class is not currently applied to vty%s",
                VTY_NEWLINE);