From patchwork Thu May 23 14:43:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Vivier X-Patchwork-Id: 1104207 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=vivier.eu Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 458srl01rZz9s4V for ; Fri, 24 May 2019 00:51:19 +1000 (AEST) Received: from localhost ([127.0.0.1]:38125 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTp3t-0001Oy-01 for incoming@patchwork.ozlabs.org; Thu, 23 May 2019 10:51:17 -0400 Received: from eggs.gnu.org ([209.51.188.92]:60928) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hTowu-0004CX-3L for qemu-devel@nongnu.org; Thu, 23 May 2019 10:44:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hTows-0006Be-Tv for qemu-devel@nongnu.org; Thu, 23 May 2019 10:44:04 -0400 Received: from mout.kundenserver.de ([212.227.126.134]:34261) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hTows-00069c-Kz for qemu-devel@nongnu.org; Thu, 23 May 2019 10:44:02 -0400 Received: from localhost.localdomain ([78.238.229.36]) by mrelayeu.kundenserver.de (mreue010 [212.227.15.167]) with ESMTPSA (Nemesis) id 1Mzydy-1gfh6S11Bm-00x4Cg; Thu, 23 May 2019 16:43:46 +0200 From: Laurent Vivier To: qemu-devel@nongnu.org Date: Thu, 23 May 2019 16:43:33 +0200 Message-Id: <20190523144336.13960-8-laurent@vivier.eu> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190523144336.13960-1-laurent@vivier.eu> References: <20190523144336.13960-1-laurent@vivier.eu> MIME-Version: 1.0 X-Provags-ID: V03:K1:wqhZU6gk88fwROrf82j7nD5p1cGnks1SE+P6uFI2h9boVBYa1xx j9dCF/nuRHLxPrQ6ONJFor1Dz92nwXFH7sKA7QSWl+3xBN5eWC1WsPuS79PaV2qqP46woZo 2TNddznXiC0wUznWi1fNKR7KKGlnz6aOlgwH8cOKkkEUN1EJtsRCDUW1XrfssjU8N1T7foL QHeZeC24NLwd0P5NB7Pzw== X-UI-Out-Filterresults: notjunk:1; V03:K0:d+8fK3F9eAM=:UNZiI+IwYo77XXgZv6V4fp tGpGZe0jTg0AgVyug8vmoX5XMzcUMBEToFDfjrOqmGOub7Ui4ktNmtbggjdbpIkzTcb0Hc2n8 PC5PXuecoi5q+HR1jUKSYymmIxcvFa3D30nKPpjjrdX/wB+7hx+m7LPA/lMSwQtFwehFGPKmc rUdKTncqztVHifTTQN3Lm1vtCuaAR2/jtxJZon0zc3FV/ZGADRi6A2rKP4O0BXUM08SmRV2BB szEV6NA0+2/KmAHSCenVj5tItlPE+Sx9n7koapoBnBoy2dgLRYrAJoH63cjZ9tm8qFtFwarRQ V85eDITLImlqgZTGbRLl7xs7ivypI/dBRCST5tMmMut6lPFdoWWOeJTLy9EYsmpCQ6vf6jdmN kLCJWk4ACiDk/XrSlAjOUl5hSGVmsW1I/VCeblYhu5wY7ZwLawqzKGAJNr6aKP26MI7cw2udx orDBmC44oGGg604vT4jkq8aH+YFcHfDQfYOy3qTa34LhpcdvhOyyYHMJxtWz2Xl5b4RqCdWh8 UXgOY4WVQ754O64jraI/GUqrDzLkkcjRwroUMv/Py3ROfK6w5SAxcCE1A+C26/q7ltbrMxbQ3 s1eigAeXszK0GNHpNVlM5NoUm592OwSkj7lmDxld3CFVADuYrW292T43y5kTHubp6o+80Zx0g B8pFuwkHEwiJHZT5iJOh2LU8vYYQnKUM4n6NGvAlCqy860YeKuTZ5s4ichzG/mGAEUbcrETMH dakVKqKney1fGkYBtYTiRZ83Zz3dEHZp/hGQaw== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.126.134 Subject: [Qemu-devel] [PULL 07/10] linux-user: Add support for setsockopt() options IPV6__MEMBERSHIP 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: Aleksandar Rikalo , Riku Voipio , Laurent Vivier , Aleksandar Markovic , Neng Chen , Aurelien Jarno Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Neng Chen Add support for options IPV6_ADD_MEMBERSHIP and IPV6_DROP_MEMPEMBERSHIP of the syscall setsockopt(). These options control membership in multicast groups. Their argument is a pointer to a struct ipv6_mreq, which is in turn defined in IP v6 header netinet/in.h as: struct ipv6_mreq { /* IPv6 multicast address of group */ struct in6_addr ipv6mr_multiaddr; /* local IPv6 address of interface */ int ipv6mr_interface; }; ...whereas its definition in kernel's include/uapi/linux/in6.h is: #if __UAPI_DEF_IPV6_MREQ struct ipv6_mreq { /* IPv6 multicast address of group */ struct in6_addr ipv6mr_multiaddr; /* local IPv6 address of interface */ int ipv6mr_ifindex; }; #endif The first field of ipv6_mreq has the same name ("ipv6mr_multiaddr") and type ("in6_addr") in both cases. Moreover, the in6_addr structure consists of fields that are always big-endian (on host of any endian), therefore the ipv6_mreq's field ipv6mr_multiaddr doesn't need any endian conversion. The second field of ipv6_mreq may, however, depending on the build environment, have different names. This is the reason why the line "#if __UAPI_DEF_IPV6_MREQ" is used in this patch - to establish the right choice for the field name. Also, endian conversion is needed for this field, since it is of type "int". Signed-off-by: Neng Chen Signed-off-by: Aleksandar Markovic Reviewed-by: Laurent Vivier Message-Id: <1558282527-22183-5-git-send-email-aleksandar.markovic@rt-rk.com> Signed-off-by: Laurent Vivier --- linux-user/syscall.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index e5545cbafac7..a0c2bf7db43c 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -1911,6 +1911,29 @@ static abi_long do_setsockopt(int sockfd, int level, int optname, &pki, sizeof(pki))); break; } + case IPV6_ADD_MEMBERSHIP: + case IPV6_DROP_MEMBERSHIP: + { + struct ipv6_mreq ipv6mreq; + + if (optlen < sizeof(ipv6mreq)) { + return -TARGET_EINVAL; + } + + if (copy_from_user(&ipv6mreq, optval_addr, sizeof(ipv6mreq))) { + return -TARGET_EFAULT; + } + +#if __UAPI_DEF_IPV6_MREQ + ipv6mreq.ipv6mr_ifindex = tswap32(ipv6mreq.ipv6mr_ifindex); +#else + ipv6mreq.ipv6mr_interface = tswap32(ipv6mreq.ipv6mr_interface); +#endif /* __UAPI_DEF_IVP6_MREQ */ + + ret = get_errno(setsockopt(sockfd, level, optname, + &ipv6mreq, sizeof(ipv6mreq))); + break; + } default: goto unimplemented; }