From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anb7a-0005wu-Ta for qemu-devel@nongnu.org; Tue, 05 Apr 2016 20:14:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1anb7X-0007lj-Nc for qemu-devel@nongnu.org; Tue, 05 Apr 2016 20:14:58 -0400 Received: from nm17-vm3.bullet.mail.ne1.yahoo.com ([98.138.91.147]:52304) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1anb7X-0007lS-HJ for qemu-devel@nongnu.org; Tue, 05 Apr 2016 20:14:55 -0400 From: steven@steven676.net Date: Tue, 5 Apr 2016 17:14:52 -0700 Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: [Qemu-devel] [PATCH 3/3] slirp: handle deferred ECONNREFUSED on non-blocking TCP sockets List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: "Edgar E. Iglesias" , Jan Kiszka slirp currently only handles ECONNREFUSED in the case where connect() returns immediately with that error; since we use non-blocking sockets, most of the time we won't receive the error until we later try to read from the socket. Ensure that we deliver the appropriate RST to the guest in this case. Signed-off-by: Steven Luo --- slirp/socket.c | 2 +- slirp/tcp_input.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/slirp/socket.c b/slirp/socket.c index 4372ec2..6d22127 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -188,7 +188,7 @@ soread(struct socket *so) DEBUG_MISC((dfd, " --- soread() disconnected, nn = %d, errno = %d-%s\n", nn, errno,strerror(errno))); sofcantrcvmore(so); - if (err == ECONNRESET + if (err == ECONNRESET || err == ECONNREFUSED || err == ENOTCONN || err == EPIPE) { tcp_drop(sototcpcb(so), err); } else { diff --git a/slirp/tcp_input.c b/slirp/tcp_input.c index 1fcca30..5433e7f 100644 --- a/slirp/tcp_input.c +++ b/slirp/tcp_input.c @@ -725,6 +725,12 @@ findso: so->so_ti = ti; tp->t_timer[TCPT_KEEP] = TCPTV_KEEP_INIT; tp->t_state = TCPS_SYN_RECEIVED; + /* + * Initialize receive sequence numbers now so that we can send a + * valid RST if the remote end rejects our connection. + */ + tp->irs = ti->ti_seq; + tcp_rcvseqinit(tp); tcp_template(tp); } return; -- 2.1.4