[Midnightbsd-cvs] src [10341] trunk/usr.sbin/rtadvd: sync with freebsd
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jun 3 16:04:50 EDT 2018
Revision: 10341
http://svnweb.midnightbsd.org/src/?rev=10341
Author: laffer1
Date: 2018-06-03 16:04:50 -0400 (Sun, 03 Jun 2018)
Log Message:
-----------
sync with freebsd
Modified Paths:
--------------
trunk/usr.sbin/rtadvd/Makefile
trunk/usr.sbin/rtadvd/config.c
trunk/usr.sbin/rtadvd/control.c
trunk/usr.sbin/rtadvd/control_server.h
trunk/usr.sbin/rtadvd/dump.c
trunk/usr.sbin/rtadvd/dump.h
trunk/usr.sbin/rtadvd/if.c
trunk/usr.sbin/rtadvd/if.h
trunk/usr.sbin/rtadvd/pathnames.h
trunk/usr.sbin/rtadvd/rrenum.c
trunk/usr.sbin/rtadvd/rrenum.h
trunk/usr.sbin/rtadvd/rtadvd.8
trunk/usr.sbin/rtadvd/rtadvd.c
trunk/usr.sbin/rtadvd/rtadvd.conf.5
trunk/usr.sbin/rtadvd/rtadvd.h
trunk/usr.sbin/rtadvd/timer.c
trunk/usr.sbin/rtadvd/timer.h
trunk/usr.sbin/rtadvd/timer_subr.c
trunk/usr.sbin/rtadvd/timer_subr.h
Property Changed:
----------------
trunk/usr.sbin/rtadvd/rtadvd.8
trunk/usr.sbin/rtadvd/rtadvd.conf.5
Modified: trunk/usr.sbin/rtadvd/Makefile
===================================================================
--- trunk/usr.sbin/rtadvd/Makefile 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/Makefile 2018-06-03 20:04:50 UTC (rev 10341)
@@ -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/rtadvd/Makefile 290149 2015-10-29 16:53:34Z delphij $
PROG= rtadvd
MAN= rtadvd.conf.5 rtadvd.8
@@ -22,8 +23,6 @@
DPADD= ${LIBUTIL}
LDADD= -lutil
-CFLAGS+= -DHAVE_ARC4RANDOM
-
WARNS?= 1
.include <bsd.prog.mk>
Modified: trunk/usr.sbin/rtadvd/config.c
===================================================================
--- trunk/usr.sbin/rtadvd/config.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/config.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/config.c 301809 2016-06-10 18:21:05Z ngie $ */
/* $KAME: config.c,v 1.84 2003/08/05 12:34:23 itojun Exp $ */
/*
@@ -34,7 +35,6 @@
#include <sys/param.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
-#include <sys/time.h>
#include <net/if.h>
#include <net/if_var.h>
@@ -58,6 +58,7 @@
#include <string.h>
#include <search.h>
#include <stdlib.h>
+#include <time.h>
#include <unistd.h>
#include <ifaddrs.h>
@@ -216,7 +217,7 @@
"<%s> ifname=%s marked as UNCONFIGURED.",
__func__, ifi->ifi_ifname);
- /* XXX: No MC leaving here becasue index is disappeared */
+ /* XXX: No MC leaving here because index is disappeared */
/* Inactivate timer */
rtadvd_remove_timer(ifi->ifi_ra_timer);
@@ -229,7 +230,6 @@
TAILQ_REMOVE(&ifilist, ifi, ifi_next);
syslog(LOG_DEBUG, "<%s>: ifinfo (idx=%d) removed.",
__func__, ifi->ifi_ifindex);
- free(ifi);
} else {
/* recreate an empty entry */
update_persist_ifinfo(&ifilist, ifi->ifi_ifname);
@@ -273,6 +273,8 @@
}
syslog(LOG_DEBUG, "<%s> leave (%s).", __func__, ifi->ifi_ifname);
+ if (!ifi->ifi_persist)
+ free(ifi);
return (0);
}
@@ -296,10 +298,8 @@
if (rai->rai_ra_data != NULL)
free(rai->rai_ra_data);
- while ((pfx = TAILQ_FIRST(&rai->rai_prefix)) != NULL) {
- TAILQ_REMOVE(&rai->rai_prefix, pfx, pfx_next);
- free(pfx);
- }
+ while ((pfx = TAILQ_FIRST(&rai->rai_prefix)) != NULL)
+ delete_prefix(pfx);
while ((sol = TAILQ_FIRST(&rai->rai_soliciter)) != NULL) {
TAILQ_REMOVE(&rai->rai_soliciter, sol, sol_next);
free(sol);
@@ -563,8 +563,9 @@
makeentry(entbuf, sizeof(entbuf), i, "vltimedecr");
if (agetflag(entbuf)) {
- struct timeval now;
- gettimeofday(&now, 0);
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
pfx->pfx_vltimeexpire =
now.tv_sec + pfx->pfx_validlifetime;
}
@@ -583,8 +584,9 @@
makeentry(entbuf, sizeof(entbuf), i, "pltimedecr");
if (agetflag(entbuf)) {
- struct timeval now;
- gettimeofday(&now, 0);
+ struct timespec now;
+
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
pfx->pfx_pltimeexpire =
now.tv_sec + pfx->pfx_preflifetime;
}
@@ -634,7 +636,7 @@
exit(1);
}
memset(&ndi, 0, sizeof(ndi));
- strncpy(ndi.ifname, ifi->ifi_ifname, sizeof(ndi.ifname));
+ strlcpy(ndi.ifname, ifi->ifi_ifname, sizeof(ndi.ifname));
if (ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&ndi) < 0)
syslog(LOG_INFO, "<%s> ioctl:SIOCGIFINFO_IN6 at %s: %s",
__func__, ifi->ifi_ifname, strerror(errno));
@@ -1123,9 +1125,9 @@
pfx->pfx_onlinkflg = ipr->ipr_raf_onlink;
pfx->pfx_autoconfflg = ipr->ipr_raf_auto;
pfx->pfx_origin = PREFIX_FROM_DYNAMIC;
+ pfx->pfx_rainfo = rai;
TAILQ_INSERT_TAIL(&rai->rai_prefix, pfx, pfx_next);
- pfx->pfx_rainfo = rai;
syslog(LOG_DEBUG, "<%s> new prefix %s/%d was added on %s",
__func__,
@@ -1164,7 +1166,7 @@
void
invalidate_prefix(struct prefix *pfx)
{
- struct timeval timo;
+ struct timespec timo;
struct rainfo *rai;
struct ifinfo *ifi;
char ntopbuf[INET6_ADDRSTRLEN];
@@ -1191,7 +1193,7 @@
delete_prefix(pfx);
}
timo.tv_sec = prefix_timo;
- timo.tv_usec = 0;
+ timo.tv_nsec = 0;
rtadvd_set_timer(&timo, pfx->pfx_timer);
}
@@ -1286,7 +1288,7 @@
memset(&ipr, 0, sizeof(ipr));
if (if_indextoname(ifindex, ipr.ipr_name) == NULL) {
- syslog(LOG_ERR, "<%s> Prefix added interface No.%d doesn't"
+ syslog(LOG_ERR, "<%s> Prefix added interface No.%d doesn't "
"exist. This should not happen! %s", __func__,
ifindex, strerror(errno));
exit(1);
@@ -1415,7 +1417,7 @@
TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) {
uint32_t vltime, pltime;
- struct timeval now;
+ struct timespec now;
ndopt_pi = (struct nd_opt_prefix_info *)buf;
ndopt_pi->nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
@@ -1432,7 +1434,7 @@
vltime = 0;
else {
if (pfx->pfx_vltimeexpire || pfx->pfx_pltimeexpire)
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
if (pfx->pfx_vltimeexpire == 0)
vltime = pfx->pfx_validlifetime;
else
Modified: trunk/usr.sbin/rtadvd/control.c
===================================================================
--- trunk/usr.sbin/rtadvd/control.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/control.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (C) 2011 Hiroki Sato <hrs at FreeBSD.org>
* All rights reserved.
@@ -23,7 +24,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtadvd/control.c 301803 2016-06-10 18:02:51Z ngie $
*
*/
@@ -59,7 +60,7 @@
int
cm_recv(int fd, char *buf)
{
- int n;
+ ssize_t n;
struct ctrl_msg_hdr *cm;
char *msg;
struct pollfd pfds[1];
@@ -98,7 +99,7 @@
}
}
- if (n != sizeof(*cm)) {
+ if (n != (ssize_t)sizeof(*cm)) {
syslog(LOG_WARNING,
"<%s> received a too small message.", __func__);
goto cm_recv_err;
@@ -123,11 +124,11 @@
"<%s> ctrl msg received: type=%d", __func__,
cm->cm_type);
- if (cm->cm_len > sizeof(cm)) {
- int msglen = cm->cm_len - sizeof(*cm);
+ if (cm->cm_len > sizeof(*cm)) {
+ size_t msglen = cm->cm_len - sizeof(*cm);
syslog(LOG_DEBUG,
- "<%s> ctrl msg has payload (len=%d)", __func__,
+ "<%s> ctrl msg has payload (len=%zu)", __func__,
msglen);
for (;;) {
@@ -153,7 +154,7 @@
}
break;
}
- if (n != msglen) {
+ if (n != (ssize_t)msglen) {
syslog(LOG_WARNING,
"<%s> payload size mismatch.", __func__);
goto cm_recv_err;
Modified: trunk/usr.sbin/rtadvd/control_server.h
===================================================================
--- trunk/usr.sbin/rtadvd/control_server.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/control_server.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (C) 2011 Hiroki Sato <hrs at FreeBSD.org>
* All rights reserved.
@@ -23,7 +24,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.sbin/rtadvd/control_server.h 225519 2011-09-12 23:52:55Z hrs $
*
*/
Modified: trunk/usr.sbin/rtadvd/dump.c
===================================================================
--- trunk/usr.sbin/rtadvd/dump.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/dump.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $FreeBSD: src/usr.sbin/rtadvd/dump.c,v 1.12 2003/08/15 19:13:53 ume Exp $ */
/* $KAME: dump.c,v 1.32 2003/05/19 09:46:50 keiichi Exp $ */
Modified: trunk/usr.sbin/rtadvd/dump.h
===================================================================
--- trunk/usr.sbin/rtadvd/dump.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/dump.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $FreeBSD: src/usr.sbin/rtadvd/dump.h,v 1.3 2001/06/11 12:39:22 ume Exp $ */
/* $KAME: dump.h,v 1.1 2000/05/23 11:31:26 itojun Exp $ */
Modified: trunk/usr.sbin/rtadvd/if.c
===================================================================
--- trunk/usr.sbin/rtadvd/if.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/if.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/if.c 308717 2016-11-16 03:54:41Z hrs $ */
/* $KAME: if.c,v 1.17 2001/01/21 15:27:30 itojun Exp $ */
/*
@@ -115,6 +116,8 @@
{
switch (sdl->sdl_type) {
case IFT_ETHER:
+ case IFT_L2VLAN:
+ case IFT_BRIDGE:
return (ROUNDUP8(ETHER_ADDR_LEN + 2));
default:
return (0);
@@ -130,6 +133,8 @@
switch (sdl->sdl_type) {
case IFT_ETHER:
+ case IFT_L2VLAN:
+ case IFT_BRIDGE:
ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
addr = (char *)(ndopt + 1);
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
@@ -359,8 +364,7 @@
ELM_MALLOC(ifi, exit(1));
ifi->ifi_ifindex = 0;
- strncpy(ifi->ifi_ifname, ifname, sizeof(ifi->ifi_ifname)-1);
- ifi->ifi_ifname[sizeof(ifi->ifi_ifname)-1] = '\0';
+ strlcpy(ifi->ifi_ifname, ifname, sizeof(ifi->ifi_ifname));
ifi->ifi_rainfo = NULL;
ifi->ifi_state = IFI_STATE_UNCONFIGURED;
TAILQ_INSERT_TAIL(ifi_head, ifi, ifi_next);
@@ -389,13 +393,13 @@
}
/* ND flags */
memset(&nd, 0, sizeof(nd));
- strncpy(nd.ifname, ifi->ifi_ifname,
+ strlcpy(nd.ifname, ifi->ifi_ifname,
sizeof(nd.ifname));
error = ioctl(s, SIOCGIFINFO_IN6, (caddr_t)&nd);
if (error) {
close(s);
- syslog(LOG_ERR,
- "<%s> ioctl() failed.", __func__);
+ if (errno != EPFNOSUPPORT)
+ syslog(LOG_ERR, "<%s> ioctl() failed.", __func__);
return (1);
}
ifi->ifi_nd_flags = nd.ndi.flags;
@@ -518,7 +522,7 @@
if (ifi->ifi_phymtu == 0) {
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_addr.sa_family = AF_INET6;
- strncpy(ifr.ifr_name, ifi->ifi_ifname,
+ strlcpy(ifr.ifr_name, ifi->ifi_ifname,
sizeof(ifr.ifr_name));
error = ioctl(s, SIOCGIFMTU, (caddr_t)&ifr);
if (error) {
Modified: trunk/usr.sbin/rtadvd/if.h
===================================================================
--- trunk/usr.sbin/rtadvd/if.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/if.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/if.h 224144 2011-07-17 19:24:54Z hrs $ */
/* $KAME: if.h,v 1.10 2003/02/24 11:29:10 ono Exp $ */
/*
Modified: trunk/usr.sbin/rtadvd/pathnames.h
===================================================================
--- trunk/usr.sbin/rtadvd/pathnames.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/pathnames.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $KAME: pathnames.h,v 1.2 2000/05/16 13:34:13 itojun Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/pathnames.h 224144 2011-07-17 19:24:54Z hrs $ */
#define _PATH_RTADVDCONF "/etc/rtadvd.conf"
#define _PATH_RTADVDPID "/var/run/rtadvd.pid"
Modified: trunk/usr.sbin/rtadvd/rrenum.c
===================================================================
--- trunk/usr.sbin/rtadvd/rrenum.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rrenum.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/rrenum.c 253970 2013-08-05 20:13:02Z hrs $ */
/* $KAME: rrenum.c,v 1.12 2002/06/10 19:59:47 itojun Exp $ */
/*
@@ -49,6 +50,7 @@
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
+#include <time.h>
#include <syslog.h>
#include "rtadvd.h"
#include "rrenum.h"
@@ -215,7 +217,7 @@
rai = ifi->ifi_rainfo;
TAILQ_FOREACH(pfx, &rai->rai_prefix, pfx_next) {
- struct timeval now;
+ struct timespec now;
if (prefix_match(&pfx->pfx_prefix,
pfx->pfx_prefixlen, &rpm->rpm_prefix,
@@ -226,7 +228,8 @@
pfx->pfx_preflifetime =
ntohl(rpu->rpu_pltime);
if (irr->irr_rrf_decrvalid) {
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC_FAST,
+ &now);
pfx->pfx_vltimeexpire =
now.tv_sec +
pfx->pfx_validlifetime;
@@ -233,7 +236,8 @@
} else
pfx->pfx_vltimeexpire = 0;
if (irr->irr_rrf_decrprefd) {
- gettimeofday(&now, 0);
+ clock_gettime(CLOCK_MONOTONIC_FAST,
+ &now);
pfx->pfx_pltimeexpire =
now.tv_sec +
pfx->pfx_preflifetime;
@@ -325,7 +329,7 @@
if ((size_t)len < sizeof(struct rr_pco_match)) {
tooshort:
syslog(LOG_ERR, "<%s> pkt too short. left len = %d. "
- "gabage at end of pkt?", __func__, len);
+ "garbage at end of pkt?", __func__, len);
return (1);
}
rpmlen = rpm->rpm_len << 3;
Modified: trunk/usr.sbin/rtadvd/rrenum.h
===================================================================
--- trunk/usr.sbin/rtadvd/rrenum.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rrenum.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/rrenum.h 222732 2011-06-06 03:06:43Z hrs $ */
/* $KAME: rrenum.h,v 1.3 2001/01/21 15:37:14 itojun Exp $ */
/*
Modified: trunk/usr.sbin/rtadvd/rtadvd.8
===================================================================
--- trunk/usr.sbin/rtadvd/rtadvd.8 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rtadvd.8 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $KAME: rtadvd.8,v 1.24 2002/05/31 16:16:08 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/rtadvd/rtadvd.8 247270 2013-02-25 16:47:09Z des $
.\"
.Dd February 25, 2013
.Dt RTADVD 8
Property changes on: trunk/usr.sbin/rtadvd/rtadvd.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/rtadvd/rtadvd.c
===================================================================
--- trunk/usr.sbin/rtadvd/rtadvd.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rtadvd.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/rtadvd.c 290149 2015-10-29 16:53:34Z delphij $ */
/* $KAME: rtadvd.c,v 1.82 2003/08/05 12:34:23 itojun Exp $ */
/*
@@ -35,7 +36,6 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/uio.h>
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
@@ -95,7 +95,7 @@
static const char *pidfilename = _PATH_RTADVDPID;
const char *conffile = _PATH_RTADVDCONF;
static struct pidfh *pfh;
-int dflag = 0, sflag = 0;
+static int dflag, sflag;
static int wait_shutdown;
#define PFD_RAWSOCK 0
@@ -139,7 +139,7 @@
#define NDOPT_FLAG_RDNSS (1 << 5)
#define NDOPT_FLAG_DNSSL (1 << 6)
-uint32_t ndopt_flags[] = {
+static uint32_t ndopt_flags[] = {
[ND_OPT_SOURCE_LINKADDR] = NDOPT_FLAG_SRCLINKADDR,
[ND_OPT_TARGET_LINKADDR] = NDOPT_FLAG_TGTLINKADDR,
[ND_OPT_PREFIX_INFORMATION] = NDOPT_FLAG_PREFIXINFO,
@@ -179,7 +179,7 @@
main(int argc, char *argv[])
{
struct pollfd set[PFD_MAX];
- struct timeval *timeout;
+ struct timespec *timeout;
int i, ch;
int fflag = 0, logopt;
int error;
@@ -243,14 +243,6 @@
/* timer initialization */
rtadvd_timer_init();
-#ifndef HAVE_ARC4RANDOM
- /* random value initialization */
-#ifdef __FreeBSD__
- srandomdev();
-#else
- srandom((unsigned long)time(NULL));
-#endif
-#endif
pfh = pidfile_open(pidfilename, 0600, &otherpid);
if (pfh == NULL) {
if (errno == EEXIST)
@@ -331,7 +323,7 @@
"<%s> set timer to %ld:%ld. waiting for "
"inputs or timeout", __func__,
(long int)timeout->tv_sec,
- (long int)timeout->tv_usec);
+ (long int)timeout->tv_nsec / 1000);
} else {
syslog(LOG_DEBUG,
"<%s> there's no timer. waiting for inputs",
@@ -339,7 +331,7 @@
}
if ((i = poll(set, sizeof(set)/sizeof(set[0]),
timeout ? (timeout->tv_sec * 1000 +
- timeout->tv_usec / 1000) : INFTIM)) < 0) {
+ timeout->tv_nsec / 1000 / 1000) : INFTIM)) < 0) {
/* EINTR would occur if a signal was delivered */
if (errno != EINTR)
@@ -432,7 +424,7 @@
if (ifi->ifi_ra_timer == NULL)
continue;
if (ifi->ifi_ra_lastsent.tv_sec == 0 &&
- ifi->ifi_ra_lastsent.tv_usec == 0 &&
+ ifi->ifi_ra_lastsent.tv_nsec == 0 &&
ifi->ifi_ra_timer != NULL) {
/*
* When RA configured but never sent,
@@ -849,7 +841,7 @@
*/
if (!IN6_IS_ADDR_LINKLOCAL(&rcvfrom.sin6_addr)) {
syslog(LOG_NOTICE,
- "RA witn non-linklocal source address "
+ "RA with non-linklocal source address "
"received from %s on %s",
inet_ntop(AF_INET6, &rcvfrom.sin6_addr,
ntopbuf, sizeof(ntopbuf)),
@@ -1006,7 +998,7 @@
set_short_delay(struct ifinfo *ifi)
{
long delay; /* must not be greater than 1000000 */
- struct timeval interval, now, min_delay, tm_tmp, *rest;
+ struct timespec interval, now, min_delay, tm_tmp, *rest;
if (ifi->ifi_ra_timer == NULL)
return;
@@ -1017,15 +1009,11 @@
* delay and send the advertisement at the
* already-scheduled time. RFC 4861 6.2.6
*/
-#ifdef HAVE_ARC4RANDOM
delay = arc4random_uniform(MAX_RA_DELAY_TIME);
-#else
- delay = random() % MAX_RA_DELAY_TIME;
-#endif
interval.tv_sec = 0;
- interval.tv_usec = delay;
+ interval.tv_nsec = delay * 1000;
rest = rtadvd_timer_rest(ifi->ifi_ra_timer);
- if (TIMEVAL_LT(rest, &interval)) {
+ if (TS_CMP(rest, &interval, <)) {
syslog(LOG_DEBUG, "<%s> random delay is larger than "
"the rest of the current timer", __func__);
interval = *rest;
@@ -1038,13 +1026,13 @@
* MIN_DELAY_BETWEEN_RAS plus the random value after the
* previous advertisement was sent.
*/
- gettimeofday(&now, NULL);
- TIMEVAL_SUB(&now, &ifi->ifi_ra_lastsent, &tm_tmp);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ TS_SUB(&now, &ifi->ifi_ra_lastsent, &tm_tmp);
min_delay.tv_sec = MIN_DELAY_BETWEEN_RAS;
- min_delay.tv_usec = 0;
- if (TIMEVAL_LT(&tm_tmp, &min_delay)) {
- TIMEVAL_SUB(&min_delay, &tm_tmp, &min_delay);
- TIMEVAL_ADD(&min_delay, &interval, &interval);
+ min_delay.tv_nsec = 0;
+ if (TS_CMP(&tm_tmp, &min_delay, <)) {
+ TS_SUB(&min_delay, &tm_tmp, &min_delay);
+ TS_ADD(&min_delay, &interval, &interval);
}
rtadvd_set_timer(&interval, ifi->ifi_ra_timer);
}
@@ -1231,6 +1219,12 @@
return;
}
+static uint32_t
+udiff(uint32_t u, uint32_t v)
+{
+ return (u >= v ? u - v : v - u);
+}
+
/* return a non-zero value if the received prefix is inconsitent with ours */
static int
prefix_check(struct nd_opt_prefix_info *pinfo,
@@ -1242,7 +1236,7 @@
int inconsistent = 0;
char ntopbuf[INET6_ADDRSTRLEN];
char prefixbuf[INET6_ADDRSTRLEN];
- struct timeval now;
+ struct timespec now;
#if 0 /* impossible */
if (pinfo->nd_opt_pi_type != ND_OPT_PREFIX_INFORMATION)
@@ -1285,11 +1279,11 @@
* XXX: can we really expect that all routers on the link
* have synchronized clocks?
*/
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
preferred_time += now.tv_sec;
if (!pfx->pfx_timer && rai->rai_clockskew &&
- abs(preferred_time - pfx->pfx_pltimeexpire) > rai->rai_clockskew) {
+ udiff(preferred_time, pfx->pfx_pltimeexpire) > rai->rai_clockskew) {
syslog(LOG_INFO,
"<%s> preferred lifetime for %s/%d"
" (decr. in real time) inconsistent on %s:"
@@ -1318,11 +1312,11 @@
valid_time = ntohl(pinfo->nd_opt_pi_valid_time);
if (pfx->pfx_vltimeexpire) {
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
valid_time += now.tv_sec;
if (!pfx->pfx_timer && rai->rai_clockskew &&
- abs(valid_time - pfx->pfx_vltimeexpire) > rai->rai_clockskew) {
+ udiff(valid_time, pfx->pfx_vltimeexpire) > rai->rai_clockskew) {
syslog(LOG_INFO,
"<%s> valid lifetime for %s/%d"
" (decr. in real time) inconsistent on %s:"
@@ -1637,7 +1631,12 @@
if_indextoifinfo(int idx)
{
struct ifinfo *ifi;
+ char *name, name0[IFNAMSIZ];
+ /* Check if the interface has a valid name or not. */
+ if (if_indextoname(idx, name0) == NULL)
+ return (NULL);
+
TAILQ_FOREACH(ifi, &ifilist, ifi_next) {
if (ifi->ifi_ifindex == idx)
return (ifi);
@@ -1779,7 +1778,7 @@
}
/* update timestamp */
- gettimeofday(&ifi->ifi_ra_lastsent, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &ifi->ifi_ra_lastsent);
/* update counter */
ifi->ifi_rs_waitcount = 0;
@@ -1794,7 +1793,7 @@
ifi->ifi_burstcount--;
if (ifi->ifi_burstcount == 0) {
if (ifi->ifi_rainfo == ifi->ifi_rainfo_trans) {
- /* Inital burst finished. */
+ /* Initial burst finished. */
if (ifi->ifi_rainfo_trans != NULL)
ifi->ifi_rainfo_trans = NULL;
}
@@ -1861,7 +1860,7 @@
/* update RA timer */
void
-ra_timer_update(void *arg, struct timeval *tm)
+ra_timer_update(void *arg, struct timespec *tm)
{
uint16_t interval;
struct rainfo *rai;
@@ -1884,13 +1883,8 @@
* MaxRtrAdvInterval (RFC4861 6.2.4).
*/
interval = rai->rai_mininterval;
-#ifdef HAVE_ARC4RANDOM
interval += arc4random_uniform(rai->rai_maxinterval -
rai->rai_mininterval);
-#else
- interval += random() % (rai->rai_maxinterval -
- rai->rai_mininterval);
-#endif
break;
case IFI_STATE_TRANSITIVE:
/*
@@ -1911,12 +1905,12 @@
}
tm->tv_sec = interval;
- tm->tv_usec = 0;
+ tm->tv_nsec = 0;
syslog(LOG_DEBUG,
"<%s> RA timer on %s is set to %ld:%ld",
__func__, ifi->ifi_ifname,
- (long int)tm->tv_sec, (long int)tm->tv_usec);
+ (long int)tm->tv_sec, (long int)tm->tv_nsec / 1000);
return;
}
Modified: trunk/usr.sbin/rtadvd/rtadvd.conf.5
===================================================================
--- trunk/usr.sbin/rtadvd/rtadvd.conf.5 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rtadvd.conf.5 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $KAME: rtadvd.conf.5,v 1.50 2005/01/14 05:30:59 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/rtadvd/rtadvd.conf.5 233522 2012-03-26 21:22:53Z joel $
.\"
.Dd June 4, 2011
.Dt RTADVD.CONF 5
@@ -449,7 +450,7 @@
overrides the router lifetime parameter for the
.Li ne0
interface.
-.Bd -literal -offset
+.Bd -literal -offset indent
ne0:\\
:rltime#0:
.Ed
@@ -461,7 +462,7 @@
.Fl s
option to
.Xr rtadvd 8 .
-.Bd -literal -offset
+.Bd -literal -offset indent
ef0:\\
:addr="2001:db8:ffff:1000::":prefixlen#64:
.Ed
@@ -470,7 +471,7 @@
.Li wlan0
interface and adds two DNS servers and a DNS domain search options
using the default option lifetime values.
-.Bd -literal -offset
+.Bd -literal -offset indent
wlan0:\\
:addr="2001:db8:ffff:1000::":prefixlen#64:\\
:rdnss="2001:db8:ffff::10,2001:db8:ffff::2:43":\\
@@ -480,7 +481,7 @@
The following example presents the default values in an explicit manner.
The configuration is provided just for reference purposes;
YOU DO NOT NEED TO HAVE IT AT ALL.
-.Bd -literal -offset
+.Bd -literal -offset indent
default:\\
:chlim#64:raflags#0:rltime#1800:rtime#0:retrans#0:\\
:pinfoflags="la":vltime#2592000:pltime#604800:mtu#0:
Property changes on: trunk/usr.sbin/rtadvd/rtadvd.conf.5
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/rtadvd/rtadvd.h
===================================================================
--- trunk/usr.sbin/rtadvd/rtadvd.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/rtadvd.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/rtadvd.h 253970 2013-08-05 20:13:02Z hrs $ */
/* $KAME: rtadvd.h,v 1.26 2003/08/05 12:34:23 itojun Exp $ */
/*
@@ -270,7 +271,7 @@
uint32_t ifi_burstinterval;
struct rtadvd_timer *ifi_ra_timer;
/* timestamp when the latest RA was sent */
- struct timeval ifi_ra_lastsent;
+ struct timespec ifi_ra_lastsent;
uint16_t ifi_rs_waitcount;
/* statistics */
@@ -286,7 +287,7 @@
extern char *mcastif;
struct rtadvd_timer *ra_timeout(void *);
-void ra_timer_update(void *, struct timeval *);
+void ra_timer_update(void *, struct timespec *);
void ra_output(struct ifinfo *);
int prefix_match(struct in6_addr *, int,
Modified: trunk/usr.sbin/rtadvd/timer.c
===================================================================
--- trunk/usr.sbin/rtadvd/timer.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/timer.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/timer.c 253995 2013-08-06 15:49:18Z hrs $ */
/* $KAME: timer.c,v 1.9 2002/06/10 19:59:47 itojun Exp $ */
/*
@@ -31,7 +32,6 @@
* SUCH DAMAGE.
*/
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/socket.h>
@@ -44,6 +44,7 @@
#include <stdlib.h>
#include <string.h>
#include <search.h>
+#include <time.h>
#include <netdb.h>
#include "rtadvd.h"
@@ -52,13 +53,15 @@
struct rtadvd_timer_head_t ra_timer =
TAILQ_HEAD_INITIALIZER(ra_timer);
-static struct timeval tm_limit = {0x7fffffff, 0x7fffffff};
-static struct timeval tm_max;
+static struct timespec tm_limit;
+static struct timespec tm_max;
void
rtadvd_timer_init(void)
{
-
+ /* Generate maximum time in timespec. */
+ tm_limit.tv_sec = (-1) & ~((time_t)1 << ((sizeof(tm_max.tv_sec) * 8) - 1));
+ tm_limit.tv_nsec = (-1) & ~((long)1 << ((sizeof(tm_max.tv_nsec) * 8) - 1));
tm_max = tm_limit;
TAILQ_INIT(&ra_timer);
}
@@ -102,7 +105,7 @@
struct rtadvd_timer *
rtadvd_add_timer(struct rtadvd_timer *(*timeout)(void *),
- void (*update)(void *, struct timeval *),
+ void (*update)(void *, struct timespec *),
void *timeodata, void *updatedata)
{
struct rtadvd_timer *rat;
@@ -149,48 +152,48 @@
* call the expire function for the timer and update the timer.
* Return the next interval for select() call.
*/
-struct timeval *
+struct timespec *
rtadvd_check_timer(void)
{
- static struct timeval returnval;
- struct timeval now;
+ static struct timespec returnval;
+ struct timespec now;
struct rtadvd_timer *rat;
- gettimeofday(&now, NULL);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
tm_max = tm_limit;
TAILQ_FOREACH(rat, &ra_timer, rat_next) {
- if (TIMEVAL_LEQ(&rat->rat_tm, &now)) {
+ if (TS_CMP(&rat->rat_tm, &now, <=)) {
if (((*rat->rat_expire)(rat->rat_expire_data) == NULL))
continue; /* the timer was removed */
if (rat->rat_update)
(*rat->rat_update)(rat->rat_update_data, &rat->rat_tm);
- TIMEVAL_ADD(&rat->rat_tm, &now, &rat->rat_tm);
+ TS_ADD(&rat->rat_tm, &now, &rat->rat_tm);
}
- if (TIMEVAL_LT(&rat->rat_tm, &tm_max))
+ if (TS_CMP(&rat->rat_tm, &tm_max, <))
tm_max = rat->rat_tm;
}
- if (TIMEVAL_EQUAL(&tm_max, &tm_limit)) {
+ if (TS_CMP(&tm_max, &tm_limit, ==)) {
/* no need to timeout */
return (NULL);
- } else if (TIMEVAL_LT(&tm_max, &now)) {
+ } else if (TS_CMP(&tm_max, &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
- TIMEVAL_SUB(&tm_max, &now, &returnval);
+ TS_SUB(&tm_max, &now, &returnval);
return (&returnval);
}
void
-rtadvd_set_timer(struct timeval *tm, struct rtadvd_timer *rat)
+rtadvd_set_timer(struct timespec *tm, struct rtadvd_timer *rat)
{
- struct timeval now;
+ struct timespec now;
/* reset the timer */
- gettimeofday(&now, NULL);
- TIMEVAL_ADD(&now, tm, &rat->rat_tm);
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ TS_ADD(&now, tm, &rat->rat_tm);
/* update the next expiration time */
- if (TIMEVAL_LT(&rat->rat_tm, &tm_max))
+ if (TS_CMP(&rat->rat_tm, &tm_max, <))
tm_max = rat->rat_tm;
return;
Modified: trunk/usr.sbin/rtadvd/timer.h
===================================================================
--- trunk/usr.sbin/rtadvd/timer.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/timer.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/timer.h 253970 2013-08-05 20:13:02Z hrs $ */
/* $KAME: timer.h,v 1.5 2002/05/31 13:30:38 jinmei Exp $ */
/*
@@ -35,10 +36,10 @@
TAILQ_ENTRY(rtadvd_timer) rat_next;
struct rainfo *rat_rai;
- struct timeval rat_tm;
+ struct timespec rat_tm;
struct rtadvd_timer *(*rat_expire)(void *);
void *rat_expire_data;
- void (*rat_update)(void *, struct timeval *);
+ void (*rat_update)(void *, struct timespec *);
void *rat_update_data;
};
@@ -45,8 +46,8 @@
void rtadvd_timer_init(void);
void rtadvd_update_timeout_handler(void);
struct rtadvd_timer *rtadvd_add_timer(struct rtadvd_timer *(*)(void *),
- void (*)(void *, struct timeval *), void *, void *);
-void rtadvd_set_timer(struct timeval *,
+ void (*)(void *, struct timespec *), void *, void *);
+void rtadvd_set_timer(struct timespec *,
struct rtadvd_timer *);
void rtadvd_remove_timer(struct rtadvd_timer *);
-struct timeval *rtadvd_check_timer(void);
+struct timespec *rtadvd_check_timer(void);
Modified: trunk/usr.sbin/rtadvd/timer_subr.c
===================================================================
--- trunk/usr.sbin/rtadvd/timer_subr.c 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/timer_subr.c 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/timer_subr.c 253970 2013-08-05 20:13:02Z hrs $ */
/* $KAME: timer.c,v 1.9 2002/06/10 19:59:47 itojun Exp $ */
/*
@@ -30,69 +31,34 @@
* SUCH DAMAGE.
*/
-#include <sys/time.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <syslog.h>
#include <stdio.h>
#include <inttypes.h>
+#include <time.h>
#include "timer.h"
#include "timer_subr.h"
-struct timeval *
+struct timespec *
rtadvd_timer_rest(struct rtadvd_timer *rat)
{
- static struct timeval returnval, now;
+ static struct timespec returnval, now;
- gettimeofday(&now, NULL);
- if (TIMEVAL_LEQ(&rat->rat_tm, &now)) {
+ clock_gettime(CLOCK_MONOTONIC_FAST, &now);
+ if (TS_CMP(&rat->rat_tm, &now, <=)) {
syslog(LOG_DEBUG,
"<%s> a timer must be expired, but not yet",
__func__);
- returnval.tv_sec = returnval.tv_usec = 0;
+ returnval.tv_sec = returnval.tv_nsec = 0;
}
else
- TIMEVAL_SUB(&rat->rat_tm, &now, &returnval);
+ TS_SUB(&rat->rat_tm, &now, &returnval);
return (&returnval);
}
-/* result = a + b */
-void
-TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
-{
- long l;
-
- if ((l = a->tv_usec + b->tv_usec) < MILLION) {
- result->tv_usec = l;
- result->tv_sec = a->tv_sec + b->tv_sec;
- }
- else {
- result->tv_usec = l - MILLION;
- result->tv_sec = a->tv_sec + b->tv_sec + 1;
- }
-}
-
-/*
- * result = a - b
- * XXX: this function assumes that a >= b.
- */
-void
-TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
-{
- long l;
-
- if ((l = a->tv_usec - b->tv_usec) >= 0) {
- result->tv_usec = l;
- result->tv_sec = a->tv_sec - b->tv_sec;
- }
- else {
- result->tv_usec = MILLION + l;
- result->tv_sec = a->tv_sec - b->tv_sec - 1;
- }
-}
-
char *
sec2str(uint32_t s, char *buf)
{
Modified: trunk/usr.sbin/rtadvd/timer_subr.h
===================================================================
--- trunk/usr.sbin/rtadvd/timer_subr.h 2018-06-03 20:02:28 UTC (rev 10340)
+++ trunk/usr.sbin/rtadvd/timer_subr.h 2018-06-03 20:04:50 UTC (rev 10341)
@@ -1,4 +1,5 @@
-/* $MidnightBSD$ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/rtadvd/timer_subr.h 253970 2013-08-05 20:13:02Z hrs $ */
/* $KAME: timer.h,v 1.5 2002/05/31 13:30:38 jinmei Exp $ */
/*
@@ -31,27 +32,29 @@
*/
#define SSBUFLEN 1024
-#define MILLION 1000000
-/* a < b */
-#define TIMEVAL_LT(a, b) \
- (((a)->tv_sec < (b)->tv_sec) || \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec < (b)->tv_usec)))
+#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)
-/* a <= b */
-#define TIMEVAL_LEQ(a, b) \
- (((a)->tv_sec < (b)->tv_sec) || \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec <= (b)->tv_usec)))
-
-#define TIMEVAL_EQUAL(a,b) \
- (((a)->tv_sec == (b)->tv_sec) && \
- ((a)->tv_usec == (b)->tv_usec))
-
-struct timeval *rtadvd_timer_rest(struct rtadvd_timer *);
-void TIMEVAL_ADD(struct timeval *, struct timeval *,
- struct timeval *);
-void TIMEVAL_SUB(struct timeval *, struct timeval *,
- struct timeval *);
+struct timespec *rtadvd_timer_rest(struct rtadvd_timer *);
char *sec2str(uint32_t, char *buf);
More information about the Midnightbsd-cvs
mailing list