Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin rtsol: Throw IPv6 router solicitation to request autoco...



details:   https://anonhg.NetBSD.org/src/rev/225110b5271a
branches:  trunk
changeset: 474252:225110b5271a
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Jul 02 08:28:04 1999 +0000

description:
rtsol: Throw IPv6 router solicitation to request autoconfiguration
(to be used on end host).

diffstat:

 sbin/Makefile       |    4 +-
 sbin/rtsol/Makefile |   10 +
 sbin/rtsol/rtsol.8  |   95 ++++++++++
 sbin/rtsol/rtsol.c  |  466 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 573 insertions(+), 2 deletions(-)

diffs (truncated from 600 to 300 lines):

diff -r b1f0b859347e -r 225110b5271a sbin/Makefile
--- a/sbin/Makefile     Fri Jul 02 08:07:40 1999 +0000
+++ b/sbin/Makefile     Fri Jul 02 08:28:04 1999 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.58 1999/07/01 19:59:59 itojun Exp $
+#      $NetBSD: Makefile,v 1.59 1999/07/02 08:28:04 itojun Exp $
 #      @(#)Makefile    8.5 (Berkeley) 3/31/94
 
 # Not ported: XNSrouted enpload scsiformat startslip
@@ -29,6 +29,6 @@
 SUBDIR+= mount_union
 
 # IPv6
-SUBDIR+= ping6
+SUBDIR+= ping6 rtsol
 
 .include <bsd.subdir.mk>
diff -r b1f0b859347e -r 225110b5271a sbin/rtsol/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/rtsol/Makefile       Fri Jul 02 08:28:04 1999 +0000
@@ -0,0 +1,10 @@
+# $NetBSD: Makefile,v 1.1 1999/07/02 08:28:04 itojun Exp $
+
+PROG=  rtsol
+
+CPPFLAGS+=-DADVAPI=1
+CPPFLAGS+=-DINET6
+
+MAN=   rtsol.8
+
+.include <bsd.prog.mk>
diff -r b1f0b859347e -r 225110b5271a sbin/rtsol/rtsol.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/rtsol/rtsol.8        Fri Jul 02 08:28:04 1999 +0000
@@ -0,0 +1,95 @@
+.\" 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:
+.\" 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.
+.\"
+.\"     $Id: rtsol.8,v 1.1 1999/07/02 08:28:04 itojun Exp $
+.\"
+.Dd May 17, 1998
+.Dt RTSOL 8
+.Os
+.\"
+.Sh NAME
+.Nm rtsol
+.Nd send router solicitation
+.\"
+.Sh SYNOPSIS
+.Nm
+.Op Fl nv
+.Ar interface
+.\"
+.Sh DESCRIPTION
+.Nm Rtsol
+sends router solicitation packet to the specified
+.Ar interface .
+If there is any router on the network, the router may respond by
+router advertisement packet.
+Router advertisement packet contains information about the network,
+the link-local address of the router, and so forth.
+The kernel will install the new routing information and address prefix
+for the
+.Ar interface ,
+according to the information.
+.Pp
+.Nm
+implements some quickhack code for notebook computers.
+.Fl n
+disables the behavior
+.Pq the flag stands for no tricks .
+.Pp
+If
+.Fl v 
+is specified,
+.Nm
+will generate more messages.
+This is mostly for debugging.
+.Pp
+Router advertisement packet will be processed only if the
+node is configured as a host, not a router.
+To accept router advertisement packet,
+.Xr sysctl 8
+variables must be set as follows:
+.Bd -literal -offset
+# sysctl -w net.inet6.ip6.forwarding=0
+# sysctl -w net.inet6.ip6.accept_rtadv=1
+.Ed
+.Pp
+Typically this is done in system startup scripts, such as
+.Xr rc 8 .
+.\"
+.Sh RETURN VALUES
+The program exits with 0 on success, non-zero on failures.
+.\"
+.Sh SEE ALSO
+.Xr rtadvd 8 ,
+.Xr rtsold 8 ,
+.Xr sysctl 8
+.\"
+.Sh HISTORY
+The
+.Nm
+command first appeared in WIDE Hydrangea IPv6 protocol stack kit.
+.\" .Sh BUGS
+.\" (to be written)
diff -r b1f0b859347e -r 225110b5271a sbin/rtsol/rtsol.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sbin/rtsol/rtsol.c        Fri Jul 02 08:28:04 1999 +0000
@@ -0,0 +1,466 @@
+/*
+ * 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:
+ * 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>
+#ifdef ADVAPI
+#include <sys/uio.h>
+#endif
+#include <sys/ioctl.h>
+
+#include <net/if.h>
+#if defined(__FreeBSD__) && __FreeBSD__ >= 3
+#include <net/if_var.h>
+#endif /* __FreeBSD__ >= 3 */
+#include <netinet/in.h>
+#include <netinet/ip6.h>
+#include <netinet/icmp6.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <sys/sysctl.h>
+#include <netdb.h>
+#include <netinet6/in6.h>
+#include <netinet6/in6_var.h>
+#include <netinet6/nd6.h>
+
+#define ALLROUTER      "ff02::2"
+
+int main __P((int, char **));
+void usage __P((void));
+int sendit __P((int, char *, int, struct sockaddr_in6 *, int));
+int interface_down __P((char *));
+int interface_up __P((char *));
+static int getifflag6 __P((char *, int *));
+static int getdadcount __P((void));
+
+static int trick = 1;
+static int verbose = 0;
+#define vmsg(x)                { if (verbose) fprintf x; }
+
+extern char *optarg;
+extern int optind;
+
+int
+main(argc, argv)
+       int argc;
+       char *argv[];
+{
+       struct sockaddr_in6 to;
+       struct icmp6_hdr *icp;
+       u_int hlim = 255;
+       u_char outpack[sizeof(struct icmp6_hdr)];
+       u_short index;
+       int s, i, cc = sizeof(struct icmp6_hdr);
+       int opt;
+       fd_set fdset;
+       struct timeval timeout;
+       int rtsol_retry = MAX_RTR_SOLICITATIONS;
+       
+       while ((opt = getopt(argc, argv, "nv")) != EOF) {
+               switch (opt) {
+               case 'n':
+                       trick = 0;
+                       break;
+               case 'v':
+                       verbose++;
+                       break;
+               default:
+                       usage();
+                       /*NOTREACHED*/
+               }
+       }
+       argc -= optind;
+       argv += optind;
+       if (argc != 1) {
+               usage();
+               /*NOTREACHED*/
+       }
+
+       index = (u_short)if_nametoindex(argv[0]);
+       if (index == 0) {
+               errx(1, "invalid interface %s", argv[0]);
+               /*NOTREACHED*/
+       }
+
+       if (trick) {
+               /*
+                * Notebook hack:
+                * It looks that, most of the pccard drivers do not reset
+                * multicast packet filter properly on suspend/resume session.
+                * bring interface down, then up, to initialize it properly.
+                */
+               if (interface_down(argv[0]) < 0)
+                       err(1, "interface state could not be changed");
+               vmsg((stderr, "a bit of delay...\n"));
+               usleep(500 * 1000);     /* 0.5s */
+       }
+
+       if (interface_up(argv[0]) < 0)
+               err(1, "interface not ready");
+
+    {
+       struct addrinfo hints, *res;
+       int error;
+
+       memset(&hints, 0, sizeof(hints));
+       hints.ai_family = AF_INET6;
+       error = getaddrinfo(ALLROUTER, NULL, &hints, &res);
+       if (error) {
+               errx(1, "getaddrinfo: %s", gai_strerror(error));
+               /*NOTREACHED*/
+       }
+       memcpy(&to, res->ai_addr, res->ai_addrlen);
+    }
+       
+       if ((s = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6)) < 0)
+               err(1, "socket");
+
+       if (setsockopt(s, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &hlim,
+                       sizeof(hlim)) == -1)
+               err(1, "setsockopt(IPV6_MULTICAST_HOPS)");
+#ifdef ICMP6_FILTER
+    {
+       struct icmp6_filter filt;
+       ICMP6_FILTER_SETBLOCKALL(&filt);
+       ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
+       if (setsockopt(s, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
+                       sizeof(filt)) == -1)
+               err(1, "setsockopt(ICMP6_FILTER)");
+    }
+#endif
+       
+       /* fill ICMP header */
+       icp = (struct icmp6_hdr *)outpack;
+       icp->icmp6_type = ND_ROUTER_SOLICIT;
+       icp->icmp6_code = 0;



Home | Main Index | Thread Index | Old Index