From 958362f6a8e61ad6b4a95057c871838e4d4de29a Mon Sep 17 00:00:00 2001 From: ume Date: Fri, 8 Aug 2003 16:56:01 +0000 Subject: KNF, correct typos and cleanup spaces. Obtained from: KAME MFC after: 1 week --- usr.sbin/rtsold/rtsol.c | 152 +++++++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 79 deletions(-) (limited to 'usr.sbin/rtsold/rtsol.c') 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; } } -- cgit v1.1