diff options
author | sjg <sjg@FreeBSD.org> | 2013-09-05 20:18:59 +0000 |
---|---|---|
committer | sjg <sjg@FreeBSD.org> | 2013-09-05 20:18:59 +0000 |
commit | 62bb1062226d3ce6a2350808256a25508978352d (patch) | |
tree | 22b131dceb13c3df96da594fbaadb693504797c7 /usr.sbin/rtsold | |
parent | 72ab90509b3a51ab361bf710338f2ef44a4e360d (diff) | |
parent | 04932445481c2cb89ff69a83b961bdef3d64757e (diff) | |
download | FreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.zip FreeBSD-src-62bb1062226d3ce6a2350808256a25508978352d.tar.gz |
Merge from head
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 21 | ||||
-rw-r--r-- | usr.sbin/rtsold/if.c | 7 | ||||
-rw-r--r-- | usr.sbin/rtsold/probe.c | 69 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsock.c | 10 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsol.c | 30 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.8 | 15 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 51 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.h | 34 |
8 files changed, 133 insertions, 104 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index 52d4b62..a0bf2c2 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> @@ -51,8 +50,6 @@ static FILE *fp; -extern struct ifinfo *iflist; - static void dump_interface_status(void); static const char * const ifstatstr[] = {"IDLE", "DELAY", "PROBE", "DOWN", "TENTATIVE"}; @@ -62,10 +59,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 +84,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 +134,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 +142,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/if.c b/usr.sbin/rtsold/if.c index 58ec514..2bf946d 100644 --- a/usr.sbin/rtsold/if.c +++ b/usr.sbin/rtsold/if.c @@ -61,7 +61,6 @@ #include <ifaddrs.h> #include "rtsold.h" -extern int rssock; static int ifsock; static int get_llflag(const char *); @@ -304,13 +303,13 @@ if_nametosdl(char *name) lim = buf + len; for (next = buf; next < lim; next += ifm->ifm_msglen) { - ifm = (struct if_msghdr *)next; + ifm = (struct if_msghdr *)(void *)next; if (ifm->ifm_type == RTM_IFINFO) { sa = (struct sockaddr *)(ifm + 1); get_rtaddrs(ifm->ifm_addrs, sa, rti_info); if ((sa = rti_info[RTAX_IFP]) != NULL) { if (sa->sa_family == AF_LINK) { - sdl = (struct sockaddr_dl *)sa; + sdl = (struct sockaddr_dl *)(void *)sa; if (strlen(name) != sdl->sdl_nlen) continue; /* not same len */ if (strncmp(&sdl->sdl_data[0], @@ -397,7 +396,7 @@ get_llflag(const char *name) continue; if (ifa->ifa_addr->sa_family != AF_INET6) continue; - sin6 = (struct sockaddr_in6 *)ifa->ifa_addr; + sin6 = (struct sockaddr_in6 *)(void *)ifa->ifa_addr; if (!IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) continue; diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c index 657ae40..5ec54aa 100644 --- a/usr.sbin/rtsold/probe.c +++ b/usr.sbin/rtsold/probe.c @@ -35,6 +35,7 @@ #include <sys/types.h> #include <sys/ioctl.h> #include <sys/socket.h> +#include <sys/sysctl.h> #include <sys/uio.h> #include <sys/queue.h> @@ -102,41 +103,51 @@ probe_init(void) void defrouter_probe(struct ifinfo *ifinfo) { - u_char ntopbuf[INET6_ADDRSTRLEN]; - struct in6_drlist dr; - int s, i; - int ifindex = ifinfo->sdl->sdl_index; + struct in6_defrouter *p, *ep; + int ifindex, mib[4]; + char *buf, ntopbuf[INET6_ADDRSTRLEN]; + size_t l; - if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { - warnmsg(LOG_ERR, __func__, "socket: %s", strerror(errno)); + ifindex = ifinfo->sdl->sdl_index; + if (ifindex == 0) + return; + mib[0] = CTL_NET; + mib[1] = PF_INET6; + mib[2] = IPPROTO_ICMPV6; + mib[3] = ICMPV6CTL_ND6_DRLIST; + if (sysctl(mib, nitems(mib), NULL, &l, NULL, 0) < 0) { + warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s", + strerror(errno)); return; } - memset(&dr, 0, sizeof(dr)); - strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* dummy interface */ - if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) { - warnmsg(LOG_ERR, __func__, "ioctl(SIOCGDRLST_IN6): %s", + if (l == 0) + return; + buf = malloc(l); + if (buf == NULL) { + warnmsg(LOG_ERR, __func__, "malloc(): %s", strerror(errno)); + return; + } + if (sysctl(mib, nitems(mib), buf, &l, NULL, 0) < 0) { + warnmsg(LOG_ERR, __func__, "sysctl(ICMPV6CTL_ND6_DRLIST): %s", strerror(errno)); - goto closeandend; + free(buf); + return; } - - for (i = 0; i < DRLSTSIZ && dr.defrouter[i].if_index; i++) { - if (ifindex && dr.defrouter[i].if_index == ifindex) { - /* sanity check */ - if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) { - warnmsg(LOG_ERR, __func__, - "default router list contains a " - "non-link-local address(%s)", - inet_ntop(AF_INET6, - &dr.defrouter[i].rtaddr, - ntopbuf, INET6_ADDRSTRLEN)); - continue; /* ignore the address */ - } - sendprobe(&dr.defrouter[i].rtaddr, ifinfo); + ep = (struct in6_defrouter *)(void *)(buf + l); + for (p = (struct in6_defrouter *)(void *)buf; p < ep; p++) { + if (ifindex != p->if_index) + continue; + if (!IN6_IS_ADDR_LINKLOCAL(&p->rtaddr.sin6_addr)) { + warnmsg(LOG_ERR, __func__, + "default router list contains a " + "non-link-local address(%s)", + inet_ntop(AF_INET6, &p->rtaddr.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN)); + continue; /* ignore the address */ } + sendprobe(&p->rtaddr.sin6_addr, ifinfo); } - -closeandend: - close(s); + free(buf); } static void @@ -164,7 +175,7 @@ sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo) cm->cmsg_level = IPPROTO_IPV6; cm->cmsg_type = IPV6_PKTINFO; cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); - pi = (struct in6_pktinfo *)CMSG_DATA(cm); + pi = (struct in6_pktinfo *)(void *)CMSG_DATA(cm); memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/ pi->ipi6_ifindex = ifindex; diff --git a/usr.sbin/rtsold/rtsock.c b/usr.sbin/rtsold/rtsock.c index fe22bc7..702ffe1 100644 --- a/usr.sbin/rtsold/rtsock.c +++ b/usr.sbin/rtsold/rtsock.c @@ -103,7 +103,7 @@ rtsock_input(int s) lim = msg + n; for (next = msg; next < lim; next += len) { - rtm = (struct rt_msghdr *)next; + rtm = (struct rt_msghdr *)(void *)next; if (lim - next < lenlim) break; len = rtm->rtm_msglen; @@ -138,7 +138,7 @@ static int rtsock_input_ifannounce(int s __unused, struct rt_msghdr *rtm, char *lim) { struct if_announcemsghdr *ifan; - struct ifinfo *ifinfo; + struct ifinfo *ifi; ifan = (struct if_announcemsghdr *)rtm; if ((char *)(ifan + 1) > lim) @@ -158,14 +158,14 @@ rtsock_input_ifannounce(int s __unused, struct rt_msghdr *rtm, char *lim) case IFAN_DEPARTURE: warnmsg(LOG_WARNING, __func__, "interface %s removed", ifan->ifan_name); - ifinfo = find_ifinfo(ifan->ifan_index); - if (ifinfo) { + ifi = find_ifinfo(ifan->ifan_index); + if (ifi) { if (dflag > 1) { warnmsg(LOG_INFO, __func__, "bring interface %s to DOWN state", ifan->ifan_name); } - ifinfo->state = IFS_DOWN; + ifi->state = IFS_DOWN; } break; } diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c index 850e5d9..c9b3d44 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> @@ -205,7 +205,7 @@ sendpacket(struct ifinfo *ifi) cm->cmsg_level = IPPROTO_IPV6; cm->cmsg_type = IPV6_PKTINFO; cm->cmsg_len = CMSG_LEN(sizeof(struct in6_pktinfo)); - pi = (struct in6_pktinfo *)CMSG_DATA(cm); + pi = (struct in6_pktinfo *)(void *)CMSG_DATA(cm); memset(&pi->ipi6_addr, 0, sizeof(pi->ipi6_addr)); /*XXX*/ pi->ipi6_ifindex = ifi->sdl->sdl_index; @@ -237,7 +237,7 @@ sendpacket(struct ifinfo *ifi) void rtsol_input(int s) { - u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ]; + char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ]; int l, ifindex = 0, *hlimp = NULL; ssize_t msglen; struct in6_pktinfo *pi = NULL; @@ -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; @@ -275,13 +275,13 @@ rtsol_input(int s) if (cm->cmsg_level == IPPROTO_IPV6 && cm->cmsg_type == IPV6_PKTINFO && cm->cmsg_len == CMSG_LEN(sizeof(struct in6_pktinfo))) { - pi = (struct in6_pktinfo *)(CMSG_DATA(cm)); + pi = (struct in6_pktinfo *)(void *)(CMSG_DATA(cm)); ifindex = pi->ipi6_ifindex; } if (cm->cmsg_level == IPPROTO_IPV6 && cm->cmsg_type == IPV6_HOPLIMIT && cm->cmsg_len == CMSG_LEN(sizeof(int))) - hlimp = (int *)CMSG_DATA(cm); + hlimp = (int *)(void *)CMSG_DATA(cm); } if (ifindex == 0) { @@ -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) { @@ -417,7 +417,7 @@ rtsol_input(int s) break; } - addr = (struct in6_addr *)(raoptp + sizeof(*rdnss)); + addr = (struct in6_addr *)(void *)(raoptp + sizeof(*rdnss)); while ((char *)addr < (char *)RA_OPT_NEXT_HDR(raoptp)) { if (inet_ntop(AF_INET6, addr, ntopbuf, sizeof(ntopbuf)) == 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.8 b/usr.sbin/rtsold/rtsold.8 index 946eca2..a723e9c 100644 --- a/usr.sbin/rtsold/rtsold.8 +++ b/usr.sbin/rtsold/rtsold.8 @@ -161,15 +161,10 @@ will dump the current internal state into The options are as follows: .Bl -tag -width indent .It Fl a -Autoprobe outgoing interface. +Autoprobe outgoing interfaces. .Nm -will try to find a non-loopback, non-point-to-point, IPv6-capable interface. -If -.Nm -finds multiple interfaces, -.Nm -will exit with error. -.\" +will try to find any non-loopback, non-point-to-point, IPv6-capable interfaces +and send router solicitation messages on all of them. .It Fl d Enable debugging. .It Fl D @@ -261,10 +256,10 @@ If not, it will be .Sh FILES .Bl -tag -width /var/run/rtsold.dump -compact .It Pa /var/run/rtsold.pid -the pid of the currently running +The PID of the currently running .Nm . .It Pa /var/run/rtsold.dump -dumps internal state on. +Internal state dump file. .El .\" .Sh EXIT STATUS diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index d3d1289..a97b884 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> @@ -67,8 +67,7 @@ #define RTSOL_DUMPFILE "/var/run/rtsold.dump"; #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 +104,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 +115,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 +186,10 @@ main(int argc, char **argv) exit(1); } + /* Generate maximum time in timespec. */ + tm_max.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) - 1)); + tm_max.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) - 1)); + /* set log level */ if (dflag > 1) log_upto = LOG_DEBUG; @@ -363,7 +366,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 +606,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 +714,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 +731,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 +758,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 +786,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 +810,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 3ab010f..56b4185 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; @@ -153,6 +176,7 @@ extern int getinet6sysctl(int); extern int setinet6sysctl(int, int); /* rtsol.c */ +extern int rssock; extern int sockopen(void); extern void sendpacket(struct ifinfo *); extern void rtsol_input(int); @@ -163,7 +187,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); |