Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Restore a change that made AF_LOCAL sockets block on con...



details:   https://anonhg.NetBSD.org/src/rev/33811bb65c45
branches:  trunk
changeset: 555810:33811bb65c45
user:      matt <matt%NetBSD.org@localhost>
date:      Sat Nov 29 10:02:42 2003 +0000

description:
Restore a change that made AF_LOCAL sockets block on connect(2) until
accepted.  However, this time this behavor is not the default.  Instead
it must enabled by using the LOCAL_CONNWAIT socket option on either the
connecting or accepting socket.

diffstat:

 sys/kern/uipc_syscalls.c         |   6 +++---
 sys/kern/uipc_usrreq.c           |  29 +++++++++++++++++++++++------
 sys/miscfs/fifofs/fifo_vnops.c   |   7 ++++---
 sys/miscfs/portal/portal_vnops.c |   7 ++++---
 sys/sys/un.h                     |   5 +++--
 sys/sys/unpcb.h                  |   3 ++-
 6 files changed, 39 insertions(+), 18 deletions(-)

diffs (234 lines):

diff -r d91c4f5f124c -r 33811bb65c45 sys/kern/uipc_syscalls.c
--- a/sys/kern/uipc_syscalls.c  Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/kern/uipc_syscalls.c  Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_syscalls.c,v 1.85 2003/11/29 06:09:47 perry Exp $ */
+/*     $NetBSD: uipc_syscalls.c,v 1.86 2003/11/29 10:02:42 matt Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1990, 1993
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.85 2003/11/29 06:09:47 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls.c,v 1.86 2003/11/29 10:02:42 matt Exp $");
 
 #include "opt_ktrace.h"
 #include "opt_pipe.h"
@@ -924,7 +924,7 @@
        wf->f_ops = &socketops;
        wf->f_data = (caddr_t)wso;
        retval[1] = fd;
-       if ((error = unp_connect2(wso, rso)) != 0)
+       if ((error = unp_connect2(wso, rso, PRU_CONNECT2)) != 0)
                goto free4;
        FILE_SET_MATURE(rf);
        FILE_SET_MATURE(wf);
diff -r d91c4f5f124c -r 33811bb65c45 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/kern/uipc_usrreq.c    Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.71 2003/11/29 06:08:29 perry Exp $   */
+/*     $NetBSD: uipc_usrreq.c,v 1.72 2003/11/29 10:02:42 matt Exp $    */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -103,7 +103,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.71 2003/11/29 06:08:29 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.72 2003/11/29 10:02:42 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -247,7 +247,7 @@
                break;
 
        case PRU_CONNECT2:
-               error = unp_connect2(so, (struct socket *)nam);
+               error = unp_connect2(so, (struct socket *)nam, PRU_CONNECT2);
                break;
 
        case PRU_DISCONNECT:
@@ -256,6 +256,14 @@
 
        case PRU_ACCEPT:
                unp_setpeeraddr(unp, nam);
+               /*
+                * Mark the initiating STREAM socket as connected *ONLY*
+                * after it's been accepted.  This prevents a client from
+                * overrunning a server and receiving ECONNREFUSED.
+                */
+               if (unp->unp_conn != NULL &&
+                   (unp->unp_conn->unp_socket->so_state & SS_ISCONNECTING))
+                       soisconnected(unp->unp_conn->unp_socket);
                break;
 
        case PRU_SHUTDOWN:
@@ -443,6 +451,7 @@
        case PRCO_SETOPT:
                switch (optname) {
                case LOCAL_CREDS:
+               case LOCAL_CONNWAIT:
                        if (m == NULL || m->m_len != sizeof(int))
                                error = EINVAL;
                        else {
@@ -457,6 +466,9 @@
                                case LOCAL_CREDS:
                                        OPTSET(UNP_WANTCRED);
                                        break;
+                               case LOCAL_CONNWAIT:
+                                       OPTSET(UNP_CONNWAIT);
+                                       break;
                                }
                        }
                        break;
@@ -717,7 +729,7 @@
                unp3->unp_flags = unp2->unp_flags;
                so2 = so3;
        }
-       error = unp_connect2(so, so2);
+       error = unp_connect2(so, so2, PRU_CONNECT);
  bad:
        vput(vp);
  bad2:
@@ -726,9 +738,10 @@
 }
 
 int
-unp_connect2(so, so2)
+unp_connect2(so, so2, req)
        struct socket *so;
        struct socket *so2;
+       int req;
 {
        struct unpcb *unp = sotounpcb(so);
        struct unpcb *unp2;
@@ -747,7 +760,11 @@
 
        case SOCK_STREAM:
                unp2->unp_conn = unp;
-               soisconnected(so);
+               if (req == PRU_CONNECT &&
+                   ((unp->unp_flags | unp2->unp_flags) & UNP_CONNWAIT))
+                       soisconnecting(so);
+               else
+                       soisconnected(so);
                soisconnected(so2);
                break;
 
diff -r d91c4f5f124c -r 33811bb65c45 sys/miscfs/fifofs/fifo_vnops.c
--- a/sys/miscfs/fifofs/fifo_vnops.c    Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/miscfs/fifofs/fifo_vnops.c    Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fifo_vnops.c,v 1.44 2003/11/29 06:15:00 perry Exp $    */
+/*     $NetBSD: fifo_vnops.c,v 1.45 2003/11/29 10:02:42 matt Exp $     */
 
 /*
  * Copyright (c) 1990, 1993, 1995
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.44 2003/11/29 06:15:00 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.45 2003/11/29 10:02:42 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -41,6 +41,7 @@
 #include <sys/namei.h>
 #include <sys/vnode.h>
 #include <sys/socket.h>
+#include <sys/protosw.h>
 #include <sys/socketvar.h>
 #include <sys/stat.h>
 #include <sys/ioctl.h>
@@ -174,7 +175,7 @@
                        return (error);
                }
                fip->fi_writesock = wso;
-               if ((error = unp_connect2(wso, rso)) != 0) {
+               if ((error = unp_connect2(wso, rso, PRU_CONNECT2)) != 0) {
                        (void)soclose(wso);
                        (void)soclose(rso);
                        free(fip, M_VNODE);
diff -r d91c4f5f124c -r 33811bb65c45 sys/miscfs/portal/portal_vnops.c
--- a/sys/miscfs/portal/portal_vnops.c  Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/miscfs/portal/portal_vnops.c  Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: portal_vnops.c,v 1.51 2003/11/29 06:15:00 perry Exp $  */
+/*     $NetBSD: portal_vnops.c,v 1.52 2003/11/29 10:02:43 matt Exp $   */
 
 /*
  * Copyright (c) 1992, 1993
@@ -40,7 +40,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: portal_vnops.c,v 1.51 2003/11/29 06:15:00 perry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: portal_vnops.c,v 1.52 2003/11/29 10:02:43 matt Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -56,6 +56,7 @@
 #include <sys/namei.h>
 #include <sys/mbuf.h>
 #include <sys/socket.h>
+#include <sys/protosw.h>
 #include <sys/socketvar.h>
 #include <sys/un.h>
 #include <sys/unpcb.h>
@@ -292,7 +293,7 @@
        so2 = so3;
 
 
-       return (unp_connect2(so, so2));
+       return (unp_connect2(so, so2, PRU_CONNECT2));
 }
 
 int
diff -r d91c4f5f124c -r 33811bb65c45 sys/sys/un.h
--- a/sys/sys/un.h      Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/sys/un.h      Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: un.h,v 1.32 2003/11/29 06:14:03 perry Exp $    */
+/*     $NetBSD: un.h,v 1.33 2003/11/29 10:02:42 matt Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -56,6 +56,7 @@
  */
 #if defined(_NETBSD_SOURCE)
 #define        LOCAL_CREDS     0x0001          /* pass credentials to receiver */
+#define        LOCAL_CONNWAIT  0x0002          /* connects block until accepted */
 #endif
 
 #ifdef _KERNEL
@@ -65,7 +66,7 @@
 int    unp_attach __P((struct socket *));
 int    unp_bind __P((struct unpcb *, struct mbuf *, struct proc *));
 int    unp_connect __P((struct socket *, struct mbuf *, struct proc *));
-int    unp_connect2 __P((struct socket *, struct socket *));
+int    unp_connect2 __P((struct socket *, struct socket *, int));
 void   unp_detach __P((struct unpcb *));
 void   unp_discard __P((struct file *));
 void   unp_disconnect __P((struct unpcb *));
diff -r d91c4f5f124c -r 33811bb65c45 sys/sys/unpcb.h
--- a/sys/sys/unpcb.h   Sat Nov 29 06:08:29 2003 +0000
+++ b/sys/sys/unpcb.h   Sat Nov 29 10:02:42 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: unpcb.h,v 1.12 2003/08/07 16:34:22 agc Exp $   */
+/*     $NetBSD: unpcb.h,v 1.13 2003/11/29 10:02:42 matt Exp $  */
 
 /*
  * Copyright (c) 1982, 1986, 1989, 1993
@@ -82,6 +82,7 @@
 
 /* unp_flags */
 #define        UNP_WANTCRED    0x0001          /* credentials wanted */
+#define        UNP_CONNWAIT    0x0002          /* connect blocks until accepted */
 
 #define        sotounpcb(so)   ((struct unpcb *)((so)->so_pcb))
 



Home | Main Index | Thread Index | Old Index