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.149.4.11 retrieving revision 1.164.2.2 diff -u -p -r1.149.4.11 -r1.164.2.2 --- src/sys/netinet6/ip6_input.c 2017/08/28 17:53:12 1.149.4.11 +++ src/sys/netinet6/ip6_input.c 2016/11/04 14:49:21 1.164.2.2 @@ -1,4 +1,4 @@ -/* $NetBSD: ip6_input.c,v 1.149.4.11 2017/08/28 17:53:12 skrll Exp $ */ +/* $NetBSD: ip6_input.c,v 1.164.2.2 2016/11/04 14:49:21 pgoyette Exp $ */ /* $KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $ */ /* @@ -62,18 +62,20 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.149.4.11 2017/08/28 17:53:12 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.164.2.2 2016/11/04 14:49:21 pgoyette Exp $"); #ifdef _KERNEL_OPT #include "opt_gateway.h" #include "opt_inet.h" #include "opt_inet6.h" #include "opt_ipsec.h" +#include "opt_compat_netbsd.h" #include "opt_net_mpsafe.h" #endif #include #include +#include #include #include #include @@ -86,7 +88,6 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #include #include -#include #include #include @@ -119,6 +120,11 @@ __KERNEL_RCSID(0, "$NetBSD: ip6_input.c, #include #endif /* IPSEC */ +#ifdef COMPAT_50 +#include +#include +#endif + #include #include "faith.h" @@ -138,8 +144,6 @@ pfil_head_t *inet6_pfil_hook; percpu_t *ip6stat_percpu; -percpu_t *ip6_forward_rt_percpu __cacheline_aligned; - static void ip6_init2(void); static void ip6intr(void *); static struct m_tag *ip6_setdstifaddr(struct mbuf *, const struct in6_ifaddr *); @@ -199,7 +203,6 @@ 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)); } static void @@ -249,6 +252,8 @@ ip6intr(void *arg __unused) #endif } +extern struct route ip6_forward_rt; + void ip6_input(struct mbuf *m, struct ifnet *rcvif) { @@ -259,12 +264,11 @@ ip6_input(struct mbuf *m, struct ifnet * int nxt, ours = 0, rh_present = 0; struct ifnet *deliverifp = NULL; int srcrt = 0; - struct rtentry *rt = NULL; + const struct rtentry *rt; union { struct sockaddr dst; struct sockaddr_in6 dst6; } u; - struct route *ro; /* * make sure we don't have onion peering information into m_tag. @@ -428,7 +432,7 @@ ip6_input(struct mbuf *m, struct ifnet * * to the usage conflict. * in6_setscope() then also checks and rejects the cases where src or * dst are the loopback address and the receiving interface - * is not loopback. + * is not loopback. */ if (__predict_false( m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT))) @@ -444,20 +448,19 @@ ip6_input(struct mbuf *m, struct ifnet * goto bad; } - ro = percpu_getref(ip6_forward_rt_percpu); /* * Multicast check */ if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) { - bool ingroup; + struct in6_multi *in6m = 0; in6_ifstat_inc(rcvif, ifs6_in_mcast); /* * See if we belong to the destination multicast group on the * arrival interface. */ - ingroup = in6_multi_group(&ip6->ip6_dst, rcvif); - if (ingroup) + IN6_LOOKUP_MULTI(ip6->ip6_dst, rcvif, in6m); + if (in6m) ours = 1; else if (!ip6_mrouter) { uint64_t *ip6s = IP6_STAT_GETREF(); @@ -465,7 +468,7 @@ ip6_input(struct mbuf *m, struct ifnet * ip6s[IP6_STAT_CANTFORWARD]++; IP6_STAT_PUTREF(); in6_ifstat_inc(rcvif, ifs6_in_discard); - goto bad_unref; + goto bad; } deliverifp = rcvif; goto hbhcheck; @@ -476,7 +479,7 @@ ip6_input(struct mbuf *m, struct ifnet * /* * Unicast check */ - rt = rtcache_lookup2(ro, &u.dst, 1, &hit); + rt = rtcache_lookup2(&ip6_forward_rt, &u.dst, 1, &hit); if (hit) IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT); else @@ -511,20 +514,18 @@ ip6_input(struct mbuf *m, struct ifnet * * 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)) { /* this address is ready */ ours = 1; deliverifp = ia6->ia_ifp; /* correct? */ goto hbhcheck; } else { /* address is not ready, so discard the packet. */ - char ip6bufs[INET6_ADDRSTRLEN]; - char ip6bufd[INET6_ADDRSTRLEN]; nd6log(LOG_INFO, "packet to an unready address %s->%s\n", - IN6_PRINT(ip6bufs, &ip6->ip6_src), - IN6_PRINT(ip6bufd, &ip6->ip6_dst)); + ip6_sprintf(&ip6->ip6_src), + ip6_sprintf(&ip6->ip6_dst)); - goto bad_unref; + goto bad; } } @@ -570,7 +571,7 @@ ip6_input(struct mbuf *m, struct ifnet * if (!ip6_forwarding) { IP6_STATINC(IP6_STAT_CANTFORWARD); in6_ifstat_inc(rcvif, ifs6_in_discard); - goto bad_unref; + goto bad; } hbhcheck: @@ -609,8 +610,6 @@ ip6_input(struct mbuf *m, struct ifnet * #if 0 /*touches NULL pointer*/ in6_ifstat_inc(rcvif, ifs6_in_discard); #endif - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); return; /* m have already been freed */ } @@ -634,16 +633,12 @@ ip6_input(struct mbuf *m, struct ifnet * icmp6_error(m, ICMP6_PARAM_PROB, ICMP6_PARAMPROB_HEADER, (char *)&ip6->ip6_plen - (char *)ip6); - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); return; } IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr), sizeof(struct ip6_hbh)); if (hbh == NULL) { IP6_STATINC(IP6_STAT_TOOSHORT); - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); return; } KASSERT(IP6_HDR_ALIGNED_P(hbh)); @@ -667,7 +662,7 @@ ip6_input(struct mbuf *m, struct ifnet * if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) { IP6_STATINC(IP6_STAT_TOOSHORT); in6_ifstat_inc(rcvif, ifs6_in_truncated); - goto bad_unref; + goto bad; } if (m->m_pkthdr.len > sizeof(struct ip6_hdr) + plen) { if (m->m_len == m->m_pkthdr.len) { @@ -697,17 +692,13 @@ ip6_input(struct mbuf *m, struct ifnet * SOFTNET_UNLOCK(); if (error != 0) { - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); IP6_STATINC(IP6_STAT_CANTFORWARD); goto bad; } } if (!ours) - goto bad_unref; + goto bad; } else if (!ours) { - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); ip6_forward(m, srcrt); return; } @@ -727,7 +718,7 @@ ip6_input(struct mbuf *m, struct ifnet * IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) { IP6_STATINC(IP6_STAT_BADSCOPE); in6_ifstat_inc(rcvif, ifs6_in_addrerr); - goto bad_unref; + goto bad; } /* @@ -747,12 +738,6 @@ ip6_input(struct mbuf *m, struct ifnet * in6_ifstat_inc(deliverifp, ifs6_in_deliver); nest = 0; - if (rt != NULL) { - rtcache_unref(rt, ro); - rt = NULL; - } - percpu_putref(ip6_forward_rt_percpu); - rh_present = 0; while (nxt != IPPROTO_DONE) { if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) { @@ -790,7 +775,9 @@ ip6_input(struct mbuf *m, struct ifnet * & PR_LASTHDR) != 0) { int error; + SOFTNET_LOCK(); error = ipsec6_input(m); + SOFTNET_UNLOCK(); if (error) goto bad; } @@ -802,13 +789,8 @@ ip6_input(struct mbuf *m, struct ifnet * SOFTNET_UNLOCK(); } return; - - bad_unref: - rtcache_unref(rt, ro); - percpu_putref(ip6_forward_rt_percpu); bad: m_freem(m); - return; } /* @@ -854,7 +836,7 @@ ip6_getdstifaddr(struct mbuf *m) * rtalertp - XXX: should be stored more smart way */ int -ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp, +ip6_hopopts_input(u_int32_t *plenp, u_int32_t *rtalertp, struct mbuf **mp, int *offp) { struct mbuf *m = *mp; @@ -899,7 +881,7 @@ ip6_hopopts_input(u_int32_t *plenp, u_in * opthead + hbhlen is located in continuous memory region. */ static int -ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, +ip6_process_hopopts(struct mbuf *m, u_int8_t *opthead, int hbhlen, u_int32_t *rtalertp, u_int32_t *plenp) { struct ip6_hdr *ip6; @@ -1074,18 +1056,36 @@ ip6_unknown_opt(u_int8_t *optp, struct m * you are using IP6_EXTHDR_CHECK() not m_pulldown()) */ void -ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, +ip6_savecontrol(struct in6pcb *in6p, struct mbuf **mp, struct ip6_hdr *ip6, struct mbuf *m) { - struct socket *so = in6p->in6p_socket; #ifdef RFC2292 #define IS2292(x, y) ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y)) #else #define IS2292(x, y) (y) #endif - if (SOOPT_TIMESTAMP(so->so_options)) - mp = sbsavetimestamp(so->so_options, m, mp); + if (in6p->in6p_socket->so_options & SO_TIMESTAMP +#ifdef SO_OTIMESTAMP + || in6p->in6p_socket->so_options & SO_OTIMESTAMP +#endif + ) { + struct timeval tv; + + microtime(&tv); +#ifdef SO_OTIMESTAMP + if (in6p->in6p_socket->so_options & SO_OTIMESTAMP) { + struct timeval50 tv50; + timeval_to_timeval50(&tv, &tv50); + *mp = sbcreatecontrol((void *) &tv50, sizeof(tv50), + SCM_OTIMESTAMP, SOL_SOCKET); + } else +#endif + *mp = sbcreatecontrol((void *) &tv, sizeof(tv), + SCM_TIMESTAMP, SOL_SOCKET); + if (*mp) + mp = &(*mp)->m_next; + } /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */ if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION) @@ -1098,7 +1098,8 @@ ip6_savecontrol(struct in6pcb *in6p, str memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr)); in6_clearscope(&pi6.ipi6_addr); /* XXX */ pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index; - *mp = sbcreatecontrol(&pi6, sizeof(pi6), + *mp = sbcreatecontrol((void *) &pi6, + sizeof(struct in6_pktinfo), IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6); if (*mp) mp = &(*mp)->m_next; @@ -1107,7 +1108,7 @@ ip6_savecontrol(struct in6pcb *in6p, str if (in6p->in6p_flags & IN6P_HOPLIMIT) { int hlim = ip6->ip6_hlim & 0xff; - *mp = sbcreatecontrol(&hlim, sizeof(hlim), + *mp = sbcreatecontrol((void *) &hlim, sizeof(int), IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6); if (*mp) mp = &(*mp)->m_next; @@ -1121,7 +1122,7 @@ ip6_savecontrol(struct in6pcb *in6p, str flowinfo >>= 20; tclass = flowinfo & 0xff; - *mp = sbcreatecontrol(&tclass, sizeof(tclass), + *mp = sbcreatecontrol((void *)&tclass, sizeof(tclass), IPV6_TCLASS, IPPROTO_IPV6); if (*mp) @@ -1169,7 +1170,7 @@ ip6_savecontrol(struct in6pcb *in6p, str * be removed before returning in the RFC 2292. * Note: this constraint is removed in RFC3542. */ - *mp = sbcreatecontrol(hbh, hbhlen, + *mp = sbcreatecontrol((void *)hbh, hbhlen, IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS), IPPROTO_IPV6); if (*mp) @@ -1231,7 +1232,7 @@ ip6_savecontrol(struct in6pcb *in6p, str if (!(in6p->in6p_flags & IN6P_DSTOPTS)) break; - *mp = sbcreatecontrol(ip6e, elen, + *mp = sbcreatecontrol((void *)ip6e, elen, IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS), IPPROTO_IPV6); if (*mp) @@ -1242,7 +1243,7 @@ ip6_savecontrol(struct in6pcb *in6p, str if (!(in6p->in6p_flags & IN6P_RTHDR)) break; - *mp = sbcreatecontrol(ip6e, elen, + *mp = sbcreatecontrol((void *)ip6e, elen, IS2292(IPV6_2292RTHDR, IPV6_RTHDR), IPPROTO_IPV6); if (*mp) @@ -1292,7 +1293,10 @@ ip6_notify_pmtu(struct in6pcb *in6p, con if (mtu == NULL) return; - KASSERT(so != NULL); +#ifdef DIAGNOSTIC + if (so == NULL) /* I believe this is impossible */ + panic("ip6_notify_pmtu: socket is NULL"); +#endif memset(&mtuctl, 0, sizeof(mtuctl)); /* zero-clear for safety */ mtuctl.ip6m_mtu = *mtu; @@ -1300,7 +1304,7 @@ ip6_notify_pmtu(struct in6pcb *in6p, con if (sa6_recoverscope(&mtuctl.ip6m_addr)) return; - if ((m_mtu = sbcreatecontrol(&mtuctl, sizeof(mtuctl), + if ((m_mtu = sbcreatecontrol((void *)&mtuctl, sizeof(mtuctl), IPV6_PATHMTU, IPPROTO_IPV6)) == NULL) return;