KNF, from openbsd via kame
This commit is contained in:
parent
c1194e1947
commit
b31318e482
@ -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>
|
||||
|
@ -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>
|
||||
|
@ -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,27 +68,26 @@ 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");
|
||||
}
|
||||
fprintf(fp, " interface status: %s\n",
|
||||
ifinfo->active > 0 ? "active" : "inactive");
|
||||
ifinfo->active > 0 ? "active" : "inactive");
|
||||
fprintf(fp, " rtsold status: %s\n", ifstatstr[ifinfo->state]);
|
||||
fprintf(fp, " carrier detection: %s\n",
|
||||
ifinfo->mediareqok ? "available" : "unavailable");
|
||||
ifinfo->mediareqok ? "available" : "unavailable");
|
||||
fprintf(fp, " probes: %d, dadcount = %d\n",
|
||||
ifinfo->probes, ifinfo->dadcount);
|
||||
ifinfo->probes, ifinfo->dadcount);
|
||||
if (ifinfo->timer.tv_sec == tm_max.tv_sec &&
|
||||
ifinfo->timer.tv_usec == tm_max.tv_usec)
|
||||
fprintf(fp, " no timer\n");
|
||||
else {
|
||||
fprintf(fp, " timer: interval=%d:%d, expire=%s\n",
|
||||
(int)ifinfo->timer.tv_sec,
|
||||
(int)ifinfo->timer.tv_usec,
|
||||
(ifinfo->expire.tv_sec < now.tv_sec) ? "expired"
|
||||
: sec2str(ifinfo->expire.tv_sec - now.tv_sec));
|
||||
(int)ifinfo->timer.tv_sec,
|
||||
(int)ifinfo->timer.tv_usec,
|
||||
(ifinfo->expire.tv_sec < now.tv_sec) ? "expired"
|
||||
: sec2str(ifinfo->expire.tv_sec - now.tv_sec));
|
||||
}
|
||||
fprintf(fp, " number of valid RAs: %d\n", ifinfo->racnt);
|
||||
}
|
||||
@ -100,12 +99,10 @@ rtsold_dump_file(dumpfile)
|
||||
{
|
||||
if ((fp = fopen(dumpfile, "w")) == NULL) {
|
||||
warnmsg(LOG_WARNING, __FUNCTION__, "open a dump file(%s): %s",
|
||||
dumpfile, strerror(errno));
|
||||
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);
|
||||
}
|
||||
|
@ -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()
|
||||
@ -101,15 +88,14 @@ interface_up(char *name)
|
||||
|
||||
if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
|
||||
warnmsg(LOG_WARNING, __FUNCTION__, "ioctl(SIOCGIFFLAGS): %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
return(-1);
|
||||
}
|
||||
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));
|
||||
}
|
||||
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -118,23 +104,22 @@ interface_up(char *name)
|
||||
llflag = get_llflag(name);
|
||||
if (llflag < 0) {
|
||||
warnmsg(LOG_WARNING, __FUNCTION__,
|
||||
"get_llflag() failed, anyway I'll try");
|
||||
"get_llflag() failed, anyway I'll try");
|
||||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is tentative",
|
||||
name);
|
||||
name);
|
||||
return IFS_TENTATIVE;
|
||||
}
|
||||
if (llflag & IN6_IFF_DUPLICATED)
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__, "%s is duplicated",
|
||||
name);
|
||||
name);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -145,13 +130,13 @@ interface_status(struct ifinfo *ifinfo)
|
||||
char *ifname = ifinfo->ifname;
|
||||
struct ifreq ifr;
|
||||
struct ifmediareq ifmr;
|
||||
|
||||
|
||||
/* get interface flags */
|
||||
memset(&ifr, 0, sizeof(ifr));
|
||||
strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
|
||||
if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "ioctl(SIOCGIFFLAGS) on %s: %s",
|
||||
ifname, strerror(errno));
|
||||
ifname, strerror(errno));
|
||||
return(-1);
|
||||
}
|
||||
/*
|
||||
@ -171,8 +156,8 @@ interface_status(struct ifinfo *ifinfo)
|
||||
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
|
||||
if (errno != EINVAL) {
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"ioctl(SIOCGIFMEDIA) on %s: %s",
|
||||
ifname, strerror(errno));
|
||||
"ioctl(SIOCGIFMEDIA) on %s: %s",
|
||||
ifname, strerror(errno));
|
||||
return(-1);
|
||||
}
|
||||
/*
|
||||
@ -184,15 +169,15 @@ interface_status(struct ifinfo *ifinfo)
|
||||
}
|
||||
|
||||
if (ifmr.ifm_status & IFM_AVALID) {
|
||||
switch(ifmr.ifm_active & IFM_NMASK) {
|
||||
case IFM_ETHER:
|
||||
if (ifmr.ifm_status & IFM_ACTIVE)
|
||||
goto active;
|
||||
else
|
||||
goto inactive;
|
||||
break;
|
||||
default:
|
||||
goto inactive;
|
||||
switch (ifmr.ifm_active & IFM_NMASK) {
|
||||
case IFM_ETHER:
|
||||
if (ifmr.ifm_status & IFM_ACTIVE)
|
||||
goto active;
|
||||
else
|
||||
goto inactive;
|
||||
break;
|
||||
default:
|
||||
goto inactive;
|
||||
}
|
||||
}
|
||||
|
||||
@ -208,21 +193,20 @@ 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
|
||||
lladdropt_length(struct sockaddr_dl *sdl)
|
||||
{
|
||||
switch(sdl->sdl_type) {
|
||||
case IFT_ETHER:
|
||||
switch (sdl->sdl_type) {
|
||||
case IFT_ETHER:
|
||||
#ifdef IFT_IEEE80211
|
||||
case IFT_IEEE80211:
|
||||
#endif
|
||||
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
|
||||
default:
|
||||
return(0);
|
||||
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
|
||||
default:
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -233,19 +217,19 @@ lladdropt_fill(struct sockaddr_dl *sdl, struct nd_opt_hdr *ndopt)
|
||||
|
||||
ndopt->nd_opt_type = ND_OPT_SOURCE_LINKADDR; /* fixed */
|
||||
|
||||
switch(sdl->sdl_type) {
|
||||
case IFT_ETHER:
|
||||
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);
|
||||
break;
|
||||
default:
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"unsupported link type(%d)", sdl->sdl_type);
|
||||
exit(1);
|
||||
ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
|
||||
addr = (char *)(ndopt + 1);
|
||||
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
|
||||
break;
|
||||
default:
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"unsupported link type(%d)", sdl->sdl_type);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return;
|
||||
@ -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;
|
||||
ifr = (struct ifreq *) ((char *) &ifr->ifr_addr
|
||||
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;
|
||||
@ -455,13 +438,12 @@ static void
|
||||
get_rtaddrs(int addrs, struct sockaddr *sa, struct sockaddr **rti_info)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if (addrs & (1 << i)) {
|
||||
rti_info[i] = sa;
|
||||
NEXT_SA(sa);
|
||||
}
|
||||
else
|
||||
} else
|
||||
rti_info[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
@ -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,16 +58,15 @@
|
||||
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()
|
||||
{
|
||||
int scmsglen = CMSG_SPACE(sizeof(struct in6_pktinfo)) +
|
||||
CMSG_SPACE(sizeof(int));
|
||||
CMSG_SPACE(sizeof(int));
|
||||
static u_char *sndcmsgbuf = NULL;
|
||||
|
||||
|
||||
if (sndcmsgbuf == NULL &&
|
||||
(sndcmsgbuf = (u_char *)malloc(scmsglen)) == NULL) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "malloc failed");
|
||||
@ -93,66 +90,67 @@ probe_init()
|
||||
sndmhdr.msg_iovlen = 1;
|
||||
sndmhdr.msg_control = (caddr_t)sndcmsgbuf;
|
||||
sndmhdr.msg_controllen = scmsglen;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Probe if each router in the default router list is still alive.
|
||||
* 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",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
goto closeandend;
|
||||
}
|
||||
|
||||
for(i = 0; dr.defrouter[i].if_index && i < PRLSTSIZ; i++) {
|
||||
for (i = 0; dr.defrouter[i].if_index && i < PRLSTSIZ; i++) {
|
||||
if (ifindex && dr.defrouter[i].if_index == ifindex) {
|
||||
/* sanity check */
|
||||
if (!IN6_IS_ADDR_LINKLOCAL(&dr.defrouter[i].rtaddr)) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"default router list contains a "
|
||||
"non-linklocal address(%s)",
|
||||
inet_ntop(AF_INET6,
|
||||
&dr.defrouter[i].rtaddr,
|
||||
ntopbuf, INET6_ADDRSTRLEN));
|
||||
"default router list contains a "
|
||||
"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:
|
||||
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,23 +166,17 @@ 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));
|
||||
}
|
||||
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),
|
||||
if_indextoname(ifindex, ifnamebuf));
|
||||
inet_ntop(AF_INET6, addr, ntopbuf, INET6_ADDRSTRLEN),
|
||||
if_indextoname(ifindex, ifnamebuf));
|
||||
|
||||
if (sendmsg(probesock, &sndmhdr, 0))
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
|
||||
if_indextoname(ifindex, ifnamebuf), strerror(errno));
|
||||
|
||||
return;
|
||||
if_indextoname(ifindex, ifnamebuf), strerror(errno));
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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,31 +72,30 @@ 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));
|
||||
CMSG_SPACE(sizeof(int));
|
||||
if (rcvcmsgbuf == NULL && (rcvcmsgbuf = malloc(rcvcmsglen)) == NULL) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"malloc for receive msghdr failed");
|
||||
"malloc for receive msghdr failed");
|
||||
return(-1);
|
||||
}
|
||||
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
|
||||
if (sndcmsgbuf == NULL && (sndcmsgbuf = malloc(sndcmsglen)) == NULL) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"malloc for send msghdr failed");
|
||||
"malloc for send msghdr failed");
|
||||
return(-1);
|
||||
}
|
||||
memset(&sin6_allrouters, 0, sizeof(struct sockaddr_in6));
|
||||
sin6_allrouters.sin6_family = AF_INET6;
|
||||
sin6_allrouters.sin6_len = sizeof(sin6_allrouters);
|
||||
if (inet_pton(AF_INET6, ALLROUTER,
|
||||
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
|
||||
&sin6_allrouters.sin6_addr.s6_addr) != 1) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "inet_pton failed for %s",
|
||||
ALLROUTER);
|
||||
ALLROUTER);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -109,45 +108,45 @@ sockopen()
|
||||
on = 1;
|
||||
#ifdef IPV6_RECVPKTINFO
|
||||
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
|
||||
sizeof(on)) < 0) {
|
||||
sizeof(on)) < 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_RECVPKTINFO: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#else /* old adv. API */
|
||||
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_PKTINFO, &on,
|
||||
sizeof(on)) < 0) {
|
||||
sizeof(on)) < 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_PKTINFO: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
on = 1;
|
||||
/* specify to tell value of hoplimit field of received IP6 hdr */
|
||||
#ifdef IPV6_RECVHOPLIMIT
|
||||
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on,
|
||||
sizeof(on)) < 0) {
|
||||
sizeof(on)) < 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_RECVHOPLIMIT: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#else /* old adv. API */
|
||||
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_HOPLIMIT, &on,
|
||||
sizeof(on)) < 0) {
|
||||
sizeof(on)) < 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "IPV6_HOPLIMIT: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
exit(1);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* specfiy to accept only router advertisements on the socket */
|
||||
ICMP6_FILTER_SETBLOCKALL(&filt);
|
||||
ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filt);
|
||||
if (setsockopt(rssock, IPPROTO_ICMPV6, ICMP6_FILTER, &filt,
|
||||
sizeof(filt)) == -1) {
|
||||
sizeof(filt)) == -1) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "setsockopt(ICMP6_FILTER): %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
return(-1);
|
||||
}
|
||||
|
||||
@ -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,19 +196,15 @@ 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));
|
||||
|
||||
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",
|
||||
ifinfo->ifname, ifinfo->state);
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"send RS on %s, whose state is %d",
|
||||
ifinfo->ifname, ifinfo->state);
|
||||
|
||||
i = sendmsg(rssock, &sndmhdr, 0);
|
||||
|
||||
@ -215,7 +215,7 @@ sendpacket(struct ifinfo *ifinfo)
|
||||
*/
|
||||
if (errno != ENETDOWN || dflag > 0)
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "sendmsg on %s: %s",
|
||||
ifinfo->ifname, strerror(errno));
|
||||
ifinfo->ifname, strerror(errno));
|
||||
}
|
||||
|
||||
/* update counter */
|
||||
@ -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,9 +239,8 @@ rtsol_input(int s)
|
||||
}
|
||||
|
||||
/* extract optional information via Advanced API */
|
||||
for (cm = (struct cmsghdr *)CMSG_FIRSTHDR(&rcvmhdr);
|
||||
cm;
|
||||
cm = (struct cmsghdr *)CMSG_NXTHDR(&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 &&
|
||||
cm->cmsg_len == CMSG_LEN(sizeof(struct in6_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;
|
||||
}
|
||||
|
||||
@ -277,38 +274,38 @@ rtsol_input(int s)
|
||||
|
||||
if (icp->icmp6_type != ND_ROUTER_ADVERT) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"invalid icmp type(%d) from %s on %s", icp->icmp6_type,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
"invalid icmp type(%d) from %s on %s", icp->icmp6_type,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
return;
|
||||
}
|
||||
|
||||
if (icp->icmp6_code != 0) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"invalid icmp code(%d) from %s on %s", icp->icmp6_code,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
"invalid icmp code(%d) from %s on %s", icp->icmp6_code,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
return;
|
||||
}
|
||||
|
||||
if (*hlimp != 255) {
|
||||
warnmsg(LOG_NOTICE, __FUNCTION__,
|
||||
"invalid RA with hop limit(%d) from %s on %s",
|
||||
*hlimp,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
"invalid RA with hop limit(%d) from %s on %s",
|
||||
*hlimp,
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pi && !IN6_IS_ADDR_LINKLOCAL(&from.sin6_addr)) {
|
||||
warnmsg(LOG_NOTICE, __FUNCTION__,
|
||||
"invalid RA with non link-local source from %s on %s",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
"invalid RA with non link-local source from %s on %s",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
return;
|
||||
}
|
||||
|
||||
@ -316,29 +313,28 @@ rtsol_input(int s)
|
||||
|
||||
if ((ifi = find_ifinfo(pi->ipi6_ifindex)) == NULL) {
|
||||
warnmsg(LOG_NOTICE, __FUNCTION__,
|
||||
"received RA from %s on an unexpeced IF(%s)",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
"received RA from %s on an unexpeced IF(%s)",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
|
||||
return;
|
||||
}
|
||||
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"received RA from %s on %s, state is %d",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
|
||||
INET6_ADDRSTRLEN),
|
||||
ifi->ifname, ifi->state);
|
||||
"received RA from %s on %s, state is %d",
|
||||
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, INET6_ADDRSTRLEN),
|
||||
ifi->ifname, ifi->state);
|
||||
|
||||
ifi->racnt++;
|
||||
|
||||
switch(ifi->state) {
|
||||
case IFS_IDLE: /* should be ignored */
|
||||
case IFS_DELAY: /* right? */
|
||||
break;
|
||||
case IFS_PROBE:
|
||||
ifi->state = IFS_IDLE;
|
||||
ifi->probes = 0;
|
||||
rtsol_timer_update(ifi);
|
||||
break;
|
||||
switch (ifi->state) {
|
||||
case IFS_IDLE: /* should be ignored */
|
||||
case IFS_DELAY: /* right? */
|
||||
break;
|
||||
case IFS_PROBE:
|
||||
ifi->state = IFS_IDLE;
|
||||
ifi->probes = 0;
|
||||
rtsol_timer_update(ifi);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
@ -76,46 +78,41 @@ static int fflag = 0;
|
||||
/* a <= b */
|
||||
#define TIMEVAL_LEQ(a, b) (((a).tv_sec < (b).tv_sec) ||\
|
||||
(((a).tv_sec == (b).tv_sec) &&\
|
||||
((a).tv_usec <= (b).tv_usec)))
|
||||
((a).tv_usec <= (b).tv_usec)))
|
||||
|
||||
/* 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,14 +256,14 @@ 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;
|
||||
rtsold_dump_file(dumpfilename);
|
||||
}
|
||||
|
||||
|
||||
timeout = rtsol_check_timer();
|
||||
|
||||
if (once) {
|
||||
@ -309,7 +285,7 @@ main(argc, argv)
|
||||
if (e < 1) {
|
||||
if (e < 0 && errno != EINTR) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
|
||||
strerror(errno));
|
||||
strerror(errno));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@ -325,7 +301,7 @@ main(argc, argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
int
|
||||
ifconfig(char *ifname)
|
||||
{
|
||||
struct ifinfo *ifinfo;
|
||||
@ -334,12 +310,12 @@ ifconfig(char *ifname)
|
||||
|
||||
if ((sdl = if_nametosdl(ifname)) == NULL) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"failed to get link layer information for %s", ifname);
|
||||
"failed to get link layer information for %s", ifname);
|
||||
return(-1);
|
||||
}
|
||||
if (find_ifinfo(sdl->sdl_index)) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"interface %s was already configured", ifname);
|
||||
"interface %s was already configured", ifname);
|
||||
free(sdl);
|
||||
return(-1);
|
||||
}
|
||||
@ -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.
|
||||
@ -390,12 +375,28 @@ ifconfig(char *ifname)
|
||||
|
||||
return(0);
|
||||
|
||||
bad:
|
||||
bad:
|
||||
free(ifinfo->sdl);
|
||||
free(ifinfo);
|
||||
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,21 +431,20 @@ 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__,
|
||||
"link-layer address option has null length"
|
||||
" on %s. Treat as not included.", ifinfo->ifname);
|
||||
"link-layer address option has null length"
|
||||
" on %s. Treat as not included.", ifinfo->ifname);
|
||||
}
|
||||
packlen += lladdroptlen;
|
||||
ifinfo->rs_datalen = packlen;
|
||||
@ -453,7 +452,7 @@ make_packet(struct ifinfo *ifinfo)
|
||||
/* allocate buffer */
|
||||
if ((buf = malloc(packlen)) == NULL) {
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"memory allocation failed for %s", ifinfo->ifname);
|
||||
"memory allocation failed for %s", ifinfo->ifname);
|
||||
return(-1);
|
||||
}
|
||||
ifinfo->rs_data = buf;
|
||||
@ -489,9 +488,9 @@ rtsol_check_timer()
|
||||
if (TIMEVAL_LEQ(ifinfo->expire, now)) {
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"timer expiration on %s, "
|
||||
"state = %d", ifinfo->ifname,
|
||||
ifinfo->state);
|
||||
"timer expiration on %s, "
|
||||
"state = %d", ifinfo->ifname,
|
||||
ifinfo->state);
|
||||
|
||||
switch (ifinfo->state) {
|
||||
case IFS_DOWN:
|
||||
@ -510,30 +509,28 @@ 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__,
|
||||
"%s status is changed"
|
||||
" from %d to %d",
|
||||
ifinfo->ifname,
|
||||
oldstatus, ifinfo->active);
|
||||
"%s status is changed"
|
||||
" from %d to %d",
|
||||
ifinfo->ifname,
|
||||
oldstatus, ifinfo->active);
|
||||
probe = 1;
|
||||
ifinfo->state = IFS_DELAY;
|
||||
}
|
||||
else if (ifinfo->probeinterval &&
|
||||
(ifinfo->probetimer -=
|
||||
ifinfo->timer.tv_sec) <= 0) {
|
||||
} else if (ifinfo->probeinterval &&
|
||||
(ifinfo->probetimer -=
|
||||
ifinfo->timer.tv_sec) <= 0) {
|
||||
/* probe timer expired */
|
||||
ifinfo->probetimer =
|
||||
ifinfo->probeinterval;
|
||||
ifinfo->probeinterval;
|
||||
probe = 1;
|
||||
ifinfo->state = IFS_PROBE;
|
||||
}
|
||||
|
||||
if (probe && mobile_node)
|
||||
defrouter_probe(ifinfo->sdl->sdl_index);
|
||||
defrouter_probe(ifinfo);
|
||||
break;
|
||||
}
|
||||
case IFS_DELAY:
|
||||
@ -545,9 +542,8 @@ rtsol_check_timer()
|
||||
sendpacket(ifinfo);
|
||||
else {
|
||||
warnmsg(LOG_INFO, __FUNCTION__,
|
||||
"No answer "
|
||||
"after sending %d RSs",
|
||||
ifinfo->probes);
|
||||
"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
|
||||
@ -572,7 +567,7 @@ rtsol_check_timer()
|
||||
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__, "New timer is %ld:%08ld",
|
||||
(long)returnval.tv_sec, (long)returnval.tv_usec);
|
||||
(long)returnval.tv_sec, (long)returnval.tv_usec);
|
||||
|
||||
return(&returnval);
|
||||
}
|
||||
@ -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 */
|
||||
/* XXX should be configurable */
|
||||
ifinfo->timer.tv_sec = 3;
|
||||
}
|
||||
else
|
||||
} else
|
||||
ifinfo->timer = tm_max; /* stop timer(valid?) */
|
||||
break;
|
||||
case IFS_DELAY:
|
||||
@ -630,8 +623,8 @@ rtsol_timer_update(struct ifinfo *ifinfo)
|
||||
break;
|
||||
default:
|
||||
warnmsg(LOG_ERR, __FUNCTION__,
|
||||
"illegal interface state(%d) on %s",
|
||||
ifinfo->state, ifinfo->ifname);
|
||||
"illegal interface state(%d) on %s",
|
||||
ifinfo->state, ifinfo->ifname);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -639,17 +632,16 @@ rtsol_timer_update(struct ifinfo *ifinfo)
|
||||
if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
|
||||
ifinfo->expire = tm_max;
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"stop timer for %s", ifinfo->ifname);
|
||||
}
|
||||
else {
|
||||
"stop timer for %s", ifinfo->ifname);
|
||||
} else {
|
||||
gettimeofday(&now, NULL);
|
||||
TIMEVAL_ADD(&now, &ifinfo->timer, &ifinfo->expire);
|
||||
|
||||
if (dflag > 1)
|
||||
warnmsg(LOG_DEBUG, __FUNCTION__,
|
||||
"set timer for %s to %d:%d", ifinfo->ifname,
|
||||
(int)ifinfo->timer.tv_sec,
|
||||
(int)ifinfo->timer.tv_usec);
|
||||
"set timer for %s to %d:%d", ifinfo->ifname,
|
||||
(int)ifinfo->timer.tv_sec,
|
||||
(int)ifinfo->timer.tv_usec);
|
||||
}
|
||||
|
||||
#undef MILLION
|
||||
@ -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)
|
||||
found = 0;
|
||||
for (i = 0; i < n; i++) {
|
||||
if (strcmp(argv[i], ifa->ifa_name) == 0) {
|
||||
found++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
continue;
|
||||
|
||||
if (!target)
|
||||
target = ifa;
|
||||
else {
|
||||
/* if we find multiple candidates, failure. */
|
||||
if (dflag > 1)
|
||||
warnx("multiple interfaces found");
|
||||
target = NULL;
|
||||
break;
|
||||
/* if we find multiple candidates, just warn. */
|
||||
if (n != 0 && dflag > 1)
|
||||
warnx("multiple interfaces found");
|
||||
|
||||
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]);
|
||||
}
|
||||
}
|
||||
|
||||
if (target) {
|
||||
strncpy(ifname, target->ifa_name, sizeof(ifname) - 1);
|
||||
ifname[sizeof(ifname) - 1] = '\0';
|
||||
argv[0] = ifname;
|
||||
argv[1] = NULL;
|
||||
|
||||
if (dflag > 0)
|
||||
warnx("probing %s", argv[0]);
|
||||
}
|
||||
freeifaddrs(ifap);
|
||||
if (target)
|
||||
return argv;
|
||||
else
|
||||
return (char **)NULL;
|
||||
return argv;
|
||||
#endif
|
||||
}
|
||||
|
@ -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_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 interface_up __P((char *));
|
||||
extern int interface_status __P((struct ifinfo *));
|
||||
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 *));
|
||||
|
Loading…
Reference in New Issue
Block a user