2005-11-20 Paul Jakma <paul.jakma@sun.com>

        * ospf_abr.c: (ospf_abr_announce_network_to_area) check
          returned LSA of ospf_summary_lsa_refresh and print warning if
          it failed.
          (ospf_abr_announce_network_to_area) similar
          (ospf_abr_announce_rtr_to_area) similar
        * ospf_lsa.c: (ospf_router_lsa_new) check LSA returned is valid.
          (ospf_router_lsa_originate) similar
          (ospf_router_lsa_refresh, ospf_network_lsa_new) similar
          (ospf_summary_lsa_new) Check ID is valid.
          (ospf_summary_lsa_originate) ditto, and check returned LSA from
           previous function is !NULL.
          (ospf_summary_lsa_refresh) check ospf_summary_lsa_new return
           is !NULL.
          (ospf_summary_asbr_lsa_new) ID valid check.
          (ospf_summary_asbr_lsa_originate) similar.
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 31b9a4f..ff018fd 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -830,7 +830,12 @@
   lsah->length = htons (length);
 
   /* Now, create OSPF LSA instance. */
-  new = ospf_lsa_new ();
+  if ( (new = ospf_lsa_new ()) == NULL)
+    {
+      zlog_err ("%s: Unable to create new lsa", __func__);
+      return NULL;
+    }
+  
   new->area = area;
   SET_FLAG (new->flags, OSPF_LSA_SELF);
 
@@ -849,7 +854,11 @@
   struct ospf_lsa *new;
   
   /* Create new router-LSA instance. */
-  new = ospf_router_lsa_new (area);
+  if ( (new = ospf_router_lsa_new (area)) == NULL)
+    {
+      zlog_err ("%s: ospf_router_lsa_new returned NULL", __func__);
+      return NULL;
+    }
 
   /* Sanity check. */
   if (new->data->adv_router.s_addr == 0)
@@ -893,7 +902,12 @@
   ospf_ls_retransmit_delete_nbr_area (area, lsa);
 
   /* Create new router-LSA instance. */
-  new = ospf_router_lsa_new (area);
+  if ( (new = ospf_router_lsa_new (area)) == NULL)
+    {
+      zlog_err ("%s: ospf_router_lsa_new returned NULL", __func__);
+      return NULL;
+    }
+  
   new->data->ls_seqnum = lsa_seqnum_increment (lsa);
 
   ospf_lsa_install (area->ospf, NULL, new);
@@ -1075,7 +1089,12 @@
   lsah->length = htons (length);
 
   /* Create OSPF LSA instance. */
-  new = ospf_lsa_new ();
+  if ( (new = ospf_lsa_new ()) == NULL)
+    {
+      zlog_err ("%s: ospf_lsa_new returned NULL", __func__);
+      return NULL;
+    }
+  
   new->area = oi->area;
   SET_FLAG (new->flags, OSPF_LSA_SELF);
 
@@ -1242,6 +1261,15 @@
   struct lsa_header *lsah;
   int length;
 
+  if (id.s_addr == 0xffffffff)
+    {
+      /* Maybe Link State ID not available. */
+      if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
+        zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
+                    OSPF_SUMMARY_LSA);
+      return NULL;
+    }
+
   if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
     zlog_debug ("LSA[Type3]: Create summary-LSA instance");
 
@@ -1282,8 +1310,18 @@
   
   id = ospf_lsa_unique_id (area->ospf, area->lsdb, OSPF_SUMMARY_LSA, p);
 
+  if (id.s_addr == 0xffffffff)
+    {
+      /* Maybe Link State ID not available. */
+      if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
+        zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
+                    OSPF_SUMMARY_LSA);
+      return NULL;
+    }
+  
   /* Create new summary-LSA instance. */
-  new = ospf_summary_lsa_new (area, (struct prefix *) p, metric, id);
+  if ( !(new = ospf_summary_lsa_new (area, (struct prefix *) p, metric, id)))
+    return NULL;
 
   /* Instlal LSA to LSDB. */
   new = ospf_lsa_install (area->ospf, NULL, new);
@@ -1318,7 +1356,10 @@
   p.prefixlen = ip_masklen (sl->mask);
   new = ospf_summary_lsa_new (lsa->area, &p, GET_METRIC (sl->metric),
 			      sl->header.id);
-
+  
+  if (!new)
+    return NULL;
+  
   new->data->ls_seqnum = lsa_seqnum_increment (lsa);
   
   /* Re-calculate checksum. */
@@ -1369,6 +1410,15 @@
   struct lsa_header *lsah;
   int length;
 
+  if (id.s_addr == 0xffffffff)
+    {
+      /* Maybe Link State ID not available. */
+      if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
+        zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
+                    OSPF_ASBR_SUMMARY_LSA);
+      return NULL;
+    }
+
   if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
     zlog_debug ("LSA[Type3]: Create summary-LSA instance");
 
@@ -1409,8 +1459,19 @@
   
   id = ospf_lsa_unique_id (area->ospf, area->lsdb, OSPF_ASBR_SUMMARY_LSA, p);
 
+  if (id.s_addr == 0xffffffff)
+    {
+      /* Maybe Link State ID not available. */
+      if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
+        zlog_debug ("LSA[Type%d]: Link ID not available, can't originate",
+                    OSPF_ASBR_SUMMARY_LSA);
+      return NULL;
+    }
+  
   /* Create new summary-LSA instance. */
   new = ospf_summary_asbr_lsa_new (area, (struct prefix *) p, metric, id);
+  if (!new)
+    return NULL;
 
   /* Install LSA to LSDB. */
   new = ospf_lsa_install (area->ospf, NULL, new);
@@ -1445,6 +1506,8 @@
   p.prefixlen = ip_masklen (sl->mask);
   new = ospf_summary_asbr_lsa_new (lsa->area, &p, GET_METRIC (sl->metric),
 				   sl->header.id);
+  if (!new)
+    return NULL;
   
   new->data->ls_seqnum = lsa_seqnum_increment (lsa);