From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6W8N-0005GL-FS for qemu-devel@nongnu.org; Wed, 11 Jun 2008 15:37:27 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6W8L-0005Fs-Qc for qemu-devel@nongnu.org; Wed, 11 Jun 2008 15:37:27 -0400 Received: from [199.232.76.173] (port=33806 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6W8L-0005Fk-Hx for qemu-devel@nongnu.org; Wed, 11 Jun 2008 15:37:25 -0400 Received: from miranda.se.axis.com ([193.13.178.8]:38753) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1K6W8L-000274-H7 for qemu-devel@nongnu.org; Wed, 11 Jun 2008 15:37:25 -0400 Received: from axis.com (edgar.se.axis.com [10.93.151.1]) by miranda.se.axis.com (8.13.4/8.13.4/Debian-3sarge3) with ESMTP id m5BJbCCl004678 for ; Wed, 11 Jun 2008 21:37:12 +0200 Date: Wed, 11 Jun 2008 21:37:12 +0200 From: "Edgar E. Iglesias" Subject: Re: [Qemu-devel] [PATCH] Proposed fix broken RST response to a slirp redirect socket Message-ID: <20080611193712.GB20729@edgar.se.axis.com> References: <485009A9.6000900@windriver.com> <20080611180739.GA20729@edgar.se.axis.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20080611180739.GA20729@edgar.se.axis.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Edgar E. Iglesias" Cc: qemu-devel@nongnu.org On Wed, Jun 11, 2008 at 08:07:39PM +0200, Edgar E. Iglesias wrote: > On Wed, Jun 11, 2008 at 12:21:45PM -0500, Jason Wessel wrote: > > > > When using slirp networking with a redirected tcp socket, the qemu guest > > os does not receive RST packets when a redirected, accepted socket goes > > into the FIN_WAIT_2 status. Presently slirp sends ACKs instead of RST > > packets, which means the guest os application socket writes do not fail > > event after the client has terminated the socket. > > > > Here is a simple way to demonstrate the problem. > > > > * Start qemu with user mode networking plus: > > -redir tcp:4441::4441 > > > > * Assuming you booted a linux guest os you could run: > > cat /dev/zero | nc -p 4441 -l > > > > * On the host run the following command and you > > must hit control-c after about 1 second > > nc localhost 4441 > > Hello Jason, > > IIRC connections in FIN_WAIT_2 can continue to receive data. > > If I might take a wild guess at whats going on: > The host closed the receiving socket when you ctrl-c nc. That socket still has > data in it's rcvbuf so the stack aborts the connection and sends a RST. The > slirp code should now see a -1 on it's next write to that socket and an errno > ECONNRESET but it's not correctly taking care of that case, instead it's > incorrectly setting the TCP state to FIN_WAIT_2. It should have set it to > CLOSED and sent a RST to the guest. Heh, that guess wasn't entirely correct... Anyway, here is a patch that hopefully helps. Best regards -- Edgar E. Iglesias Axis Communications AB diff --git a/slirp/socket.c b/slirp/socket.c index 75003af..2a459a1 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -165,9 +165,21 @@ soread(so) if (nn < 0 && (errno == EINTR || errno == EAGAIN)) return 0; else { + int err; + socklen_t slen; + + err = errno; + if (nn == 0) + getsockopt(so->s, SOL_SOCKET, SO_ERROR, + &err, &slen); + DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); sofcantrcvmore(so); - tcp_sockclosed(sototcpcb(so)); + if (err == ECONNRESET + || err == ENOTCONN || err == EPIPE) + tcp_drop(sototcpcb(so), err); + else + tcp_sockclosed(sototcpcb(so)); return -1; } }