From patchwork Sun Jul 29 01:54:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10548097 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 741B0139A for ; Sun, 29 Jul 2018 01:55:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 56EAE2A95D for ; Sun, 29 Jul 2018 01:55:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4734E2A9F4; Sun, 29 Jul 2018 01:55:33 +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 2052A2A95D for ; Sun, 29 Jul 2018 01:55:31 +0000 (UTC) Received: from localhost ([::1]:46895 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjavh-0002Ix-4x for patchwork-qemu-devel@patchwork.kernel.org; Sat, 28 Jul 2018 21:55:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47240) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fjav1-0001xh-Uh for qemu-devel@nongnu.org; Sat, 28 Jul 2018 21:54:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fjauy-0004xz-0I for qemu-devel@nongnu.org; Sat, 28 Jul 2018 21:54:48 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:40771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fjaux-0004xv-Rx for qemu-devel@nongnu.org; Sat, 28 Jul 2018 21:54:43 -0400 Received: by mail-qt0-x242.google.com with SMTP id h4-v6so8863614qtj.7 for ; Sat, 28 Jul 2018 18:54:43 -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=7YM27AxyWDwtnAUk++RaRMTuGunfoLtcqOFv2OTsP38=; b=t2jDyB1QkuqQoBRRnmatXxV5Q7P7X0Mh+NzcwaDNwUEXedkT/qskZiwmDDiic2R+wI KiUhJmIVXWBfktSH18G2QQ8UyWJHQbQH+3tTuHoxJS4Ha2oB/n4f1OAahRqcYqqe6w2n hPS4ofWth7B4wNWkxptdPxysMaAZAAEcL53IXPIdF/Hw5wyvPq3xhzKt8dLJG678S84l zyMTNQL2SIA8p3r/beLAckuP2sJb4Pc4xFOWHgdtrC+/e3dujd2e4f55HPM1zx3CkWve F7ggnvWSXBvd8+GI4igaLJvXC8hjT7rmeOtUT6LdwZhYmFbX5+NyL0yei6Ucwweb4YKJ ssew== 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=7YM27AxyWDwtnAUk++RaRMTuGunfoLtcqOFv2OTsP38=; b=L62OfLaKn+XCoEWsp6VV5z1wCx9we2u7ofkjzNHdWjvxzjXGrqJ1/a+3TnlwXGigEk pcTltuLo5o+GPwCa/9pRx42eXX69oXhPS5VRLOGtnuK1s+XNKaFfu7bi38st3Xev1RCO DGoCj/AV2KfdHspdE6isuir5anYKQu9RbPSwcvT/JrdLT8sthe3mhmjXKxd/YFAlS2KE MmPf8vRtDnabfJqrCsamZhabPKFVcgxSWAZyxXyN463xwS8j0FeZRE3WiW7L39nu6NyZ Jekuhy6zHG9C7A5aNBwBk4o4QTjle6iVI2vvTajGG3ce9I/1h+fYqNK+TYN1DVi5MtNe FYnw== X-Gm-Message-State: AOUpUlFze/iNkt+NWfs8UV8elfQHfGmfhAXn6Rl89WIaihevUhPzUnv3 U57RsijIXGF+k7B6SOr+xPcK6kMFvMU= X-Google-Smtp-Source: AAOMgpdxvJnYjPNXN3/mHZcEOJpBENr8H8pDJsBk5WvJIaVSEpCtZVIL27vKd2X70wRBE0UkOYz+SQ== X-Received: by 2002:ac8:fb1:: with SMTP id b46-v6mr11539285qtk.31.1532829282504; Sat, 28 Jul 2018 18:54:42 -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 u27-v6sm5882211qkl.66.2018.07.28.18.54.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 28 Jul 2018 18:54:41 -0700 (PDT) To: qemu-devel@nongnu.org, samuel.thibault@ens-lyon.org, jan.kiszka@siemens.com Date: Sat, 28 Jul 2018 21:54:26 -0400 Message-Id: <20180729015426.67133-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:c0d::242 Subject: [Qemu-devel] [PATCH v2] 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: "Denis V. Lunev\" 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 --- v2: check validity of inner_hlen and update len appropriately slirp/ip_icmp.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/slirp/ip_icmp.c b/slirp/ip_icmp.c index 0b667a429a..76c6d54b11 100644 --- a/slirp/ip_icmp.c +++ b/slirp/ip_icmp.c @@ -420,7 +420,21 @@ 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; + if (inner_hlen > len) { + len = -1; + errno = -EINVAL; + } else { + len -= inner_hlen; + memmove(icp, (unsigned char *)icp + inner_hlen, len); + } + } +#endif icp->icmp_id = id; m->m_data -= hlen;