summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rtsold
diff options
context:
space:
mode:
authorkris <kris@FreeBSD.org>2000-10-06 23:46:52 +0000
committerkris <kris@FreeBSD.org>2000-10-06 23:46:52 +0000
commit44c3d480b472d6936e2fdf0b16c99e14a757266b (patch)
treedf9371dfa492543ed50950c7db8e28f45326e5bc /usr.sbin/rtsold
parenta5984fa40eeb4f40d06d1f1266a995af112d7ee5 (diff)
downloadFreeBSD-src-44c3d480b472d6936e2fdf0b16c99e14a757266b.zip
FreeBSD-src-44c3d480b472d6936e2fdf0b16c99e14a757266b.tar.gz
Sync with KAME. Format string auditing, and add -a flag to autoprobe
interfaces. Obtained from: KAME
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r--usr.sbin/rtsold/dump.c4
-rw-r--r--usr.sbin/rtsold/if.c3
-rw-r--r--usr.sbin/rtsold/probe.c3
-rw-r--r--usr.sbin/rtsold/rtsol.c3
-rw-r--r--usr.sbin/rtsold/rtsold.844
-rw-r--r--usr.sbin/rtsold/rtsold.c178
-rw-r--r--usr.sbin/rtsold/rtsold.h9
7 files changed, 195 insertions, 49 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c
index 43badd5..ce55ddd 100644
--- a/usr.sbin/rtsold/dump.c
+++ b/usr.sbin/rtsold/dump.c
@@ -1,3 +1,5 @@
+/* $KAME: dump.c,v 1.7 2000/08/13 06:14:59 itojun Exp $ */
+
/*
* Copyright (C) 1999 WIDE Project.
* All rights reserved.
@@ -98,7 +100,7 @@ rtsold_dump_file(dumpfile)
char *dumpfile;
{
if ((fp = fopen(dumpfile, "w")) == NULL) {
- warnmsg(LOG_WARNING, __FUNCTION__, "open a dump file(%s)",
+ warnmsg(LOG_WARNING, __FUNCTION__, "open a dump file(%s): %s",
dumpfile, strerror(errno));
return;
}
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index 6bf8105..35f16d2 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -1,3 +1,5 @@
+/* $KAME$ */
+
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
@@ -33,6 +35,7 @@
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <sys/ioctl.h>
+#include <sys/queue.h>
#include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c
index 64eabcf..3b29cb4 100644
--- a/usr.sbin/rtsold/probe.c
+++ b/usr.sbin/rtsold/probe.c
@@ -1,3 +1,5 @@
+/* $KAME$ */
+
/*
* Copyright (C) 1998 WIDE Project.
* All rights reserved.
@@ -34,6 +36,7 @@
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/uio.h>
+#include <sys/queue.h>
#include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c
index 41003ca..7f27aef 100644
--- a/usr.sbin/rtsold/rtsol.c
+++ b/usr.sbin/rtsold/rtsol.c
@@ -1,3 +1,5 @@
+/* $KAME$ */
+
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
@@ -33,6 +35,7 @@
#include <sys/socket.h>
#include <sys/uio.h>
#include <sys/time.h>
+#include <sys/queue.h>
#include <net/if.h>
#include <net/route.h>
diff --git a/usr.sbin/rtsold/rtsold.8 b/usr.sbin/rtsold/rtsold.8
index d1a50b1..f5e62e4 100644
--- a/usr.sbin/rtsold/rtsold.8
+++ b/usr.sbin/rtsold/rtsold.8
@@ -1,6 +1,8 @@
+.\" $KAME: rtsold.8,v 1.14 2000/08/13 18:06:39 itojun Exp $
+.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
.\" All rights reserved.
-.\"
+.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
@@ -12,7 +14,7 @@
.\" 3. Neither the name of the project nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
-.\"
+.\"
.\" THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -25,7 +27,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Id: rtsold.8,v 1.9 2000/07/04 14:44:38 jinmei Exp $
.\" $FreeBSD$
.\"
.Dd May 17, 1998
@@ -37,15 +38,21 @@
.Nd router solicitation daemon
.\"
.Sh SYNOPSIS
-.Nm
+.Nm rtsold
.Op Fl dDfm1
.Ar interface ...
+.Nm rtsold
+.Op Fl dDfm1
+.Fl a
.Nm rtsol
.Op Fl dD
.Ar interface ...
+.Nm rtsol
+.Op Fl dD
+.Fl a
.\"
.Sh DESCRIPTION
-.Nm Rtsold
+.Nm
is the daemon program to send ICMPv6 Router Solicitation messages
on the specified interfaces.
If a node (re)attaches to a link,
@@ -54,6 +61,11 @@ sends some Router Solicitations on the link destined to the link-local scope
all-routers multicast address to discover new routers
and to get non link-local addresses.
.Pp
+.Nm
+should be used on IPv6 host
+.Pq non-router node
+only.
+.Pp
If you invoke the program as
.Nm rtsol ,
it will transmit probes from the specified
@@ -80,7 +92,7 @@ Just after invocation of
daemon.
.It
The interface is up after a temporary interface failure.
-.Nm Rtsold
+.Nm
detects such failures by periodically probing to see if the status
of the interface is active or not.
Note that some network cards and drivers do not allow the extraction
@@ -118,10 +130,19 @@ Upon receipt of signal
.Dv SIGUSR1 ,
.Nm
will dump the current internal state into
-.Pa /var/run/rtsold.dump.
+.Pa /var/run/rtsold.dump .
.\"
.Sh OPTIONS
.Bl -tag -width indent
+.It Fl a
+Autoprobe outgoing interface.
+.Nm
+will try to find a non-loopback, non-p2p and IPv6-capable, interface.
+If
+.Nm
+finds multiple interfaces,
+.Nm
+will exit with error.
.\"
.It Fl d
Enable debugging.
@@ -190,3 +211,12 @@ may not work if you reinsert a network card.
In such a case,
.Nm
should be killed and restarted.
+.Pp
+IPv6 autoconfiguration specification assumes single interface host.
+You may see kernel error message if you try to autoconfigure a host with
+multiple interfaces.
+Also, it seems contradictory for
+.Nm
+to accept multiple
+.Ar interfaces
+in argument.
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c
index 7259c20..a2e39df 100644
--- a/usr.sbin/rtsold/rtsold.c
+++ b/usr.sbin/rtsold/rtsold.c
@@ -1,3 +1,5 @@
+/* $KAME: rtsold.c,v 1.26 2000/08/13 18:17:15 itojun Exp $ */
+
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
@@ -48,11 +50,13 @@
#include <errno.h>
#include <err.h>
#include <stdarg.h>
+#include <ifaddrs.h>
#include "rtsold.h"
struct ifinfo *iflist;
struct timeval tm_max = {0x7fffffff, 0x7fffffff};
-int dflag;
+int aflag = 0;
+int dflag = 0;
static int log_upto = 999;
static int fflag = 0;
@@ -99,6 +103,7 @@ static void TIMEVAL_SUB __P((struct timeval *a, struct timeval *b,
static void rtsold_set_dump_file __P((void));
static void usage __P((char *progname));
+static char **autoifprobe __P((void));
int
main(argc, argv)
@@ -121,35 +126,60 @@ main(argc, argv)
if (argv0 && argv0[strlen(argv0) - 1] != 'd') {
fflag = 1;
once = 1;
- opts = "dD";
+ opts = "adD";
} else
- opts = "dDfm1";
+ opts = "adDfm1";
while ((ch = getopt(argc, argv, opts)) != -1) {
- switch(ch) {
- case 'd':
- dflag = 1;
- break;
- case 'D':
- dflag = 2;
- break;
- case 'f':
- fflag = 1;
- break;
- case 'm':
- mobile_node = 1;
- break;
- case '1':
- once = 1;
- break;
- default:
- usage(argv0);
+ switch (ch) {
+ case 'a':
+ aflag = 1;
+ break;
+ case 'd':
+ dflag = 1;
+ break;
+ case 'D':
+ dflag = 2;
+ break;
+ case 'f':
+ fflag = 1;
+ break;
+ case 'm':
+ mobile_node = 1;
+ break;
+ case '1':
+ once = 1;
+ break;
+ default:
+ usage(argv0);
+ /*NOTREACHED*/
}
}
argc -= optind;
argv += optind;
- if (argc == 0)
+
+ if (aflag) {
+ int i;
+
+ if (argc != 0) {
+ usage(argv0);
+ /*NOTREACHED*/
+ }
+
+ argv = autoifprobe();
+ if (!argv) {
+ errx(1, "could not autoprobe interface");
+ /*NOTREACHED*/
+ }
+
+ for (i = 0; argv[i]; i++)
+ ;
+ argc = i;
+ }
+ if (argc == 0) {
usage(argv0);
+ /*NOTREACHED*/
+ }
/* set log level */
if (dflag == 0)
@@ -174,31 +204,44 @@ main(argc, argv)
/* warn if accept_rtadv is down */
if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV))
warnx("kernel is configured not to accept RAs");
+ /* warn if forwarding is up */
+ if (getinet6sysctl(IPV6CTL_FORWARDING))
+ warnx("kernel is configured as a router, not a host");
/* initialization to dump internal status to a file */
- if (signal(SIGUSR1, (void *)rtsold_set_dump_file) < 0)
+ if (signal(SIGUSR1, (void *)rtsold_set_dump_file) < 0) {
errx(1, "failed to set signal for dump status");
+ /*NOTREACHED*/
+ }
/*
* Open a socket for sending RS and receiving RA.
* This should be done before calling ifinit(), since the function
* uses the socket.
*/
- if ((s = sockopen()) < 0)
+ if ((s = sockopen()) < 0) {
errx(1, "failed to open a socket");
+ /*NOTREACHED*/
+ }
/* configuration per interface */
- if (ifinit())
+ if (ifinit()) {
errx(1, "failed to initilizatoin interfaces");
+ /*NOTREACHED*/
+ }
while (argc--) {
- if (ifconfig(*argv))
+ if (ifconfig(*argv)) {
errx(1, "failed to initialize %s", *argv);
+ /*NOTREACHED*/
+ }
argv++;
}
/* setup for probing default routers */
- if (probe_init())
+ if (probe_init()) {
errx(1, "failed to setup for probing routers");
+ /*NOTREACHED*/
+ }
if (!fflag)
daemon(0, 0); /* act as a daemon */
@@ -210,7 +253,7 @@ main(argc, argv)
if ((fp = fopen(pidfilename, "w")) == NULL)
warnmsg(LOG_ERR, __FUNCTION__,
- "failed to open a log file(%s)",
+ "failed to open a log file(%s): %s",
pidfilename, strerror(errno));
else {
fprintf(fp, "%d\n", pid);
@@ -432,7 +475,7 @@ rtsol_check_timer()
"state = %d", ifinfo->ifname,
ifinfo->state);
- switch(ifinfo->state) {
+ switch (ifinfo->state) {
case IFS_DOWN:
case IFS_TENTATIVE:
/* interface_up returns 0 on success */
@@ -510,8 +553,8 @@ rtsol_check_timer()
TIMEVAL_SUB(&rtsol_timer, &now, &returnval);
if (dflag > 1)
- warnmsg(LOG_DEBUG, __FUNCTION__, "New timer is %d:%08d",
- returnval.tv_sec, returnval.tv_usec);
+ warnmsg(LOG_DEBUG, __FUNCTION__, "New timer is %ld:%08ld",
+ (long)returnval.tv_sec, (long)returnval.tv_usec);
return(&returnval);
}
@@ -630,10 +673,13 @@ rtsold_set_dump_file()
static void
usage(char *progname)
{
- if (progname && progname[strlen(progname) - 1] != 'd')
- fprintf(stderr, "usage: rtsol [-dD] interfaces\n");
- else
- fprintf(stderr, "usage: rtsold [-dDfm1] interfaces\n");
+ if (progname && progname[strlen(progname) - 1] != 'd') {
+ fprintf(stderr, "usage: rtsol [-dD] interfaces...\n");
+ fprintf(stderr, "usage: rtsol [-dD] -a\n");
+ } else {
+ fprintf(stderr, "usage: rtsold [-adDfm1] interfaces...\n");
+ fprintf(stderr, "usage: rtsold [-dDfm1] -a\n");
+ }
exit(1);
}
@@ -659,7 +705,67 @@ warnmsg(priority, func, msg, va_alist)
}
} else {
snprintf(buf, sizeof(buf), "<%s> %s", func, msg);
- vsyslog(priority, buf, ap);
+ msg = buf;
+ vsyslog(priority, msg, ap);
}
va_end(ap);
}
+
+static char **
+autoifprobe()
+{
+#ifndef HAVE_GETIFADDRS
+ errx(1, "-a is not available with the configuration");
+#else
+ static char ifname[IFNAMSIZ + 1];
+ static char *argv[2];
+ struct ifaddrs *ifap, *ifa, *target;
+
+ if (getifaddrs(&ifap) != 0)
+ return NULL;
+
+ target = NULL;
+ /* find an ethernet */
+ for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
+ if ((ifa->ifa_flags & IFF_UP) == 0)
+ continue;
+ if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0)
+ continue;
+ if ((ifa->ifa_flags & IFF_LOOPBACK) != 0)
+ continue;
+ if ((ifa->ifa_flags & IFF_MULTICAST) == 0)
+ continue;
+
+ if (ifa->ifa_addr->sa_family != AF_INET6)
+ continue;
+
+ if (target && strcmp(target->ifa_name, ifa->ifa_name) == 0)
+ continue;
+
+ if (!target)
+ target = ifa;
+ else {
+ /* if we find multiple candidates, failure. */
+ if (dflag > 1)
+ warnx("multiple interfaces found");
+ target = NULL;
+ break;
+ }
+ }
+
+ if (target) {
+ strncpy(ifname, target->ifa_name, sizeof(ifname) - 1);
+ ifname[sizeof(ifname) - 1] = '\0';
+ argv[0] = ifname;
+ argv[1] = NULL;
+
+ if (dflag > 0)
+ warnx("probing %s", argv[0]);
+ }
+ freeifaddrs(ifap);
+ if (target)
+ return argv;
+ else
+ return (char **)NULL;
+#endif
+}
diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h
index f5c722b..b6eec21 100644
--- a/usr.sbin/rtsold/rtsold.h
+++ b/usr.sbin/rtsold/rtsold.h
@@ -1,3 +1,5 @@
+/* $KAME: rtsold.h,v 1.9 2000/08/13 06:15:00 itojun Exp $ */
+
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
* All rights reserved.
@@ -63,11 +65,8 @@ extern struct timeval tm_max;
extern int dflag;
struct ifinfo *find_ifinfo __P((int ifindex));
void rtsol_timer_update __P((struct ifinfo *ifinfo));
-#ifdef __STDC__
-extern void warnmsg __P((int, const char *, const char *, ...));
-#else
-extern void warnmsg __P((int, const char *, const char *, va_list));
-#endif
+extern void warnmsg __P((int, const char *, const char *, ...))
+ __attribute__((__format__(__printf__, 3, 4)));
/* if.c */
extern int ifinit __P((void));
OpenPOWER on IntegriCloud