@@ -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 {
@@ -29,13 +29,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 {
@@ -60,7 +53,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, i;
@@ -119,14 +112,14 @@ ssize_t net_dump_receive(NetClientState *nc, const uint8_t *buf, size_t size)
static 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,
@@ -138,7 +131,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;
@@ -167,7 +160,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;
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 <thuth@redhat.com> --- include/net/net.h | 7 +++++++ net/dump.c | 17 +++++------------ 2 files changed, 12 insertions(+), 12 deletions(-)