qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Yang Hongyang <yanghy@cn.fujitsu.com>
To: Thomas Huth <thuth@redhat.com>,
	qemu-devel@nongnu.org, jasowang@redhat.com
Cc: armbru@redhat.com, stefanha@redhat.com, mst@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2 4/5] net/dump: Provide the dumping facility as a net-filter
Date: Wed, 14 Oct 2015 10:42:36 +0800	[thread overview]
Message-ID: <561DC11C.2000906@cn.fujitsu.com> (raw)
In-Reply-To: <1444732802-14732-5-git-send-email-thuth@redhat.com>



On 10/13/2015 06:40 PM, Thomas Huth wrote:
> Use the net-filter infrastructure to provide the dumping
> functions for netdev devices, too.
>
> Signed-off-by: Thomas Huth <thuth@redhat.com>

Reviewed-by: Yang Hongyang <yanghy@cn.fujitsu.com>


> ---
>   net/dump.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
>   vl.c       |   7 +++-
>   2 files changed, 134 insertions(+), 2 deletions(-)
>
> diff --git a/net/dump.c b/net/dump.c
> index e3e82bd..dd0555f 100644
> --- a/net/dump.c
> +++ b/net/dump.c
> @@ -28,7 +28,8 @@
>   #include "qemu/iov.h"
>   #include "qemu/log.h"
>   #include "qemu/timer.h"
> -#include "hub.h"
> +#include "qapi/visitor.h"
> +#include "net/filter.h"
>
>   typedef struct DumpState {
>       int64_t start_ts;
> @@ -225,3 +226,129 @@ int net_init_dump(const NetClientOptions *opts, const char *name,
>       }
>       return rc;
>   }
> +
> +/* Dumping via filter */
> +
> +#define TYPE_FILTER_DUMP "filter-dump"
> +
> +#define FILTER_DUMP(obj) \
> +    OBJECT_CHECK(NetFilterDumpState, (obj), TYPE_FILTER_DUMP)
> +
> +struct NetFilterDumpState {
> +    NetFilterState nfs;
> +    DumpState ds;
> +    char *filename;
> +    uint32_t maxlen;
> +};
> +typedef struct NetFilterDumpState 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 = FILTER_DUMP(nf);
> +
> +    dump_receive_iov(&nfds->ds, iov, iovcnt);
> +    return 0;
> +}
> +
> +static void filter_dump_cleanup(NetFilterState *nf)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(nf);
> +
> +    dump_cleanup(&nfds->ds);
> +}
> +
> +static void filter_dump_setup(NetFilterState *nf, Error **errp)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(nf);
> +
> +    if (!nfds->filename) {
> +        error_setg(errp, "dump filter needs 'file' property set!");
> +        return;
> +    }
> +
> +    net_dump_state_init(&nfds->ds, nfds->filename, nfds->maxlen, errp);
> +}
> +
> +static void filter_dump_get_maxlen(Object *obj, Visitor *v, void *opaque,
> +                                   const char *name, Error **errp)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(obj);
> +    uint32_t value = nfds->maxlen;
> +
> +    visit_type_uint32(v, &value, name, errp);
> +}
> +
> +static void filter_dump_set_maxlen(Object *obj, Visitor *v, void *opaque,
> +                                   const char *name, Error **errp)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(obj);
> +    Error *local_err = NULL;
> +    uint32_t value;
> +
> +    visit_type_uint32(v, &value, name, &local_err);
> +    if (local_err) {
> +        goto out;
> +    }
> +    if (value == 0) {
> +        error_setg(&local_err, "Property '%s.%s' doesn't take value '%u'",
> +                   object_get_typename(obj), name, value);
> +        goto out;
> +    }
> +    nfds->maxlen = value;
> +
> +out:
> +    error_propagate(errp, local_err);
> +}
> +
> +static char *file_dump_get_filename(Object *obj, Error **errp)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(obj);
> +
> +    return g_strdup(nfds->filename);
> +}
> +
> +static void file_dump_set_filename(Object *obj, const char *value, Error **errp)
> +{
> +   NetFilterDumpState *nfds = FILTER_DUMP(obj);
> +
> +    g_free(nfds->filename);
> +    nfds->filename = g_strdup(value);
> +}
> +
> +static void filter_dump_instance_init(Object *obj)
> +{
> +    NetFilterDumpState *nfds = FILTER_DUMP(obj);
> +
> +    nfds->maxlen = 65536;
> +
> +    object_property_add(obj, "maxlen", "int", filter_dump_get_maxlen,
> +                        filter_dump_set_maxlen, NULL, NULL, NULL);
> +    object_property_add_str(obj, "file", file_dump_get_filename,
> +                            file_dump_set_filename, NULL);
> +}
> +
> +static void filter_dump_class_init(ObjectClass *oc, void *data)
> +{
> +    NetFilterClass *nfc = NETFILTER_CLASS(oc);
> +
> +    nfc->setup = filter_dump_setup;
> +    nfc->cleanup = filter_dump_cleanup;
> +    nfc->receive_iov = filter_dump_receive_iov;
> +}
> +
> +static const TypeInfo filter_dump_info = {
> +    .name = TYPE_FILTER_DUMP,
> +    .parent = TYPE_NETFILTER,
> +    .class_init = filter_dump_class_init,
> +    .instance_init = filter_dump_instance_init,
> +    .instance_size = sizeof(NetFilterDumpState),
> +};
> +
> +static void filter_dump_register_types(void)
> +{
> +    type_register_static(&filter_dump_info);
> +}
> +
> +type_init(filter_dump_register_types);
> diff --git a/vl.c b/vl.c
> index 7c806a2..b54a800 100644
> --- a/vl.c
> +++ b/vl.c
> @@ -2748,7 +2748,12 @@ static bool object_create_initial(const char *type)
>           return false;
>       }
>
> -    if (g_str_equal(type, "filter-buffer")) {
> +    /*
> +     * return false for concrete netfilters since
> +     * they depend on netdevs already existing
> +     */
> +    if (g_str_equal(type, "filter-buffer") ||
> +        g_str_equal(type, "filter-dump")) {
>           return false;
>       }
>
>

-- 
Thanks,
Yang.

  reply	other threads:[~2015-10-14  2:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-13 10:39 [Qemu-devel] [PATCH v2 0/5] Network traffic dumping via netfilter Thomas Huth
2015-10-13 10:39 ` [Qemu-devel] [PATCH v2 1/5] net/dump: Add support for receive_iov function Thomas Huth
2015-10-14  2:13   ` Yang Hongyang
2015-10-13 10:39 ` [Qemu-devel] [PATCH v2 2/5] net/dump: Rework net-dump init functions Thomas Huth
2015-10-14  2:17   ` Yang Hongyang
2015-10-13 10:40 ` [Qemu-devel] [PATCH v2 3/5] net/dump: Separate the NetClientState from the DumpState Thomas Huth
2015-10-14  2:23   ` Yang Hongyang
2015-10-13 10:40 ` [Qemu-devel] [PATCH v2 4/5] net/dump: Provide the dumping facility as a net-filter Thomas Huth
2015-10-14  2:42   ` Yang Hongyang [this message]
2015-10-13 10:40 ` [Qemu-devel] [PATCH v2 5/5] options: Add documentation for filter-dump Thomas Huth
2015-10-20  4:35 ` [Qemu-devel] [PATCH v2 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=561DC11C.2000906@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 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).