From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52418) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrW9w-00048z-BP for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZrW9s-0005nc-Lq for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:20 -0400 Received: from smtp4-g21.free.fr ([2a01:e0c:1:1599::13]:32231) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZrW9s-0005nI-Gr for qemu-devel@nongnu.org; Wed, 28 Oct 2015 15:13:16 -0400 From: Laurent Vivier Date: Wed, 28 Oct 2015 20:13:03 +0100 Message-Id: <1446059583-16340-5-git-send-email-laurent@vivier.eu> In-Reply-To: <1446059583-16340-1-git-send-email-laurent@vivier.eu> References: <1446059583-16340-1-git-send-email-laurent@vivier.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v2 4/4] linux-user: manage bind with a socket of SOCK_PACKET type. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, riku.voipio@iki.fi, Laurent Vivier This is obsolete, but if we want to use dhcp with an old distro (like deb= ian etch), we need it. Some users (like dhclient) use SOCK_PACKET with AF_PAC= KET 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=E2= =80=90 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 --- linux-user/syscall.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 31b5c2c..f048437 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -2086,6 +2086,30 @@ static int sock_flags_fixup(int fd, int target_typ= e) return fd; } =20 +static abi_long packet_target_to_host_addr(void *host_addr, + abi_ulong target_addr, + socklen_t len) +{ + struct sockaddr *addr =3D host_addr; + struct target_sockaddr *target_saddr; + + target_saddr =3D lock_user(VERIFY_READ, target_addr, len, 1); + if (!target_saddr) { + return -TARGET_EFAULT; + } + + memcpy(addr, target_saddr, len); + addr->sa_family =3D tswap16(target_saddr->sa_family); + /* spkt_protocol is big-endian */ + + unlock_user(target_saddr, target_addr, 0); + return 0; +} + +static TargetFdTrans target_packet_trans =3D { + .target_to_host_addr =3D packet_target_to_host_addr, +}; + /* do_socket() Must return target values and target errnos. */ static abi_long do_socket(int domain, int type, int protocol) { @@ -2108,6 +2132,12 @@ static abi_long do_socket(int domain, int type, in= t protocol) ret =3D get_errno(socket(domain, type, protocol)); if (ret >=3D 0) { ret =3D sock_flags_fixup(ret, target_type); + if (type =3D=3D SOCK_PACKET) { + /* Manage an obsolete case : + * if socket type is SOCK_PACKET, bind by name + */ + fd_trans_register(ret, &target_packet_trans); + } } return ret; } --=20 2.4.3