]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: fix errors in aggregate address command
authorRobert Bays <rbays@vyatta.com>
Thu, 5 Aug 2010 17:26:28 +0000 (10:26 -0700)
committerPaul Jakma <paul@quagga.net>
Mon, 21 Mar 2011 13:15:32 +0000 (13:15 +0000)
* bgpd: (bgp_aggregate_{set,unset,delete}) This fixes locking and other
  issues with aggregate set/unset command

bgpd/bgp_route.c

index ed98ac0afb89dc54e3ab77881d10b17278f9f4f0..85526f5f9cc90581ee830c625e9abeed66923ab9 100644 (file)
@@ -4985,9 +4985,8 @@ bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
 #define AGGREGATE_AS_SET       1
 
 static int
-bgp_aggregate_set (struct vty *vty, const char *prefix_str, 
-                   afi_t afi, safi_t safi,
-                  u_char summary_only, u_char as_set)
+bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
+                     afi_t afi, safi_t safi)
 {
   int ret;
   struct prefix p;
@@ -5008,34 +5007,33 @@ bgp_aggregate_set (struct vty *vty, const char *prefix_str,
   bgp = vty->index;
 
   /* Old configuration check. */
-  rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
-
-  if (rn->info)
+  rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
+  if (! rn)
     {
-      vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
-      bgp_unlock_node (rn);
+      vty_out (vty, "%% There is no aggregate-address configuration.%s",
+               VTY_NEWLINE);
       return CMD_WARNING;
     }
 
-  /* Make aggregate address structure. */
-  aggregate = bgp_aggregate_new ();
-  aggregate->summary_only = summary_only;
-  aggregate->as_set = as_set;
-  aggregate->safi = safi;
-  rn->info = aggregate;
+  aggregate = rn->info;
+  if (aggregate->safi & SAFI_UNICAST)
+    bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
+  if (aggregate->safi & SAFI_MULTICAST)
+    bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
 
-  /* Aggregate address insert into BGP routing table. */
-  if (safi & SAFI_UNICAST)
-    bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
-  if (safi & SAFI_MULTICAST)
-    bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
+  /* Unlock aggregate address configuration. */
+  rn->info = NULL;
+  bgp_aggregate_free (aggregate);
+  bgp_unlock_node (rn);
+  bgp_unlock_node (rn);
 
   return CMD_SUCCESS;
 }
 
 static int
-bgp_aggregate_unset (struct vty *vty, const char *prefix_str, 
-                     afi_t afi, safi_t safi)
+bgp_aggregate_set (struct vty *vty, const char *prefix_str,
+                   afi_t afi, safi_t safi,
+                  u_char summary_only, u_char as_set)
 {
   int ret;
   struct prefix p;
@@ -5056,25 +5054,32 @@ bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
   bgp = vty->index;
 
   /* Old configuration check. */
-  rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
-  if (! rn)
+  rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
+
+  if (rn->info)
     {
-      vty_out (vty, "%% There is no aggregate-address configuration.%s",
-              VTY_NEWLINE);
-      return CMD_WARNING;
+      vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
+      /* remove  old entry */
+      ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
+      if (ret)
+        {
+          vty_out (vty, "Error deleteing aggregate%s", VTY_NEWLINE);
+         return CMD_WARNING;
+        }
     }
 
-  aggregate = rn->info;
-  if (aggregate->safi & SAFI_UNICAST)
-    bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
-  if (aggregate->safi & SAFI_MULTICAST)
-    bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
+  /* Make aggregate address structure. */
+  aggregate = bgp_aggregate_new ();
+  aggregate->summary_only = summary_only;
+  aggregate->as_set = as_set;
+  aggregate->safi = safi;
+  rn->info = aggregate;
 
-  /* Unlock aggregate address configuration. */
-  rn->info = NULL;
-  bgp_aggregate_free (aggregate);
-  bgp_unlock_node (rn);
-  bgp_unlock_node (rn);
+  /* Aggregate address insert into BGP routing table. */
+  if (safi & SAFI_UNICAST)
+    bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
+  if (safi & SAFI_MULTICAST)
+    bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
 
   return CMD_SUCCESS;
 }