]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_vty.c
Merge pull request #714 from opensourcerouting/cli_magic_defpy
[mirror_frr.git] / bgpd / bgp_vty.c
index 86b8025d2e23547c316add26aaddb15ff3c637cd..ec660effef975f6bbf6ec1a07c63617dc55f2160 100644 (file)
@@ -275,11 +275,11 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
  * that is being parsed.
  *
  * The show commands are generally of the form:
- * "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..."
+ * "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]] ..."
  *
  * Since we use argv_find if the show command in particular doesn't have:
  * [ip]
- * [<view|vrf> WORD]
+ * [<view|vrf> VIEWVRFNAME]
  * [<ipv4|ipv6> [<unicast|multicast|vpn|labeled-unicast>]]
  * The command parsing should still be ok.
  *
@@ -863,7 +863,7 @@ DEFUN (no_auto_summary,
 /* "router bgp" commands. */
 DEFUN_NOSH (router_bgp,
        router_bgp_cmd,
-       "router bgp [(1-4294967295) [<view|vrf> WORD]]",
+       "router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
        ROUTER_STR
        BGP_STR
        AS_STR
@@ -941,7 +941,7 @@ DEFUN_NOSH (router_bgp,
 /* "no router bgp" commands. */
 DEFUN (no_router_bgp,
        no_router_bgp_cmd,
-       "no router bgp [(1-4294967295) [<view|vrf> WORD]]",
+       "no router bgp [(1-4294967295) [<view|vrf> VIEWVRFNAME]]",
        NO_STR
        ROUTER_STR
        BGP_STR
@@ -1231,7 +1231,7 @@ DEFUN (bgp_maxmed_admin,
 
 DEFUN (bgp_maxmed_admin_medv,
        bgp_maxmed_admin_medv_cmd,
-       "bgp max-med administrative (0-4294967294)",
+       "bgp max-med administrative (0-4294967295)",
        BGP_STR
        "Advertise routes with max-med\n"
        "Administratively applied, for an indefinite period\n"
@@ -1241,7 +1241,7 @@ DEFUN (bgp_maxmed_admin_medv,
   int idx_number = 3;
 
   bgp->v_maxmed_admin = 1;
-  VTY_GET_INTEGER ("max-med admin med-value", bgp->maxmed_admin_value, argv[idx_number]->arg);
+  bgp->maxmed_admin_value = strtoul (argv[idx_number]->arg, NULL, 10);
 
   bgp_maxmed_update(bgp);
 
@@ -1250,7 +1250,7 @@ DEFUN (bgp_maxmed_admin_medv,
 
 DEFUN (no_bgp_maxmed_admin,
        no_bgp_maxmed_admin_cmd,
-       "no bgp max-med administrative [(0-4294967294)]",
+       "no bgp max-med administrative [(0-4294967295)]",
        NO_STR
        BGP_STR
        "Advertise routes with max-med\n"
@@ -1267,24 +1267,7 @@ DEFUN (no_bgp_maxmed_admin,
 
 DEFUN (bgp_maxmed_onstartup,
        bgp_maxmed_onstartup_cmd,
-       "bgp max-med on-startup (5-86400)",
-       BGP_STR
-       "Advertise routes with max-med\n"
-       "Effective on a startup\n"
-       "Time (seconds) period for max-med\n")
-{
-  VTY_DECLVAR_CONTEXT(bgp, bgp);
-  int idx_number = 3;
-  VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
-  bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
-  bgp_maxmed_update(bgp);
-
-  return CMD_SUCCESS;
-}
-
-DEFUN (bgp_maxmed_onstartup_medv,
-       bgp_maxmed_onstartup_medv_cmd,
-       "bgp max-med on-startup (5-86400) (0-4294967294)",
+       "bgp max-med on-startup (5-86400) [(0-4294967295)]",
        BGP_STR
        "Advertise routes with max-med\n"
        "Effective on a startup\n"
@@ -1292,10 +1275,15 @@ DEFUN (bgp_maxmed_onstartup_medv,
        "Max MED value to be used\n")
 {
   VTY_DECLVAR_CONTEXT(bgp, bgp);
-  int idx_number = 3;
-  int idx_number_2 = 4;
-  VTY_GET_INTEGER ("max-med on-startup period", bgp->v_maxmed_onstartup, argv[idx_number]->arg);
-  VTY_GET_INTEGER ("max-med on-startup med-value", bgp->maxmed_onstartup_value, argv[idx_number_2]->arg);
+  int idx = 0;
+
+  argv_find (argv, argc, "(5-86400)", &idx);
+  bgp->v_maxmed_onstartup = strtoul (argv[idx]->arg, NULL, 10);
+  if (argv_find (argv, argc, "(0-4294967295)", &idx))
+    bgp->maxmed_onstartup_value = strtoul (argv[idx]->arg, NULL, 10);
+  else
+    bgp->maxmed_onstartup_value = BGP_MAXMED_VALUE_DEFAULT;
+
   bgp_maxmed_update(bgp);
 
   return CMD_SUCCESS;
@@ -1303,7 +1291,7 @@ DEFUN (bgp_maxmed_onstartup_medv,
 
 DEFUN (no_bgp_maxmed_onstartup,
        no_bgp_maxmed_onstartup_cmd,
-       "no bgp max-med on-startup [(5-86400) [(0-4294967294)]]",
+       "no bgp max-med on-startup [(5-86400) [(0-4294967295)]]",
        NO_STR
        BGP_STR
        "Advertise routes with max-med\n"
@@ -1472,25 +1460,11 @@ DEFUN (no_bgp_wpkt_quanta,
   return bgp_wpkt_quanta_config_vty(vty, argv[idx_number]->arg, 0);
 }
 
-static int
-bgp_coalesce_config_vty (struct vty *vty, const char *num, char set)
-{
-  VTY_DECLVAR_CONTEXT(bgp, bgp);
-
-  if (set)
-    VTY_GET_INTEGER_RANGE ("coalesce-time", bgp->coalesce_time, num,
-                          0, 4294967295);
-  else
-    bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
-
-  return CMD_SUCCESS;
-}
-
 int
 bgp_config_write_coalesce_time (struct vty *vty, struct bgp *bgp)
 {
   if (bgp->coalesce_time != BGP_DEFAULT_SUBGROUP_COALESCE_TIME)
-      vty_out (vty, " coalesce-time %d%s",
+      vty_out (vty, " coalesce-time %u%s",
                bgp->coalesce_time, VTY_NEWLINE);
 
   return 0;
@@ -1503,8 +1477,12 @@ DEFUN (bgp_coalesce_time,
        "Subgroup coalesce timer\n"
        "Subgroup coalesce timer value (in ms)\n")
 {
-  int idx_number = 1;
-  return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 1);
+  VTY_DECLVAR_CONTEXT(bgp, bgp);
+
+  int idx = 0;
+  argv_find (argv, argc, "(0-4294967295)", &idx);
+  bgp->coalesce_time = strtoul (argv[idx]->arg, NULL, 10);
+  return CMD_SUCCESS;
 }
 
 DEFUN (no_bgp_coalesce_time,
@@ -1514,8 +1492,10 @@ DEFUN (no_bgp_coalesce_time,
        "Subgroup coalesce timer\n"
        "Subgroup coalesce timer value (in ms)\n")
 {
-  int idx_number = 2;
-  return bgp_coalesce_config_vty(vty, argv[idx_number]->arg, 0);
+  VTY_DECLVAR_CONTEXT(bgp, bgp);
+
+  bgp->coalesce_time = BGP_DEFAULT_SUBGROUP_COALESCE_TIME;
+  return CMD_SUCCESS;
 }
 
 /* Maximum-paths configuration */
@@ -6481,7 +6461,7 @@ bgp_clear_prefix (struct vty *vty, const char *view_name, const char *ip_str,
 /* one clear bgp command to rule them all */
 DEFUN (clear_ip_bgp_all,
        clear_ip_bgp_all_cmd,
-       "clear [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
+       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] <*|A.B.C.D|X:X::X:X|WORD|(1-4294967295)|external|peer-group WORD> [<soft [<in|out>]|in [prefix-filter]|out>]",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -6516,7 +6496,7 @@ DEFUN (clear_ip_bgp_all,
   /* clear [ip] bgp */
   if (argv_find (argv, argc, "ip", &idx))
     afi = AFI_IP;
-  /* [<view|vrf> WORD] */
+  /* [<view|vrf> VIEWVRFNAME] */
   if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
     {
       vrf = argv[idx + 1]->arg;
@@ -6586,7 +6566,7 @@ DEFUN (clear_ip_bgp_all,
 
 DEFUN (clear_ip_bgp_prefix,
        clear_ip_bgp_prefix_cmd,
-       "clear [ip] bgp [<view|vrf> WORD] prefix A.B.C.D/M",
+       "clear [ip] bgp [<view|vrf> VIEWVRFNAME] prefix A.B.C.D/M",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -6599,7 +6579,7 @@ DEFUN (clear_ip_bgp_prefix,
 
   int idx = 0;
 
-  /* [<view|vrf> WORD] */
+  /* [<view|vrf> VIEWVRFNAME] */
   if (argv_find (argv, argc, "WORD", &idx))
     vrf = argv[idx]->arg;
 
@@ -6627,7 +6607,7 @@ DEFUN (clear_bgp_ipv6_safi_prefix,
 
 DEFUN (clear_bgp_instance_ipv6_safi_prefix,
        clear_bgp_instance_ipv6_safi_prefix_cmd,
-       "clear [ip] bgp <view|vrf> WORD ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
+       "clear [ip] bgp <view|vrf> VIEWVRFNAME ipv6 "BGP_SAFI_CMD_STR" prefix X:X::X:X/M",
        CLEAR_STR
        IP_STR
        BGP_STR
@@ -7189,7 +7169,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
               else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
                 json_object_string_add(json_peer, "state", "Idle (PfxCt)");
               else
-                json_object_string_add(json_peer, "state", LOOKUP(bgp_status_msg, peer->status));
+                json_object_string_add(json_peer, "state", lookup_msg(bgp_status_msg, peer->status, NULL));
 
               if (peer->conf_if)
                 json_object_string_add(json_peer, "idType", "interface");
@@ -7241,7 +7221,7 @@ bgp_show_summary (struct vty *vty, struct bgp *bgp, int afi, int safi,
                   else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
                     vty_out (vty, " Idle (PfxCt)");
                   else
-                    vty_out (vty, " %12s", LOOKUP(bgp_status_msg, peer->status));
+                    vty_out (vty, " %12s", lookup_msg(bgp_status_msg, peer->status, NULL));
                 }
               vty_out (vty, "%s", VTY_NEWLINE);
             }
@@ -7456,7 +7436,7 @@ bgp_show_summary_vty (struct vty *vty, const char *name,
 /* `show [ip] bgp summary' commands. */
 DEFUN (show_ip_bgp_summary,
        show_ip_bgp_summary_cmd,
-       "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]",
+       "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] summary [json]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -7475,7 +7455,7 @@ DEFUN (show_ip_bgp_summary,
   /* show [ip] bgp */
   if (argv_find (argv, argc, "ip", &idx))
     afi = AFI_IP;
-  /* [<view|vrf> WORD] */
+  /* [<view|vrf> VIEWVRFNAME] */
   if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
     vrf = argv[++idx]->arg;
   /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
@@ -8231,7 +8211,7 @@ bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *js
         json_object_boolean_true_add(json_neigh, "nbrCommonAdmin");
 
       /* Status. */
-      json_object_string_add(json_neigh, "bgpState", LOOKUP (bgp_status_msg, p->status));
+      json_object_string_add(json_neigh, "bgpState", lookup_msg(bgp_status_msg, p->status, NULL));
 
       if (p->status == Established)
         {
@@ -8304,7 +8284,7 @@ bgp_show_peer (struct vty *vty, struct peer *p, u_char use_json, json_object *js
         vty_out (vty, "  Neighbor under common administration%s", VTY_NEWLINE);
 
       /* Status. */
-      vty_out (vty, "  BGP state = %s", LOOKUP (bgp_status_msg, p->status));
+      vty_out (vty, "  BGP state = %s", lookup_msg(bgp_status_msg, p->status, NULL));
 
       if (p->status == Established)
         vty_out (vty, ", up for %8s", peer_uptime (p->uptime, timebuf, BGP_UPTIME_LEN, 0, NULL));
@@ -9412,7 +9392,7 @@ bgp_show_neighbor_vty (struct vty *vty, const char *name,
 /* "show [ip] bgp neighbors" commands.  */
 DEFUN (show_ip_bgp_neighbors,
        show_ip_bgp_neighbors_cmd,
-       "show [ip] bgp [<view|vrf> WORD] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
+       "show [ip] bgp [<view|vrf> VIEWVRFNAME] [<ipv4|ipv6|vpnv4 <all|rd ASN:nn_or_IP-address:nn>>] neighbors [<A.B.C.D|X:X::X:X|WORD>] [json]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9592,7 +9572,7 @@ bgp_show_update_groups(struct vty *vty, const char *name,
 
 DEFUN (show_ip_bgp_updgrps,
        show_ip_bgp_updgrps_cmd,
-       "show [ip] bgp [<view|vrf> WORD] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]",
+       "show [ip] bgp [<view|vrf> VIEWVRFNAME] ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] update-groups [SUBGROUP-ID]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9612,7 +9592,7 @@ DEFUN (show_ip_bgp_updgrps,
   /* show [ip] bgp */
   if (argv_find (argv, argc, "ip", &idx))
     afi = AFI_IP;
-  /* [<view|vrf> WORD] */
+  /* [<view|vrf> VIEWVRFNAME] */
   if (argv_find (argv, argc, "view", &idx) || argv_find (argv, argc, "vrf", &idx))
     vrf = argv[++idx]->arg;
   /* ["BGP_AFI_CMD_STR" ["BGP_SAFI_CMD_STR"]] */
@@ -9662,7 +9642,7 @@ DEFUN (show_bgp_updgrps_stats,
 
 DEFUN (show_bgp_instance_updgrps_stats,
        show_bgp_instance_updgrps_stats_cmd,
-       "show [ip] bgp <view|vrf> WORD update-groups statistics",
+       "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups statistics",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9722,7 +9702,7 @@ DEFUN (show_ip_bgp_updgrps_adj,
 
 DEFUN (show_ip_bgp_instance_updgrps_adj,
        show_ip_bgp_instance_updgrps_adj_cmd,
-       "show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
+       "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9780,7 +9760,7 @@ DEFUN (show_bgp_updgrps_adj,
 
 DEFUN (show_bgp_instance_updgrps_adj,
        show_bgp_instance_updgrps_adj_cmd,
-       "show [ip] bgp <view|vrf> WORD update-groups <advertise-queue|advertised-routes|packet-queue>",
+       "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups <advertise-queue|advertised-routes|packet-queue>",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9821,7 +9801,7 @@ DEFUN (show_ip_bgp_updgrps_adj_s,
 
 DEFUN (show_ip_bgp_instance_updgrps_adj_s,
        show_ip_bgp_instance_updgrps_adj_s_cmd,
-       "show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
+       "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -9897,7 +9877,7 @@ DEFUN (show_bgp_updgrps_adj_s,
 
 DEFUN (show_bgp_instance_updgrps_adj_s,
        show_bgp_instance_updgrps_adj_s_cmd,
-       "show [ip] bgp <view|vrf> WORD update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
+       "show [ip] bgp <view|vrf> VIEWVRFNAME update-groups SUBGROUP-ID <advertise-queue|advertised-routes|packet-queue>",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -10009,7 +9989,7 @@ bgp_show_one_peer_group (struct vty *vty, struct peer_group *group)
           else if (CHECK_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW))
             peer_status = "Idle (PfxCt)";
           else
-            peer_status = LOOKUP(bgp_status_msg, peer->status);
+            peer_status = lookup_msg(bgp_status_msg, peer->status, NULL);
 
           dynamic = peer_dynamic_neighbor(peer);
           vty_out (vty, "    %s %s %s %s",
@@ -10084,7 +10064,7 @@ bgp_show_peer_group_vty (struct vty *vty, const char *name,
 
 DEFUN (show_ip_bgp_peer_groups,
        show_ip_bgp_peer_groups_cmd,
-       "show [ip] bgp [<view|vrf> WORD] peer-group [PGNAME]",
+       "show [ip] bgp [<view|vrf> VIEWVRFNAME] peer-group [PGNAME]",
        SHOW_STR
        IP_STR
        BGP_STR
@@ -10975,7 +10955,6 @@ bgp_vty_init (void)
   install_element (BGP_NODE, &bgp_maxmed_admin_medv_cmd);
   install_element (BGP_NODE, &bgp_maxmed_onstartup_cmd);
   install_element (BGP_NODE, &no_bgp_maxmed_onstartup_cmd);
-  install_element (BGP_NODE, &bgp_maxmed_onstartup_medv_cmd);
 
   /* bgp disable-ebgp-connected-nh-check */
   install_element (BGP_NODE, &bgp_disable_connected_route_check_cmd);