[BACK]Return to ip6_input.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / netinet6

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/netinet6/ip6_input.c between version 1.149.4.11 and 1.169

version 1.149.4.11, 2017/08/28 17:53:12 version 1.169, 2016/10/18 07:30:31
Line 69  __KERNEL_RCSID(0, "$NetBSD$");
Line 69  __KERNEL_RCSID(0, "$NetBSD$");
 #include "opt_inet.h"  #include "opt_inet.h"
 #include "opt_inet6.h"  #include "opt_inet6.h"
 #include "opt_ipsec.h"  #include "opt_ipsec.h"
   #include "opt_compat_netbsd.h"
 #include "opt_net_mpsafe.h"  #include "opt_net_mpsafe.h"
 #endif  #endif
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/systm.h>  #include <sys/systm.h>
   #include <sys/malloc.h>
 #include <sys/mbuf.h>  #include <sys/mbuf.h>
 #include <sys/domain.h>  #include <sys/domain.h>
 #include <sys/protosw.h>  #include <sys/protosw.h>
Line 119  __KERNEL_RCSID(0, "$NetBSD$");
Line 121  __KERNEL_RCSID(0, "$NetBSD$");
 #include <netipsec/key.h>  #include <netipsec/key.h>
 #endif /* IPSEC */  #endif /* IPSEC */
   
   #ifdef COMPAT_50
   #include <compat/sys/time.h>
   #include <compat/sys/socket.h>
   #endif
   
 #include <netinet6/ip6protosw.h>  #include <netinet6/ip6protosw.h>
   
 #include "faith.h"  #include "faith.h"
Line 199  ip6_init(void)
Line 206  ip6_init(void)
         KASSERT(inet6_pfil_hook != NULL);          KASSERT(inet6_pfil_hook != NULL);
   
         ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS);          ip6stat_percpu = percpu_alloc(sizeof(uint64_t) * IP6_NSTATS);
   
         ip6_forward_rt_percpu = percpu_alloc(sizeof(struct route));          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  static void
Line 259  ip6_input(struct mbuf *m, struct ifnet *
Line 269  ip6_input(struct mbuf *m, struct ifnet *
         int nxt, ours = 0, rh_present = 0;          int nxt, ours = 0, rh_present = 0;
         struct ifnet *deliverifp = NULL;          struct ifnet *deliverifp = NULL;
         int srcrt = 0;          int srcrt = 0;
         struct rtentry *rt = NULL;          const struct rtentry *rt;
         union {          union {
                 struct sockaddr         dst;                  struct sockaddr         dst;
                 struct sockaddr_in6     dst6;                  struct sockaddr_in6     dst6;
Line 428  ip6_input(struct mbuf *m, struct ifnet *
Line 438  ip6_input(struct mbuf *m, struct ifnet *
          * to the usage conflict.           * to the usage conflict.
          * in6_setscope() then also checks and rejects the cases where src or           * in6_setscope() then also checks and rejects the cases where src or
          * dst are the loopback address and the receiving interface           * dst are the loopback address and the receiving interface
          * is not loopback.           * is not loopback.
          */           */
         if (__predict_false(          if (__predict_false(
             m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))              m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))
Line 444  ip6_input(struct mbuf *m, struct ifnet *
Line 454  ip6_input(struct mbuf *m, struct ifnet *
                 goto bad;                  goto bad;
         }          }
   
         ro = percpu_getref(ip6_forward_rt_percpu);  
         /*          /*
          * Multicast check           * Multicast check
          */           */
         if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {          if (IN6_IS_ADDR_MULTICAST(&ip6->ip6_dst)) {
                 bool ingroup;                  struct  in6_multi *in6m = 0;
   
                 in6_ifstat_inc(rcvif, ifs6_in_mcast);                  in6_ifstat_inc(rcvif, ifs6_in_mcast);
                 /*                  /*
                  * See if we belong to the destination multicast group on the                   * See if we belong to the destination multicast group on the
                  * arrival interface.                   * arrival interface.
                  */                   */
                 ingroup = in6_multi_group(&ip6->ip6_dst, rcvif);                  IN6_LOOKUP_MULTI(ip6->ip6_dst, rcvif, in6m);
                 if (ingroup)                  if (in6m)
                         ours = 1;                          ours = 1;
                 else if (!ip6_mrouter) {                  else if (!ip6_mrouter) {
                         uint64_t *ip6s = IP6_STAT_GETREF();                          uint64_t *ip6s = IP6_STAT_GETREF();
Line 465  ip6_input(struct mbuf *m, struct ifnet *
Line 474  ip6_input(struct mbuf *m, struct ifnet *
                         ip6s[IP6_STAT_CANTFORWARD]++;                          ip6s[IP6_STAT_CANTFORWARD]++;
                         IP6_STAT_PUTREF();                          IP6_STAT_PUTREF();
                         in6_ifstat_inc(rcvif, ifs6_in_discard);                          in6_ifstat_inc(rcvif, ifs6_in_discard);
                         goto bad_unref;                          goto bad;
                 }                  }
                 deliverifp = rcvif;                  deliverifp = rcvif;
                 goto hbhcheck;                  goto hbhcheck;
Line 476  ip6_input(struct mbuf *m, struct ifnet *
Line 485  ip6_input(struct mbuf *m, struct ifnet *
         /*          /*
          *  Unicast check           *  Unicast check
          */           */
           ro = percpu_getref(ip6_forward_rt_percpu);
         rt = rtcache_lookup2(ro, &u.dst, 1, &hit);          rt = rtcache_lookup2(ro, &u.dst, 1, &hit);
           percpu_putref(ip6_forward_rt_percpu);
         if (hit)          if (hit)
                 IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT);                  IP6_STATINC(IP6_STAT_FORWARD_CACHEHIT);
         else          else
Line 518  ip6_input(struct mbuf *m, struct ifnet *
Line 529  ip6_input(struct mbuf *m, struct ifnet *
                         goto hbhcheck;                          goto hbhcheck;
                 } else {                  } else {
                         /* address is not ready, so discard the packet. */                          /* 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",                          nd6log(LOG_INFO, "packet to an unready address %s->%s\n",
                             IN6_PRINT(ip6bufs, &ip6->ip6_src),                              ip6_sprintf(&ip6->ip6_src),
                             IN6_PRINT(ip6bufd, &ip6->ip6_dst));                              ip6_sprintf(&ip6->ip6_dst));
   
                         goto bad_unref;                          goto bad;
                 }                  }
         }          }
   
Line 570  ip6_input(struct mbuf *m, struct ifnet *
Line 579  ip6_input(struct mbuf *m, struct ifnet *
         if (!ip6_forwarding) {          if (!ip6_forwarding) {
                 IP6_STATINC(IP6_STAT_CANTFORWARD);                  IP6_STATINC(IP6_STAT_CANTFORWARD);
                 in6_ifstat_inc(rcvif, ifs6_in_discard);                  in6_ifstat_inc(rcvif, ifs6_in_discard);
                 goto bad_unref;                  goto bad;
         }          }
   
   hbhcheck:    hbhcheck:
Line 609  ip6_input(struct mbuf *m, struct ifnet *
Line 618  ip6_input(struct mbuf *m, struct ifnet *
 #if 0   /*touches NULL pointer*/  #if 0   /*touches NULL pointer*/
                         in6_ifstat_inc(rcvif, ifs6_in_discard);                          in6_ifstat_inc(rcvif, ifs6_in_discard);
 #endif  #endif
                         rtcache_unref(rt, ro);  
                         percpu_putref(ip6_forward_rt_percpu);  
                         return; /* m have already been freed */                          return; /* m have already been freed */
                 }                  }
   
Line 634  ip6_input(struct mbuf *m, struct ifnet *
Line 641  ip6_input(struct mbuf *m, struct ifnet *
                         icmp6_error(m, ICMP6_PARAM_PROB,                          icmp6_error(m, ICMP6_PARAM_PROB,
                                     ICMP6_PARAMPROB_HEADER,                                      ICMP6_PARAMPROB_HEADER,
                                     (char *)&ip6->ip6_plen - (char *)ip6);                                      (char *)&ip6->ip6_plen - (char *)ip6);
                         rtcache_unref(rt, ro);  
                         percpu_putref(ip6_forward_rt_percpu);  
                         return;                          return;
                 }                  }
                 IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),                  IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m, sizeof(struct ip6_hdr),
                         sizeof(struct ip6_hbh));                          sizeof(struct ip6_hbh));
                 if (hbh == NULL) {                  if (hbh == NULL) {
                         IP6_STATINC(IP6_STAT_TOOSHORT);                          IP6_STATINC(IP6_STAT_TOOSHORT);
                         rtcache_unref(rt, ro);  
                         percpu_putref(ip6_forward_rt_percpu);  
                         return;                          return;
                 }                  }
                 KASSERT(IP6_HDR_ALIGNED_P(hbh));                  KASSERT(IP6_HDR_ALIGNED_P(hbh));
Line 667  ip6_input(struct mbuf *m, struct ifnet *
Line 670  ip6_input(struct mbuf *m, struct ifnet *
         if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {          if (m->m_pkthdr.len - sizeof(struct ip6_hdr) < plen) {
                 IP6_STATINC(IP6_STAT_TOOSHORT);                  IP6_STATINC(IP6_STAT_TOOSHORT);
                 in6_ifstat_inc(rcvif, ifs6_in_truncated);                  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_pkthdr.len > sizeof(struct ip6_hdr) + plen) {
                 if (m->m_len == m->m_pkthdr.len) {                  if (m->m_len == m->m_pkthdr.len) {
Line 697  ip6_input(struct mbuf *m, struct ifnet *
Line 700  ip6_input(struct mbuf *m, struct ifnet *
                         SOFTNET_UNLOCK();                          SOFTNET_UNLOCK();
   
                         if (error != 0) {                          if (error != 0) {
                                 rtcache_unref(rt, ro);  
                                 percpu_putref(ip6_forward_rt_percpu);  
                                 IP6_STATINC(IP6_STAT_CANTFORWARD);                                  IP6_STATINC(IP6_STAT_CANTFORWARD);
                                 goto bad;                                  m_freem(m);
                                   return;
                         }                          }
                 }                  }
                 if (!ours)                  if (!ours) {
                         goto bad_unref;                          m_freem(m);
                           return;
                   }
         } else if (!ours) {          } else if (!ours) {
                 rtcache_unref(rt, ro);  
                 percpu_putref(ip6_forward_rt_percpu);  
                 ip6_forward(m, srcrt);                  ip6_forward(m, srcrt);
                 return;                  return;
         }          }
Line 727  ip6_input(struct mbuf *m, struct ifnet *
Line 729  ip6_input(struct mbuf *m, struct ifnet *
             IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {              IN6_IS_ADDR_V4MAPPED(&ip6->ip6_dst)) {
                 IP6_STATINC(IP6_STAT_BADSCOPE);                  IP6_STATINC(IP6_STAT_BADSCOPE);
                 in6_ifstat_inc(rcvif, ifs6_in_addrerr);                  in6_ifstat_inc(rcvif, ifs6_in_addrerr);
                 goto bad_unref;                  goto bad;
         }          }
   
         /*          /*
Line 747  ip6_input(struct mbuf *m, struct ifnet *
Line 749  ip6_input(struct mbuf *m, struct ifnet *
         in6_ifstat_inc(deliverifp, ifs6_in_deliver);          in6_ifstat_inc(deliverifp, ifs6_in_deliver);
         nest = 0;          nest = 0;
   
         if (rt != NULL) {  
                 rtcache_unref(rt, ro);  
                 rt = NULL;  
         }  
         percpu_putref(ip6_forward_rt_percpu);  
   
         rh_present = 0;          rh_present = 0;
         while (nxt != IPPROTO_DONE) {          while (nxt != IPPROTO_DONE) {
                 if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {                  if (ip6_hdrnestlimit && (++nest > ip6_hdrnestlimit)) {
Line 790  ip6_input(struct mbuf *m, struct ifnet *
Line 786  ip6_input(struct mbuf *m, struct ifnet *
                             & PR_LASTHDR) != 0) {                              & PR_LASTHDR) != 0) {
                                 int error;                                  int error;
   
                                   SOFTNET_LOCK();
                                 error = ipsec6_input(m);                                  error = ipsec6_input(m);
                                   SOFTNET_UNLOCK();
                                 if (error)                                  if (error)
                                         goto bad;                                          goto bad;
                         }                          }
Line 802  ip6_input(struct mbuf *m, struct ifnet *
Line 800  ip6_input(struct mbuf *m, struct ifnet *
                 SOFTNET_UNLOCK();                  SOFTNET_UNLOCK();
         }          }
         return;          return;
   
  bad_unref:  
         rtcache_unref(rt, ro);  
         percpu_putref(ip6_forward_rt_percpu);  
  bad:   bad:
         m_freem(m);          m_freem(m);
         return;  
 }  }
   
 /*  /*
Line 854  ip6_getdstifaddr(struct mbuf *m)
Line 847  ip6_getdstifaddr(struct mbuf *m)
  * rtalertp - XXX: should be stored more smart way   * rtalertp - XXX: should be stored more smart way
  */   */
 int  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 **mp, int *offp)
 {  {
         struct mbuf *m = *mp;          struct mbuf *m = *mp;
Line 899  ip6_hopopts_input(u_int32_t *plenp, u_in
Line 892  ip6_hopopts_input(u_int32_t *plenp, u_in
  * opthead + hbhlen is located in continuous memory region.   * opthead + hbhlen is located in continuous memory region.
  */   */
 static int  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)          u_int32_t *rtalertp, u_int32_t *plenp)
 {  {
         struct ip6_hdr *ip6;          struct ip6_hdr *ip6;
Line 1074  ip6_unknown_opt(u_int8_t *optp, struct m
Line 1067  ip6_unknown_opt(u_int8_t *optp, struct m
  * you are using IP6_EXTHDR_CHECK() not m_pulldown())   * you are using IP6_EXTHDR_CHECK() not m_pulldown())
  */   */
 void  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 ip6_hdr *ip6, struct mbuf *m)
 {  {
         struct socket *so = in6p->in6p_socket;  
 #ifdef RFC2292  #ifdef RFC2292
 #define IS2292(x, y)    ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))  #define IS2292(x, y)    ((in6p->in6p_flags & IN6P_RFC2292) ? (x) : (y))
 #else  #else
 #define IS2292(x, y)    (y)  #define IS2292(x, y)    (y)
 #endif  #endif
   
         if (SOOPT_TIMESTAMP(so->so_options))          if (in6p->in6p_socket->so_options & SO_TIMESTAMP
                 mp = sbsavetimestamp(so->so_options, m, mp);  #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 */          /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
         if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)          if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)
Line 1098  ip6_savecontrol(struct in6pcb *in6p, str
Line 1109  ip6_savecontrol(struct in6pcb *in6p, str
                 memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));                  memcpy(&pi6.ipi6_addr, &ip6->ip6_dst, sizeof(struct in6_addr));
                 in6_clearscope(&pi6.ipi6_addr); /* XXX */                  in6_clearscope(&pi6.ipi6_addr); /* XXX */
                 pi6.ipi6_ifindex = m->m_pkthdr.rcvif_index;                  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);                      IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
Line 1107  ip6_savecontrol(struct in6pcb *in6p, str
Line 1119  ip6_savecontrol(struct in6pcb *in6p, str
         if (in6p->in6p_flags & IN6P_HOPLIMIT) {          if (in6p->in6p_flags & IN6P_HOPLIMIT) {
                 int hlim = ip6->ip6_hlim & 0xff;                  int hlim = ip6->ip6_hlim & 0xff;
   
                 *mp = sbcreatecontrol(&hlim, sizeof(hlim),                  *mp = sbcreatecontrol((void *) &hlim, sizeof(int),
                     IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);                      IS2292(IPV6_2292HOPLIMIT, IPV6_HOPLIMIT), IPPROTO_IPV6);
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
Line 1121  ip6_savecontrol(struct in6pcb *in6p, str
Line 1133  ip6_savecontrol(struct in6pcb *in6p, str
                 flowinfo >>= 20;                  flowinfo >>= 20;
   
                 tclass = flowinfo & 0xff;                  tclass = flowinfo & 0xff;
                 *mp = sbcreatecontrol(&tclass, sizeof(tclass),                  *mp = sbcreatecontrol((void *)&tclass, sizeof(tclass),
                     IPV6_TCLASS, IPPROTO_IPV6);                      IPV6_TCLASS, IPPROTO_IPV6);
   
                 if (*mp)                  if (*mp)
Line 1169  ip6_savecontrol(struct in6pcb *in6p, str
Line 1181  ip6_savecontrol(struct in6pcb *in6p, str
                          * be removed before returning in the RFC 2292.                           * be removed before returning in the RFC 2292.
                          * Note: this constraint is removed in RFC3542.                           * Note: this constraint is removed in RFC3542.
                          */                           */
                         *mp = sbcreatecontrol(hbh, hbhlen,                          *mp = sbcreatecontrol((void *)hbh, hbhlen,
                             IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),                              IS2292(IPV6_2292HOPOPTS, IPV6_HOPOPTS),
                             IPPROTO_IPV6);                              IPPROTO_IPV6);
                         if (*mp)                          if (*mp)
Line 1231  ip6_savecontrol(struct in6pcb *in6p, str
Line 1243  ip6_savecontrol(struct in6pcb *in6p, str
                                 if (!(in6p->in6p_flags & IN6P_DSTOPTS))                                  if (!(in6p->in6p_flags & IN6P_DSTOPTS))
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol(ip6e, elen,                                  *mp = sbcreatecontrol((void *)ip6e, elen,
                                     IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),                                      IS2292(IPV6_2292DSTOPTS, IPV6_DSTOPTS),
                                     IPPROTO_IPV6);                                      IPPROTO_IPV6);
                                 if (*mp)                                  if (*mp)
Line 1242  ip6_savecontrol(struct in6pcb *in6p, str
Line 1254  ip6_savecontrol(struct in6pcb *in6p, str
                                 if (!(in6p->in6p_flags & IN6P_RTHDR))                                  if (!(in6p->in6p_flags & IN6P_RTHDR))
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol(ip6e, elen,                                  *mp = sbcreatecontrol((void *)ip6e, elen,
                                     IS2292(IPV6_2292RTHDR, IPV6_RTHDR),                                      IS2292(IPV6_2292RTHDR, IPV6_RTHDR),
                                     IPPROTO_IPV6);                                      IPPROTO_IPV6);
                                 if (*mp)                                  if (*mp)
Line 1292  ip6_notify_pmtu(struct in6pcb *in6p, con
Line 1304  ip6_notify_pmtu(struct in6pcb *in6p, con
         if (mtu == NULL)          if (mtu == NULL)
                 return;                  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 */          memset(&mtuctl, 0, sizeof(mtuctl));     /* zero-clear for safety */
         mtuctl.ip6m_mtu = *mtu;          mtuctl.ip6m_mtu = *mtu;
Line 1300  ip6_notify_pmtu(struct in6pcb *in6p, con
Line 1315  ip6_notify_pmtu(struct in6pcb *in6p, con
         if (sa6_recoverscope(&mtuctl.ip6m_addr))          if (sa6_recoverscope(&mtuctl.ip6m_addr))
                 return;                  return;
   
         if ((m_mtu = sbcreatecontrol(&mtuctl, sizeof(mtuctl),          if ((m_mtu = sbcreatecontrol((void *)&mtuctl, sizeof(mtuctl),
             IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)              IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
                 return;                  return;
   

Legend:
Removed from v.1.149.4.11  
changed lines
  Added in v.1.169

CVSweb <webmaster@jp.NetBSD.org>