diff options
author | ume <ume@FreeBSD.org> | 2003-08-08 16:56:01 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2003-08-08 16:56:01 +0000 |
commit | 958362f6a8e61ad6b4a95057c871838e4d4de29a (patch) | |
tree | 178f6af642cf6aacbd3415e4286f66d0b9bd3bba /usr.sbin/rtsold | |
parent | 0820e437dc59b5da388bb504e58d1f00bd256862 (diff) | |
download | FreeBSD-src-958362f6a8e61ad6b4a95057c871838e4d4de29a.zip FreeBSD-src-958362f6a8e61ad6b4a95057c871838e4d4de29a.tar.gz |
KNF, correct typos and cleanup spaces.
Obtained from: KAME
MFC after: 1 week
Diffstat (limited to 'usr.sbin/rtsold')
-rw-r--r-- | usr.sbin/rtsold/dump.c | 22 | ||||
-rw-r--r-- | usr.sbin/rtsold/if.c | 88 | ||||
-rw-r--r-- | usr.sbin/rtsold/probe.c | 54 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsol.c | 152 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.c | 130 | ||||
-rw-r--r-- | usr.sbin/rtsold/rtsold.h | 25 |
6 files changed, 222 insertions, 249 deletions
diff --git a/usr.sbin/rtsold/dump.c b/usr.sbin/rtsold/dump.c index 56f8afc..72d31b9 100644 --- a/usr.sbin/rtsold/dump.c +++ b/usr.sbin/rtsold/dump.c @@ -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); } diff --git a/usr.sbin/rtsold/if.c b/usr.sbin/rtsold/if.c index b1f9fd6..3d4632e 100644 --- a/usr.sbin/rtsold/if.c +++ b/usr.sbin/rtsold/if.c @@ -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; } } diff --git a/usr.sbin/rtsold/probe.c b/usr.sbin/rtsold/probe.c index c7b07e2..33f33f9 100644 --- a/usr.sbin/rtsold/probe.c +++ b/usr.sbin/rtsold/probe.c @@ -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)); } diff --git a/usr.sbin/rtsold/rtsol.c b/usr.sbin/rtsold/rtsol.c index 923628d..021eeff 100644 --- a/usr.sbin/rtsold/rtsol.c +++ b/usr.sbin/rtsold/rtsol.c @@ -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; } } diff --git a/usr.sbin/rtsold/rtsold.c b/usr.sbin/rtsold/rtsold.c index ca2044a..cc300ac 100644 --- a/usr.sbin/rtsold/rtsold.c +++ b/usr.sbin/rtsold/rtsold.c @@ -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}; +static int log_upto = 999; +static int fflag = 0; + int aflag = 0; int dflag = 0; + char *otherconf_script; -static int log_upto = 999; -static int fflag = 0; /* 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; } diff --git a/usr.sbin/rtsold/rtsold.h b/usr.sbin/rtsold/rtsold.h index c309b68..976a34b 100644 --- a/usr.sbin/rtsold/rtsold.h +++ b/usr.sbin/rtsold/rtsold.h @@ -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 *)); |