[BACK]Return to udp_usrreq.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/udp_usrreq.c between version 1.183.2.2 and 1.197

version 1.183.2.2, 2012/10/30 17:22:47 version 1.197, 2014/05/20 19:04:00
Line 73  __KERNEL_RCSID(0, "$NetBSD$");
Line 73  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/malloc.h>  #include <sys/malloc.h>
 #include <sys/mbuf.h>  #include <sys/mbuf.h>
   #include <sys/once.h>
 #include <sys/protosw.h>  #include <sys/protosw.h>
 #include <sys/socket.h>  #include <sys/socket.h>
 #include <sys/socketvar.h>  #include <sys/socketvar.h>
Line 118  __KERNEL_RCSID(0, "$NetBSD$");
Line 119  __KERNEL_RCSID(0, "$NetBSD$");
 #include <net/if_faith.h>  #include <net/if_faith.h>
 #endif  #endif
   
 #ifdef FAST_IPSEC  #ifdef IPSEC
 #include <netipsec/ipsec.h>  #include <netipsec/ipsec.h>
 #include <netipsec/ipsec_var.h>  #include <netipsec/ipsec_var.h>
 #include <netipsec/ipsec_private.h>  #include <netipsec/ipsec_private.h>
Line 126  __KERNEL_RCSID(0, "$NetBSD$");
Line 127  __KERNEL_RCSID(0, "$NetBSD$");
 #ifdef INET6  #ifdef INET6
 #include <netipsec/ipsec6.h>  #include <netipsec/ipsec6.h>
 #endif  #endif
 #endif  /* FAST_IPSEC */  #endif  /* IPSEC */
   
 #ifdef COMPAT_50  #ifdef COMPAT_50
 #include <compat/sys/socket.h>  #include <compat/sys/socket.h>
Line 148  struct inpcbtable udbtable;
Line 149  struct inpcbtable udbtable;
 percpu_t *udpstat_percpu;  percpu_t *udpstat_percpu;
   
 #ifdef INET  #ifdef INET
 #ifdef IPSEC_NAT_T  #ifdef IPSEC
 static int udp4_espinudp (struct mbuf **, int, struct sockaddr *,  static int udp4_espinudp (struct mbuf **, int, struct sockaddr *,
         struct socket *);          struct socket *);
 #endif  #endif
Line 174  static void udp_notify (struct inpcb *, 
Line 175  static void udp_notify (struct inpcb *, 
 #endif  #endif
 int     udbhashsize = UDBHASHSIZE;  int     udbhashsize = UDBHASHSIZE;
   
   /*
    * For send - really max datagram size; for receive - 40 1K datagrams.
    */
   static int      udp_sendspace = 9216;
   static int      udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
   
 #ifdef MBUFTRACE  #ifdef MBUFTRACE
 struct mowner udp_mowner = MOWNER_INIT("udp", "");  struct mowner udp_mowner = MOWNER_INIT("udp", "");
 struct mowner udp_rx_mowner = MOWNER_INIT("udp", "rx");  struct mowner udp_rx_mowner = MOWNER_INIT("udp", "rx");
Line 225  EVCNT_ATTACH_STATIC(udp6_swcsum);
Line 232  EVCNT_ATTACH_STATIC(udp6_swcsum);
   
 static void sysctl_net_inet_udp_setup(struct sysctllog **);  static void sysctl_net_inet_udp_setup(struct sysctllog **);
   
 void  static int
 udp_init(void)  do_udpinit(void)
 {  {
   
         sysctl_net_inet_udp_setup(NULL);  
   
         in_pcbinit(&udbtable, udbhashsize, udbhashsize);          in_pcbinit(&udbtable, udbhashsize, udbhashsize);
           udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS);
   
         MOWNER_ATTACH(&udp_tx_mowner);          MOWNER_ATTACH(&udp_tx_mowner);
         MOWNER_ATTACH(&udp_rx_mowner);          MOWNER_ATTACH(&udp_rx_mowner);
         MOWNER_ATTACH(&udp_mowner);          MOWNER_ATTACH(&udp_mowner);
   
 #ifdef INET          return 0;
         udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS);  }
 #endif  
 #ifdef INET6  void
         udp6stat_percpu = percpu_alloc(sizeof(uint64_t) * UDP6_NSTATS);  udp_init_common(void)
 #endif  {
           static ONCE_DECL(doudpinit);
   
           RUN_ONCE(&doudpinit, do_udpinit);
   }
   
   void
   udp_init(void)
   {
   
           sysctl_net_inet_udp_setup(NULL);
   
           udp_init_common();
 }  }
   
 /*  /*
Line 404  udp_input(struct mbuf *m, ...)
Line 422  udp_input(struct mbuf *m, ...)
                 UDP_STATINC(UDP_STAT_HDROPS);                  UDP_STATINC(UDP_STAT_HDROPS);
                 return;                  return;
         }          }
           if (m == NULL) {
                   /*
                    * packet has been processed by ESP stuff -
                    * e.g. dropped NAT-T-keep-alive-packet ...
                    */
                   return;
           }
           ip = mtod(m, struct ip *);
 #ifdef INET6  #ifdef INET6
         if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) {          if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) {
                 struct sockaddr_in6 src6, dst6;                  struct sockaddr_in6 src6, dst6;
Line 626  udp4_sendup(struct mbuf *m, int off /* o
Line 652  udp4_sendup(struct mbuf *m, int off /* o
                 return;                  return;
         }          }
   
 #if defined(FAST_IPSEC)  #if defined(IPSEC)
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (so != NULL && ipsec4_in_reject_so(m, so)) {          if (so != NULL && ipsec4_in_reject_so(m, so)) {
                 IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);                  IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
Line 676  udp6_sendup(struct mbuf *m, int off /* o
Line 702  udp6_sendup(struct mbuf *m, int off /* o
                 return;                  return;
         in6p = sotoin6pcb(so);          in6p = sotoin6pcb(so);
   
 #if defined(FAST_IPSEC)  #if defined(IPSEC)
         /* check AH/ESP integrity. */          /* check AH/ESP integrity. */
         if (so != NULL && ipsec6_in_reject_so(m, so)) {          if (so != NULL && ipsec6_in_reject_so(m, so)) {
                 IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO);                  IPSEC6_STATINC(IPSEC_STAT_IN_POLVIO);
Line 758  udp4_realinput(struct sockaddr_in *src, 
Line 784  udp4_realinput(struct sockaddr_in *src, 
                 /*                  /*
                  * Locate pcb(s) for datagram.                   * Locate pcb(s) for datagram.
                  */                   */
                 CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {                  TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {
                         inp = (struct inpcb *)inph;                          inp = (struct inpcb *)inph;
                         if (inp->inp_af != AF_INET)                          if (inp->inp_af != AF_INET)
                                 continue;                                  continue;
Line 804  udp4_realinput(struct sockaddr_in *src, 
Line 830  udp4_realinput(struct sockaddr_in *src, 
                                 return rcvcnt;                                  return rcvcnt;
                 }                  }
   
 #ifdef IPSEC_NAT_T  #ifdef IPSEC
                 /* Handle ESP over UDP */                  /* Handle ESP over UDP */
                 if (inp->inp_flags & INP_ESPINUDP_ALL) {                  if (inp->inp_flags & INP_ESPINUDP_ALL) {
                         struct sockaddr *sa = (struct sockaddr *)src;                          struct sockaddr *sa = (struct sockaddr *)src;
Line 903  udp6_realinput(int af, struct sockaddr_i
Line 929  udp6_realinput(int af, struct sockaddr_i
                 /*                  /*
                  * Locate pcb(s) for datagram.                   * Locate pcb(s) for datagram.
                  */                   */
                 CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {                  TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {
                         in6p = (struct in6pcb *)inph;                          in6p = (struct in6pcb *)inph;
                         if (in6p->in6p_af != AF_INET6)                          if (in6p->in6p_af != AF_INET6)
                                 continue;                                  continue;
Line 1058  udp_ctloutput(int op, struct socket *so,
Line 1084  udp_ctloutput(int op, struct socket *so,
                                 break;                                  break;
   
                         switch(optval) {                          switch(optval) {
 #ifdef IPSEC_NAT_T  
                         case 0:                          case 0:
                                 inp->inp_flags &= ~INP_ESPINUDP_ALL;                                  inp->inp_flags &= ~INP_ESPINUDP_ALL;
                                 break;                                  break;
Line 1072  udp_ctloutput(int op, struct socket *so,
Line 1097  udp_ctloutput(int op, struct socket *so,
                                 inp->inp_flags &= ~INP_ESPINUDP_ALL;                                  inp->inp_flags &= ~INP_ESPINUDP_ALL;
                                 inp->inp_flags |= INP_ESPINUDP_NON_IKE;                                  inp->inp_flags |= INP_ESPINUDP_NON_IKE;
                                 break;                                  break;
 #endif  
                         default:                          default:
                                 error = EINVAL;                                  error = EINVAL;
                                 break;                                  break;
Line 1173  release:
Line 1197  release:
         return (error);          return (error);
 }  }
   
 int     udp_sendspace = 9216;           /* really max datagram size */  static int
 int     udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));  udp_attach(struct socket *so, int proto)
                                         /* 40 1K datagrams */  {
           struct inpcb *inp;
           int error;
   
           KASSERT(sotoinpcb(so) == NULL);
   
 /*ARGSUSED*/          /* Assign the lock (must happen even if we will error out). */
 int          sosetlock(so);
   
   #ifdef MBUFTRACE
           so->so_mowner = &udp_mowner;
           so->so_rcv.sb_mowner = &udp_rx_mowner;
           so->so_snd.sb_mowner = &udp_tx_mowner;
   #endif
           if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
                   error = soreserve(so, udp_sendspace, udp_recvspace);
                   if (error) {
                           return error;
                   }
           }
   
           error = in_pcballoc(so, &udbtable);
           if (error) {
                   return error;
           }
           inp = sotoinpcb(so);
           inp->inp_ip.ip_ttl = ip_defttl;
           KASSERT(solocked(so));
   
           return error;
   }
   
   static void
   udp_detach(struct socket *so)
   {
           struct inpcb *inp;
   
           KASSERT(solocked(so));
           inp = sotoinpcb(so);
           KASSERT(inp != NULL);
           in_pcbdetach(inp);
   }
   
   static int
 udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,  udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
         struct mbuf *control, struct lwp *l)      struct mbuf *control, struct lwp *l)
 {  {
         struct inpcb *inp;          struct inpcb *inp;
         int s;          int s, error = 0;
         int error = 0;  
   
         if (req == PRU_CONTROL)          KASSERT(req != PRU_ATTACH);
                 return (in_control(so, (long)m, (void *)nam,          KASSERT(req != PRU_DETACH);
                     (struct ifnet *)control, l));  
   
           if (req == PRU_CONTROL) {
                   return in_control(so, (long)m, (void *)nam,
                       (struct ifnet *)control, l);
           }
         s = splsoftnet();          s = splsoftnet();
   
         if (req == PRU_PURGEIF) {          if (req == PRU_PURGEIF) {
                 mutex_enter(softnet_lock);                  mutex_enter(softnet_lock);
                 in_pcbpurgeif0(&udbtable, (struct ifnet *)control);                  in_pcbpurgeif0(&udbtable, (struct ifnet *)control);
Line 1199  udp_usrreq(struct socket *so, int req, s
Line 1264  udp_usrreq(struct socket *so, int req, s
                 in_pcbpurgeif(&udbtable, (struct ifnet *)control);                  in_pcbpurgeif(&udbtable, (struct ifnet *)control);
                 mutex_exit(softnet_lock);                  mutex_exit(softnet_lock);
                 splx(s);                  splx(s);
                 return (0);                  return 0;
         }          }
   
           KASSERT(solocked(so));
         inp = sotoinpcb(so);          inp = sotoinpcb(so);
 #ifdef DIAGNOSTIC  
         if (req != PRU_SEND && req != PRU_SENDOOB && control)          KASSERT(!control || (req == PRU_SEND || req == PRU_SENDOOB));
                 panic("udp_usrreq: unexpected control mbuf");          if (inp == NULL) {
 #endif                  splx(s);
         if (req == PRU_ATTACH) {                  return EINVAL;
                 sosetlock(so);  
         } else if (inp == 0) {  
                 error = EINVAL;  
                 goto release;  
         }          }
   
         /*          /*
Line 1219  udp_usrreq(struct socket *so, int req, s
Line 1281  udp_usrreq(struct socket *so, int req, s
          * the udp pcb queue and/or pcb addresses.           * the udp pcb queue and/or pcb addresses.
          */           */
         switch (req) {          switch (req) {
   
         case PRU_ATTACH:  
                 if (inp != 0) {  
                         error = EISCONN;  
                         break;  
                 }  
 #ifdef MBUFTRACE  
                 so->so_mowner = &udp_mowner;  
                 so->so_rcv.sb_mowner = &udp_rx_mowner;  
                 so->so_snd.sb_mowner = &udp_tx_mowner;  
 #endif  
                 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {  
                         error = soreserve(so, udp_sendspace, udp_recvspace);  
                         if (error)  
                                 break;  
                 }  
                 error = in_pcballoc(so, &udbtable);  
                 if (error)  
                         break;  
                 inp = sotoinpcb(so);  
                 inp->inp_ip.ip_ttl = ip_defttl;  
                 break;  
   
         case PRU_DETACH:  
                 in_pcbdetach(inp);  
                 break;  
   
         case PRU_BIND:          case PRU_BIND:
                 error = in_pcbbind(inp, nam, l);                  error = in_pcbbind(inp, nam, l);
                 break;                  break;
Line 1348  udp_usrreq(struct socket *so, int req, s
Line 1383  udp_usrreq(struct socket *so, int req, s
         default:          default:
                 panic("udp_usrreq");                  panic("udp_usrreq");
         }          }
   
 release:  
         splx(s);          splx(s);
         return (error);  
           return error;
 }  }
   
 static int  static int
Line 1367  sysctl_net_inet_udp_stats(SYSCTLFN_ARGS)
Line 1401  sysctl_net_inet_udp_stats(SYSCTLFN_ARGS)
 static void  static void
 sysctl_net_inet_udp_setup(struct sysctllog **clog)  sysctl_net_inet_udp_setup(struct sysctllog **clog)
 {  {
         sysctl_createv(clog, 0, NULL, NULL,  
                        CTLFLAG_PERMANENT,  
                        CTLTYPE_NODE, "net", NULL,  
                        NULL, 0, NULL, 0,  
                        CTL_NET, CTL_EOL);  
         sysctl_createv(clog, 0, NULL, NULL,          sysctl_createv(clog, 0, NULL, NULL,
                        CTLFLAG_PERMANENT,                         CTLFLAG_PERMANENT,
                        CTLTYPE_NODE, "inet", NULL,                         CTLTYPE_NODE, "inet", NULL,
Line 1437  udp_statinc(u_int stat)
Line 1467  udp_statinc(u_int stat)
         UDP_STATINC(stat);          UDP_STATINC(stat);
 }  }
   
 #if (defined INET && defined IPSEC_NAT_T)  #if defined(INET) && defined(IPSEC)
 /*  /*
  * Returns:   * Returns:
  * 1 if the packet was processed   * 1 if the packet was processed
Line 1455  udp4_espinudp(struct mbuf **mp, int off,
Line 1485  udp4_espinudp(struct mbuf **mp, int off,
         size_t minlen;          size_t minlen;
         size_t iphdrlen;          size_t iphdrlen;
         struct ip *ip;          struct ip *ip;
         struct mbuf *n;  
         struct m_tag *tag;          struct m_tag *tag;
         struct udphdr *udphdr;          struct udphdr *udphdr;
         u_int16_t sport, dport;          u_int16_t sport, dport;
Line 1483  udp4_espinudp(struct mbuf **mp, int off,
Line 1512  udp4_espinudp(struct mbuf **mp, int off,
   
         /* Ignore keepalive packets */          /* Ignore keepalive packets */
         if ((len == 1) && (*(unsigned char *)data == 0xff)) {          if ((len == 1) && (*(unsigned char *)data == 0xff)) {
                   m_free(m);
                   *mp = NULL; /* avoid any further processiong by caller ... */
                 return 1;                  return 1;
         }          }
   
Line 1542  udp4_espinudp(struct mbuf **mp, int off,
Line 1573  udp4_espinudp(struct mbuf **mp, int off,
         ip->ip_p = IPPROTO_ESP;          ip->ip_p = IPPROTO_ESP;
   
         /*          /*
          * Copy the mbuf to avoid multiple free, as both           * We have modified the packet - it is now ESP, so we should not
          * esp4_input (which we call) and udp_input (which           * return to UDP processing ...
          * called us) free the mbuf.           *
          */  
         if ((n = m_dup(m, 0, M_COPYALL, M_DONTWAIT)) == NULL) {  
                 printf("udp4_espinudp: m_dup failed\n");  
                 return 0;  
         }  
   
         /*  
          * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember           * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember
          * the source UDP port. This is required if we want           * the source UDP port. This is required if we want
          * to select the right SPD for multiple hosts behind           * to select the right SPD for multiple hosts behind
Line 1560  udp4_espinudp(struct mbuf **mp, int off,
Line 1584  udp4_espinudp(struct mbuf **mp, int off,
         if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS,          if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS,
             sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) {              sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) {
                 printf("udp4_espinudp: m_tag_get failed\n");                  printf("udp4_espinudp: m_tag_get failed\n");
                 m_freem(n);                  m_freem(m);
                 return 0;                  return -1;
         }          }
         ((u_int16_t *)(tag + 1))[0] = sport;          ((u_int16_t *)(tag + 1))[0] = sport;
         ((u_int16_t *)(tag + 1))[1] = dport;          ((u_int16_t *)(tag + 1))[1] = dport;
         m_tag_prepend(n, tag);          m_tag_prepend(m, tag);
   
 #ifdef FAST_IPSEC  #ifdef IPSEC
         ipsec4_common_input(n, iphdrlen, IPPROTO_ESP);          ipsec4_common_input(m, iphdrlen, IPPROTO_ESP);
 #else  #else
         esp4_input(n, iphdrlen);          esp4_input(m, iphdrlen);
 #endif  #endif
   
         /* We handled it, it shouldn't be handled by UDP */          /* We handled it, it shouldn't be handled by UDP */
           *mp = NULL; /* avoid free by caller ... */
         return 1;          return 1;
 }  }
 #endif  #endif
   
   PR_WRAP_USRREQS(udp)
   #define udp_attach      udp_attach_wrapper
   #define udp_detach      udp_detach_wrapper
   #define udp_usrreq      udp_usrreq_wrapper
   
   const struct pr_usrreqs udp_usrreqs = {
           .pr_attach      = udp_attach,
           .pr_detach      = udp_detach,
           .pr_generic     = udp_usrreq,
   };

Legend:
Removed from v.1.183.2.2  
changed lines
  Added in v.1.197

CVSweb <webmaster@jp.NetBSD.org>