From: Thomas Huth <thuth@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>,
Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org, yanghy@cn.fujitsu.com
Cc: Markus Armbruster <armbru@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>
Subject: [Qemu-devel] [PATCH RFC 3/5] net/dump: Separate the NetClientState from the DumpState
Date: Thu, 27 Aug 2015 04:33:22 +0200 [thread overview]
Message-ID: <1440642804-29001-4-git-send-email-thuth@redhat.com> (raw)
In-Reply-To: <1440642804-29001-1-git-send-email-thuth@redhat.com>
With the upcoming dumping-via-netfilter patch, the DumpState
should not be related to NetClientState anymore, so move the
related information to a new struct called DumpNetClient.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
net/dump.c | 73 +++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 48 insertions(+), 25 deletions(-)
diff --git a/net/dump.c b/net/dump.c
index 27083d4..8317102 100644
--- a/net/dump.c
+++ b/net/dump.c
@@ -31,7 +31,6 @@
#include "hub.h"
typedef struct DumpState {
- NetClientState nc;
int64_t start_ts;
int fd;
int pcap_caplen;
@@ -58,10 +57,8 @@ struct pcap_sf_pkthdr {
uint32_t len;
};
-static ssize_t dump_receive_iov(NetClientState *nc, const struct iovec *iov,
- int cnt)
+static ssize_t dump_receive_iov(DumpState *s, const struct iovec *iov, int cnt)
{
- DumpState *s = DO_UPCAST(DumpState, nc, nc);
struct pcap_sf_pkthdr hdr;
int64_t ts;
int caplen;
@@ -94,30 +91,12 @@ static ssize_t dump_receive_iov(NetClientState *nc, const struct iovec *iov,
return size;
}
-static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size)
+static void dump_cleanup(DumpState *s)
{
- struct iovec iov = {
- .iov_base = (void *)buf,
- .iov_len = size
- };
- return dump_receive_iov(nc, &iov, 1);
-}
-
-static void dump_cleanup(NetClientState *nc)
-{
- DumpState *s = DO_UPCAST(DumpState, nc, nc);
-
close(s->fd);
+ s->fd = -1;
}
-static NetClientInfo net_dump_info = {
- .type = NET_CLIENT_OPTIONS_KIND_DUMP,
- .size = sizeof(DumpState),
- .receive = dump_receive,
- .receive_iov = dump_receive_iov,
- .cleanup = dump_cleanup,
-};
-
static int net_dump_state_init(DumpState *s, const char *filename,
int len, Error **errp)
{
@@ -154,6 +133,48 @@ static int net_dump_state_init(DumpState *s, const char *filename,
return 0;
}
+/* Dumping via VLAN netclient */
+
+typedef struct DumpNetClient {
+ NetClientState nc;
+ DumpState ds;
+} DumpNetClient;
+
+static ssize_t dumpclient_receive(NetClientState *nc, const uint8_t *buf,
+ size_t size)
+{
+ DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc);
+ struct iovec iov = {
+ .iov_base = (void *)buf,
+ .iov_len = size
+ };
+
+ return dump_receive_iov(&dc->ds, &iov, 1);
+}
+
+static ssize_t dumpclient_receive_iov(NetClientState *nc,
+ const struct iovec *iov, int cnt)
+{
+ DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc);
+
+ return dump_receive_iov(&dc->ds, iov, cnt);
+}
+
+static void dumpclient_cleanup(NetClientState *nc)
+{
+ DumpNetClient *dc = DO_UPCAST(DumpNetClient, nc, nc);
+
+ dump_cleanup(&dc->ds);
+}
+
+static NetClientInfo net_dump_info = {
+ .type = NET_CLIENT_OPTIONS_KIND_DUMP,
+ .size = sizeof(DumpNetClient),
+ .receive = dumpclient_receive,
+ .receive_iov = dumpclient_receive_iov,
+ .cleanup = dumpclient_cleanup,
+};
+
int net_init_dump(const NetClientOptions *opts, const char *name,
NetClientState *peer, Error **errp)
{
@@ -162,6 +183,7 @@ int net_init_dump(const NetClientOptions *opts, const char *name,
char def_file[128];
const NetdevDumpOptions *dump;
NetClientState *nc;
+ DumpNetClient *dnc;
assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP);
dump = opts->dump;
@@ -195,7 +217,8 @@ int net_init_dump(const NetClientOptions *opts, const char *name,
snprintf(nc->info_str, sizeof(nc->info_str),
"dump to %s (len=%d)", file, len);
- rc = net_dump_state_init(DO_UPCAST(DumpState, nc, nc), file, len, errp);
+ dnc = DO_UPCAST(DumpNetClient, nc, nc);
+ rc = net_dump_state_init(&dnc->ds, file, len, errp);
if (rc) {
qemu_del_net_client(nc);
}
--
1.8.3.1
next prev parent reply other threads:[~2015-08-27 2:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 2:33 [Qemu-devel] [PATCH RFC 0/5] Network traffic dumping via netfilter Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 1/5] net/dump: Add support for receive_iov function Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 2/5] net/dump: Rework net-dump init functions Thomas Huth
2015-08-27 2:33 ` Thomas Huth [this message]
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 4/5] net/dump: Provide the dumping facility as a net filter Thomas Huth
2015-08-27 3:03 ` Yang Hongyang
2015-09-01 19:52 ` Eric Blake
2015-09-01 21:19 ` Thomas Huth
2015-08-27 2:33 ` [Qemu-devel] [PATCH RFC 5/5] net/dump: Add documentation Thomas Huth
2015-08-27 3:29 ` [Qemu-devel] [PATCH RFC 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=1440642804-29001-4-git-send-email-thuth@redhat.com \
--to=thuth@redhat.com \
--cc=armbru@redhat.com \
--cc=jasowang@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=yanghy@cn.fujitsu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.