From: Laurent Vivier <Laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Riku Voipio <riku.voipio@iki.fi>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
Date: Tue, 01 Jan 2013 18:27:34 +0100 [thread overview]
Message-ID: <1357061254.3025.9.camel@Quad> (raw)
In-Reply-To: <CAFEAcA8L0n6oWOFWhF-0DEWADqsOz=4uJGxditAUAB+rL=6imQ@mail.gmail.com>
Le mardi 01 janvier 2013 à 15:03 +0000, Peter Maydell a écrit :
> On 31 December 2012 22:19, Laurent Vivier <Laurent@vivier.eu> wrote:
> > Le lundi 31 décembre 2012 à 21:32 +0000, Peter Maydell a écrit :
> >> 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 == SOCK_PACKET) {
> >> protocol = tswap16(protocol);
> >> }
>
> Looking more carefully at packet(7) this is actually the wrong
> guard anyway. You need to check for
> (domain == AF_PACKET) || (type == 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 endianess.
> >
> > Correct me if I'm wrong.
> >
> > target host
> > little endian / big endian
> >
> > memory 00 00 00 03
>
> 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 <sys/socket.h>
> #include <netpacket/packet.h>
> #include <net/ethernet.h>
> #include <arpa/inet.h>
>
> int main(void) {
> return socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
> }
>
> 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
--
"Just play. Have fun. Enjoy the game."
- Michael Jordan
next prev parent reply other threads:[~2013-01-01 17:27 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-31 19:37 [Qemu-devel] [PATCH 0/2] linux-user: dhclient support Laurent Vivier
2012-12-31 19:37 ` [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER) Laurent Vivier
2012-12-31 20:56 ` Peter Maydell
2012-12-31 19:38 ` [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2012-12-31 21:32 ` Peter Maydell
2012-12-31 22:19 ` Laurent Vivier
2013-01-01 15:03 ` Peter Maydell
2013-01-01 17:27 ` Laurent Vivier [this message]
2013-01-01 18:37 ` Laurent Vivier
2013-01-01 19:45 ` Peter Maydell
2013-01-01 22:12 ` Laurent Vivier
2013-01-01 22:50 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1357061254.3025.9.camel@Quad \
--to=laurent@vivier.eu \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=riku.voipio@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).