From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Thomas Huth <thuth@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>,
Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: Re: [Qemu-devel] [PATCH RFC 4/5] net/dump: Provide the dumping facility as a net filter
Date: Thu, 27 Aug 2015 11:03:07 +0800 [thread overview]
Message-ID: <55DE7DEB.9040203@cn.fujitsu.com> (raw)
In-Reply-To: <1440642804-29001-5-git-send-email-thuth@redhat.com>
On 08/27/2015 10:33 AM, Thomas Huth wrote:
> Add glue code to use the dumping functions as a netdev
> filter, too.
Overall looks good to me, thanks.
Note that the QAPI part might change later, so there might be some rebase
work later, thanks again!
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> net/dump.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> net/filter.c | 1 +
> net/filters.h | 2 ++
> qapi-schema.json | 20 +++++++++++++++++++-
> 4 files changed, 76 insertions(+), 1 deletion(-)
>
> diff --git a/net/dump.c b/net/dump.c
> index 8317102..b09d2b9 100644
> --- a/net/dump.c
> +++ b/net/dump.c
> @@ -28,7 +28,9 @@
> #include "qemu/iov.h"
> #include "qemu/log.h"
> #include "qemu/timer.h"
> +#include "net/filter.h"
> #include "hub.h"
> +#include "filters.h"
>
> typedef struct DumpState {
> int64_t start_ts;
> @@ -224,3 +226,55 @@ int net_init_dump(const NetClientOptions *opts, const char *name,
> }
> return rc;
> }
> +
> +/* Dumping via filter */
> +
> +typedef struct NetFilterDumpState {
> + NetFilterState nf;
> + DumpState ds;
> +} NetFilterDumpState;
> +
> +static ssize_t filter_dump_receive_iov(NetFilterState *nf, NetClientState *sndr,
> + unsigned flags,
> + const struct iovec *iov, int iovcnt,
> + NetPacketSent *sent_cb)
> +{
> + NetFilterDumpState *nfds = DO_UPCAST(NetFilterDumpState, nf, nf);
> +
> + dump_receive_iov(&nfds->ds, iov, iovcnt);
> + return 0;
> +}
> +
> +static void filter_dump_cleanup(NetFilterState *nf)
> +{
> + NetFilterDumpState *nfds = DO_UPCAST(NetFilterDumpState, nf, nf);
> +
> + dump_cleanup(&nfds->ds);
> +}
> +
> +static NetFilterInfo net_filter_dump_info = {
> + .type = NET_FILTER_OPTIONS_KIND_DUMP,
> + .size = sizeof(NetFilterDumpState),
> + .receive_iov = filter_dump_receive_iov,
> + .cleanup = filter_dump_cleanup,
> +};
> +
> +int net_init_filter_dump(const NetFilterOptions *opts, const char *name,
> + int chain, NetClientState *netdev, Error **errp)
> +{
> + NetFilterState *nf;
> + NetFilterDumpState *nfds;
> + const NetFilterDumpOptions *dumpopt;
> + int dump_len = 65536;
> +
> + assert(opts->kind == NET_FILTER_OPTIONS_KIND_DUMP);
> + dumpopt = opts->dump;
> + if (dumpopt->has_maxlen) {
> + dump_len = dumpopt->maxlen;
> + }
> +
> + nf = qemu_new_net_filter(&net_filter_dump_info, netdev, name, chain);
> + nfds = DO_UPCAST(NetFilterDumpState, nf, nf);
> +
> + return net_dump_state_init(&nfds->ds, dumpopt->file, dump_len, errp);
> +}
> diff --git a/net/filter.c b/net/filter.c
> index f23fc7f..536d236 100644
> --- a/net/filter.c
> +++ b/net/filter.c
> @@ -216,6 +216,7 @@ typedef int (NetFilterInit)(const NetFilterOptions *opts,
> static
> NetFilterInit * const net_filter_init_fun[NET_FILTER_OPTIONS_KIND_MAX] = {
> [NET_FILTER_OPTIONS_KIND_BUFFER] = net_init_filter_buffer,
> + [NET_FILTER_OPTIONS_KIND_DUMP] = net_init_filter_dump,
> };
>
> static int net_filter_init1(const NetFilter *netfilter, Error **errp)
> diff --git a/net/filters.h b/net/filters.h
> index 3b546db..f63bde1 100644
> --- a/net/filters.h
> +++ b/net/filters.h
> @@ -13,5 +13,7 @@
>
> int net_init_filter_buffer(const NetFilterOptions *opts, const char *name,
> int chain, NetClientState *netdev, Error **errp);
> +int net_init_filter_dump(const NetFilterOptions *opts, const char *name,
> + int chain, NetClientState *netdev, Error **errp);
wrong alignment.
>
> #endif /* QEMU_NET_FILTERS_H */
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 7882641..71caca9 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2599,6 +2599,23 @@
> '*interval': 'uint32' } }
>
> ##
> +# @NetFilterDumpOptions
> +#
> +# a dumping filter for network backends.
> +#
> +# @file: Name of the file where the dump data should be written into.
> +#
> +# @maxlen: Crop big packets to this size before writing them into the
> +# dump file.
> +#
> +# Since 2.5
> +##
> +{ 'struct': 'NetFilterDumpOptions',
> + 'data': {
> + 'file': 'str',
> + '*maxlen': 'int32' } }
> +
> +##
> # @NetFilterOptions
> #
> # A discriminated record of network filters.
> @@ -2608,7 +2625,8 @@
> ##
> { 'union': 'NetFilterOptions',
> 'data': {
> - 'buffer': 'NetFilterBufferOptions'} }
> + 'buffer': 'NetFilterBufferOptions',
> + 'dump': 'NetFilterDumpOptions' } }
>
> ##
> # @NetFilter
>
--
Thanks,
Yang.
next prev parent reply other threads:[~2015-08-27 3:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 2:33 [Qemu-devel] [PATCH RFC 0/5] Network traffic dumping via netfilter Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 1/5] net/dump: Add support for receive_iov function Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 2/5] net/dump: Rework net-dump init functions Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 3/5] net/dump: Separate the NetClientState from the DumpState Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 4/5] net/dump: Provide the dumping facility as a net filter Thomas Huth
2015-08-27 3:03 ` Yang Hongyang [this message]
2015-09-01 19:52 ` Eric Blake
2015-09-01 21:19 ` Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 5/5] net/dump: Add documentation Thomas Huth
2015-08-27 3:29 ` [Qemu-devel] [PATCH RFC 0/5] Network traffic dumping via netfilter Jason Wang
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=55DE7DEB.9040203@cn.fujitsu.com \
--to=yanghy@cn.fujitsu.com \
--cc=armbru@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.com \
/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.