]> git.puffer.fish Git - mirror/frr.git/commitdiff
[ospfd] Bug #134, ospfd should be more robust to backward time change
authorPaul Jakma <paul.jakma@sun.com>
Sun, 27 Aug 2006 06:49:29 +0000 (06:49 +0000)
committerPaul Jakma <paul.jakma@sun.com>
Sun, 27 Aug 2006 06:49:29 +0000 (06:49 +0000)
2006-08-25 Paul Jakma <paul.jakma@sun.com>

* (general) Bug #134. Be more robust to backward time changes,
  use the newly added libzebra time functions.
  In most cases: recent_time -> recent_relative_time()
  gettimeofday -> quagga_gettime (QUAGGA_CLK_MONOTONIC, ..)
  time -> quagga_time.
  (ospf_make_md5_digest) time() call deliberately not changed.
  (ospf_external_lsa_refresh) remove useless gettimeofday, LSA
  tv_orig time was already set in ospf_lsa_new, called via
  ospf_external_lsa_new.

ospfd/ChangeLog
ospfd/ospf_dump.c
ospfd/ospf_flood.c
ospfd/ospf_lsa.c
ospfd/ospf_nsm.c
ospfd/ospf_packet.c
ospfd/ospf_route.c
ospfd/ospf_spf.c
ospfd/ospf_vty.c
ospfd/ospfd.c

index 05f96ace29f01ccd8c475231f55baba3636908b5..1d7a4a1e94ac194a2cc7d6af8ff5936efcc6003b 100644 (file)
@@ -1,3 +1,15 @@
+2006-08-25 Paul Jakma <paul.jakma@sun.com>
+
+       * (general) Bug #134. Be more robust to backward time changes,
+         use the newly added libzebra time functions.
+         In most cases: recent_time -> recent_relative_time()
+         gettimeofday -> quagga_gettime (QUAGGA_CLK_MONOTONIC, ..)
+         time -> quagga_time.
+         (ospf_make_md5_digest) time() call deliberately not changed.
+         (ospf_external_lsa_refresh) remove useless gettimeofday, LSA
+         tv_orig time was already set in ospf_lsa_new, called via
+         ospf_external_lsa_new.
+
 2006-08-04 Paul Jakma <paul.jakma@sun.com>
 
        * ospf_lsdb.c: (ospf_lsdb_delete_entry) new function, consolidate
index b8dc7951b9c027ee5c4c650298bd4510def383c2..2fcbfe6415d748b008d2cfd4a7f6cf29c38a2234 100644 (file)
@@ -300,7 +300,7 @@ ospf_timer_dump (struct thread *t, char *buf, size_t size)
   if (!t)
     return "inactive";
   
-  result = tv_sub (t->u.sands, recent_time);
+  result = tv_sub (t->u.sands, recent_relative_time());
   return ospf_timeval_dump (&result, buf, size);
 }
 
index 91cbbf3dd934f4202875ce3e97c8a419334a9a20..0f485fe30eb7f2f7d4f29d89af038d997519efa4 100644 (file)
@@ -268,7 +268,7 @@ ospf_flood (struct ospf *ospf, struct ospf_neighbor *nbr,
                       "while local one is initial instance.");
           ; /* Accept this LSA for quick LSDB resynchronization. */
         }
-      else if (tv_cmp (tv_sub (recent_time, current->tv_recv),
+      else if (tv_cmp (tv_sub (recent_relative_time (), current->tv_recv),
                       int2tv (OSPF_MIN_LS_ARRIVAL)) < 0)
         {
           if (IS_DEBUG_OSPF_EVENT)
index b99b931c13bd5e962cf8d25dbaf3b7dd7258c5d7..05eed35ebeb6c3bf98ea47c8fdce480e86035f02 100644 (file)
@@ -141,7 +141,7 @@ ospf_lsa_refresh_delay (struct ospf_lsa *lsa)
   struct timeval delta, now;
   int delay = 0;
 
-  gettimeofday (&now, NULL);
+  quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
   delta = tv_sub (now, lsa->tv_orig);
 
   if (tv_cmp (delta, int2tv (OSPF_MIN_LS_INTERVAL)) < 0)
@@ -163,10 +163,9 @@ int
 get_age (struct ospf_lsa *lsa)
 {
   int age;
-  struct timeval now;
 
-  gettimeofday (&now, NULL);
-  age = ntohs (lsa->data->ls_age) + tv_floor (tv_sub (now, lsa->tv_recv));
+  age = ntohs (lsa->data->ls_age) 
+        + tv_floor (tv_sub (recent_relative_time (), lsa->tv_recv));
 
   return age;
 }
@@ -229,7 +228,7 @@ ospf_lsa_new ()
   new->flags = 0;
   new->lock = 1;
   new->retransmit_counter = 0;
-  gettimeofday (&new->tv_recv, NULL);
+  new->tv_recv = recent_relative_time ();
   new->tv_orig = new->tv_recv;
   new->refresh_list = -1;
   
@@ -2460,9 +2459,6 @@ ospf_external_lsa_refresh (struct ospf *ospf, struct ospf_lsa *lsa,
   
   new->data->ls_seqnum = lsa_seqnum_increment (lsa);
 
-  /* Record timestamp. */
-  gettimeofday (&new->tv_orig, NULL);
-
   /* Re-calculate checksum. */
   ospf_lsa_checksum (new->data);
 
@@ -3770,7 +3766,7 @@ ospf_refresher_register_lsa (struct ospf *ospf, struct ospf_lsa *lsa)
        delay = 0;
 
       current_index = ospf->lsa_refresh_queue.index +
-       (time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY;
+       (quagga_time (NULL) - ospf->lsa_refresher_started)/OSPF_LSA_REFRESHER_GRANULARITY;
       
       index = (current_index + delay/OSPF_LSA_REFRESHER_GRANULARITY)
        % (OSPF_LSA_REFRESHER_SLOTS);
@@ -3829,7 +3825,7 @@ ospf_lsa_refresh_walker (struct thread *t)
      modulus. */
   ospf->lsa_refresh_queue.index =
    ((unsigned long)(ospf->lsa_refresh_queue.index +
-                   (time (NULL) - ospf->lsa_refresher_started) /
+                   (quagga_time (NULL) - ospf->lsa_refresher_started) /
                    OSPF_LSA_REFRESHER_GRANULARITY)) % OSPF_LSA_REFRESHER_SLOTS;
 
   if (IS_DEBUG_OSPF (lsa, LSA_REFRESH))
@@ -3867,7 +3863,7 @@ ospf_lsa_refresh_walker (struct thread *t)
 
   ospf->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
                                           ospf, ospf->lsa_refresh_interval);
-  ospf->lsa_refresher_started = time (NULL);
+  ospf->lsa_refresher_started = quagga_time (NULL);
 
   for (ALL_LIST_ELEMENTS (lsa_to_refresh, node, nnode, lsa))
     ospf_lsa_refresh (ospf, lsa);
index e3517cdd242877a2c5653a9224934cc678babc94..69bd48ceb206936a09c334a66b7a7f626064e4c6 100644 (file)
@@ -617,10 +617,10 @@ nsm_notice_state_change (struct ospf_neighbor *nbr, int next_state, int event)
 
   /* Advance in NSM */
   if (next_state > nbr->state)
-    nbr->ts_last_progress = recent_time;
+    nbr->ts_last_progress = recent_relative_time ();
   else /* regression in NSM */
     {
-      nbr->ts_last_regress = recent_time;
+      nbr->ts_last_regress = recent_relative_time ();
       nbr->last_regress_str = ospf_nsm_event_str [event];
     }
 
@@ -747,7 +747,7 @@ nsm_change_state (struct ospf_neighbor *nbr, int state)
   if (state == NSM_ExStart)
     {
       if (nbr->dd_seqnum == 0)
-       nbr->dd_seqnum = time (NULL);
+       nbr->dd_seqnum = quagga_time (NULL);
       else
        nbr->dd_seqnum++;
 
index 6449e63a79c473316d14b060803e04d91093809e..d7a3564501b8562c031ceb7ee775eebe8a13640a 100644 (file)
@@ -337,7 +337,9 @@ ospf_make_md5_digest (struct ospf_interface *oi, struct ospf_packet *op)
     return 0;
 
   /* We do this here so when we dup a packet, we don't have to
-     waste CPU rewriting other headers. */
+     waste CPU rewriting other headers.
+     
+     Note that quagga_time /deliberately/ is not used here */
   t = (time(NULL) & 0xFFFFFFFF);
   if (t > oi->crypt_seqnum)
     oi->crypt_seqnum = t;
@@ -444,7 +446,7 @@ ospf_ls_upd_timer (struct thread *thread)
                  fired.  This is a small tweak to what is in the RFC,
                  but it will cut out out a lot of retransmit traffic
                  - MAG */
-               if (tv_cmp (tv_sub (recent_time, lsa->tv_recv), 
+               if (tv_cmp (tv_sub (recent_relative_time (), lsa->tv_recv), 
                            int2tv (retransmit_interval)) >= 0)
                  listnode_add (update, rn->info);
            }
@@ -1363,7 +1365,7 @@ ospf_db_desc (struct ip *iph, struct ospf_header *ospfh,
          else
            {
              struct timeval t, now;
-             gettimeofday (&now, NULL);
+             quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
              t = tv_sub (now, nbr->last_send_ts);
              if (tv_cmp (t, int2tv (nbr->v_inactivity)) < 0)
                {
@@ -1948,7 +1950,7 @@ ospf_ls_upd (struct ip *iph, struct ospf_header *ospfh,
            {
              struct timeval now;
              
-             gettimeofday (&now, NULL);
+             quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
              
              if (tv_cmp (tv_sub (now, current->tv_orig), 
                          int2tv (OSPF_MIN_LS_ARRIVAL)) > 0)
@@ -3158,7 +3160,7 @@ ospf_db_desc_send (struct ospf_neighbor *nbr)
   if (nbr->last_send)
     ospf_packet_free (nbr->last_send);
   nbr->last_send = ospf_packet_dup (op);
-  gettimeofday (&nbr->last_send_ts, NULL);
+  quagga_gettime (QUAGGA_CLK_MONOTONIC, &nbr->last_send_ts);
 }
 
 /* Re-send Database Description. */
index e0f2565f971b004302abc8f3d65878b34dc37e3f..3a1fa9992445fc09a23035f9332abbb5cee9efc2 100644 (file)
@@ -47,7 +47,7 @@ ospf_route_new ()
 
   new = XCALLOC (MTYPE_OSPF_ROUTE, sizeof (struct ospf_route));
 
-  new->ctime = time (NULL);
+  new->ctime = quagga_time (NULL);
   new->mtime = new->ctime;
   new->paths = list_new ();
   new->paths->del = (void (*) (void *))ospf_path_free;
index 7228d2d4140998e3229c7382b01601812da0eca8..a133d5f87d5b66b5019a351489b6ea5005d7738e 100644 (file)
@@ -1136,7 +1136,7 @@ ospf_spf_calculate (struct ospf_area *area, struct route_table *new_table,
   /* Increment SPF Calculation Counter. */
   area->spf_calculation++;
 
-  gettimeofday (&area->ospf->ts_spf, NULL);
+  quagga_gettime (QUAGGA_CLK_MONOTONIC, &area->ospf->ts_spf);
 
   if (IS_DEBUG_OSPF_EVENT)
     zlog_debug ("ospf_spf_calculate: Stop. %ld vertices",
@@ -1243,7 +1243,7 @@ ospf_spf_calculate_schedule (struct ospf *ospf)
     }
   
   /* XXX Monotic timers: we only care about relative time here. */
-  result = tv_sub (recent_time, ospf->ts_spf);
+  result = tv_sub (recent_relative_time (), ospf->ts_spf);
   
   elapsed = (result.tv_sec * 1000) + (result.tv_usec / 1000);
   ht = ospf->spf_holdtime * ospf->spf_hold_multiplier;
index 912f1d09c847547a9a7e71616c2bf203bef1e212..04e1df46e13e193bb190bb160d1400c78c27d71b 100644 (file)
@@ -2691,7 +2691,7 @@ DEFUN (show_ip_ospf,
   vty_out (vty, " SPF algorithm ");
   if (ospf->ts_spf.tv_sec || ospf->ts_spf.tv_usec)
     {
-      result = tv_sub (recent_time, ospf->ts_spf);
+      result = tv_sub (recent_relative_time (), ospf->ts_spf);
       vty_out (vty, "last executed %s ago%s",
                ospf_timeval_dump (&result, timebuf, sizeof (timebuf)),
                VTY_NEWLINE);
@@ -3157,7 +3157,8 @@ show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
   vty_out (vty, " %d state changes%s", nbr->state_change, VTY_NEWLINE);
   if (nbr->ts_last_progress.tv_sec || nbr->ts_last_progress.tv_usec)
     {
-      struct timeval res = tv_sub (recent_time, nbr->ts_last_progress);
+      struct timeval res
+        = tv_sub (recent_relative_time (), nbr->ts_last_progress);
       vty_out (vty, "    Most recent state change statistics:%s",
                VTY_NEWLINE);
       vty_out (vty, "      Progressive change %s ago%s",
@@ -3166,7 +3167,8 @@ show_ip_ospf_neighbor_detail_sub (struct vty *vty, struct ospf_interface *oi,
     }
   if (nbr->ts_last_regress.tv_sec || nbr->ts_last_regress.tv_usec)
     {
-      struct timeval res = tv_sub (recent_time, nbr->ts_last_regress);
+      struct timeval res
+        = tv_sub (recent_relative_time (), nbr->ts_last_regress);
       vty_out (vty, "      Regressive change %s ago, due to %s%s",
                ospf_timeval_dump (&res, timebuf, sizeof(timebuf)),
                (nbr->last_regress_str ? nbr->last_regress_str : "??"),
index 95615e4a47b8ee70e5ec8718a4e6ea1ff41acbb8..a1f0f0111f794ebefabf07df4ac0d0a6612fd398 100644 (file)
@@ -202,7 +202,7 @@ ospf_new (void)
   new->lsa_refresh_interval = OSPF_LSA_REFRESH_INTERVAL_DEFAULT;
   new->t_lsa_refresher = thread_add_timer (master, ospf_lsa_refresh_walker,
                                           new, new->lsa_refresh_interval);
-  new->lsa_refresher_started = time (NULL);
+  new->lsa_refresher_started = quagga_time (NULL);
 
   if ((new->fd = ospf_sock_init()) < 0)
     {
@@ -1317,7 +1317,7 @@ ospf_timers_refresh_set (struct ospf *ospf, int interval)
     return 1;
 
   time_left = ospf->lsa_refresh_interval -
-    (time (NULL) - ospf->lsa_refresher_started);
+    (quagga_time (NULL) - ospf->lsa_refresher_started);
   
   if (time_left > interval)
     {
@@ -1336,7 +1336,7 @@ ospf_timers_refresh_unset (struct ospf *ospf)
   int time_left;
 
   time_left = ospf->lsa_refresh_interval -
-    (time (NULL) - ospf->lsa_refresher_started);
+    (quagga_time (NULL) - ospf->lsa_refresher_started);
 
   if (time_left > OSPF_LSA_REFRESH_INTERVAL_DEFAULT)
     {
@@ -1657,5 +1657,5 @@ ospf_master_init ()
   om = &ospf_master;
   om->ospf = list_new ();
   om->master = thread_master_create ();
-  om->start_time = time (NULL);
+  om->start_time = quagga_time (NULL);
 }