From patchwork Thu Apr 7 08:34:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Thibault X-Patchwork-Id: 8769681 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 58C1E9F39A for ; Thu, 7 Apr 2016 08:36:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6527320251 for ; Thu, 7 Apr 2016 08:36:11 +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 70CF52024F for ; Thu, 7 Apr 2016 08:36:10 +0000 (UTC) Received: from localhost ([::1]:48332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao5Q9-00010i-Sc for patchwork-qemu-devel@patchwork.kernel.org; Thu, 07 Apr 2016 04:36:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36041) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ao5Og-0006wx-GN 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-00063u-Qi 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-JK 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="173024069" 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-00024P-Rc; 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:27 +0200 Message-Id: <1460018068-7909-4-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: "Edgar E. Iglesias" , Steven Luo , Samuel Thibault , jan.kiszka@siemens.com Subject: [Qemu-devel] [PULL 3/4] slirp: Propagate host TCP RST to the guest. 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: "Edgar E. Iglesias" When the host aborts (RST) its side of a TCP connection we need to propagate that RST to the guest. The current code can leave such guest connections dangling forever. Spotted by Jason Wessel. [steven@steven676.net: coding style adjustments] Signed-off-by: Steven Luo Signed-off-by: Samuel Thibault --- slirp/socket.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/slirp/socket.c b/slirp/socket.c index 7f022a6..0d67b12 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -176,9 +176,24 @@ soread(struct socket *so) if (nn < 0 && (errno == EINTR || errno == EAGAIN)) return 0; else { + int err; + socklen_t slen = sizeof err; + + 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; } }