From nobody Thu Nov 6 01:38:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538935625375952.768936935435; Sun, 7 Oct 2018 11:07:05 -0700 (PDT) Received: from localhost ([::1]:43137 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DSD-0000nB-B0 for importer@patchew.org; Sun, 07 Oct 2018 14:06:57 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54581) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DQn-0008VG-MN for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9DQk-000116-OW for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:29 -0400 Received: from hera.aquilenet.fr ([2a0c:e300::1]:54630) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9DQi-0000vJ-3U for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:24 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 54315297; Sun, 7 Oct 2018 20:05:20 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id j5GJEnLToivr; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 3ECB34A4; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1g9DQc-0001Mq-BY; Sun, 07 Oct 2018 20:05:18 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 7 Oct 2018 20:05:16 +0200 Message-Id: <20181007180518.5212-2-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> References: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULL 1/3] slirp: document mbuf pointers and sizes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Peter Maydell and fix confusing datasize name into gapsize in m_inc. Signed-off-by: Peter Maydell Signed-off-by: Samuel Thibault --- slirp/mbuf.c | 14 +++++++------- slirp/mbuf.h | 13 +++++++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/slirp/mbuf.c b/slirp/mbuf.c index 1b7868355a..aa1f28afb1 100644 --- a/slirp/mbuf.c +++ b/slirp/mbuf.c @@ -151,7 +151,7 @@ m_cat(struct mbuf *m, struct mbuf *n) void m_inc(struct mbuf *m, int size) { - int datasize; + int gapsize; =20 /* some compilers throw up on gotos. This one we can fake. */ if (M_ROOM(m) > size) { @@ -159,17 +159,17 @@ m_inc(struct mbuf *m, int size) } =20 if (m->m_flags & M_EXT) { - datasize =3D m->m_data - m->m_ext; - m->m_ext =3D g_realloc(m->m_ext, size + datasize); + gapsize =3D m->m_data - m->m_ext; + m->m_ext =3D g_realloc(m->m_ext, size + gapsize); } else { - datasize =3D m->m_data - m->m_dat; - m->m_ext =3D g_malloc(size + datasize); + gapsize =3D m->m_data - m->m_dat; + m->m_ext =3D g_malloc(size + gapsize); memcpy(m->m_ext, m->m_dat, m->m_size); m->m_flags |=3D M_EXT; } =20 - m->m_data =3D m->m_ext + datasize; - m->m_size =3D size + datasize; + m->m_data =3D m->m_ext + gapsize; + m->m_size =3D size + gapsize; } =20 =20 diff --git a/slirp/mbuf.h b/slirp/mbuf.h index 33b84485d6..bfdf8c4577 100644 --- a/slirp/mbuf.h +++ b/slirp/mbuf.h @@ -47,6 +47,19 @@ * free the m_ext. This is inefficient memory-wise, but who cares. */ =20 +/* + * mbufs allow to have a gap between the start of the allocated buffer (m_= ext if + * M_EXT is set, m_dat otherwise) and the in-use data: + * + * |--gapsize----->|---m_len-------> + * |----------m_size------------------------------> + * |----M_ROOM--------------------> + * |-M_FREEROOM--> + * + * ^ ^ ^ + * m_dat/m_ext m_data end of buffer + */ + /* * How much room is in the mbuf, from m_data to the end of the mbuf */ --=20 2.19.0 From nobody Thu Nov 6 01:38:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538935733374484.084152258607; Sun, 7 Oct 2018 11:08:53 -0700 (PDT) Received: from localhost ([::1]:43144 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DU3-0002C9-Bh for importer@patchew.org; Sun, 07 Oct 2018 14:08:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54608) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DQp-0008VL-8z for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9DQo-00017i-8a for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:31 -0400 Received: from hera.aquilenet.fr ([2a0c:e300::1]:54644) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9DQn-0000wv-Lo for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:29 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 013E24A4; Sun, 7 Oct 2018 20:05:21 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id cb1vOvp_vShb; Sun, 7 Oct 2018 20:05:20 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 4DAD4CEB; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1g9DQc-0001Ms-Cc; Sun, 07 Oct 2018 20:05:18 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 7 Oct 2018 20:05:17 +0200 Message-Id: <20181007180518.5212-3-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> References: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULL 2/3] slirp: fix ICMP handling on macOS hosts X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Oates , jan.kiszka@siemens.com, stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Andrew Oates On Linux, SOCK_DGRAM+IPPROTO_ICMP sockets give only the ICMP packet when read from. On macOS, however, the socket acts like a SOCK_RAW socket and includes the IP header as well. This change strips the extra IP header from the received packet on macOS before sending it to the guest. SOCK_DGRAM ICMP sockets aren't supported on other BSDs, but we enable this behavior for them as well to treat the sockets the same as raw sockets. Signed-off-by: Andrew Oates Signed-off-by: Samuel Thibault --- slirp/ip_icmp.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 0b667a429a..da100d1f55 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -420,7 +420,32 @@ void icmp_receive(struct socket *so) icp =3D mtod(m, struct icmp *); =20 id =3D icp->icmp_id; - len =3D qemu_recv(so->s, icp, m->m_len, 0); + len =3D qemu_recv(so->s, icp, M_ROOM(m), 0); + /* + * The behavior of reading SOCK_DGRAM+IPPROTO_ICMP sockets is inconsis= tent + * between host OSes. On Linux, only the ICMP header and payload is + * included. On macOS/Darwin, the socket acts like a raw socket and + * includes the IP header as well. On other BSDs, SOCK_DGRAM+IPPROTO_= ICMP + * sockets aren't supported at all, so we treat them like raw sockets.= It + * isn't possible to detect this difference at runtime, so we must use= an + * #ifdef to determine if we need to remove the IP header. + */ +#ifdef CONFIG_BSD + if (len >=3D sizeof(struct ip)) { + struct ip *inner_ip =3D mtod(m, struct ip *); + int inner_hlen =3D inner_ip->ip_hl << 2; + if (inner_hlen > len) { + len =3D -1; + errno =3D -EINVAL; + } else { + len -=3D inner_hlen; + memmove(icp, (unsigned char *)icp + inner_hlen, len); + } + } else { + len =3D -1; + errno =3D -EINVAL; + } +#endif icp->icmp_id =3D id; =20 m->m_data -=3D hlen; --=20 2.19.0 From nobody Thu Nov 6 01:38:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1538935626106259.74830545949794; Sun, 7 Oct 2018 11:07:06 -0700 (PDT) Received: from localhost ([::1]:43138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DSF-0000pL-Od for importer@patchew.org; Sun, 07 Oct 2018 14:06:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g9DQp-0008VP-I3 for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g9DQo-00017w-Aj for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:31 -0400 Received: from hera.aquilenet.fr ([2a0c:e300::1]:54658) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1g9DQn-0000xM-Q2 for qemu-devel@nongnu.org; Sun, 07 Oct 2018 14:05:30 -0400 Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 523F7CEB; Sun, 7 Oct 2018 20:05:21 +0200 (CEST) Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 6yzXeFyD6d-C; Sun, 7 Oct 2018 20:05:20 +0200 (CEST) Received: from var.youpi.perso.aquilenet.fr (unknown [IPv6:2a01:cb19:181:c200:3602:86ff:fe2c:6a19]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 5629ECF3; Sun, 7 Oct 2018 20:05:19 +0200 (CEST) Received: from samy by var.youpi.perso.aquilenet.fr with local (Exim 4.91) (envelope-from ) id 1g9DQc-0001Mu-Dd; Sun, 07 Oct 2018 20:05:18 +0200 X-Virus-Scanned: Debian amavisd-new at aquilenet.fr From: Samuel Thibault To: qemu-devel@nongnu.org, peter.maydell@linaro.org Date: Sun, 7 Oct 2018 20:05:18 +0200 Message-Id: <20181007180518.5212-4-samuel.thibault@ens-lyon.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> References: <20181007180518.5212-1-samuel.thibault@ens-lyon.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a0c:e300::1 Subject: [Qemu-devel] [PULL 3/3] slirp: Propagate host TCP RST packet to the guest after socket disconnected X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jan.kiszka@siemens.com, Gavin Grant , stefanha@redhat.com, Samuel Thibault Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Gavin Grant Commit 27d92ebc5ed1bb0b518d0ebc4c609182ad20a799 handled the case where the = TCP connection is abruptly closed via a RST packet, by checking for the ECONNRE= SET errno. However it does not consider the case where the connection has been half-closed by the host (FIN/ACK), then the host socket is disconnected. For example, if the host application calls close() on the socket, then the application exits. In this case, the socket still exists due to the file descriptor in SLIRP, = but it is disconnected. recv() does not indicate an error since an orderly sock= et close has previously occurred. The socket will then be stuck in FIN_WAIT_2, until the peer sends FIN/ACK or a timeout occurs. Instead we can send a RST to the peer and transition to the CLOSED state. Signed-off-by: Gavin Grant Signed-off-by: Samuel Thibault --- slirp/socket.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/slirp/socket.c b/slirp/socket.c index 08fe98907d..322383a1f9 100644 --- a/slirp/socket.c +++ b/slirp/socket.c @@ -204,12 +204,19 @@ soread(struct socket *so) return 0; else { int err; - socklen_t slen =3D sizeof err; + socklen_t elen =3D sizeof err; + struct sockaddr_storage addr; + struct sockaddr *paddr =3D (struct sockaddr *) &addr; + socklen_t alen =3D sizeof addr; =20 err =3D errno; if (nn =3D=3D 0) { - getsockopt(so->s, SOL_SOCKET, SO_ERROR, - &err, &slen); + if (getpeername(so->s, paddr, &alen) < 0) { + err =3D errno; + } else { + getsockopt(so->s, SOL_SOCKET, SO_ERROR, + &err, &elen); + } } =20 DEBUG_MISC((dfd, " --- soread() disconnected, nn =3D %d, errno =3D %d-%= s\n", nn, errno,strerror(errno))); --=20 2.19.0