[BACK]Return to uipc_socket.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / kern

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/sys/kern/uipc_socket.c between version 1.115.2.3 and 1.129.2.1

version 1.115.2.3, 2005/12/31 11:34:26 version 1.129.2.1, 2007/05/13 21:23:47
Line 91  __KERNEL_RCSID(0, "$NetBSD$");
Line 91  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/pool.h>  #include <sys/pool.h>
 #include <sys/event.h>  #include <sys/event.h>
 #include <sys/poll.h>  #include <sys/poll.h>
   #include <sys/kauth.h>
   
 #include <uvm/uvm.h>  #include <uvm/uvm.h>
   
Line 126  EVCNT_ATTACH_STATIC(sosend_kvalimit);
Line 127  EVCNT_ATTACH_STATIC(sosend_kvalimit);
   
 #endif /* SOSEND_COUNTERS */  #endif /* SOSEND_COUNTERS */
   
 void  static struct callback_entry sokva_reclaimerentry;
 soinit(void)  
 {  
   
         /* Set the initial adjusted socket buffer size. */  
         if (sb_max_set(sb_max))  
                 panic("bad initial sb_max value: %lu", sb_max);  
   
 }  
   
 #ifdef SOSEND_NO_LOAN  #ifdef SOSEND_NO_LOAN
 int use_sosend_loan = 0;  int sock_loan_thresh = -1;
 #else  #else
 int use_sosend_loan = 1;  int sock_loan_thresh = 4096;
 #endif  #endif
   
 static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER;  static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER;
Line 152  int somaxkva = SOMAXKVA;
Line 145  int somaxkva = SOMAXKVA;
 static int socurkva;  static int socurkva;
 static int sokvawaiters;  static int sokvawaiters;
   
 #define SOCK_LOAN_THRESH        4096  
 #define SOCK_LOAN_CHUNK         65536  #define SOCK_LOAN_CHUNK         65536
   
 static size_t sodopendfree(struct socket *);  static size_t sodopendfree(void);
 static size_t sodopendfreel(struct socket *);  static size_t sodopendfreel(void);
   
 static vsize_t  static vsize_t
 sokvareserve(struct socket *so, vsize_t len)  sokvareserve(struct socket *so, vsize_t len)
Line 173  sokvareserve(struct socket *so, vsize_t 
Line 165  sokvareserve(struct socket *so, vsize_t 
                  * try to do pendfree.                   * try to do pendfree.
                  */                   */
   
                 freed = sodopendfreel(so);                  freed = sodopendfreel();
   
                 /*                  /*
                  * if some kva was freed, try again.                   * if some kva was freed, try again.
Line 292  sodoloanfree(struct vm_page **pgs, caddr
Line 284  sodoloanfree(struct vm_page **pgs, caddr
 }  }
   
 static size_t  static size_t
 sodopendfree(struct socket *so)  sodopendfree()
 {  {
         int s;          int s;
         size_t rv;          size_t rv;
   
         s = splvm();          s = splvm();
         simple_lock(&so_pendfree_slock);          simple_lock(&so_pendfree_slock);
         rv = sodopendfreel(so);          rv = sodopendfreel();
         simple_unlock(&so_pendfree_slock);          simple_unlock(&so_pendfree_slock);
         splx(s);          splx(s);
   
Line 315  sodopendfree(struct socket *so)
Line 307  sodopendfree(struct socket *so)
  */   */
   
 static size_t  static size_t
 sodopendfreel(struct socket *so)  sodopendfreel()
 {  {
         size_t rv = 0;          size_t rv = 0;
   
Line 390  sosend_loan(struct socket *so, struct ui
Line 382  sosend_loan(struct socket *so, struct ui
         vaddr_t lva, va;          vaddr_t lva, va;
         int npgs, i, error;          int npgs, i, error;
   
         if (VMSPACE_IS_KERNEL(uio->uio_vmspace))          if (VMSPACE_IS_KERNEL_P(uio->uio_vmspace))
                 return (0);                  return (0);
   
         if (iov->iov_len < (size_t) space)          if (iov->iov_len < (size_t) space)
Line 439  sosend_loan(struct socket *so, struct ui
Line 431  sosend_loan(struct socket *so, struct ui
         return (space);          return (space);
 }  }
   
   static int
   sokva_reclaim_callback(struct callback_entry *ce, void *obj, void *arg)
   {
   
           KASSERT(ce == &sokva_reclaimerentry);
           KASSERT(obj == NULL);
   
           sodopendfree();
           if (!vm_map_starved_p(kernel_map)) {
                   return CALLBACK_CHAIN_ABORT;
           }
           return CALLBACK_CHAIN_CONTINUE;
   }
   
   void
   soinit(void)
   {
   
           /* Set the initial adjusted socket buffer size. */
           if (sb_max_set(sb_max))
                   panic("bad initial sb_max value: %lu", sb_max);
   
           callback_register(&vm_map_to_kernel(kernel_map)->vmk_reclaim_callback,
               &sokva_reclaimerentry, NULL, sokva_reclaim_callback);
   }
   
 /*  /*
  * Socket operation routines.   * Socket operation routines.
  * These routines are called by the routines in   * These routines are called by the routines in
Line 455  socreate(int dom, struct socket **aso, i
Line 473  socreate(int dom, struct socket **aso, i
         uid_t           uid;          uid_t           uid;
         int             error, s;          int             error, s;
   
           if (kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET,
               KAUTH_REQ_NETWORK_SOCKET_OPEN, (void *)(u_long)dom,
               (void *)(u_long)type, (void *)(u_long)proto) != 0)
                   return (EPERM);
   
         if (proto)          if (proto)
                 prp = pffindproto(dom, proto, type);                  prp = pffindproto(dom, proto, type);
         else          else
                 prp = pffindtype(dom, type);                  prp = pffindtype(dom, type);
         if (prp == 0 || prp->pr_usrreq == 0)          if (prp == 0) {
                   /* no support for domain */
                   if (pffinddomain(dom) == 0)
                           return (EAFNOSUPPORT);
                   /* no support for socket type */
                   if (proto == 0 && type != 0)
                           return (EPROTOTYPE);
                   return (EPROTONOSUPPORT);
           }
           if (prp->pr_usrreq == 0)
                 return (EPROTONOSUPPORT);                  return (EPROTONOSUPPORT);
         if (prp->pr_type != type)          if (prp->pr_type != type)
                 return (EPROTOTYPE);                  return (EPROTOTYPE);
Line 478  socreate(int dom, struct socket **aso, i
Line 510  socreate(int dom, struct socket **aso, i
         so->so_mowner = &prp->pr_domain->dom_mowner;          so->so_mowner = &prp->pr_domain->dom_mowner;
 #endif  #endif
         if (l != NULL) {          if (l != NULL) {
                 uid = l->l_proc->p_ucred->cr_uid;                  uid = kauth_cred_geteuid(l->l_cred);
         } else {          } else {
                 uid = 0;                  uid = 0;
         }          }
Line 622  soclose(struct socket *so)
Line 654  soclose(struct socket *so)
 int  int
 soabort(struct socket *so)  soabort(struct socket *so)
 {  {
           int error;
   
         return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0,          KASSERT(so->so_head == NULL);
           error = (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0,
             (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);              (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);
           if (error) {
                   sofree(so);
           }
           return error;
 }  }
   
 int  int
Line 705  sodisconnect(struct socket *so)
Line 743  sodisconnect(struct socket *so)
             (struct lwp *)0);              (struct lwp *)0);
  bad:   bad:
         splx(s);          splx(s);
         sodopendfree(so);          sodopendfree();
         return (error);          return (error);
 }  }
   
Line 737  sosend(struct socket *so, struct mbuf *a
Line 775  sosend(struct socket *so, struct mbuf *a
         int             error, s, dontroute, atomic;          int             error, s, dontroute, atomic;
   
         p = l->l_proc;          p = l->l_proc;
         sodopendfree(so);          sodopendfree();
   
         clen = 0;          clen = 0;
         atomic = sosendallatonce(so) || top;          atomic = sosendallatonce(so) || top;
Line 825  sosend(struct socket *so, struct mbuf *a
Line 863  sosend(struct socket *so, struct mbuf *a
                                         mlen = MLEN;                                          mlen = MLEN;
                                 }                                  }
                                 MCLAIM(m, so->so_snd.sb_mowner);                                  MCLAIM(m, so->so_snd.sb_mowner);
                                 if (use_sosend_loan &&                                  if (sock_loan_thresh >= 0 &&
                                     uio->uio_iov->iov_len >= SOCK_LOAN_THRESH &&                                      uio->uio_iov->iov_len >= sock_loan_thresh &&
                                     space >= SOCK_LOAN_THRESH &&                                      space >= sock_loan_thresh &&
                                     (len = sosend_loan(so, uio, m,                                      (len = sosend_loan(so, uio, m,
                                                        space)) != 0) {                                                         space)) != 0) {
                                         SOSEND_COUNTER_INCR(&sosend_loan_big);                                          SOSEND_COUNTER_INCR(&sosend_loan_big);
Line 955  soreceive(struct socket *so, struct mbuf
Line 993  soreceive(struct socket *so, struct mbuf
                 flags = 0;                  flags = 0;
   
         if ((flags & MSG_DONTWAIT) == 0)          if ((flags & MSG_DONTWAIT) == 0)
                 sodopendfree(so);                  sodopendfree();
   
         if (flags & MSG_OOB) {          if (flags & MSG_OOB) {
                 m = m_get(M_WAIT, MT_DATA);                  m = m_get(M_WAIT, MT_DATA);

Legend:
Removed from v.1.115.2.3  
changed lines
  Added in v.1.129.2.1

CVSweb <webmaster@jp.NetBSD.org>