ospfd: Some small tweaks to the SPF execution reason patch

* ospf_spf.h: use an enum for the reason, and have it as a new argument to
  ospf_spf_calculate_schedule, no need for additional call, and let compiler
  do the checking.
* ospf_spf.c: format changes - Quagga coding style places function names
  at the start of a new line, for easy grepping for definition.
  (ospf_spf_calculate_timer) Change the log format of SPF execution time to
  avoid ginormous line, and make logging conditional, as is the norm.
diff --git a/ospfd/ospf_abr.c b/ospfd/ospf_abr.c
index ca1af2c..e172e53 100644
--- a/ospfd/ospf_abr.c
+++ b/ospfd/ospf_abr.c
@@ -556,8 +556,7 @@
 
   if (new_flags != ospf->flags)
     {
-      ospf_flag_spf_reason (SPF_FLAG_ABR_STATUS_CHANGE);
-      ospf_spf_calculate_schedule (ospf);
+      ospf_spf_calculate_schedule (ospf, SPF_FLAG_ABR_STATUS_CHANGE);
       if (IS_DEBUG_OSPF_EVENT)
 	zlog_debug ("ospf_check_abr_status(): new router flags: %x",new_flags);
       ospf->flags = new_flags;
diff --git a/ospfd/ospf_asbr.c b/ospfd/ospf_asbr.c
index dbf7f11..8bef175 100644
--- a/ospfd/ospf_asbr.c
+++ b/ospfd/ospf_asbr.c
@@ -264,8 +264,7 @@
     }
 
   /* Transition from/to status ASBR, schedule timer. */
-  ospf_flag_spf_reason (SPF_FLAG_ASBR_STATUS_CHANGE);
-  ospf_spf_calculate_schedule (ospf);
+  ospf_spf_calculate_schedule (ospf, SPF_FLAG_ASBR_STATUS_CHANGE);
   ospf_router_lsa_update (ospf);
 }
 
diff --git a/ospfd/ospf_ase.c b/ospfd/ospf_ase.c
index 9038b3a..8aedc80 100644
--- a/ospfd/ospf_ase.c
+++ b/ospfd/ospf_ase.c
@@ -679,7 +679,7 @@
 
       quagga_gettime(QUAGGA_CLK_MONOTONIC, &stop_time);
 
-      zlog_info ("SPF Processing Time(usecs): External Routes: %d\n",
+      zlog_info ("SPF Processing Time(usecs): External Routes: %ld\n",
 		 (stop_time.tv_sec - start_time.tv_sec)*1000000L+
 		 (stop_time.tv_usec - start_time.tv_usec));
     }
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 31cbaae..94c31c9 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -2409,10 +2409,7 @@
       ospf_refresher_register_lsa (ospf, new);
     }
   if (rt_recalc)
-    {
-      ospf_flag_spf_reason (SPF_FLAG_ROUTER_LSA_INSTALL);
-      ospf_spf_calculate_schedule (ospf);
-    }
+    ospf_spf_calculate_schedule (ospf, SPF_FLAG_ROUTER_LSA_INSTALL);
   return new;
 }
 
@@ -2446,10 +2443,7 @@
       ospf_refresher_register_lsa (ospf, new);
     }
   if (rt_recalc)
-    {
-      ospf_flag_spf_reason (SPF_FLAG_NETWORK_LSA_INSTALL);
-      ospf_spf_calculate_schedule (ospf);
-    }
+    ospf_spf_calculate_schedule (ospf, SPF_FLAG_NETWORK_LSA_INSTALL);
 
   return new;
 }
@@ -2472,8 +2466,7 @@
       /* This doesn't exist yet... */
       ospf_summary_incremental_update(new); */
 #else /* #if 0 */
-      ospf_flag_spf_reason (SPF_FLAG_SUMMARY_LSA_INSTALL);
-      ospf_spf_calculate_schedule (ospf);
+      ospf_spf_calculate_schedule (ospf, SPF_FLAG_SUMMARY_LSA_INSTALL);
 #endif /* #if 0 */
  
     }
@@ -2504,8 +2497,7 @@
 	 - RFC 2328 Section 16.5 implies it should be */
       /* ospf_ase_calculate_schedule(); */
 #else  /* #if 0 */
-      ospf_flag_spf_reason (SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL);
-      ospf_spf_calculate_schedule (ospf);
+      ospf_spf_calculate_schedule (ospf, SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL);
 #endif /* #if 0 */
     }
 
@@ -3027,8 +3019,7 @@
 	    ospf_ase_incremental_update (ospf, lsa);
             break;
           default:
-	    ospf_flag_spf_reason (SPF_FLAG_MAXAGE);
-	    ospf_spf_calculate_schedule (ospf);
+	    ospf_spf_calculate_schedule (ospf, SPF_FLAG_MAXAGE);
             break;
           }
 	ospf_lsa_maxage (ospf, lsa);
diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c
index a7155bc..1fe8ab4 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -50,42 +50,41 @@
 
 static unsigned int spf_reason_flags = 0;
 
-static void ospf_clear_spf_reason_flags ()
+static void
+ospf_clear_spf_reason_flags ()
 {
   spf_reason_flags = 0;
 }
 
-void ospf_flag_spf_reason (unsigned int reason)
+static void 
+ospf_spf_set_reason (ospf_spf_reason_t reason)
 {
-  if (reason <= SPF_FLAG_MAX_VALUE)
-    spf_reason_flags |= reason;
-  else
-    spf_reason_flags |= SPF_FLAG_MISC;
+  spf_reason_flags |= 1 << reason;
 }
 
 static void
 ospf_get_spf_reason_str (char *buf)
 {
-  if (buf)
+  if (!buf)
+   return;
+ 
+  buf[0] = '\0';
+  if (spf_reason_flags)
     {
-      buf[0] = '\0';
-      if (spf_reason_flags)
-	{
-	  if (spf_reason_flags & SPF_FLAG_ROUTER_LSA_INSTALL)
-	    strcat (buf, "R, ");
-	  if (spf_reason_flags & SPF_FLAG_NETWORK_LSA_INSTALL)
-	    strcat (buf, "N, ");
-	  if (spf_reason_flags & SPF_FLAG_SUMMARY_LSA_INSTALL)
-	    strcat (buf, "S, ");
-	  if (spf_reason_flags & SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL)
-	    strcat (buf, "AS, ");
-	  if (spf_reason_flags & SPF_FLAG_ABR_STATUS_CHANGE)
-	    strcat (buf, "ABR, ");
-	  if (spf_reason_flags & SPF_FLAG_ASBR_STATUS_CHANGE)
-	    strcat (buf, "ASBR, ");
-	  if (spf_reason_flags & SPF_FLAG_MAXAGE)
-	    strcat (buf, "M, ");
-      }
+      if (spf_reason_flags & SPF_FLAG_ROUTER_LSA_INSTALL)
+        strcat (buf, "R, ");
+      if (spf_reason_flags & SPF_FLAG_NETWORK_LSA_INSTALL)
+        strcat (buf, "N, ");
+      if (spf_reason_flags & SPF_FLAG_SUMMARY_LSA_INSTALL)
+        strcat (buf, "S, ");
+      if (spf_reason_flags & SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL)
+        strcat (buf, "AS, ");
+      if (spf_reason_flags & SPF_FLAG_ABR_STATUS_CHANGE)
+        strcat (buf, "ABR, ");
+      if (spf_reason_flags & SPF_FLAG_ASBR_STATUS_CHANGE)
+        strcat (buf, "ASBR, ");
+      if (spf_reason_flags & SPF_FLAG_MAXAGE)
+        strcat (buf, "M, ");
       buf[strlen(buf)-2] = '\0'; /* skip the last ", " */
     }
 }
@@ -1313,7 +1312,7 @@
   unsigned long ia_time, prune_time, rt_time;
   unsigned long abr_time, total_spf_time, spf_time;
   char rbuf[32];		/* reason_buf */
-
+  
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("SPF: Timer (SPF calculation expire)");
 
@@ -1405,12 +1404,18 @@
 
   ospf_get_spf_reason_str (rbuf);
 
-  if (IS_OSPF_ABR (ospf))
-    zlog_info ("SPF Processing Time(usecs): # Areas: %d, SPF Time: %ld, InterArea: %ld, Prune: %ld, RouteInstall: %ld, ABR: %ld, Total: %ld, Reason: %s\n",
-	       areas_processed, spf_time, ia_time, prune_time, rt_time, abr_time, total_spf_time, rbuf);
-  else
-    zlog_info ("SPF Processing Time(usecs): SPF Time: %ld, InterArea: %ld, Prune: %ld, RouteInstall: %ld, Total: %ld, Reason: %s\n",
-	       spf_time, ia_time, prune_time, rt_time, total_spf_time, rbuf);
+  if (IS_DEBUG_OSPF_EVENT)
+    {
+      zlog_info ("SPF Processing Time(usecs): %ld", total_spf_time);
+      zlog_info ("\t    SPF Time: %ld", spf_time);
+      zlog_info ("\t   InterArea: %ld", ia_time);
+      zlog_info ("\t       Prune: %ld", prune_time);
+      zlog_info ("\tRouteInstall: %ld", rt_time);
+      if (IS_OSPF_ABR (ospf))
+        zlog_info ("\t         ABR: %ld (%d areas)",
+                   abr_time, areas_processed);
+      zlog_info ("Reason(s) for SPF: %s", rbuf);
+    }
 
   ospf_clear_spf_reason_flags ();
 
@@ -1420,7 +1425,7 @@
 /* Add schedule for SPF calculation.  To avoid frequenst SPF calc, we
    set timer for SPF calc. */
 void
-ospf_spf_calculate_schedule (struct ospf *ospf)
+ospf_spf_calculate_schedule (struct ospf *ospf, ospf_spf_reason_t reason)
 {
   unsigned long delay, elapsed, ht;
   struct timeval result;
@@ -1432,6 +1437,8 @@
   if (ospf == NULL)
     return;
   
+  ospf_spf_set_reason (reason);
+  
   /* SPF calculation timer is already scheduled. */
   if (ospf->t_spf_calc)
     {
diff --git a/ospfd/ospf_spf.h b/ospfd/ospf_spf.h
index c9c539a..e33b3e5 100644
--- a/ospfd/ospf_spf.h
+++ b/ospfd/ospf_spf.h
@@ -59,22 +59,20 @@
   int backlink;			/* index back to parent for router-lsa's */
 };
 
-extern void ospf_spf_calculate_schedule (struct ospf *);
+/* What triggered the SPF ? */
+typedef enum {
+  SPF_FLAG_ROUTER_LSA_INSTALL = 1,
+  SPF_FLAG_NETWORK_LSA_INSTALL,
+  SPF_FLAG_SUMMARY_LSA_INSTALL,
+  SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL,
+  SPF_FLAG_MAXAGE,
+  SPF_FLAG_ABR_STATUS_CHANGE,
+  SPF_FLAG_ASBR_STATUS_CHANGE,
+  SPF_FLAG_CONFIG_CHANGE,
+} ospf_spf_reason_t;
+
+extern void ospf_spf_calculate_schedule (struct ospf *, ospf_spf_reason_t);
 extern void ospf_rtrs_free (struct route_table *);
 
 /* void ospf_spf_calculate_timer_add (); */
-
-/* What triggered the SPF ? Can have at most 32 reasons with this */
-#define SPF_FLAG_ROUTER_LSA_INSTALL 0x1
-#define SPF_FLAG_NETWORK_LSA_INSTALL 0x2
-#define SPF_FLAG_SUMMARY_LSA_INSTALL 0x4
-#define SPF_FLAG_ASBR_SUMMARY_LSA_INSTALL 0x8
-#define SPF_FLAG_MAXAGE 0x10
-#define SPF_FLAG_ABR_STATUS_CHANGE 0x20
-#define SPF_FLAG_ASBR_STATUS_CHANGE 0x40
-#define SPF_FLAG_MAX_VALUE 0x40	/* Update this when adding flags */
-#define SPF_FLAG_MISC 0x1000000	/* Keep this last */
-
-extern void ospf_flag_spf_reason (unsigned int reason);
-
 #endif /* _QUAGGA_OSPF_SPF_H */
diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c
index 5674da0..72493a2 100644
--- a/ospfd/ospf_vty.c
+++ b/ospfd/ospf_vty.c
@@ -771,7 +771,7 @@
 	{
 	  vl_data->vl_oi = ospf_vl_new (ospf, vl_data);
 	  ospf_vl_add (ospf, vl_data);
-	  ospf_spf_calculate_schedule (ospf);
+	  ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
 	}
     }
   return vl_data;
@@ -2172,7 +2172,7 @@
   if (!CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
     {
       SET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
-      ospf_spf_calculate_schedule (ospf);
+      ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
     }
   return CMD_SUCCESS;
 }
@@ -2189,7 +2189,7 @@
   if (CHECK_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE))
     {
       UNSET_FLAG (ospf->config, OSPF_RFC1583_COMPATIBLE);
-      ospf_spf_calculate_schedule (ospf);
+      ospf_spf_calculate_schedule (ospf, SPF_FLAG_CONFIG_CHANGE);
     }
   return CMD_SUCCESS;
 }