rework bgpd timeout handling a bit

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

rework bgpd timeout handling a bit

Claudio Jeker
mrt_timeout should just return -1 when there is no timeout set.
The poll loop in bgpd.c already limits the maximum wait time.
While there switch to using time_t for the calculation.

OK?
--
:wq Claudio

? obj
Index: bgpd.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.c,v
retrieving revision 1.210
diff -u -p -r1.210 bgpd.c
--- bgpd.c 14 Feb 2019 10:38:04 -0000 1.210
+++ bgpd.c 14 Feb 2019 10:44:14 -0000
@@ -102,13 +102,14 @@ main(int argc, char *argv[])
  struct bgpd_config *conf;
  struct peer *peer_l, *p;
  struct pollfd pfd[POLL_MAX];
+ time_t timeout;
  pid_t se_pid = 0, rde_pid = 0, pid;
  char *conffile;
  char *saved_argv0;
  int debug = 0;
  int rflag = 0, sflag = 0;
  int rfd = -1;
- int ch, timeout, status;
+ int ch, status;
  int pipe_m2s[2];
  int pipe_m2r[2];
 
@@ -262,9 +263,9 @@ BROKEN if (pledge("stdio rpath wpath cpa
  pfd[PFD_SOCK_ROUTE].events = POLLIN;
 
  timeout = mrt_timeout(conf->mrt);
- if (timeout > MAX_TIMEOUT)
- timeout = MAX_TIMEOUT;
 
+ if (timeout < 0 || timeout > MAX_TIMEOUT)
+ timeout = MAX_TIMEOUT;
  if (poll(pfd, POLL_MAX, timeout * 1000) == -1)
  if (errno != EINTR) {
  log_warn("poll error");
Index: bgpd.h
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/bgpd.h,v
retrieving revision 1.367
diff -u -p -r1.367 bgpd.h
--- bgpd.h 14 Feb 2019 10:38:04 -0000 1.367
+++ bgpd.h 14 Feb 2019 10:44:14 -0000
@@ -1093,7 +1093,6 @@ struct rde_hashstats {
 
 #define MRT_FILE_LEN 512
 #define MRT2MC(x) ((struct mrt_config *)(x))
-#define MRT_MAX_TIMEOUT 7200
 
 enum mrt_type {
  MRT_NONE,
@@ -1195,7 +1194,7 @@ void mrt_clear_seq(void);
 void mrt_write(struct mrt *);
 void mrt_clean(struct mrt *);
 void mrt_init(struct imsgbuf *, struct imsgbuf *);
-int mrt_timeout(struct mrt_head *);
+time_t mrt_timeout(struct mrt_head *);
 void mrt_reconfigure(struct mrt_head *);
 void mrt_handler(struct mrt_head *);
 struct mrt *mrt_get(struct mrt_head *, struct mrt *);
Index: mrt.c
===================================================================
RCS file: /cvs/src/usr.sbin/bgpd/mrt.c,v
retrieving revision 1.91
diff -u -p -r1.91 mrt.c
--- mrt.c 14 Feb 2019 10:38:04 -0000 1.91
+++ mrt.c 14 Feb 2019 10:44:14 -0000
@@ -909,12 +909,12 @@ mrt_open(struct mrt *mrt, time_t now)
  return (1);
 }
 
-int
+time_t
 mrt_timeout(struct mrt_head *mrt)
 {
  struct mrt *m;
  time_t now;
- int timeout = MRT_MAX_TIMEOUT;
+ time_t timeout = -1;
 
  now = time(NULL);
  LIST_FOREACH(m, mrt, entry) {
@@ -925,11 +925,12 @@ mrt_timeout(struct mrt_head *mrt)
  MRT2MC(m)->ReopenTimer =
     now + MRT2MC(m)->ReopenTimerInterval;
  }
- if (MRT2MC(m)->ReopenTimer - now < timeout)
+ if (timeout == -1 ||
+    MRT2MC(m)->ReopenTimer - now < timeout)
  timeout = MRT2MC(m)->ReopenTimer - now;
  }
  }
- return (timeout > 0 ? timeout : 0);
+ return (timeout);
 }
 
 void