From owner-freebsd-net@FreeBSD.ORG Sat Jun 21 18:00:09 2014 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 81A7CC4; Sat, 21 Jun 2014 18:00:09 +0000 (UTC) Received: from mail-qc0-x22a.google.com (mail-qc0-x22a.google.com [IPv6:2607:f8b0:400d:c01::22a]) (using TLSv1 with cipher ECDHE-RSA-RC4-SHA (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 353B1261F; Sat, 21 Jun 2014 18:00:09 +0000 (UTC) Received: by mail-qc0-f170.google.com with SMTP id l6so4731865qcy.15 for ; Sat, 21 Jun 2014 11:00:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=zu9A8i5tu32gkI7sIvcWNrVpu8Ifg1jsELH4LA1nPks=; b=AdLxpJ0DlltSy1Q1FqAn8hJtJpST4Dnm9EixkN2MxB83K56usNCz2+enF2towsYtdu fYD3R7kuVa1dnZICqlJVvFdNYOTXqaMJ6p929OP6GHaLQ67gFePMudpdu8pm0A/EKZyK MszGTFvocCiem40y9qtpp79ZQR6jMpfMta7lZzBKZVoN5uXJQGl9QOJSO6Po8sloGcrC Q+GH8HfBSpKYgqqhuktO9xAZt/af4HvRAvwgdbkJbnA7VUKotw5omlY+NMyLyQpNsaXE BNXWh9yLiAXzA7GlaKQBCFgReIwbswewokSPe/DKIFGZqIQugdgzj7Saq/yFhomRxLBy HSTA== MIME-Version: 1.0 X-Received: by 10.140.98.234 with SMTP id o97mr16465655qge.35.1403373608340; Sat, 21 Jun 2014 11:00:08 -0700 (PDT) Received: by 10.96.73.39 with HTTP; Sat, 21 Jun 2014 11:00:08 -0700 (PDT) In-Reply-To: <1403366415.39384.11.camel@bruno> References: <1403366415.39384.11.camel@bruno> Date: Sat, 21 Jun 2014 11:00:08 -0700 Message-ID: Subject: Re: getpeername returning ENOTCONN for a connected socket From: hiren panchasara To: Sean Bruno Content-Type: text/plain; charset=UTF-8 Cc: "freebsd-net@freebsd.org" X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 Jun 2014 18:00:09 -0000 On Sat, Jun 21, 2014 at 9:00 AM, Sean Bruno wrote: > On Fri, 2014-06-20 at 16:21 -0700, hiren panchasara wrote: >> Reviving an old thread where Steve found this problem: A call to >> getpeername on a connected tcp socket returns ENOTCONN with no prior >> errors being reported by previous socket calls. >> >> Please look at http://lists.freebsd.org/pipermail/freebsd-net/2011-January/027647.html >> for more details. >> >> Here is a proposed patch derived from >> $src/sys/netsmb/smb_trantcp.c:nbssn_recv()'s way of handling a similar >> situation: >> >> Index: sys/kern/uipc_syscalls.c >> =================================================================== >> --- sys/kern/uipc_syscalls.c (revision 267693) >> +++ sys/kern/uipc_syscalls.c (working copy) >> @@ -1755,6 +1755,12 @@ >> if (error != 0) >> return (error); >> so = fp->f_data; >> + if ((so->so_state & (SS_ISDISCONNECTED|SS_ISDISCONNECTING)) || >> + (so->so_rcv.sb_state & SBS_CANTRCVMORE)) { >> + error = ECONNRESET; >> + goto done; >> + } >> if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) { >> error = ENOTCONN; >> goto done; >> >> Does this look correct? >> >> cheers, >> Hiren > > Has this been tested in "anger" anywhere? No. This patch is from code observation after looking at the problem. I should at least writeup a small module to do local testing as Steve did in original report. I'll do that and get back. I'd appreciate if someone can point me to a better way of testing this. (specially in "anger" ;-)) cheers, Hiren