From patchwork Mon Jul 13 07:39: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: 494254 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 4398C1402B9 for ; Mon, 13 Jul 2015 17:42:11 +1000 (AEST) Received: from localhost ([::1]:53352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEYNN-0006rB-6z for incoming@patchwork.ozlabs.org; Mon, 13 Jul 2015 03:42:09 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35030) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEYKt-0003Tt-BQ for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZEYKr-0003yh-Bp for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57051) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZEYKr-0003yG-6B for qemu-devel@nongnu.org; Mon, 13 Jul 2015 03:39:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (Postfix) with ESMTPS id CC3842620 for ; Mon, 13 Jul 2015 07:39:32 +0000 (UTC) Received: from thh440s.redhat.com (vpn1-4-235.ams2.redhat.com [10.36.4.235]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6D7dQ8B007406; Mon, 13 Jul 2015 03:39:31 -0400 From: Thomas Huth To: qemu-devel@nongnu.org, Stefan Hajnoczi , Jason Wang Date: Mon, 13 Jul 2015 09:39:23 +0200 Message-Id: <1436773166-12113-3-git-send-email-thuth@redhat.com> In-Reply-To: <1436773166-12113-1-git-send-email-thuth@redhat.com> References: <1436773166-12113-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Markus Armbruster Subject: [Qemu-devel] [PATCH v2 2/5] net/dump: Move DumpState into NetClientState 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 We want to provide (almost) every netdev device with the ability to dump network traffic, so let's embed the DumpState into the NetClientState structure. Signed-off-by: Thomas Huth --- include/net/net.h | 7 +++++++ net/dump.c | 17 +++++------------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/include/net/net.h b/include/net/net.h index 6a6cbef..b265047 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -58,6 +58,12 @@ typedef void (SetVnetHdrLen)(NetClientState *, int); typedef int (SetVnetLE)(NetClientState *, bool); typedef int (SetVnetBE)(NetClientState *, bool); +typedef struct NetDumpState { + int64_t start_ts; + int fd; + int pcap_caplen; +} NetDumpState; + typedef struct NetClientInfo { NetClientOptionsKind type; size_t size; @@ -92,6 +98,7 @@ struct NetClientState { NetClientDestructor *destructor; unsigned int queue_index; unsigned rxfilter_notify_enabled:1; + NetDumpState nds; }; typedef struct NICState { diff --git a/net/dump.c b/net/dump.c index 935918e..a430b96 100644 --- a/net/dump.c +++ b/net/dump.c @@ -30,13 +30,6 @@ #include "qemu/timer.h" #include "hub.h" -typedef struct DumpState { - NetClientState nc; - int64_t start_ts; - int fd; - int pcap_caplen; -} DumpState; - #define PCAP_MAGIC 0xa1b2c3d4 struct pcap_file_hdr { @@ -61,7 +54,7 @@ struct pcap_sf_pkthdr { ssize_t net_dump_receive_iov(NetClientState *nc, const struct iovec *iov, int cnt) { - DumpState *s = DO_UPCAST(DumpState, nc, nc); + NetDumpState *s = &nc->nds; struct pcap_sf_pkthdr hdr; int64_t ts; int caplen; @@ -105,14 +98,14 @@ ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) void net_dump_cleanup(NetClientState *nc) { - DumpState *s = DO_UPCAST(DumpState, nc, nc); + NetDumpState *s = &nc->nds; close(s->fd); } static NetClientInfo net_dump_info = { .type = NET_CLIENT_OPTIONS_KIND_DUMP, - .size = sizeof(DumpState), + .size = sizeof(NetClientState), .receive = net_dump_receive, .receive_iov = net_dump_receive_iov, .cleanup = net_dump_cleanup, @@ -124,7 +117,7 @@ static int net_dump_init(NetClientState *peer, const char *device, { struct pcap_file_hdr hdr; NetClientState *nc; - DumpState *s; + NetDumpState *s; struct tm tm; int fd; @@ -153,7 +146,7 @@ static int net_dump_init(NetClientState *peer, const char *device, snprintf(nc->info_str, sizeof(nc->info_str), "dump to %s (len=%d)", filename, len); - s = DO_UPCAST(DumpState, nc, nc); + s = &nc->nds; s->fd = fd; s->pcap_caplen = len;