[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.296.2.4 and 1.298.6.1

version 1.296.2.4, 2014/05/22 11:41:09 version 1.298.6.1, 2018/02/09 14:12:22
Line 96  __KERNEL_RCSID(0, "$NetBSD$");
Line 96  __KERNEL_RCSID(0, "$NetBSD$");
 #include "opt_inet.h"  #include "opt_inet.h"
 #include "opt_compat_netbsd.h"  #include "opt_compat_netbsd.h"
 #include "opt_gateway.h"  #include "opt_gateway.h"
   #include "opt_pfil_hooks.h"
 #include "opt_ipsec.h"  #include "opt_ipsec.h"
 #include "opt_mrouting.h"  #include "opt_mrouting.h"
 #include "opt_mbuftrace.h"  #include "opt_mbuftrace.h"
Line 138  __KERNEL_RCSID(0, "$NetBSD$");
Line 139  __KERNEL_RCSID(0, "$NetBSD$");
 #ifdef MROUTING  #ifdef MROUTING
 #include <netinet/ip_mroute.h>  #include <netinet/ip_mroute.h>
 #endif  #endif
 #include <netinet/portalgo.h>  
   
 #ifdef IPSEC  #ifdef KAME_IPSEC
 #include <netipsec/ipsec.h>  #include <netinet6/ipsec.h>
   #include <netinet6/ipsec_private.h>
   #include <netkey/key.h>
 #endif  #endif
   #ifdef FAST_IPSEC
   #include <netipsec/ipsec.h>
   #include <netipsec/key.h>
   #endif  /* FAST_IPSEC*/
   
 #ifndef IPFORWARDING  #ifndef IPFORWARDING
 #ifdef GATEWAY  #ifdef GATEWAY
Line 155  __KERNEL_RCSID(0, "$NetBSD$");
Line 161  __KERNEL_RCSID(0, "$NetBSD$");
 #define IPSENDREDIRECTS 1  #define IPSENDREDIRECTS 1
 #endif  #endif
 #ifndef IPFORWSRCRT  #ifndef IPFORWSRCRT
 #define IPFORWSRCRT     1       /* forward source-routed packets */  #define IPFORWSRCRT     0       /* forward source-routed packets */
 #endif  #endif
 #ifndef IPALLOWSRCRT  #ifndef IPALLOWSRCRT
 #define IPALLOWSRCRT    1       /* allow source-routed packets */  #define IPALLOWSRCRT    0       /* allow source-routed packets */
 #endif  #endif
 #ifndef IPMTUDISC  #ifndef IPMTUDISC
 #define IPMTUDISC       1  #define IPMTUDISC       1
Line 229  uint16_t ip_id;
Line 235  uint16_t ip_id;
   
 percpu_t *ipstat_percpu;  percpu_t *ipstat_percpu;
   
 pfil_head_t *inet_pfil_hook;  #ifdef PFIL_HOOKS
   struct pfil_head inet_pfil_hook;
   #endif
   
 struct pool inmulti_pool;  struct pool inmulti_pool;
   
Line 324  ip_init(void)
Line 332  ip_init(void)
         ipflow_init(ip_hashsize);          ipflow_init(ip_hashsize);
 #endif  #endif
   
   #ifdef PFIL_HOOKS
         /* Register our Packet Filter hook. */          /* Register our Packet Filter hook. */
         inet_pfil_hook = pfil_head_create(PFIL_TYPE_AF, (void *)AF_INET);          inet_pfil_hook.ph_type = PFIL_TYPE_AF;
         KASSERT(inet_pfil_hook != NULL);          inet_pfil_hook.ph_af   = AF_INET;
           i = pfil_head_register(&inet_pfil_hook);
           if (i != 0)
                   printf("ip_init: WARNING: unable to register pfil hook, "
                       "error %d\n", i);
   #endif /* PFIL_HOOKS */
   
 #ifdef MBUFTRACE  #ifdef MBUFTRACE
         MOWNER_ATTACH(&ip_tx_mowner);          MOWNER_ATTACH(&ip_tx_mowner);
Line 395  ip_input(struct mbuf *m)
Line 409  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 516  ip_input(struct mbuf *m)
Line 536  ip_input(struct mbuf *m)
                         m_adj(m, len - m->m_pkthdr.len);                          m_adj(m, len - m->m_pkthdr.len);
         }          }
   
   #if defined(KAME_IPSEC)
           /* ipflow (IP fast forwarding) is not compatible with IPsec. */
           m->m_flags &= ~M_CANFASTFWD;
   #else
         /*          /*
          * Assume that we can create a fast-forward IP flow entry           * Assume that we can create a fast-forward IP flow entry
          * based on this packet.           * based on this packet.
          */           */
         m->m_flags |= M_CANFASTFWD;          m->m_flags |= M_CANFASTFWD;
   #endif
   
   #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
          * filters which require that additional packets in the flow are           * filters which require that additional packets in the flow are
Line 533  ip_input(struct mbuf *m)
Line 559  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(IPSEC)  #ifdef KAME_IPSEC
           if (!ipsec_getnhist(m))
   #elif defined(FAST_IPSEC)
         if (!ipsec_indone(m))          if (!ipsec_indone(m))
 #else  #else
         if (1)          if (1)
Line 542  ip_input(struct mbuf *m)
Line 570  ip_input(struct mbuf *m)
                 struct in_addr odst;                  struct in_addr odst;
   
                 odst = ip->ip_dst;                  odst = ip->ip_dst;
                 if (pfil_run_hooks(inet_pfil_hook, &m, m->m_pkthdr.rcvif,                  if (pfil_run_hooks(&inet_pfil_hook, &m, m->m_pkthdr.rcvif,
                     PFIL_IN) != 0)                      PFIL_IN) != 0)
                         return;                          return;
                 if (m == NULL)                  if (m == NULL)
Line 565  ip_input(struct mbuf *m)
Line 593  ip_input(struct mbuf *m)
                  */                   */
                 srcrt = (odst.s_addr != ip->ip_dst.s_addr);                  srcrt = (odst.s_addr != ip->ip_dst.s_addr);
         }          }
   #endif /* PFIL_HOOKS */
   
 #ifdef ALTQ  #ifdef ALTQ
         /* XXX Temporary until ALTQ is changed to use a pfil hook */          /* XXX Temporary until ALTQ is changed to use a pfil hook */
Line 714  ip_input(struct mbuf *m)
Line 743  ip_input(struct mbuf *m)
                         IP_STATINC(IP_STAT_CANTFORWARD);                          IP_STATINC(IP_STAT_CANTFORWARD);
                         return;                          return;
                 }                  }
 #ifdef IPSEC  #ifdef KAME_IPSEC
                 /* Perform IPsec, if any. */                  if (ipsec4_in_reject(m, NULL)) {
                 if (ipsec4_input(m, IP_FORWARDING | (ip_directedbcast ?                          IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
                     IP_ALLOWBROADCAST : 0)) != 0) {  
                         goto bad;                          goto bad;
                 }                  }
 #endif  #endif
   #ifdef FAST_IPSEC
                   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) {       /* 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;
                   }
   
                   /*
                    * 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 749  ours:
Line 826  ours:
                 hlen = ip->ip_hl << 2;                  hlen = ip->ip_hl << 2;
         }          }
   
 #ifdef IPSEC  #if defined(KAME_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 ((inetsw[ip_protox[ip->ip_p]].pr_flags & PR_LASTHDR) != 0 &&
               ipsec4_in_reject(m, NULL)) {
                   IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
                   goto bad;
           }
   #endif
   #ifdef FAST_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) {                  /*
                         goto bad;                   * 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;
         }          }
 #endif  #endif /* FAST_IPSEC */
   
         /*          /*
          * Switch out to protocol's input routine.           * Switch out to protocol's input routine.
Line 1336  ip_forward(struct mbuf *m, int srcrt)
Line 1451  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  
                 (void)ipsec4_forward(mcopy, &destmtu);  #if defined(KAME_IPSEC) || defined(FAST_IPSEC)
                   {
                           /*
                            * 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;
                                           }
                                   }
   
   #ifdef  KAME_IPSEC
                                   key_freesp(sp);
   #else
                                   KEY_FREESP(&sp);
 #endif  #endif
                           }
                   }
   #endif /*defined(KAME_IPSEC) || defined(FAST_IPSEC)*/
                 IP_STATINC(IP_STAT_CANTFRAG);                  IP_STATINC(IP_STAT_CANTFRAG);
                 break;                  break;
   
Line 1394  ip_savecontrol(struct inpcb *inp, struct
Line 1557  ip_savecontrol(struct inpcb *inp, struct
                 if (*mp)                  if (*mp)
                         mp = &(*mp)->m_next;                          mp = &(*mp)->m_next;
         }          }
         if (inp->inp_flags & INP_RECVPKTINFO) {  
                 struct in_pktinfo ipi;  
                 ipi.ipi_addr = ip->ip_src;  
                 ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;  
                 *mp = sbcreatecontrol((void *) &ipi,  
                     sizeof(ipi), IP_RECVPKTINFO, IPPROTO_IP);  
                 if (*mp)  
                         mp = &(*mp)->m_next;  
         }  
         if (inp->inp_flags & INP_PKTINFO) {  
                 struct in_pktinfo ipi;  
                 ipi.ipi_addr = ip->ip_dst;  
                 ipi.ipi_ifindex = m->m_pkthdr.rcvif->if_index;  
                 *mp = sbcreatecontrol((void *) &ipi,  
                     sizeof(ipi), IP_PKTINFO, IPPROTO_IP);  
                 if (*mp)  
                         mp = &(*mp)->m_next;  
         }  
 #ifdef notyet  #ifdef notyet
         /*          /*
          * XXX           * XXX
Line 1525  sysctl_net_inet_ip_maxflows(SYSCTLFN_ARG
Line 1670  sysctl_net_inet_ip_maxflows(SYSCTLFN_ARG
         mutex_enter(softnet_lock);          mutex_enter(softnet_lock);
         KERNEL_LOCK(1, NULL);          KERNEL_LOCK(1, NULL);
   
         ipflow_reap(false);          ipflow_prune();
   
         KERNEL_UNLOCK_ONE(NULL);          KERNEL_UNLOCK_ONE(NULL);
         mutex_exit(softnet_lock);          mutex_exit(softnet_lock);
Line 1583  sysctl_net_inet_ip_setup(struct sysctllo
Line 1728  sysctl_net_inet_ip_setup(struct sysctllo
   
         sysctl_createv(clog, 0, NULL, NULL,          sysctl_createv(clog, 0, NULL, NULL,
                        CTLFLAG_PERMANENT,                         CTLFLAG_PERMANENT,
                          CTLTYPE_NODE, "net", NULL,
                          NULL, 0, NULL, 0,
                          CTL_NET, CTL_EOL);
           sysctl_createv(clog, 0, NULL, NULL,
                          CTLFLAG_PERMANENT,
                        CTLTYPE_NODE, "inet",                         CTLTYPE_NODE, "inet",
                        SYSCTL_DESCR("PF_INET related settings"),                         SYSCTL_DESCR("PF_INET related settings"),
                        NULL, 0, NULL, 0,                         NULL, 0, NULL, 0,
Line 1679  sysctl_net_inet_ip_setup(struct sysctllo
Line 1829  sysctl_net_inet_ip_setup(struct sysctllo
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,                         CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                        CTLTYPE_INT, "mtudisctimeout",                         CTLTYPE_INT, "mtudisctimeout",
                        SYSCTL_DESCR("Lifetime of a Path MTU Discovered route"),                         SYSCTL_DESCR("Lifetime of a Path MTU Discovered route"),
                        sysctl_net_inet_ip_pmtudto, 0, (void *)&ip_mtudisc_timeout, 0,                         sysctl_net_inet_ip_pmtudto, 0, &ip_mtudisc_timeout, 0,
                        CTL_NET, PF_INET, IPPROTO_IP,                         CTL_NET, PF_INET, IPPROTO_IP,
                        IPCTL_MTUDISCTIMEOUT, CTL_EOL);                         IPCTL_MTUDISCTIMEOUT, CTL_EOL);
 #ifdef GATEWAY  #ifdef GATEWAY
Line 1770  sysctl_net_inet_ip_setup(struct sysctllo
Line 1920  sysctl_net_inet_ip_setup(struct sysctllo
                        sysctl_net_inet_ip_stats, 0, NULL, 0,                         sysctl_net_inet_ip_stats, 0, NULL, 0,
                        CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS,                         CTL_NET, PF_INET, IPPROTO_IP, IPCTL_STATS,
                        CTL_EOL);                         CTL_EOL);
   
         /* anonportalgo RFC6056 subtree */  
         const struct sysctlnode *portalgo_node;  
         sysctl_createv(clog, 0, NULL, &portalgo_node,  
                        CTLFLAG_PERMANENT,  
                        CTLTYPE_NODE, "anonportalgo",  
                        SYSCTL_DESCR("Anonymous Port Algorithm Selection (RFC 6056)"),  
                        NULL, 0, NULL, 0,  
                        CTL_NET, PF_INET, IPPROTO_IP, CTL_CREATE, CTL_EOL);  
         sysctl_createv(clog, 0, &portalgo_node, NULL,  
                        CTLFLAG_PERMANENT,  
                        CTLTYPE_STRING, "available",  
                        SYSCTL_DESCR("available algorithms"),  
                        sysctl_portalgo_available, 0, NULL, PORTALGO_MAXLEN,  
                        CTL_CREATE, CTL_EOL);  
         sysctl_createv(clog, 0, &portalgo_node, NULL,  
                        CTLFLAG_PERMANENT|CTLFLAG_READWRITE,  
                        CTLTYPE_STRING, "selected",  
                        SYSCTL_DESCR("selected algorithm"),  
                        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);  
 }  }
   
 void  void

Legend:
Removed from v.1.296.2.4  
changed lines
  Added in v.1.298.6.1

CVSweb <webmaster@jp.NetBSD.org>