improve debugging functionality.

(sync with latest KAME)
This commit is contained in:
itojun 1999-12-09 15:08:33 +00:00
parent a109943094
commit d9a742bd0d
8 changed files with 102 additions and 27 deletions

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.2 1999/09/03 05:25:44 itojun Exp $
# $NetBSD: Makefile,v 1.3 1999/12/09 15:08:35 itojun Exp $
PROG= rtsol
SRCS= rtsold.c rtsol.c if.c probe.c
SRCS= rtsold.c rtsol.c if.c probe.c dump.c
CPPFLAGS+=-DINET6

View File

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.2 1999/09/03 05:25:43 itojun Exp $
# $NetBSD: Makefile,v 1.3 1999/12/09 15:08:33 itojun Exp $
PROG= rtsold
SRCS= rtsold.c rtsol.c if.c probe.c
SRCS= rtsold.c rtsol.c if.c probe.c dump.c
CPPFLAGS+=-DINET6

View File

@ -1,4 +1,4 @@
/* $NetBSD: if.c,v 1.2 1999/09/03 05:14:37 itojun Exp $ */
/* $NetBSD: if.c,v 1.3 1999/12/09 15:08:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -48,8 +48,7 @@
#ifdef __NetBSD__
#include <net/if_ether.h>
#endif
#ifdef __bsdi__
#if defined(__bsdi__) || defined(__OpenBSD__)
# include <netinet/in.h>
# include <netinet/if_ether.h>
#endif
@ -270,6 +269,8 @@ if_nametosdl(char *name)
if ((sa = rti_info[RTAX_IFP]) != NULL) {
if (sa->sa_family == AF_LINK) {
sdl = (struct sockaddr_dl *)sa;
if (strlen(name) != sdl->sdl_nlen)
continue; /* not same len */
if (strncmp(&sdl->sdl_data[0],
name,
sdl->sdl_nlen) == 0) {
@ -360,7 +361,7 @@ getifa(char *name, struct in6_ifaddr *ifap)
KREAD(ifp, &ifnet, struct ifnet);
if (ifnet.if_index == index)
break;
#if defined(__NetBSD__)
#if defined(__NetBSD__) || defined(__OpenBSD__)
ifp = TAILQ_NEXT(&ifnet, if_list);
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
ifp = TAILQ_NEXT(&ifnet, if_link);
@ -374,7 +375,7 @@ getifa(char *name, struct in6_ifaddr *ifap)
goto bad;
}
#if defined(__NetBSD__)
#if defined(__NetBSD__) || defined(__OpenBSD__)
ifa = (struct in6_ifaddr *)TAILQ_FIRST(&ifnet.if_addrlist);
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3
ifa = (struct in6_ifaddr *)TAILQ_FIRST(&ifnet.if_addrhead);
@ -389,7 +390,7 @@ getifa(char *name, struct in6_ifaddr *ifap)
return 0;
}
#if defined(__NetBSD__)
#if defined(__NetBSD__) || defined(__OpenBSD__)
ifa = (struct in6_ifaddr *)
TAILQ_NEXT((struct ifaddr *)ifap, ifa_list);
#elif defined(__FreeBSD__) && __FreeBSD__ >= 3

View File

@ -1,4 +1,4 @@
/* $NetBSD: probe.c,v 1.2 1999/09/03 05:14:37 itojun Exp $ */
/* $NetBSD: probe.c,v 1.3 1999/12/09 15:08:33 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -172,7 +172,8 @@ sendprobe(struct in6_addr *addr, int ifindex)
if_indextoname(ifindex, ifnamebuf));
if (sendmsg(probesock, &sndmhdr, 0))
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg: %s", strerror(errno));
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
if_indextoname(ifindex, ifnamebuf), strerror(errno));
return;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsol.c,v 1.2 1999/09/03 05:14:37 itojun Exp $ */
/* $NetBSD: rtsol.c,v 1.3 1999/12/09 15:08:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -80,7 +80,7 @@ sockopen()
memset(&sin6_allrouters, 0, sizeof(struct sockaddr_in6));
if (inet_pton(AF_INET6, ALLROUTER,
&sin6_allrouters.sin6_addr.s6_addr) < 0) {
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
warnmsg(LOG_ERR, __FUNCTION__, "inet_pton failed for %s",
ALLROUTER);
return(-1);
@ -176,8 +176,15 @@ sendpacket(struct ifinfo *ifinfo)
i = sendmsg(rssock, &sndmhdr, 0);
if (i < 0 || i != ifinfo->rs_datalen)
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg: %s", strerror(errno));
if (i < 0 || i != ifinfo->rs_datalen) {
/*
* ENETDOWN is not so serious, especially when using several
* network cards on a mobile node. We ignore it.
*/
if (errno != ENETDOWN || dflag > 0)
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
ifinfo->ifname, strerror(errno));
}
/* update counter */
ifinfo->probes++;

View File

@ -25,12 +25,12 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" $NetBSD: rtsold.8,v 1.2 1999/09/03 05:14:37 itojun Exp $
.\" KAME Id: rtsold.8,v 1.3 1999/08/24 07:42:27 itojun Exp
.\" $NetBSD: rtsold.8,v 1.3 1999/12/09 15:08:33 itojun Exp $
.\" KAME Id: rtsold.8,v 1.4 1999/09/30 00:57:15 jinmei Exp
.\"
.Dd May 17, 1998
.Dt RTSOLD 8
.Os
.Os KAME
.\"
.Sh NAME
.Nm rtsold
@ -98,6 +98,13 @@ When sending a Router Solicitation on an interface,
.Nm
includes a Source Link-layer address option if the interface
has its link-layer address.
.Pp
Upon receipt of signal
.Dv SIGUSR1 ,
.Nm
will dump the current internal state into
.Pa /var/tmp/rtsold.dump.
.\"
.Sh OPTIONS
.Bl -tag -width indent
.\"
@ -142,6 +149,15 @@ it will behave as
.Sh RETURN VALUES
The program exits with 0 on success, non-zero on failures.
.\"
.Sh FILES
.Bl -tag -width /var/run/rtsold.dump -compact
.It Pa /var/run/rtsold.pid
the pid of the currently running
.Nm rtsold .
.It Pa /var/tmp/rtsold.dump
dumps internal state on.
.El
.\"
.Sh SEE ALSO
.Xr rtadvd 8 ,
.Xr sysctl 8

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsold.c,v 1.2 1999/09/03 05:14:37 itojun Exp $ */
/* $NetBSD: rtsold.c,v 1.3 1999/12/09 15:08:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -37,17 +37,19 @@
#include <netinet/in.h>
#include <netinet/icmp6.h>
#include <signal.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <err.h>
#include <stdarg.h>
#include "rtsold.h"
struct ifinfo *iflist;
static struct timeval tm_max = {0x7fffffff, 0x7fffffff};
struct timeval tm_max = {0x7fffffff, 0x7fffffff};
int dflag;
static int log_upto = 999;
static int fflag = 0;
@ -74,9 +76,14 @@ static int fflag = 0;
/* a == b */
#define TIMEVAL_EQ(a, b) (((a).tv_sec==(b).tv_sec) && ((a).tv_usec==(b).tv_usec))
int main __P((int argc, char *argv[]));
/* static variables and functions */
static int mobile_node = 0;
int main __P((int argc, char *argv[]));
static int do_dump;
static char *dumpfilename = "/var/tmp/rtsold.dump"; /* XXX: should be configurable */
static char *pidfilename = "/var/run/rtsold.pid"; /* should be configurable */
static int ifconfig __P((char *ifname));
static int make_packet __P((struct ifinfo *ifinfo));
static struct timeval *rtsol_check_timer __P((void));
@ -84,6 +91,8 @@ static void TIMEVAL_ADD __P((struct timeval *a, struct timeval *b,
struct timeval *result));
static void TIMEVAL_SUB __P((struct timeval *a, struct timeval *b,
struct timeval *result));
static void rtsold_set_dump_file __P((void));
static void usage __P((char *progname));
int
@ -141,7 +150,13 @@ main(argc, argv)
if (dflag == 0)
log_upto = LOG_NOTICE;
if (!fflag) {
openlog(argv0, LOG_NDELAY|LOG_PID, LOG_DAEMON);
char *ident;
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
else
ident++;
openlog(ident, LOG_NDELAY|LOG_PID, LOG_DAEMON);
if (log_upto >= 0)
setlogmask(LOG_UPTO(log_upto));
}
@ -153,6 +168,10 @@ main(argc, argv)
if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV))
warnx("kernel is configured not to accept RAs");
/* initialization to dump internal status to a file */
if (signal(SIGUSR1, (void *)rtsold_set_dump_file) < 0)
errx(1, "failed to set signal for dump status");
/* configuration per interface */
if (ifinit())
errx(1, "failed to initilizatoin interfaces");
@ -173,6 +192,21 @@ main(argc, argv)
if (!fflag)
daemon(0, 0); /* act as a daemon */
/* dump the current pid */
if (!once) {
pid_t pid = getpid();
FILE *fp;
if ((fp = fopen(pidfilename, "w")) == NULL)
warnmsg(LOG_ERR, __FUNCTION__,
"failed to open a log file(%s)",
pidfilename, strerror(errno));
else {
fprintf(fp, "%d\n", pid);
fclose(fp);
}
}
FD_ZERO(&fdset);
FD_SET(s, &fdset);
while (1) { /* main loop */
@ -180,6 +214,11 @@ main(argc, argv)
int e;
struct fd_set select_fd = fdset;
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
rtsold_dump_file(dumpfilename);
}
timeout = rtsol_check_timer();
if (once) {
@ -189,7 +228,7 @@ main(argc, argv)
if (timeout == NULL)
break;
/* if all if have got RA packet, we are done */
/* if all interfaces have got RA packet, we are done */
for (ifi = iflist; ifi; ifi = ifi->next) {
if (ifi->state != IFS_DOWN && ifi->racnt == 0)
break;
@ -199,7 +238,7 @@ main(argc, argv)
}
if ((e = select(s + 1, &select_fd, NULL, NULL, timeout)) < 1) {
if (e < 0) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
strerror(errno));
}
@ -524,7 +563,7 @@ TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
* result = a - b
* XXX: this function assumes that a >= b.
*/
static void
void
TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
{
long l;
@ -539,6 +578,12 @@ TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
}
}
static void
rtsold_set_dump_file()
{
do_dump = 1;
}
static void
usage(char *progname)
{

View File

@ -1,4 +1,4 @@
/* $NetBSD: rtsold.h,v 1.2 1999/09/03 05:14:38 itojun Exp $ */
/* $NetBSD: rtsold.h,v 1.3 1999/12/09 15:08:33 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -58,6 +58,8 @@ struct ifinfo {
#define IFS_TENTATIVE 4
/* rtsold.c */
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__
@ -84,3 +86,6 @@ extern void rtsol_input __P((int s));
/* probe.c */
extern int probe_init __P((void));
extern void defrouter_probe __P((int ifindex));
/* dump.c */
extern void rtsold_dump_file __P((char *));