summaryrefslogtreecommitdiff
path: root/usr.sbin/ospfd
diff options
context:
space:
mode:
authorEsben Norby <norby@cvs.openbsd.org>2006-01-05 15:10:58 +0000
committerEsben Norby <norby@cvs.openbsd.org>2006-01-05 15:10:58 +0000
commit291d0d6bfca94e0d57c1d7f5d787851e515ae079 (patch)
tree4174cd0505157fda7ad6d2cd0f468fb9e3ce2186 /usr.sbin/ospfd
parent12d46410b24594e86a66a75c67a567031633a8ee (diff)
Improve how ospfd copes with time changes.
ok claudio@
Diffstat (limited to 'usr.sbin/ospfd')
-rw-r--r--usr.sbin/ospfd/lsupdate.c7
-rw-r--r--usr.sbin/ospfd/rde.c6
-rw-r--r--usr.sbin/ospfd/rde_lsdb.c20
3 files changed, 24 insertions, 9 deletions
diff --git a/usr.sbin/ospfd/lsupdate.c b/usr.sbin/ospfd/lsupdate.c
index 763a527f158..9a4d3e95901 100644
--- a/usr.sbin/ospfd/lsupdate.c
+++ b/usr.sbin/ospfd/lsupdate.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: lsupdate.c,v 1.22 2005/12/29 13:53:36 claudio Exp $ */
+/* $OpenBSD: lsupdate.c,v 1.23 2006/01/05 15:10:57 norby Exp $ */
/*
* Copyright (c) 2005 Claudio Jeker <claudio@openbsd.org>
@@ -518,6 +518,7 @@ lsa_cache_add(void *data, u_int16_t len)
{
struct lsa_cache_head *head;
struct lsa_ref *ref, *old;
+ struct timespec tp;
if ((ref = calloc(1, sizeof(*ref))) == NULL)
fatal("lsa_cache_add");
@@ -532,7 +533,9 @@ lsa_cache_add(void *data, u_int16_t len)
if ((ref->data = malloc(len)) == NULL)
fatal("lsa_cache_add");
memcpy(ref->data, data, len);
- ref->stamp = time(NULL);
+
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ ref->stamp = tp.tv_sec;
ref->len = len;
ref->refcnt = 1;
diff --git a/usr.sbin/ospfd/rde.c b/usr.sbin/ospfd/rde.c
index 63ad1e9a7ff..b3cfe3d1204 100644
--- a/usr.sbin/ospfd/rde.c
+++ b/usr.sbin/ospfd/rde.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde.c,v 1.35 2005/12/29 13:58:49 claudio Exp $ */
+/* $OpenBSD: rde.c,v 1.36 2006/01/05 15:10:57 norby Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -219,6 +219,7 @@ rde_dispatch_imsg(int fd, short event, void *bula)
struct ls_req_hdr req_hdr;
struct lsa_hdr lsa_hdr, *db_hdr;
struct rde_nbr rn, *nbr;
+ struct timespec tp;
struct lsa *lsa;
struct area *area;
struct vertex *v;
@@ -243,7 +244,8 @@ rde_dispatch_imsg(int fd, short event, void *bula)
fatalx("unknown event");
}
- now = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ now = tp.tv_sec;
for (;;) {
if ((n = imsg_get(ibuf, &imsg)) == -1)
diff --git a/usr.sbin/ospfd/rde_lsdb.c b/usr.sbin/ospfd/rde_lsdb.c
index c71b5868d1f..0b9370f380a 100644
--- a/usr.sbin/ospfd/rde_lsdb.c
+++ b/usr.sbin/ospfd/rde_lsdb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rde_lsdb.c,v 1.23 2005/11/04 11:36:31 claudio Exp $ */
+/* $OpenBSD: rde_lsdb.c,v 1.24 2006/01/05 15:10:57 norby Exp $ */
/*
* Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org>
@@ -68,12 +68,14 @@ struct vertex *
vertex_get(struct lsa *lsa, struct rde_nbr *nbr)
{
struct vertex *v;
+ struct timespec tp;
if ((v = calloc(1, sizeof(struct vertex))) == NULL)
fatal(NULL);
v->nbr = nbr;
v->lsa = lsa;
- v->changed = v->stamp = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ v->changed = v->stamp = tp.tv_sec;
v->cost = LS_INFINITY;
v->ls_id = ntohl(lsa->hdr.ls_id);
v->adv_rtr = ntohl(lsa->hdr.adv_rtr);
@@ -387,11 +389,14 @@ lsa_del(struct rde_nbr *nbr, struct lsa_hdr *lsa)
void
lsa_age(struct vertex *v)
{
+ struct timespec tp;
time_t now;
int d;
u_int16_t age;
- now = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ now = tp.tv_sec;
+
d = now - v->stamp;
/* set stamp so that at least new calls work */
v->stamp = now;
@@ -553,6 +558,7 @@ void
lsa_refresh(struct vertex *v)
{
struct timeval tv;
+ struct timespec tp;
u_int32_t seqnum;
u_int16_t len;
@@ -569,7 +575,9 @@ lsa_refresh(struct vertex *v)
v->lsa->hdr.ls_chksum = 0;
v->lsa->hdr.ls_chksum = htons(iso_cksum(v->lsa, len, LS_CKSUM_OFFSET));
- v->changed = v->stamp = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ v->changed = v->stamp = tp.tv_sec;
+
timerclear(&tv);
tv.tv_sec = LS_REFRESH_TIME;
evtimer_add(&v->ev, &tv);
@@ -579,6 +587,7 @@ void
lsa_merge(struct rde_nbr *nbr, struct lsa *lsa, struct vertex *v)
{
struct timeval tv;
+ struct timespec tp;
time_t now;
u_int16_t len;
@@ -608,7 +617,8 @@ lsa_merge(struct rde_nbr *nbr, struct lsa *lsa, struct vertex *v)
start_spf_timer();
/* set correct timeout for reflooding the LSA */
- now = time(NULL);
+ clock_gettime(CLOCK_MONOTONIC, &tp);
+ now = tp.tv_sec;
timerclear(&tv);
if (v->changed + MIN_LS_INTERVAL >= now)
tv.tv_sec = MIN_LS_INTERVAL;