From patchwork Thu Apr 7 11:04:13 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8771131 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 68E4DC0553 for ; Thu, 7 Apr 2016 11:07:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C825A20204 for ; Thu, 7 Apr 2016 11:07:24 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0D476201EC for ; Thu, 7 Apr 2016 11:07:24 +0000 (UTC) Received: from localhost ([::1]:48982 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao7mV-0001nG-6W for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 07:07:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao7jf-0005ay-1q for qemu-devel@nongnu.org; Thu, 07 Apr 2016 07:04:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ao7jZ-0007dJ-4x for qemu-devel@nongnu.org; Thu, 07 Apr 2016 07:04:26 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:9020) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao7jY-0007cy-Ts for qemu-devel@nongnu.org; Thu, 07 Apr 2016 07:04:21 -0400 X-IronPort-AV: E=Sophos;i="5.24,449,1454972400"; d="scan'208";a="173049773" Received: from unknown (HELO var.youpi.perso.aquilenet.fr) ([193.50.110.219]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 07 Apr 2016 13:04:14 +0200 Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1ao7jS-0005X0-81; Thu, 07 Apr 2016 13:04:14 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Apr 2016 13:04:13 +0200 Message-Id: <1460027053-21211-5-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1460027053-21211-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1460027053-21211-1-git-send-email-samuel.thibault@ens-lyon.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.134.164.104 Cc: steven@steven676.net, jan.kiszka@siemens.com, Steven Luo , Samuel Thibault , edgar.iglesias@gmail.com Subject: [Qemu-devel] [PULL 4/4] slirp: handle deferred ECONNREFUSED on non-blocking TCP sockets X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Steven Luo 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 Reviewed-by: Edgar E. Iglesias Signed-off-by: Samuel Thibault --- 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 0d67b12..bd97b2d 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;