From 3b46d8b708518bf01d84a4974e4cf98e2d8ccd68 Mon Sep 17 00:00:00 2001 From: dyoung Date: Sat, 2 Dec 2006 18:59:17 +0000 Subject: [PATCH] Use the queue(3) macros instead of open-coding them. Shorten staircases. Remove unnecessary casts. Where appropriate, s/8/NBBY/. De-__P(). KNF. No functional changes intended. --- sys/netinet6/in6.c | 58 ++++++++++---------- sys/netinet6/in6_pcb.c | 13 +++-- sys/netinet6/in6_src.c | 10 ++-- sys/netinet6/in6_var.h | 107 ++++++++++++++++++------------------- sys/netinet6/ip6_forward.c | 12 ++--- sys/netinet6/ip6_input.c | 15 +++--- sys/netinet6/ip6_output.c | 13 +++-- sys/netinet6/ipsec.c | 25 ++++----- sys/netinet6/nd6_nbr.c | 12 ++--- sys/netinet6/raw_ip6.c | 9 ++-- 10 files changed, 133 insertions(+), 141 deletions(-) diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index bc49ca5404b7..3e8176aff295 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6.c,v 1.119 2006/11/24 19:47:00 christos Exp $ */ +/* $NetBSD: in6.c,v 1.120 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: in6.c,v 1.198 2001/07/18 09:12:38 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.119 2006/11/24 19:47:00 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6.c,v 1.120 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_pfil_hooks.h" @@ -294,7 +294,7 @@ in6_mask2len(mask, lim0) } y = 0; if (p < lim) { - for (y = 0; y < 8; y++) { + for (y = 0; y < NBBY; y++) { if ((*p & (0x80 >> y)) == 0) break; } @@ -573,7 +573,7 @@ in6_control(so, cmd, data, ifp, l) * signed. */ maxexpire = ((time_t)~0) & - ~((time_t)1 << ((sizeof(maxexpire) * 8) - 1)); + ~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1)); if (ia->ia6_lifetime.ia6t_vltime < maxexpire - ia->ia6_updatetime) { retlt->ia6t_expire = ia->ia6_updatetime + @@ -591,7 +591,7 @@ in6_control(so, cmd, data, ifp, l) * signed. */ maxexpire = ((time_t)~0) & - ~((time_t)1 << ((sizeof(maxexpire) * 8) - 1)); + ~((time_t)1 << ((sizeof(maxexpire) * NBBY) - 1)); if (ia->ia6_lifetime.ia6t_pltime < maxexpire - ia->ia6_updatetime) { retlt->ia6t_preferred = ia->ia6_updatetime + @@ -1109,8 +1109,7 @@ in6_update_ifa(ifp, ifra, ia, flags) mltaddr.sin6_len = sizeof(struct sockaddr_in6); mltaddr.sin6_family = AF_INET6; mltaddr.sin6_addr = in6addr_linklocal_allnodes; - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != - 0) + if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) goto cleanup; /* XXX: should not fail */ /* @@ -1170,19 +1169,17 @@ in6_update_ifa(ifp, ifra, ia, flags) dad_delay = arc4random() % (MAX_RTR_SOLICITATION_DELAY * hz); } - if (in6_nigroup(ifp, hostname, hostnamelen, &mltaddr) == 0) { - imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, - dad_delay); /* XXX jinmei */ - if (!imm) { - nd6log((LOG_WARNING, "in6_update_ifa: " - "addmulti failed for %s on %s (errno=%d)\n", - ip6_sprintf(&mltaddr.sin6_addr), - if_name(ifp), error)); - /* XXX not very fatal, go on... */ - } else { - LIST_INSERT_HEAD(&ia->ia6_memberships, - imm, i6mm_chain); - } + if (in6_nigroup(ifp, hostname, hostnamelen, &mltaddr) != 0) + ; + else if ((imm = in6_joingroup(ifp, &mltaddr.sin6_addr, &error, + dad_delay)) == NULL) { /* XXX jinmei */ + nd6log((LOG_WARNING, "in6_update_ifa: " + "addmulti failed for %s on %s (errno=%d)\n", + ip6_sprintf(&mltaddr.sin6_addr), + if_name(ifp), error)); + /* XXX not very fatal, go on... */ + } else { + LIST_INSERT_HEAD(&ia->ia6_memberships, imm, i6mm_chain); } @@ -1191,8 +1188,7 @@ in6_update_ifa(ifp, ifra, ia, flags) * (ff01::1%ifN, and ff01::%ifN/32) */ mltaddr.sin6_addr = in6addr_nodelocal_allnodes; - if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) - != 0) + if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0) goto cleanup; /* XXX: should not fail */ /* XXX: again, do we really need the route? */ @@ -1491,7 +1487,7 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, l) return EOPNOTSUPP; #endif } - if (sizeof(struct in6_addr) * 8 < iflr->prefixlen) + if (sizeof(struct in6_addr) * NBBY < iflr->prefixlen) return EINVAL; switch (cmd) { @@ -1911,7 +1907,7 @@ struct in6_addr *src, *dst; } break; } else - match += 8; + match += NBBY; return match; } @@ -1930,14 +1926,14 @@ in6_are_prefix_equal(p1, p2, len) return 0; } - bytelen = len / 8; - bitlen = len % 8; + bytelen = len / NBBY; + bitlen = len % NBBY; if (bcmp(&p1->s6_addr, &p2->s6_addr, bytelen)) return 0; if (bitlen != 0 && - p1->s6_addr[bytelen] >> (8 - bitlen) != - p2->s6_addr[bytelen] >> (8 - bitlen)) + p1->s6_addr[bytelen] >> (NBBY - bitlen) != + p2->s6_addr[bytelen] >> (NBBY - bitlen)) return 0; return 1; @@ -1948,7 +1944,7 @@ in6_prefixlen2mask(maskp, len) struct in6_addr *maskp; int len; { - static const u_char maskarray[8] = {0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; + static const u_char maskarray[NBBY] = {0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; int bytelen, bitlen, i; /* sanity check */ @@ -1959,8 +1955,8 @@ in6_prefixlen2mask(maskp, len) } bzero(maskp, sizeof(*maskp)); - bytelen = len / 8; - bitlen = len % 8; + bytelen = len / NBBY; + bitlen = len % NBBY; for (i = 0; i < bytelen; i++) maskp->s6_addr[i] = 0xff; if (bitlen) diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index b8ec93832d10..91b543edb0a9 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -1,4 +1,4 @@ -/* $NetBSD: in6_pcb.c,v 1.75 2006/11/16 01:33:45 christos Exp $ */ +/* $NetBSD: in6_pcb.c,v 1.76 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.75 2006/11/16 01:33:45 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.76 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -445,7 +445,7 @@ in6_pcbconnect(v, nam, l) return (error); } } - if (ifp == NULL && in6p->in6p_route.ro_rt) + if (ifp == NULL && in6p->in6p_route.ro_rt != NULL) ifp = in6p->in6p_route.ro_rt->rt_ifp; in6p->in6p_ip6.ip6_hlim = (u_int8_t)in6_selecthlim(in6p, ifp); @@ -675,7 +675,7 @@ in6_pcbnotify(table, dst, fport_arg, src, lport_arg, cmd, cmdarg, notify) */ if ((PRC_IS_REDIRECT(cmd) || cmd == PRC_HOSTDEAD) && IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr) && - in6p->in6p_route.ro_rt && + in6p->in6p_route.ro_rt != NULL && !(in6p->in6p_route.ro_rt->rt_flags & RTF_HOST)) { struct sockaddr_in6 *dst6; @@ -971,15 +971,14 @@ in6_pcbrtentry(in6p) rtalloc((struct route *)ro); } else #endif - if (ro->ro_rt == (struct rtentry *)NULL && - !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { + if (ro->ro_rt == NULL && !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_faddr)) { bzero(dst6, sizeof(*dst6)); dst6->sin6_family = AF_INET6; dst6->sin6_len = sizeof(struct sockaddr_in6); dst6->sin6_addr = in6p->in6p_faddr; rtalloc((struct route *)ro); } - return (ro->ro_rt); + return ro->ro_rt; } struct in6pcb * diff --git a/sys/netinet6/in6_src.c b/sys/netinet6/in6_src.c index 89d18bc65293..fc565a6dfb14 100644 --- a/sys/netinet6/in6_src.c +++ b/sys/netinet6/in6_src.c @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.30 2006/11/16 01:33:45 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.31 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" @@ -667,7 +667,7 @@ selectroute(dstsock, opts, mopts, ro, retifp, retrt, clone, norouteok) * by that address must be a neighbor of the sending host. */ ron = &opts->ip6po_nextroute; - if ((ron->ro_rt && + if ((ron->ro_rt != NULL && (ron->ro_rt->rt_flags & (RTF_UP | RTF_GATEWAY)) != RTF_UP) || !IN6_ARE_ADDR_EQUAL(&satosin6(&ron->ro_dst)->sin6_addr, @@ -713,8 +713,8 @@ selectroute(dstsock, opts, mopts, ro, retifp, retrt, clone, norouteok) * a new one. Note that we should check the address family of the * cached destination, in case of sharing the cache with IPv4. */ - if (ro) { - if (ro->ro_rt && + if (ro != NULL) { + if (ro->ro_rt != NULL && (!(ro->ro_rt->rt_flags & RTF_UP) || ((struct sockaddr *)(&ro->ro_dst))->sa_family != AF_INET6 || !IN6_ARE_ADDR_EQUAL(&satosin6(&ro->ro_dst)->sin6_addr, @@ -722,7 +722,7 @@ selectroute(dstsock, opts, mopts, ro, retifp, retrt, clone, norouteok) RTFREE(ro->ro_rt); ro->ro_rt = (struct rtentry *)NULL; } - if (ro->ro_rt == (struct rtentry *)NULL) { + if (ro->ro_rt == NULL) { struct sockaddr_in6 *sa6; /* No route yet, so try to acquire one */ diff --git a/sys/netinet6/in6_var.h b/sys/netinet6/in6_var.h index 56e637302f75..d217f72d4fb1 100644 --- a/sys/netinet6/in6_var.h +++ b/sys/netinet6/in6_var.h @@ -1,4 +1,4 @@ -/* $NetBSD: in6_var.h,v 1.47 2006/11/20 04:17:57 dyoung Exp $ */ +/* $NetBSD: in6_var.h,v 1.48 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: in6_var.h,v 1.81 2002/06/08 11:16:51 itojun Exp $ */ /* @@ -552,14 +552,14 @@ do { \ struct in6_ifaddr *_ia; \ \ IFP_TO_IA6((ifp), _ia); \ - if (_ia == NULL) \ + if (_ia == NULL) { \ (in6m) = NULL; \ - else \ - for ((in6m) = _ia->ia6_multiaddrs.lh_first; \ - (in6m) != NULL && \ - !IN6_ARE_ADDR_EQUAL(&(in6m)->in6m_addr, &(addr)); \ - (in6m) = (in6m)->in6m_entry.le_next) \ - continue; \ + break; \ + } \ + LIST_FOREACH((in6m), &_ia->ia6_multiaddrs, in6m_entry) {\ + if (IN6_ARE_ADDR_EQUAL(&(in6m)->in6m_addr, &(addr)))\ + break; \ + } \ } while (/*CONSTCOND*/ 0) /* @@ -573,17 +573,18 @@ do { \ /* struct in6_multistep step; */ \ /* struct in6_multi *in6m; */ \ do { \ - if (((in6m) = (step).i_in6m) != NULL) \ - (step).i_in6m = (in6m)->in6m_entry.le_next; \ - else \ - while ((step).i_ia != NULL) { \ - (in6m) = (step).i_ia->ia6_multiaddrs.lh_first; \ - (step).i_ia = (step).i_ia->ia_next; \ - if ((in6m) != NULL) { \ - (step).i_in6m = (in6m)->in6m_entry.le_next; \ - break; \ - } \ + if (((in6m) = (step).i_in6m) != NULL) { \ + (step).i_in6m = LIST_NEXT((in6m), in6m_entry); \ + break; \ + } \ + while ((step).i_ia != NULL) { \ + (in6m) = LIST_FIRST(&(step).i_ia->ia6_multiaddrs); \ + (step).i_ia = (step).i_ia->ia_next; \ + if ((in6m) != NULL) { \ + (step).i_in6m = LIST_NEXT((in6m), in6m_entry); \ + break; \ } \ + } \ } while (/*CONSTCOND*/ 0) #define IN6_FIRST_MULTI(step, in6m) \ @@ -607,51 +608,49 @@ do { \ /* struct ip6_moptions *imop */ \ /* struct in6_multi_mship *imm; */ \ do { \ - for ((imm) = (imop)->im6o_memberships.lh_first; \ - (imm) != NULL; (imm) = (imm)->i6mm_chain.le_next) { \ + LIST_FOREACH((imm), &(imop)->im6o_memberships, i6mm_chain) { \ if ((imm)->i6mm_maddr->in6m_ifp != (ifp)) \ continue; \ - if (!IN6_ARE_ADDR_EQUAL(&(imm)->i6mm_maddr->in6m_addr, \ + if (IN6_ARE_ADDR_EQUAL(&(imm)->i6mm_maddr->in6m_addr, \ &(addr))) \ - continue; \ - break; \ + break; \ } \ } while (/*CONSTCOND*/ 0) -struct in6_multi *in6_addmulti __P((struct in6_addr *, struct ifnet *, - int *, int)); -void in6_delmulti __P((struct in6_multi *)); -struct in6_multi_mship *in6_joingroup __P((struct ifnet *, struct in6_addr *, - int *, int)); -int in6_leavegroup __P((struct in6_multi_mship *)); -int in6_mask2len __P((struct in6_addr *, u_char *)); -int in6_control __P((struct socket *, u_long, caddr_t, struct ifnet *, - struct lwp *)); -int in6_update_ifa __P((struct ifnet *, struct in6_aliasreq *, - struct in6_ifaddr *, int)); -void in6_purgeaddr __P((struct ifaddr *)); -int in6if_do_dad __P((struct ifnet *)); -void in6_purgeif __P((struct ifnet *)); -void in6_savemkludge __P((struct in6_ifaddr *)); -void in6_setmaxmtu __P((void)); -int in6_if2idlen __P((struct ifnet *)); -void *in6_domifattach __P((struct ifnet *)); -void in6_domifdetach __P((struct ifnet *, void *)); -void in6_restoremkludge __P((struct in6_ifaddr *, struct ifnet *)); +struct in6_multi *in6_addmulti(struct in6_addr *, struct ifnet *, + int *, int); +void in6_delmulti(struct in6_multi *); +struct in6_multi_mship *in6_joingroup(struct ifnet *, struct in6_addr *, + int *, int); +int in6_leavegroup(struct in6_multi_mship *); +int in6_mask2len(struct in6_addr *, u_char *); +int in6_control(struct socket *, u_long, caddr_t, struct ifnet *, + struct lwp *); +int in6_update_ifa(struct ifnet *, struct in6_aliasreq *, + struct in6_ifaddr *, int); +void in6_purgeaddr(struct ifaddr *); +int in6if_do_dad(struct ifnet *); +void in6_purgeif(struct ifnet *); +void in6_savemkludge(struct in6_ifaddr *); +void in6_setmaxmtu (void); +int in6_if2idlen (struct ifnet *); +void *in6_domifattach(struct ifnet *); +void in6_domifdetach(struct ifnet *, void *); +void in6_restoremkludge(struct in6_ifaddr *, struct ifnet *); void in6_ifremloop(struct ifaddr *); void in6_ifaddloop(struct ifaddr *); -void in6_createmkludge __P((struct ifnet *)); -void in6_purgemkludge __P((struct ifnet *)); -struct in6_ifaddr *in6ifa_ifpforlinklocal __P((struct ifnet *, int)); -struct in6_ifaddr *in6ifa_ifpwithaddr __P((struct ifnet *, struct in6_addr *)); -char *ip6_sprintf __P((const struct in6_addr *)); -int in6_matchlen __P((struct in6_addr *, struct in6_addr *)); -int in6_are_prefix_equal __P((struct in6_addr *, struct in6_addr *, int)); -void in6_prefixlen2mask __P((struct in6_addr *, int)); -void in6_purgeprefix __P((struct ifnet *)); +void in6_createmkludge(struct ifnet *); +void in6_purgemkludge(struct ifnet *); +struct in6_ifaddr *in6ifa_ifpforlinklocal(struct ifnet *, int); +struct in6_ifaddr *in6ifa_ifpwithaddr(struct ifnet *, struct in6_addr *); +char *ip6_sprintf(const struct in6_addr *); +int in6_matchlen(struct in6_addr *, struct in6_addr *); +int in6_are_prefix_equal(struct in6_addr *, struct in6_addr *, int); +void in6_prefixlen2mask(struct in6_addr *, int); +void in6_purgeprefix(struct ifnet *); -int in6_src_ioctl __P((u_long, caddr_t)); -int in6_is_addr_deprecated __P((struct sockaddr_in6 *)); +int in6_src_ioctl(u_long, caddr_t); +int in6_is_addr_deprecated(struct sockaddr_in6 *); struct in6pcb; #endif /* _KERNEL */ diff --git a/sys/netinet6/ip6_forward.c b/sys/netinet6/ip6_forward.c index b6c256e078c0..e2a187115df4 100644 --- a/sys/netinet6/ip6_forward.c +++ b/sys/netinet6/ip6_forward.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_forward.c,v 1.49 2006/06/29 16:56:31 liamjfoy Exp $ */ +/* $NetBSD: ip6_forward.c,v 1.50 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: ip6_forward.c,v 1.109 2002/09/11 08:10:17 sakane Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.49 2006/06/29 16:56:31 liamjfoy Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_forward.c,v 1.50 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_ipsec.h" #include "opt_pfil_hooks.h" @@ -338,7 +338,7 @@ ip6_forward(m, srcrt) /* * ip6_forward_rt.ro_dst.sin6_addr is equal to ip6->ip6_dst */ - if (ip6_forward_rt.ro_rt == 0 || + if (ip6_forward_rt.ro_rt == NULL || (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) == 0) { if (ip6_forward_rt.ro_rt) { RTFREE(ip6_forward_rt.ro_rt); @@ -348,7 +348,7 @@ ip6_forward(m, srcrt) rtalloc((struct route *)&ip6_forward_rt); } - if (ip6_forward_rt.ro_rt == 0) { + if (ip6_forward_rt.ro_rt == NULL) { ip6stat.ip6s_noroute++; /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */ if (mcopy) { @@ -358,7 +358,7 @@ ip6_forward(m, srcrt) m_freem(m); return; } - } else if ((rt = ip6_forward_rt.ro_rt) == 0 || + } else if ((rt = ip6_forward_rt.ro_rt) == NULL || !IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &dst->sin6_addr)) { if (ip6_forward_rt.ro_rt) { RTFREE(ip6_forward_rt.ro_rt); @@ -370,7 +370,7 @@ ip6_forward(m, srcrt) dst->sin6_addr = ip6->ip6_dst; rtalloc((struct route *)&ip6_forward_rt); - if (ip6_forward_rt.ro_rt == 0) { + if (ip6_forward_rt.ro_rt == NULL) { ip6stat.ip6s_noroute++; /* XXX in6_ifstat_inc(rt->rt_ifp, ifs6_in_noroute) */ if (mcopy) { diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 11ac59720f40..b40625535408 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.90 2006/11/16 01:33:45 christos Exp $ */ +/* $NetBSD: ip6_input.c,v 1.91 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.90 2006/11/16 01:33:45 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.91 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_inet6.h" @@ -458,7 +458,7 @@ ip6_input(m) else { struct sockaddr_in6 *dst6; - if (ip6_forward_rt.ro_rt) { + if (ip6_forward_rt.ro_rt != NULL) { /* route is down or destination is different */ ip6stat.ip6s_forward_cachemiss++; RTFREE(ip6_forward_rt.ro_rt); @@ -485,7 +485,7 @@ ip6_input(m) * But we think it's even useful in some situations, e.g. when using * a special daemon which wants to intercept the packet. */ - if (ip6_forward_rt.ro_rt && + if (ip6_forward_rt.ro_rt != NULL && (ip6_forward_rt.ro_rt->rt_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST && !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) && @@ -528,7 +528,8 @@ ip6_input(m) */ #if defined(NFAITH) && 0 < NFAITH if (ip6_keepfaith) { - if (ip6_forward_rt.ro_rt && ip6_forward_rt.ro_rt->rt_ifp && + if (ip6_forward_rt.ro_rt != NULL && + ip6_forward_rt.ro_rt->rt_ifp != NULL && ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) { /* XXX do we need more sanity checks? */ ours = 1; @@ -546,9 +547,7 @@ ip6_input(m) * working right. */ struct ifaddr *ifa; - for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first; - ifa; - ifa = ifa->ifa_list.tqe_next) { + TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrlist, ifa_list) { if (ifa->ifa_addr == NULL) continue; /* just for safety */ if (ifa->ifa_addr->sa_family != AF_INET6) diff --git a/sys/netinet6/ip6_output.c b/sys/netinet6/ip6_output.c index a9d9b2d65da7..88e02715a8f0 100644 --- a/sys/netinet6/ip6_output.c +++ b/sys/netinet6/ip6_output.c @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_output.c,v 1.106 2006/11/25 18:41:36 yamt Exp $ */ +/* $NetBSD: ip6_output.c,v 1.107 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.106 2006/11/25 18:41:36 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.107 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_inet6.h" @@ -701,7 +701,7 @@ skip_ipsec2:; routefound: if (rt && !IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - if (opt && opt->ip6po_nextroute.ro_rt) { + if (opt && opt->ip6po_nextroute.ro_rt != NULL) { /* * The nexthop is explicitly specified by the * application. We assume the next hop is an IPv6 @@ -1377,7 +1377,7 @@ ip6_getpmtu(ro_pmtu, ro, ifp, dst, mtup, alwaysfragp) /* The first hop and the final destination may differ. */ struct sockaddr_in6 *sa6_dst = (struct sockaddr_in6 *)&ro_pmtu->ro_dst; - if (ro_pmtu->ro_rt && + if (ro_pmtu->ro_rt != NULL && ((ro_pmtu->ro_rt->rt_flags & RTF_UP) == 0 || !IN6_ARE_ADDR_EQUAL(&sa6_dst->sin6_addr, dst))) { RTFREE(ro_pmtu->ro_rt); @@ -1392,7 +1392,7 @@ ip6_getpmtu(ro_pmtu, ro, ifp, dst, mtup, alwaysfragp) rtalloc((struct route *)ro_pmtu); } } - if (ro_pmtu->ro_rt) { + if (ro_pmtu->ro_rt != NULL) { u_int32_t ifmtu; if (ifp == NULL) @@ -2584,9 +2584,8 @@ ip6_setmoptions(optname, im6op, m) * address, and choose the outgoing interface. * XXX: is it a good approach? */ - ro.ro_rt = NULL; + bzero(&ro, sizeof(ro)); dst = (struct sockaddr_in6 *)&ro.ro_dst; - bzero(dst, sizeof(*dst)); dst->sin6_family = AF_INET6; dst->sin6_len = sizeof(*dst); dst->sin6_addr = mreq->ipv6mr_multiaddr; diff --git a/sys/netinet6/ipsec.c b/sys/netinet6/ipsec.c index c6e10b9275ab..421bc03388bc 100644 --- a/sys/netinet6/ipsec.c +++ b/sys/netinet6/ipsec.c @@ -1,4 +1,4 @@ -/* $NetBSD: ipsec.c,v 1.110 2006/11/16 01:33:45 christos Exp $ */ +/* $NetBSD: ipsec.c,v 1.111 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: ipsec.c,v 1.136 2002/05/19 00:36:39 itojun Exp $ */ /* @@ -35,7 +35,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.110 2006/11/16 01:33:45 christos Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ipsec.c,v 1.111 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -2732,19 +2732,19 @@ ipsec4_output(struct ipsec_output_state *state, struct secpolicy *sp, state->ro = &isr->sav->sah->sa_route; state->dst = (struct sockaddr *)&state->ro->ro_dst; dst4 = (struct sockaddr_in *)state->dst; - if (state->ro->ro_rt - && ((state->ro->ro_rt->rt_flags & RTF_UP) == 0 - || dst4->sin_addr.s_addr != ip->ip_dst.s_addr)) { + if (state->ro->ro_rt != NULL && + ((state->ro->ro_rt->rt_flags & RTF_UP) == 0 || + dst4->sin_addr.s_addr != ip->ip_dst.s_addr)) { RTFREE(state->ro->ro_rt); bzero((caddr_t)state->ro, sizeof (*state->ro)); } - if (state->ro->ro_rt == 0) { + if (state->ro->ro_rt == NULL) { dst4->sin_family = AF_INET; dst4->sin_len = sizeof(*dst4); dst4->sin_addr = ip->ip_dst; rtalloc(state->ro); } - if (state->ro->ro_rt == 0) { + if (state->ro->ro_rt == NULL) { ipstat.ips_noroute++; error = EHOSTUNREACH; goto bad; @@ -3122,20 +3122,21 @@ ipsec6_output_tunnel(struct ipsec_output_state *state, struct secpolicy *sp, state->ro = &isr->sav->sah->sa_route; state->dst = (struct sockaddr *)&state->ro->ro_dst; dst6 = (struct sockaddr_in6 *)state->dst; - if (state->ro->ro_rt - && ((state->ro->ro_rt->rt_flags & RTF_UP) == 0 - || !IN6_ARE_ADDR_EQUAL(&dst6->sin6_addr, &ip6->ip6_dst))) { + if (state->ro->ro_rt != NULL && + ((state->ro->ro_rt->rt_flags & RTF_UP) == 0 || + !IN6_ARE_ADDR_EQUAL(&dst6->sin6_addr, + &ip6->ip6_dst))) { RTFREE(state->ro->ro_rt); bzero((caddr_t)state->ro, sizeof (*state->ro)); } - if (state->ro->ro_rt == 0) { + if (state->ro->ro_rt == NULL) { bzero(dst6, sizeof(*dst6)); dst6->sin6_family = AF_INET6; dst6->sin6_len = sizeof(*dst6); dst6->sin6_addr = ip6->ip6_dst; rtalloc(state->ro); } - if (state->ro->ro_rt == 0) { + if (state->ro->ro_rt == NULL) { ip6stat.ip6s_noroute++; ipsec6stat.out_noroute++; error = EHOSTUNREACH; diff --git a/sys/netinet6/nd6_nbr.c b/sys/netinet6/nd6_nbr.c index 0a5a158b2d88..ef59fecf1f11 100644 --- a/sys/netinet6/nd6_nbr.c +++ b/sys/netinet6/nd6_nbr.c @@ -1,4 +1,4 @@ -/* $NetBSD: nd6_nbr.c,v 1.65 2006/06/28 16:43:43 drochner Exp $ */ +/* $NetBSD: nd6_nbr.c,v 1.66 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $ */ /* @@ -31,7 +31,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.65 2006/06/28 16:43:43 drochner Exp $"); +__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.66 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -1185,7 +1185,7 @@ nd6_dad_stop(ifa) nd6_dad_stoptimer(dp); - TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list); + TAILQ_REMOVE(&dadq, dp, dad_list); free(dp, M_IP6NDP); dp = NULL; IFAFREE(ifa); @@ -1231,7 +1231,7 @@ nd6_dad_timer(ifa) nd6log((LOG_INFO, "%s: could not run DAD, driver problem?\n", if_name(ifa->ifa_ifp))); - TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list); + TAILQ_REMOVE(&dadq, dp, dad_list); free(dp, M_IP6NDP); dp = NULL; IFAFREE(ifa); @@ -1284,7 +1284,7 @@ nd6_dad_timer(ifa) if_name(ifa->ifa_ifp), ip6_sprintf(&ia->ia_addr.sin6_addr))); - TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list); + TAILQ_REMOVE(&dadq, dp, dad_list); free(dp, M_IP6NDP); dp = NULL; IFAFREE(ifa); @@ -1360,7 +1360,7 @@ nd6_dad_duplicated(ifa) } } - TAILQ_REMOVE(&dadq, (struct dadq *)dp, dad_list); + TAILQ_REMOVE(&dadq, dp, dad_list); free(dp, M_IP6NDP); dp = NULL; IFAFREE(ifa); diff --git a/sys/netinet6/raw_ip6.c b/sys/netinet6/raw_ip6.c index 127f28f5cade..4d2ac2160567 100644 --- a/sys/netinet6/raw_ip6.c +++ b/sys/netinet6/raw_ip6.c @@ -1,4 +1,4 @@ -/* $NetBSD: raw_ip6.c,v 1.78 2006/07/23 22:06:13 ad Exp $ */ +/* $NetBSD: raw_ip6.c,v 1.79 2006/12/02 18:59:17 dyoung Exp $ */ /* $KAME: raw_ip6.c,v 1.82 2001/07/23 18:57:56 jinmei Exp $ */ /* @@ -62,7 +62,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.78 2006/07/23 22:06:13 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: raw_ip6.c,v 1.79 2006/12/02 18:59:17 dyoung Exp $"); #include "opt_ipsec.h" @@ -695,7 +695,7 @@ rip6_usrreq(so, req, m, nam, control, l) error = EINVAL; break; } - if ((ifnet.tqh_first == 0) || (addr->sin6_family != AF_INET6)) { + if (TAILQ_EMPTY(&ifnet) || addr->sin6_family != AF_INET6) { error = EADDRNOTAVAIL; break; } @@ -736,8 +736,7 @@ rip6_usrreq(so, req, m, nam, control, l) error = EINVAL; break; } - if (ifnet.tqh_first == 0) - { + if (TAILQ_EMPTY(&ifnet)) { error = EADDRNOTAVAIL; break; }