summaryrefslogtreecommitdiffstats
path: root/usr.sbin/rtsold
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2001-06-11 12:39:29 +0000
committerume <ume@FreeBSD.org>2001-06-11 12:39:29 +0000
commit832f8d224926758a9ae0b23a6b45353e44fbc87a (patch)
treea79fc7ad2b97862c4a404f352f0211ad93a7b5f1 /usr.sbin/rtsold
parent2693854b01a52b0395a91322aa3edf926bddff38 (diff)
downloadFreeBSD-src-832f8d224926758a9ae0b23a6b45353e44fbc87a.zip
FreeBSD-src-832f8d224926758a9ae0b23a6b45353e44fbc87a.tar.gz
Sync with recent KAME.
This work was based on kame-20010528-freebsd43-snap.tgz and some critical problem after the snap was out were fixed. There are many many changes since last KAME merge. TODO: - The definitions of SADB_* in sys/net/pfkeyv2.h are still different from RFC2407/IANA assignment because of binary compatibility issue. It should be fixed under 5-CURRENT. - ip6po_m member of struct ip6_pktopts is no longer used. But, it is still there because of binary compatibility issue. It should be removed under 5-CURRENT. Reviewed by: itojun Obtained from: KAME MFC after: 3 weeks
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r--usr.sbin/rtsold/Makefile4
-rw-r--r--usr.sbin/rtsold/dump.c2
-rw-r--r--usr.sbin/rtsold/if.c9
-rw-r--r--usr.sbin/rtsold/probe.c2
-rw-r--r--usr.sbin/rtsold/rtsock.c179
-rw-r--r--usr.sbin/rtsold/rtsol.c2
-rw-r--r--usr.sbin/rtsold/rtsold.842
-rw-r--r--usr.sbin/rtsold/rtsold.c33
-rw-r--r--usr.sbin/rtsold/rtsold.h6
9 files changed, 246 insertions, 33 deletions
diff --git a/usr.sbin/rtsold/Makefile b/usr.sbin/rtsold/Makefile
index 9181ed5..a677ba5 100644
--- a/usr.sbin/rtsold/Makefile
+++ b/usr.sbin/rtsold/Makefile
@@ -14,10 +14,8 @@
# $FreeBSD$
PROG= rtsold
-SRCS= rtsold.c rtsol.c if.c probe.c dump.c
+SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
CFLAGS+=-DINET6 -DHAVE_GETIFADDRS
-LDADD= -lkvm
-DPADD= ${LIBKVM}
MAN= rtsold.8
MLINKS= rtsold.8 rtsol.8
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c
index ce55ddd..0f75971 100644
--- a/usr.sbin/rtsold/dump.c
+++ b/usr.sbin/rtsold/dump.c
@@ -1,4 +1,4 @@
-/* $KAME: dump.c,v 1.7 2000/08/13 06:14:59 itojun Exp $ */
+/* $KAME: dump.c,v 1.8 2000/10/05 22:20:39 itojun Exp $ */
/*
* Copyright (C) 1999 WIDE Project.
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index 35f16d2..4566b73 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -1,4 +1,4 @@
-/* $KAME$ */
+/* $KAME: if.c,v 1.15 2001/05/22 06:04:17 jinmei Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -218,6 +218,9 @@ lladdropt_length(struct sockaddr_dl *sdl)
{
switch(sdl->sdl_type) {
case IFT_ETHER:
+#ifdef IFT_IEEE80211
+ case IFT_IEEE80211:
+#endif
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
default:
return(0);
@@ -233,6 +236,9 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt)
switch(sdl->sdl_type) {
case IFT_ETHER:
+#ifdef IFT_IEEE80211
+ case IFT_IEEE80211:
+#endif
ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
addr = (char *)(ndopt + 1);
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
@@ -295,6 +301,7 @@ if_nametosdl(char *name)
return(NULL);
memcpy((caddr_t)ret_sdl, (caddr_t)sdl, sdl->sdl_len);
+ free(buf);
return(ret_sdl);
}
diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c
index 3b29cb4..34bb66e 100644
--- a/usr.sbin/rtsold/probe.c
+++ b/usr.sbin/rtsold/probe.c
@@ -1,4 +1,4 @@
-/* $KAME$ */
+/* $KAME: probe.c,v 1.10 2000/08/13 06:14:59 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
diff --git a/usr.sbin/rtsold/rtsock.c b/usr.sbin/rtsold/rtsock.c
new file mode 100644
index 0000000..f1c4be8
--- /dev/null
+++ b/usr.sbin/rtsold/rtsock.c
@@ -0,0 +1,179 @@
+/* $KAME: rtsock.c,v 1.3 2000/10/10 08:46:45 itojun Exp $ */
+/* $FreeBSD$ */
+
+/*
+ * Copyright (C) 2000 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:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 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
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <sys/time.h>
+#include <sys/queue.h>
+
+#include <net/if.h>
+#include <net/route.h>
+#include <net/if_dl.h>
+
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+
+#include <time.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <syslog.h>
+#include "rtsold.h"
+
+#define ROUNDUP(a, size) \
+ (((a) & ((size)-1)) ? (1 + ((a) | ((size)-1))) : (a))
+
+#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
+ ((caddr_t)(ap) + \
+ ((ap)->sa_len ? ROUNDUP((ap)->sa_len, sizeof(u_long)) \
+ : sizeof(u_long)))
+
+#ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
+static int rtsock_input_ifannounce __P((int, struct rt_msghdr *, char *));
+#endif
+
+static struct {
+ u_char type;
+ size_t minlen;
+ int (*func) __P((int, struct rt_msghdr *, char *));
+} rtsock_dispatch[] = {
+#ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
+ { RTM_IFANNOUNCE, sizeof(struct if_announcemsghdr),
+ rtsock_input_ifannounce },
+#endif
+ { 0, NULL },
+};
+
+int
+rtsock_open()
+{
+
+ return socket(PF_ROUTE, SOCK_RAW, 0);
+}
+
+int
+rtsock_input(s)
+ int s;
+{
+ ssize_t n;
+ char msg[2048];
+ char *lim, *next;
+ struct rt_msghdr *rtm;
+ int idx;
+ size_t len;
+ int ret = 0;
+ const size_t lenlim =
+ offsetof(struct rt_msghdr, rtm_msglen) + sizeof(rtm->rtm_msglen);
+
+ n = read(s, msg, sizeof(msg));
+
+ lim = msg + n;
+ for (next = msg; next < lim; next += len) {
+ rtm = (struct rt_msghdr *)next;
+ if (lim - next < lenlim)
+ break;
+ len = rtm->rtm_msglen;
+ if (len < lenlim)
+ break;
+
+ if (dflag > 1) {
+ warnmsg(LOG_INFO, __FUNCTION__,
+ "rtmsg type %d, len=%lu", rtm->rtm_type,
+ (u_long)len);
+ }
+
+ for (idx = 0; rtsock_dispatch[idx].func; idx++) {
+ if (rtm->rtm_type != rtsock_dispatch[idx].type)
+ continue;
+ if (rtm->rtm_msglen < rtsock_dispatch[idx].minlen) {
+ warnmsg(LOG_INFO, __FUNCTION__,
+ "rtmsg type %d too short!", rtm->rtm_type);
+ continue;
+ }
+
+ ret = (*rtsock_dispatch[idx].func)(s, rtm, lim);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+#ifdef RTM_IFANNOUNCE /*NetBSD 1.5 or later*/
+static int
+rtsock_input_ifannounce(s, rtm, lim)
+ int s;
+ struct rt_msghdr *rtm;
+ char *lim;
+{
+ struct if_announcemsghdr *ifan;
+ struct ifinfo *ifinfo;
+
+ ifan = (struct if_announcemsghdr *)rtm;
+ if ((char *)(ifan + 1) > lim)
+ return -1;
+
+ switch (ifan->ifan_what) {
+ case IFAN_ARRIVAL:
+ /*
+ * XXX for NetBSD 1.5, interface index will monotonically be
+ * increased as new pcmcia card gets inserted.
+ * we may be able to do a name-based interface match,
+ * and call ifreconfig() to enable the interface again.
+ */
+ warnmsg(LOG_INFO, __FUNCTION__,
+ "interface %s inserted", ifan->ifan_name);
+ break;
+ case IFAN_DEPARTURE:
+ warnmsg(LOG_WARNING, __FUNCTION__,
+ "interface %s removed", ifan->ifan_name);
+ ifinfo = find_ifinfo(ifan->ifan_index);
+ if (ifinfo) {
+ if (dflag > 1) {
+ warnmsg(LOG_INFO, __FUNCTION__,
+ "bring interface %s to DOWN state",
+ ifan->ifan_name);
+ }
+ ifinfo->state = IFS_DOWN;
+ }
+ break;
+ }
+
+ return 0;
+}
+#endif
diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c
index 7f27aef..62a73d0 100644
--- a/usr.sbin/rtsold/rtsol.c
+++ b/usr.sbin/rtsold/rtsol.c
@@ -1,4 +1,4 @@
-/* $KAME$ */
+/* $KAME: rtsol.c,v 1.11 2000/08/13 06:14:59 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
diff --git a/usr.sbin/rtsold/rtsold.8 b/usr.sbin/rtsold/rtsold.8
index 2eaae80..1cf369e 100644
--- a/usr.sbin/rtsold/rtsold.8
+++ b/usr.sbin/rtsold/rtsold.8
@@ -1,4 +1,4 @@
-.\" $KAME: rtsold.8,v 1.14 2000/08/13 18:06:39 itojun Exp $
+.\" $KAME: rtsold.8,v 1.16 2000/10/15 13:19:05 itojun Exp $
.\"
.\" Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
.\" All rights reserved.
@@ -31,7 +31,7 @@
.\"
.Dd May 17, 1998
.Dt RTSOLD 8
-.Os KAME
+.Os
.\"
.Sh NAME
.Nm rtsold
@@ -62,8 +62,8 @@ 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
+should be used on IPv6 hosts
+.Pq non-router nodes
only.
.Pp
If you invoke the program as
@@ -106,9 +106,9 @@ Every 60 seconds if the
option is specified and the
.Nm
daemon cannot get the interface status.
-This feature does not conform to IPv6 neighbor discovery
+This feature does not conform to the IPv6 neighbor discovery
specification, but is provided for mobile stations.
-Default interval for router advertisements, which is on the order of 10
+The default interval for router advertisements, which is on the order of 10
minutes, is slightly long for mobile stations.
This feature is provided
for such stations so that they can find new routers as soon as possible
@@ -117,14 +117,14 @@ when they attach to another link.
.Lp
Once
.Nm
-sends a Router Solicitation, and receives a valid Router Advertisement,
+has sent a Router Solicitation, and has received a valid Router Advertisement,
it refrains from sending additional solicitations on that interface, until
the next time one of the above events occurs.
.Lp
When sending a Router Solicitation on an interface,
.Nm
includes a Source Link-layer address option if the interface
-has its link-layer address.
+has a link-layer address.
.Pp
Upon receipt of signal
.Dv SIGUSR1 ,
@@ -137,7 +137,7 @@ will dump the current internal state into
.It Fl a
Autoprobe outgoing interface.
.Nm
-will try to find a non-loopback, non-p2p and IPv6-capable, interface.
+will try to find a non-loopback, non-point-to-point, IPv6-capable interface.
If
.Nm
finds multiple interfaces,
@@ -147,13 +147,13 @@ will exit with error.
.It Fl d
Enable debugging.
.It Fl D
-Enable more debugging including to print internal timer information.
+Enable more debugging including the printing of internal timer information.
.It Fl f
.Fl f
prevents
.Nm
from becoming a daemon (foreground mode).
-Warning messages are generated to standard error output,
+Warning messages are generated to standard error
instead of
.Xr syslog 3 .
.It Fl m
@@ -170,11 +170,15 @@ periodically sends Router Solicitation on an interface that does not support
ioctl.
.It Fl 1
Perform only one probe.
-Transmit Router Solicitation packet until valid Router Advertisement packet
-arrives all the interfaces more than once, then exit.
+Transmit Router Solicitation packets until at least one valid Router
+Advertisement packet has arrived on each
+.Ar interface ,
+then exit.
.El
.Sh RETURN VALUES
-The program exits with 0 on success, non-zero on failures.
+The
+.Nm
+program exits 0 on success, and >0 on failures.
.\"
.Sh FILES
.Bl -tag -width /var/run/rtsold.dump -compact
@@ -204,7 +208,7 @@ In some operating systems, when a PCMCIA network card is removed
and reinserted, the corresponding interface index is changed.
However,
.Nm
-does not assume such changes, and always uses the index that
+assumes such changes will not occur, and always uses the index that
it got at invocation. As a result,
.Nm
may not work if you reinsert a network card.
@@ -212,11 +216,11 @@ 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
+The IPv6 autoconfiguration specification assumes a single-interface host.
+You may see kernel error messages if you try to autoconfigure a host with
multiple interfaces.
Also, it seems contradictory for
.Nm
to accept multiple
-.Ar interfaces
-in argument.
+.Ar interface
+arguments.
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c
index a2e39df..a4bb0e4 100644
--- a/usr.sbin/rtsold/rtsold.c
+++ b/usr.sbin/rtsold/rtsold.c
@@ -1,4 +1,4 @@
-/* $KAME: rtsold.c,v 1.26 2000/08/13 18:17:15 itojun Exp $ */
+/* $KAME: rtsold.c,v 1.31 2001/05/22 06:03:06 jinmei Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -110,7 +110,7 @@ main(argc, argv)
int argc;
char *argv[];
{
- int s, ch;
+ int s, rtsock, maxfd, ch;
int once = 0;
struct timeval *timeout;
struct fd_set fdset;
@@ -223,6 +223,13 @@ main(argc, argv)
errx(1, "failed to open a socket");
/*NOTREACHED*/
}
+ maxfd = s;
+ if ((rtsock = rtsock_open()) < 0) {
+ errx(1, "failed to open a socket");
+ /*NOTREACHED*/
+ }
+ if (rtsock > maxfd)
+ maxfd = rtsock;
/* configuration per interface */
if (ifinit()) {
@@ -263,6 +270,7 @@ main(argc, argv)
FD_ZERO(&fdset);
FD_SET(s, &fdset);
+ FD_SET(rtsock, &fdset);
while (1) { /* main loop */
int e;
struct fd_set select_fd = fdset;
@@ -289,8 +297,8 @@ main(argc, argv)
if (ifi == NULL)
break;
}
-
- if ((e = select(s + 1, &select_fd, NULL, NULL, timeout)) < 1) {
+ e = select(maxfd + 1, &select_fd, NULL, NULL, timeout);
+ if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
strerror(errno));
@@ -299,7 +307,9 @@ main(argc, argv)
}
/* packet reception */
- if (FD_ISSET(s, &fdset))
+ if (FD_ISSET(rtsock, &select_fd))
+ rtsock_input(rtsock);
+ if (FD_ISSET(s, &select_fd))
rtsol_input(s);
}
/* NOTREACHED */
@@ -597,7 +607,18 @@ rtsol_timer_update(struct ifinfo *ifinfo)
ifinfo->timer.tv_usec = interval % MILLION;
break;
case IFS_PROBE:
- ifinfo->timer.tv_sec = RTR_SOLICITATION_INTERVAL;
+ if (ifinfo->probes < MAX_RTR_SOLICITATIONS)
+ ifinfo->timer.tv_sec = RTR_SOLICITATION_INTERVAL;
+ else {
+ /*
+ * After sending MAX_RTR_SOLICITATIONS solicitations,
+ * we're just waiting for possible replies; there
+ * will be no more solicatation. Thus, we change
+ * the timer value to MAX_RTR_SOLICITATION_DELAY based
+ * on RFC 2461, Section 6.3.7.
+ */
+ ifinfo->timer.tv_sec = MAX_RTR_SOLICITATION_DELAY;
+ }
break;
default:
warnmsg(LOG_ERR, __FUNCTION__,
diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h
index b6eec21..52175fa 100644
--- a/usr.sbin/rtsold/rtsold.h
+++ b/usr.sbin/rtsold/rtsold.h
@@ -1,4 +1,4 @@
-/* $KAME: rtsold.h,v 1.9 2000/08/13 06:15:00 itojun Exp $ */
+/* $KAME: rtsold.h,v 1.11 2000/10/10 06:18:04 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -89,3 +89,7 @@ extern void defrouter_probe __P((int ifindex));
/* dump.c */
extern void rtsold_dump_file __P((char *));
+
+/* rtsock.c */
+extern int rtsock_open __P((void));
+extern int rtsock_input __P((int));
OpenPOWER on IntegriCloud