From patchwork Mon Jan 11 14:16:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Riku Voipio X-Patchwork-Id: 565888 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EE1641402BC for ; Tue, 12 Jan 2016 01:19:03 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b=Nw3kkYd3; dkim-atps=neutral Received: from localhost ([::1]:54483 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdJF-0000jU-NC for incoming@patchwork.ozlabs.org; Mon, 11 Jan 2016 09:19:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdGt-0004c7-Fp for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aIdGr-00029x-9H for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:35 -0500 Received: from mail-lf0-x231.google.com ([2a00:1450:4010:c07::231]:34182) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aIdGr-00029n-1z for qemu-devel@nongnu.org; Mon, 11 Jan 2016 09:16:33 -0500 Received: by mail-lf0-x231.google.com with SMTP id 17so11991959lfz.1 for ; Mon, 11 Jan 2016 06:16:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=yvKXI4ZmIfoYvtqZuxpK3rdxhLKdWfKJ6wHuWtzmWVM=; b=Nw3kkYd3Vc+Yj4+f0qXu7Xhctt9EKDvme5DjQR2auhNa7KJ3OgiuMunVtTCCIcli/v Vze5itUwHCJPXqBEydJDJDTsNLxTmKYyHTUGnOhqcUieM17SWR1TmfV2+PTNOXIljSZS OYumY59HCchjryaWzgSFgXo9FoPyAfAXk0a4E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding; bh=yvKXI4ZmIfoYvtqZuxpK3rdxhLKdWfKJ6wHuWtzmWVM=; b=BE0bDGXP5UymLJ70U+OVtO9JoKgs5mJkFkivUCJ3SUttWQprYWjcVRcC5EfmQI9+EW ZYbB02caPy1KcDJfTDbZfEZhY1f5q6979jasmh7zNThKnFXkZCAt7YorGgL+scOokG+l SaNpGDvqjjcglfNyvSkxM0CLJnXQoYhk/I39EzoQIfF3K48kncMy4td4jgSk/SLES4HY 8kXZJzuIRlc1g/M/4hiVaD2WT2Vv42Syba/mGIFaLWQkUTk+7/77TEk9jWP9stOzF6DM kGvtznCMhvwdYARhABYxCN8nGrU5EcO2lHVCturPcwkK9O1JzFDoXOx0DOoIzY1U2UoI YKmQ== X-Gm-Message-State: ALoCoQmOrZeyYQr9LU28rZOFtZUusL77eCfnIMH7yEKGfhJfbLgUfC076yFbSgN3mvQJxvdMm0vhdYNwQsW8+IW1agw0QMSESg== X-Received: by 10.25.21.208 with SMTP id 77mr35940616lfv.96.1452521792456; Mon, 11 Jan 2016 06:16:32 -0800 (PST) Received: from localhost.localdomain (91-157-175-207.elisa-laajakaista.fi. [91.157.175.207]) by smtp.gmail.com with ESMTPSA id 130sm16806735lff.31.2016.01.11.06.16.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Jan 2016 06:16:31 -0800 (PST) From: riku.voipio@linaro.org To: qemu-devel@nongnu.org Date: Mon, 11 Jan 2016 16:16:10 +0200 Message-Id: <0cf227229bfd288a67fd9d4005ee01ffdb492c70.1452521686.git.riku.voipio@linaro.org> X-Mailer: git-send-email 2.6.4 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:4010:c07::231 Cc: Laurent Vivier Subject: [Qemu-devel] [PULL 08/17] linux-user: manage bind with a socket of SOCK_PACKET type. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laurent Vivier This is obsolete, but if we want to use dhcp with an old distro (like debian etch), we need it. Some users (like dhclient) use SOCK_PACKET with AF_PACKET and the kernel allows that. packet(7) In Linux 2.0, the only way to get a packet socket was by calling socket(AF_INET, SOCK_PACKET, protocol). This is still supported but strongly deprecated. The main difference between the two methods is that SOCK_PACKET uses the old struct sockaddr_pkt to specify an inter‐ face, which doesn't provide physical layer independence. struct sockaddr_pkt { unsigned short spkt_family; unsigned char spkt_device[14]; unsigned short spkt_protocol; }; spkt_family contains the device type, spkt_protocol is the IEEE 802.3 protocol type as defined in and spkt_device is the device name as a null-terminated string, for example, eth0. Signed-off-by: Laurent Vivier Signed-off-by: Riku Voipio --- linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3484132..94d64fa 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2090,6 +2090,30 @@ static int sock_flags_fixup(int fd, int target_type) return fd; } +static abi_long packet_target_to_host_sockaddr(void *host_addr, + abi_ulong target_addr, + socklen_t len) +{ + struct sockaddr *addr = host_addr; + struct target_sockaddr *target_saddr; + + target_saddr = lock_user(VERIFY_READ, target_addr, len, 1); + if (!target_saddr) { + return -TARGET_EFAULT; + } + + memcpy(addr, target_saddr, len); + addr->sa_family = tswap16(target_saddr->sa_family); + /* spkt_protocol is big-endian */ + + unlock_user(target_saddr, target_addr, 0); + return 0; +} + +static TargetFdTrans target_packet_trans = { + .target_to_host_addr = packet_target_to_host_sockaddr, +}; + /* do_socket() Must return target values and target errnos. */ static abi_long do_socket(int domain, int type, int protocol) { @@ -2112,6 +2136,12 @@ static abi_long do_socket(int domain, int type, int protocol) ret = get_errno(socket(domain, type, protocol)); if (ret >= 0) { ret = sock_flags_fixup(ret, target_type); + if (type == SOCK_PACKET) { + /* Manage an obsolete case : + * if socket type is SOCK_PACKET, bind by name + */ + fd_trans_register(ret, &target_packet_trans); + } } return ret; }