diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2007-12-23 18:56:18 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2007-12-23 18:56:18 +0000 |
commit | 2942b54c71a23e7b911959a4ab867ab8cf3fe9ff (patch) | |
tree | 46800df996e036a0ad40aa40c7352e4dd378711b /usr.sbin | |
parent | 679a73616277bf0c242a2e756ff8f8d0add821a3 (diff) |
provide timer_nextduein, which provides the number of seconds until the
next timer expires.
use that in the session engine's mainloop, which simplifies it and
removes the last bits of timer internals knowledge from anywhere outside
timer.c.
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/bgpd/session.c | 34 | ||||
-rw-r--r-- | usr.sbin/bgpd/session.h | 3 | ||||
-rw-r--r-- | usr.sbin/bgpd/timer.c | 16 |
3 files changed, 28 insertions, 25 deletions
diff --git a/usr.sbin/bgpd/session.c b/usr.sbin/bgpd/session.c index f2d10f2046c..484640c07cd 100644 --- a/usr.sbin/bgpd/session.c +++ b/usr.sbin/bgpd/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.278 2007/12/23 16:42:45 henning Exp $ */ +/* $OpenBSD: session.c,v 1.279 2007/12/23 18:56:17 henning Exp $ */ /* * Copyright (c) 2003, 2004, 2005 Henning Brauer <henning@openbsd.org> @@ -183,7 +183,6 @@ session_main(struct bgpd_config *config, struct peer *cpeers, int nfds, timeout; unsigned int i, j, idx_peers, idx_listeners, idx_mrts; pid_t pid; - time_t nextaction; u_int pfd_elms = 0, peer_l_elms = 0, mrt_l_elms = 0; u_int listener_cnt, ctl_cnt, mrt_cnt; u_int new_cnt; @@ -396,18 +395,18 @@ session_main(struct bgpd_config *config, struct peer *cpeers, pfd[PFD_SOCK_RCTL].fd = rcsock; pfd[PFD_SOCK_RCTL].events = POLLIN; - nextaction = time(NULL) + 240; /* loop every 240s at least */ i = PFD_LISTENERS_START; - TAILQ_FOREACH(la, conf->listen_addrs, entry) { pfd[i].fd = la->fd; pfd[i].events = POLLIN; i++; } - idx_listeners = i; + timeout = 240; /* loop every 240s at least */ for (p = peers; p != NULL; p = p->next) { + time_t nextaction; + /* check timers */ if (timer_due(p, Timer_Hold)) bgp_fsm(p, EVNT_TIMER_HOLDTIME); @@ -430,29 +429,19 @@ session_main(struct bgpd_config *config, struct peer *cpeers, p->IdleHoldTime); } - /* XXX set nextaction to the first expiring timer */ - if (p->ConnectRetryTimer && - p->ConnectRetryTimer < nextaction) - nextaction = p->ConnectRetryTimer; - if (p->HoldTimer && p->HoldTimer < nextaction) - nextaction = p->HoldTimer; - if (p->KeepaliveTimer && p->KeepaliveTimer < nextaction) - nextaction = p->KeepaliveTimer; - if (p->IdleHoldTimer && p->IdleHoldTimer < nextaction) - nextaction = p->IdleHoldTimer; - if (p->IdleHoldResetTimer && - p->IdleHoldResetTimer < nextaction) - nextaction = p->IdleHoldResetTimer; + if ((nextaction = timer_nextduein(p)) != -1 && + nextaction < timeout) + timeout = nextaction; /* XXX carp demotion */ if (p->demoted && p->state == STATE_ESTABLISHED) { if (time(NULL) - p->stats.last_updown >= INTERVAL_HOLD_DEMOTED) session_demote(p, -1); - if (p->stats.last_updown + - INTERVAL_HOLD_DEMOTED < nextaction) - nextaction = p->stats.last_updown + - INTERVAL_HOLD_DEMOTED; + if (p->stats.last_updown + INTERVAL_HOLD_DEMOTED + - time(NULL) < timeout) + timeout = p->stats.last_updown + + INTERVAL_HOLD_DEMOTED - time(NULL); } /* are we waiting for a write? */ @@ -489,7 +478,6 @@ session_main(struct bgpd_config *config, struct peer *cpeers, i++; } - timeout = nextaction - time(NULL); if (timeout < 0) timeout = 0; if ((nfds = poll(pfd, i, timeout * 1000)) == -1) diff --git a/usr.sbin/bgpd/session.h b/usr.sbin/bgpd/session.h index a1798514267..ca143f3706e 100644 --- a/usr.sbin/bgpd/session.h +++ b/usr.sbin/bgpd/session.h @@ -1,4 +1,4 @@ -/* $OpenBSD: session.h,v 1.94 2007/12/23 18:26:13 henning Exp $ */ +/* $OpenBSD: session.h,v 1.95 2007/12/23 18:56:17 henning Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -278,6 +278,7 @@ int carp_demote_set(char *, int); /* timer.c */ time_t *timer_get(struct peer *, enum Timer); int timer_due(struct peer *, enum Timer); +time_t timer_nextduein(struct peer *); 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 d6b97bd0896..a924a5d4339 100644 --- a/usr.sbin/bgpd/timer.c +++ b/usr.sbin/bgpd/timer.c @@ -1,4 +1,4 @@ -/* $OpenBSD: timer.c,v 1.3 2007/12/23 18:26:13 henning Exp $ */ +/* $OpenBSD: timer.c,v 1.4 2007/12/23 18:56:17 henning Exp $ */ /* * Copyright (c) 2003-2007 Henning Brauer <henning@openbsd.org> @@ -55,6 +55,20 @@ timer_due(struct peer *p, enum Timer timer) return (0); } +time_t +timer_nextduein(struct peer *p) +{ + u_int i; + time_t d, r = -1; + + for (i = 1; i < Timer_Max; i++) + if (timer_running(p, i, &d)) + if (r == -1 || d < r) + r = d; + + return (r); +} + int timer_running(struct peer *p, enum Timer timer, time_t *left) { |