From patchwork Sat Feb 18 08:31:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Helge Deller X-Patchwork-Id: 9581015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A1C6600F6 for ; Sat, 18 Feb 2017 08:31:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3DB332858F for ; Sat, 18 Feb 2017 08:31:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F9E8286ED; Sat, 18 Feb 2017 08:31:59 +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=-6.4 required=2.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_SPAM 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 3F6392858F for ; Sat, 18 Feb 2017 08:31:57 +0000 (UTC) Received: from localhost ([::1]:57578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf0Qu-00030O-MT for patchwork-qemu-devel@patchwork.kernel.org; Sat, 18 Feb 2017 03:31:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cf0Qf-0002s1-M3 for qemu-devel@nongnu.org; Sat, 18 Feb 2017 03:31:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cf0Qc-0005bv-Cn for qemu-devel@nongnu.org; Sat, 18 Feb 2017 03:31:41 -0500 Received: from mout.gmx.net ([212.227.15.19]:55958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cf0Qc-0005aZ-04 for qemu-devel@nongnu.org; Sat, 18 Feb 2017 03:31:38 -0500 Received: from ls3530.fritz.box ([193.159.26.95]) by mail.gmx.com (mrgmx003 [212.227.17.190]) with ESMTPSA (Nemesis) id 0MdKkd-1cxUsW1HT1-00IY15; Sat, 18 Feb 2017 09:31:19 +0100 Date: Sat, 18 Feb 2017 09:31:14 +0100 From: Helge Deller To: qemu-devel@nongnu.org, Riku Voipio Message-ID: <20170218083114.GA3424@ls3530.fritz.box> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-Provags-ID: V03:K0:69eKvKChe7qovpECGA7cGlhzhSexStJ2IZ8OWv/BUMjiHROhivy sYFp+JZ8fYEuNFWGdcvI/HbkBus40Gd3DG+9Pkxi+0Fizrs5OfwqXyULF/muvpHu8nR8T/3 A+jzqKY0dc5FLwv16FC52vUqBqAZc1b3F7FZnEDZMcq0tJRbYTf5cVxKqVIK+IjdZNxkhPO cWFsxYrXNBViqLxaaOQjw== X-UI-Out-Filterresults: notjunk:1; V01:K0:eHkbix2PRrY=:CX1yZhUB0O/4287CySV+NM S9e52EVcQ+6UqbcDBam7wJ1KiSiZLd2egEfF0m40QbuInUIHsE7NRLZwX8eWgNK4kCnsYOAZb Z6u0A1RoXBRctKFdIXq7VjL/dc/AiLpIBhYXwJTWKnNVUAf2glAf64F8IHUHJT5wvVBgi9oiN 2mU38C1ccwOHUPgjur0Vn5jL1XhAwCWXlMKQeOBjnnDKc1IQ5sBxZzZphfMq9vFhV9uCif4+I NFZLIqzwa9sKRyCsBl6njDsuv8NFHxEsXU99B4JO7m39c7A+SZ10LMx493zP9YaEZ+I69s6BL g0fw6JDzNku1LwgdY8XCnGdnwJws2BXv5+eX7ShImsnIbSh7FdFkIv5siUWdFH+EuDEZ+S583 K3sFIhz/YELsb/zNhLcBWT6YOjoGBv/GM8rgKnK66vGZn7enruRKJJvHDXgnWqxhGGAKI/SkF VCy1nhgV4Du9DAfFot9Wt6Ur+wO+v4EQDjgmFU5nzno9I5FQx1/j7RIms3+hcoVz2ROLGKhY0 Nr1shMU+Vf9B0S41vblCyh/XfXy554hSxrDEDRNzlKRiuQM42q/JpK5NnuuPAU10XWue8Ucl/ OfJ7qeHcMLc4i0L04ysbqamVBhQFd/UnkgKx7JTlHI9IIRu1/OQ4XgBVGLjmrJyL4UwIJE66R cjwhQSsZRmhJIoHY7JY1xWp4XTfEL8AdVS5h/upWzH2SJPljHnPxI7mUS5M64+Aw2OLL0/zPU o+EBjcuoCajglUvF7HCCkvFLVFiWhKm77ti3gy0EnEqr/mLvAyiiKkdxjO8= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 212.227.15.19 Subject: [Qemu-devel] [PATCH v4] 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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=0 optname=12 Unsupported setsockopt level=41 optname=16 Unsupported setsockopt level=41 optname=25 Unsupported setsockopt level=41 optname=50 Unsupported setsockopt level=41 optname=51 Unsupported setsockopt level=41 optname=8 Unsupported setsockopt level=58 optname=1 Tested with hppa-linux-user (big-endian) on x86_64 (little-endian). Signed-off-by: Helge Deller --- Changes to v3: - Fix up checkpatch fallouts 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é diff --git a/linux-user/syscall.c b/linux-user/syscall.c index f569f82..6bd3ea7 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,34 @@ static inline abi_long host_to_target_sockaddr(abi_ulong target_addr, return 0; } +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 == 0) { + return 0; + } + + target_saddr = lock_user(VERIFY_WRITE, target_addr, len, 0); + if (!target_saddr) { + return -TARGET_EFAULT; + } + memcpy(target_saddr, addr, len); + if (len >= offsetof(struct target_sockaddr_in6, sin6_family) + + sizeof(target_saddr->sin6_family)) { + target_saddr->sin6_family = tswap16(addr->sin6_family); + } + if (len >= offsetof(struct target_sockaddr_in6, sin6_scope_id) + + sizeof(target_saddr->sin6_scope_id)) { + target_saddr->sin6_scope_id = 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_msgh) { @@ -1839,6 +1869,85 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, } break; + case SOL_IP: + switch (cmsg->cmsg_type) { + case IP_TTL: + { + uint32_t *v = (uint32_t *)data; + uint32_t *t_int = (uint32_t *)target_data; + if (tgt_len != 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 = (struct errhdr_t *)data; + struct errhdr_t *target_errh = + (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->offender, + (void *) &errh->offender, sizeof(errh->offender)); + break; + } + default: + goto unimplemented; + } + break; + + case SOL_IPV6: + switch (cmsg->cmsg_type) { + case IPV6_HOPLIMIT: + { + uint32_t *v = (uint32_t *)data; + uint32_t *t_int = (uint32_t *)target_data; + if (tgt_len != 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 = (struct errhdr6_t *)data; + struct errhdr6_t *target_errh = + (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 +2877,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 +2927,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 = 0; if (optlen < sizeof(uint32_t)) { return -TARGET_EINVAL; @@ -2827,6 +2942,50 @@ static abi_long do_setsockopt(int sockfd, int level, int optname, ret = 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 = tswap32(pki.ipi6_ifindex); + + ret = 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 = 0; val < 8; val++) { + icmp6f.data[val] = tswap32(icmp6f.data[val]); + } + + ret = get_errno(setsockopt(sockfd, level, optname, + &icmp6f, sizeof(icmp6f))); + break; + } default: goto unimplemented; } @@ -2834,7 +2993,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)]; }; +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;