[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.302 and 1.302.2.2

version 1.302, 2012/06/25 15:28:39 version 1.302.2.2, 2013/06/23 06:20:25
Line 141  __KERNEL_RCSID(0, "$NetBSD$");
Line 141  __KERNEL_RCSID(0, "$NetBSD$");
 #endif  #endif
 #include <netinet/portalgo.h>  #include <netinet/portalgo.h>
   
 #ifdef FAST_IPSEC  #ifdef IPSEC
 #include <netipsec/ipsec.h>  #include <netipsec/ipsec.h>
 #include <netipsec/key.h>  #endif
 #endif  /* FAST_IPSEC*/  
   
 #ifndef IPFORWARDING  #ifndef IPFORWARDING
 #ifdef GATEWAY  #ifdef GATEWAY
Line 405  ip_input(struct mbuf *m)
Line 404  ip_input(struct mbuf *m)
         int downmatch;          int downmatch;
         int checkif;          int checkif;
         int srcrt = 0;          int srcrt = 0;
 #ifdef FAST_IPSEC  
         struct m_tag *mtag;  
         struct tdb_ident *tdbi;  
         struct secpolicy *sp;  
         int error, s;  
 #endif /* FAST_IPSEC */  
   
         MCLAIM(m, &ip_rx_mowner);          MCLAIM(m, &ip_rx_mowner);
         KASSERT((m->m_flags & M_PKTHDR) != 0);          KASSERT((m->m_flags & M_PKTHDR) != 0);
Line 550  ip_input(struct mbuf *m)
Line 543  ip_input(struct mbuf *m)
          * let ipfilter look at packet on the wire,           * let ipfilter look at packet on the wire,
          * not the decapsulated packet.           * not the decapsulated packet.
          */           */
 #if defined(FAST_IPSEC)  #if defined(IPSEC)
         if (!ipsec_indone(m))          if (!ipsec_indone(m))
 #else  #else
         if (1)          if (1)
Line 732  ip_input(struct mbuf *m)
Line 725  ip_input(struct mbuf *m)
                         IP_STATINC(IP_STAT_CANTFORWARD);                          IP_STATINC(IP_STAT_CANTFORWARD);
                         return;                          return;
                 }                  }
 #ifdef FAST_IPSEC  #ifdef IPSEC
                 mtag = m_tag_find(m, PACKET_TAG_IPSEC_IN_DONE, NULL);                  /* Perform IPsec, if any. */
                 s = splsoftnet();                  if (ipsec4_input(m, IP_FORWARDING | (ip_directedbcast ?
                 if (mtag != NULL) {                      IP_ALLOWBROADCAST : 0)) != 0) {
                         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) {       /* NB: can happen if error */  
                         splx(s);  
                         /*XXX error stat???*/  
                         DPRINTF(("ip_input: no SP for forwarding\n"));  /*XXX*/  
                         goto bad;  
                 }  
   
                 /*  
                  * Check security policy against packet attributes.  
                  */  
                 error = ipsec_in_reject(sp, m);  
                 KEY_FREESP(&sp);  
                 splx(s);  
                 if (error) {  
                         IP_STATINC(IP_STAT_CANTFORWARD);  
                         goto bad;                          goto bad;
                 }                  }
   #endif
                 /*  
                  * Peek at the outbound SP for this packet to determine if  
                  * it's a Fast Forward candidate.  
                  */  
                 mtag = m_tag_find(m, PACKET_TAG_IPSEC_PENDING_TDB, NULL);  
                 if (mtag != NULL)  
                         m->m_flags &= ~M_CANFASTFWD;  
                 else {  
                         s = splsoftnet();  
                         sp = ipsec4_checkpolicy(m, IPSEC_DIR_OUTBOUND,  
                             (IP_FORWARDING |  
                              (ip_directedbcast ? IP_ALLOWBROADCAST : 0)),  
                             &error, NULL);  
                         if (sp != NULL) {  
                                 m->m_flags &= ~M_CANFASTFWD;  
                                 KEY_FREESP(&sp);  
                         }  
                         splx(s);  
                 }  
 #endif  /* FAST_IPSEC */  
   
                 ip_forward(m, srcrt);                  ip_forward(m, srcrt);
         }          }
         return;          return;
Line 809  ours:
Line 760  ours:
                 hlen = ip->ip_hl << 2;                  hlen = ip->ip_hl << 2;
         }          }
   
 #ifdef FAST_IPSEC  #ifdef IPSEC
         /*          /*
          * enforce IPsec policy checking if we are seeing last header.           * Enforce IPsec policy checking if we are seeing last header.
          * note that we do not visit this with protocols with pcb layer           * Note that we do not visit this with protocols with PCB layer
          * code - like udp/tcp/raw ip.           * code - like UDP/TCP/raw IP.
          */           */
         if ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {          if ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0) {
                 /*                  if (ipsec4_input(m, 0) != 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(("ip_input: no SP, packet discarded\n"));/*XXX*/  
                 }  
                 splx(s);  
                 if (error)  
                         goto bad;                          goto bad;
                   }
         }          }
 #endif /* FAST_IPSEC */  #endif
   
         /*          /*
          * Switch out to protocol's input routine.           * Switch out to protocol's input routine.
Line 1422  ip_forward(struct mbuf *m, int srcrt)
Line 1347  ip_forward(struct mbuf *m, int srcrt)
   
                 if ((rt = rtcache_validate(&ipforward_rt)) != NULL)                  if ((rt = rtcache_validate(&ipforward_rt)) != NULL)
                         destmtu = rt->rt_ifp->if_mtu;                          destmtu = rt->rt_ifp->if_mtu;
   #ifdef IPSEC
 #if defined(FAST_IPSEC)                  (void)ipsec4_forward(mcopy, &destmtu);
                 {  #endif
                         /*  
                          * If the packet is routed over IPsec tunnel, tell the  
                          * originator the tunnel MTU.  
                          *      tunnel MTU = if MTU - sizeof(IP) - ESP/AH hdrsiz  
                          * XXX quickhack!!!  
                          */  
   
                         struct secpolicy *sp;  
                         int ipsecerror;  
                         size_t ipsechdr;  
                         struct route *ro;  
   
                         sp = ipsec4_getpolicybyaddr(mcopy,  
                             IPSEC_DIR_OUTBOUND, IP_FORWARDING,  
                             &ipsecerror);  
   
                         if (sp != NULL) {  
                                 /* count IPsec header size */  
                                 ipsechdr = ipsec4_hdrsiz(mcopy,  
                                     IPSEC_DIR_OUTBOUND, NULL);  
   
                                 /*  
                                  * find the correct route for outer IPv4  
                                  * header, compute tunnel MTU.  
                                  */  
   
                                 if (sp->req != NULL  
                                  && sp->req->sav != NULL  
                                  && sp->req->sav->sah != NULL) {  
                                         ro = &sp->req->sav->sah->sa_route;  
                                         rt = rtcache_validate(ro);  
                                         if (rt && rt->rt_ifp) {  
                                                 destmtu =  
                                                     rt->rt_rmx.rmx_mtu ?  
                                                     rt->rt_rmx.rmx_mtu :  
                                                     rt->rt_ifp->if_mtu;  
                                                 destmtu -= ipsechdr;  
                                         }  
                                 }  
   
                                 KEY_FREESP(&sp);  
                         }  
                 }  
 #endif /*defined(FAST_IPSEC)*/  
                 IP_STATINC(IP_STAT_CANTFRAG);                  IP_STATINC(IP_STAT_CANTFRAG);
                 break;                  break;
   
Line 1906  sysctl_net_inet_ip_setup(struct sysctllo
Line 1787  sysctl_net_inet_ip_setup(struct sysctllo
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,                         CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                        CTLTYPE_STRING, "selected",                         CTLTYPE_STRING, "selected",
                        SYSCTL_DESCR("selected algorithm"),                         SYSCTL_DESCR("selected algorithm"),
                        sysctl_portalgo_selected, 0, NULL, PORTALGO_MAXLEN,                         sysctl_portalgo_selected4, 0, NULL, PORTALGO_MAXLEN,
                          CTL_CREATE, CTL_EOL);
           sysctl_createv(clog, 0, &portalgo_node, NULL,
                          CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                          CTLTYPE_STRUCT, "reserve",
                          SYSCTL_DESCR("bitmap of reserved ports"),
                          sysctl_portalgo_reserve4, 0, NULL, 0,
                        CTL_CREATE, CTL_EOL);                         CTL_CREATE, CTL_EOL);
 }  }
   

Legend:
Removed from v.1.302  
changed lines
  Added in v.1.302.2.2

CVSweb <webmaster@jp.NetBSD.org>