diff options
-rw-r--r-- | usr.sbin/rtadvd/if.c | 46 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rrenum.c | 4 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.c | 590 | ||||
-rw-r--r-- | usr.sbin/rtadvd/rtadvd.h | 7 | ||||
-rw-r--r-- | usr.sbin/rtadvd/timer.c | 18 |
5 files changed, 325 insertions, 340 deletions
diff --git a/usr.sbin/rtadvd/if.c b/usr.sbin/rtadvd/if.c index 841b93dfc9e..3edd634e21b 100644 --- a/usr.sbin/rtadvd/if.c +++ b/usr.sbin/rtadvd/if.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if.c,v 1.11 2002/02/17 19:42:39 millert Exp $ */ +/* $OpenBSD: if.c,v 1.12 2002/05/21 23:29:46 itojun Exp $ */ /* $KAME: if.c,v 1.17 2001/01/21 15:27:30 itojun Exp $ */ /* @@ -36,23 +36,12 @@ #include <sys/ioctl.h> #include <net/if.h> #include <net/if_types.h> -#ifdef __FreeBSD__ -# include <net/ethernet.h> -#endif #include <ifaddrs.h> -#ifdef __NetBSD__ -#include <net/if_ether.h> -#endif #include <net/route.h> #include <net/if_dl.h> #include <netinet/in.h> #include <netinet/icmp6.h> -#ifdef __bsdi__ -# include <netinet/if_ether.h> -#endif -#ifdef __OpenBSD__ #include <netinet/if_ether.h> -#endif #include <unistd.h> #include <errno.h> #include <stdlib.h> @@ -215,11 +204,12 @@ 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: + case IFT_FDDI: + return(ROUNDUP8(ETHER_ADDR_LEN + 2)); + default: + return(0); } } @@ -230,17 +220,17 @@ 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)", - __FUNCTION__, sdl->sdl_type); - exit(1); + switch (sdl->sdl_type) { + case IFT_ETHER: + case IFT_FDDI: + 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)", + __FUNCTION__, sdl->sdl_type); + exit(1); } return; diff --git a/usr.sbin/rtadvd/rrenum.c b/usr.sbin/rtadvd/rrenum.c index 9dc2ac5e3f9..e10930be8b4 100644 --- a/usr.sbin/rtadvd/rrenum.c +++ b/usr.sbin/rtadvd/rrenum.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rrenum.c,v 1.7 2001/01/21 15:42:36 itojun Exp $ */ +/* $OpenBSD: rrenum.c,v 1.8 2002/05/21 23:29:46 itojun Exp $ */ /* $KAME: rrenum.c,v 1.10 2001/01/21 15:32:16 itojun Exp $ */ /* @@ -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: diff --git a/usr.sbin/rtadvd/rtadvd.c b/usr.sbin/rtadvd/rtadvd.c index d04e36dd340..a134123fcfd 100644 --- a/usr.sbin/rtadvd/rtadvd.c +++ b/usr.sbin/rtadvd/rtadvd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rtadvd.c,v 1.15 2002/02/17 19:42:39 millert Exp $ */ +/* $OpenBSD: rtadvd.c,v 1.16 2002/05/21 23:29:46 itojun Exp $ */ /* $KAME: rtadvd.c,v 1.50 2001/02/04 06:15:15 itojun Exp $ */ /* @@ -155,9 +155,7 @@ main(argc, argv) int maxfd = 0; struct timeval *timeout; int i, ch; - int fflag = 0; - - openlog("rtadvd", LOG_NDELAY|LOG_PID, LOG_DAEMON); + int fflag = 0, logopt; /* get command line options and arguments */ #ifdef MIP6 @@ -167,36 +165,36 @@ main(argc, argv) #endif while ((ch = getopt(argc, argv, OPTIONS)) != -1) { #undef OPTIONS - switch(ch) { - case 'c': - conffile = optarg; - break; - case 'd': - dflag = 1; - break; - case 'D': - dflag = 2; - break; - case 'f': - fflag = 1; - break; + switch (ch) { + case 'c': + conffile = optarg; + break; + case 'd': + dflag = 1; + break; + case 'D': + dflag = 2; + break; + case 'f': + fflag = 1; + break; case 'M': mcastif = optarg; break; #ifdef MIP6 - case 'm': - mobileip6 = 1; - break; + case 'm': + mobileip6 = 1; + break; #endif - case 'R': - fprintf(stderr, "rtadvd: " - "the -R option is currently ignored.\n"); - /* accept_rr = 1; */ - /* run anyway... */ - break; - case 's': - sflag = 1; - break; + case 'R': + fprintf(stderr, "rtadvd: " + "the -R option is currently ignored.\n"); + /* accept_rr = 1; */ + /* run anyway... */ + break; + case 's': + sflag = 1; + break; } } argc -= optind; @@ -212,6 +210,11 @@ main(argc, argv) exit(1); } + logopt = LOG_NDELAY | LOG_PID; + if (fflag) + logopt |= LOG_PERROR; + openlog("rtadvd", logopt, LOG_DAEMON); + /* set log level */ if (dflag == 0) (void)setlogmask(LOG_UPTO(LOG_ERR)); @@ -243,8 +246,8 @@ main(argc, argv) /* record the current PID */ if (pidfile(NULL) < 0) { syslog(LOG_ERR, - "<%s> failed to open the pid log file, run anyway.", - __FUNCTION__); + "<%s> failed to open the pid log file, run anyway.", + __FUNCTION__); } FD_ZERO(&fdset); @@ -262,7 +265,7 @@ main(argc, argv) signal(SIGUSR1, (void *)rtadvd_set_dump_file); while (1) { - fd_set select_fd = fdset; /* reinitialize */ + struct fd_set select_fd = fdset; /* reinitialize */ if (do_dump) { /* SIGUSR1 */ do_dump = 0; @@ -279,15 +282,14 @@ main(argc, argv) if (timeout != NULL) { syslog(LOG_DEBUG, - "<%s> set timer to %ld:%ld. waiting for " - "inputs or timeout", - __FUNCTION__, - (long int)timeout->tv_sec, - (long int)timeout->tv_usec); + "<%s> set timer to %ld:%ld. waiting for " + "inputs or timeout", __FUNCTION__, + (long int)timeout->tv_sec, + (long int)timeout->tv_usec); } else { syslog(LOG_DEBUG, - "<%s> there's no timer. waiting for inputs", - __FUNCTION__); + "<%s> there's no timer. waiting for inputs", + __FUNCTION__); } if ((i = select(maxfd + 1, &select_fd, @@ -295,7 +297,7 @@ main(argc, argv) /* EINTR would occur upon SIGUSR1 for status dump */ if (errno != EINTR) syslog(LOG_ERR, "<%s> select: %s", - __FUNCTION__, strerror(errno)); + __FUNCTION__, strerror(errno)); continue; } if (i == 0) /* timeout */ @@ -360,11 +362,8 @@ rtmsg_input() n = read(rtsock, msg, sizeof(msg)); if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> received a routing message " - "(type = %d, len = %d)", - __FUNCTION__, - rtmsg_type(msg), n); + syslog(LOG_DEBUG, "<%s> received a routing message " + "(type = %d, len = %d)", __FUNCTION__, rtmsg_type(msg), n); } if (n > rtmsg_len(msg)) { /* @@ -373,10 +372,10 @@ rtmsg_input() */ if (dflag > 1) syslog(LOG_DEBUG, - "<%s> received data length is larger than" - "1st routing message len. multiple messages?" - " read %d bytes, but 1st msg len = %d", - __FUNCTION__, n, rtmsg_len(msg)); + "<%s> received data length is larger than " + "1st routing message len. multiple messages? " + "read %d bytes, but 1st msg len = %d", + __FUNCTION__, n, rtmsg_len(msg)); #if 0 /* adjust length */ n = rtmsg_len(msg); @@ -431,99 +430,92 @@ rtmsg_input() } oldifflags = iflist[ifindex]->ifm_flags; - switch(type) { - case RTM_ADD: - /* init ifflags because it may have changed */ - iflist[ifindex]->ifm_flags = - if_getflags(ifindex, - iflist[ifindex]->ifm_flags); - - if (sflag) - break; /* we aren't interested in prefixes */ - - addr = get_addr(msg); - plen = get_prefixlen(msg); - /* sanity check for plen */ - if (plen < 4 /* as RFC2373, prefixlen is at least 4 */ - || plen > 127) { + switch (type) { + case RTM_ADD: + /* init ifflags because it may have changed */ + iflist[ifindex]->ifm_flags = + if_getflags(ifindex, iflist[ifindex]->ifm_flags); + + if (sflag) + break; /* we aren't interested in prefixes */ + + addr = get_addr(msg); + plen = get_prefixlen(msg); + /* sanity check for plen */ + /* as RFC2373, prefixlen is at least 4 */ + if (plen < 4 || plen > 127) { syslog(LOG_INFO, "<%s> new interface route's" - "plen %d is invalid for a prefix", - __FUNCTION__, plen); + "plen %d is invalid for a prefix", + __FUNCTION__, plen); break; - } - prefix = find_prefix(rai, addr, plen); - if (prefix) { - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> new prefix(%s/%d) " - "added on %s, " - "but it was already in list", - __FUNCTION__, - inet_ntop(AF_INET6, - addr, (char *)addrbuf, - INET6_ADDRSTRLEN), - plen, - rai->ifname); - } - break; - } - make_prefix(rai, ifindex, addr, plen); - break; - case RTM_DELETE: - /* init ifflags because it may have changed */ - iflist[ifindex]->ifm_flags = - if_getflags(ifindex, - iflist[ifindex]->ifm_flags); - - if (sflag) - break; - - addr = get_addr(msg); - plen = get_prefixlen(msg); - /* sanity check for plen */ - if (plen < 4 /* as RFC2373, prefixlen is at least 4 */ - || plen > 127) { - syslog(LOG_INFO, "<%s> deleted interface" - "route's" - "plen %d is invalid for a prefix", - __FUNCTION__, plen); + } + prefix = find_prefix(rai, addr, plen); + if (prefix) { + if (dflag > 1) { + syslog(LOG_DEBUG, + "<%s> new prefix(%s/%d) " + "added on %s, " + "but it was already in list", + __FUNCTION__, + inet_ntop(AF_INET6, addr, + (char *)addrbuf, INET6_ADDRSTRLEN), + plen, rai->ifname); + } break; - } - prefix = find_prefix(rai, addr, plen); - if (prefix == NULL) { - if (dflag > 1) { - syslog(LOG_DEBUG, - "<%s> prefix(%s/%d) was " - "deleted on %s, " - "but it was not in list", - __FUNCTION__, - inet_ntop(AF_INET6, - addr, (char *)addrbuf, - INET6_ADDRSTRLEN), - plen, - rai->ifname); - } - break; - } - delete_prefix(rai, prefix); - break; + } + make_prefix(rai, ifindex, addr, plen); + break; + case RTM_DELETE: + /* init ifflags because it may have changed */ + iflist[ifindex]->ifm_flags = + if_getflags(ifindex, iflist[ifindex]->ifm_flags); + + if (sflag) + break; + + addr = get_addr(msg); + plen = get_prefixlen(msg); + /* sanity check for plen */ + /* as RFC2373, prefixlen is at least 4 */ + if (plen < 4 || plen > 127) { + syslog(LOG_INFO, + "<%s> deleted interface route's " + "plen %d is invalid for a prefix", + __FUNCTION__, plen); + break; + } + prefix = find_prefix(rai, addr, plen); + if (prefix == NULL) { + if (dflag > 1) { + syslog(LOG_DEBUG, + "<%s> prefix(%s/%d) was " + "deleted on %s, " + "but it was not in list", + __FUNCTION__, + inet_ntop(AF_INET6, addr, + (char *)addrbuf, INET6_ADDRSTRLEN), + plen, rai->ifname); + } + break; + } + delete_prefix(rai, prefix); + break; case RTM_NEWADDR: case RTM_DELADDR: - /* init ifflags because it may have changed */ - iflist[ifindex]->ifm_flags = - if_getflags(ifindex, - iflist[ifindex]->ifm_flags); - break; + /* init ifflags because it may have changed */ + iflist[ifindex]->ifm_flags = + if_getflags(ifindex, iflist[ifindex]->ifm_flags); + break; case RTM_IFINFO: - iflist[ifindex]->ifm_flags = get_ifm_flags(next); - break; + iflist[ifindex]->ifm_flags = get_ifm_flags(next); + break; default: /* should not reach here */ if (dflag > 1) { syslog(LOG_DEBUG, - "<%s:%d> unknown rtmsg %d on %s", - __FUNCTION__, __LINE__, type, - if_indextoname(ifindex, ifname)); + "<%s:%d> unknown rtmsg %d on %s", + __FUNCTION__, __LINE__, type, + if_indextoname(ifindex, ifname)); } return; } @@ -532,21 +524,19 @@ rtmsg_input() if ((oldifflags & IFF_UP) != 0 && /* UP to DOWN */ (iflist[ifindex]->ifm_flags & IFF_UP) == 0) { syslog(LOG_INFO, - "<%s> interface %s becomes down. stop timer.", - __FUNCTION__, rai->ifname); + "<%s> interface %s becomes down. stop timer.", + __FUNCTION__, rai->ifname); rtadvd_remove_timer(&rai->timer); - } - else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */ + } else if ((oldifflags & IFF_UP) == 0 && /* DOWN to UP */ (iflist[ifindex]->ifm_flags & IFF_UP) != 0) { syslog(LOG_INFO, - "<%s> interface %s becomes up. restart timer.", - __FUNCTION__, rai->ifname); + "<%s> interface %s becomes up. restart timer.", + __FUNCTION__, rai->ifname); rai->initcounter = 0; /* reset the counter */ rai->waiting = 0; /* XXX */ rai->timer = rtadvd_add_timer(ra_timeout, - ra_timer_update, - rai, rai); + ra_timer_update, rai, rai); ra_timer_update((void *)rai, &rai->timer->tm); rtadvd_set_timer(&rai->timer->tm, rai->timer); } @@ -641,104 +631,102 @@ rtadvd_input() icp = (struct icmp6_hdr *)rcvmhdr.msg_iov[0].iov_base; #endif - switch(icp->icmp6_type) { - case ND_ROUTER_SOLICIT: - /* - * Message verification - RFC-2461 6.1.1 - * XXX: these checks must be done in the kernel as well, - * but we can't completely rely on them. - */ - if (*hlimp != 255) { - syslog(LOG_NOTICE, - "<%s> RS with invalid hop limit(%d) " - "received from %s on %s", - __FUNCTION__, *hlimp, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); - return; - } - if (icp->icmp6_code) { - syslog(LOG_NOTICE, - "<%s> RS with invalid ICMP6 code(%d) " - "received from %s on %s", - __FUNCTION__, icp->icmp6_code, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); - return; - } - if (i < sizeof(struct nd_router_solicit)) { - syslog(LOG_NOTICE, - "<%s> RS from %s on %s does not have enough " - "length (len = %d)", - __FUNCTION__, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); - return; - } - rs_input(i, (struct nd_router_solicit *)icp, pi, &from); - break; - case ND_ROUTER_ADVERT: - /* - * Message verification - RFC-2461 6.1.2 - * XXX: there's a same dilemma as above... - */ - if (*hlimp != 255) { - syslog(LOG_NOTICE, - "<%s> RA with invalid hop limit(%d) " - "received from %s on %s", - __FUNCTION__, *hlimp, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); - return; - } - if (icp->icmp6_code) { - syslog(LOG_NOTICE, - "<%s> RA with invalid ICMP6 code(%d) " - "received from %s on %s", - __FUNCTION__, icp->icmp6_code, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf)); - return; - } - if (i < sizeof(struct nd_router_advert)) { - syslog(LOG_NOTICE, - "<%s> RA from %s on %s does not have enough " - "length (len = %d)", - __FUNCTION__, - inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, - INET6_ADDRSTRLEN), - if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); - return; - } - ra_input(i, (struct nd_router_advert *)icp, pi, &from); - break; - case ICMP6_ROUTER_RENUMBERING: - if (accept_rr == 0) { - syslog(LOG_ERR, - "<%s> received a router renumbering " - "message, but not allowed to be accepted", - __FUNCTION__); - break; - } - rr_input(i, (struct icmp6_router_renum *)icp, pi, &from, - &dst); - break; - default: - /* - * Note that this case is POSSIBLE, especially just - * after invocation of the daemon. This is because we - * could receive message after opening the socket and - * before setting ICMP6 type filter(see sock_open()). - */ - syslog(LOG_ERR, - "<%s> invalid icmp type(%d)", - __FUNCTION__, icp->icmp6_type); - return; + switch (icp->icmp6_type) { + case ND_ROUTER_SOLICIT: + /* + * Message verification - RFC-2461 6.1.1 + * XXX: these checks must be done in the kernel as well, + * but we can't completely rely on them. + */ + if (*hlimp != 255) { + syslog(LOG_NOTICE, + "<%s> RS with invalid hop limit(%d) " + "received from %s on %s", + __FUNCTION__, *hlimp, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + return; + } + if (icp->icmp6_code) { + syslog(LOG_NOTICE, + "<%s> RS with invalid ICMP6 code(%d) " + "received from %s on %s", + __FUNCTION__, icp->icmp6_code, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + return; + } + if (i < sizeof(struct nd_router_solicit)) { + syslog(LOG_NOTICE, + "<%s> RS from %s on %s does not have enough " + "length (len = %d)", + __FUNCTION__, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); + return; + } + rs_input(i, (struct nd_router_solicit *)icp, pi, &from); + break; + case ND_ROUTER_ADVERT: + /* + * Message verification - RFC-2461 6.1.2 + * XXX: there's a same dilemma as above... + */ + if (*hlimp != 255) { + syslog(LOG_NOTICE, + "<%s> RA with invalid hop limit(%d) " + "received from %s on %s", + __FUNCTION__, *hlimp, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + return; + } + if (icp->icmp6_code) { + syslog(LOG_NOTICE, + "<%s> RA with invalid ICMP6 code(%d) " + "received from %s on %s", + __FUNCTION__, icp->icmp6_code, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf)); + return; + } + if (i < sizeof(struct nd_router_advert)) { + syslog(LOG_NOTICE, + "<%s> RA from %s on %s does not have enough " + "length (len = %d)", + __FUNCTION__, + inet_ntop(AF_INET6, &from.sin6_addr, ntopbuf, + INET6_ADDRSTRLEN), + if_indextoname(pi->ipi6_ifindex, ifnamebuf), i); + return; + } + ra_input(i, (struct nd_router_advert *)icp, pi, &from); + break; + case ICMP6_ROUTER_RENUMBERING: + if (accept_rr == 0) { + syslog(LOG_ERR, "<%s> received a router renumbering " + "message, but not allowed to be accepted", + __FUNCTION__); + break; + } + rr_input(i, (struct icmp6_router_renum *)icp, pi, &from, + &dst); + break; + default: + /* + * Note that this case is POSSIBLE, especially just + * after invocation of the daemon. This is because we + * could receive message after opening the socket and + * before setting ICMP6 type filter(see sock_open()). + */ + syslog(LOG_ERR, "<%s> invalid icmp type(%d)", + __FUNCTION__, icp->icmp6_type); + return; } return; @@ -822,7 +810,7 @@ rs_input(int len, struct nd_router_solicit *rs, /*XXX RFC2553 need clarification on flowinfo */ sol->addr.sin6_flowinfo = 0; sol->next = ra->soliciter; - ra->soliciter = sol->next; + ra->soliciter = sol; } /* @@ -1108,8 +1096,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo, pp->pltimeexpire); inconsistent++; } - } - else if (preferred_time != pp->preflifetime) { + } else if (preferred_time != pp->preflifetime) { syslog(LOG_INFO, "<%s> prefeerred lifetime for %s/%d" " inconsistent on %s:" @@ -1145,8 +1132,7 @@ prefix_check(struct nd_opt_prefix_info *pinfo, pp->vltimeexpire); inconsistent++; } - } - else if (valid_time != pp->validlifetime) { + } else if (valid_time != pp->validlifetime) { syslog(LOG_INFO, "<%s> valid lifetime for %s/%d" " inconsistent on %s:" @@ -1170,17 +1156,21 @@ find_prefix(struct rainfo *rai, struct in6_addr *prefix, int plen) { struct prefix *pp; int bytelen, bitlen; + u_char bitmask; for (pp = rai->prefix.next; pp != &rai->prefix; pp = pp->next) { if (plen != pp->prefixlen) continue; bytelen = plen / 8; bitlen = plen % 8; + bitmask = 0xff << (8 - bitlen); if (memcmp((void *)prefix, (void *)&pp->prefix, bytelen)) continue; - if (prefix->s6_addr[bytelen] >> (8 - bitlen) == - pp->prefix.s6_addr[bytelen] >> (8 - bitlen)) + if (bitlen == 0 || + ((prefix->s6_addr[bytelen] & bitmask) == + (pp->prefix.s6_addr[bytelen] & bitmask))) { return(pp); + } } return(NULL); @@ -1192,16 +1182,20 @@ prefix_match(struct in6_addr *p0, int plen0, struct in6_addr *p1, int plen1) { int bytelen, bitlen; + u_char bitmask; if (plen0 < plen1) return(0); bytelen = plen1 / 8; bitlen = plen1 % 8; + bitmask = 0xff << (8 - bitlen); if (memcmp((void *)p0, (void *)p1, bytelen)) return(0); - if (p0->s6_addr[bytelen] >> (8 - bitlen) == - p1->s6_addr[bytelen] >> (8 - bitlen)) + if (bitlen == 0 || + ((p0->s6_addr[bytelen] & bitmask) == + (p1->s6_addr[bytelen] & bitmask))) { return(1); + } return(0); } @@ -1217,64 +1211,66 @@ nd6_options(struct nd_opt_hdr *hdr, int limit, optlen = hdr->nd_opt_len << 3; if (hdr->nd_opt_len == 0) { syslog(LOG_ERR, - "<%s> bad ND option length(0) (type = %d)", - __FUNCTION__, hdr->nd_opt_type); + "<%s> bad ND option length(0) (type = %d)", + __FUNCTION__, hdr->nd_opt_type); goto bad; } - if (hdr->nd_opt_type > ND_OPT_MTU) { - syslog(LOG_INFO, - "<%s> unknown ND option(type %d)", - __FUNCTION__, - hdr->nd_opt_type); +#ifdef MIP6 + if (hdr->nd_opt_type > ND_OPT_HOMEAGENT_INFO) +#else + if (hdr->nd_opt_type > ND_OPT_MTU) +#endif + { + syslog(LOG_INFO, "<%s> unknown ND option(type %d)", + __FUNCTION__, hdr->nd_opt_type); continue; } if ((ndopt_flags[hdr->nd_opt_type] & optflags) == 0) { - syslog(LOG_INFO, - "<%s> unexpected ND option(type %d)", - __FUNCTION__, - hdr->nd_opt_type); + syslog(LOG_INFO, "<%s> unexpected ND option(type %d)", + __FUNCTION__, hdr->nd_opt_type); continue; } - switch(hdr->nd_opt_type) { - case ND_OPT_SOURCE_LINKADDR: - case ND_OPT_TARGET_LINKADDR: - case ND_OPT_REDIRECTED_HEADER: - case ND_OPT_MTU: - if (ndopts->nd_opt_array[hdr->nd_opt_type]) { - syslog(LOG_INFO, - "<%s> duplicated ND option" - " (type = %d)", - __FUNCTION__, - hdr->nd_opt_type); - } - ndopts->nd_opt_array[hdr->nd_opt_type] = hdr; - break; - case ND_OPT_PREFIX_INFORMATION: - { - struct nd_optlist *pfxlist; - - if (ndopts->nd_opts_pi == 0) { - ndopts->nd_opts_pi = - (struct nd_opt_prefix_info *)hdr; - continue; - } - if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) { - syslog(LOG_ERR, - "<%s> can't allocate memory", - __FUNCTION__); - goto bad; - } - pfxlist->next = ndopts->nd_opts_list; - pfxlist->opt = hdr; - ndopts->nd_opts_list = pfxlist; - - break; - } - default: /* impossible */ - break; + switch (hdr->nd_opt_type) { + case ND_OPT_SOURCE_LINKADDR: + case ND_OPT_TARGET_LINKADDR: + case ND_OPT_REDIRECTED_HEADER: + case ND_OPT_MTU: +#ifdef MIP6 + case ND_OPT_ADVINTERVAL: + case ND_OPT_HOMEAGENT_INFO: +#endif + if (ndopts->nd_opt_array[hdr->nd_opt_type]) { + syslog(LOG_INFO, + "<%s> duplicated ND option (type = %d)", + __FUNCTION__, hdr->nd_opt_type); + } + ndopts->nd_opt_array[hdr->nd_opt_type] = hdr; + break; + case ND_OPT_PREFIX_INFORMATION: + { + struct nd_optlist *pfxlist; + + if (ndopts->nd_opts_pi == 0) { + ndopts->nd_opts_pi = + (struct nd_opt_prefix_info *)hdr; + continue; + } + if ((pfxlist = malloc(sizeof(*pfxlist))) == NULL) { + syslog(LOG_ERR, "<%s> can't allocate memory", + __FUNCTION__); + goto bad; + } + pfxlist->next = ndopts->nd_opts_list; + pfxlist->opt = hdr; + ndopts->nd_opts_list = pfxlist; + + break; + } + default: /* impossible */ + break; } } @@ -1291,7 +1287,7 @@ free_ndopts(union nd_opts *ndopts) { struct nd_optlist *opt = ndopts->nd_opts_list, *next; - while(opt) { + while (opt) { next = opt->next; free(opt); opt = next; @@ -1388,7 +1384,7 @@ sock_open() __FUNCTION__); exit(1); } - while(ra) { + while (ra) { mreq.ipv6mr_interface = ra->ifindex; if (setsockopt(sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mreq, sizeof(mreq)) < 0) { diff --git a/usr.sbin/rtadvd/rtadvd.h b/usr.sbin/rtadvd/rtadvd.h index 6636573376c..01914adf8d0 100644 --- a/usr.sbin/rtadvd/rtadvd.h +++ b/usr.sbin/rtadvd/rtadvd.h @@ -1,5 +1,5 @@ -/* $OpenBSD: rtadvd.h,v 1.7 2002/02/16 21:28:08 millert Exp $ */ -/* $KAME: rtadvd.h,v 1.14 2000/11/11 06:57:22 jinmei Exp $ */ +/* $OpenBSD: rtadvd.h,v 1.8 2002/05/21 23:29:46 itojun Exp $ */ +/* $KAME: rtadvd.h,v 1.19 2001/12/20 02:09:37 k-sugyou Exp $ */ /* * Copyright (C) 1998 WIDE Project. @@ -53,7 +53,7 @@ #define MAXROUTERLIFETIME 9000 #define MIN_MAXINTERVAL (mobileip6 ? 1.5 : 4.0) #define MAX_MAXINTERVAL 1800 -#define MIN_MININTERVAL (mobileip6 ? 0.5 : 3) +#define MIN_MININTERVAL (mobileip6 ? 0.05 : 3.0) #define MAXREACHABLETIME 3600000 #ifndef MIP6 @@ -151,6 +151,7 @@ void ra_timer_update(void *, struct timeval *); int prefix_match(struct in6_addr *, int, struct in6_addr *, int); struct rainfo *if_indextorainfo(int); +struct prefix *find_prefix(struct rainfo *, struct in6_addr *, int); extern struct in6_addr in6a_site_allrouters; #ifdef MIP6 diff --git a/usr.sbin/rtadvd/timer.c b/usr.sbin/rtadvd/timer.c index 88f2417ace2..55f9a221fca 100644 --- a/usr.sbin/rtadvd/timer.c +++ b/usr.sbin/rtadvd/timer.c @@ -1,5 +1,5 @@ -/* $OpenBSD: timer.c,v 1.5 2002/02/16 21:28:08 millert Exp $ */ -/* $KAME: timer.c,v 1.4 2000/05/27 11:30:43 jinmei Exp $ */ +/* $OpenBSD: timer.c,v 1.6 2002/05/21 23:29:46 itojun Exp $ */ +/* $KAME: timer.c,v 1.7 2002/05/21 14:26:55 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,12 +75,12 @@ rtadvd_add_timer(void (*timeout)(void *), if (timeout == NULL) { syslog(LOG_ERR, - "<%s> timeout function unspecfied", __FUNCTION__); + "<%s> timeout function unspecified", __FUNCTION__); exit(1); } if (update == NULL) { syslog(LOG_ERR, - "<%s> update function unspecfied", __FUNCTION__); + "<%s> update function unspecified", __FUNCTION__); exit(1); } newtimer->expire = timeout; @@ -136,7 +136,7 @@ rtadvd_check_timer() timer_head.tm = tm_max; - while(tm != &timer_head) { + while (tm != &timer_head) { if (TIMEVAL_LEQ(tm->tm, now)) { (*tm->expire)(tm->expire_data); (*tm->update)(tm->update_data, &tm->tm); @@ -152,12 +152,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); } |