[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.86 and 1.94.2.1

version 1.86, 2006/05/07 16:02:40 version 1.94.2.1, 2007/02/27 16:55:03
Line 112  __KERNEL_RCSID(0, "$NetBSD$");
Line 112  __KERNEL_RCSID(0, "$NetBSD$");
 #include <netinet6/ipsec.h>  #include <netinet6/ipsec.h>
 #endif  #endif
   
   #ifdef FAST_IPSEC
   #include <netipsec/ipsec.h>
   #include <netipsec/ipsec6.h>
   #include <netipsec/key.h>
   #endif /* FAST_IPSEC */
   
 #include <netinet6/ip6protosw.h>  #include <netinet6/ip6protosw.h>
   
 #include "faith.h"  #include "faith.h"
Line 189  ip6_init()
Line 195  ip6_init()
 }  }
   
 static void  static void
 ip6_init2(dummy)  ip6_init2(void *dummy)
         void *dummy;  
 {  {
   
         /* nd6_timer_init */          /* nd6_timer_init */
Line 232  ip6intr()
Line 237  ip6intr()
 extern struct   route_in6 ip6_forward_rt;  extern struct   route_in6 ip6_forward_rt;
   
 void  void
 ip6_input(m)  ip6_input(struct mbuf *m)
         struct mbuf *m;  
 {  {
         struct ip6_hdr *ip6;          struct ip6_hdr *ip6;
         int off = sizeof(struct ip6_hdr), nest;          int off = sizeof(struct ip6_hdr), nest;
Line 242  ip6_input(m)
Line 246  ip6_input(m)
         int nxt, ours = 0;          int nxt, ours = 0;
         struct ifnet *deliverifp = NULL;          struct ifnet *deliverifp = NULL;
         int srcrt = 0;          int srcrt = 0;
   #ifdef FAST_IPSEC
           struct m_tag *mtag;
           struct tdb_ident *tdbi;
           struct secpolicy *sp;
           int s, error;
   #endif
   
 #ifdef IPSEC  #ifdef IPSEC
         /*          /*
Line 266  ip6_input(m)
Line 276  ip6_input(m)
                 else                  else
                         ip6stat.ip6s_mext1++;                          ip6stat.ip6s_mext1++;
         } else {          } else {
 #define M2MMAX  (sizeof(ip6stat.ip6s_m2m)/sizeof(ip6stat.ip6s_m2m[0]))  #define M2MMAX  __arraycount(ip6stat.ip6s_m2m)
                 if (m->m_next) {                  if (m->m_next) {
                         if (m->m_flags & M_LOOP) {                          if (m->m_flags & M_LOOP) {
                                 ip6stat.ip6s_m2m[lo0ifp->if_index]++; /* XXX */                                  ip6stat.ip6s_m2m[lo0ifp->if_index]++; /* XXX */
Line 328  ip6_input(m)
Line 338  ip6_input(m)
          */           */
 #ifdef IPSEC  #ifdef IPSEC
         if (!ipsec_getnhist(m))          if (!ipsec_getnhist(m))
   #elif defined(FAST_IPSEC)
           if (!ipsec_indone(m))
 #else  #else
         if (1)          if (1)
 #endif  #endif
Line 410  ip6_input(m)
Line 422  ip6_input(m)
          * 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(
               m_makewritable(&m, 0, sizeof(struct ip6_hdr), M_DONTWAIT)))
                   goto bad;
           ip6 = mtod(m, struct ip6_hdr *);
         if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {          if (in6_clearscope(&ip6->ip6_src) || in6_clearscope(&ip6->ip6_dst)) {
                 ip6stat.ip6s_badscope++; /* XXX */                  ip6stat.ip6s_badscope++; /* XXX */
                 goto bad;                  goto bad;
Line 447  ip6_input(m)
Line 463  ip6_input(m)
         /*          /*
          *  Unicast check           *  Unicast check
          */           */
         if (ip6_forward_rt.ro_rt != NULL &&          if (!IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,
             (ip6_forward_rt.ro_rt->rt_flags & RTF_UP) != 0 &&              &((const struct sockaddr_in6 *)rtcache_getdst((const struct route *)&ip6_forward_rt))->sin6_addr))
             IN6_ARE_ADDR_EQUAL(&ip6->ip6_dst,                  rtcache_free((struct route *)&ip6_forward_rt);
             &((struct sockaddr_in6 *)(&ip6_forward_rt.ro_dst))->sin6_addr))          else
                   rtcache_check((struct route *)&ip6_forward_rt);
           if (ip6_forward_rt.ro_rt != NULL) {
                   /* XXX Revalidated route is accounted wrongly. */
                 ip6stat.ip6s_forward_cachehit++;                  ip6stat.ip6s_forward_cachehit++;
         else {          } else {
                 struct sockaddr_in6 *dst6;                  struct sockaddr_in6 *dst6;
   
                 if (ip6_forward_rt.ro_rt) {                  ip6stat.ip6s_forward_cachemiss++;
                         /* route is down or destination is different */  
                         ip6stat.ip6s_forward_cachemiss++;  
                         RTFREE(ip6_forward_rt.ro_rt);  
                         ip6_forward_rt.ro_rt = 0;  
                 }  
   
                 bzero(&ip6_forward_rt.ro_dst, sizeof(struct sockaddr_in6));                  dst6 = &ip6_forward_rt.ro_dst;
                 dst6 = (struct sockaddr_in6 *)&ip6_forward_rt.ro_dst;                  memset(dst6, 0, sizeof(*dst6));
                 dst6->sin6_len = sizeof(struct sockaddr_in6);                  dst6->sin6_len = sizeof(struct sockaddr_in6);
                 dst6->sin6_family = AF_INET6;                  dst6->sin6_family = AF_INET6;
                 dst6->sin6_addr = ip6->ip6_dst;                  dst6->sin6_addr = ip6->ip6_dst;
   
                 rtalloc((struct route *)&ip6_forward_rt);                  rtcache_init((struct route *)&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 482  ip6_input(m)
Line 496  ip6_input(m)
          * But we think it's even useful in some situations, e.g. when using           * But we think it's even useful in some situations, e.g. when using
          * a special daemon which wants to intercept the packet.           * a special daemon which wants to intercept the packet.
          */           */
         if (ip6_forward_rt.ro_rt &&          if (ip6_forward_rt.ro_rt != NULL &&
             (ip6_forward_rt.ro_rt->rt_flags &              (ip6_forward_rt.ro_rt->rt_flags &
              (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&               (RTF_HOST|RTF_GATEWAY)) == RTF_HOST &&
             !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) &&              !(ip6_forward_rt.ro_rt->rt_flags & RTF_CLONED) &&
Line 525  ip6_input(m)
Line 539  ip6_input(m)
          */           */
 #if defined(NFAITH) && 0 < NFAITH  #if defined(NFAITH) && 0 < NFAITH
         if (ip6_keepfaith) {          if (ip6_keepfaith) {
                 if (ip6_forward_rt.ro_rt && ip6_forward_rt.ro_rt->rt_ifp &&                  if (ip6_forward_rt.ro_rt != NULL &&
                       ip6_forward_rt.ro_rt->rt_ifp != NULL &&
                     ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) {                      ip6_forward_rt.ro_rt->rt_ifp->if_type == IFT_FAITH) {
                         /* XXX do we need more sanity checks? */                          /* XXX do we need more sanity checks? */
                         ours = 1;                          ours = 1;
Line 543  ip6_input(m)
Line 558  ip6_input(m)
          * working right.           * working right.
          */           */
         struct ifaddr *ifa;          struct ifaddr *ifa;
         for (ifa = m->m_pkthdr.rcvif->if_addrlist.tqh_first;          TAILQ_FOREACH(ifa, &m->m_pkthdr.rcvif->if_addrlist, ifa_list) {
              ifa;  
              ifa = ifa->ifa_list.tqe_next) {  
                 if (ifa->ifa_addr == NULL)                  if (ifa->ifa_addr == NULL)
                         continue;       /* just for safety */                          continue;       /* just for safety */
                 if (ifa->ifa_addr->sa_family != AF_INET6)                  if (ifa->ifa_addr->sa_family != AF_INET6)
Line 753  ip6_input(m)
Line 766  ip6_input(m)
                         goto bad;                          goto bad;
                 }                  }
 #endif  #endif
   #ifdef FAST_IPSEC
           /*
            * enforce IPsec policy checking if we are seeing last header.
            * note that we do not visit this with protocols with pcb layer
            * code - like udp/tcp/raw ip.
            */
           if ((inet6sw[ip_protox[nxt]].pr_flags & PR_LASTHDR) != 0) {
                   /*
                    * Check if the packet has already had IPsec processing
                    * done.  If so, then just pass it along.  This tag gets
                    * set during AH, ESP, etc. input handling, before the
                    * packet is returned to the ip input queue for delivery.
                    */
                   mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);
                   s = splsoftnet();
                   if (mtag != NULL) {
                           tdbi = (struct tdb_ident *)(mtag + 1);
                           sp = ipsec_getpolicy(tdbi, IPSEC_DIR_INBOUND);
                   } else {
                           sp = ipsec_getpolicybyaddr(m, IPSEC_DIR_INBOUND,
                                                                           IP_FORWARDING, &error);
                   }
                   if (sp != NULL) {
                           /*
                            * Check security policy against packet attributes.
                            */
                           error = ipsec_in_reject(sp, m);
                           KEY_FREESP(&sp);
                   } else {
                           /* XXX error stat??? */
                           error = EINVAL;
                           DPRINTF(("ip6_input: no SP, packet discarded\n"));/*XXX*/
                           goto bad;
                   }
                   splx(s);
                   if (error)
                           goto bad;
           }
   #endif /* FAST_IPSEC */
   
   
                 nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);                  nxt = (*inet6sw[ip6_protox[nxt]].pr_input)(&m, &off, nxt);
         }          }
Line 1048  ip6_savecontrol(in6p, mp, ip6, m)
Line 1101  ip6_savecontrol(in6p, mp, ip6, m)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
 #endif  #endif
   
           /* some OSes call this logic with IPv4 packet, for SO_TIMESTAMP */
           if ((ip6->ip6_vfc & IPV6_VERSION_MASK) != IPV6_VERSION)
                   return;
   
         /* RFC 2292 sec. 5 */          /* RFC 2292 sec. 5 */
         if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {          if ((in6p->in6p_flags & IN6P_PKTINFO) != 0) {
                 struct in6_pktinfo pi6;                  struct in6_pktinfo pi6;
Line 1239  ip6_savecontrol(in6p, mp, ip6, m)
Line 1297  ip6_savecontrol(in6p, mp, ip6, m)
   
   
 void  void
 ip6_notify_pmtu(struct in6pcb *in6p, struct sockaddr_in6 *dst, uint32_t *mtu)  ip6_notify_pmtu(struct in6pcb *in6p, const struct sockaddr_in6 *dst,
       uint32_t *mtu)
 {  {
         struct socket *so;          struct socket *so;
         struct mbuf *m_mtu;          struct mbuf *m_mtu;
Line 1265  ip6_notify_pmtu(struct in6pcb *in6p, str
Line 1324  ip6_notify_pmtu(struct in6pcb *in6p, str
             IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)              IPV6_PATHMTU, IPPROTO_IPV6)) == NULL)
                 return;                  return;
   
         if (sbappendaddr(&so->so_rcv, (struct sockaddr *)dst, NULL, m_mtu)          if (sbappendaddr(&so->so_rcv, (const struct sockaddr *)dst, NULL, m_mtu)
             == 0) {              == 0) {
                 m_freem(m_mtu);                  m_freem(m_mtu);
                 /* XXX: should count statistics */                  /* XXX: should count statistics */

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

CVSweb <webmaster@jp.NetBSD.org>