From patchwork Thu Aug 27 02:33:23 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 511155 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 314A2140216 for ; Thu, 27 Aug 2015 12:34:25 +1000 (AEST) Received: from localhost ([::1]:50355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn1C-0002UN-VK for incoming@patchwork.ozlabs.org; Wed, 26 Aug 2015 22:34:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45379) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn0U-0001F0-5Z for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZUn0T-0003ly-2U for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42680) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZUn0S-0003lu-RZ for qemu-devel@nongnu.org; Wed, 26 Aug 2015 22:33:37 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 918D6341AC5; Thu, 27 Aug 2015 02:33:36 +0000 (UTC) Received: from thh440s.redhat.com (vpn1-7-173.ams2.redhat.com [10.36.7.173]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t7R2XPWC008792; Wed, 26 Aug 2015 22:33:34 -0400 From: Thomas Huth To: Stefan Hajnoczi , Jason Wang , qemu-devel@nongnu.org, yanghy@cn.fujitsu.com Date: Thu, 27 Aug 2015 04:33:23 +0200 Message-Id: <1440642804-29001-5-git-send-email-thuth@redhat.com> In-Reply-To: <1440642804-29001-1-git-send-email-thuth@redhat.com> References: <1440642804-29001-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Markus Armbruster , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH RFC 4/5] net/dump: Provide the dumping facility as a net filter X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Add glue code to use the dumping functions as a netdev filter, too. Signed-off-by: Thomas Huth --- 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); #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