From patchwork Thu Apr 7 08:34:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8769641 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 685CBC0553 for ; Thu, 7 Apr 2016 08:34:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFE5C20222 for ; Thu, 7 Apr 2016 08:34:48 +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 C6F6A20204 for ; Thu, 7 Apr 2016 08:34:47 +0000 (UTC) Received: from localhost ([::1]:48312 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao5Oo-0006xE-S4 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 04:34:46 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36040) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao5Og-0006ww-GC for qemu-devel@nongnu.org; Thu, 07 Apr 2016 04:34:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ao5Od-00063m-9g for qemu-devel@nongnu.org; Thu, 07 Apr 2016 04:34:38 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:12330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao5Od-00063h-2I for qemu-devel@nongnu.org; Thu, 07 Apr 2016 04:34:35 -0400 X-IronPort-AV: E=Sophos;i="5.24,448,1454972400"; d="scan'208";a="173024070" 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 10:34:33 +0200 Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.87) (envelope-from ) id 1ao5Oa-00024S-S7; Thu, 07 Apr 2016 10:34:32 +0200 From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Thu, 7 Apr 2016 10:34:28 +0200 Message-Id: <1460018068-7909-5-git-send-email-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.8.0.rc3 In-Reply-To: <1460018068-7909-1-git-send-email-samuel.thibault@ens-lyon.org> References: <1460018068-7909-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: jan.kiszka@siemens.com, Steven Luo , Samuel Thibault 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;