sync with latest kame.

- decrease warning level on missing rtadvd.conf (actually, the file
  can be omitted)
- strict prototype
- gather stats better, emit stats on SIGUSR1 to /var/run
This commit is contained in:
itojun 2000-05-23 11:37:58 +00:00
parent e662e86225
commit e459e7617b
18 changed files with 417 additions and 76 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.2 1999/07/03 06:26:26 itojun Exp $
# $NetBSD: Makefile,v 1.3 2000/05/23 11:37:58 itojun Exp $
PROG= rtadvd
SRCS= rtadvd.c rrenum.c advcap.c if.c config.c timer.c
SRCS= rtadvd.c rrenum.c advcap.c if.c config.c timer.c dump.c
CPPFLAGS+=-DINET6
MAN= rtadvd.8 rtadvd.conf.5

View File

@ -1,4 +1,5 @@
/* $NetBSD: advcap.c,v 1.4 2000/03/13 06:16:46 itojun Exp $ */
/* $NetBSD: advcap.c,v 1.5 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: advcap.c,v 1.4 2000/05/23 11:17:40 itojun Exp $ */
/*
* Copyright (c) 1983 The Regents of the University of California.
@ -137,7 +138,7 @@ getent(bp, name, cp)
tf = open(RM = cp, O_RDONLY);
}
if (tf < 0) {
syslog(LOG_WARNING,
syslog(LOG_INFO,
"<%s> open: %s", __FUNCTION__, strerror(errno));
return (-2);
}

View File

@ -1,4 +1,5 @@
/* $NetBSD: advcap.h,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: advcap.h,v 1.3 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: advcap.h,v 1.2 2000/05/16 13:34:13 itojun Exp $ */
/*
* Copyright (C) 1994,1995 by Andrey A. Chernov, Moscow, Russia.

View File

@ -1,4 +1,5 @@
/* $NetBSD: config.c,v 1.6 2000/03/13 06:16:46 itojun Exp $ */
/* $NetBSD: config.c,v 1.7 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: config.c,v 1.12 2000/05/22 22:23:07 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -57,7 +58,7 @@
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#ifdef __NetBSD__
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <search.h>
#endif
#include <unistd.h>
@ -260,6 +261,8 @@ getconfig(intface)
/* link into chain */
insque(pfx, &tmp->prefix);
pfx->origin = PREFIX_FROM_CONFIG;
makeentry(entbuf, i, "prefixlen", added);
MAYHAVE(val, entbuf, 64);
if (val < 0 || val > 128) {
@ -438,6 +441,7 @@ get_prefix(struct rainfo *rai)
pp->preflifetime = DEF_ADVPREFERREDLIFETIME;
pp->onlinkflg = 1;
pp->autoconfflg = 1;
pp->origin = PREFIX_FROM_KERNEL;
/* link into chain */
insque(pp, &rai->prefix);
@ -493,6 +497,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
prefix->preflifetime = ipr->ipr_pltime;
prefix->onlinkflg = ipr->ipr_raf_onlink;
prefix->autoconfflg = ipr->ipr_raf_auto;
prefix->origin = PREFIX_FROM_DYNAMIC;
insque(prefix, &rai->prefix);
@ -520,7 +525,7 @@ add_prefix(struct rainfo *rai, struct in6_prefixreq *ipr)
/*
* Delete a prefix to the list of specified interface and reconstruct
* the outgoing packet.
* The prefix must be in the list
* The prefix must be in the list.
*/
void
delete_prefix(struct rainfo *rai, struct prefix *prefix)

View File

@ -1,4 +1,5 @@
/* $NetBSD: config.h,v 1.3 2000/02/02 04:07:50 itojun Exp $ */
/* $NetBSD: config.h,v 1.4 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: config.h,v 1.3 2000/05/16 13:34:13 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.

207
usr.sbin/rtadvd/dump.c Normal file
View File

@ -0,0 +1,207 @@
/* $NetBSD: dump.c,v 1.1 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: dump.c,v 1.10 2000/05/23 11:31:25 itojun Exp $ */
/*
* 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/types.h>
#include <sys/socket.h>
#include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
#include <net/if_var.h>
#endif /* __FreeBSD__ >= 3 */
#include <net/if_dl.h>
#include <netinet/in.h>
/* XXX: the following two are non-standard include files */
#include <netinet6/in6_var.h>
#include <netinet6/nd6.h>
#include <arpa/inet.h>
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <syslog.h>
#include <string.h>
#include <errno.h>
#include "rtadvd.h"
#include "timer.h"
#include "dump.h"
static FILE *fp;
extern struct rainfo *ralist;
static char *ether_str __P((struct sockaddr_dl *));
static void if_dump __P((void));
#ifdef __FreeBSD__ /* XXX: see PORTABILITY */
#define LONGLONG "%qu"
#else
#define LONGLONG "%llu"
#endif
static char *
ether_str(sdl)
struct sockaddr_dl *sdl;
{
static char ebuf[32];
u_char *cp;
if (sdl->sdl_alen && sdl->sdl_alen > 5) {
cp = (u_char *)LLADDR(sdl);
sprintf(ebuf, "%x:%x:%x:%x:%x:%x",
cp[0], cp[1], cp[2], cp[3], cp[4], cp[5]);
}
else {
sprintf(ebuf, "NONE");
}
return(ebuf);
}
static void
if_dump()
{
struct rainfo *rai;
struct prefix *pfx;
char prefixbuf[INET6_ADDRSTRLEN];
int first;
for (rai = ralist; rai; rai = rai->next) {
fprintf(fp, "%s:\n", rai->ifname);
/* control information */
if (rai->lastsent.tv_sec) {
/* note that ctime() appends CR by itself */
fprintf(fp, " Last RA sent: %s",
ctime((time_t *)&rai->lastsent.tv_sec));
}
if (rai->timer) {
fprintf(fp, " Next RA will be sent: %s",
ctime((time_t *)&rai->timer->tm.tv_sec));
}
fprintf(fp, " waits: %d, initcount: %d\n",
rai->waiting, rai->initcounter);
/* statistics */
fprintf(fp,
" statistics: RA(out/in/inconsistent): "
LONGLONG "/" LONGLONG "/" LONGLONG ", ",
(unsigned long long)rai->raoutput,
(unsigned long long)rai->rainput,
(unsigned long long)rai->rainconsistent);
fprintf(fp, "RS(input): " LONGLONG "\n",
(unsigned long long)rai->rsinput);
/* interface information */
if (rai->advlinkopt)
fprintf(fp, " Link-layer address: %s\n",
ether_str(rai->sdl));
fprintf(fp, " MTU: %d\n", rai->phymtu);
/* Router configuration variables */
fprintf(fp,
" DefaultLifetime: %d, MaxAdvInterval: %d, "
"MinAdvInterval: %d\n",
rai->lifetime, rai->maxinterval, rai->mininterval);
fprintf(fp, " Flags: %s%s%s MTU: %d\n",
rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
#ifdef MIP6
rai->haflg ? "H" :
#endif
"", rai->linkmtu);
fprintf(fp, " ReachableTime: %d, RetransTimer: %d, "
"CurHopLimit: %d\n", rai->reachabletime,
rai->retranstimer, rai->hoplimit);
#ifdef MIP6
fprintf(fp, " HAPreference: %d, HALifetime: %d\n",
rai->hapref, rai->hatime);
#endif
for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix;
pfx = pfx->next) {
if (first) {
fprintf(fp, " Prefixes:\n");
first = 0;
}
fprintf(fp, " %s/%d(",
inet_ntop(AF_INET6, &pfx->prefix,
prefixbuf, sizeof(prefixbuf)),
pfx->prefixlen);
switch(pfx->origin) {
case PREFIX_FROM_KERNEL:
fprintf(fp, "KERNEL, ");
break;
case PREFIX_FROM_CONFIG:
fprintf(fp, "CONFIG, ");
break;
case PREFIX_FROM_DYNAMIC:
fprintf(fp, "DYNAMIC, ");
break;
}
if (pfx->validlifetime == ND6_INFINITE_LIFETIME)
fprintf(fp, "vltime: infinity, ");
else
fprintf(fp, "vltime: %ld, ",
(long)pfx->validlifetime);
if (pfx->preflifetime == ND6_INFINITE_LIFETIME)
fprintf(fp, "pltime: infinity, ");
else
fprintf(fp, "pltime: %ld, ",
(long)pfx->preflifetime);
fprintf(fp, "flags: %s%s%s",
pfx->onlinkflg ? "L" : "",
pfx->autoconfflg ? "A" : "",
#ifdef MIP6
pfx->routeraddr ? "R" :
#endif
"");
fprintf(fp, ")\n");
}
}
}
void
rtadvd_dump_file(dumpfile)
char *dumpfile;
{
if ((fp = fopen(dumpfile, "w")) == NULL) {
syslog(LOG_WARNING, "<%s> open a dump file(%s)",
__FUNCTION__, dumpfile);
return;
}
if_dump();
fclose(fp);
}

33
usr.sbin/rtadvd/dump.h Normal file
View File

@ -0,0 +1,33 @@
/* $NetBSD: dump.h,v 1.1 2000/05/23 11:37:58 itojun Exp $ */
/* $KAME: dump.h,v 1.1 2000/05/23 11:31:26 itojun Exp $ */
/*
* Copyright (C) 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.
*/
extern void rtadvd_dump_file __P((char *));

View File

@ -1,4 +1,5 @@
/* $NetBSD: if.c,v 1.4 2000/02/28 09:55:45 itojun Exp $ */
/* $NetBSD: if.c,v 1.5 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: if.c,v 1.8 2000/05/22 22:04:37 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -148,7 +149,7 @@ if_nametosdl(char *name)
int
if_getmtu(char *name)
{
#if defined(__FreeBSD__) || defined(__NetBSD__)
#ifndef __bsdi__
struct ifreq ifr;
int s;
@ -165,8 +166,7 @@ if_getmtu(char *name)
close(s);
return(ifr.ifr_mtu);
#endif
#ifdef __bsdi__
#else
struct ifaddrs *ifap, *ifa;
struct if_data *ifd;
@ -185,8 +185,6 @@ if_getmtu(char *name)
freeifaddrs(ifap);
return 0;
#endif
/* last resort */
return 0;
}
/* give interface index and its old flags, then new flags returned */

View File

@ -1,4 +1,5 @@
/* $NetBSD: if.h,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: if.h,v 1.3 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: if.h,v 1.2 2000/05/16 13:34:13 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, 1998, and 1999 WIDE Project.

View File

@ -1,3 +1,4 @@
/* $NetBSD: pathnames.h,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: pathnames.h,v 1.3 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: pathnames.h,v 1.2 2000/05/16 13:34:13 itojun Exp $ */
#define _PATH_RTADVDCONF "/etc/rtadvd.conf"

View File

@ -1,4 +1,5 @@
/* $NetBSD: rrenum.c,v 1.3 2000/03/13 06:16:46 itojun Exp $ */
/* $NetBSD: rrenum.c,v 1.4 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: rrenum.c,v 1.3 2000/05/16 13:34:14 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.

View File

@ -1,4 +1,5 @@
/* $NetBSD: rrenum.h,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: rrenum.h,v 1.3 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: rrenum.h,v 1.2 2000/05/16 13:34:14 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.

View File

@ -1,8 +1,9 @@
.\" $NetBSD: rtadvd.8,v 1.7 2000/03/13 06:16:46 itojun Exp $
.\"
.\" $NetBSD: rtadvd.8,v 1.8 2000/05/23 11:37:59 itojun Exp $
.\" $KAME: rtadvd.8,v 1.8 2000/05/22 22:12:11 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:
@ -14,7 +15,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
@ -27,8 +28,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" KAME Id: rtadvd.8,v 1.5 2000/02/08 05:19:36 itojun Exp
.\"
.Dd May 17, 1998
.Dt RTADVD 8
.Os
@ -41,7 +40,7 @@
.Op Fl dDfRs
.Ar interface ...
.Sh DESCRIPTION
.Nm Rtadvd
.Nm
advertises router advertisement packet to the specified
.Ar interfaces .
.Pp
@ -62,7 +61,7 @@ In particular,
reads all the interface routes from the routing table and advertises
them as on-link prefixes.
.Pp
.Nm Rtadvd
.Nm
also watches the routing table.
By default, if an interface direct route is
added/deleted on an advertising interface,
@ -100,6 +99,12 @@ If you enable it, certain IPsec setup is suggested for security reasons.
Do not monitor routing table changes (static prefix).
.El
.Pp
Upon receipt of signal
.Dv SIGUSR1 ,
.Nm
will dump the current internal state into
.Pa /var/run/rtadvd.dump.
.Pp
Use
.Dv SIGTERM
to kill
@ -116,6 +121,13 @@ The program exits with 0 on success, and non-zero on failures.
.Bl -tag -width /etc/rtadvd.conf -compact
.It Pa /etc/rtadvd.conf
The default configuration file.
.It Pa /var/run/rtadvd.pid
contains pid of the currently running
.Nm rtadvd .
.It Pa /var/run/rtadvd.dump
on which
.Nm
dumps its internal state.
.El
.Sh SEE ALSO
.Xr daemon 3 ,

View File

@ -1,4 +1,5 @@
/* $NetBSD: rtadvd.c,v 1.8 2000/03/27 17:07:23 kleink Exp $ */
/* $NetBSD: rtadvd.c,v 1.9 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: rtadvd.c,v 1.26 2000/05/23 11:31:26 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -59,17 +60,21 @@
#include "timer.h"
#include "if.h"
#include "config.h"
#include "dump.h"
struct msghdr rcvmhdr;
static u_char *rcvcmsgbuf;
static size_t rcvcmsgbuflen;
static u_char *sndcmsgbuf = NULL;
static size_t sndcmsgbuflen;
static int do_dump;
struct msghdr sndmhdr;
struct iovec rcviov[2];
struct iovec sndiov[2];
struct sockaddr_in6 from;
struct sockaddr_in6 sin6_allnodes = {sizeof(sin6_allnodes), AF_INET6};
static char *dumpfilename = "/var/run/rtadvd.dump"; /* XXX: should be configurable */
static char *pidfilename = "/var/run/rtadvd.pid"; /* should be configurable */
int sock, rtsock;
#ifdef MIP6
int mobileip6 = 0;
@ -123,16 +128,17 @@ static void rs_input __P((int, struct nd_router_solicit *,
struct in6_pktinfo *, struct sockaddr_in6 *));
static void ra_input __P((int, struct nd_router_advert *,
struct in6_pktinfo *, struct sockaddr_in6 *));
static void prefix_check __P((struct nd_opt_prefix_info *, struct rainfo *,
struct sockaddr_in6 *));
static int prefix_check __P((struct nd_opt_prefix_info *, struct rainfo *,
struct sockaddr_in6 *));
static int nd6_options __P((struct nd_opt_hdr *, int,
union nd_opts *, u_int32_t));
static void free_ndopts __P((union nd_opts *));
static struct rainfo *if_indextorainfo __P((int));
static void ra_output __P((struct rainfo *));
static void rtmsg_input __P((void));
struct prefix *find_prefix __P((struct rainfo *, struct in6_addr *, int));
static void rtadvd_set_dump_file __P((void));
struct prefix *find_prefix __P((struct rainfo *, struct in6_addr *, int));
int
main(argc, argv)
@ -144,8 +150,10 @@ main(argc, argv)
struct timeval *timeout;
int i, ch;
int fflag = 0;
FILE *pidfp;
pid_t pid;
openlog(*argv, LOG_NDELAY|LOG_PID, LOG_DAEMON);
openlog("rtadvd", LOG_NDELAY|LOG_PID, LOG_DAEMON);
/* get command line options and arguments */
#ifdef MIP6
@ -221,6 +229,17 @@ main(argc, argv)
if (!fflag)
daemon(1, 0);
/* record the current PID */
pid = getpid();
if ((pidfp = fopen(pidfilename, "w")) == NULL)
syslog(LOG_ERR,
"<%s> failed to open a log file(%s), run anyway.",
__FUNCTION__, pidfilename);
else {
fprintf(pidfp, "%d\n", pid);
fclose(pidfp);
}
FD_ZERO(&fdset);
FD_SET(sock, &fdset);
maxfd = sock;
@ -231,11 +250,17 @@ main(argc, argv)
maxfd = rtsock;
}
signal(SIGTERM, die);
signal(SIGTERM, (void *)die);
signal(SIGUSR1, (void *)rtadvd_set_dump_file);
while (1) {
struct fd_set select_fd = fdset; /* reinitialize */
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
rtadvd_dump_file(dumpfilename);
}
/* timer expiration check and reset the timer */
timeout = rtadvd_check_timer();
@ -246,9 +271,11 @@ main(argc, argv)
(long int)timeout->tv_sec, (long int)timeout->tv_usec);
if ((i = select(maxfd + 1, &select_fd,
NULL, NULL, timeout)) < 0){
syslog(LOG_ERR, "<%s> select: %s",
__FUNCTION__, strerror(errno));
NULL, NULL, timeout)) < 0) {
/* EINTR would occur upon SIGUSR1 for status dump */
if (errno != EINTR)
syslog(LOG_ERR, "<%s> select: %s",
__FUNCTION__, strerror(errno));
continue;
}
if (i == 0) /* timeout */
@ -261,6 +288,12 @@ main(argc, argv)
exit(0); /* NOTREACHED */
}
static void
rtadvd_set_dump_file()
{
do_dump = 1;
}
static void
die(sig)
int sig;
@ -290,7 +323,7 @@ die(sig)
static void
rtmsg_input()
{
int n, type, ifindex, plen;
int n, type, ifindex = 0, plen;
size_t len;
char msg[2048], *next, *lim;
u_char ifname[16];
@ -699,6 +732,8 @@ rs_input(int len, struct nd_router_solicit *rs,
goto done;
}
ra->rsinput++; /* increment statistics */
/*
* Decide whether to send RA according to the rate-limit
* consideration.
@ -766,6 +801,7 @@ ra_input(int len, struct nd_router_advert *ra,
union nd_opts ndopts;
char *on_off[] = {"OFF", "ON"};
u_int32_t reachabletime, retranstimer, mtu;
int inconsistent = 0;
syslog(LOG_DEBUG,
"<%s> RA received from %s on %s",
@ -802,6 +838,8 @@ ra_input(int len, struct nd_router_advert *ra,
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
goto done;
}
rai->rainput++; /* increment statistics */
/* Cur Hop Limit value */
if (ra->nd_ra_curhoplimit && rai->hoplimit &&
ra->nd_ra_curhoplimit != rai->hoplimit) {
@ -814,6 +852,7 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->hoplimit);
inconsistent++;
}
/* M flag */
if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_MANAGED) !=
@ -827,6 +866,7 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
on_off[rai->managedflg]);
inconsistent++;
}
/* O flag */
if ((ra->nd_ra_flags_reserved & ND_RA_FLAG_OTHER) !=
@ -840,6 +880,7 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
on_off[rai->otherflg]);
inconsistent++;
}
/* Reachable Time */
reachabletime = ntohl(ra->nd_ra_reachable);
@ -854,6 +895,7 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->reachabletime);
inconsistent++;
}
/* Retrans Timer */
retranstimer = ntohl(ra->nd_ra_retransmit);
@ -868,6 +910,7 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->retranstimer);
inconsistent++;
}
/* Values in the MTU options */
if (ndopts.nd_opts_mtu) {
@ -881,37 +924,48 @@ ra_input(int len, struct nd_router_advert *ra,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->linkmtu);
inconsistent++;
}
}
/* Preferred and Valid Lifetimes for prefixes */
{
struct nd_optlist *optp = ndopts.nd_opts_list;
if (ndopts.nd_opts_pi)
prefix_check(ndopts.nd_opts_pi, rai, from);
if (ndopts.nd_opts_pi) {
if (prefix_check(ndopts.nd_opts_pi, rai, from))
inconsistent++;
}
while (optp) {
prefix_check((struct nd_opt_prefix_info *)optp->opt,
rai, from);
if (prefix_check((struct nd_opt_prefix_info *)optp->opt,
rai, from))
inconsistent++;
optp = optp->next;
}
}
if (inconsistent) {
printf("RA input %d inconsistents\n", inconsistent);
rai->rainconsistent++;
}
done:
free_ndopts(&ndopts);
return;
}
static void
/* return a non-zero value if the received prefix is inconsitent with ours */
static int
prefix_check(struct nd_opt_prefix_info *pinfo,
struct rainfo *rai, struct sockaddr_in6 *from)
{
u_int32_t preferred_time, valid_time;
struct prefix *pp;
int inconsistent = 0;
u_char ntopbuf[INET6_ADDRSTRLEN], prefixbuf[INET6_ADDRSTRLEN];
#if 0 /* impossible */
if (pinfo->nd_opt_pi_type != ND_OPT_PREFIX_INFORMATION)
return;
return(0);
#endif
/*
@ -941,11 +995,11 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
rai->ifname);
return;
return(0);
}
preferred_time = ntohl(pinfo->nd_opt_pi_preferred_time);
if (preferred_time != pp->preflifetime)
if (preferred_time != pp->preflifetime) {
syslog(LOG_WARNING,
"<%s> prefeerred lifetime for %s/%d"
" inconsistent on %s:"
@ -958,9 +1012,11 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
pp->preflifetime);
inconsistent++;
}
valid_time = ntohl(pinfo->nd_opt_pi_valid_time);
if (valid_time != pp->validlifetime)
if (valid_time != pp->validlifetime) {
syslog(LOG_WARNING,
"<%s> valid lifetime for %s/%d"
" inconsistent on %s:"
@ -973,6 +1029,10 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
inet_ntop(AF_INET6, &from->sin6_addr,
ntopbuf, INET6_ADDRSTRLEN),
pp->validlifetime);
inconsistent++;
}
return(inconsistent);
}
struct prefix *
@ -1283,6 +1343,7 @@ struct rainfo *rainfo;
/* update counter */
if (rainfo->initcounter < MAX_INITIAL_RTR_ADVERTISEMENTS)
rainfo->initcounter++;
rainfo->raoutput++;
/* update timestamp */
gettimeofday(&rainfo->lastsent, NULL);

View File

@ -1,6 +1,9 @@
.\" $NetBSD: rtadvd.conf.5,v 1.3 2000/05/23 11:37:59 itojun Exp $
.\" $KAME: rtadvd.conf.5,v 1.5 2000/05/22 22:22:56 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 +15,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,9 +28,6 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $NetBSD: rtadvd.conf.5,v 1.2 1999/07/03 18:12:18 itojun Exp $
.\" KAME Id: rtadvd.conf.5,v 1.1.2.13.2.4.4.1 1999/02/12 08:13:34 sumikawa Exp
.\"
.Dd May 17, 1998
.Dt RTADVD.CONF 5
.Os
@ -35,39 +35,42 @@
.Nm rtadvd.conf
.Nd config file for router advertisement daemon
.Sh DESCRIPTION
The file describes how the router advertisement packet must be constructed
This file describes how the router advertisement packet must be constructed
for each of the interfaces.
.Pp
It obeys famous
It obeys the famous
.Xr termcap 5
file format.
Each line in the file describes a network interface.
Fields are separated by a colon
.Po
.Dq \&:
.Pc ,
.Pq Sq \&: ,
and each field contains one capability description.
Lines may be concatenated by \e character.
The comment marker is `#' character.
Lines may be concatenated by
.Sq \e
character.
The comment marker is the
.Sq \#
character.
.Pp
.Sh CAPABILITIES
Capabilities describe the value to be filled into ICMPv6 router
advertisement message and to control
advertisement messages and to control
.Xr rtadvd 8
behavior.
Therefore, you are encouraged to read IETF neighbor discovery documents
if you would like to modify sample configuration file.
if you would like to modify the sample configuration file.
.Pp
Note that almost all items have default values.
If you omit an item, the default value of the item will be used.
.Pp
There are two items to control interval of sending router advertisements.
There are two items which control the interval of sending router advertisements.
.Bl -tag -width indent
.It Cm \&maxinterval
(num) The maximum time allowed between sending unsolicited
multicast router advertisements
.Pq unit: seconds .
The default value is 600. Its value must be no less than 4 seconds
The default value is 600.
Its value must be no less than 4 seconds
and no greater than 1800 seconds.
.It Cm \&mininterval
(num) The minimum time allowed between sending unsolicited multicast
@ -81,14 +84,14 @@ the value of
.El
.Pp
The following items are for ICMPv6 router advertisement message
header.
header.
.Bl -tag -width indent
.It Cm \&chlim
(num) The value for Cur Hop Limit field.
The default value is 64.
.It Cm \&raflags
(num) Flags field in router advertisement message header.
Bit 7
Bit 7
.Po
.Li 0x80
.Pc
@ -130,15 +133,15 @@ If its value is more than 1, you must specify the index of the prefix
for each item below.
Indices vary from 0 to N-1, where N is the
value of
.Ic addrs.
Each index shall follows the name of each item, e.g.
.Ic addrs .
Each index shall follows the name of each item, e.g.,
.Dq prefixlen2 .
.It Cm \&prefixlen
(num) Prefix length field.
The default value is 64.
.It Cm \&pinfoflags
(num) Flags field in prefix information option.
Bit 7
Bit 7
.Po
.Li 0x80
.Pc
@ -148,7 +151,7 @@ and Bit 6
.Li 0x40
.Pc
means Autonomous address-configuration flag bit.
The default value is 0xc0, i.e. both bits are set.
The default value is 0xc0, i.e., both bits are set.
.It Cm \&addr
(str) The address filled into Prefix field.
Since
@ -177,7 +180,8 @@ which will be attached to router advertisement header.
.It Cm \&mtu
(num or str) MTU (maximum transmission unit) field.
If 0 is specified, it means that the option will not be included.
The default value is 0. If the special string
The default value is 0.
If the special string
.Dq auto
is specified for this item, MTU option will be included and its value
will be set to the interface MTU automatically.
@ -243,7 +247,7 @@ RFC 2461
.Sh HISTORY
The
.Xr rtadvd 8
and the configuration file
and the configuration file
.Nm
first appeared in WIDE Hydrangea IPv6 protocol stack kit.
.\" .Sh BUGS

View File

@ -1,4 +1,5 @@
/* $NetBSD: rtadvd.h,v 1.3 2000/03/13 06:16:46 itojun Exp $ */
/* $NetBSD: rtadvd.h,v 1.4 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: rtadvd.h,v 1.8 2000/05/16 13:34:14 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -64,6 +65,10 @@
#define MIN_DELAY_BETWEEN_RAS 3
#define MAX_RA_DELAY_TIME 500000 /* usec */
#define PREFIX_FROM_KERNEL 1
#define PREFIX_FROM_CONFIG 2
#define PREFIX_FROM_DYNAMIC 3
struct prefix {
struct prefix *next; /* forward link */
struct prefix *prev; /* previous link */
@ -75,7 +80,8 @@ struct prefix {
#ifdef MIP6
u_int routeraddr; /* bool: RouterAddress */
#endif
int prefixlen;
int prefixlen;
int origin; /* from kernel or cofig */
struct in6_addr prefix;
};
@ -86,7 +92,7 @@ struct rainfo {
/* timer related parameters */
struct rtadvd_timer *timer;
int initcounter; /* counter for the first few advertisements */
struct timeval lastsent; /* timestamp when the lates RA was sent */
struct timeval lastsent; /* timestamp when the latest RA was sent */
int waiting; /* number of RS waiting for RA */
/* interface information */
@ -120,6 +126,12 @@ struct rainfo {
/* actual RA packet data and its length */
size_t ra_datalen;
u_char *ra_data;
/* statistics */
u_quad_t raoutput; /* number of RAs sent */
u_quad_t rainput; /* number of RAs received */
u_quad_t rainconsistent; /* number of RAs inconsistent with ours */
u_quad_t rsinput; /* number of RSs received */
};
void ra_timeout __P((void *));

View File

@ -1,4 +1,5 @@
/* $NetBSD: timer.c,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: timer.c,v 1.3 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: timer.c,v 1.3 2000/05/22 22:23:07 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -35,7 +36,7 @@
#include <syslog.h>
#include <stdlib.h>
#include <string.h>
#ifdef __NetBSD__
#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <search.h>
#endif
#include "timer.h"

View File

@ -1,4 +1,5 @@
/* $NetBSD: timer.h,v 1.2 1999/07/06 13:02:09 itojun Exp $ */
/* $NetBSD: timer.h,v 1.3 2000/05/23 11:37:59 itojun Exp $ */
/* $KAME: timer.h,v 1.2 2000/05/16 13:34:14 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.