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

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

Diff for /src/sys/netinet/ip_input.c between version 1.319.4.4 and 1.331

version 1.319.4.4, 2015/12/27 12:10:07 version 1.331, 2016/06/30 06:48:58
Line 284  struct mowner ip_tx_mowner = MOWNER_INIT
Line 284  struct mowner ip_tx_mowner = MOWNER_INIT
   
 static void             ipintr(void *);  static void             ipintr(void *);
 static void             ip_input(struct mbuf *);  static void             ip_input(struct mbuf *);
 static void             ip_forward(struct mbuf *, int);  static void             ip_forward(struct mbuf *, int, struct ifnet *);
 static bool             ip_dooptions(struct mbuf *);  static bool             ip_dooptions(struct mbuf *);
 static struct in_ifaddr *ip_rtaddr(struct in_addr);  static struct in_ifaddr *ip_rtaddr(struct in_addr);
 static void             sysctl_net_inet_ip_setup(struct sysctllog **);  static void             sysctl_net_inet_ip_setup(struct sysctllog **);
Line 374  ip_input(struct mbuf *m)
Line 374  ip_input(struct mbuf *m)
         int checkif;          int checkif;
         int srcrt = 0;          int srcrt = 0;
         ifnet_t *ifp;          ifnet_t *ifp;
           struct psref psref;
   
         KASSERTMSG(cpu_softintr_p(), "ip_input: not in the software "          KASSERTMSG(cpu_softintr_p(), "ip_input: not in the software "
             "interrupt handler; synchronization assumptions violated");              "interrupt handler; synchronization assumptions violated");
   
         MCLAIM(m, &ip_rx_mowner);          MCLAIM(m, &ip_rx_mowner);
         KASSERT((m->m_flags & M_PKTHDR) != 0);          KASSERT((m->m_flags & M_PKTHDR) != 0);
         ifp = m->m_pkthdr.rcvif;  
           ifp = m_get_rcvif_psref(m, &psref);
           if (__predict_false(ifp == NULL))
                   goto bad;
   
         /*          /*
          * If no IP addresses have been set yet but the interfaces           * If no IP addresses have been set yet but the interfaces
Line 403  ip_input(struct mbuf *m)
Line 407  ip_input(struct mbuf *m)
                                   (max_linkhdr + 3) & ~3)) == NULL) {                                    (max_linkhdr + 3) & ~3)) == NULL) {
                         /* XXXJRT new stat, please */                          /* XXXJRT new stat, please */
                         IP_STATINC(IP_STAT_TOOSMALL);                          IP_STATINC(IP_STAT_TOOSMALL);
                         return;                          goto out;
                 }                  }
         } else if (__predict_false(m->m_len < sizeof (struct ip))) {          } else if (__predict_false(m->m_len < sizeof (struct ip))) {
                 if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {                  if ((m = m_pullup(m, sizeof (struct ip))) == NULL) {
                         IP_STATINC(IP_STAT_TOOSMALL);                          IP_STATINC(IP_STAT_TOOSMALL);
                         return;                          goto out;
                 }                  }
         }          }
         ip = mtod(m, struct ip *);          ip = mtod(m, struct ip *);
Line 424  ip_input(struct mbuf *m)
Line 428  ip_input(struct mbuf *m)
         if (hlen > m->m_len) {          if (hlen > m->m_len) {
                 if ((m = m_pullup(m, hlen)) == NULL) {                  if ((m = m_pullup(m, hlen)) == NULL) {
                         IP_STATINC(IP_STAT_BADHLEN);                          IP_STATINC(IP_STAT_BADHLEN);
                         return;                          goto out;
                 }                  }
                 ip = mtod(m, struct ip *);                  ip = mtod(m, struct ip *);
         }          }
Line 528  ip_input(struct mbuf *m)
Line 532  ip_input(struct mbuf *m)
                 freed = pfil_run_hooks(inet_pfil_hook, &m, ifp, PFIL_IN) != 0;                  freed = pfil_run_hooks(inet_pfil_hook, &m, ifp, PFIL_IN) != 0;
                 SOFTNET_UNLOCK();                  SOFTNET_UNLOCK();
                 if (freed || m == NULL) {                  if (freed || m == NULL) {
                         return;                          goto out;
                 }                  }
                 ip = mtod(m, struct ip *);                  ip = mtod(m, struct ip *);
                 hlen = ip->ip_hl << 2;                  hlen = ip->ip_hl << 2;
Line 557  ip_input(struct mbuf *m)
Line 561  ip_input(struct mbuf *m)
                 if ((*altq_input)(m, AF_INET) == 0) {                  if ((*altq_input)(m, AF_INET) == 0) {
                         /* Packet dropped by traffic conditioner. */                          /* Packet dropped by traffic conditioner. */
                         SOFTNET_UNLOCK();                          SOFTNET_UNLOCK();
                         return;                          goto out;
                 }                  }
                 SOFTNET_UNLOCK();                  SOFTNET_UNLOCK();
         }          }
Line 571  ip_input(struct mbuf *m)
Line 575  ip_input(struct mbuf *m)
          */           */
         ip_nhops = 0;           /* for source routed packets */          ip_nhops = 0;           /* for source routed packets */
         if (hlen > sizeof (struct ip) && ip_dooptions(m))          if (hlen > sizeof (struct ip) && ip_dooptions(m))
                 return;                  goto out;
   
         /*          /*
          * Enable a consistency check between the destination address           * Enable a consistency check between the destination address
Line 659  ip_input(struct mbuf *m)
Line 663  ip_input(struct mbuf *m)
                         if (ip_mforward(m, ifp) != 0) {                          if (ip_mforward(m, ifp) != 0) {
                                 SOFTNET_UNLOCK();                                  SOFTNET_UNLOCK();
                                 IP_STATINC(IP_STAT_CANTFORWARD);                                  IP_STATINC(IP_STAT_CANTFORWARD);
                                 m_freem(m);                                  goto bad;
                                 return;  
                         }                          }
                         SOFTNET_UNLOCK();                          SOFTNET_UNLOCK();
   
Line 681  ip_input(struct mbuf *m)
Line 684  ip_input(struct mbuf *m)
                  */                   */
                 if (!in_multi_group(ip->ip_dst, ifp, 0)) {                  if (!in_multi_group(ip->ip_dst, ifp, 0)) {
                         IP_STATINC(IP_STAT_CANTFORWARD);                          IP_STATINC(IP_STAT_CANTFORWARD);
                         m_freem(m);                          goto bad;
                         return;  
                 }                  }
                 goto ours;                  goto ours;
         }          }
Line 694  ip_input(struct mbuf *m)
Line 696  ip_input(struct mbuf *m)
          * Not for us; forward if possible and desirable.           * Not for us; forward if possible and desirable.
          */           */
         if (ipforwarding == 0) {          if (ipforwarding == 0) {
                   m_put_rcvif_psref(ifp, &psref);
                 IP_STATINC(IP_STAT_CANTFORWARD);                  IP_STATINC(IP_STAT_CANTFORWARD);
                 m_freem(m);                  m_freem(m);
         } else {          } else {
Line 704  ip_input(struct mbuf *m)
Line 707  ip_input(struct mbuf *m)
                  * forwarding loop till TTL goes to 0.                   * forwarding loop till TTL goes to 0.
                  */                   */
                 if (downmatch) {                  if (downmatch) {
                           m_put_rcvif_psref(ifp, &psref);
                         icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);                          icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_HOST, 0, 0);
                         IP_STATINC(IP_STAT_CANTFORWARD);                          IP_STATINC(IP_STAT_CANTFORWARD);
                         return;                          return;
Line 720  ip_input(struct mbuf *m)
Line 724  ip_input(struct mbuf *m)
                         SOFTNET_UNLOCK();                          SOFTNET_UNLOCK();
                 }                  }
 #endif  #endif
                 ip_forward(m, srcrt);                  ip_forward(m, srcrt, ifp);
                   m_put_rcvif_psref(ifp, &psref);
         }          }
         return;          return;
   
 ours:  ours:
           m_put_rcvif_psref(ifp, &psref);
           ifp = NULL;
   
         /*          /*
          * If offset or IP_MF are set, must reassemble.           * If offset or IP_MF are set, must reassemble.
          */           */
Line 781  ours:
Line 789  ours:
         SOFTNET_UNLOCK();          SOFTNET_UNLOCK();
         return;          return;
 bad:  bad:
           m_put_rcvif_psref(ifp, &psref);
         m_freem(m);          m_freem(m);
         return;          return;
   
 badcsum:  badcsum:
           m_put_rcvif_psref(ifp, &psref);
         IP_STATINC(IP_STAT_BADSUM);          IP_STATINC(IP_STAT_BADSUM);
         m_freem(m);          m_freem(m);
           return;
   out:
           m_put_rcvif_psref(ifp, &psref);
 }  }
   
 /*  /*
Line 988  ip_dooptions(struct mbuf *m)
Line 1001  ip_dooptions(struct mbuf *m)
                         case IPOPT_TS_TSONLY:                          case IPOPT_TS_TSONLY:
                                 break;                                  break;
   
                         case IPOPT_TS_TSANDADDR:                          case IPOPT_TS_TSANDADDR: {
                                   struct ifnet *rcvif;
                                   int s;
   
                                 if (ipt->ipt_ptr - 1 + sizeof(n_time) +                                  if (ipt->ipt_ptr - 1 + sizeof(n_time) +
                                     sizeof(struct in_addr) > ipt->ipt_len) {                                      sizeof(struct in_addr) > ipt->ipt_len) {
                                         code = (u_char *)&ipt->ipt_ptr -                                          code = (u_char *)&ipt->ipt_ptr -
Line 996  ip_dooptions(struct mbuf *m)
Line 1012  ip_dooptions(struct mbuf *m)
                                         goto bad;                                          goto bad;
                                 }                                  }
                                 ipaddr.sin_addr = dst;                                  ipaddr.sin_addr = dst;
                                   rcvif = m_get_rcvif(m, &s);
                                 ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr),                                  ia = ifatoia(ifaof_ifpforaddr(sintosa(&ipaddr),
                                     m->m_pkthdr.rcvif));                                      rcvif));
                                   m_put_rcvif(rcvif, &s);
                                 if (ia == 0)                                  if (ia == 0)
                                         continue;                                          continue;
                                 bcopy(&ia->ia_addr.sin_addr,                                  bcopy(&ia->ia_addr.sin_addr,
                                     cp0, sizeof(struct in_addr));                                      cp0, sizeof(struct in_addr));
                                 ipt->ipt_ptr += sizeof(struct in_addr);                                  ipt->ipt_ptr += sizeof(struct in_addr);
                                 break;                                  break;
                           }
   
                         case IPOPT_TS_PRESPEC:                          case IPOPT_TS_PRESPEC:
                                 if (ipt->ipt_ptr - 1 + sizeof(n_time) +                                  if (ipt->ipt_ptr - 1 + sizeof(n_time) +
Line 1034  ip_dooptions(struct mbuf *m)
Line 1053  ip_dooptions(struct mbuf *m)
                 }                  }
         }          }
         if (forward) {          if (forward) {
                   struct ifnet *rcvif;
                   struct psref psref;
   
                 if (ip_forwsrcrt == 0) {                  if (ip_forwsrcrt == 0) {
                         type = ICMP_UNREACH;                          type = ICMP_UNREACH;
                         code = ICMP_UNREACH_SRCFAIL;                          code = ICMP_UNREACH_SRCFAIL;
                         goto bad;                          goto bad;
                 }                  }
                 ip_forward(m, 1);  
                   rcvif = m_get_rcvif_psref(m, &psref);
                   if (__predict_false(rcvif == NULL)) {
                           type = ICMP_UNREACH;
                           code = ICMP_UNREACH_HOST;
                           goto bad;
                   }
                   ip_forward(m, 1, rcvif);
                   m_put_rcvif_psref(rcvif, &psref);
                 return true;                  return true;
         }          }
         return false;          return false;
Line 1186  ip_drainstub(void)
Line 1216  ip_drainstub(void)
  * via a source route.   * via a source route.
  */   */
 static void  static void
 ip_forward(struct mbuf *m, int srcrt)  ip_forward(struct mbuf *m, int srcrt, struct ifnet *rcvif)
 {  {
         struct ip *ip = mtod(m, struct ip *);          struct ip *ip = mtod(m, struct ip *);
         struct rtentry *rt;          struct rtentry *rt;
Line 1254  ip_forward(struct mbuf *m, int srcrt)
Line 1284  ip_forward(struct mbuf *m, int srcrt)
          * Also, don't send redirect if forwarding using a default route           * Also, don't send redirect if forwarding using a default route
          * or a route modified by a redirect.           * or a route modified by a redirect.
          */           */
         if (rt->rt_ifp == m->m_pkthdr.rcvif &&          if (rt->rt_ifp == rcvif &&
             (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&              (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
             !in_nullhost(satocsin(rt_getkey(rt))->sin_addr) &&              !in_nullhost(satocsin(rt_getkey(rt))->sin_addr) &&
             ipsendredirects && !srcrt) {              ipsendredirects && !srcrt) {
Line 1360  ip_savecontrol(struct inpcb *inp, struct
Line 1390  ip_savecontrol(struct inpcb *inp, struct
     struct mbuf *m)      struct mbuf *m)
 {  {
         struct socket *so = inp->inp_socket;          struct socket *so = inp->inp_socket;
         ifnet_t *ifp = m->m_pkthdr.rcvif;          ifnet_t *ifp;
         int inpflags = inp->inp_flags;          int inpflags = inp->inp_flags;
           struct psref psref;
   
           ifp = m_get_rcvif_psref(m, &psref);
           if (__predict_false(ifp == NULL))
                   return; /* XXX should report error? */
   
         if (so->so_options & SO_TIMESTAMP          if (so->so_options & SO_TIMESTAMP
 #ifdef SO_OTIMESTAMP  #ifdef SO_OTIMESTAMP
Line 1423  ip_savecontrol(struct inpcb *inp, struct
Line 1458  ip_savecontrol(struct inpcb *inp, struct
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
           m_put_rcvif_psref(ifp, &psref);
 }  }
   
 /*  /*
Line 1584  sysctl_net_inet_ip_setup(struct sysctllo
Line 1620  sysctl_net_inet_ip_setup(struct sysctllo
                        sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0,                         sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0,
                        CTL_NET, PF_INET, IPPROTO_IP,                         CTL_NET, PF_INET, IPPROTO_IP,
                        IPCTL_MTUDISCTIMEOUT, CTL_EOL);                         IPCTL_MTUDISCTIMEOUT, CTL_EOL);
 #if NGIF > 0  
         sysctl_createv(clog, 0, NULL, NULL,  
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,  
                        CTLTYPE_INT, "gifttl",  
                        SYSCTL_DESCR("Default TTL for a gif tunnel datagram"),  
                        NULL, 0, &ip_gif_ttl, 0,  
                        CTL_NET, PF_INET, IPPROTO_IP,  
                        IPCTL_GIF_TTL, CTL_EOL);  
 #endif /* NGIF */  
 #ifndef IPNOPRIVPORTS  #ifndef IPNOPRIVPORTS
         sysctl_createv(clog, 0, NULL, NULL,          sysctl_createv(clog, 0, NULL, NULL,
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,                         CTLFLAG_PERMANENT|CTLFLAG_READWRITE,

Legend:
Removed from v.1.319.4.4  
changed lines
  Added in v.1.331

CVSweb <webmaster@jp.NetBSD.org>