[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.94.2.1 and 1.103

version 1.94.2.1, 2007/02/27 16:55:03 version 1.103, 2007/05/02 20:40:27
Line 182  ip6_init()
Line 182  ip6_init()
         ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;          ip6_desync_factor = arc4random() % MAX_TEMP_DESYNC_FACTOR;
   
         ip6_init2((void *)0);          ip6_init2((void *)0);
   #ifdef GATEWAY
           ip6flow_init(ip6_hashsize);
   #endif
   
 #ifdef PFIL_HOOKS  #ifdef PFIL_HOOKS
         /* Register our Packet Filter hook. */          /* Register our Packet Filter hook. */
Line 234  ip6intr()
Line 237  ip6intr()
         }          }
 }  }
   
 extern struct   route_in6 ip6_forward_rt;  extern struct   route ip6_forward_rt;
   
 void  void
 ip6_input(struct mbuf *m)  ip6_input(struct mbuf *m)
Line 246  ip6_input(struct mbuf *m)
Line 249  ip6_input(struct mbuf *m)
         int nxt, ours = 0;          int nxt, ours = 0;
         struct ifnet *deliverifp = NULL;          struct ifnet *deliverifp = NULL;
         int srcrt = 0;          int srcrt = 0;
           const struct sockaddr_in6 *cdst;
 #ifdef FAST_IPSEC  #ifdef FAST_IPSEC
         struct m_tag *mtag;          struct m_tag *mtag;
         struct tdb_ident *tdbi;          struct tdb_ident *tdbi;
Line 298  ip6_input(struct mbuf *m)
Line 302  ip6_input(struct mbuf *m)
          * it.  Otherwise, if it is aligned, make sure the entire base           * it.  Otherwise, if it is aligned, make sure the entire base
          * IPv6 header is in the first mbuf of the chain.           * IPv6 header is in the first mbuf of the chain.
          */           */
         if (IP6_HDR_ALIGNED_P(mtod(m, caddr_t)) == 0) {          if (IP6_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
                 struct ifnet *inifp = m->m_pkthdr.rcvif;                  struct ifnet *inifp = m->m_pkthdr.rcvif;
                 if ((m = m_copyup(m, sizeof(struct ip6_hdr),                  if ((m = m_copyup(m, sizeof(struct ip6_hdr),
                                   (max_linkhdr + 3) & ~3)) == NULL) {                                    (max_linkhdr + 3) & ~3)) == NULL) {
Line 324  ip6_input(struct mbuf *m)
Line 328  ip6_input(struct mbuf *m)
                 goto bad;                  goto bad;
         }          }
   
   #if defined(IPSEC)
           /* IPv6 fast forwarding is not compatible with IPsec. */
           m->m_flags &= ~M_CANFASTFWD;
   #else
           /*
            * Assume that we can create a fast-forward IP flow entry
            * based on this packet.
            */
           m->m_flags |= M_CANFASTFWD;
   #endif
   
 #ifdef PFIL_HOOKS  #ifdef PFIL_HOOKS
         /*          /*
          * Run through list of hooks for input packets.  If there are any           * Run through list of hooks for input packets.  If there are any
Line 460  ip6_input(struct mbuf *m)
Line 475  ip6_input(struct mbuf *m)
                 goto hbhcheck;                  goto hbhcheck;
         }          }
   
           cdst = satocsin6(rtcache_getdst(&ip6_forward_rt));
         /*          /*
          *  Unicast check           *  Unicast check
          */           */
         if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,          if (cdst == NULL)
             &((const struct sockaddr_in6 *)rtcache_getdst((const struct route *)&ip6_forward_rt))->sin6_addr))                  ;
                 rtcache_free((struct route *)&ip6_forward_rt);          else if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst, &cdst->sin6_addr))
                   rtcache_free(&ip6_forward_rt);
         else          else
                 rtcache_check((struct route *)&ip6_forward_rt);                  rtcache_check(&ip6_forward_rt);
         if (ip6_forward_rt.ro_rt != NULL) {          if (ip6_forward_rt.ro_rt != NULL) {
                 /* XXX Revalidated route is accounted wrongly. */                  /* XXX Revalidated route is accounted wrongly. */
                 ip6stat.ip6s_forward_cachehit++;                  ip6stat.ip6s_forward_cachehit++;
         } else {          } else {
                 struct sockaddr_in6 *dst6;                  union {
                           struct sockaddr         dst;
                           struct sockaddr_in6     dst6;
                   } u;
   
                 ip6stat.ip6s_forward_cachemiss++;                  ip6stat.ip6s_forward_cachemiss++;
   
                 dst6 = &ip6_forward_rt.ro_dst;                  sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
                 memset(dst6, 0, sizeof(*dst6));                  rtcache_setdst(&ip6_forward_rt, &u.dst);
                 dst6->sin6_len = sizeof(struct sockaddr_in6);  
                 dst6->sin6_family = AF_INET6;  
                 dst6->sin6_addr = ip6->ip6_dst;  
   
                 rtcache_init((struct route *)&ip6_forward_rt);                  rtcache_init(&ip6_forward_rt);
         }          }
   
 #define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key))  #define rt6_key(r) ((struct sockaddr_in6 *)((r)->rt_nodes->rn_key))
Line 639  ip6_input(struct mbuf *m)
Line 656  ip6_input(struct mbuf *m)
                         in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);                          in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_hdrerr);
                         icmp6_error(m, ICMP6_PARAM_PROB,                          icmp6_error(m, ICMP6_PARAM_PROB,
                                     ICMP6_PARAMPROB_HEADER,                                      ICMP6_PARAMPROB_HEADER,
                                     (caddr_t)&ip6->ip6_plen - (caddr_t)ip6);                                      (char *)&ip6->ip6_plen - (char *)ip6);
                         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),
Line 936  ip6_process_hopopts(m, opthead, hbhlen, 
Line 953  ip6_process_hopopts(m, opthead, hbhlen, 
                                 return (-1);                                  return (-1);
                         }                          }
                         optlen = IP6OPT_RTALERT_LEN;                          optlen = IP6OPT_RTALERT_LEN;
                         bcopy((caddr_t)(opt + 2), (caddr_t)&rtalert_val, 2);                          bcopy((void *)(opt + 2), (void *)&rtalert_val, 2);
                         *rtalertp = ntohs(rtalert_val);                          *rtalertp = ntohs(rtalert_val);
                         break;                          break;
                 case IP6OPT_JUMBO:                  case IP6OPT_JUMBO:
Line 1095  ip6_savecontrol(in6p, mp, ip6, m)
Line 1112  ip6_savecontrol(in6p, mp, ip6, m)
                 struct timeval tv;                  struct timeval tv;
   
                 microtime(&tv);                  microtime(&tv);
                 *mp = sbcreatecontrol((caddr_t) &tv, sizeof(tv),                  *mp = sbcreatecontrol((void *) &tv, sizeof(tv),
                     SCM_TIMESTAMP, SOL_SOCKET);                      SCM_TIMESTAMP, SOL_SOCKET);
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
Line 1114  ip6_savecontrol(in6p, mp, ip6, m)
Line 1131  ip6_savecontrol(in6p, mp, ip6, m)
                 in6_clearscope(&pi6.ipi6_addr); /* XXX */                  in6_clearscope(&pi6.ipi6_addr); /* XXX */
                 pi6.ipi6_ifindex = m->m_pkthdr.rcvif ?                  pi6.ipi6_ifindex = m->m_pkthdr.rcvif ?
                     m->m_pkthdr.rcvif->if_index : 0;                      m->m_pkthdr.rcvif->if_index : 0;
                 *mp = sbcreatecontrol((caddr_t) &pi6,                  *mp = sbcreatecontrol((void *) &pi6,
                     sizeof(struct in6_pktinfo),                      sizeof(struct in6_pktinfo),
                     IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);                      IS2292(IPV6_2292PKTINFO, IPV6_PKTINFO), IPPROTO_IPV6);
                 if (*mp)                  if (*mp)
Line 1124  ip6_savecontrol(in6p, mp, ip6, m)
Line 1141  ip6_savecontrol(in6p, mp, ip6, m)
         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, sizeof(int),                  *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 1138  ip6_savecontrol(in6p, mp, ip6, m)
Line 1155  ip6_savecontrol(in6p, mp, ip6, m)
                 flowinfo >>= 20;                  flowinfo >>= 20;
   
                 tclass = flowinfo & 0xff;                  tclass = flowinfo & 0xff;
                 *mp = sbcreatecontrol((caddr_t)&tclass, sizeof(tclass),                  *mp = sbcreatecontrol((void *)&tclass, sizeof(tclass),
                     IPV6_TCLASS, IPPROTO_IPV6);                      IPV6_TCLASS, IPPROTO_IPV6);
   
                 if (*mp)                  if (*mp)
Line 1186  ip6_savecontrol(in6p, mp, ip6, m)
Line 1203  ip6_savecontrol(in6p, mp, ip6, m)
                          * 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((caddr_t)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 1248  ip6_savecontrol(in6p, mp, ip6, m)
Line 1265  ip6_savecontrol(in6p, mp, ip6, m)
                                 if (!in6p->in6p_flags & IN6P_DSTOPTS)                                  if (!in6p->in6p_flags & IN6P_DSTOPTS)
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol((caddr_t)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 1259  ip6_savecontrol(in6p, mp, ip6, m)
Line 1276  ip6_savecontrol(in6p, mp, ip6, m)
                                 if (!in6p->in6p_flags & IN6P_RTHDR)                                  if (!in6p->in6p_flags & IN6P_RTHDR)
                                         break;                                          break;
   
                                 *mp = sbcreatecontrol((caddr_t)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 1320  ip6_notify_pmtu(struct in6pcb *in6p, con
Line 1337  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((caddr_t)&mtuctl, sizeof(mtuctl),          if ((m_mtu = sbcreatecontrol((void *)&mtuctl, sizeof(mtuctl),
             IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)              IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
                 return;                  return;
   
Line 1360  ip6_pullexthdr(m, off, nxt)
Line 1377  ip6_pullexthdr(m, off, nxt)
         }          }
 #endif  #endif
   
         m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);          m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
         if (nxt == IPPROTO_AH)          if (nxt == IPPROTO_AH)
                 elen = (ip6e.ip6e_len + 2) << 2;                  elen = (ip6e.ip6e_len + 2) << 2;
         else          else
Line 1383  ip6_pullexthdr(m, off, nxt)
Line 1400  ip6_pullexthdr(m, off, nxt)
                 return NULL;                  return NULL;
         }          }
   
         m_copydata(m, off, elen, mtod(n, caddr_t));          m_copydata(m, off, elen, mtod(n, void *));
         n->m_len = elen;          n->m_len = elen;
         return n;          return n;
 }  }
Line 1416  ip6_get_prevhdr(m, off)
Line 1433  ip6_get_prevhdr(m, off)
                 nxt = ip6->ip6_nxt;                  nxt = ip6->ip6_nxt;
                 len = sizeof(struct ip6_hdr);                  len = sizeof(struct ip6_hdr);
                 while (len < off) {                  while (len < off) {
                         ip6e = (struct ip6_ext *)(mtod(m, caddr_t) + len);                          ip6e = (struct ip6_ext *)(mtod(m, char *) + len);
   
                         switch (nxt) {                          switch (nxt) {
                         case IPPROTO_FRAGMENT:                          case IPPROTO_FRAGMENT:
Line 1465  ip6_nexthdr(m, off, proto, nxtp)
Line 1482  ip6_nexthdr(m, off, proto, nxtp)
                         return -1;                          return -1;
                 if (m->m_pkthdr.len < off + sizeof(ip6))                  if (m->m_pkthdr.len < off + sizeof(ip6))
                         return -1;                          return -1;
                 m_copydata(m, off, sizeof(ip6), (caddr_t)&ip6);                  m_copydata(m, off, sizeof(ip6), (void *)&ip6);
                 if (nxtp)                  if (nxtp)
                         *nxtp = ip6.ip6_nxt;                          *nxtp = ip6.ip6_nxt;
                 off += sizeof(ip6);                  off += sizeof(ip6);
Line 1478  ip6_nexthdr(m, off, proto, nxtp)
Line 1495  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), (void *)&fh);
                 if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)                  if ((fh.ip6f_offlg & IP6F_OFF_MASK) != 0)
                         return -1;                          return -1;
                 if (nxtp)                  if (nxtp)
Line 1489  ip6_nexthdr(m, off, proto, nxtp)
Line 1506  ip6_nexthdr(m, off, proto, nxtp)
         case IPPROTO_AH:          case IPPROTO_AH:
                 if (m->m_pkthdr.len < off + sizeof(ip6e))                  if (m->m_pkthdr.len < off + sizeof(ip6e))
                         return -1;                          return -1;
                 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);                  m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
                 if (nxtp)                  if (nxtp)
                         *nxtp = ip6e.ip6e_nxt;                          *nxtp = ip6e.ip6e_nxt;
                 off += (ip6e.ip6e_len + 2) << 2;                  off += (ip6e.ip6e_len + 2) << 2;
Line 1502  ip6_nexthdr(m, off, proto, nxtp)
Line 1519  ip6_nexthdr(m, off, proto, nxtp)
         case IPPROTO_DSTOPTS:          case IPPROTO_DSTOPTS:
                 if (m->m_pkthdr.len < off + sizeof(ip6e))                  if (m->m_pkthdr.len < off + sizeof(ip6e))
                         return -1;                          return -1;
                 m_copydata(m, off, sizeof(ip6e), (caddr_t)&ip6e);                  m_copydata(m, off, sizeof(ip6e), (void *)&ip6e);
                 if (nxtp)                  if (nxtp)
                         *nxtp = ip6e.ip6e_nxt;                          *nxtp = ip6e.ip6e_nxt;
                 off += (ip6e.ip6e_len + 1) << 3;                  off += (ip6e.ip6e_len + 1) << 3;
Line 1591  ip6_delaux(m)
Line 1608  ip6_delaux(m)
                 m_tag_delete(m, mtag);                  m_tag_delete(m, mtag);
 }  }
   
   #ifdef GATEWAY
   /*
    * sysctl helper routine for net.inet.ip6.maxflows. Since
    * we could reduce this value, call ip6flow_reap();
    */
   static int
   sysctl_net_inet6_ip6_maxflows(SYSCTLFN_ARGS)
   {
           int s;
   
           s = sysctl_lookup(SYSCTLFN_CALL(rnode));
           if (s || newp == NULL)
                   return (s);
   
           s = splsoftnet();
           ip6flow_reap(0);
           splx(s);
   
           return (0);
   }
   
   static int
   sysctl_net_inet6_ip6_hashsize(SYSCTLFN_ARGS)
   {
           int error, tmp;
           struct sysctlnode node;
   
           node = *rnode;
           tmp = ip6_hashsize;
           node.sysctl_data = &tmp;
           error = sysctl_lookup(SYSCTLFN_CALL(&node));
           if (error || newp == NULL)
                   return (error);
   
           if ((tmp & (tmp - 1)) == 0 && tmp != 0) {
                   /*
                    * Can only fail due to malloc()
                    */
                   if (ip6flow_invalidate_all(tmp))
                           return ENOMEM;
           } else {
                   /*
                    * EINVAL if not a power of 2
                    */
                   return EINVAL;
           }
   
           return (0);
   }
   #endif /* GATEWAY */
   
   static int
   sysctl_net_inet6_ip6_rht0(SYSCTLFN_ARGS)
   {
           int error, tmp;
           struct sysctlnode node;
   
           node = *rnode;
           tmp = ip6_rht0;
           node.sysctl_data = &tmp;
           error = sysctl_lookup(SYSCTLFN_CALL(&node));
           if (error || newp == NULL)
                   return error;
   
           switch (tmp) {
           case -1:        /* disable processing */
           case 0:         /* disable for host, enable for router */
           case 1:         /* enable for all */
                   break;
           default:
                   return EINVAL;
           }
           ip6_rht0 = tmp;
           return 0;
   }
   
 /*  /*
  * System control for IP6   * System control for IP6
  */   */
Line 1874  SYSCTL_SETUP(sysctl_net_inet6_ip6_setup,
Line 1967  SYSCTL_SETUP(sysctl_net_inet6_ip6_setup,
                        NULL, 0, &ip6_mcast_pmtu, 0,                         NULL, 0, &ip6_mcast_pmtu, 0,
                        CTL_NET, PF_INET6, IPPROTO_IPV6,                         CTL_NET, PF_INET6, IPPROTO_IPV6,
                        CTL_CREATE, CTL_EOL);                         CTL_CREATE, CTL_EOL);
   #ifdef GATEWAY
           sysctl_createv(clog, 0, NULL, NULL,
                           CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                           CTLTYPE_INT, "maxflows",
                           SYSCTL_DESCR("Number of flows for fast forwarding (IPv6)"),
                           sysctl_net_inet6_ip6_maxflows, 0, &ip6_maxflows, 0,
                           CTL_NET, PF_INET6, IPPROTO_IPV6,
                           CTL_CREATE, CTL_EOL);
           sysctl_createv(clog, 0, NULL, NULL,
                           CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                           CTLTYPE_INT, "hashsize",
                           SYSCTL_DESCR("Size of hash table for fast forwarding (IPv6)"),
                           sysctl_net_inet6_ip6_hashsize, 0, &ip6_hashsize, 0,
                           CTL_NET, PF_INET6, IPPROTO_IPV6,
                           CTL_CREATE, CTL_EOL);
   #endif
           sysctl_createv(clog, 0, NULL, NULL,
                           CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                           CTLTYPE_INT, "rht0",
                           SYSCTL_DESCR("Processing of routing header type 0 (IPv6)"),
                           sysctl_net_inet6_ip6_rht0, 0, &ip6_rht0, 0,
                           CTL_NET, PF_INET6, IPPROTO_IPV6,
                           CTL_CREATE, CTL_EOL);
 }  }

Legend:
Removed from v.1.94.2.1  
changed lines
  Added in v.1.103

CVSweb <webmaster@jp.NetBSD.org>