From nobody Sun Apr 28 21:27:09 2024 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.zoho.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 1487366849660682.880908253331; Fri, 17 Feb 2017 13:27:29 -0800 (PST) Received: from localhost ([::1]:56109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ceq3s-000481-AX for importer@patchew.org; Fri, 17 Feb 2017 16:27:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cepmE-0006b1-IC for qemu-devel@nongnu.org; Fri, 17 Feb 2017 16:09:16 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cepm9-0005Gx-Hq for qemu-devel@nongnu.org; Fri, 17 Feb 2017 16:09:14 -0500 Received: from mout.gmx.net ([212.227.17.20]:64236) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cepm6-00059v-BZ for qemu-devel@nongnu.org; Fri, 17 Feb 2017 16:09:09 -0500 Received: from ls3530.fritz.box ([193.159.29.53]) by mail.gmx.com (mrgmx103 [212.227.17.168]) with ESMTPSA (Nemesis) id 0LzbXq-1cIKq91Huc-014hQN; Fri, 17 Feb 2017 22:08:35 +0100 Date: Fri, 17 Feb 2017 22:08:32 +0100 From: Helge Deller To: qemu-devel@nongnu.org, Riku Voipio Message-ID: <20170217210831.GA26068@ls3530.fritz.box> References: <20170211221148.GA2924@ls3530.fritz.box> <20170213220131.GA10356@ls3530.fritz.box> MIME-Version: 1.0 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable In-Reply-To: <20170213220131.GA10356@ls3530.fritz.box> User-Agent: Mutt/1.7.1 (2016-10-04) X-Provags-ID: V03:K0:z018GbRaKGqZ843zVCL2TZdQo/bGKuYFAYG2qDi6j2luwV5WQpv pkmBRN0Ik5bVamNX8fN69fS08fiZ3FkuI/r37KOWuRpR5GyAf8bkj++sxinXrdxJxpBHhn/ jwUxpcDlZZEEEErZfVAY4C3IJwhDsB1BkabsMEvc+pPPYvA91xx9HsMEo3NL7+8FAk8LrJ8 gt0iKL3WO/F0kUAVqRQPg== X-UI-Out-Filterresults: notjunk:1;V01:K0:JB+UIkSOU9k=:1krXLhLXeQ+00+yQjr/+0f sOUrFeZF6/PQtDurw5ggBJIMkUpvBoulDPNiVcchyTE/yUeb7Hkrbk/yCH1PMKa9ohX/bhaQj OX9Ex1hEzTpsYX4AsYBl+LtDMyFhLODpWb2I6FMTon01J4+E8AoWxkDgLPtmarKFRVsIfyM1u B+dp/X5biI2LWthaNJ5XgN5R2BWNAEMehskEarW53myzEMRLAmOneb/7nKBArm2FP8x2/xCxI MZPQFRpG+Is3vdZdxhPHrfQHRNJihtLJCTFcWapngcOIRkdyxXbFB+9Y+foOxenRkFcBcAdiQ 92EVbGzhq9UZMUoO3RXkvrypX8EAxq9dHadh7F1b7RNaCq2mxlK4XOvubqKfo7p+yv3KBydsA Mc+6njK+8RVC6W1hANEBO08su3JfzEASp7B4tCtfTj9ssr0TL5OT395uonIInvNJJ4mmYhhNj 6HIhy9Y21tiIg9UGSj1DA7x4qf/u7FxHRWoKRTkknBnYBl7UXmZP8i9Nn3YvaDjJbWAWGGSxO 7xpmgbXsdYsYc0DRGMHb8fY8SugAYbmw4BeRuiw7/uLMF9HUMxbAmS2EbtjqhWre64WCPYIa2 bsDimDUWUtX6+EyjgsfaYTYIbGLwmjCdia89dBssxvLU+bn7GNX2D6O1uLTpPXEKSwzdI/Vi3 lzg7hpRZbZXTMQYy1+2ry/6cwjuCmwCwntnrxmMg8O9LQujzW1Aj2c5Uf8772pLgFMoie6G4e 7itZJWZwvaab83Iv4/uMT2aeLgQaUfFM2jmc06A6dLYDPMGAHeL5F6bJ1IM= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.17.20 Subject: [Qemu-devel] [PATCH v3] linux-user: Add sockopts for IPv6 ping and IPv6 traceroute 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: Philippe =?iso-8859-15?Q?Mathieu-Daud=E9?= , Laurent Vivier , Richard Henderson 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" Add the neccessary sockopts for ping and traceroute on IPv6. This fixes the following qemu warnings with IPv6: Unsupported ancillary data: 0/2 Unsupported ancillary data: 0/11 Unsupported ancillary data: 41/25 Unsupported setsockopt level=3D0 optname=3D12=20 Unsupported setsockopt level=3D41 optname=3D16 Unsupported setsockopt level=3D41 optname=3D25 Unsupported setsockopt level=3D41 optname=3D50 Unsupported setsockopt level=3D41 optname=3D51 Unsupported setsockopt level=3D41 optname=3D8 Unsupported setsockopt level=3D58 optname=3D1 Tested with hppa-linux-user (big-endian) on x86_64 (little-endian). Signed-off-by: Helge Deller --- Changes to v2: (all suggested by Laurent Vivier) - Drop goto statements and replaced by real code - New function host_to_target_sockaddr_in6() - Fix IPV6_PKTINFO which uses in6_pktinfo instead of uint32_t - Move one IPV6_CHECKSUM from SOL_ICMPV6 to SOL_IPV6 - Fix ICMPV6_FILTER to use icmpv6_filter Changes to v1: - Added IPV6_PKTINFO sockopt as reported by Philippe Mathieu-Daud=C3=A9 diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f569f82..c0c2d3d 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -57,6 +57,8 @@ int __clone2(int (*fn)(void *), void *child_stack_base, #include #include #include +#include +#include #include "qemu-common.h" #ifdef CONFIG_TIMERFD #include @@ -1640,6 +1642,33 @@ static inline abi_long host_to_target_sockaddr(abi_u= long target_addr, return 0; } =20 +static inline abi_long host_to_target_sockaddr_in6(abi_ulong target_addr, + struct sockaddr_in6 *addr, + socklen_t len) +{ + struct target_sockaddr_in6 *target_saddr; + + if (len =3D=3D 0) { + return 0; + } + + target_saddr =3D lock_user(VERIFY_WRITE, target_addr, len, 0); + if (!target_saddr) + return -TARGET_EFAULT; + memcpy(target_saddr, addr, len); + if (len >=3D offsetof(struct target_sockaddr_in6, sin6_family) + + sizeof(target_saddr->sin6_family)) { + target_saddr->sin6_family =3D tswap16(addr->sin6_family); + } + if (len >=3D offsetof(struct target_sockaddr_in6, sin6_scope_id) + + sizeof(target_saddr->sin6_scope_id)) { + target_saddr->sin6_scope_id =3D tswap16(addr->sin6_scope_id); + } + unlock_user(target_saddr, target_addr, len); + + return 0; +} + static inline abi_long target_to_host_cmsg(struct msghdr *msgh, struct target_msghdr *target_ms= gh) { @@ -1839,6 +1868,82 @@ static inline abi_long host_to_target_cmsg(struct ta= rget_msghdr *target_msgh, } break; =20 + case SOL_IP: + switch (cmsg->cmsg_type) { + case IP_TTL: + { + uint32_t *v =3D (uint32_t *)data; + uint32_t *t_int =3D (uint32_t *)target_data; + if (tgt_len !=3D CMSG_LEN(0)) + goto unimplemented; + + __put_user(*v, t_int); + break; + } + case IP_RECVERR: + { + struct errhdr_t { + struct sock_extended_err ee; + struct sockaddr_in offender; + }; + struct errhdr_t *errh =3D (struct errhdr_t *)data; + struct errhdr_t *target_errh =3D + (struct errhdr_t *)target_data; + + __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); + __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); + __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); + __put_user(errh->ee.ee_code, &target_errh->ee.ee_code); + __put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad); + __put_user(errh->ee.ee_info, &target_errh->ee.ee_info); + __put_user(errh->ee.ee_data, &target_errh->ee.ee_data); + host_to_target_sockaddr((unsigned long) &target_errh->offe= nder, + (void *) &errh->offender, sizeof(errh->offender)); + break; + } + default: + goto unimplemented; + } + break; + + case SOL_IPV6: + switch (cmsg->cmsg_type) { + case IPV6_HOPLIMIT: + { + uint32_t *v =3D (uint32_t *)data; + uint32_t *t_int =3D (uint32_t *)target_data; + if (tgt_len !=3D CMSG_LEN(0)) + goto unimplemented; + + __put_user(*v, t_int); + break; + } + case IPV6_RECVERR: + { + struct errhdr6_t { + struct sock_extended_err ee; + struct sockaddr_in6 offender; + }; + struct errhdr6_t *errh =3D (struct errhdr6_t *)data; + struct errhdr6_t *target_errh =3D + (struct errhdr6_t *)target_data; + + __put_user(errh->ee.ee_errno, &target_errh->ee.ee_errno); + __put_user(errh->ee.ee_origin, &target_errh->ee.ee_origin); + __put_user(errh->ee.ee_type, &target_errh->ee.ee_type); + __put_user(errh->ee.ee_code, &target_errh->ee.ee_code); + __put_user(errh->ee.ee_pad, &target_errh->ee.ee_pad); + __put_user(errh->ee.ee_info, &target_errh->ee.ee_info); + __put_user(errh->ee.ee_data, &target_errh->ee.ee_data); + host_to_target_sockaddr_in6((unsigned long) &target_errh->= offender, + &errh->offender, sizeof(errh->offender)); + break; + } + default: + goto unimplemented; + } + break; + default: unimplemented: gemu_log("Unsupported ancillary data: %d/%d\n", @@ -2768,6 +2873,7 @@ static abi_long do_setsockopt(int sockfd, int level, = int optname, case IP_PKTINFO: case IP_MTU_DISCOVER: case IP_RECVERR: + case IP_RECVTTL: case IP_RECVTOS: #ifdef IP_FREEBIND case IP_FREEBIND: @@ -2817,6 +2923,11 @@ static abi_long do_setsockopt(int sockfd, int level,= int optname, case IPV6_MTU: case IPV6_V6ONLY: case IPV6_RECVPKTINFO: + case IPV6_UNICAST_HOPS: + case IPV6_RECVERR: + case IPV6_RECVHOPLIMIT: + case IPV6_2292HOPLIMIT: + case IPV6_CHECKSUM: val =3D 0; if (optlen < sizeof(uint32_t)) { return -TARGET_EINVAL; @@ -2827,6 +2938,50 @@ static abi_long do_setsockopt(int sockfd, int level,= int optname, ret =3D get_errno(setsockopt(sockfd, level, optname, &val, sizeof(val))); break; + case IPV6_PKTINFO: + { + struct in6_pktinfo pki; + + if (optlen < sizeof(pki)) { + return -TARGET_EINVAL; + } + + if (copy_from_user(&pki, optval_addr, sizeof(pki))) { + return -TARGET_EFAULT; + } + + pki.ipi6_ifindex =3D tswap32(pki.ipi6_ifindex); + + ret =3D get_errno(setsockopt(sockfd, level, optname, + &pki, sizeof(pki))); + break; + } + default: + goto unimplemented; + } + break; + case SOL_ICMPV6: + switch(optname) { + case ICMPV6_FILTER: + { + struct icmp6_filter icmp6f; + + if (optlen < sizeof(icmp6f)) { + return -TARGET_EINVAL; + } + + if (copy_from_user(&icmp6f, optval_addr, sizeof(icmp6f))) { + return -TARGET_EFAULT; + } + + for (val =3D 0; val < 8; val++) { + icmp6f.data[val] =3D tswap32(icmp6f.data[val]); + } + + ret =3D get_errno(setsockopt(sockfd, level, optname, + &icmp6f, sizeof(icmp6f))); + break; + } default: goto unimplemented; } @@ -2834,7 +2989,8 @@ static abi_long do_setsockopt(int sockfd, int level, = int optname, case SOL_RAW: switch (optname) { case ICMP_FILTER: - /* struct icmp_filter takes an u32 value */ + case IPV6_CHECKSUM: + /* those take an u32 value */ if (optlen < sizeof(uint32_t)) { return -TARGET_EINVAL; } diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 72ca5b1..40c5027 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -164,6 +164,14 @@ struct target_sockaddr_in { sizeof(struct target_in_addr)]; }; =20 +struct target_sockaddr_in6 { + uint16_t sin6_family; + uint16_t sin6_port; /* big endian */ + uint32_t sin6_flowinfo; /* big endian */ + struct in6_addr sin6_addr; /* IPv6 address, big endian */ + uint32_t sin6_scope_id; +}; + struct target_sock_filter { abi_ushort code; uint8_t jt;