Source-Changes-HG archive

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

[src/trunk]: src/sys Change the behavor of AF_LOCAL connect() to sleep until ...



details:   https://anonhg.NetBSD.org/src/rev/cc2d9e21d588
branches:  trunk
changeset: 551292:cc2d9e21d588
user:      matt <matt%NetBSD.org@localhost>
date:      Wed Sep 03 21:30:12 2003 +0000

description:
Change the behavor of AF_LOCAL connect() to sleep until the server has
accepted the connection.  This can prevent a client from overwhelming a
server.

diffstat:

 sys/kern/uipc_usrreq.c         |  24 ++++++++++++++++++------
 sys/miscfs/fifofs/fifo_vnops.c |   7 ++++---
 sys/sys/un.h                   |   4 ++--
 3 files changed, 24 insertions(+), 11 deletions(-)

diffs (128 lines):

diff -r a448a0476c67 -r cc2d9e21d588 sys/kern/uipc_usrreq.c
--- a/sys/kern/uipc_usrreq.c    Wed Sep 03 20:53:16 2003 +0000
+++ b/sys/kern/uipc_usrreq.c    Wed Sep 03 21:30:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uipc_usrreq.c,v 1.67 2003/08/07 16:32:00 agc Exp $     */
+/*     $NetBSD: uipc_usrreq.c,v 1.68 2003/09/03 21:30:12 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.67 2003/08/07 16:32:00 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_usrreq.c,v 1.68 2003/09/03 21:30:12 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:
@@ -707,7 +715,7 @@
                unp3->unp_flags = unp2->unp_flags;
                so2 = so3;
        }
-       error = unp_connect2(so, so2);
+       error = unp_connect2(so, so, PRU_CONNECT);
  bad:
        vput(vp);
  bad2:
@@ -716,9 +724,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;
@@ -737,7 +746,10 @@
 
        case SOCK_STREAM:
                unp2->unp_conn = unp;
-               soisconnected(so);
+               if (req == PRU_CONNECT)
+                       soisconnecting(so);
+               else
+                       soisconnected(so);
                soisconnected(so2);
                break;
 
diff -r a448a0476c67 -r cc2d9e21d588 sys/miscfs/fifofs/fifo_vnops.c
--- a/sys/miscfs/fifofs/fifo_vnops.c    Wed Sep 03 20:53:16 2003 +0000
+++ b/sys/miscfs/fifofs/fifo_vnops.c    Wed Sep 03 21:30:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: fifo_vnops.c,v 1.42 2003/08/07 16:32:34 agc Exp $      */
+/*     $NetBSD: fifo_vnops.c,v 1.43 2003/09/03 21:30:14 matt Exp $     */
 
 /*
  * Copyright (c) 1990, 1993, 1995
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.42 2003/08/07 16:32:34 agc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fifo_vnops.c,v 1.43 2003/09/03 21:30:14 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 a448a0476c67 -r cc2d9e21d588 sys/sys/un.h
--- a/sys/sys/un.h      Wed Sep 03 20:53:16 2003 +0000
+++ b/sys/sys/un.h      Wed Sep 03 21:30:12 2003 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: un.h,v 1.30 2003/08/07 16:34:21 agc Exp $      */
+/*     $NetBSD: un.h,v 1.31 2003/09/03 21:30:13 matt Exp $     */
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -65,7 +65,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 *));



Home | Main Index | Thread Index | Old Index