From nobody Tue Oct 28 12:14:06 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; dkim=fail; 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 151543319770235.07490828590994; Mon, 8 Jan 2018 09:39:57 -0800 (PST) Received: from localhost ([::1]:47263 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYbOv-0008KU-0o for importer@patchew.org; Mon, 08 Jan 2018 12:39:57 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33886) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYbFB-00006J-LN for qemu-devel@nongnu.org; Mon, 08 Jan 2018 12:29:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYbF8-0000ht-G9 for qemu-devel@nongnu.org; Mon, 08 Jan 2018 12:29:53 -0500 Received: from mail-qk0-x243.google.com ([2607:f8b0:400d:c09::243]:44501) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eYbF8-0000hO-CU for qemu-devel@nongnu.org; Mon, 08 Jan 2018 12:29:50 -0500 Received: by mail-qk0-x243.google.com with SMTP id v188so15086157qkh.11 for ; Mon, 08 Jan 2018 09:29:50 -0800 (PST) Received: from x1.local ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id j127sm787922qkd.88.2018.01.08.09.29.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 08 Jan 2018 09:29:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WI+9i6Ed0QWaQh8rKK0RExXr90jMLMJ1cDrZWoVgPFE=; b=X2lQrvF/U883cbDckqPPJfMHfoGC7Xvr+fq3faVGdMb5j+WuAofXUth1yj8dps4Yp8 40ictUE/ngCPojHZZ7wOWfFz0XECj+eanbwrYcOpgO/xm9bnIN7NNgZOX454RuSsm8kz eABZ1Ju5+pSJSFKEPPD/dzaMa3TwsWUUPKmz7iV6Ybi/UpqBVSkAjJwD5c7g50TZm9P9 RdD+lPU6FF8wS0xp7KR+RiRDudIFVgR3gqkH2ESKQcleEx1s/WwzSDoxVWEzituVUm0z sI6LMc0wscoLcer6uJjol6eSOlXaL53uR97qGUUn2l2CIHHJT22CBNJo6IVz9ZrrPFob 4aFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=WI+9i6Ed0QWaQh8rKK0RExXr90jMLMJ1cDrZWoVgPFE=; b=mexXHC9RFc66npTuFWfixiqXEip28HBx7wHz/72/tikhdtwh3OlXG5ykQpSQ0ZcmMN H3yxUQqyEEV4EnJM/AWhJisbSy20godMtYNaiJQgsPvfyIO7QAHE0Xt7bWjnLKCq/INy S0TNMhqKoTd8PLzJbYdSG0JAyFCX5PRr06RVyFDcFYt3rpfXhST45pwE8p6RRWp4CGma eruARg1EXwLQLcsQhaet2emXjQKAFAINJSYcVOHN3kAplxn+HBSUjzlaLGHffTX0x2mE ZM7Vryq8vZrgKjfrJClJiWh38tP9ijNFDNUszO1BvG77S+AwUK2Sv2n9YCAyOp9vIai7 +rlg== X-Gm-Message-State: AKwxytephYcTgIbQqEnUiCDU81VclFff3S0i6sgz+DGlHDXmGH06/ll1 EHSLv8hKNM6ZVdi+rLTxgCA= X-Google-Smtp-Source: ACJfBosk9c/Pp6b8TiXqqIRcRsMd7f7cUH+7G2pRC6Le8J5LPkzjiz96tlw+HLYIBiOowNIV45ZJpQ== X-Received: by 10.55.53.80 with SMTP id c77mr17744479qka.1.1515432589931; Mon, 08 Jan 2018 09:29:49 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Samuel Thibault , Jan Kiszka , "Michael S . Tsirkin" , Paolo Bonzini , Eric Blake , Thomas Huth , Richard Henderson , Peter Maydell Date: Mon, 8 Jan 2018 14:29:04 -0300 Message-Id: <20180108172904.8772-13-f4bug@amsat.org> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180108172904.8772-1-f4bug@amsat.org> References: <20180108172904.8772-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c09::243 Subject: [Qemu-devel] [RFC PATCH 12/12] slirp: use HOST_SUPPORTS_UNALIGNED_ACCESS 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: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Access struct in6_addr with 'void *', then cast to 'u8 *' to avoid alignment issues. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- ugly... slirp/ip6.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/slirp/ip6.h b/slirp/ip6.h index c6493a0856..4eaeaa9a0a 100644 --- a/slirp/ip6.h +++ b/slirp/ip6.h @@ -51,11 +51,19 @@ 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00 } } =20 +#ifdef HOST_SUPPORTS_UNALIGNED_ACCESS static inline bool in6_equal(const struct in6_addr *a, const struct in6_ad= dr *b) { return memcmp(a, b, sizeof(*a)) =3D=3D 0; } +#else +static inline bool in6_equal(const void *a, const void *b) +{ + return memcmp(a, b, sizeof(struct in6_addr)) =3D=3D 0; +} +#endif =20 +#ifdef HOST_SUPPORTS_UNALIGNED_ACCESS static inline bool in6_equal_net(const struct in6_addr *a, const struct in6_addr *b, int prefix_len) @@ -71,7 +79,28 @@ static inline bool in6_equal_net(const struct in6_addr *= a, return a->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)) =3D=3D b->s6_addr[prefix_len / 8] >> (8 - (prefix_len % 8)); } +#else +static inline bool in6_equal_net(const void *a, + const void *b, + int prefix_len) +{ + const uint8_t *aa =3D (uint8_t *)a; + const uint8_t *ab =3D (uint8_t *)b; + + if (memcmp(a, b, prefix_len / 8) !=3D 0) { + return 0; + } + + if (prefix_len % 8 =3D=3D 0) { + return 1; + } + + return (aa[prefix_len / 8] >> (8 - (prefix_len % 8))) + =3D=3D (ab[prefix_len / 8] >> (8 - (prefix_len % 8))); +} +#endif =20 +#ifdef HOST_SUPPORTS_UNALIGNED_ACCESS static inline bool in6_equal_mach(const struct in6_addr *a, const struct in6_addr *b, int prefix_len) @@ -89,6 +118,28 @@ static inline bool in6_equal_mach(const struct in6_addr= *a, return (a->s6_addr[prefix_len / 8] & ((1U << (8 - (prefix_len % 8))) -= 1)) =3D=3D (b->s6_addr[prefix_len / 8] & ((1U << (8 - (prefix_len % 8)= )) - 1)); } +#else +static inline bool in6_equal_mach(const void *a, + const void *b, + int prefix_len) +{ + const uint8_t *aa =3D (uint8_t *)a; + const uint8_t *ab =3D (uint8_t *)b; + + if (memcmp(&(aa[DIV_ROUND_UP(prefix_len, 8)]), + &(ab[DIV_ROUND_UP(prefix_len, 8)]), + 16 - DIV_ROUND_UP(prefix_len, 8)) !=3D 0) { + return 0; + } + + if (prefix_len % 8 =3D=3D 0) { + return 1; + } + + return (aa[prefix_len / 8] & ((1U << (8 - (prefix_len % 8))) - 1)) + =3D=3D (ab[prefix_len / 8] & ((1U << (8 - (prefix_len % 8))) - 1)); +} +#endif =20 =20 #define in6_equal_router(a)\ @@ -112,10 +163,17 @@ static inline bool in6_equal_mach(const struct in6_ad= dr *a, #define in6_zero(a)\ (in6_equal(a, &(struct in6_addr)ZERO_ADDR)) =20 +#ifdef HOST_SUPPORTS_UNALIGNED_ACCESS static inline bool in6_multicast(const struct in6_addr *a) { return a->s6_addr[0] =3D=3D 0xff; } +#else +static inline bool in6_multicast(const void *a) +{ + return ((const uint8_t *)a)[0] =3D=3D 0xff; +} +#endif =20 /* Compute emulated host MAC address from its ipv6 address */ static inline void in6_compute_ethaddr(struct in6_addr ip, --=20 2.15.1