[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.61 and 1.67

version 1.61, 2003/05/14 06:47:41 version 1.67, 2003/10/14 05:33:04
Line 42 
Line 42 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 149  struct ip6stat ip6stat;
Line 145  struct ip6stat ip6stat;
 static void ip6_init2 __P((void *));  static void ip6_init2 __P((void *));
   
 static int ip6_hopopts_input __P((u_int32_t *, u_int32_t *, struct mbuf **, int *));  static int ip6_hopopts_input __P((u_int32_t *, u_int32_t *, struct mbuf **, int *));
   static struct mbuf *ip6_pullexthdr __P((struct mbuf *, size_t, int));
   
 /*  /*
  * IP6 initialization: fill in IP6 protocol switch table.   * IP6 initialization: fill in IP6 protocol switch table.
Line 173  ip6_init()
Line 170  ip6_init()
         ip6intrq.ifq_maxlen = ip6qmaxlen;          ip6intrq.ifq_maxlen = ip6qmaxlen;
         nd6_init();          nd6_init();
         frag6_init();          frag6_init();
         ip6_flow_seq = arc4random();  
   
         ip6_init2((void *)0);          ip6_init2((void *)0);
   
Line 229  ip6_input(m)
Line 225  ip6_input(m)
         u_int32_t rtalert = ~0;          u_int32_t rtalert = ~0;
         int nxt, ours = 0;          int nxt, ours = 0;
         struct ifnet *deliverifp = NULL;          struct ifnet *deliverifp = NULL;
           int srcrt = 0;
   
 #ifdef IPSEC  #ifdef IPSEC
         /*          /*
Line 314  ip6_input(m)
Line 311  ip6_input(m)
         if (1)          if (1)
 #endif  #endif
         {          {
                   struct in6_addr odst;
   
                   odst = ip6->ip6_dst;
                 if (pfil_run_hooks(&inet6_pfil_hook, &m, m->m_pkthdr.rcvif,                  if (pfil_run_hooks(&inet6_pfil_hook, &m, m->m_pkthdr.rcvif,
                                    PFIL_IN) != 0)                                     PFIL_IN) != 0)
                         return;                          return;
                 if (m == NULL)                  if (m == NULL)
                         return;                          return;
                 ip6 = mtod(m, struct ip6_hdr *);                  ip6 = mtod(m, struct ip6_hdr *);
                   srcrt = !IN6_ARE_ADDR_EQUAL(&odst, &ip6->ip6_dst);
         }          }
 #endif /* PFIL_HOOKS */  #endif /* PFIL_HOOKS */
   
Line 682  ip6_input(m)
Line 683  ip6_input(m)
                         return;                          return;
                 }                  }
         } else if (!ours) {          } else if (!ours) {
                 ip6_forward(m, 0);                  ip6_forward(m, srcrt);
                 return;                  return;
         }          }
   
Line 1011  ip6_savecontrol(in6p, mp, ip6, m)
Line 1012  ip6_savecontrol(in6p, mp, ip6, m)
   
                 microtime(&tv);                  microtime(&tv);
                 *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),                  *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),
                         SCM_TIMESTAMP, SOL_SOCKET);                      SCM_TIMESTAMP, SOL_SOCKET);
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
 #endif  #endif
         if (in6p->in6p_flags & IN6P_RECVDSTADDR) {          if (in6p->in6p_flags & IN6P_RECVDSTADDR) {
                 *mp = sbcreatecontrol((caddr_t) &ip6->ip6_dst,                  *mp = sbcreatecontrol((caddr_t) &ip6->ip6_dst,
                         sizeof(struct in6_addr), IPV6_RECVDSTADDR,                      sizeof(struct in6_addr), IPV6_RECVDSTADDR, IPPROTO_IPV6);
                         IPPROTO_IPV6);  
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
Line 1043  ip6_savecontrol(in6p, mp, ip6, m)
Line 1043  ip6_savecontrol(in6p, mp, ip6, m)
                                         ? m->m_pkthdr.rcvif->if_index                                          ? m->m_pkthdr.rcvif->if_index
                                         : 0;                                          : 0;
                 *mp = sbcreatecontrol((caddr_t) &pi6,                  *mp = sbcreatecontrol((caddr_t) &pi6,
                         sizeof(struct in6_pktinfo), IPV6_PKTINFO,                      sizeof(struct in6_pktinfo), IPV6_PKTINFO, IPPROTO_IPV6);
                         IPPROTO_IPV6);  
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
         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((caddr_t) &hlim,                  *mp = sbcreatecontrol((caddr_t) &hlim, sizeof(int),
                         sizeof(int), IPV6_HOPLIMIT, IPPROTO_IPV6);                      IPV6_HOPLIMIT, IPPROTO_IPV6);
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
Line 1075  ip6_savecontrol(in6p, mp, ip6, m)
Line 1074  ip6_savecontrol(in6p, mp, ip6, m)
                 if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {                  if (ip6->ip6_nxt == IPPROTO_HOPOPTS) {
                         struct ip6_hbh *hbh;                          struct ip6_hbh *hbh;
                         int hbhlen;                          int hbhlen;
                           struct mbuf *ext;
   
                         IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,                          ext = ip6_pullexthdr(m, sizeof(struct ip6_hdr),
                                 sizeof(struct ip6_hdr), sizeof(struct ip6_hbh));                              ip6->ip6_nxt);
                         if (hbh == NULL) {                          if (ext == NULL) {
                                 ip6stat.ip6s_tooshort++;                                  ip6stat.ip6s_tooshort++;
                                 return;                                  return;
                         }                          }
                           hbh = mtod(ext, struct ip6_hbh *);
                         hbhlen = (hbh->ip6h_len + 1) << 3;                          hbhlen = (hbh->ip6h_len + 1) << 3;
                         IP6_EXTHDR_GET(hbh, struct ip6_hbh *, m,                          if (hbhlen != ext->m_len) {
                                 sizeof(struct ip6_hdr), hbhlen);                                  m_freem(ext);
                         if (hbh == NULL) {  
                                 ip6stat.ip6s_tooshort++;                                  ip6stat.ip6s_tooshort++;
                                 return;                                  return;
                         }                          }
Line 1097  ip6_savecontrol(in6p, mp, ip6, m)
Line 1097  ip6_savecontrol(in6p, mp, ip6, m)
                          * But it's too painful operation...                           * But it's too painful operation...
                          */                           */
                         *mp = sbcreatecontrol((caddr_t)hbh, hbhlen,                          *mp = sbcreatecontrol((caddr_t)hbh, hbhlen,
                                               IPV6_HOPOPTS, IPPROTO_IPV6);                              IPV6_HOPOPTS, IPPROTO_IPV6);
                         if (*mp)                          if (*mp)
                                 mp = &(*mp)->m_next;                                  mp = &(*mp)->m_next;
                           m_freem(ext);
                 }                  }
         }          }
   
Line 1116  ip6_savecontrol(in6p, mp, ip6, m)
Line 1117  ip6_savecontrol(in6p, mp, ip6, m)
                  * the chain of ancillary data.                   * the chain of ancillary data.
                  */                   */
                 while (1) {     /* is explicit loop prevention necessary? */                  while (1) {     /* is explicit loop prevention necessary? */
                         struct ip6_ext *ip6e;                          struct ip6_ext *ip6e = NULL;
                         int elen;                          int elen;
                           struct mbuf *ext = NULL;
   
                         IP6_EXTHDR_GET(ip6e, struct ip6_ext *, m, off,                          /*
                                 sizeof(struct ip6_ext));                           * if it is not an extension header, don't try to
                         if (ip6e == NULL) {                           * pull it from the chain.
                            */
                           switch (nxt) {
                           case IPPROTO_DSTOPTS:
                           case IPPROTO_ROUTING:
                           case IPPROTO_HOPOPTS:
                           case IPPROTO_AH: /* is it possible? */
                                   break;
                           default:
                                   goto loopend;
                           }
   
                           ext = ip6_pullexthdr(m, off, nxt);
                           if (ext == NULL) {
                                 ip6stat.ip6s_tooshort++;                                  ip6stat.ip6s_tooshort++;
                                 return;                                  return;
                         }                          }
                           ip6e = mtod(ext, struct ip6_ext *);
                         if (nxt == IPPROTO_AH)                          if (nxt == IPPROTO_AH)
                                 elen = (ip6e->ip6e_len + 2) << 2;                                  elen = (ip6e->ip6e_len + 2) << 2;
                         else                          else
                                 elen = (ip6e->ip6e_len + 1) << 3;                                  elen = (ip6e->ip6e_len + 1) << 3;
                         IP6_EXTHDR_GET(ip6e, struct ip6_ext *, m, off, elen);                          if (elen != ext->m_len) {
                         if (ip6e == NULL) {                                  m_freem(ext);
                                 ip6stat.ip6s_tooshort++;                                  ip6stat.ip6s_tooshort++;
                                 return;                                  return;
                         }                          }
                         KASSERT(IP6_HDR_ALIGNED_P(ip6e));                          KASSERT(IP6_HDR_ALIGNED_P(ip6e));
   
                         switch (nxt) {                          switch (nxt) {
                         case IPPROTO_DSTOPTS:                          case IPPROTO_DSTOPTS:
                                 if (!in6p->in6p_flags & IN6P_DSTOPTS)                                  if (!in6p->in6p_flags & IN6P_DSTOPTS)
                                         break;                                          break;
   
Line 1150  ip6_savecontrol(in6p, mp, ip6, m)
Line 1166  ip6_savecontrol(in6p, mp, ip6, m)
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol((caddr_t)ip6e, elen,                                  *mp = sbcreatecontrol((caddr_t)ip6e, elen,
                                                       IPV6_DSTOPTS,                                      IPV6_DSTOPTS, IPPROTO_IPV6);
                                                       IPPROTO_IPV6);  
                                 if (*mp)                                  if (*mp)
                                         mp = &(*mp)->m_next;                                          mp = &(*mp)->m_next;
                                 break;                                  break;
Line 1161  ip6_savecontrol(in6p, mp, ip6, m)
Line 1176  ip6_savecontrol(in6p, mp, ip6, m)
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol((caddr_t)ip6e, elen,                                  *mp = sbcreatecontrol((caddr_t)ip6e, elen,
                                                       IPV6_RTHDR,                                      IPV6_RTHDR, IPPROTO_IPV6);
                                                       IPPROTO_IPV6);  
                                 if (*mp)                                  if (*mp)
                                         mp = &(*mp)->m_next;                                          mp = &(*mp)->m_next;
                                 break;                                  break;
   
                         case IPPROTO_UDP:                          case IPPROTO_HOPOPTS:
                         case IPPROTO_TCP:                          case IPPROTO_AH: /* is it possible? */
                         case IPPROTO_ICMPV6:                                  break;
   
                         default:                          default:
                                 /*                                  /*
                                  * stop search if we encounter an upper                                   * other cases have been filtered in the above.
                                  * layer protocol headers.                                   * none will visit this case.  here we supply
                                    * the code just in case (nxt overwritten or
                                    * other cases).
                                  */                                   */
                                   m_freem(ext);
                                 goto loopend;                                  goto loopend;
   
                         case IPPROTO_HOPOPTS:  
                         case IPPROTO_AH: /* is it possible? */  
                                 break;  
                         }                          }
   
                         /* proceed with the next header. */                          /* proceed with the next header. */
                         off += elen;                          off += elen;
                         nxt = ip6e->ip6e_nxt;                          nxt = ip6e->ip6e_nxt;
                           ip6e = NULL;
                           m_freem(ext);
                           ext = NULL;
                 }                  }
           loopend:            loopend:
                 ;                  ;
         }          }
         if ((in6p->in6p_flags & IN6P_HOPOPTS) && privileged) {  }
                 /* to be done */  
   /*
    * pull single extension header from mbuf chain.  returns single mbuf that
    * contains the result, or NULL on error.
    */
   static struct mbuf *
   ip6_pullexthdr(m, off, nxt)
           struct mbuf *m;
           size_t off;
           int nxt;
   {
           struct ip6_ext ip6e;
           size_t elen;
           struct mbuf *n;
   
   #ifdef DIAGNOSTIC
           switch (nxt) {
           case IPPROTO_DSTOPTS:
           case IPPROTO_ROUTING:
           case IPPROTO_HOPOPTS:
           case IPPROTO_AH: /* is it possible? */
                   break;
           default:
                   printf("ip6_pullexthdr: invalid nxt=%d\n", nxt);
         }          }
         if ((in6p->in6p_flags & IN6P_DSTOPTS) && privileged) {  #endif
                 /* to be done */  
           m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);
           if (nxt == IPPROTO_AH)
                   elen = (ip6e.ip6e_len + 2) << 2;
           else
                   elen = (ip6e.ip6e_len + 1) << 3;
   
           MGET(n, M_DONTWAIT, MT_DATA);
           if (n && elen >= MLEN) {
                   MCLGET(n, M_DONTWAIT);
                   if ((n->m_flags & M_EXT) == 0) {
                           m_free(n);
                           n = NULL;
                   }
           }
           if (!n)
                   return NULL;
   
           n->m_len = 0;
           if (elen >= M_TRAILINGSPACE(n)) {
                   m_free(n);
                   return NULL;
         }          }
         /* IN6P_RTHDR - to be done */  
   
           m_copydata(m, off, elen, mtod(n, caddr_t));
           n->m_len = elen;
           return n;
 }  }
   
 /*  /*
Line 1287  ip6_nexthdr(m, off, proto, nxtp)
Line 1351  ip6_nexthdr(m, off, proto, nxtp)
                 if (m->m_pkthdr.len < off + sizeof(fh))                  if (m->m_pkthdr.len < off + sizeof(fh))
                         return -1;                          return -1;
                 m_copydata(m, off, sizeof(fh), (caddr_t)&fh);                  m_copydata(m, off, sizeof(fh), (caddr_t)&fh);
                 if ((ntohs(fh.ip6f_offlg) & IP6F_OFF_MASK) != 0)                  if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
                         return -1;                          return -1;
                 if (nxtp)                  if (nxtp)
                         *nxtp = fh.ip6f_nxt;                          *nxtp = fh.ip6f_nxt;

Legend:
Removed from v.1.61  
changed lines
  Added in v.1.67

CVSweb <webmaster@jp.NetBSD.org>