diff options
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 19 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsol.c | 20 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 52 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.h | 33 |
4 files changed, 76 insertions, 48 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index 52d4b62e1390..ddf0d3c0d533 100644 --- a/usr.sbin/rtsold/dump.c +++ b/usr.sbin/rtsold/dump.c @@ -32,7 +32,6 @@ */ #include <sys/types.h> -#include <sys/time.h> #include <sys/socket.h> #include <sys/queue.h> @@ -62,10 +61,10 @@ dump_interface_status(void) struct ifinfo *ifi; struct rainfo *rai; struct ra_opt *rao; - struct timeval now; + struct timespec now; char ntopbuf[INET6_ADDRSTRLEN]; - gettimeofday(&now, NULL); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) { fprintf(fp, "Interface %s\n", ifi->ifname); @@ -87,12 +86,12 @@ dump_interface_status(void) fprintf(fp, " probes: %d, dadcount = %d\n", ifi->probes, ifi->dadcount); if (ifi->timer.tv_sec == tm_max.tv_sec && - ifi->timer.tv_usec == tm_max.tv_usec) + ifi->timer.tv_nsec == tm_max.tv_nsec) fprintf(fp, " no timer\n"); else { fprintf(fp, " timer: interval=%d:%d, expire=%s\n", (int)ifi->timer.tv_sec, - (int)ifi->timer.tv_usec, + (int)ifi->timer.tv_nsec / 1000, (ifi->expire.tv_sec < now.tv_sec) ? "expired" : sec2str(&ifi->expire)); } @@ -137,7 +136,7 @@ rtsold_dump_file(const char *dumpfile) } const char * -sec2str(const struct timeval *total) +sec2str(const struct timespec *total) { static char result[256]; int days, hours, mins, secs; @@ -145,14 +144,14 @@ sec2str(const struct timeval *total) char *p = result; char *ep = &result[sizeof(result)]; int n; - struct timeval now; + struct timespec now; time_t tsec; - gettimeofday(&now, NULL); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); tsec = total->tv_sec; - tsec += total->tv_usec / 1000000; + tsec += total->tv_nsec / 1000 / 1000000; tsec -= now.tv_sec; - tsec -= now.tv_usec / 1000000; + tsec -= now.tv_nsec / 1000 / 1000000; days = tsec / 3600 / 24; hours = (tsec / 3600) % 24; diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c index 181012c52fb3..f7210f666693 100644 --- a/usr.sbin/rtsold/rtsol.c +++ b/usr.sbin/rtsold/rtsol.c @@ -35,7 +35,6 @@ #include <sys/param.h> #include <sys/socket.h> #include <sys/uio.h> -#include <sys/time.h> #include <sys/queue.h> #include <sys/wait.h> #include <sys/stat.h> @@ -58,6 +57,7 @@ #include <fcntl.h> #include <unistd.h> #include <stdio.h> +#include <time.h> #include <err.h> #include <errno.h> #include <string.h> @@ -256,8 +256,8 @@ rtsol_input(int s) size_t len; char nsbuf[INET6_ADDRSTRLEN + 1 + IFNAMSIZ + 1]; char dname[NI_MAXHOST]; - struct timeval now; - struct timeval lifetime; + struct timespec now; + struct timespec lifetime; int newent_rai; int newent_rao; @@ -376,7 +376,7 @@ rtsol_input(int s) ifi->otherconfig = 1; CALL_SCRIPT(OTHER, NULL); } - gettimeofday(&now, NULL); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); newent_rai = 0; rai = find_rainfo(ifi, &from); if (rai == NULL) { @@ -472,7 +472,7 @@ rtsol_input(int s) memset(&lifetime, 0, sizeof(lifetime)); lifetime.tv_sec = ntohl(rdnss->nd_opt_rdnss_lifetime); - timeradd(&now, &lifetime, &rao->rao_expire); + TS_ADD(&now, &lifetime, &rao->rao_expire); if (newent_rao) TAILQ_INSERT_TAIL(&rai->rai_ra_opt, @@ -531,7 +531,7 @@ rtsol_input(int s) memset(&lifetime, 0, sizeof(lifetime)); lifetime.tv_sec = ntohl(dnssl->nd_opt_dnssl_lifetime); - timeradd(&now, &lifetime, &rao->rao_expire); + TS_ADD(&now, &lifetime, &rao->rao_expire); if (newent_rao) TAILQ_INSERT_TAIL(&rai->rai_ra_opt, @@ -574,7 +574,7 @@ ra_opt_handler(struct ifinfo *ifi) struct ra_opt *rao; struct rainfo *rai; struct script_msg *smp1, *smp2, *smp3; - struct timeval now; + struct timespec now; struct script_msg_head_t sm_rdnss_head = TAILQ_HEAD_INITIALIZER(sm_rdnss_head); struct script_msg_head_t sm_dnssl_head = @@ -584,7 +584,7 @@ ra_opt_handler(struct ifinfo *ifi) dcount = 0; dlen = strlen(resstr_sh_prefix) + strlen(resstr_nl); - gettimeofday(&now, NULL); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); /* * All options from multiple RAs with the same or different @@ -595,7 +595,7 @@ ra_opt_handler(struct ifinfo *ifi) TAILQ_FOREACH(rao, &rai->rai_ra_opt, rao_next) { switch (rao->rao_type) { case ND_OPT_RDNSS: - if (timercmp(&now, &rao->rao_expire, >)) { + if (TS_CMP(&now, &rao->rao_expire, >)) { warnmsg(LOG_INFO, __func__, "expired rdnss entry: %s", (char *)rao->rao_msg); @@ -617,7 +617,7 @@ ra_opt_handler(struct ifinfo *ifi) break; case ND_OPT_DNSSL: - if (timercmp(&now, &rao->rao_expire, >)) { + if (TS_CMP(&now, &rao->rao_expire, >)) { warnmsg(LOG_INFO, __func__, "expired dnssl entry: %s", (char *)rao->rao_msg); diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index d3d1289aa562..2826c2cc43e5 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -33,7 +33,6 @@ #include <sys/types.h> #include <sys/ioctl.h> -#include <sys/time.h> #include <sys/socket.h> #include <sys/param.h> @@ -54,6 +53,7 @@ #include <string.h> #include <stdlib.h> #include <stdio.h> +#include <time.h> #include <errno.h> #include <err.h> #include <stdarg.h> @@ -68,7 +68,7 @@ #define RTSOL_PIDFILE "/var/run/rtsold.pid"; struct ifinfo *iflist; -struct timeval tm_max = {0x7fffffff, 0x7fffffff}; +struct timespec tm_max; static int log_upto = 999; static int fflag = 0; @@ -105,7 +105,7 @@ static int ifreconfig(char *); #endif static int make_packet(struct ifinfo *); -static struct timeval *rtsol_check_timer(void); +static struct timespec *rtsol_check_timer(void); #ifndef SMALL static void rtsold_set_dump_file(int); @@ -116,7 +116,7 @@ int main(int argc, char **argv) { int s, ch, once = 0; - struct timeval *timeout; + struct timespec *timeout; const char *opts; #ifdef HAVE_POLL_H struct pollfd set[2]; @@ -187,6 +187,12 @@ main(int argc, char **argv) exit(1); } + /* Generate maximum time in timespec. */ + memset(&tm_max.tv_sec, 0xff, sizeof(tm_max.tv_sec)); + memset(&tm_max.tv_nsec, 0xff, sizeof(tm_max.tv_nsec)); + tm_max.tv_sec &= ~(1UL << (sizeof(tm_max.tv_sec) * 8 - 1)); + tm_max.tv_nsec &= ~(1UL << (sizeof(tm_max.tv_nsec) * 8 - 1)); + /* set log level */ if (dflag > 1) log_upto = LOG_DEBUG; @@ -363,7 +369,7 @@ main(int argc, char **argv) break; } #ifdef HAVE_POLL_H - e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_usec / 1000) : INFTIM); + e = poll(set, 2, timeout ? (timeout->tv_sec * 1000 + timeout->tv_nsec / 1000 / 1000) : INFTIM); #else e = select(maxfd + 1, selectfdp, NULL, NULL, timeout); #endif @@ -603,22 +609,22 @@ make_packet(struct ifinfo *ifi) return (0); } -static struct timeval * +static struct timespec * rtsol_check_timer(void) { - static struct timeval returnval; - struct timeval now, rtsol_timer; + static struct timespec returnval; + struct timespec now, rtsol_timer; struct ifinfo *ifi; struct rainfo *rai; struct ra_opt *rao; int flags; - gettimeofday(&now, NULL); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); rtsol_timer = tm_max; TAILQ_FOREACH(ifi, &ifinfo_head, ifi_next) { - if (timercmp(&ifi->expire, &now, <=)) { + if (TS_CMP(&ifi->expire, &now, <=)) { warnmsg(LOG_DEBUG, __func__, "timer expiration on %s, " "state = %d", ifi->ifname, ifi->state); @@ -711,7 +717,7 @@ rtsol_check_timer(void) "type=%d, msg=%s, expire=%s", rao->rao_type, (char *)rao->rao_msg, sec2str(&rao->rao_expire)); - if (timercmp(&now, &rao->rao_expire, + if (TS_CMP(&now, &rao->rao_expire, >=)) { warnmsg(LOG_DEBUG, __func__, "RA expiration timer: " @@ -728,21 +734,21 @@ rtsol_check_timer(void) if (expire) ra_opt_handler(ifi); } - if (timercmp(&ifi->expire, &rtsol_timer, <)) + if (TS_CMP(&ifi->expire, &rtsol_timer, <)) rtsol_timer = ifi->expire; } - if (timercmp(&rtsol_timer, &tm_max, ==)) { + if (TS_CMP(&rtsol_timer, &tm_max, ==)) { warnmsg(LOG_DEBUG, __func__, "there is no timer"); return (NULL); - } else if (timercmp(&rtsol_timer, &now, <)) + } else if (TS_CMP(&rtsol_timer, &now, <)) /* this may occur when the interval is too small */ - returnval.tv_sec = returnval.tv_usec = 0; + returnval.tv_sec = returnval.tv_nsec = 0; else - timersub(&rtsol_timer, &now, &returnval); + TS_SUB(&rtsol_timer, &now, &returnval); now.tv_sec += returnval.tv_sec; - now.tv_usec += returnval.tv_usec; + now.tv_nsec += returnval.tv_nsec; warnmsg(LOG_DEBUG, __func__, "New timer is %s", sec2str(&now)); @@ -755,7 +761,7 @@ rtsol_timer_update(struct ifinfo *ifi) #define MILLION 1000000 #define DADRETRY 10 /* XXX: adhoc */ long interval; - struct timeval now; + struct timespec now; bzero(&ifi->timer, sizeof(ifi->timer)); @@ -783,7 +789,7 @@ rtsol_timer_update(struct ifinfo *ifi) interval = arc4random_uniform(MAX_RTR_SOLICITATION_DELAY * MILLION); #endif ifi->timer.tv_sec = interval / MILLION; - ifi->timer.tv_usec = interval % MILLION; + ifi->timer.tv_nsec = (interval % MILLION) * 1000; break; case IFS_PROBE: if (ifi->probes < MAX_RTR_SOLICITATIONS) @@ -807,16 +813,16 @@ rtsol_timer_update(struct ifinfo *ifi) } /* reset the timer */ - if (timercmp(&ifi->timer, &tm_max, ==)) { + if (TS_CMP(&ifi->timer, &tm_max, ==)) { ifi->expire = tm_max; warnmsg(LOG_DEBUG, __func__, "stop timer for %s", ifi->ifname); } else { - gettimeofday(&now, NULL); - timeradd(&now, &ifi->timer, &ifi->expire); + clock_gettime(CLOCK_MONOTONIC_FAST, &now); + TS_ADD(&now, &ifi->timer, &ifi->expire); now.tv_sec += ifi->timer.tv_sec; - now.tv_usec += ifi->timer.tv_usec; + now.tv_nsec += ifi->timer.tv_nsec; warnmsg(LOG_DEBUG, __func__, "set timer for %s to %s", ifi->ifname, sec2str(&now)); } diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h index 3ab010f1914a..69f9c352fe9e 100644 --- a/usr.sbin/rtsold/rtsold.h +++ b/usr.sbin/rtsold/rtsold.h @@ -43,7 +43,7 @@ struct ra_opt { TAILQ_ENTRY(ra_opt) rao_next; u_int8_t rao_type; - struct timeval rao_expire; + struct timespec rao_expire; size_t rao_len; void *rao_msg; }; @@ -73,8 +73,8 @@ struct ifinfo { int state; int probes; int dadcount; - struct timeval timer; - struct timeval expire; + struct timespec timer; + struct timespec expire; int errors; /* # of errors we've got - detect wedge */ #define IFI_DNSOPT_STATE_NOINFO 0 #define IFI_DNSOPT_STATE_RECEIVED 1 @@ -124,8 +124,31 @@ extern TAILQ_HEAD(ifinfo_head_t, ifinfo) ifinfo_head; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }}} #endif +#define TS_CMP(tsp, usp, cmp) \ + (((tsp)->tv_sec == (usp)->tv_sec) ? \ + ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ + ((tsp)->tv_sec cmp (usp)->tv_sec)) +#define TS_ADD(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec + (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec + (usp)->tv_nsec; \ + if ((vsp)->tv_nsec >= 1000000000L) { \ + (vsp)->tv_sec++; \ + (vsp)->tv_nsec -= 1000000000L; \ + } \ + } while (0) +#define TS_SUB(tsp, usp, vsp) \ + do { \ + (vsp)->tv_sec = (tsp)->tv_sec - (usp)->tv_sec; \ + (vsp)->tv_nsec = (tsp)->tv_nsec - (usp)->tv_nsec; \ + if ((vsp)->tv_nsec < 0) { \ + (vsp)->tv_sec--; \ + (vsp)->tv_nsec += 1000000000L; \ + } \ + } while (0) + /* rtsold.c */ -extern struct timeval tm_max; +extern struct timespec tm_max; extern int dflag; extern int aflag; extern int Fflag; @@ -163,7 +186,7 @@ extern void defrouter_probe(struct ifinfo *); /* dump.c */ extern void rtsold_dump_file(const char *); -extern const char *sec2str(const struct timeval *); +extern const char *sec2str(const struct timespec *); /* rtsock.c */ extern int rtsock_open(void); |