diff options
Diffstat (limited to 'net/dump.c')
| -rw-r--r-- | net/dump.c | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/net/dump.c b/net/dump.c index f835c51187..004231d481 100644 --- a/net/dump.c +++ b/net/dump.c @@ -27,9 +27,10 @@ #include "qemu-error.h" #include "qemu-log.h" #include "qemu-timer.h" +#include "hub.h" typedef struct DumpState { - VLANClientState nc; + NetClientState nc; int64_t start_ts; int fd; int pcap_caplen; @@ -56,7 +57,7 @@ struct pcap_sf_pkthdr { uint32_t len; }; -static ssize_t dump_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t dump_receive(NetClientState *nc, const uint8_t *buf, size_t size) { DumpState *s = DO_UPCAST(DumpState, nc, nc); struct pcap_sf_pkthdr hdr; @@ -85,7 +86,7 @@ static ssize_t dump_receive(VLANClientState *nc, const uint8_t *buf, size_t size return size; } -static void dump_cleanup(VLANClientState *nc) +static void dump_cleanup(NetClientState *nc) { DumpState *s = DO_UPCAST(DumpState, nc, nc); @@ -93,17 +94,17 @@ static void dump_cleanup(VLANClientState *nc) } static NetClientInfo net_dump_info = { - .type = NET_CLIENT_TYPE_DUMP, + .type = NET_CLIENT_OPTIONS_KIND_DUMP, .size = sizeof(DumpState), .receive = dump_receive, .cleanup = dump_cleanup, }; -static int net_dump_init(VLANState *vlan, const char *device, +static int net_dump_init(NetClientState *peer, const char *device, const char *name, const char *filename, int len) { struct pcap_file_hdr hdr; - VLANClientState *nc; + NetClientState *nc; DumpState *s; struct tm tm; int fd; @@ -128,7 +129,7 @@ static int net_dump_init(VLANState *vlan, const char *device, return -1; } - nc = qemu_new_net_client(&net_dump_info, vlan, NULL, device, name); + nc = qemu_new_net_client(&net_dump_info, peer, device, name); snprintf(nc->info_str, sizeof(nc->info_str), "dump to %s (len=%d)", filename, len); @@ -144,21 +145,41 @@ static int net_dump_init(VLANState *vlan, const char *device, return 0; } -int net_init_dump(QemuOpts *opts, const char *name, VLANState *vlan) +int net_init_dump(const NetClientOptions *opts, const char *name, + NetClientState *peer) { int len; const char *file; char def_file[128]; + const NetdevDumpOptions *dump; - assert(vlan); + assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); + dump = opts->dump; - file = qemu_opt_get(opts, "file"); - if (!file) { - snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", vlan->id); + assert(peer); + + if (dump->has_file) { + file = dump->file; + } else { + int id; + int ret; + + ret = net_hub_id_for_client(peer, &id); + assert(ret == 0); /* peer must be on a hub */ + + snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", id); file = def_file; } - len = qemu_opt_get_size(opts, "len", 65536); + if (dump->has_len) { + if (dump->len > INT_MAX) { + error_report("invalid length: %"PRIu64, dump->len); + return -1; + } + len = dump->len; + } else { + len = 65536; + } - return net_dump_init(vlan, "dump", name, file, len); + return net_dump_init(peer, "dump", name, file, len); } |