diff options
Diffstat (limited to 'sys')
-rw-r--r-- | sys/netinet/in_gif.c | 7 | ||||
-rw-r--r-- | sys/netinet/in_gif.h | 2 | ||||
-rw-r--r-- | sys/netinet6/ah_core.c | 6 | ||||
-rw-r--r-- | sys/netinet6/ah_output.c | 2 | ||||
-rw-r--r-- | sys/netinet6/dest6.c | 1 | ||||
-rw-r--r-- | sys/netinet6/esp_core.c | 3 | ||||
-rw-r--r-- | sys/netinet6/esp_input.c | 14 | ||||
-rw-r--r-- | sys/netinet6/esp_output.c | 4 | ||||
-rw-r--r-- | sys/netinet6/frag6.c | 34 | ||||
-rw-r--r-- | sys/netinet6/icmp6.c | 345 | ||||
-rw-r--r-- | sys/netinet6/in6.c | 189 |
11 files changed, 281 insertions, 326 deletions
diff --git a/sys/netinet/in_gif.c b/sys/netinet/in_gif.c index 187b2a4a6b3b..3d2ff660a992 100644 --- a/sys/netinet/in_gif.c +++ b/sys/netinet/in_gif.c @@ -75,8 +75,8 @@ static int gif_validate4(const struct ip *, struct gif_softc *, extern struct domain inetdomain; struct protosw in_gif_protosw = -{ SOCK_RAW, &inetdomain, 0/*IPPROTO_IPV[46]*/, PR_ATOMIC|PR_ADDR, - in_gif_input, (pr_output_t*)rip_output, 0, rip_ctloutput, +{ SOCK_RAW, &inetdomain, 0/* IPPROTO_IPV[46] */, PR_ATOMIC|PR_ADDR, + in_gif_input, (pr_output_t*)rip_output, 0, rip_ctloutput, 0, 0, 0, 0, 0, &rip_usrreqs @@ -316,8 +316,7 @@ gif_validate4(ip, sc, ifp) return 0; } /* reject packets with broadcast on source */ - TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_link) - { + TAILQ_FOREACH(ia4, &in_ifaddrhead, ia_link) { if ((ia4->ia_ifa.ifa_ifp->if_flags & IFF_BROADCAST) == 0) continue; if (ip->ip_src.s_addr == ia4->ia_broadaddr.sin_addr.s_addr) diff --git a/sys/netinet/in_gif.h b/sys/netinet/in_gif.h index f2a1aec2c787..b2e3a681657c 100644 --- a/sys/netinet/in_gif.h +++ b/sys/netinet/in_gif.h @@ -36,7 +36,7 @@ #define GIF_TTL 30 struct gif_softc; -void in_gif_input(struct mbuf *, int off); +void in_gif_input(struct mbuf *, int); int in_gif_output(struct ifnet *, int, struct mbuf *); int gif_encapcheck4(const struct mbuf *, int, int, void *); int in_gif_attach(struct gif_softc *); diff --git a/sys/netinet6/ah_core.c b/sys/netinet6/ah_core.c index cbb620647ff7..2785fa0277bf 100644 --- a/sys/netinet6/ah_core.c +++ b/sys/netinet6/ah_core.c @@ -1534,8 +1534,8 @@ ah6_calccksum(m, ahdat, len, algo, sav) break; } - case IPPROTO_HOPOPTS: - case IPPROTO_DSTOPTS: + case IPPROTO_HOPOPTS: + case IPPROTO_DSTOPTS: { struct ip6_ext *ip6e; int hdrlen, optlen; @@ -1603,7 +1603,7 @@ ah6_calccksum(m, ahdat, len, algo, sav) break; } - case IPPROTO_ROUTING: + case IPPROTO_ROUTING: /* * For an input packet, we can just calculate `as is'. * For an output packet, we assume ip6_output have already diff --git a/sys/netinet6/ah_output.c b/sys/netinet6/ah_output.c index f4c4204cc332..9f31caff5a66 100644 --- a/sys/netinet6/ah_output.c +++ b/sys/netinet6/ah_output.c @@ -333,7 +333,7 @@ ah_hdrlen(sav) { const struct ah_algorithm *algo; int plen, ahlen; - + algo = ah_algorithm_lookup(sav->alg_auth); if (!algo) return 0; diff --git a/sys/netinet6/dest6.c b/sys/netinet6/dest6.c index ced896f683d6..d74b7ffe25a7 100644 --- a/sys/netinet6/dest6.c +++ b/sys/netinet6/dest6.c @@ -107,7 +107,6 @@ dest6_input(mp, offp, proto) case IP6OPT_PADN: optlen = *(opt + 1) + 2; break; - default: /* unknown option */ optlen = ip6_unknown_opt(opt, m, opt - mtod(m, u_int8_t *)); diff --git a/sys/netinet6/esp_core.c b/sys/netinet6/esp_core.c index db09b9405c40..07738ce8c698 100644 --- a/sys/netinet6/esp_core.c +++ b/sys/netinet6/esp_core.c @@ -188,7 +188,6 @@ esp_max_ivlen() if (esp_algorithms[idx].ivlenval > ivlen) ivlen = esp_algorithms[idx].ivlenval; } - return ivlen; } @@ -1131,6 +1130,6 @@ esp_auth(m0, skip, length, sav, sum) } (*algo->result)(&s, sumbuf); bcopy(sumbuf, sum, siz); /* XXX */ - + return 0; } diff --git a/sys/netinet6/esp_input.c b/sys/netinet6/esp_input.c index 43f0a61a1fdb..44f7d0c7051e 100644 --- a/sys/netinet6/esp_input.c +++ b/sys/netinet6/esp_input.c @@ -331,8 +331,8 @@ noreplaycheck: nxt = esptail.esp_nxt; taillen = esptail.esp_padlen + sizeof(esptail); - if (m->m_pkthdr.len < taillen - || m->m_pkthdr.len - taillen < hlen) { /* ? */ + if (m->m_pkthdr.len < taillen || + m->m_pkthdr.len - taillen < hlen) { /* ? */ ipseclog((LOG_WARNING, "bad pad length in IPv4 ESP input: %s %s\n", ipsec4_logpacketstr(ip, spi), ipsec_logsastr(sav))); @@ -715,14 +715,6 @@ noreplaycheck: flowinfo = ip6->ip6_flow; m_adj(m, off + esplen + ivlen); if (m->m_len < sizeof(*ip6)) { -#ifndef PULLDOWN_TEST - /* - * m_pullup is prohibited in KAME IPv6 input processing - * but there's no other way! - */ -#else - /* okay to pullup in m_pulldown style */ -#endif m = m_pullup(m, sizeof(*ip6)); if (!m) { ipsec6stat.in_inval++; @@ -743,7 +735,7 @@ noreplaycheck: } key_sa_recordxfer(sav, m); - if (ipsec_addhist(m, IPPROTO_ESP, spi) != 0 || + if (ipsec_addhist(m, IPPROTO_ESP, spi) != 0 || ipsec_addhist(m, IPPROTO_IPV6, 0) != 0) { ipsec6stat.in_nomem++; goto bad; diff --git a/sys/netinet6/esp_output.c b/sys/netinet6/esp_output.c index 0365e207502f..e47476d50bb7 100644 --- a/sys/netinet6/esp_output.c +++ b/sys/netinet6/esp_output.c @@ -357,7 +357,7 @@ esp_output(m, nexthdrp, md, isr, af) m->m_pkthdr.len += esphlen; esp = mtod(md, struct esp *); } - + nxt = *nexthdrp; *nexthdrp = IPPROTO_ESP; switch (af) { @@ -426,7 +426,7 @@ esp_output(m, nexthdrp, md, isr, af) /* ESP packet, including nxthdr field, must be length of 4n */ if (padbound < 4) padbound = 4; - + extendsiz = padbound - (plen % padbound); if (extendsiz == 1) extendsiz = padbound + 1; diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c index 96c1a1b4df9a..5fae15107956 100644 --- a/sys/netinet6/frag6.c +++ b/sys/netinet6/frag6.c @@ -192,16 +192,15 @@ frag6_input(mp, offp, proto) */ if ((ip6f->ip6f_offlg & IP6F_MORE_FRAG) && (((ntohs(ip6->ip6_plen) - offset) & 0x7) != 0)) { - icmp6_error(m, ICMP6_PARAM_PROB, - ICMP6_PARAMPROB_HEADER, - offsetof(struct ip6_hdr, ip6_plen)); + icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, + offsetof(struct ip6_hdr, ip6_plen)); in6_ifstat_inc(dstifp, ifs6_reass_fail); return IPPROTO_DONE; } ip6stat.ip6s_fragments++; in6_ifstat_inc(dstifp, ifs6_reass_reqd); - + /* offset now points to data portion */ offset += sizeof(struct ip6_frag); @@ -231,7 +230,7 @@ frag6_input(mp, offp, proto) goto dropfrag; frag6_nfragpackets++; q6 = (struct ip6q *)malloc(sizeof(struct ip6q), M_FTABLE, - M_DONTWAIT); + M_DONTWAIT); if (q6 == NULL) goto dropfrag; bzero(q6, sizeof(*q6)); @@ -257,8 +256,8 @@ frag6_input(mp, offp, proto) */ fragoff = ntohs(ip6f->ip6f_offlg & IP6F_OFF_MASK); if (fragoff == 0) { - q6->ip6q_unfrglen = offset - sizeof(struct ip6_hdr) - - sizeof(struct ip6_frag); + q6->ip6q_unfrglen = offset - sizeof(struct ip6_hdr) - + sizeof(struct ip6_frag); q6->ip6q_nxt = ip6f->ip6f_nxt; } @@ -272,16 +271,15 @@ frag6_input(mp, offp, proto) /* The 1st fragment has already arrived. */ if (q6->ip6q_unfrglen + fragoff + frgpartlen > IPV6_MAXPACKET) { icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, - offset - sizeof(struct ip6_frag) + - offsetof(struct ip6_frag, ip6f_offlg)); + offset - sizeof(struct ip6_frag) + + offsetof(struct ip6_frag, ip6f_offlg)); frag6_doing_reass = 0; return (IPPROTO_DONE); } - } - else if (fragoff + frgpartlen > IPV6_MAXPACKET) { + } else if (fragoff + frgpartlen > IPV6_MAXPACKET) { icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, - offset - sizeof(struct ip6_frag) + - offsetof(struct ip6_frag, ip6f_offlg)); + offset - sizeof(struct ip6_frag) + + offsetof(struct ip6_frag, ip6f_offlg)); frag6_doing_reass = 0; return (IPPROTO_DONE); } @@ -315,9 +313,9 @@ frag6_input(mp, offp, proto) ip6err->ip6_dst = q6->ip6q_dst; icmp6_error(merr, ICMP6_PARAM_PROB, - ICMP6_PARAMPROB_HEADER, - erroff - sizeof(struct ip6_frag) + - offsetof(struct ip6_frag, ip6f_offlg)); + ICMP6_PARAMPROB_HEADER, + erroff - sizeof(struct ip6_frag) + + offsetof(struct ip6_frag, ip6f_offlg)); } } } @@ -515,7 +513,7 @@ insert: plen += t->m_len; m->m_pkthdr.len = plen; } - + ip6stat.ip6s_reassembled++; in6_ifstat_inc(dstifp, ifs6_reass_ok); @@ -564,7 +562,7 @@ frag6_freef(q6) /* adjust pointer */ ip6 = mtod(m, struct ip6_hdr *); - /* restoure source and destination addresses */ + /* restore source and destination addresses */ ip6->ip6_src = q6->ip6q_src; ip6->ip6_dst = q6->ip6q_dst; diff --git a/sys/netinet6/icmp6.c b/sys/netinet6/icmp6.c index 07b337357145..986560a6f61a 100644 --- a/sys/netinet6/icmp6.c +++ b/sys/netinet6/icmp6.c @@ -554,7 +554,7 @@ icmp6_input(mp, offp, proto) int n0len; /* - * Prepare an internal mbuf. m_pullup() doesn't + * Prepare an internal mbuf. m_pullup() doesn't * always copy the length we specified. */ if (maxlen >= MCLBYTES) { @@ -589,7 +589,7 @@ icmp6_input(mp, offp, proto) /* new mbuf contains only ipv6+icmpv6 headers */ n->m_len = noff + sizeof(struct icmp6_hdr); /* - * Adjust mbuf. ip6_plen will be adjusted in + * Adjust mbuf. ip6_plen will be adjusted in * ip6_output(). */ m_adj(n0, off + sizeof(struct icmp6_hdr)); @@ -642,7 +642,7 @@ icmp6_input(mp, offp, proto) case MLD_MTRACE_RESP: case MLD_MTRACE: - /* XXX: these two are experimental. not officially defind. */ + /* XXX: these two are experimental. not officially defined. */ /* XXX: per-interface statistics? */ break; /* just pass it to applications */ @@ -664,7 +664,7 @@ icmp6_input(mp, offp, proto) if (mode == FQDN) { #ifndef PULLDOWN_TEST IP6_EXTHDR_CHECK(m, off, sizeof(struct icmp6_nodeinfo), - IPPROTO_DONE); + IPPROTO_DONE); #endif n = m_copy(m, 0, M_COPYALL); if (n) @@ -675,7 +675,7 @@ icmp6_input(mp, offp, proto) u_char *p; int maxlen, maxhlen; - if ((icmp6_nodeinfo & 5) != 5) + if ((icmp6_nodeinfo & 5) != 5) break; if (code != 0) @@ -887,12 +887,11 @@ icmp6_notify_error(m, off, icmp6len, code) } #ifndef PULLDOWN_TEST IP6_EXTHDR_CHECK(m, off, - sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr), - -1); + sizeof(struct icmp6_hdr) + sizeof(struct ip6_hdr), -1); icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off); #else IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off, - sizeof(*icmp6) + sizeof(struct ip6_hdr)); + sizeof(*icmp6) + sizeof(struct ip6_hdr)); if (icmp6 == NULL) { icmp6stat.icp6s_tooshort++; return (-1); @@ -905,7 +904,7 @@ icmp6_notify_error(m, off, icmp6len, code) void (*ctlfunc) __P((int, struct sockaddr *, void *)); u_int8_t nxt = eip6->ip6_nxt; int eoff = off + sizeof(struct icmp6_hdr) + - sizeof(struct ip6_hdr); + sizeof(struct ip6_hdr); struct ip6ctlparam ip6cp; struct in6_addr *finaldst = NULL; int icmp6type = icmp6->icmp6_type; @@ -922,20 +921,19 @@ icmp6_notify_error(m, off, icmp6len, code) case IPPROTO_DSTOPTS: case IPPROTO_AH: #ifndef PULLDOWN_TEST - IP6_EXTHDR_CHECK(m, 0, eoff + - sizeof(struct ip6_ext), - -1); + IP6_EXTHDR_CHECK(m, 0, + eoff + sizeof(struct ip6_ext), -1); eh = (struct ip6_ext *)(mtod(m, caddr_t) + eoff); #else IP6_EXTHDR_GET(eh, struct ip6_ext *, m, - eoff, sizeof(*eh)); + eoff, sizeof(*eh)); if (eh == NULL) { icmp6stat.icp6s_tooshort++; return (-1); } #endif - + if (nxt == IPPROTO_AH) eoff += (eh->ip6e_len + 2) << 2; else @@ -952,13 +950,12 @@ icmp6_notify_error(m, off, icmp6len, code) * destination (e.g. path MTU). */ #ifndef PULLDOWN_TEST - IP6_EXTHDR_CHECK(m, 0, eoff + sizeof(*rth), - -1); - rth = (struct ip6_rthdr *)(mtod(m, caddr_t) - + eoff); + IP6_EXTHDR_CHECK(m, 0, eoff + sizeof(*rth), -1); + rth = (struct ip6_rthdr *) + (mtod(m, caddr_t) + eoff); #else IP6_EXTHDR_GET(rth, struct ip6_rthdr *, m, - eoff, sizeof(*rth)); + eoff, sizeof(*rth)); if (rth == NULL) { icmp6stat.icp6s_tooshort++; return (-1); @@ -978,13 +975,13 @@ icmp6_notify_error(m, off, icmp6len, code) int hops; #ifndef PULLDOWN_TEST - IP6_EXTHDR_CHECK(m, 0, eoff + rthlen, - -1); - rth0 = (struct ip6_rthdr0 *)(mtod(m, caddr_t) + eoff); + IP6_EXTHDR_CHECK(m, 0, eoff + rthlen, -1); + rth0 = (struct ip6_rthdr0 *) + (mtod(m, caddr_t) + eoff); #else IP6_EXTHDR_GET(rth0, - struct ip6_rthdr0 *, m, - eoff, rthlen); + struct ip6_rthdr0 *, m, + eoff, rthlen); if (rth0 == NULL) { icmp6stat.icp6s_tooshort++; return (-1); @@ -1001,13 +998,12 @@ icmp6_notify_error(m, off, icmp6len, code) case IPPROTO_FRAGMENT: #ifndef PULLDOWN_TEST IP6_EXTHDR_CHECK(m, 0, eoff + - sizeof(struct ip6_frag), - -1); - fh = (struct ip6_frag *)(mtod(m, caddr_t) - + eoff); + sizeof(struct ip6_frag), -1); + fh = (struct ip6_frag *)(mtod(m, caddr_t) + + eoff); #else IP6_EXTHDR_GET(fh, struct ip6_frag *, m, - eoff, sizeof(*fh)); + eoff, sizeof(*fh)); if (fh == NULL) { icmp6stat.icp6s_tooshort++; return (-1); @@ -1042,14 +1038,23 @@ icmp6_notify_error(m, off, icmp6len, code) icmp6 = (struct icmp6_hdr *)(mtod(m, caddr_t) + off); #else IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off, - sizeof(*icmp6) + sizeof(struct ip6_hdr)); + sizeof(*icmp6) + sizeof(struct ip6_hdr)); if (icmp6 == NULL) { icmp6stat.icp6s_tooshort++; return (-1); } #endif + /* + * retrieve parameters from the inner IPv6 header, and convert + * them into sockaddr structures. + * XXX: there is no guarantee that the source or destination + * addresses of the inner packet are in the same scope as + * the addresses of the icmp packet. But there is no other + * way to determine the zone. + */ eip6 = (struct ip6_hdr *)(icmp6 + 1); + bzero(&icmp6dst, sizeof(icmp6dst)); icmp6dst.sin6_len = sizeof(struct sockaddr_in6); icmp6dst.sin6_family = AF_INET6; @@ -1088,8 +1093,7 @@ icmp6_notify_error(m, off, icmp6len, code) goto freeit; } #endif - icmp6src.sin6_flowinfo = - (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); + icmp6src.sin6_flowinfo = (eip6->ip6_flow & IPV6_FLOWLABEL_MASK); if (finaldst == NULL) finaldst = &eip6->ip6_dst; @@ -1108,10 +1112,10 @@ icmp6_notify_error(m, off, icmp6len, code) } ctlfunc = (void (*) __P((int, struct sockaddr *, void *))) - (inet6sw[ip6_protox[nxt]].pr_ctlinput); + (inet6sw[ip6_protox[nxt]].pr_ctlinput); if (ctlfunc) { (void) (*ctlfunc)(code, (struct sockaddr *)&icmp6dst, - &ip6cp); + &ip6cp); } } return (0); @@ -1149,8 +1153,8 @@ icmp6_mtudisc_update(ip6cp, validated) rt = rtalloc1((struct sockaddr *)&sin6, 0, RTF_CLONING | RTF_PRCLONING); - if (rt && (rt->rt_flags & RTF_HOST) - && !(rt->rt_rmx.rmx_locks & RTV_MTU)) { + if (rt && (rt->rt_flags & RTF_HOST) && + !(rt->rt_rmx.rmx_locks & RTV_MTU)) { if (mtu < IPV6_MMTU) { /* xxx */ rt->rt_rmx.rmx_locks |= RTV_MTU; @@ -1167,7 +1171,7 @@ icmp6_mtudisc_update(ip6cp, validated) /* * Process a Node Information Query packet, based on * draft-ietf-ipngwg-icmp-name-lookups-07. - * + * * Spec incompatibilities: * - IPv6 Subject address handling * - IPv4 Subject address handling support missing @@ -1203,7 +1207,7 @@ ni6_input(m, off) IP6_EXTHDR_GET(ni6, struct icmp6_nodeinfo *, m, off, sizeof(*ni6)); if (ni6 == NULL) { /* m is already reclaimed */ - return NULL; + return (NULL); } #endif @@ -1307,7 +1311,8 @@ ni6_input(m, off) * XXX if we are to allow other cases, we should really * be careful about scope here. * basically, we should disallow queries toward IPv6 - * destination X with subject Y, if scope(X) > scope(Y). + * destination X with subject Y, + * if scope(X) > scope(Y). * if we allow scope(X) > scope(Y), it will result in * information leakage across scope boundary. */ @@ -1333,7 +1338,7 @@ ni6_input(m, off) if (subj == NULL) goto bad; if (!ni6_dnsmatch(subj, subjlen, mtod(n, const char *), - n->m_len)) { + n->m_len)) { goto bad; } m_freem(n); @@ -1373,13 +1378,13 @@ ni6_input(m, off) case NI_QTYPE_NODEADDR: addrs = ni6_addrs(ni6, m, &ifp, subj); if ((replylen += addrs * (sizeof(struct in6_addr) + - sizeof(u_int32_t))) > MCLBYTES) + sizeof(u_int32_t))) > MCLBYTES) replylen = MCLBYTES; /* XXX: will truncate pkt later */ break; default: /* * XXX: We must return a reply with the ICMP6 code - * `unknown Qtype' in this case. However we regard the case + * `unknown Qtype' in this case. However we regard the case * as an FQDN query for backward compatibility. * Older versions set a random value to this field, * so it rarely varies in the defined qtypes. @@ -1439,8 +1444,7 @@ ni6_input(m, off) case NI_QTYPE_FQDN: nni6->ni_code = ICMP6_NI_SUCCESS; fqdn = (struct ni_reply_fqdn *)(mtod(n, caddr_t) + - sizeof(struct ip6_hdr) + - sizeof(struct icmp6_nodeinfo)); + sizeof(struct ip6_hdr) + sizeof(struct icmp6_nodeinfo)); nni6->ni_flags = 0; /* XXX: meaningless TTL */ fqdn->ni_fqdn_ttl = 0; /* ditto. */ /* @@ -1465,7 +1469,7 @@ ni6_input(m, off) copied = ni6_store_addrs(ni6, nni6, ifp, lenlim); /* XXX: reset mbuf length */ n->m_pkthdr.len = n->m_len = sizeof(struct ip6_hdr) + - sizeof(struct icmp6_nodeinfo) + copied; + sizeof(struct icmp6_nodeinfo) + copied; break; } default: @@ -1685,18 +1689,16 @@ ni6_addrs(ni6, m, ifpp, subj) } IFNET_RLOCK(); - for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) - { + for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) { addrsofif = 0; - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; ifa6 = (struct in6_ifaddr *)ifa; if ((niflags & NI_NODEADDR_FLAG_ALL) == 0 && IN6_ARE_ADDR_EQUAL(&subj_ip6->sin6_addr, - &ifa6->ia_addr.sin6_addr)) + &ifa6->ia_addr.sin6_addr)) iffound = 1; /* @@ -1770,14 +1772,12 @@ ni6_store_addrs(ni6, nni6, ifp0, resid) if (ifp0 == NULL && !(niflags & NI_NODEADDR_FLAG_ALL)) return (0); /* needless to copy */ - + IFNET_RLOCK(); again: - for (; ifp; ifp = TAILQ_NEXT(ifp, if_list)) - { + for (; ifp; ifp = TAILQ_NEXT(ifp, if_list)) { for (ifa = ifp->if_addrlist.tqh_first; ifa; - ifa = ifa->ifa_list.tqe_next) - { + ifa = ifa->ifa_list.tqe_next) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; ifa6 = (struct in6_ifaddr *)ifa; @@ -1794,9 +1794,8 @@ ni6_store_addrs(ni6, nni6, ifp0, resid) ifp_dep = ifp; continue; - } - else if ((ifa6->ia6_flags & IN6_IFF_DEPRECATED) == 0 && - allow_deprecated != 0) + } else if ((ifa6->ia6_flags & IN6_IFF_DEPRECATED) == 0 && + allow_deprecated != 0) continue; /* we now collect deprecated addrs */ /* What do we have to do about ::1? */ @@ -1819,7 +1818,7 @@ ni6_store_addrs(ni6, nni6, ifp0, resid) /* * check if anycast is okay. - * XXX: just experimental. not in the spec. + * XXX: just experimental. not in the spec. */ if ((ifa6->ia6_flags & IN6_IFF_ANYCAST) != 0 && (niflags & NI_NODEADDR_FLAG_ANYCAST) == 0) @@ -1836,8 +1835,7 @@ ni6_store_addrs(ni6, nni6, ifp0, resid) * We give up much more copy. * Set the truncate flag and return. */ - nni6->ni_flags |= - NI_NODEADDR_FLAG_TRUNCATE; + nni6->ni_flags |= NI_NODEADDR_FLAG_TRUNCATE; IFNET_RUNLOCK(); return (copied); } @@ -1866,21 +1864,20 @@ ni6_store_addrs(ni6, nni6, ifp0, resid) else ltime = 0; } - + bcopy(<ime, cp, sizeof(u_int32_t)); cp += sizeof(u_int32_t); /* copy the address itself */ bcopy(&ifa6->ia_addr.sin6_addr, cp, - sizeof(struct in6_addr)); + sizeof(struct in6_addr)); /* XXX: KAME link-local hack; remove ifindex */ if (IN6_IS_ADDR_LINKLOCAL(&ifa6->ia_addr.sin6_addr)) ((struct in6_addr *)cp)->s6_addr16[1] = 0; cp += sizeof(struct in6_addr); - + resid -= (sizeof(struct in6_addr) + sizeof(u_int32_t)); - copied += (sizeof(struct in6_addr) + - sizeof(u_int32_t)); + copied += (sizeof(struct in6_addr) + sizeof(u_int32_t)); } if (ifp0) /* we need search only on the specified IF */ break; @@ -1921,7 +1918,7 @@ icmp6_rip6_input(mp, off) IP6_EXTHDR_GET(icmp6, struct icmp6_hdr *, m, off, sizeof(*icmp6)); if (icmp6 == NULL) { /* m is already reclaimed */ - return IPPROTO_DONE; + return (IPPROTO_DONE); } #endif @@ -1931,8 +1928,7 @@ icmp6_rip6_input(mp, off) /* KAME hack: recover scopeid */ (void)in6_recoverscope(&rip6src, &ip6->ip6_src, m->m_pkthdr.rcvif); - LIST_FOREACH(in6p, &ripcb, inp_list) - { + LIST_FOREACH(in6p, &ripcb, inp_list) { if ((in6p->inp_vflag & INP_IPV6) == 0) continue; #ifdef HAVE_NRL_INPCB @@ -1959,8 +1955,8 @@ icmp6_rip6_input(mp, off) /* strip intermediate headers */ m_adj(n, off); if (sbappendaddr(&last->in6p_socket->so_rcv, - (struct sockaddr *)&rip6src, - n, opts) == 0) { + (struct sockaddr *)&rip6src, n, opts) + == 0) { /* should notify about lost packet */ m_freem(n); if (opts) { @@ -1979,7 +1975,7 @@ icmp6_rip6_input(mp, off) /* strip intermediate headers */ m_adj(m, off); if (sbappendaddr(&last->in6p_socket->so_rcv, - (struct sockaddr *)&rip6src, m, opts) == 0) { + (struct sockaddr *)&rip6src, m, opts) == 0) { m_freem(m); if (opts) m_freem(opts); @@ -2120,9 +2116,9 @@ icmp6_reflect(m, off) } #endif /* - * If the incoming packet was addressed directly to us(i.e. unicast), + * If the incoming packet was addressed directly to us (i.e. unicast), * use dst as the src for the reply. - * The IN6_IFF_NOTREADY case would be VERY rare, but is possible + * The IN6_IFF_NOTREADY case should be VERY rare, but is possible * (for example) when we encounter an error while forwarding procedure * destined to a duplicated address of ours. */ @@ -2176,7 +2172,7 @@ icmp6_reflect(m, off) icmp6->icmp6_cksum = 0; icmp6->icmp6_cksum = in6_cksum(m, IPPROTO_ICMPV6, - sizeof(struct ip6_hdr), plen); + sizeof(struct ip6_hdr), plen); /* * XXX option handling @@ -2214,7 +2210,7 @@ icmp6_redirect_diag(src6, dst6, tgt6) { static char buf[1024]; snprintf(buf, sizeof(buf), "(src=%s dst=%s tgt=%s)", - ip6_sprintf(src6), ip6_sprintf(dst6), ip6_sprintf(tgt6)); + ip6_sprintf(src6), ip6_sprintf(dst6), ip6_sprintf(tgt6)); return buf; } @@ -2269,15 +2265,16 @@ icmp6_redirect_input(m, off) /* validation */ if (!IN6_IS_ADDR_LINKLOCAL(&src6)) { nd6log((LOG_ERR, - "ICMP6 redirect sent from %s rejected; " - "must be from linklocal\n", ip6_sprintf(&src6))); + "ICMP6 redirect sent from %s rejected; " + "must be from linklocal\n", + ip6_sprintf(&src6))); goto bad; } if (ip6->ip6_hlim != 255) { nd6log((LOG_ERR, - "ICMP6 redirect sent from %s rejected; " - "hlim=%d (must be 255)\n", - ip6_sprintf(&src6), ip6->ip6_hlim)); + "ICMP6 redirect sent from %s rejected; " + "hlim=%d (must be 255)\n", + ip6_sprintf(&src6), ip6->ip6_hlim)); goto bad; } { @@ -2304,19 +2301,19 @@ icmp6_redirect_input(m, off) gw6 = &(((struct sockaddr_in6 *)rt->rt_gateway)->sin6_addr); if (bcmp(&src6, gw6, sizeof(struct in6_addr)) != 0) { nd6log((LOG_ERR, - "ICMP6 redirect rejected; " - "not equal to gw-for-src=%s (must be same): " - "%s\n", - ip6_sprintf(gw6), - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "ICMP6 redirect rejected; " + "not equal to gw-for-src=%s (must be same): " + "%s\n", + ip6_sprintf(gw6), + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); RTFREE_LOCKED(rt); goto bad; } } else { nd6log((LOG_ERR, - "ICMP6 redirect rejected; " - "no route found for redirect dst: %s\n", - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "ICMP6 redirect rejected; " + "no route found for redirect dst: %s\n", + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); goto bad; } RTFREE_LOCKED(rt); @@ -2324,9 +2321,9 @@ icmp6_redirect_input(m, off) } if (IN6_IS_ADDR_MULTICAST(&reddst6)) { nd6log((LOG_ERR, - "ICMP6 redirect rejected; " - "redirect dst must be unicast: %s\n", - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "ICMP6 redirect rejected; " + "redirect dst must be unicast: %s\n", + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); goto bad; } @@ -2337,9 +2334,9 @@ icmp6_redirect_input(m, off) is_onlink = 1; /* on-link destination case */ if (!is_router && !is_onlink) { nd6log((LOG_ERR, - "ICMP6 redirect rejected; " - "neither router case nor onlink case: %s\n", - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "ICMP6 redirect rejected; " + "neither router case nor onlink case: %s\n", + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); goto bad; } /* validation passed */ @@ -2348,8 +2345,8 @@ icmp6_redirect_input(m, off) nd6_option_init(nd_rd + 1, icmp6len, &ndopts); if (nd6_options(&ndopts) < 0) { nd6log((LOG_INFO, "icmp6_redirect_input: " - "invalid ND option, rejected: %s\n", - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "invalid ND option, rejected: %s\n", + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); /* nd6_options have incremented stats */ goto freeit; } @@ -2366,16 +2363,16 @@ icmp6_redirect_input(m, off) if (lladdr && ((ifp->if_addrlen + 2 + 7) & ~7) != lladdrlen) { nd6log((LOG_INFO, - "icmp6_redirect_input: lladdrlen mismatch for %s " - "(if %d, icmp6 packet %d): %s\n", - ip6_sprintf(&redtgt6), ifp->if_addrlen, lladdrlen - 2, - icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); + "icmp6_redirect_input: lladdrlen mismatch for %s " + "(if %d, icmp6 packet %d): %s\n", + ip6_sprintf(&redtgt6), ifp->if_addrlen, lladdrlen - 2, + icmp6_redirect_diag(&src6, &reddst6, &redtgt6))); goto bad; } /* RFC 2461 8.3 */ nd6_cache_lladdr(ifp, &redtgt6, lladdr, lladdrlen, ND_REDIRECT, - is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER); + is_onlink ? ND_REDIRECT_ONLINK : ND_REDIRECT_ROUTER); if (!is_onlink) { /* better router case. perform rtredirect. */ /* perform rtredirect */ @@ -2393,8 +2390,8 @@ icmp6_redirect_input(m, off) bcopy(&reddst6, &sdst.sin6_addr, sizeof(struct in6_addr)); bcopy(&src6, &ssrc.sin6_addr, sizeof(struct in6_addr)); rtredirect((struct sockaddr *)&sdst, (struct sockaddr *)&sgw, - (struct sockaddr *)NULL, RTF_GATEWAY | RTF_HOST, - (struct sockaddr *)&ssrc); + (struct sockaddr *)NULL, RTF_GATEWAY | RTF_HOST, + (struct sockaddr *)&ssrc); } /* finally update cached route in each socket via pfctlinput */ { @@ -2593,78 +2590,82 @@ nolladdropt:; if (p - (u_char *)ip6 > maxlen) goto noredhdropt; - { - /* redirected header option */ - int len; - struct nd_opt_rd_hdr *nd_opt_rh; + { + /* redirected header option */ + int len; + struct nd_opt_rd_hdr *nd_opt_rh; - /* - * compute the maximum size for icmp6 redirect header option. - * XXX room for auth header? - */ - len = maxlen - (p - (u_char *)ip6); - len &= ~7; - - /* This is just for simplicity. */ - if (m0->m_pkthdr.len != m0->m_len) { - if (m0->m_next) { - m_freem(m0->m_next); - m0->m_next = NULL; + /* + * compute the maximum size for icmp6 redirect header option. + * XXX room for auth header? + */ + len = maxlen - (p - (u_char *)ip6); + len &= ~7; + + /* This is just for simplicity. */ + if (m0->m_pkthdr.len != m0->m_len) { + if (m0->m_next) { + m_freem(m0->m_next); + m0->m_next = NULL; + } + m0->m_pkthdr.len = m0->m_len; } - m0->m_pkthdr.len = m0->m_len; - } - /* - * Redirected header option spec (RFC2461 4.6.3) talks nothing - * about padding/truncate rule for the original IP packet. - * From the discussion on IPv6imp in Feb 1999, the consensus was: - * - "attach as much as possible" is the goal - * - pad if not aligned (original size can be guessed by original - * ip6 header) - * Following code adds the padding if it is simple enough, - * and truncates if not. - */ - if (m0->m_next || m0->m_pkthdr.len != m0->m_len) - panic("assumption failed in %s:%d", __FILE__, __LINE__); - - if (len - sizeof(*nd_opt_rh) < m0->m_pkthdr.len) { - /* not enough room, truncate */ - m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh); - } else { - /* enough room, pad or truncate */ - size_t extra; - - extra = m0->m_pkthdr.len % 8; - if (extra) { - /* pad if easy enough, truncate if not */ - if (8 - extra <= M_TRAILINGSPACE(m0)) { - /* pad */ - m0->m_len += (8 - extra); - m0->m_pkthdr.len += (8 - extra); - } else { - /* truncate */ - m0->m_pkthdr.len -= extra; - m0->m_len -= extra; + /* + * Redirected header option spec (RFC2461 4.6.3) talks nothing + * about padding/truncate rule for the original IP packet. + * From the discussion on IPv6imp in Feb 1999, + * the consensus was: + * - "attach as much as possible" is the goal + * - pad if not aligned (original size can be guessed by + * original ip6 header) + * Following code adds the padding if it is simple enough, + * and truncates if not. + */ + if (m0->m_next || m0->m_pkthdr.len != m0->m_len) + panic("assumption failed in %s:%d", __FILE__, + __LINE__); + + if (len - sizeof(*nd_opt_rh) < m0->m_pkthdr.len) { + /* not enough room, truncate */ + m0->m_pkthdr.len = m0->m_len = len - + sizeof(*nd_opt_rh); + } else { + /* enough room, pad or truncate */ + size_t extra; + + extra = m0->m_pkthdr.len % 8; + if (extra) { + /* pad if easy enough, truncate if not */ + if (8 - extra <= M_TRAILINGSPACE(m0)) { + /* pad */ + m0->m_len += (8 - extra); + m0->m_pkthdr.len += (8 - extra); + } else { + /* truncate */ + m0->m_pkthdr.len -= extra; + m0->m_len -= extra; + } } + len = m0->m_pkthdr.len + sizeof(*nd_opt_rh); + m0->m_pkthdr.len = m0->m_len = len - + sizeof(*nd_opt_rh); } - len = m0->m_pkthdr.len + sizeof(*nd_opt_rh); - m0->m_pkthdr.len = m0->m_len = len - sizeof(*nd_opt_rh); - } - nd_opt_rh = (struct nd_opt_rd_hdr *)p; - bzero(nd_opt_rh, sizeof(*nd_opt_rh)); - nd_opt_rh->nd_opt_rh_type = ND_OPT_REDIRECTED_HEADER; - nd_opt_rh->nd_opt_rh_len = len >> 3; - p += sizeof(*nd_opt_rh); - m->m_pkthdr.len = m->m_len = p - (u_char *)ip6; - - /* connect m0 to m */ - m_tag_delete_chain(m0, NULL); - m0->m_flags &= ~M_PKTHDR; - m->m_next = m0; - m->m_pkthdr.len = m->m_len + m0->m_len; - m0 = NULL; - } + nd_opt_rh = (struct nd_opt_rd_hdr *)p; + bzero(nd_opt_rh, sizeof(*nd_opt_rh)); + nd_opt_rh->nd_opt_rh_type = ND_OPT_REDIRECTED_HEADER; + nd_opt_rh->nd_opt_rh_len = len >> 3; + p += sizeof(*nd_opt_rh); + m->m_pkthdr.len = m->m_len = p - (u_char *)ip6; + + /* connect m0 to m */ + m_tag_delete_chain(m0, NULL); + m0->m_flags &= ~M_PKTHDR; + m->m_next = m0; + m->m_pkthdr.len = m->m_len + m0->m_len; + m0 = NULL; + } noredhdropt:; if (m0) { m_freem(m0); @@ -2689,8 +2690,8 @@ noredhdropt:; ip6->ip6_plen = htons(m->m_pkthdr.len - sizeof(struct ip6_hdr)); nd_rd->nd_rd_cksum = 0; - nd_rd->nd_rd_cksum - = in6_cksum(m, IPPROTO_ICMPV6, sizeof(*ip6), ntohs(ip6->ip6_plen)); + nd_rd->nd_rd_cksum = in6_cksum(m, IPPROTO_ICMPV6, + sizeof(*ip6), ntohs(ip6->ip6_plen)); /* send the packet to outside... */ ip6_output(m, NULL, NULL, 0, NULL, &outif, NULL); diff --git a/sys/netinet6/in6.c b/sys/netinet6/in6.c index a887c35019f5..a60d0532301c 100644 --- a/sys/netinet6/in6.c +++ b/sys/netinet6/in6.c @@ -133,11 +133,10 @@ const struct sockaddr_in6 sa6_any = {sizeof(sa6_any), AF_INET6, static int in6_lifaddr_ioctl __P((struct socket *, u_long, caddr_t, struct ifnet *, struct thread *)); static int in6_ifinit __P((struct ifnet *, struct in6_ifaddr *, - struct sockaddr_in6 *, int)); + struct sockaddr_in6 *, int)); static void in6_unlink_ifa __P((struct in6_ifaddr *, struct ifnet *)); struct in6_multihead in6_multihead; /* XXX BSS initialization */ - int (*faithprefix_p)(struct in6_addr *); /* @@ -150,7 +149,7 @@ in6_ifloop_request(int cmd, struct ifaddr *ifa) struct sockaddr_in6 all1_sa; struct rtentry *nrt = NULL; int e; - + bzero(&all1_sa, sizeof(all1_sa)); all1_sa.sin6_family = AF_INET6; all1_sa.sin6_len = sizeof(struct sockaddr_in6); @@ -165,9 +164,9 @@ in6_ifloop_request(int cmd, struct ifaddr *ifa) * which changes the outgoing interface to the loopback interface. */ e = rtrequest(cmd, ifa->ifa_addr, ifa->ifa_addr, - (struct sockaddr *)&all1_sa, - RTF_UP|RTF_HOST|RTF_LLINFO, &nrt); + (struct sockaddr *)&all1_sa, RTF_UP|RTF_HOST|RTF_LLINFO, &nrt); if (e != 0) { + /* XXX need more descriptive message */ log(LOG_ERR, "in6_ifloop_request: " "%s operation failed for %s (errno=%d)\n", cmd == RTM_ADD ? "ADD" : "DELETE", @@ -269,7 +268,7 @@ in6_ifremloop(struct ifaddr *ifa) * Before deleting, check if a corresponding loopbacked host * route surely exists. With this check, we can avoid to * delete an interface direct route whose destination is same - * as the address being removed. This can happen when remofing + * as the address being removed. This can happen when removing * a subnet-router anycast address on an interface attahced * to a shared medium. */ @@ -317,8 +316,8 @@ in6_mask2len(mask, lim0) int x = 0, y; u_char *lim = lim0, *p; - if (lim0 == NULL || - lim0 - (u_char *)mask > sizeof(*mask)) /* ignore the scope_id part */ + /* ignore the scope_id part */ + if (lim0 == NULL || lim0 - (u_char *)mask > sizeof(*mask)) lim = (u_char *)mask + sizeof(*mask); for (p = (u_char *)mask; p < lim; x++, p++) { if (*p != 0xff) @@ -343,7 +342,7 @@ in6_mask2len(mask, lim0) if (*p != 0) return (-1); } - + return x * 8 + y; } @@ -398,7 +397,7 @@ in6_control(so, cmd, data, ifp, td) case SIOCSIFINFO_FLAGS: if (!privileged) return (EPERM); - /* fall through */ + /* FALLTHROUGH */ case OSIOCGIFINFO_IN6: case SIOCGIFINFO_IN6: case SIOCGDRLST_IN6: @@ -440,7 +439,7 @@ in6_control(so, cmd, data, ifp, td) case SIOCDLIFADDR: if (!privileged) return (EPERM); - /* fall through */ + /* FALLTHROUGH */ case SIOCGLIFADDR: return in6_lifaddr_ioctl(so, cmd, data, ifp, td); } @@ -456,9 +455,9 @@ in6_control(so, cmd, data, ifp, td) if (sa6->sin6_addr.s6_addr16[1] == 0) { /* link ID is not embedded by the user */ sa6->sin6_addr.s6_addr16[1] = - htons(ifp->if_index); + htons(ifp->if_index); } else if (sa6->sin6_addr.s6_addr16[1] != - htons(ifp->if_index)) { + htons(ifp->if_index)) { return (EINVAL); /* link ID contradicts */ } if (sa6->sin6_scope_id) { @@ -509,7 +508,7 @@ in6_control(so, cmd, data, ifp, td) case SIOCGIFADDR_IN6: /* This interface is basically deprecated. use SIOCGIFCONF. */ - /* fall through */ + /* FALLTHROUGH */ case SIOCGIFAFLAG_IN6: case SIOCGIFNETMASK_IN6: case SIOCGIFDSTADDR_IN6: @@ -571,7 +570,7 @@ in6_control(so, cmd, data, ifp, td) || in6_ifstat[ifp->if_index] == NULL) { /* return EAFNOSUPPORT? */ bzero(&ifr->ifr_ifru.ifru_stat, - sizeof(ifr->ifr_ifru.ifru_stat)); + sizeof(ifr->ifr_ifru.ifru_stat)); } else ifr->ifr_ifru.ifru_stat = *in6_ifstat[ifp->if_index]; break; @@ -583,7 +582,7 @@ in6_control(so, cmd, data, ifp, td) icmp6_ifstat[ifp->if_index] == NULL) { /* return EAFNOSUPPORT? */ bzero(&ifr->ifr_ifru.ifru_stat, - sizeof(ifr->ifr_ifru.ifru_icmp6stat)); + sizeof(ifr->ifr_ifru.ifru_icmp6stat)); } else ifr->ifr_ifru.ifru_icmp6stat = *icmp6_ifstat[ifp->if_index]; @@ -634,15 +633,16 @@ in6_control(so, cmd, data, ifp, td) bzero(&pr0, sizeof(pr0)); pr0.ndpr_ifp = ifp; pr0.ndpr_plen = in6_mask2len(&ifra->ifra_prefixmask.sin6_addr, - NULL); - if (pr0.ndpr_plen == 128) + NULL); + if (pr0.ndpr_plen == 128) { break; /* we don't need to install a host route. */ + } pr0.ndpr_prefix = ifra->ifra_addr; pr0.ndpr_mask = ifra->ifra_prefixmask.sin6_addr; /* apply the mask for safety. */ for (i = 0; i < 4; i++) { pr0.ndpr_prefix.sin6_addr.s6_addr32[i] &= - ifra->ifra_prefixmask.sin6_addr.s6_addr32[i]; + ifra->ifra_prefixmask.sin6_addr.s6_addr32[i]; } /* * XXX: since we don't have an API to set prefix (not address) @@ -653,11 +653,11 @@ in6_control(so, cmd, data, ifp, td) */ pr0.ndpr_raf_onlink = 1; /* should be configurable? */ pr0.ndpr_raf_auto = - ((ifra->ifra_flags & IN6_IFF_AUTOCONF) != 0); + ((ifra->ifra_flags & IN6_IFF_AUTOCONF) != 0); pr0.ndpr_vltime = ifra->ifra_lifetime.ia6t_vltime; pr0.ndpr_pltime = ifra->ifra_lifetime.ia6t_pltime; - /* add the prefix if there's one. */ + /* add the prefix if not yet. */ if ((pr = nd6_prefix_lookup(&pr0)) == NULL) { /* * nd6_prelist_add will install the corresponding @@ -666,7 +666,7 @@ in6_control(so, cmd, data, ifp, td) if ((error = nd6_prelist_add(&pr0, NULL, &pr)) != 0) return (error); if (pr == NULL) { - log(LOG_ERR, "nd6_prelist_add succedded but " + log(LOG_ERR, "nd6_prelist_add succeeded but " "no prefix\n"); return (EINVAL); /* XXX panic here? */ } @@ -718,7 +718,7 @@ in6_control(so, cmd, data, ifp, td) /* * If the address being deleted is the only one that owns * the corresponding prefix, expire the prefix as well. - * XXX: theoretically, we don't have to warry about such + * XXX: theoretically, we don't have to worry about such * relationship, since we separate the address management * and the prefix management. We do this, however, to provide * as much backward compatibility as possible in terms of @@ -811,12 +811,11 @@ in6_update_ifa(ifp, ifra, ia) return (EINVAL); if (ifra->ifra_prefixmask.sin6_len != 0) { plen = in6_mask2len(&ifra->ifra_prefixmask.sin6_addr, - (u_char *)&ifra->ifra_prefixmask + - ifra->ifra_prefixmask.sin6_len); + (u_char *)&ifra->ifra_prefixmask + + ifra->ifra_prefixmask.sin6_len); if (plen <= 0) return (EINVAL); - } - else { + } else { /* * In this case, ia must not be NULL. We just use its prefix * length. @@ -829,14 +828,13 @@ in6_update_ifa(ifp, ifra, ia) * zone identifier. */ dst6 = ifra->ifra_dstaddr; - if ((ifp->if_flags & (IFF_POINTOPOINT|IFF_LOOPBACK)) && + if ((ifp->if_flags & (IFF_POINTOPOINT|IFF_LOOPBACK)) != 0 && (dst6.sin6_family == AF_INET6)) { int scopeid; #ifndef SCOPEDROUTING if ((error = in6_recoverscope(&dst6, - &ifra->ifra_dstaddr.sin6_addr, - ifp)) != 0) + &ifra->ifra_dstaddr.sin6_addr, ifp)) != 0) return (error); #endif scopeid = in6_addr2scopeid(ifp, &dst6.sin6_addr); @@ -901,11 +899,11 @@ in6_update_ifa(ifp, ifra, ia) hostIsNew = 1; /* * When in6_update_ifa() is called in a process of a received - * RA, it is called under splnet(). So, we should call malloc - * with M_NOWAIT. + * RA, it is called under an interrupt context. So, we should + * call malloc with M_NOWAIT. */ - ia = (struct in6_ifaddr *) - malloc(sizeof(*ia), M_IFADDR, M_NOWAIT); + ia = (struct in6_ifaddr *) malloc(sizeof(*ia), M_IFADDR, + M_NOWAIT); if (ia == NULL) return (ENOBUFS); bzero((caddr_t)ia, sizeof(*ia)); @@ -919,8 +917,8 @@ in6_update_ifa(ifp, ifra, ia) * XXX: some functions expect that ifa_dstaddr is not * NULL for p2p interfaces. */ - ia->ia_ifa.ifa_dstaddr - = (struct sockaddr *)&ia->ia_dstaddr; + ia->ia_ifa.ifa_dstaddr = + (struct sockaddr *)&ia->ia_dstaddr; } else { ia->ia_ifa.ifa_dstaddr = NULL; } @@ -960,22 +958,19 @@ in6_update_ifa(ifp, ifra, ia) /* * If a new destination address is specified, scrub the old one and * install the new destination. Note that the interface must be - * p2p or loopback (see the check above.) + * p2p or loopback (see the check above.) */ if (dst6.sin6_family == AF_INET6 && - !IN6_ARE_ADDR_EQUAL(&dst6.sin6_addr, - &ia->ia_dstaddr.sin6_addr)) { + !IN6_ARE_ADDR_EQUAL(&dst6.sin6_addr, &ia->ia_dstaddr.sin6_addr)) { int e; if ((ia->ia_flags & IFA_ROUTE) != 0 && - (e = rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST)) - != 0) { + (e = rtinit(&(ia->ia_ifa), (int)RTM_DELETE, RTF_HOST)) != 0) { log(LOG_ERR, "in6_update_ifa: failed to remove " "a route to the old destination: %s\n", ip6_sprintf(&ia->ia_addr.sin6_addr)); /* proceed anyway... */ - } - else + } else ia->ia_flags &= ~IFA_ROUTE; ia->ia_dstaddr = dst6; } @@ -986,32 +981,17 @@ in6_update_ifa(ifp, ifra, ia) /* * Beyond this point, we should call in6_purgeaddr upon an error, - * not just go to unlink. + * not just go to unlink. */ -#if 0 /* disable this mechanism for now */ - /* update prefix list */ - if (hostIsNew && - (ifra->ifra_flags & IN6_IFF_NOPFX) == 0) { /* XXX */ - int iilen; - - iilen = (sizeof(ia->ia_prefixmask.sin6_addr) << 3) - plen; - if ((error = in6_prefix_add_ifid(iilen, ia)) != 0) { - in6_purgeaddr((struct ifaddr *)ia); - return (error); - } - } -#endif - if ((ifp->if_flags & IFF_MULTICAST) != 0) { struct sockaddr_in6 mltaddr, mltmask; struct in6_multi *in6m; if (hostIsNew) { - /* - * join solicited multicast addr for new host id - */ + /* join solicited multicast addr for new host id */ struct in6_addr llsol; + bzero(&llsol, sizeof(struct in6_addr)); llsol.s6_addr16[0] = htons(0xff02); llsol.s6_addr16[1] = htons(ifp->if_index); @@ -1191,8 +1171,7 @@ in6_purgeaddr(ifa) ip6_sprintf(&ia->ia_addr.sin6_addr), if_name(ifp), e); /* proceed anyway... */ - } - else + } else ia->ia_flags &= ~IFA_ROUTE; } @@ -1287,8 +1266,7 @@ in6_purgeif(ifp) { struct ifaddr *ifa, *nifa; - for (ifa = TAILQ_FIRST(&ifp->if_addrlist); ifa != NULL; ifa = nifa) - { + for (ifa = TAILQ_FIRST(&ifp->if_addrlist); ifa != NULL; ifa = nifa) { nifa = TAILQ_NEXT(ifa, ifa_list); if (ifa->ifa_addr->sa_family != AF_INET6) continue; @@ -1336,7 +1314,7 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, td) /* sanity checks */ if (!data || !ifp) { panic("invalid argument to in6_lifaddr_ioctl"); - /*NOTRECHED*/ + /* NOTREACHED */ } switch (cmd) { @@ -1407,27 +1385,26 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, td) /* copy args to in6_aliasreq, perform ioctl(SIOCAIFADDR_IN6). */ bzero(&ifra, sizeof(ifra)); - bcopy(iflr->iflr_name, ifra.ifra_name, - sizeof(ifra.ifra_name)); + bcopy(iflr->iflr_name, ifra.ifra_name, sizeof(ifra.ifra_name)); bcopy(&iflr->addr, &ifra.ifra_addr, - ((struct sockaddr *)&iflr->addr)->sa_len); + ((struct sockaddr *)&iflr->addr)->sa_len); if (hostid) { /* fill in hostid part */ ifra.ifra_addr.sin6_addr.s6_addr32[2] = - hostid->s6_addr32[2]; + hostid->s6_addr32[2]; ifra.ifra_addr.sin6_addr.s6_addr32[3] = - hostid->s6_addr32[3]; + hostid->s6_addr32[3]; } - if (((struct sockaddr *)&iflr->dstaddr)->sa_family) { /*XXX*/ + if (((struct sockaddr *)&iflr->dstaddr)->sa_family) { /* XXX */ bcopy(&iflr->dstaddr, &ifra.ifra_dstaddr, - ((struct sockaddr *)&iflr->dstaddr)->sa_len); + ((struct sockaddr *)&iflr->dstaddr)->sa_len); if (hostid) { ifra.ifra_dstaddr.sin6_addr.s6_addr32[2] = - hostid->s6_addr32[2]; + hostid->s6_addr32[2]; ifra.ifra_dstaddr.sin6_addr.s6_addr32[3] = - hostid->s6_addr32[3]; + hostid->s6_addr32[3]; } } @@ -1476,8 +1453,7 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, td) } } - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; if (!cmp) @@ -1516,27 +1492,26 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, td) if (IN6_IS_ADDR_LINKLOCAL(&s6->sin6_addr)) { s6->sin6_addr.s6_addr16[1] = 0; s6->sin6_scope_id = - in6_addr2scopeid(ifp, &s6->sin6_addr); + in6_addr2scopeid(ifp, &s6->sin6_addr); } #endif if ((ifp->if_flags & IFF_POINTOPOINT) != 0) { bcopy(&ia->ia_dstaddr, &iflr->dstaddr, - ia->ia_dstaddr.sin6_len); + ia->ia_dstaddr.sin6_len); #ifndef SCOPEDROUTING /* XXX see above */ s6 = (struct sockaddr_in6 *)&iflr->dstaddr; if (IN6_IS_ADDR_LINKLOCAL(&s6->sin6_addr)) { s6->sin6_addr.s6_addr16[1] = 0; s6->sin6_scope_id = - in6_addr2scopeid(ifp, - &s6->sin6_addr); + in6_addr2scopeid(ifp, + &s6->sin6_addr); } #endif } else bzero(&iflr->dstaddr, sizeof(iflr->dstaddr)); iflr->prefixlen = - in6_mask2len(&ia->ia_prefixmask.sin6_addr, - NULL); + in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); iflr->flags = ia->ia6_flags; /* XXX */ @@ -1547,23 +1522,23 @@ in6_lifaddr_ioctl(so, cmd, data, ifp, td) /* fill in6_aliasreq and do ioctl(SIOCDIFADDR_IN6) */ bzero(&ifra, sizeof(ifra)); bcopy(iflr->iflr_name, ifra.ifra_name, - sizeof(ifra.ifra_name)); + sizeof(ifra.ifra_name)); bcopy(&ia->ia_addr, &ifra.ifra_addr, - ia->ia_addr.sin6_len); + ia->ia_addr.sin6_len); if ((ifp->if_flags & IFF_POINTOPOINT) != 0) { bcopy(&ia->ia_dstaddr, &ifra.ifra_dstaddr, - ia->ia_dstaddr.sin6_len); + ia->ia_dstaddr.sin6_len); } else { bzero(&ifra.ifra_dstaddr, sizeof(ifra.ifra_dstaddr)); } bcopy(&ia->ia_prefixmask, &ifra.ifra_dstaddr, - ia->ia_prefixmask.sin6_len); + ia->ia_prefixmask.sin6_len); ifra.ifra_flags = ia->ia6_flags; return in6_control(so, SIOCDIFADDR_IN6, (caddr_t)&ifra, - ifp, td); + ifp, td); } } } @@ -1591,8 +1566,7 @@ in6_ifinit(ifp, ia, sin6, newhost) * if this is its first address, * and to validate the address if necessary. */ - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr == NULL) continue; /* just for safety */ if (ifa->ifa_addr->sa_family != AF_INET6) @@ -1698,7 +1672,7 @@ in6_addmulti(maddr6, ifp, errorp) LIST_INSERT_HEAD(&in6_multihead, in6m, in6m_entry); /* - * Let MLD6 know that we have joined a new IP6 multicast + * Let MLD6 know that we have joined a new IPv6 multicast * group. */ mld6_start_listening(in6m); @@ -1741,8 +1715,7 @@ in6ifa_ifpforlinklocal(ifp, ignoreflags) { struct ifaddr *ifa; - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr == NULL) continue; /* just for safety */ if (ifa->ifa_addr->sa_family != AF_INET6) @@ -1769,8 +1742,7 @@ in6ifa_ifpwithaddr(ifp, addr) { struct ifaddr *ifa; - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr == NULL) continue; /* just for safety */ if (ifa->ifa_addr->sa_family != AF_INET6) @@ -1845,10 +1817,12 @@ in6_localaddr(in6) if (IN6_IS_ADDR_LOOPBACK(in6) || IN6_IS_ADDR_LINKLOCAL(in6)) return 1; - for (ia = in6_ifaddr; ia; ia = ia->ia_next) + for (ia = in6_ifaddr; ia; ia = ia->ia_next) { if (IN6_ARE_MASKED_ADDR_EQUAL(in6, &ia->ia_addr.sin6_addr, - &ia->ia_prefixmask.sin6_addr)) + &ia->ia_prefixmask.sin6_addr)) { return 1; + } + } return (0); } @@ -1962,11 +1936,8 @@ in6_ifawithscope(oifp, dst) struct ifaddr *ifa; struct ifnet *ifp; struct in6_ifaddr *ifa_best = NULL; - + if (oifp == NULL) { -#if 0 - printf("in6_ifawithscope: output interface is not specified\n"); -#endif return (NULL); } @@ -2252,8 +2223,7 @@ in6_ifawithifp(ifp, dst) * If two or more, return one which matches the dst longest. * If none, return one of global addresses assigned other ifs. */ - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; if (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_ANYCAST) @@ -2287,8 +2257,7 @@ in6_ifawithifp(ifp, dst) if (besta) return (besta); - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; if (((struct in6_ifaddr *)ifa)->ia6_flags & IN6_IFF_ANYCAST) @@ -2332,8 +2301,7 @@ in6_if_up(ifp) in6_ifattach(ifp, NULL); dad_delay = 0; - TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) - { + TAILQ_FOREACH(ifa, &ifp->if_addrlist, ifa_list) { if (ifa->ifa_addr->sa_family != AF_INET6) continue; ia = (struct in6_ifaddr *)ifa; @@ -2390,14 +2358,13 @@ in6_setmaxmtu() struct ifnet *ifp; IFNET_RLOCK(); - for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) - { + for (ifp = TAILQ_FIRST(&ifnet); ifp; ifp = TAILQ_NEXT(ifp, if_list)) { if ((ifp->if_flags & IFF_LOOPBACK) == 0 && nd_ifinfo[ifp->if_index].linkmtu > maxmtu) maxmtu = nd_ifinfo[ifp->if_index].linkmtu; } IFNET_RUNLOCK(); - if (maxmtu) /* update only when maxmtu is positive */ + if (maxmtu) /* update only when maxmtu is positive */ in6_maxmtu = maxmtu; } @@ -2412,7 +2379,7 @@ in6_sin6_2_sin(struct sockaddr_in *sin, struct sockaddr_in6 *sin6) sin->sin_len = sizeof(struct sockaddr_in); sin->sin_family = AF_INET; sin->sin_port = sin6->sin6_port; - sin->sin_addr.s_addr = sin6->sin6_addr.s6_addr32[3]; + sin->sin_addr.s_addr = sin6->sin6_addr.s6_addr32[3]; } /* Convert sockaddr_in to sockaddr_in6 in v4 mapped addr format. */ |