2003-06-19 Vladimir Ivaschenko <hazard@francoudi.com>

	* ospfd/ospf_zebra.c: [zebra 19434] fix for disappearing OSPF routes
	modify ospf_zebra_delete() to specify nexthop when deleting routes
	with zebra.
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index bdb0c0f..81bf59a 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -309,7 +309,7 @@
 
   return 0;
 }
-
+
 void
 ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or)
 {
@@ -333,7 +333,7 @@
       /* Distance value. */
       distance = ospf_distance_apply (p, or);
       if (distance)
-	SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
+        SET_FLAG (message, ZAPI_MESSAGE_DISTANCE);
 
       /* Make packet. */
       s = zclient->obuf;
@@ -358,7 +358,7 @@
 
       /* Nexthop, ifindex, distance and metric information. */
       for (node = listhead (or->path); node; nextnode (node))
-	{
+        {
 	  path = getdata (node);
 
 	  if (path->nexthop.s_addr != INADDR_ANY)
@@ -374,6 +374,14 @@
 	      else
 		stream_putl (s, 0);
 	    }
+
+          if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
+            {
+              zlog_info ("Zebra: Route add %s/%d nexthop %s",
+                     inet_ntoa (p->prefix), 
+                     p->prefixlen, 
+                     inet_ntoa (path->nexthop));
+	    }
 	}
 
       if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
@@ -391,19 +399,6 @@
       stream_putw_at (s, 0, stream_get_endp (s));
 
       writen (zclient->sock, s->data, stream_get_endp (s));
-
-#if 0
-      if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
-	{
-	  char *nexthop_str;
-
-	  nexthop_str = strdup (inet_ntoa (*nexthop));
-	  zlog_info ("Zebra: Route add %s/%d nexthop %s metric %d",
-		     inet_ntoa (p->prefix), p->prefixlen, nexthop_str,
-		     metric);
-	  free (nexthop_str);
-	}
-#endif /* 0 */
     }
 }
 
@@ -411,25 +406,45 @@
 ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or)
 {
   struct zapi_ipv4 api;
+  struct ospf_path *path;
+  struct in_addr *nexthop;
+  listnode node;
 
   if (zclient->redist[ZEBRA_ROUTE_OSPF])
     {
       api.type = ZEBRA_ROUTE_OSPF;
       api.flags = 0;
       api.message = 0;
-      zapi_ipv4_delete (zclient, p, &api);
+      api.ifindex_num = 0;
+      api.nexthop_num = 0;
+      SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP);
 
-#if 0
-      if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
+      for (node = listhead (or->path); node; nextnode (node))
 	{
-	  char *nexthop_str;
+	  path = getdata (node);
 
-	  nexthop_str = strdup (inet_ntoa (*nexthop));
-	  zlog_info ("Zebra: Route delete %s/%d nexthop %s",
-		     inet_ntoa (p->prefix), p->prefixlen, nexthop_str);
-	  free (nexthop_str);
+	  if (path->nexthop.s_addr != INADDR_ANY)
+	    {
+	      api.nexthop_num = 1;
+	      nexthop = &path->nexthop;
+	      api.nexthop = &nexthop;
+	    }
+	  else
+	    {
+	      api.ifindex_num = 1;
+	      api.ifindex = &path->oi->ifp->ifindex;
+	    }
+
+          zapi_ipv4_delete (zclient, p, &api);
+
+          if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE) && api.nexthop_num)
+	    {
+	      zlog_info ("Zebra: Route delete %s/%d nexthop %s",
+                     inet_ntoa (p->prefix), 
+                     p->prefixlen, 
+                     inet_ntoa (**api.nexthop));
+	    }
 	}
-#endif /* 0 */
     }
 }
 
@@ -466,6 +481,11 @@
       api.ifindex_num = 0;
 
       zapi_ipv4_delete (zclient, p, &api);
+
+      if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE))
+	    zlog_info ("Zebra: Route delete discard %s/%d",
+		inet_ntoa (p->prefix), p->prefixlen);
+
     }
 }