From: Anthony Liguori <aliguori@us.ibm.com>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [Patch] Add -net dump option
Date: Fri, 06 Feb 2009 12:53:22 -0600 [thread overview]
Message-ID: <498C8722.1050306@us.ibm.com> (raw)
In-Reply-To: <20090204102251.GA16599@ulanbator.act-europe.fr>
Tristan Gingold wrote:
> Hi,
>
> this patch add a new network pseudo nic that dump traffic to a tcpdump
> compatible file. I have found this feature useful to debug network protocols
> with the user stack.
>
> Signed-off-by: Tristan Gingold <gingold@adacore.com>
> Tristan.
>
>
> diff --git a/qemu-doc.texi b/qemu-doc.texi
> index b2fa19e..73c133a 100644
> --- a/qemu-doc.texi
> +++ b/qemu-doc.texi
> @@ -739,6 +739,15 @@ vde_switch -F -sock /tmp/myswitch
> qemu linux.img -net nic -net vde,sock=/tmp/myswitch
> @end example
>
> +@item -net dump[,vlan=@var{n}][,file=@var{file}][,len=@var{len}]
> +Dump network traffic on VLAN @var{n} to file @var{file} (@file{qemu.tcpdump} by
> +default). At most @var{len} bytes (64 by default) by packet are stored. The
> +dump can be analyzed with tools such as tcpdump.
> +
> +For better results you'd better to use this option before the @samp{-net user}
>
For better results, you should use this option before the @samp{-net user}
> +one as the user stack may send replies before the initial packet was propagated
>
I'd rather you fix this properly.
> +to all receivers.
> +
> @item -net none
> Indicate that no network devices should be configured. It is used to
> override the default configuration (@option{-net nic -net user}) which
>
> diff --git a/net.c b/net.c
> index 8d9b3de..872a17e 100644
> --- a/net.c
> +++ b/net.c
> @@ -1064,6 +1064,75 @@ static int net_vde_init(VLANState *vlan, const char *model,
> }
> #endif
>
> +static VLANClientState *tcpdump_vc;
> +static FILE *tcpdump_file;
> +static int tcpdump_caplen;
>
Instead of it being globals, you should have a proper state. That way
you can use this functionality with multiple VLANs.
> +#define TCPDUMP_MAGIC 0xa1b2c3d4
> +
> +struct pcap_file_hdr {
> + uint32_t magic;
> + uint16_t version_major;
> + uint16_t version_minor;
> + int32_t thiszone;
> + uint32_t sigfigs;
> + uint32_t snaplen;
> + uint32_t linktype;
> +};
> +
> +struct pcap_sf_pkthdr {
> + struct {
> + int32_t tv_sec;
> + int32_t tv_usec;
> + } ts;
> + uint32_t caplen;
> + uint32_t len;
> +};
> +
> +static void tcpdump_receive(void *opaque, const uint8_t *buf, int size)
> +{
> + struct pcap_sf_pkthdr hdr;
> + int64_t ts = muldiv64 (qemu_get_clock(vm_clock),1000000, ticks_per_sec);
> + int caplen = size > tcpdump_caplen ? tcpdump_caplen : size;
> +
> + hdr.ts.tv_sec = ts / 1000000000LL;
> + hdr.ts.tv_usec = ts % 1000000;
> + hdr.caplen = caplen;
> + hdr.len = size;
> + fwrite(&hdr, sizeof(hdr), 1, tcpdump_file);
> + fwrite(buf, caplen, 1, tcpdump_file);
>
You should have some error checking here. Are tcpdump files always
native endian?
Regards,
Anthony Liguori
next prev parent reply other threads:[~2009-02-06 18:53 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-02-04 10:22 [Qemu-devel] [Patch] Add -net dump option Tristan Gingold
2009-02-06 18:53 ` Anthony Liguori [this message]
2009-02-10 11:00 ` Tristan Gingold
2009-02-10 12:15 ` Jamie Lokier
2009-02-10 12:59 ` Tristan Gingold
2009-02-10 22:05 ` Jamie Lokier
2009-02-13 14:01 ` [Qemu-devel] Ping: [Patch] Add -net dump option (v2) Tristan Gingold
2009-02-23 15:30 ` [Qemu-devel] Ping*2: [Patch-v2] Add -net dump option Tristan Gingold
2009-02-27 19:09 ` [Qemu-devel] [Patch] " Anthony Liguori
2009-02-07 4:09 ` Luca Bigliardi
2009-02-10 11:01 ` Tristan Gingold
2009-02-10 17:04 ` [Qemu-devel] SET rezo-actu DIGEST GAYET Thierry
-- strict thread matches above, loose matches on Subject: below --
2009-03-05 10:10 [Qemu-devel] [Patch] Add -net dump option Tristan Gingold
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=498C8722.1050306@us.ibm.com \
--to=aliguori@us.ibm.com \
--cc=qemu-devel@nongnu.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.