From 2518efd15b75687d4791a5eb4b0d7febc36cffbc Mon Sep 17 00:00:00 2001 From: Paul Jakma Date: Sun, 27 Aug 2006 06:49:29 +0000 Subject: [ospfd] Bug #134, ospfd should be more robust to backward time change 2006-08-25 Paul Jakma * (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 | 12 ++++++++++++ ospfd/ospf_dump.c | 2 +- ospfd/ospf_flood.c | 2 +- ospfd/ospf_lsa.c | 18 +++++++----------- ospfd/ospf_nsm.c | 6 +++--- ospfd/ospf_packet.c | 12 +++++++----- ospfd/ospf_route.c | 2 +- ospfd/ospf_spf.c | 4 ++-- ospfd/ospf_vty.c | 8 +++++--- ospfd/ospfd.c | 8 ++++---- 10 files changed, 43 insertions(+), 31 deletions(-) diff --git a/ospfd/ChangeLog b/ospfd/ChangeLog index 05f96ace..1d7a4a1e 100644 --- a/ospfd/ChangeLog +++ b/ospfd/ChangeLog @@ -1,3 +1,15 @@ +2006-08-25 Paul Jakma + + * (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 * ospf_lsdb.c: (ospf_lsdb_delete_entry) new function, consolidate diff --git a/ospfd/ospf_dump.c b/ospfd/ospf_dump.c index b8dc7951..2fcbfe64 100644 --- a/ospfd/ospf_dump.c +++ b/ospfd/ospf_dump.c @@ -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); } diff --git a/ospfd/ospf_flood.c b/ospfd/ospf_flood.c index 91cbbf3d..0f485fe3 100644 --- a/ospfd/ospf_flood.c +++ b/ospfd/ospf_flood.c @@ -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) diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index b99b931c..05eed35e 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -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); diff --git a/ospfd/ospf_nsm.c b/ospfd/ospf_nsm.c index e3517cdd..69bd48ce 100644 --- a/ospfd/ospf_nsm.c +++ b/ospfd/ospf_nsm.c @@ -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++; diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index 6449e63a..d7a35645 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -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. */ diff --git a/ospfd/ospf_route.c b/ospfd/ospf_route.c index e0f2565f..3a1fa999 100644 --- a/ospfd/ospf_route.c +++ b/ospfd/ospf_route.c @@ -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; diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index 7228d2d4..a133d5f8 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -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; diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 912f1d09..04e1df46 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -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 : "??"), diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 95615e4a..a1f0f011 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -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); } -- cgit v1.2.1