KNF, correct typos and cleanup spaces.

Obtained from:	KAME
MFC after:	1 week
This commit is contained in:
ume 2003-08-08 16:56:01 +00:00
parent 0820e437dc
commit 958362f6a8
15 changed files with 289 additions and 328 deletions

View File

@ -161,7 +161,7 @@ getent(bp, name, cp)
}
break;
}
if (cp >= bp+BUFSIZ) {
if (cp >= bp + BUFSIZ) {
write(STDERR_FILENO, "Remcap entry too long\n",
23);
break;
@ -198,7 +198,7 @@ tnchktc()
p = tbuf + strlen(tbuf) - 2; /* before the last colon */
while (*--p != ':')
if (p<tbuf) {
if (p < tbuf) {
write(STDERR_FILENO, "Bad remcap entry\n", 18);
return (0);
}

View File

@ -233,8 +233,7 @@ getconfig(intface)
MAYHAVE(val64, "retrans", DEF_ADVRETRANSTIMER);
if (val64 < 0 || val64 > 0xffffffff) {
syslog(LOG_ERR,
"<%s> retrans time out of range", __func__);
syslog(LOG_ERR, "<%s> retrans time out of range", __func__);
exit(1);
}
tmp->retranstimer = (u_int32_t)val64;
@ -276,7 +275,7 @@ getconfig(intface)
/* prefix information */
/*
* This is an implementation specific parameter to consinder
* This is an implementation specific parameter to consider
* link propagation delays and poorly synchronized clocks when
* checking consistency of advertised lifetimes.
*/
@ -567,6 +566,7 @@ get_prefix(struct rainfo *rai)
__func__);
exit(1);
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
int plen;
@ -577,7 +577,6 @@ get_prefix(struct rainfo *rai)
a = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr;
if (IN6_IS_ADDR_LINKLOCAL(a))
continue;
/* get prefix length */
m = (u_char *)&((struct sockaddr_in6 *)ifa->ifa_netmask)->sin6_addr;
lim = (u_char *)(ifa->ifa_netmask) + ifa->ifa_netmask->sa_len;
@ -611,7 +610,6 @@ get_prefix(struct rainfo *rai)
*p++ &= *m++;
while (p < ep)
*p++ = 0x00;
if (!inet_ntop(AF_INET6, &pp->prefix, ntopbuf,
sizeof(ntopbuf))) {
syslog(LOG_ERR, "<%s> inet_ntop failed", __func__);
@ -839,7 +837,7 @@ init_prefix(struct in6_prefixreq *ipr)
ipr->ipr_pltime = DEF_ADVPREFERREDLIFETIME;
ipr->ipr_raf_onlink = 1;
ipr->ipr_raf_auto = 1;
return 0;
return 0;
#endif
}
@ -887,8 +885,7 @@ make_packet(struct rainfo *rainfo)
if ((lladdroptlen = lladdropt_length(rainfo->sdl)) == 0) {
syslog(LOG_INFO,
"<%s> link-layer address option has"
" null length on %s."
" Treat as not included.",
" null length on %s. Treat as not included.",
__func__, rainfo->ifname);
rainfo->advlinkopt = 0;
}

View File

@ -90,10 +90,8 @@ ether_str(sdl)
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 {
} else
sprintf(ebuf, "NONE");
}
return(ebuf);
}
@ -119,11 +117,11 @@ if_dump()
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));
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));
ctime((time_t *)&rai->timer->tm.tv_sec));
}
else
fprintf(fp, " RA timer is stopped");
@ -131,32 +129,30 @@ if_dump()
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, " 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);
(unsigned long long)rai->rsinput);
/* interface information */
if (rai->advlinkopt)
fprintf(fp, " Link-layer address: %s\n",
ether_str(rai->sdl));
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, " DefaultLifetime: %d, MaxAdvInterval: %d, "
"MinAdvInterval: %d\n", rai->lifetime, rai->maxinterval,
rai->mininterval);
fprintf(fp, " Flags: %s%s%s, ",
rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
rai->managedflg ? "M" : "", rai->otherflg ? "O" : "",
#ifdef MIP6
rai->haflg ? "H" :
rai->haflg ? "H" :
#endif
"");
"");
fprintf(fp, "Preference: %s, ",
rtpref_str[(rai->rtpref >> 3) & 0xff]);
fprintf(fp, "MTU: %d\n", rai->linkmtu);
@ -170,7 +166,7 @@ if_dump()
if (rai->clockskew)
fprintf(fp, " Clock skew: %ldsec\n",
rai->clockskew);
rai->clockskew);
for (first = 1, pfx = rai->prefix.next; pfx != &rai->prefix;
pfx = pfx->next) {
if (first) {
@ -178,10 +174,9 @@ if_dump()
first = 0;
}
fprintf(fp, " %s/%d(",
inet_ntop(AF_INET6, &pfx->prefix,
prefixbuf, sizeof(prefixbuf)),
pfx->prefixlen);
switch(pfx->origin) {
inet_ntop(AF_INET6, &pfx->prefix, prefixbuf,
sizeof(prefixbuf)), pfx->prefixlen);
switch (pfx->origin) {
case PREFIX_FROM_KERNEL:
fprintf(fp, "KERNEL, ");
break;
@ -241,7 +236,7 @@ rtadvd_dump_file(dumpfile)
{
if ((fp = fopen(dumpfile, "w")) == NULL) {
syslog(LOG_WARNING, "<%s> open a dump file(%s)",
__func__, dumpfile);
__func__, dumpfile);
return;
}

View File

@ -215,11 +215,11 @@ if_getflags(int ifindex, int oifflags)
int
lladdropt_length(struct sockaddr_dl *sdl)
{
switch(sdl->sdl_type) {
case IFT_ETHER:
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
default:
return(0);
switch (sdl->sdl_type) {
case IFT_ETHER:
return(ROUNDUP8(ETHER_ADDR_LEN + 2));
default:
return(0);
}
}
@ -230,17 +230,16 @@ 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:
ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
addr = (char *)(ndopt + 1);
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
break;
default:
syslog(LOG_ERR,
"<%s> unsupported link type(%d)",
__func__, sdl->sdl_type);
exit(1);
switch (sdl->sdl_type) {
case IFT_ETHER:
ndopt->nd_opt_len = (ROUNDUP8(ETHER_ADDR_LEN + 2)) >> 3;
addr = (char *)(ndopt + 1);
memcpy(addr, LLADDR(sdl), ETHER_ADDR_LEN);
break;
default:
syslog(LOG_ERR, "<%s> unsupported link type(%d)",
__func__, sdl->sdl_type);
exit(1);
}
return;

View File

@ -1,5 +1,5 @@
/* $FreeBSD$ */
/* $KAME: rrenum.c,v 1.10 2001/01/21 15:32:16 itojun Exp $ */
/* $KAME: rrenum.c,v 1.12 2002/06/10 19:59:47 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@ -92,7 +92,7 @@ rr_pco_check(int len, struct rr_pco_match *rpm)
return 1;
}
/* rpm->rpm_code must be valid value */
switch(rpm->rpm_code) {
switch (rpm->rpm_code) {
case RPM_PCO_ADD:
case RPM_PCO_CHANGE:
case RPM_PCO_SETGLOBAL:

View File

@ -530,14 +530,14 @@ rtmsg_input()
}
/* check if an interface flag is changed */
if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */
(iflist[ifindex]->ifm_flags & IFF_UP) == 0) {
if ((oldifflags & IFF_UP) && /* UP to DOWN */
!(iflist[ifindex]->ifm_flags & IFF_UP)) {
syslog(LOG_INFO,
"<%s> interface %s becomes down. stop timer.",
__func__, rai->ifname);
rtadvd_remove_timer(&rai->timer);
} else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */
(iflist[ifindex]->ifm_flags & IFF_UP) != 0) {
} else if (!(oldifflags & IFF_UP) && /* DOWN to UP */
(iflist[ifindex]->ifm_flags & IFF_UP)) {
syslog(LOG_INFO,
"<%s> interface %s becomes up. restart timer.",
__func__, rai->ifname);
@ -760,7 +760,7 @@ rs_input(int len, struct nd_router_solicit *rs,
memset(&ndopts, 0, sizeof(ndopts));
if (nd6_options((struct nd_opt_hdr *)(rs + 1),
len - sizeof(struct nd_router_solicit),
&ndopts, NDOPT_FLAG_SRCLINKADDR)) {
&ndopts, NDOPT_FLAG_SRCLINKADDR)) {
syslog(LOG_DEBUG,
"<%s> ND option check failed for an RS from %s on %s",
__func__,
@ -1092,7 +1092,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
if (rai->clockskew &&
abs(preferred_time - pp->pltimeexpire) > rai->clockskew) {
syslog(LOG_INFO,
"<%s> prefeerred lifetime for %s/%d"
"<%s> preferred lifetime for %s/%d"
" (decr. in real time) inconsistent on %s:"
" %d from %s, %ld from us",
__func__,
@ -1107,7 +1107,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo,
}
} else if (preferred_time != pp->preflifetime) {
syslog(LOG_INFO,
"<%s> prefeerred lifetime for %s/%d"
"<%s> preferred lifetime for %s/%d"
" inconsistent on %s:"
" %d from %s, %d from us",
__func__,
@ -1227,16 +1227,14 @@ nd6_options(struct nd_opt_hdr *hdr, int limit,
}
if (hdr->nd_opt_type > ND_OPT_MTU) {
syslog(LOG_INFO,
"<%s> unknown ND option(type %d)",
syslog(LOG_INFO, "<%s> unknown ND option(type %d)",
__func__, hdr->nd_opt_type);
continue;
}
if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) {
syslog(LOG_INFO,
"<%s> unexpected ND option(type %d)",
__func__, hdr->nd_opt_type);
syslog(LOG_INFO, "<%s> unexpected ND option(type %d)",
__func__, hdr->nd_opt_type);
continue;
}

View File

@ -90,7 +90,7 @@ struct prefix {
u_int routeraddr; /* bool: RouterAddress */
#endif
int prefixlen;
int origin; /* from kernel or cofig */
int origin; /* from kernel or config */
struct in6_addr prefix;
};
@ -99,7 +99,7 @@ struct rtinfo {
struct rtinfo *next; /* forward link */
u_int32_t ltime; /* route lifetime */
u_int rtpref; /* router preference */
u_int rtpref; /* route preference */
int prefixlen;
struct in6_addr prefix;
};
@ -135,6 +135,7 @@ struct rainfo {
#ifdef MIP6
int haflg; /* HAFlag */
#endif
int rtpref; /* router preference */
u_int32_t linkmtu; /* AdvLinkMTU */
u_int32_t reachabletime; /* AdvReachableTime */

View File

@ -1,5 +1,5 @@
/* $FreeBSD$ */
/* $KAME: timer.c,v 1.4 2000/05/27 11:30:43 jinmei Exp $ */
/* $KAME: timer.c,v 1.9 2002/06/10 19:59:47 itojun Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -45,7 +45,7 @@ static struct rtadvd_timer timer_head;
#define MILLION 1000000
#define TIMEVAL_EQUAL(t1,t2) ((t1)->tv_sec == (t2)->tv_sec &&\
(t1)->tv_usec == (t2)->tv_usec)
(t1)->tv_usec == (t2)->tv_usec)
static struct timeval tm_max = {0x7fffffff, 0x7fffffff};
@ -75,7 +75,7 @@ rtadvd_add_timer(struct rtadvd_timer *(*timeout) __P((void *)),
if (timeout == NULL) {
syslog(LOG_ERR,
"<%s> timeout function unspecfied", __func__);
"<%s> timeout function unspecified", __func__);
exit(1);
}
newtimer->expire = timeout;
@ -149,12 +149,10 @@ rtadvd_check_timer()
if (TIMEVAL_EQUAL(&tm_max, &timer_head.tm)) {
/* no need to timeout */
return(NULL);
}
else if (TIMEVAL_LT(timer_head.tm, now)) {
} else if (TIMEVAL_LT(timer_head.tm, now)) {
/* this may occur when the interval is too small */
returnval.tv_sec = returnval.tv_usec = 0;
}
else
} else
TIMEVAL_SUB(&timer_head.tm, &now, &returnval);
return(&returnval);
}

View File

@ -1,5 +1,5 @@
/* $FreeBSD$ */
/* $KAME: timer.h,v 1.3 2000/05/27 11:30:43 jinmei Exp $ */
/* $KAME: timer.h,v 1.5 2002/05/31 13:30:38 jinmei Exp $ */
/*
* Copyright (C) 1998 WIDE Project.
@ -60,6 +60,6 @@ void rtadvd_remove_timer __P((struct rtadvd_timer **));
struct timeval * rtadvd_check_timer __P((void));
struct timeval * rtadvd_timer_rest __P((struct rtadvd_timer *));
void TIMEVAL_ADD __P((struct timeval *, struct timeval *,
struct timeval *));
struct timeval *));
void TIMEVAL_SUB __P((struct timeval *, struct timeval *,
struct timeval *));
struct timeval *));

View File

@ -69,29 +69,28 @@ 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, " other config: %s\n",
ifinfo->otherconfig ? "on" : "off");
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);
}
@ -103,12 +102,10 @@ rtsold_dump_file(dumpfile)
{
if ((fp = fopen(dumpfile, "w")) == NULL) {
warnmsg(LOG_WARNING, __func__, "open a dump file(%s): %s",
dumpfile, strerror(errno));
dumpfile, strerror(errno));
return;
}
dump_interface_status();
fclose(fp);
}
@ -139,6 +136,5 @@ sec2str(total)
p += sprintf(p, "%dm", mins);
}
sprintf(p, "%ds", secs);
return(result);
}

View File

@ -69,7 +69,6 @@
#include <errno.h>
#include <limits.h>
#include <ifaddrs.h>
#include "rtsold.h"
extern int rssock;
@ -97,15 +96,14 @@ interface_up(char *name)
if (ioctl(ifsock, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) {
warnmsg(LOG_WARNING, __func__, "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, __func__,
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
}
"ioctl(SIOCSIFFLAGS): %s", strerror(errno));
return(-1);
}
@ -114,23 +112,22 @@ interface_up(char *name)
llflag = get_llflag(name);
if (llflag < 0) {
warnmsg(LOG_WARNING, __func__,
"get_llflag() failed, anyway I'll try");
"get_llflag() failed, anyway I'll try");
return 0;
}
if (!(llflag & IN6_IFF_NOTREADY)) {
warnmsg(LOG_DEBUG, __func__,
"%s is ready", name);
warnmsg(LOG_DEBUG, __func__, "%s is ready", name);
return(0);
} else {
if (llflag & IN6_IFF_TENTATIVE) {
warnmsg(LOG_DEBUG, __func__, "%s is tentative",
name);
name);
return IFS_TENTATIVE;
}
if (llflag & IN6_IFF_DUPLICATED)
warnmsg(LOG_DEBUG, __func__, "%s is duplicated",
name);
name);
return -1;
}
}
@ -141,13 +138,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, __func__, "ioctl(SIOCGIFFLAGS) on %s: %s",
ifname, strerror(errno));
ifname, strerror(errno));
return(-1);
}
/*
@ -167,8 +164,8 @@ interface_status(struct ifinfo *ifinfo)
if (ioctl(ifsock, SIOCGIFMEDIA, (caddr_t)&ifmr) < 0) {
if (errno != EINVAL) {
warnmsg(LOG_DEBUG, __func__,
"ioctl(SIOCGIFMEDIA) on %s: %s",
ifname, strerror(errno));
"ioctl(SIOCGIFMEDIA) on %s: %s",
ifname, strerror(errno));
return(-1);
}
/*
@ -180,15 +177,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;
}
}
@ -204,21 +201,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);
}
}
@ -229,19 +225,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, __func__,
"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, __func__,
"unsupported link type(%d)", sdl->sdl_type);
exit(1);
}
return;
@ -332,14 +328,14 @@ get_llflag(const char *name)
exit(1);
}
if (getifaddrs(&ifap) != 0) {
warnmsg(LOG_ERR, __func__, "etifaddrs: %s",
warnmsg(LOG_ERR, __func__, "getifaddrs: %s",
strerror(errno));
exit(1);
}
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;
@ -366,17 +362,17 @@ get_llflag(const char *name)
return -1;
}
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;
}
}

View File

@ -61,16 +61,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 *, int));
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, __func__, "malloc failed");
@ -94,12 +93,11 @@ 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)
@ -116,30 +114,29 @@ defrouter_probe(int ifindex)
strcpy(dr.ifname, "lo0"); /* dummy interface */
if (ioctl(s, SIOCGDRLST_IN6, (caddr_t)&dr) < 0) {
warnmsg(LOG_ERR, __func__, "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, __func__,
"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);
dr.defrouter[i].if_index);
}
}
closeandend:
closeandend:
close(s);
return;
}
static void
@ -148,7 +145,8 @@ sendprobe(struct in6_addr *addr, int ifindex)
struct sockaddr_in6 sa6_probe;
struct in6_pktinfo *pi;
struct cmsghdr *cm;
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];;
u_char ntopbuf[INET6_ADDRSTRLEN], ifnamebuf[IFNAMSIZ];
int hoplimit = 1;
bzero(&sa6_probe, sizeof(sa6_probe));
sa6_probe.sin6_family = AF_INET6;
@ -169,23 +167,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, __func__, "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, __func__, "sendmsg on %s: %s",
if_indextoname(ifindex, ifnamebuf), strerror(errno));
return;
if_indextoname(ifindex, ifnamebuf), strerror(errno));
}

View File

@ -71,7 +71,8 @@ static struct sockaddr_in6 from;
int rssock;
static struct sockaddr_in6 sin6_allrouters = {sizeof(sin6_allrouters), AF_INET6};
static struct sockaddr_in6 sin6_allrouters =
{sizeof(sin6_allrouters), AF_INET6};
static void call_script __P((char *, char *));
static int safefile __P((const char *));
@ -86,24 +87,24 @@ sockopen()
static u_char *rcvcmsgbuf = NULL, *sndcmsgbuf = NULL;
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, __func__,
"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, __func__,
"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, __func__, "inet_pton failed for %s",
ALLROUTER);
ALLROUTER);
return(-1);
}
@ -116,45 +117,45 @@ sockopen()
on = 1;
#ifdef IPV6_RECVPKTINFO
if (setsockopt(rssock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &on,
sizeof(on)) < 0) {
sizeof(on)) < 0) {
warnmsg(LOG_ERR, __func__, "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, __func__, "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, __func__, "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, __func__, "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, __func__, "setsockopt(ICMP6_FILTER): %s",
strerror(errno));
strerror(errno));
return(-1);
}
@ -181,9 +182,10 @@ sockopen()
void
sendpacket(struct ifinfo *ifinfo)
{
int i;
struct cmsghdr *cm;
struct in6_pktinfo *pi;
struct cmsghdr *cm;
int hoplimit = 255;
int i;
sndmhdr.msg_name = (caddr_t)&sin6_allrouters;
sndmhdr.msg_iov[0].iov_base = (caddr_t)ifinfo->rs_data;
@ -199,22 +201,16 @@ 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,
__func__, "send RS on %s, whose state is %d",
ifinfo->ifname, ifinfo->state);
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, __func__,
"send RS on %s, whose state is %d",
ifinfo->ifname, ifinfo->state);
i = sendmsg(rssock, &sndmhdr, 0);
if (i < 0 || i != ifinfo->rs_datalen) {
/*
* ENETDOWN is not so serious, especially when using several
@ -222,7 +218,7 @@ sendpacket(struct ifinfo *ifinfo)
*/
if (errno != ENETDOWN || dflag > 0)
warnmsg(LOG_ERR, __func__, "sendmsg on %s: %s",
ifinfo->ifname, strerror(errno));
ifinfo->ifname, strerror(errno));
}
/* update counter */
@ -249,9 +245,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))) {
@ -265,19 +260,19 @@ rtsol_input(int s)
}
if (ifindex == 0) {
warnmsg(LOG_ERR,
__func__, "failed to get receiving interface");
warnmsg(LOG_ERR, __func__,
"failed to get receiving interface");
return;
}
if (hlimp == NULL) {
warnmsg(LOG_ERR,
__func__, "failed to get receiving hop limit");
warnmsg(LOG_ERR, __func__,
"failed to get receiving hop limit");
return;
}
if (i < sizeof(struct nd_router_advert)) {
warnmsg(LOG_ERR,
__func__, "packet size(%d) is too short", i);
warnmsg(LOG_ERR, __func__,
"packet size(%d) is too short", i);
return;
}
@ -285,38 +280,38 @@ rtsol_input(int s)
if (icp->icmp6_type != ND_ROUTER_ADVERT) {
warnmsg(LOG_ERR, __func__,
"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, __func__,
"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, __func__,
"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, __func__,
"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;
}
@ -324,18 +319,17 @@ rtsol_input(int s)
if ((ifi = find_ifinfo(pi->ipi6_ifindex)) == NULL) {
warnmsg(LOG_NOTICE, __func__,
"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 unexpected IF(%s)",
inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf,
INET6_ADDRSTRLEN),
if_indextoname(pi->ipi6_ifindex, ifnamebuf));
return;
}
warnmsg(LOG_DEBUG, __func__,
"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);
nd_ra = (struct nd_router_advert *)icp;
@ -356,15 +350,15 @@ rtsol_input(int s)
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;
}
}

View File

@ -51,23 +51,29 @@
#include <err.h>
#include <stdarg.h>
#include <ifaddrs.h>
#include "rtsold.h"
struct ifinfo *iflist;
struct timeval tm_max = {0x7fffffff, 0x7fffffff};
int aflag = 0;
int dflag = 0;
char *otherconf_script;
static int log_upto = 999;
static int fflag = 0;
int aflag = 0;
int dflag = 0;
char *otherconf_script;
/* protocol constatns */
#define MAX_RTR_SOLICITATION_DELAY 1 /* second */
#define RTR_SOLICITATION_INTERVAL 4 /* seconds */
#define MAX_RTR_SOLICITATIONS 3 /* times */
/* implementation dependent constants */
#define PROBE_INTERVAL 60 /* secondes XXX: should be configurable */
/*
* implementation dependent constants in secondes
* XXX: should be configurable
*/
#define PROBE_INTERVAL 60
/* utility macros */
/* a < b */
@ -78,12 +84,12 @@ 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;
@ -91,32 +97,31 @@ 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));
static int ifconfig __P((char *));
#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 void usage __P((char *));
static char **autoifprobe __P((void));
int
main(argc, argv)
int argc;
char *argv[];
char **argv;
{
int s, rtsock, maxfd, ch;
int once = 0;
struct timeval *timeout;
struct fd_set fdset;
char *argv0;
char *opts;
char *argv0, *opts;
/*
* Initialization
@ -190,6 +195,7 @@ main(argc, argv)
log_upto = LOG_NOTICE;
if (!fflag) {
char *ident;
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
@ -206,7 +212,7 @@ main(argc, argv)
}
#ifndef HAVE_ARC4RANDOM
/* random value initilization */
/* random value initialization */
srandom((u_long)time(NULL));
#endif
@ -269,8 +275,8 @@ main(argc, argv)
if ((fp = fopen(pidfilename, "w")) == NULL)
warnmsg(LOG_ERR, __func__,
"failed to open a log file(%s): %s",
pidfilename, strerror(errno));
"failed to open a pid log file(%s): %s",
pidfilename, strerror(errno));
else {
fprintf(fp, "%d\n", pid);
fclose(fp);
@ -288,7 +294,7 @@ main(argc, argv)
do_dump = 0;
rtsold_dump_file(dumpfilename);
}
timeout = rtsol_check_timer();
if (once) {
@ -310,7 +316,7 @@ main(argc, argv)
if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __func__, "select: %s",
strerror(errno));
strerror(errno));
}
continue;
}
@ -335,12 +341,12 @@ ifconfig(char *ifname)
if ((sdl = if_nametosdl(ifname)) == NULL) {
warnmsg(LOG_ERR, __func__,
"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, __func__,
"interface %s was already configured", ifname);
"interface %s was already configured", ifname);
free(sdl);
return(-1);
}
@ -391,7 +397,7 @@ ifconfig(char *ifname)
return(0);
bad:
bad:
free(ifinfo->sdl);
free(ifinfo);
return(-1);
@ -419,7 +425,6 @@ ifreconfig(char *ifname)
free(ifi->rs_data);
free(ifi->sdl);
free(ifi);
return rv;
}
#endif
@ -432,21 +437,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, __func__,
"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;
@ -454,7 +458,7 @@ make_packet(struct ifinfo *ifinfo)
/* allocate buffer */
if ((buf = malloc(packlen)) == NULL) {
warnmsg(LOG_ERR, __func__,
"memory allocation failed for %s", ifinfo->ifname);
"memory allocation failed for %s", ifinfo->ifname);
return(-1);
}
ifinfo->rs_data = buf;
@ -490,9 +494,9 @@ rtsol_check_timer()
if (TIMEVAL_LEQ(ifinfo->expire, now)) {
if (dflag > 1)
warnmsg(LOG_DEBUG, __func__,
"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:
@ -511,24 +515,22 @@ 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, __func__,
"%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;
}
@ -553,9 +555,8 @@ rtsol_check_timer()
sendpacket(ifinfo);
else {
warnmsg(LOG_INFO, __func__,
"No answer "
"after sending %d RSs",
ifinfo->probes);
"No answer after sending %d RSs",
ifinfo->probes);
ifinfo->probes = 0;
ifinfo->state = IFS_IDLE;
}
@ -571,8 +572,7 @@ rtsol_check_timer()
if (TIMEVAL_EQ(rtsol_timer, tm_max)) {
warnmsg(LOG_DEBUG, __func__, "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
@ -580,7 +580,7 @@ rtsol_check_timer()
if (dflag > 1)
warnmsg(LOG_DEBUG, __func__, "New timer is %ld:%08ld",
(long)returnval.tv_sec, (long)returnval.tv_usec);
(long)returnval.tv_sec, (long)returnval.tv_usec);
return(&returnval);
}
@ -601,13 +601,12 @@ 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
@ -638,8 +637,8 @@ rtsol_timer_update(struct ifinfo *ifinfo)
break;
default:
warnmsg(LOG_ERR, __func__,
"illegal interface state(%d) on %s",
ifinfo->state, ifinfo->ifname);
"illegal interface state(%d) on %s",
ifinfo->state, ifinfo->ifname);
return;
}
@ -647,17 +646,16 @@ rtsol_timer_update(struct ifinfo *ifinfo)
if (TIMEVAL_EQ(ifinfo->timer, tm_max)) {
ifinfo->expire = tm_max;
warnmsg(LOG_DEBUG, __func__,
"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, __func__,
"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
@ -675,8 +673,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;
}
@ -694,8 +691,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;
}

View File

@ -37,7 +37,7 @@ struct ifinfo {
struct sockaddr_dl *sdl; /* link-layer address */
char ifname[IF_NAMESIZE]; /* interface name */
int active; /* interface status */
int probeinterval; /* interval of probe timer(if necessary) */
int probeinterval; /* interval of probe timer (if necessary) */
int probetimer; /* rest of probe timer */
int mediareqok; /* wheter the IF supports SIOCGIFMEDIA */
int otherconfig; /* need a separate protocol for the "other"
@ -66,29 +66,28 @@ struct ifinfo {
extern struct timeval tm_max;
extern int dflag;
extern char *otherconf_script;
struct ifinfo *find_ifinfo __P((int ifindex));
void rtsol_timer_update __P((struct ifinfo *ifinfo));
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)));
/* 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((int));
/* dump.c */
extern void rtsold_dump_file __P((char *));