[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.194 and 1.201.2.1

version 1.194, 2009/11/07 07:27:49 version 1.201.2.1, 2011/06/06 09:09:39
Line 98  __KERNEL_RCSID(0, "$NetBSD$");
Line 98  __KERNEL_RCSID(0, "$NetBSD$");
 #include <compat/sys/socket.h>  #include <compat/sys/socket.h>
 #endif  #endif
   
 #include <uvm/uvm.h>  #include <uvm/uvm_extern.h>
   #include <uvm/uvm_loan.h>
   #include <uvm/uvm_page.h>
   
 MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options");  MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options");
 MALLOC_DEFINE(M_SONAME, "soname", "socket name");  MALLOC_DEFINE(M_SONAME, "soname", "socket name");
Line 452  socket_listener_cb(kauth_cred_t cred, ka
Line 454  socket_listener_cb(kauth_cred_t cred, ka
         case KAUTH_REQ_NETWORK_SOCKET_DROP: {          case KAUTH_REQ_NETWORK_SOCKET_DROP: {
                 /* Normal users can only drop their own connections. */                  /* Normal users can only drop their own connections. */
                 struct socket *so = (struct socket *)arg1;                  struct socket *so = (struct socket *)arg1;
                 uid_t sockuid = so->so_uidinfo->ui_uid;  
   
                 if (sockuid == kauth_cred_getuid(cred) ||                  if (proc_uidmatch(cred, so->so_cred))
                     sockuid == kauth_cred_geteuid(cred))  
                         result = KAUTH_RESULT_ALLOW;                          result = KAUTH_RESULT_ALLOW;
   
                 break;                  break;
Line 463  socket_listener_cb(kauth_cred_t cred, ka
Line 463  socket_listener_cb(kauth_cred_t cred, ka
   
         case KAUTH_REQ_NETWORK_SOCKET_OPEN:          case KAUTH_REQ_NETWORK_SOCKET_OPEN:
                 /* We allow "raw" routing/bluetooth sockets to anyone. */                  /* We allow "raw" routing/bluetooth sockets to anyone. */
                 if ((u_long)arg1 == PF_ROUTE || (u_long)arg1 == PF_BLUETOOTH)                  if ((u_long)arg1 == PF_ROUTE || (u_long)arg1 == PF_OROUTE
                       || (u_long)arg1 == PF_BLUETOOTH) {
                         result = KAUTH_RESULT_ALLOW;                          result = KAUTH_RESULT_ALLOW;
                 else {                  } else {
                         /* Privileged, let secmodel handle this. */                          /* Privileged, let secmodel handle this. */
                         if ((u_long)arg2 == SOCK_RAW)                          if ((u_long)arg2 == SOCK_RAW)
                                 break;                                  break;
Line 561  socreate(int dom, struct socket **aso, i
Line 562  socreate(int dom, struct socket **aso, i
         so->so_snd.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;          so->so_mowner = &prp->pr_domain->dom_mowner;
 #endif  #endif
         /* so->so_cred = kauth_cred_dup(l->l_cred); */  
         uid = kauth_cred_geteuid(l->l_cred);          uid = kauth_cred_geteuid(l->l_cred);
         so->so_uidinfo = uid_find(uid);          so->so_uidinfo = uid_find(uid);
         so->so_egid = kauth_cred_getegid(l->l_cred);  
         so->so_cpid = l->l_proc->p_pid;          so->so_cpid = l->l_proc->p_pid;
         if (lockso != NULL) {          if (lockso != NULL) {
                 /* Caller wants us to share a lock. */                  /* Caller wants us to share a lock. */
Line 583  socreate(int dom, struct socket **aso, i
Line 582  socreate(int dom, struct socket **aso, i
                 sofree(so);                  sofree(so);
                 return error;                  return error;
         }          }
           so->so_cred = kauth_cred_dup(l->l_cred);
         sounlock(so);          sounlock(so);
         *aso = so;          *aso = so;
         return 0;          return 0;
Line 704  sofree(struct socket *so)
Line 704  sofree(struct socket *so)
         /* Remove acccept filter if one is present. */          /* Remove acccept filter if one is present. */
         if (so->so_accf != NULL)          if (so->so_accf != NULL)
                 (void)accept_filt_clear(so);                  (void)accept_filt_clear(so);
         /* kauth_cred_free(so->so_cred); */  
         sounlock(so);          sounlock(so);
         if (refs == 0)          /* XXX */          if (refs == 0)          /* XXX */
                 soput(so);                  soput(so);
Line 773  soclose(struct socket *so)
Line 772  soclose(struct socket *so)
  discard:   discard:
         if (so->so_state & SS_NOFDREF)          if (so->so_state & SS_NOFDREF)
                 panic("soclose: NOFDREF");                  panic("soclose: NOFDREF");
           kauth_cred_free(so->so_cred);
         so->so_state |= SS_NOFDREF;          so->so_state |= SS_NOFDREF;
         sofree(so);          sofree(so);
         return (error);          return (error);
Line 905  sosend(struct socket *so, struct mbuf *a
Line 905  sosend(struct socket *so, struct mbuf *a
         struct proc     *p;          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;
           short           wakeup_state = 0;
   
         p = l->l_proc;          p = l->l_proc;
         sodopendfree();          sodopendfree();
Line 979  sosend(struct socket *so, struct mbuf *a
Line 980  sosend(struct socket *so, struct mbuf *a
                                 goto release;                                  goto release;
                         }                          }
                         sbunlock(&so->so_snd);                          sbunlock(&so->so_snd);
                           if (wakeup_state & SS_RESTARTSYS) {
                                   error = ERESTART;
                                   goto out;
                           }
                         error = sbwait(&so->so_snd);                          error = sbwait(&so->so_snd);
                         if (error)                          if (error)
                                 goto out;                                  goto out;
                           wakeup_state = so->so_state;
                         goto restart;                          goto restart;
                 }                  }
                   wakeup_state = 0;
                 mp = &top;                  mp = &top;
                 space -= clen;                  space -= clen;
                 do {                  do {
Line 1018  sosend(struct socket *so, struct mbuf *a
Line 1025  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);
                                         m_clget(m, M_WAIT);                                          m_clget(m, M_DONTWAIT);
                                         if ((m->m_flags & M_EXT) == 0)                                          if ((m->m_flags & M_EXT) == 0)
                                                 goto nopages;                                                  goto nopages;
                                         mlen = MCLBYTES;                                          mlen = MCLBYTES;
Line 1159  soreceive(struct socket *so, struct mbuf
Line 1166  soreceive(struct socket *so, struct mbuf
         struct mbuf     *nextrecord;          struct mbuf     *nextrecord;
         int             mbuf_removed = 0;          int             mbuf_removed = 0;
         const struct domain *dom;          const struct domain *dom;
           short           wakeup_state = 0;
   
         pr = so->so_proto;          pr = so->so_proto;
         atomic = pr->pr_flags & PR_ATOMIC;          atomic = pr->pr_flags & PR_ATOMIC;
Line 1273  soreceive(struct socket *so, struct mbuf
Line 1281  soreceive(struct socket *so, struct mbuf
                 SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 1");                  SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 1");
                 SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 1");                  SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 1");
                 sbunlock(&so->so_rcv);                  sbunlock(&so->so_rcv);
                 error = sbwait(&so->so_rcv);                  if (wakeup_state & SS_RESTARTSYS)
                           error = ERESTART;
                   else
                           error = sbwait(&so->so_rcv);
                 if (error != 0) {                  if (error != 0) {
                         sounlock(so);                          sounlock(so);
                         splx(s);                          splx(s);
                         return error;                          return error;
                 }                  }
                   wakeup_state = so->so_state;
                 goto restart;                  goto restart;
         }          }
  dontblock:   dontblock:
Line 1417  soreceive(struct socket *so, struct mbuf
Line 1429  soreceive(struct socket *so, struct mbuf
                         panic("receive 3");                          panic("receive 3");
 #endif  #endif
                 so->so_state &= ~SS_RCVATMARK;                  so->so_state &= ~SS_RCVATMARK;
                   wakeup_state = 0;
                 len = uio->uio_resid;                  len = uio->uio_resid;
                 if (so->so_oobmark && len > so->so_oobmark - offset)                  if (so->so_oobmark && len > so->so_oobmark - offset)
                         len = so->so_oobmark - offset;                          len = so->so_oobmark - offset;
Line 1549  soreceive(struct socket *so, struct mbuf
Line 1562  soreceive(struct socket *so, struct mbuf
                                     NULL, (struct mbuf *)(long)flags, NULL, l);                                      NULL, (struct mbuf *)(long)flags, NULL, l);
                         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);                          if (wakeup_state & SS_RESTARTSYS)
                                   error = ERESTART;
                           else
                                   error = sbwait(&so->so_rcv);
                         if (error != 0) {                          if (error != 0) {
                                 sbunlock(&so->so_rcv);                                  sbunlock(&so->so_rcv);
                                 sounlock(so);                                  sounlock(so);
Line 1558  soreceive(struct socket *so, struct mbuf
Line 1574  soreceive(struct socket *so, struct mbuf
                         }                          }
                         if ((m = so->so_rcv.sb_mb) != NULL)                          if ((m = so->so_rcv.sb_mb) != NULL)
                                 nextrecord = m->m_nextpkt;                                  nextrecord = m->m_nextpkt;
                           wakeup_state = so->so_state;
                 }                  }
         }          }
   
Line 1624  soshutdown(struct socket *so, int how)
Line 1641  soshutdown(struct socket *so, int how)
         return error;          return error;
 }  }
   
 int  void
 sodrain(struct socket *so)  sorestart(struct socket *so)
 {  {
         int error;          /*
            * An application has called close() on an fd on which another
            * of its threads has called a socket system call.
            * Mark this and wake everyone up, and code that would block again
            * instead returns ERESTART.
            * On system call re-entry the fd is validated and EBADF returned.
            * Any other fd will block again on the 2nd syscall.
            */
         solock(so);          solock(so);
         so->so_state |= SS_ISDRAINING;          so->so_state |= SS_RESTARTSYS;
         cv_broadcast(&so->so_cv);          cv_broadcast(&so->so_cv);
         error = soshutdown(so, SHUT_RDWR);          cv_broadcast(&so->so_snd.sb_cv);
           cv_broadcast(&so->so_rcv.sb_cv);
         sounlock(so);          sounlock(so);
   
         return error;  
 }  }
   
 void  void

Legend:
Removed from v.1.194  
changed lines
  Added in v.1.201.2.1

CVSweb <webmaster@jp.NetBSD.org>