+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
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);
}
"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)
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)
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;
}
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;
new->data->ls_seqnum = lsa_seqnum_increment (lsa);
- /* Record timestamp. */
- gettimeofday (&new->tv_orig, NULL);
-
/* Re-calculate checksum. */
ospf_lsa_checksum (new->data);
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);
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))
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);
/* 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];
}
if (state == NSM_ExStart)
{
if (nbr->dd_seqnum == 0)
- nbr->dd_seqnum = time (NULL);
+ nbr->dd_seqnum = quagga_time (NULL);
else
nbr->dd_seqnum++;
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;
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);
}
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)
{
{
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)
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. */
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;
/* 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",
}
/* 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;
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);
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",
}
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 : "??"),
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)
{
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)
{
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)
{
om = &ospf_master;
om->ospf = list_new ();
om->master = thread_master_create ();
- om->start_time = time (NULL);
+ om->start_time = quagga_time (NULL);
}