[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.74 and 1.111.2.4

version 1.74, 2002/11/27 03:36:04 version 1.111.2.4, 2006/07/07 12:30:51
Line 48 
Line 48 
  * 2. Redistributions in binary form must reproduce the above copyright   * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the   *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.   *    documentation and/or other materials provided with the distribution.
  * 3. All advertising materials mentioning features or use of this software   * 3. Neither the name of the University nor the names of its contributors
  *    must display the following acknowledgement:  
  *      This product includes software developed by the University of  
  *      California, Berkeley and its contributors.  
  * 4. Neither the name of the University nor the names of its contributors  
  *    may be used to endorse or promote products derived from this software   *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.   *    without specific prior written permission.
  *   *
Line 76  __KERNEL_RCSID(0, "$NetBSD$");
Line 72  __KERNEL_RCSID(0, "$NetBSD$");
   
 #include "opt_sock_counters.h"  #include "opt_sock_counters.h"
 #include "opt_sosend_loan.h"  #include "opt_sosend_loan.h"
   #include "opt_mbuftrace.h"
   #include "opt_somaxkva.h"
   
 #include <sys/param.h>  #include <sys/param.h>
 #include <sys/systm.h>  #include <sys/systm.h>
Line 92  __KERNEL_RCSID(0, "$NetBSD$");
Line 90  __KERNEL_RCSID(0, "$NetBSD$");
 #include <sys/resourcevar.h>  #include <sys/resourcevar.h>
 #include <sys/pool.h>  #include <sys/pool.h>
 #include <sys/event.h>  #include <sys/event.h>
   #include <sys/poll.h>
   #include <sys/kauth.h>
   
 #include <uvm/uvm.h>  #include <uvm/uvm.h>
   
 struct pool     socket_pool;  POOL_INIT(socket_pool, sizeof(struct socket), 0, 0, 0, "sockpl", NULL);
   
   MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options");
   MALLOC_DEFINE(M_SONAME, "soname", "socket name");
   
 extern int      somaxconn;                      /* patchable (XXX sysctl) */  extern int      somaxconn;                      /* patchable (XXX sysctl) */
 int             somaxconn = SOMAXCONN;  int             somaxconn = SOMAXCONN;
Line 103  int  somaxconn = SOMAXCONN;
Line 106  int  somaxconn = SOMAXCONN;
 #ifdef SOSEND_COUNTERS  #ifdef SOSEND_COUNTERS
 #include <sys/device.h>  #include <sys/device.h>
   
 struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,  static struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "sosend", "loan big");      NULL, "sosend", "loan big");
 struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,  static struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "sosend", "copy big");      NULL, "sosend", "copy big");
 struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,  static struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "sosend", "copy small");      NULL, "sosend", "copy small");
 struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,  static struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
     NULL, "sosend", "kva limit");      NULL, "sosend", "kva limit");
   
 #define SOSEND_COUNTER_INCR(ev)         (ev)->ev_count++  #define SOSEND_COUNTER_INCR(ev)         (ev)->ev_count++
   
   EVCNT_ATTACH_STATIC(sosend_loan_big);
   EVCNT_ATTACH_STATIC(sosend_copy_big);
   EVCNT_ATTACH_STATIC(sosend_copy_small);
   EVCNT_ATTACH_STATIC(sosend_kvalimit);
 #else  #else
   
 #define SOSEND_COUNTER_INCR(ev)         /* nothing */  #define SOSEND_COUNTER_INCR(ev)         /* nothing */
   
 #endif /* SOSEND_COUNTERS */  #endif /* SOSEND_COUNTERS */
   
 void  static struct callback_entry sokva_reclaimerentry;
 soinit(void)  
 {  
   
         pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0,  
             "sockpl", NULL);  
   
 #ifdef SOSEND_COUNTERS  
         evcnt_attach_static(&sosend_loan_big);  
         evcnt_attach_static(&sosend_copy_big);  
         evcnt_attach_static(&sosend_copy_small);  
         evcnt_attach_static(&sosend_kvalimit);  
 #endif /* SOSEND_COUNTERS */  
 }  
   
 #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
   
 struct mbuf *so_pendfree;  static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER;
   static struct mbuf *so_pendfree;
   
 int somaxkva = 16 * 1024 * 1024;  #ifndef SOMAXKVA
 int socurkva;  #define SOMAXKVA (16 * 1024 * 1024)
 int sokvawaiters;  #endif
   int somaxkva = SOMAXKVA;
   static int socurkva;
   static int sokvawaiters;
   
 #define SOCK_LOAN_THRESH        4096  
 #define SOCK_LOAN_CHUNK         65536  #define SOCK_LOAN_CHUNK         65536
   
   static size_t sodopendfree(void);
   static size_t sodopendfreel(void);
   
   static vsize_t
   sokvareserve(struct socket *so, vsize_t len)
   {
           int s;
           int error;
   
           s = splvm();
           simple_lock(&so_pendfree_slock);
           while (socurkva + len > somaxkva) {
                   size_t freed;
   
                   /*
                    * try to do pendfree.
                    */
   
                   freed = sodopendfreel();
   
                   /*
                    * if some kva was freed, try again.
                    */
   
                   if (freed)
                           continue;
   
                   SOSEND_COUNTER_INCR(&sosend_kvalimit);
                   sokvawaiters++;
                   error = ltsleep(&socurkva, PVM | PCATCH, "sokva", 0,
                       &so_pendfree_slock);
                   sokvawaiters--;
                   if (error) {
                           len = 0;
                           break;
                   }
           }
           socurkva += len;
           simple_unlock(&so_pendfree_slock);
           splx(s);
           return len;
   }
   
 static void  static void
 sodoloanfree(caddr_t buf, u_int size)  sokvaunreserve(vsize_t len)
 {  {
         struct vm_page **pgs;          int s;
         vaddr_t va, sva, eva;  
           s = splvm();
           simple_lock(&so_pendfree_slock);
           socurkva -= len;
           if (sokvawaiters)
                   wakeup(&socurkva);
           simple_unlock(&so_pendfree_slock);
           splx(s);
   }
   
   /*
    * sokvaalloc: allocate kva for loan.
    */
   
   vaddr_t
   sokvaalloc(vsize_t len, struct socket *so)
   {
           vaddr_t lva;
   
           /*
            * reserve kva.
            */
   
           if (sokvareserve(so, len) == 0)
                   return 0;
   
           /*
            * allocate kva.
            */
   
           lva = uvm_km_alloc(kernel_map, len, 0, UVM_KMF_VAONLY | UVM_KMF_WAITVA);
           if (lva == 0) {
                   sokvaunreserve(len);
                   return (0);
           }
   
           return lva;
   }
   
   /*
    * sokvafree: free kva for loan.
    */
   
   void
   sokvafree(vaddr_t sva, vsize_t len)
   {
   
           /*
            * free kva.
            */
   
           uvm_km_free(kernel_map, sva, len, UVM_KMF_VAONLY);
   
           /*
            * unreserve kva.
            */
   
           sokvaunreserve(len);
   }
   
   static void
   sodoloanfree(struct vm_page **pgs, caddr_t buf, size_t size, boolean_t mapped)
   {
           vaddr_t sva, eva;
         vsize_t len;          vsize_t len;
         paddr_t pa;          int npgs;
         int i, npgs;  
           KASSERT(pgs != NULL);
   
         eva = round_page((vaddr_t) buf + size);          eva = round_page((vaddr_t) buf + size);
         sva = trunc_page((vaddr_t) buf);          sva = trunc_page((vaddr_t) buf);
         len = eva - sva;          len = eva - sva;
         npgs = len >> PAGE_SHIFT;          npgs = len >> PAGE_SHIFT;
   
         pgs = alloca(npgs * sizeof(*pgs));          if (mapped) {
                   pmap_kremove(sva, len);
         for (i = 0, va = sva; va < eva; i++, va += PAGE_SIZE) {                  pmap_update(pmap_kernel());
                 if (pmap_extract(pmap_kernel(), va, &pa) == FALSE)  
                         panic("sodoloanfree: va 0x%lx not mapped", va);  
                 pgs[i] = PHYS_TO_VM_PAGE(pa);  
         }          }
   
         pmap_kremove(sva, len);  
         pmap_update(pmap_kernel());  
         uvm_unloan(pgs, npgs, UVM_LOAN_TOPAGE);          uvm_unloan(pgs, npgs, UVM_LOAN_TOPAGE);
         uvm_km_free(kernel_map, sva, len);          sokvafree(sva, len);
         socurkva -= len;  
         if (sokvawaiters)  
                 wakeup(&socurkva);  
 }  }
   
 static size_t  static size_t
 sodopendfree(struct socket *so)  sodopendfree()
 {  {
         struct mbuf *m;  
         size_t rv = 0;  
         int s;          int s;
           size_t rv;
   
         s = splvm();          s = splvm();
           simple_lock(&so_pendfree_slock);
           rv = sodopendfreel();
           simple_unlock(&so_pendfree_slock);
           splx(s);
   
         for (;;) {          return rv;
                 m = so_pendfree;  }
                 if (m == NULL)  
                         break;  
                 so_pendfree = m->m_next;  
                 splx(s);  
   
                 rv += m->m_ext.ext_size;  /*
                 sodoloanfree(m->m_ext.ext_buf, m->m_ext.ext_size);   * sodopendfreel: free mbufs on "pendfree" list.
                 s = splvm();   * unlock and relock so_pendfree_slock when freeing mbufs.
                 pool_cache_put(&mbpool_cache, m);   *
         }   * => called with so_pendfree_slock held.
    * => called at splvm.
    */
   
   static size_t
   sodopendfreel()
   {
           size_t rv = 0;
   
           LOCK_ASSERT(simple_lock_held(&so_pendfree_slock));
   
         for (;;) {          for (;;) {
                 m = so->so_pendfree;                  struct mbuf *m;
                   struct mbuf *next;
   
                   m = so_pendfree;
                 if (m == NULL)                  if (m == NULL)
                         break;                          break;
                 so->so_pendfree = m->m_next;                  so_pendfree = NULL;
                 splx(s);                  simple_unlock(&so_pendfree_slock);
                   /* XXX splx */
   
                   for (; m != NULL; m = next) {
                           next = m->m_next;
                           KASSERT((~m->m_flags & (M_EXT|M_EXT_PAGES)) == 0);
                           KASSERT(m->m_ext.ext_refcnt == 0);
   
                           rv += m->m_ext.ext_size;
                           sodoloanfree(m->m_ext.ext_pgs, m->m_ext.ext_buf,
                               m->m_ext.ext_size,
                               (m->m_ext.ext_flags & M_EXT_LAZY) == 0);
                           pool_cache_put(&mbpool_cache, m);
                   }
   
                 rv += m->m_ext.ext_size;                  /* XXX splvm */
                 sodoloanfree(m->m_ext.ext_buf, m->m_ext.ext_size);                  simple_lock(&so_pendfree_slock);
                 s = splvm();  
                 pool_cache_put(&mbpool_cache, m);  
         }          }
   
         splx(s);  
         return (rv);          return (rv);
 }  }
   
 static void  void
 soloanfree(struct mbuf *m, caddr_t buf, u_int size, void *arg)  soloanfree(struct mbuf *m, caddr_t buf, size_t size, void *arg)
 {  {
         struct socket *so = arg;  
         int s;          int s;
   
         if (m == NULL) {          KASSERT(m != NULL);
                 sodoloanfree(buf, size);  
                 return;          /*
         }           * postpone freeing mbuf.
            *
            * we can't do it in interrupt context
            * because we need to put kva back to kernel_map.
            */
   
         s = splvm();          s = splvm();
         m->m_next = so->so_pendfree;          simple_lock(&so_pendfree_slock);
         so->so_pendfree = m;          m->m_next = so_pendfree;
         splx(s);          so_pendfree = m;
         if (sokvawaiters)          if (sokvawaiters)
                 wakeup(&socurkva);                  wakeup(&socurkva);
           simple_unlock(&so_pendfree_slock);
           splx(s);
 }  }
   
 static long  static long
Line 245  sosend_loan(struct socket *so, struct ui
Line 366  sosend_loan(struct socket *so, struct ui
         struct iovec *iov = uio->uio_iov;          struct iovec *iov = uio->uio_iov;
         vaddr_t sva, eva;          vaddr_t sva, eva;
         vsize_t len;          vsize_t len;
         struct vm_page **pgs;          vaddr_t lva;
         vaddr_t lva, va;          int npgs, error;
         int npgs, s, i, error;  #if !defined(__HAVE_LAZY_MBUF)
           vaddr_t va;
           int i;
   #endif /* !defined(__HAVE_LAZY_MBUF) */
   
         if (uio->uio_segflg != UIO_USERSPACE)          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 262  sosend_loan(struct socket *so, struct ui
Line 386  sosend_loan(struct socket *so, struct ui
         len = eva - sva;          len = eva - sva;
         npgs = len >> PAGE_SHIFT;          npgs = len >> PAGE_SHIFT;
   
         while (socurkva + len > somaxkva) {          /* XXX KDASSERT */
                 if (sodopendfree(so))          KASSERT(npgs <= M_EXT_MAXPAGES);
                         continue;  
                 SOSEND_COUNTER_INCR(&sosend_kvalimit);  
                 s = splvm();  
                 sokvawaiters++;  
                 (void) tsleep(&socurkva, PVM, "sokva", 0);  
                 sokvawaiters--;  
                 splx(s);  
         }  
   
         lva = uvm_km_valloc_wait(kernel_map, len);          lva = sokvaalloc(len, so);
         if (lva == 0)          if (lva == 0)
                 return (0);                  return 0;
         socurkva += len;  
   
         pgs = alloca(npgs * sizeof(*pgs));  
   
         error = uvm_loan(&uio->uio_procp->p_vmspace->vm_map, sva, len,          error = uvm_loan(&uio->uio_vmspace->vm_map, sva, len,
             pgs, UVM_LOAN_TOPAGE);              m->m_ext.ext_pgs, UVM_LOAN_TOPAGE);
         if (error) {          if (error) {
                 uvm_km_free(kernel_map, lva, len);                  sokvafree(lva, len);
                 socurkva -= len;  
                 return (0);                  return (0);
         }          }
   
   #if !defined(__HAVE_LAZY_MBUF)
         for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE)          for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE)
                 pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pgs[i]), VM_PROT_READ);                  pmap_kenter_pa(va, VM_PAGE_TO_PHYS(m->m_ext.ext_pgs[i]),
                       VM_PROT_READ);
         pmap_update(pmap_kernel());          pmap_update(pmap_kernel());
   #endif /* !defined(__HAVE_LAZY_MBUF) */
   
         lva += (vaddr_t) iov->iov_base & PAGE_MASK;          lva += (vaddr_t) iov->iov_base & PAGE_MASK;
   
         MEXTADD(m, (caddr_t) lva, space, M_MBUF, soloanfree, so);          MEXTADD(m, (caddr_t) lva, space, M_MBUF, soloanfree, so);
           m->m_flags |= M_EXT_PAGES | M_EXT_ROMAP;
   
   #if defined(__HAVE_LAZY_MBUF)
           m->m_flags |= M_EXT_LAZY;
           m->m_ext.ext_flags |= M_EXT_LAZY;
   #endif /* defined(__HAVE_LAZY_MBUF) */
   
         uio->uio_resid -= space;          uio->uio_resid -= space;
         /* uio_offset not updated, not set/used for write(2) */          /* uio_offset not updated, not set/used for write(2) */
Line 308  sosend_loan(struct socket *so, struct ui
Line 429  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 317  sosend_loan(struct socket *so, struct ui
Line 464  sosend_loan(struct socket *so, struct ui
  */   */
 /*ARGSUSED*/  /*ARGSUSED*/
 int  int
 socreate(int dom, struct socket **aso, int type, int proto)  socreate(int dom, struct socket **aso, int type, int proto, struct lwp *l)
 {  {
         struct proc     *p;          const struct protosw    *prp;
         struct protosw  *prp;  
         struct socket   *so;          struct socket   *so;
           uid_t           uid;
         int             error, s;          int             error, s;
   
         p = curproc;            /* XXX */  
         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 342  socreate(int dom, struct socket **aso, i
Line 497  socreate(int dom, struct socket **aso, i
         so->so_proto = prp;          so->so_proto = prp;
         so->so_send = sosend;          so->so_send = sosend;
         so->so_receive = soreceive;          so->so_receive = soreceive;
         if (p != 0)  #ifdef MBUFTRACE
                 so->so_uid = p->p_ucred->cr_uid;          so->so_rcv.sb_mowner = &prp->pr_domain->dom_mowner;
           so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner;
           so->so_mowner = &prp->pr_domain->dom_mowner;
   #endif
           if (l != NULL) {
                   uid = kauth_cred_geteuid(l->l_proc->p_cred);
           } else {
                   uid = 0;
           }
           so->so_uidinfo = uid_find(uid);
         error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0,          error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0,
             (struct mbuf *)(long)proto, (struct mbuf *)0, p);              (struct mbuf *)(long)proto, (struct mbuf *)0, l);
         if (error) {          if (error) {
                 so->so_state |= SS_NOFDREF;                  so->so_state |= SS_NOFDREF;
                 sofree(so);                  sofree(so);
Line 358  socreate(int dom, struct socket **aso, i
Line 522  socreate(int dom, struct socket **aso, i
 }  }
   
 int  int
 sobind(struct socket *so, struct mbuf *nam, struct proc *p)  sobind(struct socket *so, struct mbuf *nam, struct lwp *l)
 {  {
         int     s, error;          int     s, error;
   
         s = splsoftnet();          s = splsoftnet();
         error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0,          error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0,
             nam, (struct mbuf *)0, p);              nam, (struct mbuf *)0, l);
         splx(s);          splx(s);
         return (error);          return (error);
 }  }
Line 376  solisten(struct socket *so, int backlog)
Line 540  solisten(struct socket *so, int backlog)
   
         s = splsoftnet();          s = splsoftnet();
         error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0,          error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0,
             (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);              (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);
         if (error) {          if (error) {
                 splx(s);                  splx(s);
                 return (error);                  return (error);
Line 393  solisten(struct socket *so, int backlog)
Line 557  solisten(struct socket *so, int backlog)
 void  void
 sofree(struct socket *so)  sofree(struct socket *so)
 {  {
         struct mbuf *m;  
   
         if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)          if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0)
                 return;                  return;
Line 406  sofree(struct socket *so)
Line 569  sofree(struct socket *so)
                 if (!soqremque(so, 0))                  if (!soqremque(so, 0))
                         return;                          return;
         }          }
         sbrelease(&so->so_snd);          if (so->so_rcv.sb_hiwat)
                   (void)chgsbsize(so->so_uidinfo, &so->so_rcv.sb_hiwat, 0,
                       RLIM_INFINITY);
           if (so->so_snd.sb_hiwat)
                   (void)chgsbsize(so->so_uidinfo, &so->so_snd.sb_hiwat, 0,
                       RLIM_INFINITY);
           sbrelease(&so->so_snd, so);
         sorflush(so);          sorflush(so);
         while ((m = so->so_pendfree) != NULL) {  
                 so->so_pendfree = m->m_next;  
                 m->m_next = so_pendfree;  
                 so_pendfree = m;  
         }  
         pool_put(&socket_pool, so);          pool_put(&socket_pool, so);
 }  }
   
Line 464  soclose(struct socket *so)
Line 628  soclose(struct socket *so)
         if (so->so_pcb) {          if (so->so_pcb) {
                 int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH,                  int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH,
                     (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0,                      (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0,
                     (struct proc *)0);                      (struct lwp *)0);
                 if (error == 0)                  if (error == 0)
                         error = error2;                          error = error2;
         }          }
Line 485  soabort(struct socket *so)
Line 649  soabort(struct socket *so)
 {  {
   
         return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0,          return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0,
             (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);              (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);
 }  }
   
 int  int
Line 501  soaccept(struct socket *so, struct mbuf 
Line 665  soaccept(struct socket *so, struct mbuf 
         if ((so->so_state & SS_ISDISCONNECTED) == 0 ||          if ((so->so_state & SS_ISDISCONNECTED) == 0 ||
             (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0)              (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0)
                 error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT,                  error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT,
                     (struct mbuf *)0, nam, (struct mbuf *)0, (struct proc *)0);                      (struct mbuf *)0, nam, (struct mbuf *)0, (struct lwp *)0);
         else          else
                 error = ECONNABORTED;                  error = ECONNABORTED;
   
Line 510  soaccept(struct socket *so, struct mbuf 
Line 674  soaccept(struct socket *so, struct mbuf 
 }  }
   
 int  int
 soconnect(struct socket *so, struct mbuf *nam)  soconnect(struct socket *so, struct mbuf *nam, struct lwp *l)
 {  {
         struct proc     *p;  
         int             s, error;          int             s, error;
   
         p = curproc;            /* XXX */  
         if (so->so_options & SO_ACCEPTCONN)          if (so->so_options & SO_ACCEPTCONN)
                 return (EOPNOTSUPP);                  return (EOPNOTSUPP);
         s = splsoftnet();          s = splsoftnet();
Line 531  soconnect(struct socket *so, struct mbuf
Line 693  soconnect(struct socket *so, struct mbuf
                 error = EISCONN;                  error = EISCONN;
         else          else
                 error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,                  error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT,
                     (struct mbuf *)0, nam, (struct mbuf *)0, p);                      (struct mbuf *)0, nam, (struct mbuf *)0, l);
         splx(s);          splx(s);
         return (error);          return (error);
 }  }
Line 544  soconnect2(struct socket *so1, struct so
Line 706  soconnect2(struct socket *so1, struct so
         s = splsoftnet();          s = splsoftnet();
         error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2,          error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2,
             (struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0,              (struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0,
             (struct proc *)0);              (struct lwp *)0);
         splx(s);          splx(s);
         return (error);          return (error);
 }  }
Line 565  sodisconnect(struct socket *so)
Line 727  sodisconnect(struct socket *so)
         }          }
         error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT,          error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT,
             (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0,              (struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0,
             (struct proc *)0);              (struct lwp *)0);
  bad:   bad:
         splx(s);          splx(s);
         sodopendfree(so);          sodopendfree();
         return (error);          return (error);
 }  }
   
Line 592  sodisconnect(struct socket *so)
Line 754  sodisconnect(struct socket *so)
  */   */
 int  int
 sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top,  sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top,
         struct mbuf *control, int flags)          struct mbuf *control, int flags, struct lwp *l)
 {  {
         struct proc     *p;  
         struct mbuf     **mp, *m;          struct mbuf     **mp, *m;
           struct proc     *p;
         long            space, len, resid, clen, mlen;          long            space, len, resid, clen, mlen;
         int             error, s, dontroute, atomic;          int             error, s, dontroute, atomic;
   
         sodopendfree(so);          p = l->l_proc;
           sodopendfree();
   
         p = curproc;            /* XXX */  
         clen = 0;          clen = 0;
         atomic = sosendallatonce(so) || top;          atomic = sosendallatonce(so) || top;
         if (uio)          if (uio)
Line 622  sosend(struct socket *so, struct mbuf *a
Line 784  sosend(struct socket *so, struct mbuf *a
         dontroute =          dontroute =
             (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&              (flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 &&
             (so->so_proto->pr_flags & PR_ATOMIC);              (so->so_proto->pr_flags & PR_ATOMIC);
         p->p_stats->p_ru.ru_msgsnd++;          if (p)
                   p->p_stats->p_ru.ru_msgsnd++;
         if (control)          if (control)
                 clen = control->m_len;                  clen = control->m_len;
 #define snderr(errno)   { error = errno; splx(s); goto release; }  #define snderr(errno)   { error = errno; splx(s); goto release; }
Line 654  sosend(struct socket *so, struct mbuf *a
Line 817  sosend(struct socket *so, struct mbuf *a
                 if ((atomic && resid > so->so_snd.sb_hiwat) ||                  if ((atomic && resid > so->so_snd.sb_hiwat) ||
                     clen > so->so_snd.sb_hiwat)                      clen > so->so_snd.sb_hiwat)
                         snderr(EMSGSIZE);                          snderr(EMSGSIZE);
                 if (space < resid + clen && uio &&                  if (space < resid + clen &&
                     (atomic || space < so->so_snd.sb_lowat || space < clen)) {                      (atomic || space < so->so_snd.sb_lowat || space < clen)) {
                         if (so->so_state & SS_NBIO)                          if (so->so_state & SS_NBIO)
                                 snderr(EWOULDBLOCK);                                  snderr(EWOULDBLOCK);
Line 678  sosend(struct socket *so, struct mbuf *a
Line 841  sosend(struct socket *so, struct mbuf *a
                                         top->m_flags |= M_EOR;                                          top->m_flags |= M_EOR;
                         } else do {                          } else do {
                                 if (top == 0) {                                  if (top == 0) {
                                         MGETHDR(m, M_WAIT, MT_DATA);                                          m = m_gethdr(M_WAIT, MT_DATA);
                                         mlen = MHLEN;                                          mlen = MHLEN;
                                         m->m_pkthdr.len = 0;                                          m->m_pkthdr.len = 0;
                                         m->m_pkthdr.rcvif = (struct ifnet *)0;                                          m->m_pkthdr.rcvif = (struct ifnet *)0;
                                 } else {                                  } else {
                                         MGET(m, M_WAIT, MT_DATA);                                          m = m_get(M_WAIT, MT_DATA);
                                         mlen = MLEN;                                          mlen = MLEN;
                                 }                                  }
                                 if (use_sosend_loan &&                                  MCLAIM(m, so->so_snd.sb_mowner);
                                     uio->uio_iov->iov_len >= SOCK_LOAN_THRESH &&                                  if (sock_loan_thresh >= 0 &&
                                     space >= SOCK_LOAN_THRESH &&                                      uio->uio_iov->iov_len >= 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 697  sosend(struct socket *so, struct mbuf *a
Line 861  sosend(struct socket *so, struct mbuf *a
                                 }                                  }
                                 if (resid >= MINCLSIZE && space >= MCLBYTES) {                                  if (resid >= MINCLSIZE && space >= MCLBYTES) {
                                         SOSEND_COUNTER_INCR(&sosend_copy_big);                                          SOSEND_COUNTER_INCR(&sosend_copy_big);
                                         MCLGET(m, M_WAIT);                                          m_clget(m, M_WAIT);
                                         if ((m->m_flags & M_EXT) == 0)                                          if ((m->m_flags & M_EXT) == 0)
                                                 goto nopages;                                                  goto nopages;
                                         mlen = MCLBYTES;                                          mlen = MCLBYTES;
Line 736  sosend(struct socket *so, struct mbuf *a
Line 900  sosend(struct socket *so, struct mbuf *a
                                         break;                                          break;
                                 }                                  }
                         } while (space > 0 && atomic);                          } while (space > 0 && atomic);
   
                         s = splsoftnet();                          s = splsoftnet();
   
                         if (so->so_state & SS_CANTSENDMORE)                          if (so->so_state & SS_CANTSENDMORE)
Line 748  sosend(struct socket *so, struct mbuf *a
Line 912  sosend(struct socket *so, struct mbuf *a
                                 so->so_state |= SS_MORETOCOME;                                  so->so_state |= SS_MORETOCOME;
                         error = (*so->so_proto->pr_usrreq)(so,                          error = (*so->so_proto->pr_usrreq)(so,
                             (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,                              (flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND,
                             top, addr, control, p);                              top, addr, control, curlwp);        /* XXX */
                         if (dontroute)                          if (dontroute)
                                 so->so_options &= ~SO_DONTROUTE;                                  so->so_options &= ~SO_DONTROUTE;
                         if (resid > 0)                          if (resid > 0)
Line 794  int
Line 958  int
 soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,  soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio,
         struct mbuf **mp0, struct mbuf **controlp, int *flagsp)          struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
 {  {
           struct lwp *l = curlwp;
         struct mbuf     *m, **mp;          struct mbuf     *m, **mp;
         int             flags, len, error, s, offset, moff, type, orig_resid;          int             flags, len, error, s, offset, moff, type, orig_resid;
         struct protosw  *pr;          const struct protosw    *pr;
         struct mbuf     *nextrecord;          struct mbuf     *nextrecord;
         int             mbuf_removed = 0;          int             mbuf_removed = 0;
   
Line 804  soreceive(struct socket *so, struct mbuf
Line 969  soreceive(struct socket *so, struct mbuf
         mp = mp0;          mp = mp0;
         type = 0;          type = 0;
         orig_resid = uio->uio_resid;          orig_resid = uio->uio_resid;
   
         if (paddr)          if (paddr)
                 *paddr = 0;                  *paddr = 0;
         if (controlp)          if (controlp)
Line 814  soreceive(struct socket *so, struct mbuf
Line 980  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);
                 error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,                  error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m,
                     (struct mbuf *)(long)(flags & MSG_PEEK), (struct mbuf *)0,                      (struct mbuf *)(long)(flags & MSG_PEEK),
                     (struct proc *)0);                      (struct mbuf *)0, l);
                 if (error)                  if (error)
                         goto bad;                          goto bad;
                 do {                  do {
Line 837  soreceive(struct socket *so, struct mbuf
Line 1003  soreceive(struct socket *so, struct mbuf
                 *mp = (struct mbuf *)0;                  *mp = (struct mbuf *)0;
         if (so->so_state & SS_ISCONFIRMING && uio->uio_resid)          if (so->so_state & SS_ISCONFIRMING && uio->uio_resid)
                 (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,                  (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
                     (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);                      (struct mbuf *)0, (struct mbuf *)0, l);
   
  restart:   restart:
         if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0)          if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0)
Line 910  soreceive(struct socket *so, struct mbuf
Line 1076  soreceive(struct socket *so, struct mbuf
          * While we process the initial mbufs containing address and control           * While we process the initial mbufs containing address and control
          * info, we save a copy of m->m_nextpkt into nextrecord.           * info, we save a copy of m->m_nextpkt into nextrecord.
          */           */
 #ifdef notyet /* XXXX */          if (l)
         if (uio->uio_procp)                  l->l_proc->p_stats->p_ru.ru_msgrcv++;
                 uio->uio_procp->p_stats->p_ru.ru_msgrcv++;  
 #endif  
         KASSERT(m == so->so_rcv.sb_mb);          KASSERT(m == so->so_rcv.sb_mb);
         SBLASTRECORDCHK(&so->so_rcv, "soreceive 1");          SBLASTRECORDCHK(&so->so_rcv, "soreceive 1");
         SBLASTMBUFCHK(&so->so_rcv, "soreceive 1");          SBLASTMBUFCHK(&so->so_rcv, "soreceive 1");
Line 951  soreceive(struct socket *so, struct mbuf
Line 1115  soreceive(struct socket *so, struct mbuf
                         sbfree(&so->so_rcv, m);                          sbfree(&so->so_rcv, m);
                         mbuf_removed = 1;                          mbuf_removed = 1;
                         if (controlp) {                          if (controlp) {
                                 if (pr->pr_domain->dom_externalize &&                                  struct domain *dom = pr->pr_domain;
                                   if (dom->dom_externalize && l &&
                                     mtod(m, struct cmsghdr *)->cmsg_type ==                                      mtod(m, struct cmsghdr *)->cmsg_type ==
                                     SCM_RIGHTS)                                      SCM_RIGHTS)
                                         error = (*pr->pr_domain->dom_externalize)(m);                                          error = (*dom->dom_externalize)(m, l);
                                 *controlp = m;                                  *controlp = m;
                                 so->so_rcv.sb_mb = m->m_next;                                  so->so_rcv.sb_mb = m->m_next;
                                 m->m_next = 0;                                  m->m_next = 0;
                                 m = so->so_rcv.sb_mb;                                  m = so->so_rcv.sb_mb;
                         } else {                          } else {
                                   /*
                                    * Dispose of any SCM_RIGHTS message that went
                                    * through the read path rather than recv.
                                    */
                                   if (pr->pr_domain->dom_dispose &&
                                       mtod(m, struct cmsghdr *)->cmsg_type == SCM_RIGHTS)
                                           (*pr->pr_domain->dom_dispose)(m);
                                 MFREE(m, so->so_rcv.sb_mb);                                  MFREE(m, so->so_rcv.sb_mb);
                                 m = so->so_rcv.sb_mb;                                  m = so->so_rcv.sb_mb;
                         }                          }
Line 1140  soreceive(struct socket *so, struct mbuf
Line 1312  soreceive(struct socket *so, struct mbuf
                                 (*pr->pr_usrreq)(so, PRU_RCVD,                                  (*pr->pr_usrreq)(so, PRU_RCVD,
                                     (struct mbuf *)0,                                      (struct mbuf *)0,
                                     (struct mbuf *)(long)flags,                                      (struct mbuf *)(long)flags,
                                     (struct mbuf *)0,                                      (struct mbuf *)0, l);
                                     (struct proc *)0);  
                         SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2");                          SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2");
                         SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2");                          SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2");
                         error = sbwait(&so->so_rcv);                          error = sbwait(&so->so_rcv);
Line 1178  soreceive(struct socket *so, struct mbuf
Line 1349  soreceive(struct socket *so, struct mbuf
                 SBLASTMBUFCHK(&so->so_rcv, "soreceive 4");                  SBLASTMBUFCHK(&so->so_rcv, "soreceive 4");
                 if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)                  if (pr->pr_flags & PR_WANTRCVD && so->so_pcb)
                         (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,                          (*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0,
                             (struct mbuf *)(long)flags, (struct mbuf *)0,                              (struct mbuf *)(long)flags, (struct mbuf *)0, l);
                             (struct proc *)0);  
         }          }
         if (orig_resid == uio->uio_resid && orig_resid &&          if (orig_resid == uio->uio_resid && orig_resid &&
             (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {              (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) {
Line 1187  soreceive(struct socket *so, struct mbuf
Line 1357  soreceive(struct socket *so, struct mbuf
                 splx(s);                  splx(s);
                 goto restart;                  goto restart;
         }          }
   
         if (flagsp)          if (flagsp)
                 *flagsp |= flags;                  *flagsp |= flags;
  release:   release:
Line 1199  soreceive(struct socket *so, struct mbuf
Line 1369  soreceive(struct socket *so, struct mbuf
 int  int
 soshutdown(struct socket *so, int how)  soshutdown(struct socket *so, int how)
 {  {
         struct protosw  *pr;          const struct protosw    *pr;
   
         pr = so->so_proto;          pr = so->so_proto;
         if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))          if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR))
Line 1209  soshutdown(struct socket *so, int how)
Line 1379  soshutdown(struct socket *so, int how)
                 sorflush(so);                  sorflush(so);
         if (how == SHUT_WR || how == SHUT_RDWR)          if (how == SHUT_WR || how == SHUT_RDWR)
                 return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0,                  return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0,
                     (struct mbuf *)0, (struct mbuf *)0, (struct proc *)0);                      (struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0);
         return (0);          return (0);
 }  }
   
Line 1217  void
Line 1387  void
 sorflush(struct socket *so)  sorflush(struct socket *so)
 {  {
         struct sockbuf  *sb, asb;          struct sockbuf  *sb, asb;
         struct protosw  *pr;          const struct protosw    *pr;
         int             s;          int             s;
   
         sb = &so->so_rcv;          sb = &so->so_rcv;
Line 1228  sorflush(struct socket *so)
Line 1398  sorflush(struct socket *so)
         socantrcvmore(so);          socantrcvmore(so);
         sbunlock(sb);          sbunlock(sb);
         asb = *sb;          asb = *sb;
         memset((caddr_t)sb, 0, sizeof(*sb));          /*
            * Clear most of the sockbuf structure, but leave some of the
            * fields valid.
            */
           memset(&sb->sb_startzero, 0,
               sizeof(*sb) - offsetof(struct sockbuf, sb_startzero));
         splx(s);          splx(s);
         if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)          if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
                 (*pr->pr_domain->dom_dispose)(asb.sb_mb);                  (*pr->pr_domain->dom_dispose)(asb.sb_mb);
         sbrelease(&asb);          sbrelease(&asb, so);
 }  }
   
 int  int
Line 1256  sosetopt(struct socket *so, int level, i
Line 1431  sosetopt(struct socket *so, int level, i
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
                           if (mtod(m, struct linger *)->l_linger < 0 ||
                               mtod(m, struct linger *)->l_linger > (INT_MAX / hz)) {
                                   error = EDOM;
                                   goto bad;
                           }
                         so->so_linger = mtod(m, struct linger *)->l_linger;                          so->so_linger = mtod(m, struct linger *)->l_linger;
                         /* fall thru... */                          /* fall thru... */
   
Line 1306  sosetopt(struct socket *so, int level, i
Line 1486  sosetopt(struct socket *so, int level, i
                         case SO_RCVBUF:                          case SO_RCVBUF:
                                 if (sbreserve(optname == SO_SNDBUF ?                                  if (sbreserve(optname == SO_SNDBUF ?
                                     &so->so_snd : &so->so_rcv,                                      &so->so_snd : &so->so_rcv,
                                     (u_long) optval) == 0) {                                      (u_long) optval, so) == 0) {
                                         error = ENOBUFS;                                          error = ENOBUFS;
                                         goto bad;                                          goto bad;
                                 }                                  }
Line 1334  sosetopt(struct socket *so, int level, i
Line 1514  sosetopt(struct socket *so, int level, i
                 case SO_RCVTIMEO:                  case SO_RCVTIMEO:
                     {                      {
                         struct timeval *tv;                          struct timeval *tv;
                         short val;                          int val;
   
                         if (m == NULL || m->m_len < sizeof(*tv)) {                          if (m == NULL || m->m_len < sizeof(*tv)) {
                                 error = EINVAL;                                  error = EINVAL;
                                 goto bad;                                  goto bad;
                         }                          }
                         tv = mtod(m, struct timeval *);                          tv = mtod(m, struct timeval *);
                         if (tv->tv_sec * hz + tv->tv_usec / tick > SHRT_MAX) {                          if (tv->tv_sec > (INT_MAX - tv->tv_usec / tick) / hz) {
                                 error = EDOM;                                  error = EDOM;
                                 goto bad;                                  goto bad;
                         }                          }
Line 1451  sogetopt(struct socket *so, int level, i
Line 1631  sogetopt(struct socket *so, int level, i
                         break;                          break;
                     }                      }
   
                   case SO_OVERFLOWED:
                           *mtod(m, int *) = so->so_rcv.sb_overflowed;
                           break;
   
                 default:                  default:
                         (void)m_free(m);                          (void)m_free(m);
                         return (ENOPROTOOPT);                          return (ENOPROTOOPT);
Line 1463  sogetopt(struct socket *so, int level, i
Line 1647  sogetopt(struct socket *so, int level, i
 void  void
 sohasoutofband(struct socket *so)  sohasoutofband(struct socket *so)
 {  {
         struct proc *p;          fownsignal(so->so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so);
   
         if (so->so_pgid < 0)  
                 gsignal(-so->so_pgid, SIGURG);  
         else if (so->so_pgid > 0 && (p = pfind(so->so_pgid)) != 0)  
                 psignal(p, SIGURG);  
         selwakeup(&so->so_rcv.sb_sel);          selwakeup(&so->so_rcv.sb_sel);
 }  }
   
Line 1492  filt_soread(struct knote *kn, long hint)
Line 1671  filt_soread(struct knote *kn, long hint)
         so = (struct socket *)kn->kn_fp->f_data;          so = (struct socket *)kn->kn_fp->f_data;
         kn->kn_data = so->so_rcv.sb_cc;          kn->kn_data = so->so_rcv.sb_cc;
         if (so->so_state & SS_CANTRCVMORE) {          if (so->so_state & SS_CANTRCVMORE) {
                 kn->kn_flags |= EV_EOF;                  kn->kn_flags |= EV_EOF;
                 kn->kn_fflags = so->so_error;                  kn->kn_fflags = so->so_error;
                 return (1);                  return (1);
         }          }
Line 1523  filt_sowrite(struct knote *kn, long hint
Line 1702  filt_sowrite(struct knote *kn, long hint
         so = (struct socket *)kn->kn_fp->f_data;          so = (struct socket *)kn->kn_fp->f_data;
         kn->kn_data = sbspace(&so->so_snd);          kn->kn_data = sbspace(&so->so_snd);
         if (so->so_state & SS_CANTSENDMORE) {          if (so->so_state & SS_CANTSENDMORE) {
                 kn->kn_flags |= EV_EOF;                  kn->kn_flags |= EV_EOF;
                 kn->kn_fflags = so->so_error;                  kn->kn_fflags = so->so_error;
                 return (1);                  return (1);
         }          }
Line 1548  filt_solisten(struct knote *kn, long hin
Line 1727  filt_solisten(struct knote *kn, long hin
         /*          /*
          * Set kn_data to number of incoming connections, not           * Set kn_data to number of incoming connections, not
          * counting partial (incomplete) connections.           * counting partial (incomplete) connections.
          */           */
         kn->kn_data = so->so_qlen;          kn->kn_data = so->so_qlen;
         return (kn->kn_data > 0);          return (kn->kn_data > 0);
 }  }
Line 1587  soo_kqfilter(struct file *fp, struct kno
Line 1766  soo_kqfilter(struct file *fp, struct kno
         return (0);          return (0);
 }  }
   
   #include <sys/sysctl.h>
   
   static int sysctl_kern_somaxkva(SYSCTLFN_PROTO);
   
   /*
    * sysctl helper routine for kern.somaxkva.  ensures that the given
    * value is not too small.
    * (XXX should we maybe make sure it's not too large as well?)
    */
   static int
   sysctl_kern_somaxkva(SYSCTLFN_ARGS)
   {
           int error, new_somaxkva;
           struct sysctlnode node;
           int s;
   
           new_somaxkva = somaxkva;
           node = *rnode;
           node.sysctl_data = &new_somaxkva;
           error = sysctl_lookup(SYSCTLFN_CALL(&node));
           if (error || newp == NULL)
                   return (error);
   
           if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */
                   return (EINVAL);
   
           s = splvm();
           simple_lock(&so_pendfree_slock);
           somaxkva = new_somaxkva;
           wakeup(&socurkva);
           simple_unlock(&so_pendfree_slock);
           splx(s);
   
           return (error);
   }
   
   SYSCTL_SETUP(sysctl_kern_somaxkva_setup, "sysctl kern.somaxkva setup")
   {
   
           sysctl_createv(clog, 0, NULL, NULL,
                          CTLFLAG_PERMANENT,
                          CTLTYPE_NODE, "kern", NULL,
                          NULL, 0, NULL, 0,
                          CTL_KERN, CTL_EOL);
   
           sysctl_createv(clog, 0, NULL, NULL,
                          CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
                          CTLTYPE_INT, "somaxkva",
                          SYSCTL_DESCR("Maximum amount of kernel memory to be "
                                       "used for socket buffers"),
                          sysctl_kern_somaxkva, 0, NULL, 0,
                          CTL_KERN, KERN_SOMAXKVA, CTL_EOL);
   }

Legend:
Removed from v.1.74  
changed lines
  Added in v.1.111.2.4

CVSweb <webmaster@jp.NetBSD.org>