]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgp: Fix view/vrf lookup
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 Mar 2017 18:31:01 +0000 (13:31 -0500)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 2 Mar 2017 18:31:01 +0000 (13:31 -0500)
This commit fixes the view/vrf lookup that got broken.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
bgpd/bgp_route.c
bgpd/bgp_vty.c
bgpd/bgp_vty.h

index 55823a272fd0a2e41ac6252ecb7fe8e55ff9436b..a9a2c38c814b383d84158be6f5c3f3bb67354342 100644 (file)
@@ -8358,7 +8358,6 @@ DEFUN (show_ip_bgp,
        "Display route and more specific routes\n"
        JSON_STR)
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   afi_t afi = AFI_IP6;
   safi_t safi = SAFI_UNICAST;
   int exact_match = 0;
@@ -8366,23 +8365,13 @@ DEFUN (show_ip_bgp,
   struct bgp *bgp = NULL;
   int idx = 0;
 
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
   int uj = use_json (argc, argv);
   if (uj) argc--;
 
-  bgp = bgp_lookup_by_vrf_id (vrf);
-  if (bgp == NULL)
-    {
-      if (vrf == VRF_DEFAULT)
-        vty_out (vty, "Can't find BGP instance (default)%s", VTY_NEWLINE);
-      else
-        vty_out (vty, "Can't find BGP instance %d%s", vrf, VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
   if (argv_find(argv, argc, "cidr-only", &idx))
     return bgp_show (vty, bgp, afi, safi, bgp_show_type_cidr_only, NULL, uj);
 
@@ -8465,7 +8454,7 @@ DEFUN (show_ip_bgp_route,
 
   afi_t afi = AFI_IP6;
   safi_t safi = SAFI_UNICAST;
-  vrf_id_t vrf = VRF_DEFAULT;;
+  //  vrf_id_t vrf = VRF_DEFAULT;;
   char *prefix = NULL;
   struct bgp *bgp = NULL;
   enum bgp_path_type path_type;
@@ -8473,20 +8462,11 @@ DEFUN (show_ip_bgp_route,
 
   int idx = 0;
 
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
-  if (vrf != VRF_ALL)
-    {
-      bgp = bgp_lookup_by_vrf_id (vrf);
-      if (bgp == NULL)
-        {
-          vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
-          return CMD_WARNING;
-        }
-    }
-  else
+  if (!bgp)
     {
       vty_out (vty, "Specified 'all' vrf's but this command currently only works per view/vrf%s", VTY_NEWLINE);
       return CMD_WARNING;
@@ -8534,12 +8514,12 @@ DEFUN (show_ip_bgp_regexp,
        "Display routes matching the AS path regular expression\n"
        "A regular-expression to match the BGP AS paths\n")
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   afi_t afi = AFI_IP6;
   safi_t safi = SAFI_UNICAST;
+  struct bgp *bgp = NULL;
 
   int idx = 0;
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
@@ -8564,12 +8544,12 @@ DEFUN (show_ip_bgp_instance_all,
        BGP_SAFI_HELP_STR
        JSON_STR)
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   afi_t afi = AFI_IP;
   safi_t safi = SAFI_UNICAST;
+  struct bgp *bgp = NULL;
 
   int idx = 0;
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
@@ -9253,41 +9233,19 @@ DEFUN (show_ip_bgp_instance_neighbor_prefix_counts,
        "Display detailed prefix count information\n"
        JSON_STR)
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   afi_t afi = AFI_IP6;
   safi_t safi = SAFI_UNICAST;
   struct peer *peer;
   int idx = 0;
   struct bgp *bgp = NULL;
 
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
   int uj = use_json (argc, argv);
   if (uj) argc--;
 
-  if (vrf != VRF_ALL)
-    {
-      bgp = bgp_lookup_by_vrf_id (vrf);
-      if (bgp == NULL)
-        {
-          if (uj)
-            {
-              json_object *json_no = NULL;
-              json_no = json_object_new_object();
-              json_object_string_add(json_no, "warning", "Can't find BGP view");
-              vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
-              json_object_free(json_no);
-            }
-          else
-            vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
-          return CMD_WARNING;
-        }
-    }
-  else
-    bgp = NULL;
-
   argv_find (argv, argc, "neighbors", &idx);
   peer = peer_lookup_in_view (vty, bgp, argv[idx+1]->arg, uj);
   if (! peer)
@@ -9629,7 +9587,6 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
        "Name of the route map\n"
        JSON_STR)
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   afi_t afi = AFI_IP6;
   safi_t safi = SAFI_UNICAST;
   char *rmap_name = NULL;
@@ -9640,29 +9597,13 @@ DEFUN (show_ip_bgp_instance_neighbor_advertised_route,
 
   int idx = 0;
 
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
   int uj = use_json (argc, argv);
   if (uj) argc--;
 
-  bgp = bgp_lookup_by_vrf_id (vrf);
-  if (bgp == NULL)
-    {
-      if (uj)
-       {
-         json_object *json_no = NULL;
-         json_no = json_object_new_object();
-         json_object_string_add(json_no, "warning", "Can't find BGP view");
-         vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
-         json_object_free(json_no);
-            }
-      else
-       vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
-      return CMD_WARNING;
-    }
-
   /* neighbors <A.B.C.D|X:X::X:X|WORD> */
   argv_find (argv, argc, "neighbors", &idx);
   peerstr = argv[++idx]->arg;
@@ -9809,7 +9750,6 @@ DEFUN (show_ip_bgp_neighbor_routes,
        "Display routes learned from neighbor\n"
        JSON_STR)
 {
-  vrf_id_t vrf = VRF_DEFAULT;
   char *peerstr = NULL;
   struct bgp *bgp = NULL;
   afi_t afi = AFI_IP6;
@@ -9819,34 +9759,13 @@ DEFUN (show_ip_bgp_neighbor_routes,
 
   int idx = 0;
 
-  bgp_vty_find_and_parse_afi_safi_vrf (vty, argv, argc, &idx, &afi, &safi, &vrf);
+  bgp_vty_find_and_parse_afi_safi_bgp (vty, argv, argc, &idx, &afi, &safi, &bgp);
   if (!idx)
     return CMD_WARNING;
 
   int uj = use_json (argc, argv);
   if (uj) argc--;
 
-  if (vrf != VRF_ALL)
-    {
-      bgp = bgp_lookup_by_vrf_id (vrf);
-      if (bgp == NULL)
-        {
-          if (uj)
-            {
-              json_object *json_no = NULL;
-              json_no = json_object_new_object();
-              json_object_string_add(json_no, "warning", "Can't find BGP view");
-              vty_out (vty, "%s%s", json_object_to_json_string(json_no), VTY_NEWLINE);
-              json_object_free(json_no);
-            }
-          else
-            vty_out (vty, "Can't find BGP instance %s%s", argv[5]->arg, VTY_NEWLINE);
-          return CMD_WARNING;
-        }
-    }
-  else
-    bgp = NULL;
-
   /* neighbors <A.B.C.D|X:X::X:X|WORD> */
   argv_find (argv, argc, "neighbors", &idx);
   peerstr = argv[++idx]->arg;
index 6ad356a04c985a19cdf68fe7011fd25556bb63bb..1a8e693720f83a00c9bd246596e8bc24053cffbc 100644 (file)
@@ -214,10 +214,10 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
 }
 
 /*
- * bgp_vty_find_and_parse_afi_safi_vrf
+ * bgp_vty_find_and_parse_afi_safi_bgp
  *
- * For a given 'show ...' command, correctly parse the afi/safi/vrf out from it
- * This function *assumes* that the calling function pre-sets the afi/safi/vrf
+ * For a given 'show ...' command, correctly parse the afi/safi/bgp out from it
+ * This function *assumes* that the calling function pre-sets the afi/safi/bgp
  * to appropriate values for the calling function.  This is to allow the
  * calling function to make decisions appropriate for the show command
  * that is being parsed.
@@ -238,7 +238,7 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
  * idx  -> The current place in the command, generally should be 0 for this function
  * afi  -> The parsed afi if it was included in the show command, returned here
  * safi -> The parsed safi if it was included in the show command, returned here
- * vrf  -> The parsed vrf id if it was included in the show command, returned here
+ * bgp  -> Pointer to the bgp data structure we need to fill in.
  *
  * The function returns the correct location in the parse tree for the
  * last token found.
@@ -247,14 +247,14 @@ argv_find_and_parse_safi (struct cmd_token **argv, int argc, int *index, safi_t
  * it found the last token.
  */
 int
-bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
-                                     afi_t *afi, safi_t *safi, vrf_id_t *vrf)
+bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
+                                     afi_t *afi, safi_t *safi, struct bgp **bgp)
 {
   char *vrf_name = NULL;
 
   assert (afi);
   assert (safi);
-  assert (vrf && *vrf != VRF_UNKNOWN);
+  assert (bgp);
 
   if (argv_find (argv, argc, "ip", idx))
       *afi = AFI_IP;
@@ -263,26 +263,34 @@ bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, i
     {
       vrf_name = argv[*idx + 1]->arg;
       *idx += 2;
-    }
-
-  if (argv_find_and_parse_afi (argv, argc, idx, afi))
-    argv_find_and_parse_safi (argv, argc, idx, safi);
 
-  if (vrf_name)
-    {
-      if (strmatch(vrf_name, "all"))
-       *vrf = VRF_ALL;
+      if (strmatch (vrf_name, "all"))
+        *bgp = NULL;
       else
-       *vrf = vrf_name_to_id (vrf_name);
+        {
+          *bgp = bgp_lookup_by_name (vrf_name);
+          if (!*bgp)
+            {
+              vty_out (vty, "View/Vrf specified is unknown: %s%s", vrf_name, VTY_NEWLINE);
+              *idx = 0;
+              return 0;
+            }
+        }
     }
-
-  if (*vrf == VRF_UNKNOWN)
+  else
     {
-      vty_out (vty, "View/Vrf specified is unknown: %s", vrf_name);
-      *idx = 0;
-      return 0;
+      *bgp = bgp_get_default ();
+      if (!*bgp)
+        {
+          vty_out (vty, "Unable to find default BGP instance%s", VTY_NEWLINE);
+          *idx = 0;
+          return 0;
+        }
     }
 
+  if (argv_find_and_parse_afi (argv, argc, idx, afi))
+    argv_find_and_parse_safi (argv, argc, idx, safi);
+
   *idx += 1;
   return *idx;
 }
index 13e67d112ee1beb73d1c47d5b7de05be9260029e..33d24d530e5db86c8b4438b6a2ff012f9a180efc 100644 (file)
@@ -64,6 +64,6 @@ extern int
 argv_find_and_parse_safi(struct cmd_token **argv, int argc, int *index, safi_t *safi);
 
 extern int
-bgp_vty_find_and_parse_afi_safi_vrf (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
-                                     afi_t *afi, safi_t *safi, vrf_id_t *vrf);
+bgp_vty_find_and_parse_afi_safi_bgp (struct vty *vty, struct cmd_token **argv, int argc, int *idx,
+                                     afi_t *afi, safi_t *safi, struct bgp **bgp);
 #endif /* _QUAGGA_BGP_VTY_H */