Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet6/ip6_input.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.175 retrieving revision 1.178.2.7 diff -u -p -r1.175 -r1.178.2.7 --- src/sys/netinet6/ip6_input.c 2017/02/22 07:46:00 1.175 +++ src/sys/netinet6/ip6_input.c 2018/04/09 13:34:10 1.178.2.7 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.175 2017/02/22 07:46:00 ozaki-r Exp $ */ +/* $NetBSD: ip6_input.c,v 1.178.2.7 2018/04/09 13:34:10 bouyer 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.175 2017/02/22 07:46:00 ozaki-r Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.178.2.7 2018/04/09 13:34:10 bouyer Exp $"); #ifdef _KERNEL_OPT #include "opt_gateway.h" @@ -205,10 +205,7 @@ ip6_init(void) KASSERT(inet6_pfil_hook != NULL); ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS); - ip6_forward_rt_percpu = percpu_alloc(sizeof(struct route)); - if (ip6_forward_rt_percpu == NULL) - panic("failed to alllocate ip6_forward_rt_percpu"); } static void @@ -231,9 +228,7 @@ ip6intr(void *arg __unused) { struct mbuf *m; -#ifndef NET_MPSAFE - mutex_enter(softnet_lock); -#endif + SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE(); while ((m = pktq_dequeue(ip6_pktq)) != NULL) { struct psref psref; struct ifnet *rcvif = m_get_rcvif_psref(m, &psref); @@ -253,9 +248,7 @@ ip6intr(void *arg __unused) ip6_input(m, rcvif); m_put_rcvif_psref(rcvif, &psref); } -#ifndef NET_MPSAFE - mutex_exit(softnet_lock); -#endif + SOFTNET_KERNEL_UNLOCK_UNLESS_NET_MPSAFE(); } void @@ -265,7 +258,7 @@ ip6_input(struct mbuf *m, struct ifnet * int hit, off = sizeof(struct ip6_hdr), nest; u_int32_t plen; u_int32_t rtalert = ~0; - int nxt, ours = 0, rh_present = 0; + int nxt, ours = 0, rh_present = 0, frg_present; struct ifnet *deliverifp = NULL; int srcrt = 0; struct rtentry *rt = NULL; @@ -458,15 +451,15 @@ ip6_input(struct mbuf *m, struct ifnet * * Multicast check */ if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - struct in6_multi *in6m = 0; + bool ingroup; in6_ifstat_inc(rcvif, ifs6_in_mcast); /* * See if we belong to the destination multicast group on the * arrival interface. */ - in6m = in6_lookup_multi(&ip6->ip6_dst, rcvif); - if (in6m) + ingroup = in6_multi_group(&ip6->ip6_dst, rcvif); + if (ingroup) ours = 1; else if (!ip6_mrouter) { uint64_t *ip6s = IP6_STAT_GETREF(); @@ -514,13 +507,33 @@ ip6_input(struct mbuf *m, struct ifnet * #endif rt->rt_ifp->if_type == IFT_LOOP) { struct in6_ifaddr *ia6 = (struct in6_ifaddr *)rt->rt_ifa; + int addrok; + if (ia6->ia6_flags & IN6_IFF_ANYCAST) m->m_flags |= M_ANYCAST6; /* * packets to a tentative, duplicated, or somehow invalid * address must not be accepted. */ - if (!(ia6->ia6_flags & (IN6_IFF_NOTREADY | IN6_IFF_DETACHED))) { + if (ia6->ia6_flags & IN6_IFF_NOTREADY) + addrok = 0; + else if (ia6->ia6_flags & IN6_IFF_DETACHED && + !IN6_IS_ADDR_UNSPECIFIED(&ip6->ip6_src)) + { + /* Allow internal traffic to DETACHED addresses */ + struct sockaddr_in6 sin6; + int s; + + memset(&sin6, 0, sizeof(sin6)); + sin6.sin6_family = AF_INET6; + sin6.sin6_len = sizeof(sin6); + sin6.sin6_addr = ip6->ip6_src; + s = pserialize_read_enter(); + addrok = (ifa_ifwithaddr(sin6tosa(&sin6)) != NULL); + pserialize_read_exit(s); + } else + addrok = 1; + if (addrok) { /* this address is ready */ ours = 1; deliverifp = ia6->ia_ifp; /* correct? */ @@ -763,6 +776,7 @@ ip6_input(struct mbuf *m, struct ifnet * percpu_putref(ip6_forward_rt_percpu); rh_present = 0; + frg_present = 0; while (nxt != IPPROTO_DONE) { if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { IP6_STATINC(IP6_STAT_TOOMANYHDR); @@ -786,6 +800,12 @@ ip6_input(struct mbuf *m, struct ifnet * IP6_STATINC(IP6_STAT_BADOPTIONS); goto bad; } + } else if (nxt == IPPROTO_FRAGMENT) { + if (frg_present++) { + in6_ifstat_inc(rcvif, ifs6_in_hdrerr); + IP6_STATINC(IP6_STAT_BADOPTIONS); + goto bad; + } } #ifdef IPSEC @@ -799,18 +819,14 @@ ip6_input(struct mbuf *m, struct ifnet * & PR_LASTHDR) != 0) { int error; - SOFTNET_LOCK(); error = ipsec6_input(m); - SOFTNET_UNLOCK(); if (error) goto bad; } } #endif /* IPSEC */ - SOFTNET_LOCK(); nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt); - SOFTNET_UNLOCK(); } return; @@ -1322,10 +1338,7 @@ ip6_notify_pmtu(struct in6pcb *in6p, con if (mtu == NULL) return; -#ifdef DIAGNOSTIC - if (so == NULL) /* I believe this is impossible */ - panic("ip6_notify_pmtu: socket is NULL"); -#endif + KASSERT(so != NULL); memset(&mtuctl, 0, sizeof(mtuctl)); /* zero-clear for safety */ mtuctl.ip6m_mtu = *mtu; @@ -1339,8 +1352,8 @@ ip6_notify_pmtu(struct in6pcb *in6p, con if (sbappendaddr(&so->so_rcv, (const struct sockaddr *)dst, NULL, m_mtu) == 0) { + soroverflow(so); m_freem(m_mtu); - /* XXX: should count statistics */ } else sorwakeup(so); @@ -1399,50 +1412,44 @@ ip6_pullexthdr(struct mbuf *m, size_t of } /* - * Get pointer to the previous header followed by the header + * Get offset to the previous header followed by the header * currently processed. - * XXX: This function supposes that - * M includes all headers, - * the next header field and the header length field of each header - * are valid, and - * the sum of each header length equals to OFF. - * Because of these assumptions, this function must be called very - * carefully. Moreover, it will not be used in the near future when - * we develop `neater' mechanism to process extension headers. */ -u_int8_t * +int ip6_get_prevhdr(struct mbuf *m, int off) { struct ip6_hdr *ip6 = mtod(m, struct ip6_hdr *); - if (off == sizeof(struct ip6_hdr)) - return (&ip6->ip6_nxt); - else { - int len, nxt; - struct ip6_ext *ip6e = NULL; + if (off == sizeof(struct ip6_hdr)) { + return offsetof(struct ip6_hdr, ip6_nxt); + } else if (off < sizeof(struct ip6_hdr)) { + panic("%s: off < sizeof(struct ip6_hdr)", __func__); + } else { + int len, nlen, nxt; + struct ip6_ext ip6e; nxt = ip6->ip6_nxt; len = sizeof(struct ip6_hdr); + nlen = 0; while (len < off) { - ip6e = (struct ip6_ext *)(mtod(m, char *) + len); + m_copydata(m, len, sizeof(ip6e), &ip6e); switch (nxt) { case IPPROTO_FRAGMENT: - len += sizeof(struct ip6_frag); + nlen = sizeof(struct ip6_frag); break; case IPPROTO_AH: - len += (ip6e->ip6e_len + 2) << 2; + nlen = (ip6e.ip6e_len + 2) << 2; break; default: - len += (ip6e->ip6e_len + 1) << 3; + nlen = (ip6e.ip6e_len + 1) << 3; break; } - nxt = ip6e->ip6e_nxt; + len += nlen; + nxt = ip6e.ip6e_nxt; } - if (ip6e) - return (&ip6e->ip6e_nxt); - else - return NULL; + + return (len - nlen); } }