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 <th...@redhat.com> --- 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; -- 1.8.3.1