KNF, from openbsd via kame

This commit is contained in:
itojun 2002-05-31 10:22:11 +00:00
parent c1194e1947
commit b31318e482
9 changed files with 351 additions and 360 deletions

View File

@ -1,13 +1,16 @@
# $NetBSD: Makefile,v 1.7 2001/12/12 01:48:43 tv Exp $
# $NetBSD: Makefile,v 1.8 2002/05/31 10:22:11 itojun Exp $
PROG= rtsol
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS
CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM
#MAN= rtsold.8
NOMAN= # defined
.PATH: ${.CURDIR}/../../usr.sbin/rtsold
LDADD+= -lutil
DPADD+= ${LIBUTIL}
.include <bsd.prog.mk>

View File

@ -1,11 +1,14 @@
# $NetBSD: Makefile,v 1.6 2001/07/09 06:04:28 itojun Exp $
# $NetBSD: Makefile,v 1.7 2002/05/31 10:22:13 itojun Exp $
PROG= rtsold
SRCS= rtsold.c rtsol.c if.c probe.c dump.c rtsock.c
CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS
CPPFLAGS+=-DINET6 -DHAVE_GETIFADDRS -DHAVE_ARC4RANDOM
MAN= rtsold.8
MLINKS= rtsold.8 rtsol.8
LDADD+= -lutil
DPADD+= ${LIBUTIL}
.include <bsd.prog.mk>

View File

@ -1,5 +1,5 @@
/* $NetBSD: dump.c,v 1.5 2001/08/22 05:24:37 itojun Exp $ */
/* $KAME: dump.c,v 1.9 2001/08/20 06:55:54 itojun Exp $ */
/* $NetBSD: dump.c,v 1.6 2002/05/31 10:22:13 itojun Exp $ */
/* $KAME: dump.c,v 1.10 2002/05/31 10:10:03 itojun Exp $ */
/*
* Copyright (C) 1999 WIDE Project.
@ -68,8 +68,7 @@ dump_interface_status()
if (ifinfo->probeinterval) {
fprintf(fp, "%d\n", ifinfo->probeinterval);
fprintf(fp, " probe timer: %d\n", ifinfo->probetimer);
}
else {
} else {
fprintf(fp, "infinity\n");
fprintf(fp, " no probe timer\n");
}
@ -103,9 +102,7 @@ rtsold_dump_file(dumpfile)
dumpfile, strerror(errno));
return;
}
dump_interface_status();
fclose(fp);
}
@ -147,6 +144,5 @@ sec2str(total)
p += n;
}
snprintf(p, ep - p, "%ds", secs);
return(result);
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: if.c,v 1.8 2001/11/14 01:55:38 itojun Exp $ */
/* $KAME: if.c,v 1.15 2001/05/22 06:04:17 jinmei Exp $ */
/* $NetBSD: if.c,v 1.9 2002/05/31 10:22:14 itojun Exp $ */
/* $KAME: if.c,v 1.18 2002/05/31 10:10:03 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -37,23 +37,11 @@
#include <sys/queue.h>
#include <net/if.h>
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
#include <net/if_var.h>
#endif /* __FreeBSD__ >= 3 */
#include <net/if_types.h>
#include <net/route.h>
#include <net/if_dl.h>
#include <net/if_media.h>
#ifdef __FreeBSD__
# include <net/ethernet.h>
#endif
#ifdef __NetBSD__
#include <net/if_ether.h>
#endif
#if defined(__bsdi__) || defined(__OpenBSD__)
# include <netinet/in.h>
# include <netinet/if_ether.h>
#endif
#include <netinet/in.h>
#include <netinet/icmp6.h>
@ -76,12 +64,11 @@
extern int rssock;
static int ifsock;
static int get_llflag __P((const char *name));
static int get_llflag __P((const char *));
#ifndef HAVE_GETIFADDRS
static unsigned int if_maxindex __P((void));
#endif
static void get_rtaddrs __P((int addrs, struct sockaddr *sa,
struct sockaddr **rti_info));
static void get_rtaddrs __P((int, struct sockaddr *, struct sockaddr **));
int
ifinit()
@ -106,10 +93,9 @@ interface_up(char *name)
}
if (!(ifr.ifr_flags & IFF_UP)) {
ifr.ifr_flags |= IFF_UP;
if (ioctl(ifsock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) {
if (ioctl(ifsock, SIOCSIFFLAGS, (caddr_t)&ifr) < 0)
warnmsg(LOG_ERR, __FUNCTION__,
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
}
return(-1);
}
@ -123,8 +109,7 @@ interface_up(char *name)
}
if (!(llflag & IN6_IFF_NOTREADY)) {
warnmsg(LOG_DEBUG, __FUNCTION__,
"%s is ready", name);
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is ready", name);
return(0);
} else {
if (llflag & IN6_IFF_TENTATIVE) {
@ -208,8 +193,7 @@ interface_status(struct ifinfo *ifinfo)
#define NEXT_SA(ap) (ap) = (struct sockaddr *) \
((caddr_t)(ap) + ((ap)->sa_len ? ROUNDUP((ap)->sa_len,\
sizeof(u_long)) :\
sizeof(u_long)))
sizeof(u_long)) : sizeof(u_long)))
#define ROUNDUP8(a) (1 + (((a) - 1) | 7))
int
@ -343,8 +327,8 @@ get_llflag(const char *name)
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
if (strlen(ifa->ifa_name) != strlen(name)
|| strncmp(ifa->ifa_name, name, strlen(name)) != 0)
if (strlen(ifa->ifa_name) != strlen(name) ||
strncmp(ifa->ifa_name, name, strlen(name)) != 0)
continue;
if (ifa->ifa_addr->sa_family != AF_INET6)
continue;
@ -401,12 +385,11 @@ get_llflag(const char *name)
/* Look for this interface in the list */
ifr_end = (struct ifreq *) (ifconf.ifc_buf + ifconf.ifc_len);
for (ifr = ifconf.ifc_req;
ifr < ifr_end;
for (ifr = ifconf.ifc_req; ifr < ifr_end;
ifr = (struct ifreq *) ((char *) &ifr->ifr_addr
+ ifr->ifr_addr.sa_len)) {
if (strlen(ifr->ifr_name) != strlen(name)
|| strncmp(ifr->ifr_name, name, strlen(name)) != 0)
if (strlen(ifr->ifr_name) != strlen(name) ||
strncmp(ifr->ifr_name, name, strlen(name)) != 0)
continue;
if (ifr->ifr_addr.sa_family != AF_INET6)
continue;
@ -460,8 +443,7 @@ get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
if (addrs & (1 << i)) {
rti_info[i] = sa;
NEXT_SA(sa);
}
else
} else
rti_info[i] = NULL;
}
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: probe.c,v 1.5 2000/08/13 06:20:02 itojun Exp $ */
/* $KAME: probe.c,v 1.10 2000/08/13 06:14:59 itojun Exp $ */
/* $NetBSD: probe.c,v 1.6 2002/05/31 10:22:14 itojun Exp $ */
/* $KAME: probe.c,v 1.14 2002/05/31 10:10:03 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -38,9 +38,7 @@
#include <sys/queue.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>
#include <netinet6/in6_var.h>
@ -60,8 +58,7 @@
static struct msghdr sndmhdr;
static struct iovec sndiov[2];
static int probesock;
static void sendprobe __P((struct in6_addr *addr, int ifindex));
static void sendprobe __P((struct in6_addr *, struct ifinfo *));
int
probe_init()
@ -93,7 +90,6 @@ probe_init()
sndmhdr.msg_iovlen = 1;
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
sndmhdr.msg_controllen = scmsglen;
return(0);
}
@ -101,17 +97,18 @@ probe_init()
* Probe if each router in the default router list is still alive.
*/
void
defrouter_probe(int ifindex)
defrouter_probe(struct ifinfo *ifinfo)
{
u_char ntopbuf[INET6_ADDRSTRLEN];
struct in6_drlist dr;
int s, i;
u_char ntopbuf[INET6_ADDRSTRLEN];
int ifindex = ifinfo->sdl->sdl_index;
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno));
return;
}
bzero(&dr, sizeof(dr));
memset(&dr, 0, sizeof(dr));
strcpy(dr.ifname, "lo0"); /* dummy interface */
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGDRLST_IN6): %s",
@ -125,34 +122,35 @@ defrouter_probe(int ifindex)
if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) {
warnmsg(LOG_ERR, __FUNCTION__,
"default router list contains a "
"non-linklocal address(%s)",
"non-link-local address(%s)",
inet_ntop(AF_INET6,
&dr.defrouter[i].rtaddr,
ntopbuf, INET6_ADDRSTRLEN));
continue; /* ignore the address */
}
sendprobe(&dr.defrouter[i].rtaddr,
dr.defrouter[i].if_index);
sendprobe(&dr.defrouter[i].rtaddr, ifinfo);
}
}
closeandend:
close(s);
return;
}
static void
sendprobe(struct in6_addr *addr, int ifindex)
sendprobe(struct in6_addr *addr, struct ifinfo *ifinfo)
{
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
struct sockaddr_in6 sa6_probe;
struct in6_pktinfo *pi;
struct cmsghdr *cm;
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];;
u_int32_t ifindex = ifinfo->sdl->sdl_index;
int hoplimit = 1;
bzero(&sa6_probe, sizeof(sa6_probe));
memset(&sa6_probe, 0, sizeof(sa6_probe));
sa6_probe.sin6_family = AF_INET6;
sa6_probe.sin6_len = sizeof(sa6_probe);
sa6_probe.sin6_addr = *addr;
sa6_probe.sin6_scope_id = ifinfo->linkid;
sndmhdr.msg_name = (caddr_t)&sa6_probe;
sndmhdr.msg_iov[0].iov_base = NULL;
@ -168,15 +166,11 @@ sendprobe(struct in6_addr *addr, int ifindex)
pi->ipi6_ifindex = ifindex;
/* specify the hop limit of the packet for safety */
{
int hoplimit = 1;
cm = CMSG_NXTHDR(&sndmhdr, cm);
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_HOPLIMIT;
cm->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
}
warnmsg(LOG_DEBUG, __FUNCTION__, "probe a router %s on %s",
inet_ntop(AF_INET6, addr, ntopbuf, INET6_ADDRSTRLEN),
@ -185,6 +179,4 @@ sendprobe(struct in6_addr *addr, int ifindex)
if (sendmsg(probesock, &sndmhdr, 0))
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
if_indextoname(ifindex, ifnamebuf), strerror(errno));
return;
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: rtsock.c,v 1.1 2001/07/09 06:04:28 itojun Exp $ */
/* $KAME: rtsock.c,v 1.3 2000/10/10 08:46:45 itojun Exp $ */
/* $NetBSD: rtsock.c,v 1.2 2002/05/31 10:22:14 itojun Exp $ */
/* $KAME: rtsock.c,v 1.4 2001/09/19 06:59:41 sakane Exp $ */
/*
* Copyright (C) 2000 WIDE Project.

View File

@ -1,5 +1,5 @@
/* $NetBSD: rtsol.c,v 1.8 2001/11/14 01:56:29 itojun Exp $ */
/* $KAME: rtsol.c,v 1.14 2001/11/13 10:31:23 jinmei Exp $ */
/* $NetBSD: rtsol.c,v 1.9 2002/05/31 10:22:15 itojun Exp $ */
/* $KAME: rtsol.c,v 1.15 2002/05/31 10:10:03 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -72,11 +72,10 @@ static struct sockaddr_in6 sin6_allrouters = {sizeof(sin6_allrouters), AF_INET6}
int
sockopen()
{
int on;
struct icmp6_filter filt;
static u_char answer[1500];
int rcvcmsglen, sndcmsglen;
static u_char *rcvcmsgbuf = NULL, *sndcmsgbuf = NULL;
int rcvcmsglen, sndcmsglen, on;
static u_char answer[1500];
struct icmp6_filter filt;
sndcmsglen = rcvcmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
CMSG_SPACE(sizeof(int));
@ -174,11 +173,16 @@ sockopen()
void
sendpacket(struct ifinfo *ifinfo)
{
int i;
struct cmsghdr *cm;
struct in6_pktinfo *pi;
struct cmsghdr *cm;
int hoplimit = 255;
int i;
struct sockaddr_in6 dst;
sndmhdr.msg_name = (caddr_t)&sin6_allrouters;
dst = sin6_allrouters;
dst.sin6_scope_id = ifinfo->linkid;
sndmhdr.msg_name = (caddr_t)&dst;
sndmhdr.msg_iov[0].iov_base = (caddr_t)ifinfo->rs_data;
sndmhdr.msg_iov[0].iov_len = ifinfo->rs_datalen;
@ -192,18 +196,14 @@ sendpacket(struct ifinfo *ifinfo)
pi->ipi6_ifindex = ifinfo->sdl->sdl_index;
/* specify the hop limit of the packet */
{
int hoplimit = 255;
cm = CMSG_NXTHDR(&sndmhdr, cm);
cm->cmsg_level = IPPROTO_IPV6;
cm->cmsg_type = IPV6_HOPLIMIT;
cm->cmsg_len = CMSG_LEN(sizeof(int));
memcpy(CMSG_DATA(cm), &hoplimit, sizeof(int));
}
warnmsg(LOG_DEBUG,
__FUNCTION__, "send RS on %s, whose state is %d",
warnmsg(LOG_DEBUG, __FUNCTION__,
"send RS on %s, whose state is %d",
ifinfo->ifname, ifinfo->state);
i = sendmsg(rssock, &sndmhdr, 0);
@ -225,14 +225,12 @@ sendpacket(struct ifinfo *ifinfo)
void
rtsol_input(int s)
{
int i;
int *hlimp = NULL;
struct icmp6_hdr *icp;
int ifindex = 0;
struct cmsghdr *cm;
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
int ifindex = 0, i, *hlimp = NULL;
struct in6_pktinfo *pi = NULL;
struct ifinfo *ifi = NULL;
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
struct icmp6_hdr *icp;
struct cmsghdr *cm;
/* get message */
if ((i = recvmsg(s, &rcvmhdr, 0)) < 0) {
@ -241,8 +239,7 @@ rtsol_input(int s)
}
/* extract optional information via Advanced API */
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvmhdr);
cm;
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvmhdr); cm;
cm = (struct cmsghdr *)CMSG_NXTHDR(&rcvmhdr, cm)) {
if (cm->cmsg_level == IPPROTO_IPV6 &&
cm->cmsg_type == IPV6_PKTINFO &&
@ -257,19 +254,19 @@ rtsol_input(int s)
}
if (ifindex == 0) {
warnmsg(LOG_ERR,
__FUNCTION__, "failed to get receiving interface");
warnmsg(LOG_ERR, __FUNCTION__,
"failed to get receiving interface");
return;
}
if (hlimp == NULL) {
warnmsg(LOG_ERR,
__FUNCTION__, "failed to get receiving hop limit");
warnmsg(LOG_ERR, __FUNCTION__,
"failed to get receiving hop limit");
return;
}
if (i < sizeof(struct nd_router_advert)) {
warnmsg(LOG_ERR,
__FUNCTION__, "packet size(%d) is too short", i);
warnmsg(LOG_ERR, __FUNCTION__,
"packet size(%d) is too short", i);
return;
}
@ -325,8 +322,7 @@ rtsol_input(int s)
warnmsg(LOG_DEBUG, __FUNCTION__,
"received RA from %s on %s, state is %d",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN),
ifi->ifname, ifi->state);
ifi->racnt++;

View File

@ -1,5 +1,5 @@
/* $NetBSD: rtsold.c,v 1.13 2002/03/25 19:55:41 wiz Exp $ */
/* $KAME: rtsold.c,v 1.32 2001/07/09 22:34:07 itojun Exp $ */
/* $NetBSD: rtsold.c,v 1.14 2002/05/31 10:22:16 itojun Exp $ */
/* $KAME: rtsold.c,v 1.48 2002/05/31 10:13:57 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -33,6 +33,7 @@
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <net/if.h>
#include <net/if_dl.h>
@ -50,6 +51,7 @@
#include <err.h>
#include <stdarg.h>
#include <ifaddrs.h>
#include <util.h>
#include "rtsold.h"
struct ifinfo *iflist;
@ -81,41 +83,36 @@ 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[]));
int main __P((int, char **));
/* static variables and functions */
static int mobile_node = 0;
static int do_dump;
static char *dumpfilename = "/var/run/rtsold.dump"; /* XXX: should be configurable */
static char *pidfilename = "/var/run/rtsold.pid"; /* should be configurable */
static int ifconfig __P((char *ifname));
#if 0
static int ifreconfig __P((char *ifname));
static int ifreconfig __P((char *));
#endif
static int make_packet __P((struct ifinfo *ifinfo));
static int make_packet __P((struct ifinfo *));
static struct timeval *rtsol_check_timer __P((void));
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 TIMEVAL_ADD __P((struct timeval *, struct timeval *,
struct timeval *));
static void TIMEVAL_SUB __P((struct timeval *, struct timeval *,
struct timeval *));
static void rtsold_set_dump_file __P((void));
static void usage __P((char *progname));
static char **autoifprobe __P((void));
static void usage __P((char *));
int
main(argc, argv)
int argc;
char *argv[];
char **argv;
{
int s, maxfd, ch;
int rtsock;
int once = 0;
int s, maxfd, ch, once = 0;
struct timeval *timeout;
struct fd_set fdset;
char *argv0;
char *opts;
char *argv0, *opts;
fd_set fdset;
int rtsock;
/*
* Initialization
@ -158,25 +155,7 @@ main(argc, argv)
argc -= optind;
argv += optind;
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) {
if ((!aflag && argc == 0) || (aflag && argc != 0)) {
usage(argv0);
/*NOTREACHED*/
}
@ -186,6 +165,7 @@ main(argc, argv)
log_upto = LOG_NOTICE;
if (!fflag) {
char *ident;
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
@ -243,7 +223,9 @@ main(argc, argv)
exit(1);
/*NOTREACHED*/
}
while (argc--) {
if (aflag)
argv = autoifprobe();
while (argv && *argv) {
if (ifconfig(*argv)) {
warnmsg(LOG_ERR, __FUNCTION__,
"failed to initialize %s", *argv);
@ -263,16 +245,10 @@ main(argc, argv)
/* dump the current pid */
if (!once) {
pid_t pid = getpid();
FILE *fp;
if ((fp = fopen(pidfilename, "w")) == NULL)
if (pidfile(NULL) < 0) {
warnmsg(LOG_ERR, __FUNCTION__,
"failed to open a log file(%s): %s",
pidfilename, strerror(errno));
else {
fprintf(fp, "%d\n", pid);
fclose(fp);
"failed to open a pid log file: %s",
strerror(errno));
}
}
@ -280,8 +256,8 @@ main(argc, argv)
FD_SET(s, &fdset);
FD_SET(rtsock, &fdset);
while (1) { /* main loop */
fd_set select_fd = fdset;
int e;
struct fd_set select_fd = fdset;
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
@ -325,7 +301,7 @@ main(argc, argv)
return 0;
}
static int
int
ifconfig(char *ifname)
{
struct ifinfo *ifinfo;
@ -358,6 +334,15 @@ ifconfig(char *ifname)
if (make_packet(ifinfo))
goto bad;
/* set link ID of this interface. */
#ifdef HAVE_SCOPELIB
if (inet_zoneid(AF_INET6, 2, ifname, &ifinfo->linkid))
goto bad;
#else
/* XXX: assume interface IDs as link IDs */
ifinfo->linkid = ifinfo->sdl->sdl_index;
#endif
/*
* check if the interface is available.
* also check if SIOCGIFMEDIA ioctl is OK on the interface.
@ -396,6 +381,22 @@ ifconfig(char *ifname)
return(-1);
}
void
iflist_init()
{
struct ifinfo *ifi, *next;
for (ifi = iflist; ifi; ifi = next) {
next = ifi->next;
if (ifi->sdl)
free(ifi->sdl);
if (ifi->rs_data)
free(ifi->rs_data);
free(ifi);
iflist = NULL;
}
}
#if 0
static int
ifreconfig(char *ifname)
@ -418,7 +419,6 @@ ifreconfig(char *ifname)
free(ifi->rs_data);
free(ifi->sdl);
free(ifi);
return rv;
}
#endif
@ -431,16 +431,15 @@ find_ifinfo(int ifindex)
for (ifi = iflist; ifi; ifi = ifi->next)
if (ifi->sdl->sdl_index == ifindex)
return(ifi);
return(NULL);
}
static int
make_packet(struct ifinfo *ifinfo)
{
char *buf;
struct nd_router_solicit *rs;
size_t packlen = sizeof(struct nd_router_solicit), lladdroptlen = 0;
struct nd_router_solicit *rs;
char *buf;
if ((lladdroptlen = lladdropt_length(ifinfo->sdl)) == 0) {
warnmsg(LOG_INFO, __FUNCTION__,
@ -510,8 +509,7 @@ rtsol_check_timer()
int oldstatus = ifinfo->active;
int probe = 0;
ifinfo->active =
interface_status(ifinfo);
ifinfo->active = interface_status(ifinfo);
if (oldstatus != ifinfo->active) {
warnmsg(LOG_DEBUG, __FUNCTION__,
@ -521,8 +519,7 @@ rtsol_check_timer()
oldstatus, ifinfo->active);
probe = 1;
ifinfo->state = IFS_DELAY;
}
else if (ifinfo->probeinterval &&
} else if (ifinfo->probeinterval &&
(ifinfo->probetimer -=
ifinfo->timer.tv_sec) <= 0) {
/* probe timer expired */
@ -533,7 +530,7 @@ rtsol_check_timer()
}
if (probe && mobile_node)
defrouter_probe(ifinfo->sdl->sdl_index);
defrouter_probe(ifinfo);
break;
}
case IFS_DELAY:
@ -545,8 +542,7 @@ rtsol_check_timer()
sendpacket(ifinfo);
else {
warnmsg(LOG_INFO, __FUNCTION__,
"No answer "
"after sending %d RSs",
"No answer after sending %d RSs",
ifinfo->probes);
ifinfo->probes = 0;
ifinfo->state = IFS_IDLE;
@ -563,8 +559,7 @@ rtsol_check_timer()
if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
warnmsg(LOG_DEBUG, __FUNCTION__, "there is no timer");
return(NULL);
}
else if (TIMEVAL_LT(rtsol_timer, now))
} else if (TIMEVAL_LT(rtsol_timer, now))
/* this may occur when the interval is too small */
returnval.tv_sec = returnval.tv_usec = 0;
else
@ -593,16 +588,14 @@ rtsol_timer_update(struct ifinfo *ifinfo)
if (++ifinfo->dadcount > DADRETRY) {
ifinfo->dadcount = 0;
ifinfo->timer.tv_sec = PROBE_INTERVAL;
}
else
} else
ifinfo->timer.tv_sec = 1;
break;
case IFS_IDLE:
if (mobile_node) {
/* XXX should be configurable */
ifinfo->timer.tv_sec = 3;
}
else
} else
ifinfo->timer = tm_max; /* stop timer(valid?) */
break;
case IFS_DELAY:
@ -640,8 +633,7 @@ rtsol_timer_update(struct ifinfo *ifinfo)
ifinfo->expire = tm_max;
warnmsg(LOG_DEBUG, __FUNCTION__,
"stop timer for %s", ifinfo->ifname);
}
else {
} else {
gettimeofday(&now, NULL);
TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
@ -667,8 +659,7 @@ TIMEVAL_ADD(struct timeval *a, struct timeval *b, struct timeval *result)
if ((l = a->tv_usec + b->tv_usec) < MILLION) {
result->tv_usec = l;
result->tv_sec = a->tv_sec + b->tv_sec;
}
else {
} else {
result->tv_usec = l - MILLION;
result->tv_sec = a->tv_sec + b->tv_sec + 1;
}
@ -686,8 +677,7 @@ TIMEVAL_SUB(struct timeval *a, struct timeval *b, struct timeval *result)
if ((l = a->tv_usec - b->tv_usec) >= 0) {
result->tv_usec = l;
result->tv_sec = a->tv_sec - b->tv_sec;
}
else {
} else {
result->tv_usec = MILLION + l;
result->tv_sec = a->tv_sec - b->tv_sec - 1;
}
@ -740,16 +730,30 @@ warnmsg(priority, func, msg, va_alist)
va_end(ap);
}
static char **
/*
* return a list of interfaces which is suitable to sending an RS.
*/
char **
autoifprobe()
{
#ifndef HAVE_GETIFADDRS
errx(1, "-a is not available with the configuration");
#else
static char ifname[IFNAMSIZ + 1];
static char *argv[2];
static char **argv = NULL;
static int n = 0;
char **a;
int i, found;
struct ifaddrs *ifap, *ifa, *target;
/* initialize */
while (n--)
free(argv[n]);
if (argv) {
free(argv);
argv = NULL;
}
n = 0;
if (getifaddrs(&ifap) != 0)
return NULL;
@ -768,33 +772,44 @@ autoifprobe()
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;
found = 0;
for (i = 0; i < n; i++) {
if (strcmp(argv[i], ifa->ifa_name) == 0) {
found++;
break;
}
}
if (found)
continue;
if (target) {
strncpy(ifname, target->ifa_name, sizeof(ifname) - 1);
ifname[sizeof(ifname) - 1] = '\0';
argv[0] = ifname;
argv[1] = NULL;
/* if we find multiple candidates, just warn. */
if (n != 0 && dflag > 1)
warnx("multiple interfaces found");
if (dflag > 0)
warnx("probing %s", argv[0]);
a = (char **)realloc(argv, (n + 1) * sizeof(char **));
if (a == NULL)
err(1, "realloc");
argv = a;
argv[n] = (char *)malloc(1 + strlen(ifa->ifa_name));
if (!argv[n])
err(1, "malloc");
strcpy(argv[n], ifa->ifa_name);
n++;
}
if (n) {
a = (char **)realloc(argv, (n + 1) * sizeof(char **));
if (a == NULL)
err(1, "realloc");
argv = a;
argv[n] = NULL;
if (dflag > 0) {
for (i = 0; i < n; i++)
warnx("probing %s", argv[i]);
}
}
freeifaddrs(ifap);
if (target)
return argv;
else
return (char **)NULL;
#endif
}

View File

@ -1,5 +1,5 @@
/* $NetBSD: rtsold.h,v 1.7 2001/07/09 06:04:29 itojun Exp $ */
/* $KAME: rtsold.h,v 1.11 2000/10/10 06:18:04 itojun Exp $ */
/* $NetBSD: rtsold.h,v 1.8 2002/05/31 10:22:17 itojun Exp $ */
/* $KAME: rtsold.h,v 1.14 2002/05/31 10:10:03 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -35,6 +35,7 @@ struct ifinfo {
struct sockaddr_dl *sdl; /* link-layer address */
char ifname[IF_NAMESIZE]; /* interface name */
u_int32_t linkid; /* link ID of this interface */
int active; /* interface status */
int probeinterval; /* interval of probe timer(if necessary) */
int probetimer; /* rest of probe timer */
@ -62,29 +63,32 @@ struct ifinfo {
/* 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));
extern int aflag;
extern int ifconfig __P((char *));
extern void iflist_init __P((void));
struct ifinfo *find_ifinfo __P((int));
void rtsol_timer_update __P((struct ifinfo *));
extern void warnmsg __P((int, const char *, const char *, ...))
__attribute__((__format__(__printf__, 3, 4)));
extern char **autoifprobe __P((void));
/* if.c */
extern int ifinit __P((void));
extern int interface_up __P((char *name));
extern int interface_up __P((char *));
extern int interface_status __P((struct ifinfo *));
extern int lladdropt_length __P((struct sockaddr_dl *sdl));
extern void lladdropt_fill __P((struct sockaddr_dl *sdl,
struct nd_opt_hdr *ndopt));
extern struct sockaddr_dl *if_nametosdl __P((char *name));
extern int getinet6sysctl __P((int code));
extern int lladdropt_length __P((struct sockaddr_dl *));
extern void lladdropt_fill __P((struct sockaddr_dl *, struct nd_opt_hdr *));
extern struct sockaddr_dl *if_nametosdl __P((char *));
extern int getinet6sysctl __P((int));
/* rtsol.c */
extern int sockopen __P((void));
extern void sendpacket __P((struct ifinfo *ifinfo));
extern void rtsol_input __P((int s));
extern void sendpacket __P((struct ifinfo *));
extern void rtsol_input __P((int));
/* probe.c */
extern int probe_init __P((void));
extern void defrouter_probe __P((int ifindex));
extern void defrouter_probe __P((struct ifinfo *));
/* dump.c */
extern void rtsold_dump_file __P((char *));