[Midnightbsd-cvs] src [10340] trunk/usr.sbin/rtsold: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 3 16:02:29 EDT 2018
Revision: 10340
http://svnweb.midnightbsd.org/src/?rev=10340
Author: laffer1
Date: 2018-06-03 16:02:28 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/usr.sbin/rtsold/Makefile
trunk/usr.sbin/rtsold/dump.c
trunk/usr.sbin/rtsold/if.c
trunk/usr.sbin/rtsold/probe.c
trunk/usr.sbin/rtsold/rtsock.c
trunk/usr.sbin/rtsold/rtsol.c
trunk/usr.sbin/rtsold/rtsold.8
trunk/usr.sbin/rtsold/rtsold.c
trunk/usr.sbin/rtsold/rtsold.h
Modified: trunk/usr.sbin/rtsold/Makefile
===================================================================
--- trunk/usr.sbin/rtsold/Makefile 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/Makefile 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+# $MidnightBSD$
# Copyright (c) 1996 WIDE Project. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
@@ -12,7 +13,7 @@
# LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE.
#
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/rtsold/Makefile 290149 2015-10-29 16:53:34Z delphij $
PROG= rtsold
MAN= rtsold.8
@@ -20,7 +21,7 @@
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
WARNS?= 3
-CFLAGS+= -DHAVE_ARC4RANDOM -DHAVE_POLL_H
+CFLAGS+= -DHAVE_POLL_H
DPADD= ${LIBKVM}
LDADD= -lkvm
Modified: trunk/usr.sbin/rtsold/dump.c
===================================================================
--- trunk/usr.sbin/rtsold/dump.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/dump.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: dump.c,v 1.13 2003/10/05 00:09:36 itojun Exp $ */
/*
@@ -28,11 +29,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/dump.c 254462 2013-08-17 19:23:35Z hrs $
*/
#include <sys/types.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <sys/queue.h>
@@ -51,8 +51,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 +60,10 @@
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 +85,12 @@
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 +135,7 @@
}
const char *
-sec2str(const struct timeval *total)
+sec2str(const struct timespec *total)
{
static char result[256];
int days, hours, mins, secs;
@@ -145,14 +143,14 @@
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;
Modified: trunk/usr.sbin/rtsold/if.c
===================================================================
--- trunk/usr.sbin/rtsold/if.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/if.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: if.c,v 1.27 2003/10/05 00:09:36 itojun Exp $ */
/*
@@ -28,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/if.c 300283 2016-05-20 07:08:19Z truckman $
*/
#include <sys/param.h>
@@ -61,7 +62,6 @@
#include <ifaddrs.h>
#include "rtsold.h"
-extern int rssock;
static int ifsock;
static int get_llflag(const char *);
@@ -84,7 +84,7 @@
int s;
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
memset(&nd, 0, sizeof(nd));
strlcpy(nd.ifname, name, sizeof(nd.ifname));
@@ -182,7 +182,7 @@
/* get interface flags */
memset(&ifr, 0, sizeof(ifr));
- strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
+ strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
warnmsg(LOG_ERR, __func__, "ioctl(SIOCGIFFLAGS) on %s: %s",
ifname, strerror(errno));
@@ -198,7 +198,7 @@
if (!ifinfo->mediareqok)
goto active;
memset(&ifmr, 0, sizeof(ifmr));
- strncpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
+ strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name));
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (errno != EINVAL) {
@@ -304,13 +304,13 @@
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,12 +397,12 @@
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;
memset(&ifr6, 0, sizeof(ifr6));
- strncpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
+ strlcpy(ifr6.ifr_name, name, sizeof(ifr6.ifr_name));
memcpy(&ifr6.ifr_ifru.ifru_addr, sin6, sin6->sin6_len);
if (ioctl(s, SIOCGIFAFLAG_IN6, &ifr6) < 0) {
warnmsg(LOG_ERR, __func__,
Modified: trunk/usr.sbin/rtsold/probe.c
===================================================================
--- trunk/usr.sbin/rtsold/probe.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/probe.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: probe.c,v 1.17 2003/10/05 00:09:36 itojun Exp $ */
/*
@@ -28,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/probe.c 254470 2013-08-17 22:13:26Z hrs $
*/
#include <sys/param.h>
@@ -35,6 +36,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 +104,51 @@
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 +176,7 @@
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;
Modified: trunk/usr.sbin/rtsold/rtsock.c
===================================================================
--- trunk/usr.sbin/rtsold/rtsock.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/rtsock.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $KAME: rtsock.c,v 1.3 2000/10/10 08:46:45 itojun Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtsold/rtsock.c 254462 2013-08-17 19:23:35Z hrs $ */
/*
* Copyright (C) 2000 WIDE Project.
@@ -103,7 +104,7 @@
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 +139,7 @@
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 +159,14 @@
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;
}
Modified: trunk/usr.sbin/rtsold/rtsol.c
===================================================================
--- trunk/usr.sbin/rtsold/rtsol.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/rtsol.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: rtsol.c,v 1.27 2003/10/05 00:09:36 itojun Exp $ */
/*
@@ -29,13 +30,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/rtsol.c 307646 2016-10-19 17:31:59Z markj $
*/
#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 +58,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
+#include <time.h>
#include <err.h>
#include <errno.h>
#include <string.h>
@@ -205,7 +206,7 @@
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 +238,7 @@
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 +257,8 @@
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 +276,13 @@
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) {
@@ -347,7 +348,7 @@
/* xxx: more validation? */
if ((ifi = find_ifinfo(pi->ipi6_ifindex)) == NULL) {
- warnmsg(LOG_INFO, __func__,
+ warnmsg(LOG_DEBUG, __func__,
"received RA from %s on an unexpected IF(%s)",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
sizeof(ntopbuf)),
@@ -376,7 +377,7 @@
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 +418,7 @@
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 +473,7 @@
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 +532,7 @@
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 +575,7 @@
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 +585,7 @@
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 +596,7 @@
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 +618,7 @@
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);
Modified: trunk/usr.sbin/rtsold/rtsold.8
===================================================================
--- trunk/usr.sbin/rtsold/rtsold.8 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/rtsold.8 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $KAME: rtsold.8,v 1.20 2003/04/11 12:46:12 jinmei Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -27,7 +28,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.sbin/rtsold/rtsold.8 251059 2013-05-28 13:54:26Z markj $
.\"
.Dd June 14, 2011
.Dt RTSOLD 8
@@ -230,7 +231,7 @@
instead of the default PID file
.Pa /var/run/rtsold.pid .
.It Fl R Ar script-name
-Specifies a script to run when router advertisment options
+Specifies a script to run when router advertisement options
.Dv RDNSS Pq Recursive DNS Server
or
.Dv DNSSL Pq DNS Search List
Modified: trunk/usr.sbin/rtsold/rtsold.c
===================================================================
--- trunk/usr.sbin/rtsold/rtsold.c 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/rtsold.c 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: rtsold.c,v 1.67 2003/05/17 18:16:15 itojun Exp $ */
/*
@@ -28,12 +29,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/rtsold.c 295898 2016-02-22 20:20:10Z markj $
*/
#include <sys/types.h>
#include <sys/ioctl.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include <sys/param.h>
@@ -54,6 +54,7 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
+#include <time.h>
#include <errno.h>
#include <err.h>
#include <stdarg.h>
@@ -67,8 +68,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 +105,7 @@
#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 @@
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,10 @@
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;
@@ -220,10 +224,6 @@
errx(1, "pid filename (%s) must be an absolute path",
pidfilename);
}
-#ifndef HAVE_ARC4RANDOM
- /* random value initialization */
- srandom((u_long)time(NULL));
-#endif
#if (__FreeBSD_version < 900000)
if (Fflag) {
@@ -363,7 +363,7 @@
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 +603,22 @@
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;
+ struct ra_opt *rao, *raotmp;
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);
@@ -705,13 +705,14 @@
int expire = 0;
TAILQ_FOREACH(rai, &ifi->ifi_rainfo, rai_next) {
- TAILQ_FOREACH(rao, &rai->rai_ra_opt, rao_next) {
+ TAILQ_FOREACH_SAFE(rao, &rai->rai_ra_opt,
+ rao_next, raotmp) {
warnmsg(LOG_DEBUG, __func__,
"RA expiration timer: "
"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 +729,21 @@
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 +756,7 @@
#define MILLION 1000000
#define DADRETRY 10 /* XXX: adhoc */
long interval;
- struct timeval now;
+ struct timespec now;
bzero(&ifi->timer, sizeof(ifi->timer));
@@ -777,13 +778,9 @@
ifi->timer = tm_max; /* stop timer(valid?) */
break;
case IFS_DELAY:
-#ifndef HAVE_ARC4RANDOM
- interval = random() % (MAX_RTR_SOLICITATION_DELAY * MILLION);
-#else
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 +804,16 @@
}
/* 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));
}
@@ -839,15 +836,15 @@
usage(void)
{
#ifndef SMALL
- fprintf(stderr, "usage: rtsold [-adDfFm1] [-O script-name] "
- "[-P pidfile] [-R script-name] interfaces...\n");
fprintf(stderr, "usage: rtsold [-dDfFm1] [-O script-name] "
- "[-P pidfile] [-R script-name] -a\n");
+ "[-p pidfile] [-R script-name] interface ...\n");
+ fprintf(stderr, "usage: rtsold [-dDfFm1] [-O script-name] "
+ "[-p pidfile] [-R script-name] -a\n");
#else
fprintf(stderr, "usage: rtsol [-dDF] [-O script-name] "
- "[-P pidfile] [-R script-name] interfaces...\n");
+ "[-p pidfile] [-R script-name] interface ...\n");
fprintf(stderr, "usage: rtsol [-dDF] [-O script-name] "
- "[-P pidfile] [-R script-name] -a\n");
+ "[-p pidfile] [-R script-name] -a\n");
#endif
}
@@ -881,7 +878,7 @@
static int n = 0;
char **a;
int s = 0, i, found;
- struct ifaddrs *ifap, *ifa, *target;
+ struct ifaddrs *ifap, *ifa;
struct in6_ndireq nd;
/* initialize */
@@ -901,7 +898,6 @@
exit(1);
}
- target = NULL;
/* find an ethernet */
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if ((ifa->ifa_flags & IFF_UP) == 0)
Modified: trunk/usr.sbin/rtsold/rtsold.h
===================================================================
--- trunk/usr.sbin/rtsold/rtsold.h 2018-06-03 20:01:44 UTC (rev 10339)
+++ trunk/usr.sbin/rtsold/rtsold.h 2018-06-03 20:02:28 UTC (rev 10340)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $KAME: rtsold.h,v 1.19 2003/04/16 09:48:15 itojun Exp $ */
/*
@@ -28,7 +29,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtsold/rtsold.h 293290 2016-01-07 00:40:51Z bdrewery $
*/
struct script_msg {
@@ -43,7 +44,7 @@
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;
};
@@ -67,14 +68,14 @@
int active; /* interface status */
int probeinterval; /* interval of probe timer (if necessary) */
int probetimer; /* rest of probe timer */
- int mediareqok; /* wheter the IF supports SIOCGIFMEDIA */
+ int mediareqok; /* whether the IF supports SIOCGIFMEDIA */
int otherconfig; /* need a separate protocol for the "other"
* configuration */
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 +125,31 @@
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 +177,7 @@
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 +188,7 @@
/* 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);
More information about the Midnightbsd-cvs
mailing list