summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorClaudio Jeker <claudio@cvs.openbsd.org>2019-05-24 11:37:53 +0000
committerClaudio Jeker <claudio@cvs.openbsd.org>2019-05-24 11:37:53 +0000
commit49f74d777204976049b15383919b2866e9dfd47f (patch)
tree12cbef186d83509a2f0955ceb14a68e83dcedcaa /usr.sbin
parent277cc0f0a77a09a9d024509d5f1735dff310b34d (diff)
Change timer_nextisdue() and timer_nextduein() to take the current time
as an argument. This way getmonotime() can be called once at the start of looping over all peers instead of twice during the loop. Makes a big difference with many peers. OK florian@ sthen@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/bgpd/session.c8
-rw-r--r--usr.sbin/bgpd/session.h6
-rw-r--r--usr.sbin/bgpd/timer.c10
3 files changed, 13 insertions, 11 deletions
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c
index a080c273e7d..921b0b3a84a 100644
--- a/usr.sbin/bgpd/session.c
+++ b/usr.sbin/bgpd/session.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.c,v 1.380 2019/05/08 12:41:55 claudio Exp $ */
+/* $OpenBSD: session.c,v 1.381 2019/05/24 11:37:52 claudio Exp $ */
/*
* Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org>
@@ -191,6 +191,7 @@ session_main(int debug, int verbose)
struct ctl_conn *ctl_conn;
struct listen_addr *la;
void *newp;
+ time_t now;
short events;
log_init(debug, LOG_DAEMON);
@@ -358,12 +359,13 @@ session_main(int debug, int verbose)
idx_listeners = i;
timeout = 240; /* loop every 240s at least */
+ now = getmonotime();
TAILQ_FOREACH(p, &conf->peers, entry) {
time_t nextaction;
struct peer_timer *pt;
/* check timers */
- if ((pt = timer_nextisdue(p)) != NULL) {
+ if ((pt = timer_nextisdue(p, now)) != NULL) {
switch (pt->type) {
case Timer_Hold:
bgp_fsm(p, EVNT_TIMER_HOLDTIME);
@@ -405,7 +407,7 @@ session_main(int debug, int verbose)
fatalx("King Bula lost in time");
}
}
- if ((nextaction = timer_nextduein(p)) != -1 &&
+ if ((nextaction = timer_nextduein(p, now)) != -1 &&
nextaction < timeout)
timeout = nextaction;
diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h
index 0320545d570..c9448e132f0 100644
--- a/usr.sbin/bgpd/session.h
+++ b/usr.sbin/bgpd/session.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: session.h,v 1.137 2019/05/08 12:41:55 claudio Exp $ */
+/* $OpenBSD: session.h,v 1.138 2019/05/24 11:37:52 claudio Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -308,8 +308,8 @@ void session_stop(struct peer *, u_int8_t);
/* timer.c */
time_t getmonotime(void);
struct peer_timer *timer_get(struct peer *, enum Timer);
-struct peer_timer *timer_nextisdue(struct peer *);
-time_t timer_nextduein(struct peer *);
+struct peer_timer *timer_nextisdue(struct peer *, time_t);
+time_t timer_nextduein(struct peer *, time_t);
int timer_running(struct peer *, enum Timer, time_t *);
void timer_set(struct peer *, enum Timer, u_int);
void timer_stop(struct peer *, enum Timer);
diff --git a/usr.sbin/bgpd/timer.c b/usr.sbin/bgpd/timer.c
index b1bb5eec279..36278fb0000 100644
--- a/usr.sbin/bgpd/timer.c
+++ b/usr.sbin/bgpd/timer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: timer.c,v 1.17 2017/01/24 04:22:42 benno Exp $ */
+/* $OpenBSD: timer.c,v 1.18 2019/05/24 11:37:52 claudio Exp $ */
/*
* Copyright (c) 2003-2007 Henning Brauer <henning@openbsd.org>
@@ -49,23 +49,23 @@ timer_get(struct peer *p, enum Timer timer)
}
struct peer_timer *
-timer_nextisdue(struct peer *p)
+timer_nextisdue(struct peer *p, time_t now)
{
struct peer_timer *pt;
pt = TAILQ_FIRST(&p->timers);
- if (pt != NULL && pt->val > 0 && pt->val <= getmonotime())
+ if (pt != NULL && pt->val > 0 && pt->val <= now)
return (pt);
return (NULL);
}
time_t
-timer_nextduein(struct peer *p)
+timer_nextduein(struct peer *p, time_t now)
{
struct peer_timer *pt;
if ((pt = TAILQ_FIRST(&p->timers)) != NULL && pt->val > 0)
- return (MAXIMUM(pt->val - getmonotime(), 0));
+ return (MAXIMUM(pt->val - now, 0));
return (-1);
}