From patchwork Thu Jul 26 01:08:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhijian Li (Fujitsu)\" via" X-Patchwork-Id: 10545047 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9030214E2 for ; Thu, 26 Jul 2018 01:27:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 703C82A7B1 for ; Thu, 26 Jul 2018 01:27:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61CCE2A964; Thu, 26 Jul 2018 01:27:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id F0FC62A7B1 for ; Thu, 26 Jul 2018 01:27:40 +0000 (UTC) Received: from localhost ([::1]:57204 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiV47-0007kE-Tr for patchwork-qemu-devel@patchwork.kernel.org; Wed, 25 Jul 2018 21:27:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40908) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fiUlS-0003Nc-RG for qemu-devel@nongnu.org; Wed, 25 Jul 2018 21:08:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fiUlP-0000uB-PW for qemu-devel@nongnu.org; Wed, 25 Jul 2018 21:08:22 -0400 Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:34025) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fiUlP-0000rQ-K2 for qemu-devel@nongnu.org; Wed, 25 Jul 2018 21:08:19 -0400 Received: by mail-qk0-x244.google.com with SMTP id b66-v6so27909qkj.1 for ; Wed, 25 Jul 2018 18:08:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=10YnePuOXunZwLUCoiOxmwjvQTmRsFKqLftP38qFvOI=; b=H3yEHFKMFMv9KXhvoLgYXO81b5/wHiBbodH+lkEbLh7AdVQLnM4MBNqkyvPP7rB2sD rxld5qQ/1hxFDquthqGLQyRKK5Ue6UfITflIhLj2ZJKr3E1qQQ8Yimk1xaH7o140QQlx M3NTg610/W4GYZVDljql6by1aDAKNDHI2ld7Bd9oWNEexGCvKbD27cFZ+46MSe+Q+wSn pFEpfGnPbAEY1KrIv7oZ4fxLwAD5Mj5dzRmrBEx/ptS0kXeV1zXIs6L3gyWNMlzjgDCj Ka0llG6mnV0cIWLP1SUq+jJIAYw3Y96odjRElIp6gfwHt2LLjfkOnOMsdXzL1PPLG63e xqPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=10YnePuOXunZwLUCoiOxmwjvQTmRsFKqLftP38qFvOI=; b=hGFVelMSL92FAkx5G/Zrq72Lm4LhW18uyKvMVKTK5VVJPTWK61xjtk4AN2SNgAuncK hYDwifgYz40Ty65yDLOLHBBCfHTapC7m4cdaYBbDs7RUnN/BfjjB4NYv4wJdoIrplySQ TrIe6lo3uFegSFiKJgGo9uR0mqRDrLxXvPe09sBbdZVw+E/n9QhdJcelrjb+p4j4IoNy qHvQEdfYg06kia9DGWsPxTf9NypX81yN517aHKZ7mGgwcgYsscpd8ryjhob1TGW7JlDx QMVrFf3l+8rKig0/Nft9mv6epLJtRgOHv+DCWRWm3qk2zfDozbO8UjGXAtvvrM50sHZw 515w== X-Gm-Message-State: AOUpUlHZUTHBCjKHogsTcDyEuYWPp/88cxOQikK6AziEIvEfE/nY7sQe vLpM1NEMbmlfdwCQx6jb2c43NQ== X-Google-Smtp-Source: AAOMgpfkhIrljhbMlv7+s8CaGs1FSJkjKE0j2VbXkGP7wcWt0dwHmE6yPxzwlxUZBuyJSrMvubO6eg== X-Received: by 2002:a37:de1a:: with SMTP id h26-v6mr22468903qkj.442.1532567298448; Wed, 25 Jul 2018 18:08:18 -0700 (PDT) Received: from localhost.localdomain (c-65-96-174-46.hsd1.ma.comcast.net. [65.96.174.46]) by smtp.gmail.com with ESMTPSA id 33-v6sm14575605qtw.3.2018.07.25.18.08.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jul 2018 18:08:17 -0700 (PDT) To: samuel.thibault@ens-lyon.org, jan.kiszka@siemens.com, qemu-devel@nongnu.org Date: Wed, 25 Jul 2018 21:08:12 -0400 Message-Id: <20180726010812.5909-1-aoates@google.com> X-Mailer: git-send-email 2.17.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::244 X-Mailman-Approved-At: Wed, 25 Jul 2018 21:27:02 -0400 Subject: [Qemu-devel] [PATCH] 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: , X-Patchwork-Original-From: aoates--- via Qemu-devel From: "Zhijian Li (Fujitsu)\" via" Reply-To: aoates@google.com Cc: Andrew Oates Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Andrew Oates --- slirp/ip_icmp.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 0b667a429a..5fa67814f4 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -420,7 +420,15 @@ void icmp_receive(struct socket *so) icp = mtod(m, struct icmp *); id = icp->icmp_id; - len = qemu_recv(so->s, icp, m->m_len, 0); + len = qemu_recv(so->s, icp, M_ROOM(m), 0); +#ifdef CONFIG_DARWIN + if (len > 0) { + /* Skip the IP header that OS X (unlike Linux) includes. */ + struct ip *inner_ip = mtod(m, struct ip *); + int inner_hlen = inner_ip->ip_hl << 2; + memmove(icp, (unsigned char *)icp + inner_hlen, len - inner_hlen); + } +#endif icp->icmp_id = id; m->m_data -= hlen;