From owner-freebsd-net Wed Feb 7 17:39:51 2001 Delivered-To: freebsd-net@freebsd.org Received: from prism.flugsvamp.com (cb58709-a.mdsn1.wi.home.com [24.17.241.9]) by hub.freebsd.org (Postfix) with ESMTP id 4F5F937B401 for ; Wed, 7 Feb 2001 17:39:31 -0800 (PST) Received: (from jlemon@localhost) by prism.flugsvamp.com (8.11.0/8.11.0) id f181eeP88216 for net@freebsd.org; Wed, 7 Feb 2001 19:40:40 -0600 (CST) (envelope-from jlemon) Date: Wed, 7 Feb 2001 19:40:40 -0600 From: Jonathan Lemon To: net@freebsd.org Subject: Re: [itojun@iijlab.net: accept(2) behavior with tcp RST right after handshake] Message-ID: <20010207194040.O650@prism.flugsvamp.com> References: <9384.981594820@coconut.itojun.org> <9619.981596009@coconut.itojun.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0pre2i In-Reply-To: <9619.981596009@coconut.itojun.org> Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org Current updated patch for comments is below. Jayanth did make one point that an application could assume that the error return from accept was in regards to the listening socket instead of the new socket, so that may be a concern. -- Jonathan Index: uipc_socket.c =================================================================== RCS file: /ncvs/src/sys/kern/uipc_socket.c,v retrieving revision 1.68.2.11 diff -u -r1.68.2.11 uipc_socket.c --- uipc_socket.c 2000/12/22 10:25:21 1.68.2.11 +++ uipc_socket.c 2001/02/07 20:30:29 @@ -365,11 +365,8 @@ so->so_state &= ~SS_NOFDREF; if ((so->so_state & SS_ISDISCONNECTED) == 0) error = (*so->so_proto->pr_usrreqs->pru_accept)(so, nam); - else { - if (nam) - *nam = 0; - error = 0; - } + else + error = ECONNABORTED; splx(s); return (error); } Index: uipc_syscalls.c =================================================================== RCS file: /ncvs/src/sys/kern/uipc_syscalls.c,v retrieving revision 1.65.2.6 diff -u -r1.65.2.6 uipc_syscalls.c --- uipc_syscalls.c 2000/12/02 00:47:50 1.65.2.6 +++ uipc_syscalls.c 2001/02/07 21:27:03 @@ -283,7 +283,19 @@ nfp->f_ops = &socketops; nfp->f_type = DTYPE_SOCKET; sa = 0; - (void) soaccept(so, &sa); + error = soaccept(so, &sa); + if (error) { + /* + * return a namelen of zero for older code which might + * ignore the return value from accept. + */ + if (uap->name != NULL) { + namelen = 0; + (void) copyout((caddr_t)&namelen, + (caddr_t)uap->anamelen, sizeof(*uap->anamelen)); + } + goto noconnection; + } if (sa == NULL) { namelen = 0; if (uap->name) @@ -307,6 +319,7 @@ error = copyout((caddr_t)&namelen, (caddr_t)uap->anamelen, sizeof (*uap->anamelen)); } +noconnection: if (sa) FREE(sa, M_SONAME); To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message