summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-31 09:53:27 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>2002-05-31 09:53:27 +0000
commit4d373c4a676771041c805b6a2583e193324e6f8d (patch)
tree3381837b3bf7335be9cec1c272641d207331a65b /usr.sbin
parent23c764dea356800d33d5ee45822da12470a0d6d1 (diff)
KNF; itojun ok
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/rtsold/dump.c24
-rw-r--r--usr.sbin/rtsold/if.c95
-rw-r--r--usr.sbin/rtsold/probe.c56
-rw-r--r--usr.sbin/rtsold/rtsol.c166
-rw-r--r--usr.sbin/rtsold/rtsold.c112
5 files changed, 206 insertions, 247 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c
index 57d614e8219..deaa6b356f8 100644
--- a/usr.sbin/rtsold/dump.c
+++ b/usr.sbin/rtsold/dump.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dump.c,v 1.7 2002/02/16 21:28:09 millert Exp $ */
+/* $OpenBSD: dump.c,v 1.8 2002/05/31 09:53:26 deraadt Exp $ */
/* $KAME: dump.c,v 1.9 2001/08/20 06:55:54 itojun Exp $ */
/*
@@ -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);
}
diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c
index f3b8f464b4f..edd74486b1d 100644
--- a/usr.sbin/rtsold/if.c
+++ b/usr.sbin/rtsold/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.10 2002/02/17 19:42:39 millert Exp $ */
+/* $OpenBSD: if.c,v 1.11 2002/05/31 09:53:26 deraadt Exp $ */
/* $KAME: if.c,v 1.15 2001/05/22 06:04:17 jinmei Exp $ */
/*
@@ -101,15 +101,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 +117,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 +143,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 +169,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 +182,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 +206,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 +230,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 +340,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 +398,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 +451,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;
}
}
diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c
index 2b79441cd25..5fa148c71f7 100644
--- a/usr.sbin/rtsold/probe.c
+++ b/usr.sbin/rtsold/probe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: probe.c,v 1.5 2002/05/22 09:09:32 deraadt Exp $ */
+/* $OpenBSD: probe.c,v 1.6 2002/05/31 09:53:26 deraadt Exp $ */
/* $KAME: probe.c,v 1.10 2000/08/13 06:14:59 itojun Exp $ */
/*
@@ -62,14 +62,13 @@ static struct iovec sndiov[2];
static int probesock;
static void sendprobe(struct in6_addr *addr, int ifindex);
-
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,19 +92,18 @@ 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)
{
+ u_char ntopbuf[INET6_ADDRSTRLEN];
struct in6_drlist dr;
int s, i;
- u_char ntopbuf[INET6_ADDRSTRLEN];
if ((s = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) {
warnmsg(LOG_ERR, __FUNCTION__, "socket: %s", strerror(errno));
@@ -115,39 +113,39 @@ defrouter_probe(int ifindex)
strlcpy(dr.ifname, "lo0", sizeof dr.ifname); /* 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-linklocal 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
sendprobe(struct in6_addr *addr, int ifindex)
{
+ 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];;
+ int hoplimit = 1;
bzero(&sa6_probe, sizeof(sa6_probe));
sa6_probe.sin6_family = AF_INET6;
@@ -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));
}
diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c
index aa424913de6..6c419b5b618 100644
--- a/usr.sbin/rtsold/rtsol.c
+++ b/usr.sbin/rtsold/rtsol.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsol.c,v 1.6 2001/11/14 01:59:47 itojun Exp $ */
+/* $OpenBSD: rtsol.c,v 1.7 2002/05/31 09:53:26 deraadt Exp $ */
/* $KAME: rtsol.c,v 1.14 2001/11/13 10:31:23 jinmei Exp $ */
/*
@@ -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,9 +173,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;
@@ -192,19 +192,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 +211,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 +221,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 +235,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 +250,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 +270,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 +309,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;
}
}
diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c
index 241cbcc27b5..26e2888396d 100644
--- a/usr.sbin/rtsold/rtsold.c
+++ b/usr.sbin/rtsold/rtsold.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rtsold.c,v 1.18 2002/03/25 20:46:49 deraadt Exp $ */
+/* $OpenBSD: rtsold.c,v 1.19 2002/05/31 09:53:26 deraadt Exp $ */
/* $KAME: rtsold.c,v 1.32 2001/07/09 22:34:07 itojun Exp $ */
/*
@@ -78,13 +78,11 @@ 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(int argc, char *argv[]);
-
/* static variables and functions */
static int mobile_node = 0;
volatile sig_atomic_t do_dump;
@@ -110,15 +108,13 @@ main(argc, argv)
int argc;
char *argv[];
{
- int s, maxfd, ch;
+ int s, maxfd, ch, once = 0, i;
+ struct timeval *timeout;
+ char *argv0, *opts;
+ fd_set fdset;
#if 0
int rtsock;
#endif
- int once = 0;
- struct timeval *timeout;
- fd_set fdset;
- char *argv0;
- char *opts;
/*
* Initialization
@@ -162,8 +158,6 @@ main(argc, argv)
argv += optind;
if (aflag) {
- int i;
-
if (argc != 0) {
usage(argv0);
/*NOTREACHED*/
@@ -189,6 +183,7 @@ main(argc, argv)
log_upto = LOG_NOTICE;
if (!fflag) {
char *ident;
+
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
@@ -270,8 +265,8 @@ main(argc, argv)
if (!once) {
if (pidfile(NULL) < 0) {
warnmsg(LOG_ERR, __FUNCTION__,
- "failed to open a pid log file: %s",
- strerror(errno));
+ "failed to open a pid log file: %s",
+ strerror(errno));
}
}
@@ -281,14 +276,14 @@ main(argc, argv)
FD_SET(rtsock, &fdset);
#endif
while (1) { /* main loop */
- int e;
fd_set select_fd = fdset;
+ int e;
if (do_dump) { /* SIGUSR1 */
do_dump = 0;
rtsold_dump_file(dumpfilename);
}
-
+
timeout = rtsol_check_timer();
if (once) {
@@ -310,7 +305,7 @@ main(argc, argv)
if (e < 1) {
if (e < 0 && errno != EINTR) {
warnmsg(LOG_ERR, __FUNCTION__, "select: %s",
- strerror(errno));
+ strerror(errno));
}
continue;
}
@@ -337,12 +332,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);
}
@@ -393,7 +388,7 @@ ifconfig(char *ifname)
return(0);
- bad:
+bad:
free(ifinfo->sdl);
free(ifinfo);
return(-1);
@@ -421,7 +416,6 @@ ifreconfig(char *ifname)
free(ifi->rs_data);
free(ifi->sdl);
free(ifi);
-
return rv;
}
#endif
@@ -434,21 +428,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;
@@ -456,7 +449,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;
@@ -492,9 +485,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:
@@ -513,24 +506,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, __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;
}
@@ -548,9 +539,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;
}
@@ -566,8 +556,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
@@ -575,7 +564,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);
}
@@ -596,16 +585,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:
@@ -633,8 +620,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;
}
@@ -642,17 +629,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
@@ -670,8 +656,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;
}
@@ -689,8 +674,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;
}