From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:34838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tq5cv-0006nh-Ql for qemu-devel@nongnu.org; Tue, 01 Jan 2013 12:27:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tq5cu-0000R1-Hd for qemu-devel@nongnu.org; Tue, 01 Jan 2013 12:27:45 -0500 Received: from moutng.kundenserver.de ([212.227.17.9]:50552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tq5cu-0000Qx-8D for qemu-devel@nongnu.org; Tue, 01 Jan 2013 12:27:44 -0500 Message-ID: <1357061254.3025.9.camel@Quad> From: Laurent Vivier Date: Tue, 01 Jan 2013 18:27:34 +0100 In-Reply-To: References: <1356982680-12436-1-git-send-email-laurent@vivier.eu> <1356982680-12436-3-git-send-email-laurent@vivier.eu> <1356992395.3199.25.camel@Quad> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Riku Voipio , qemu-devel@nongnu.org Le mardi 01 janvier 2013 =C3=A0 15:03 +0000, Peter Maydell a =C3=A9crit : > On 31 December 2012 22:19, Laurent Vivier wrote: > > Le lundi 31 d=C3=A9cembre 2012 =C3=A0 21:32 +0000, Peter Maydell a =C3= =A9crit : > >> Also it seems rather involved since we swap things three times and > >> have an entirely new abi_* function. Either I'm completely confused > >> or it should be enough to just have > >> > >> if (type =3D=3D SOCK_PACKET) { > >> protocol =3D tswap16(protocol); > >> } >=20 > Looking more carefully at packet(7) this is actually the wrong > guard anyway. You need to check for > (domain =3D=3D AF_PACKET) || (type =3D=3D SOCK_PACKET) I agree. > since SOCK_PACKET is the obsolete Linux 2.0 way of doing packet sockets. But dhclient is always using this... > > works... sometime. In fact, work if target endianess is network endiane= ss. > > > > Correct me if I'm wrong. > > > > target host > > little endian / big endian > > > > memory 00 00 00 03 >=20 > Syscall arguments aren't generally passed in memory, they're > in registers (and if they were pased in memory for some architecture > then that arch would do a load-and-swap-from-memory in main.c). > So the value you see in do_socket() is always "the integer passed > as a syscall parameter, as a host-order integer". Yes, I missed that. > So in this case, with a simple guest program: > #include > #include > #include > #include >=20 > int main(void) { > return socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); > } >=20 > you will find that do_socket() in QEMU is passed either 0x3 [if the > guest is bigendian and the guest htons() is a no-op] or 0x0300 > [if the guest is littleendian]. Since what we want to pass to the > host socket() call is 0x3 if the host is bigendian and 0x0300 if > the host is little endian, this amounts to needing to do a 16 bit > byteswap if the host and guest are different endianness, which > is exactly what tswap16() does. I checked with i386-to-i386 > that do_socket() gets passed 0x300 and we correctly send it > through to the host socket(). Yes, I agree. I correct the patch. Thank you, Laurent --=20 "Just play. Have fun. Enjoy the game." - Michael Jordan