diff options
Diffstat (limited to 'net')
-rw-r--r-- | net/Makefile.objs | 2 | ||||
-rw-r--r-- | net/dump.c | 27 | ||||
-rw-r--r-- | net/dump.h | 2 | ||||
-rw-r--r-- | net/hub.c | 339 | ||||
-rw-r--r-- | net/hub.h | 29 | ||||
-rw-r--r-- | net/queue.c | 38 | ||||
-rw-r--r-- | net/queue.h | 25 | ||||
-rw-r--r-- | net/slirp.c | 34 | ||||
-rw-r--r-- | net/slirp.h | 2 | ||||
-rw-r--r-- | net/socket.c | 134 | ||||
-rw-r--r-- | net/socket.h | 2 | ||||
-rw-r--r-- | net/tap-win32.c | 26 | ||||
-rw-r--r-- | net/tap.c | 44 | ||||
-rw-r--r-- | net/tap.h | 20 | ||||
-rw-r--r-- | net/vde.c | 16 | ||||
-rw-r--r-- | net/vde.h | 2 |
16 files changed, 558 insertions, 184 deletions
diff --git a/net/Makefile.objs b/net/Makefile.objs index 72f50bc..cf04187 100644 --- a/net/Makefile.objs +++ b/net/Makefile.objs @@ -1,4 +1,4 @@ -common-obj-y = queue.o checksum.o util.o +common-obj-y = queue.o checksum.o util.o hub.o common-obj-y += socket.o common-obj-y += dump.o common-obj-$(CONFIG_POSIX) += tap.o @@ -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); @@ -99,11 +100,11 @@ static NetClientInfo net_dump_info = { .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); @@ -145,7 +146,7 @@ static int net_dump_init(VLANState *vlan, const char *device, } int net_init_dump(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { int len; const char *file; @@ -155,12 +156,18 @@ int net_init_dump(const NetClientOptions *opts, const char *name, assert(opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP); dump = opts->dump; - assert(vlan); + assert(peer); if (dump->has_file) { file = dump->file; } else { - snprintf(def_file, sizeof(def_file), "qemu-vlan%d.pcap", vlan->id); + 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; } @@ -174,5 +181,5 @@ int net_init_dump(const NetClientOptions *opts, const char *name, len = 65536; } - return net_dump_init(vlan, "dump", name, file, len); + return net_dump_init(peer, "dump", name, file, len); } @@ -28,6 +28,6 @@ #include "qapi-types.h" int net_init_dump(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); #endif /* QEMU_NET_DUMP_H */ diff --git a/net/hub.c b/net/hub.c new file mode 100644 index 0000000..ac157e3 --- /dev/null +++ b/net/hub.c @@ -0,0 +1,339 @@ +/* + * Hub net client + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> + * Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#include "monitor.h" +#include "net.h" +#include "hub.h" +#include "iov.h" + +/* + * A hub broadcasts incoming packets to all its ports except the source port. + * Hubs can be used to provide independent network segments, also confusingly + * named the QEMU 'vlan' feature. + */ + +typedef struct NetHub NetHub; + +typedef struct NetHubPort { + NetClientState nc; + QLIST_ENTRY(NetHubPort) next; + NetHub *hub; + int id; +} NetHubPort; + +struct NetHub { + int id; + QLIST_ENTRY(NetHub) next; + int num_ports; + QLIST_HEAD(, NetHubPort) ports; +}; + +static QLIST_HEAD(, NetHub) hubs = QLIST_HEAD_INITIALIZER(&hubs); + +static ssize_t net_hub_receive(NetHub *hub, NetHubPort *source_port, + const uint8_t *buf, size_t len) +{ + NetHubPort *port; + + QLIST_FOREACH(port, &hub->ports, next) { + if (port == source_port) { + continue; + } + + qemu_send_packet(&port->nc, buf, len); + } + return len; +} + +static ssize_t net_hub_receive_iov(NetHub *hub, NetHubPort *source_port, + const struct iovec *iov, int iovcnt) +{ + NetHubPort *port; + ssize_t len = iov_size(iov, iovcnt); + + QLIST_FOREACH(port, &hub->ports, next) { + if (port == source_port) { + continue; + } + + qemu_sendv_packet(&port->nc, iov, iovcnt); + } + return len; +} + +static NetHub *net_hub_new(int id) +{ + NetHub *hub; + + hub = g_malloc(sizeof(*hub)); + hub->id = id; + hub->num_ports = 0; + QLIST_INIT(&hub->ports); + + QLIST_INSERT_HEAD(&hubs, hub, next); + + return hub; +} + +static int net_hub_port_can_receive(NetClientState *nc) +{ + NetHubPort *port; + NetHubPort *src_port = DO_UPCAST(NetHubPort, nc, nc); + NetHub *hub = src_port->hub; + + QLIST_FOREACH(port, &hub->ports, next) { + if (port == src_port) { + continue; + } + + if (!qemu_can_send_packet(&port->nc)) { + return 0; + } + } + + return 1; +} + +static ssize_t net_hub_port_receive(NetClientState *nc, + const uint8_t *buf, size_t len) +{ + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc); + + return net_hub_receive(port->hub, port, buf, len); +} + +static ssize_t net_hub_port_receive_iov(NetClientState *nc, + const struct iovec *iov, int iovcnt) +{ + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc); + + return net_hub_receive_iov(port->hub, port, iov, iovcnt); +} + +static void net_hub_port_cleanup(NetClientState *nc) +{ + NetHubPort *port = DO_UPCAST(NetHubPort, nc, nc); + + QLIST_REMOVE(port, next); +} + +static NetClientInfo net_hub_port_info = { + .type = NET_CLIENT_OPTIONS_KIND_HUBPORT, + .size = sizeof(NetHubPort), + .can_receive = net_hub_port_can_receive, + .receive = net_hub_port_receive, + .receive_iov = net_hub_port_receive_iov, + .cleanup = net_hub_port_cleanup, +}; + +static NetHubPort *net_hub_port_new(NetHub *hub, const char *name) +{ + NetClientState *nc; + NetHubPort *port; + int id = hub->num_ports++; + char default_name[128]; + + if (!name) { + snprintf(default_name, sizeof(default_name), + "hub%dport%d", hub->id, id); + name = default_name; + } + + nc = qemu_new_net_client(&net_hub_port_info, NULL, "hub", name); + port = DO_UPCAST(NetHubPort, nc, nc); + port->id = id; + port->hub = hub; + + QLIST_INSERT_HEAD(&hub->ports, port, next); + + return port; +} + +/** + * Create a port on a given hub + * @name: Net client name or NULL for default name. + * + * If there is no existing hub with the given id then a new hub is created. + */ +NetClientState *net_hub_add_port(int hub_id, const char *name) +{ + NetHub *hub; + NetHubPort *port; + + QLIST_FOREACH(hub, &hubs, next) { + if (hub->id == hub_id) { + break; + } + } + + if (!hub) { + hub = net_hub_new(hub_id); + } + + port = net_hub_port_new(hub, name); + return &port->nc; +} + +/** + * Find a specific client on a hub + */ +NetClientState *net_hub_find_client_by_name(int hub_id, const char *name) +{ + NetHub *hub; + NetHubPort *port; + NetClientState *peer; + + QLIST_FOREACH(hub, &hubs, next) { + if (hub->id == hub_id) { + QLIST_FOREACH(port, &hub->ports, next) { + peer = port->nc.peer; + + if (peer && strcmp(peer->name, name) == 0) { + return peer; + } + } + } + } + return NULL; +} + +/** + * Find a available port on a hub; otherwise create one new port + */ +NetClientState *net_hub_port_find(int hub_id) +{ + NetHub *hub; + NetHubPort *port; + NetClientState *nc; + + QLIST_FOREACH(hub, &hubs, next) { + if (hub->id == hub_id) { + QLIST_FOREACH(port, &hub->ports, next) { + nc = port->nc.peer; + if (!nc) { + return &(port->nc); + } + } + break; + } + } + + nc = net_hub_add_port(hub_id, NULL); + return nc; +} + +/** + * Print hub configuration + */ +void net_hub_info(Monitor *mon) +{ + NetHub *hub; + NetHubPort *port; + + QLIST_FOREACH(hub, &hubs, next) { + monitor_printf(mon, "hub %d\n", hub->id); + QLIST_FOREACH(port, &hub->ports, next) { + if (port->nc.peer) { + monitor_printf(mon, " \\ "); + print_net_client(mon, port->nc.peer); + } + } + } +} + +/** + * Get the hub id that a client is connected to + * + * @id Pointer for hub id output, may be NULL + */ +int net_hub_id_for_client(NetClientState *nc, int *id) +{ + NetHubPort *port; + + if (nc->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) { + port = DO_UPCAST(NetHubPort, nc, nc); + } else if (nc->peer != NULL && nc->peer->info->type == + NET_CLIENT_OPTIONS_KIND_HUBPORT) { + port = DO_UPCAST(NetHubPort, nc, nc->peer); + } else { + return -ENOENT; + } + + if (id) { + *id = port->hub->id; + } + return 0; +} + +int net_init_hubport(const NetClientOptions *opts, const char *name, + NetClientState *peer) +{ + const NetdevHubPortOptions *hubport; + + assert(opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT); + hubport = opts->hubport; + + /* Treat hub port like a backend, NIC must be the one to peer */ + if (peer) { + return -EINVAL; + } + + net_hub_add_port(hubport->hubid, name); + return 0; +} + +/** + * Warn if hub configurations are likely wrong + */ +void net_hub_check_clients(void) +{ + NetHub *hub; + NetHubPort *port; + NetClientState *peer; + + QLIST_FOREACH(hub, &hubs, next) { + int has_nic = 0, has_host_dev = 0; + + QLIST_FOREACH(port, &hub->ports, next) { + peer = port->nc.peer; + if (!peer) { + fprintf(stderr, "Warning: hub port %s has no peer\n", + port->nc.name); + continue; + } + + switch (peer->info->type) { + case NET_CLIENT_OPTIONS_KIND_NIC: + has_nic = 1; + break; + case NET_CLIENT_OPTIONS_KIND_USER: + case NET_CLIENT_OPTIONS_KIND_TAP: + case NET_CLIENT_OPTIONS_KIND_SOCKET: + case NET_CLIENT_OPTIONS_KIND_VDE: + has_host_dev = 1; + break; + default: + break; + } + } + if (has_host_dev && !has_nic) { + fprintf(stderr, "Warning: vlan %d with no nics\n", hub->id); + } + if (has_nic && !has_host_dev) { + fprintf(stderr, + "Warning: vlan %d is not connected to host network\n", + hub->id); + } + } +} diff --git a/net/hub.h b/net/hub.h new file mode 100644 index 0000000..26a1ade --- /dev/null +++ b/net/hub.h @@ -0,0 +1,29 @@ +/* + * Hub net client + * + * Copyright IBM, Corp. 2012 + * + * Authors: + * Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> + * Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> + * + * This work is licensed under the terms of the GNU LGPL, version 2 or later. + * See the COPYING.LIB file in the top-level directory. + * + */ + +#ifndef NET_HUB_H +#define NET_HUB_H + +#include "qemu-common.h" + +int net_init_hubport(const NetClientOptions *opts, const char *name, + NetClientState *peer); +NetClientState *net_hub_add_port(int hub_id, const char *name); +NetClientState *net_hub_find_client_by_name(int hub_id, const char *name); +void net_hub_info(Monitor *mon); +int net_hub_id_for_client(NetClientState *nc, int *id); +void net_hub_check_clients(void); +NetClientState *net_hub_port_find(int hub_id); + +#endif /* NET_HUB_H */ diff --git a/net/queue.c b/net/queue.c index 1ab5247..e8030aa 100644 --- a/net/queue.c +++ b/net/queue.c @@ -23,6 +23,7 @@ #include "net/queue.h" #include "qemu-queue.h" +#include "net.h" /* The delivery handler may only return zero if it will call * qemu_net_queue_flush() when it determines that it is once again able @@ -40,7 +41,7 @@ struct NetPacket { QTAILQ_ENTRY(NetPacket) entry; - VLANClientState *sender; + NetClientState *sender; unsigned flags; int size; NetPacketSent *sent_cb; @@ -48,8 +49,6 @@ struct NetPacket { }; struct NetQueue { - NetPacketDeliver *deliver; - NetPacketDeliverIOV *deliver_iov; void *opaque; QTAILQ_HEAD(packets, NetPacket) packets; @@ -57,16 +56,12 @@ struct NetQueue { unsigned delivering : 1; }; -NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver, - NetPacketDeliverIOV *deliver_iov, - void *opaque) +NetQueue *qemu_new_net_queue(void *opaque) { NetQueue *queue; queue = g_malloc0(sizeof(NetQueue)); - queue->deliver = deliver; - queue->deliver_iov = deliver_iov; queue->opaque = opaque; QTAILQ_INIT(&queue->packets); @@ -89,7 +84,7 @@ void qemu_del_net_queue(NetQueue *queue) } static ssize_t qemu_net_queue_append(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const uint8_t *buf, size_t size, @@ -110,7 +105,7 @@ static ssize_t qemu_net_queue_append(NetQueue *queue, } static ssize_t qemu_net_queue_append_iov(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const struct iovec *iov, int iovcnt, @@ -143,7 +138,7 @@ static ssize_t qemu_net_queue_append_iov(NetQueue *queue, } static ssize_t qemu_net_queue_deliver(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const uint8_t *data, size_t size) @@ -151,14 +146,14 @@ static ssize_t qemu_net_queue_deliver(NetQueue *queue, ssize_t ret = -1; queue->delivering = 1; - ret = queue->deliver(sender, flags, data, size, queue->opaque); + ret = qemu_deliver_packet(sender, flags, data, size, queue->opaque); queue->delivering = 0; return ret; } static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const struct iovec *iov, int iovcnt) @@ -166,14 +161,14 @@ static ssize_t qemu_net_queue_deliver_iov(NetQueue *queue, ssize_t ret = -1; queue->delivering = 1; - ret = queue->deliver_iov(sender, flags, iov, iovcnt, queue->opaque); + ret = qemu_deliver_packet_iov(sender, flags, iov, iovcnt, queue->opaque); queue->delivering = 0; return ret; } ssize_t qemu_net_queue_send(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const uint8_t *data, size_t size, @@ -181,8 +176,8 @@ ssize_t qemu_net_queue_send(NetQueue *queue, { ssize_t ret; - if (queue->delivering) { - return qemu_net_queue_append(queue, sender, flags, data, size, NULL); + if (queue->delivering || !qemu_can_send_packet(sender)) { + return qemu_net_queue_append(queue, sender, flags, data, size, sent_cb); } ret = qemu_net_queue_deliver(queue, sender, flags, data, size); @@ -197,7 +192,7 @@ ssize_t qemu_net_queue_send(NetQueue *queue, } ssize_t qemu_net_queue_send_iov(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const struct iovec *iov, int iovcnt, @@ -205,8 +200,9 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue, { ssize_t ret; - if (queue->delivering) { - return qemu_net_queue_append_iov(queue, sender, flags, iov, iovcnt, NULL); + if (queue->delivering || !qemu_can_send_packet(sender)) { + return qemu_net_queue_append_iov(queue, sender, flags, + iov, iovcnt, sent_cb); } ret = qemu_net_queue_deliver_iov(queue, sender, flags, iov, iovcnt); @@ -220,7 +216,7 @@ ssize_t qemu_net_queue_send_iov(NetQueue *queue, return ret; } -void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from) +void qemu_net_queue_purge(NetQueue *queue, NetClientState *from) { NetPacket *packet, *next; diff --git a/net/queue.h b/net/queue.h index a31958e..9d44a9b 100644 --- a/net/queue.h +++ b/net/queue.h @@ -29,43 +29,30 @@ typedef struct NetPacket NetPacket; typedef struct NetQueue NetQueue; -typedef void (NetPacketSent) (VLANClientState *sender, ssize_t ret); - -typedef ssize_t (NetPacketDeliver) (VLANClientState *sender, - unsigned flags, - const uint8_t *buf, - size_t size, - void *opaque); - -typedef ssize_t (NetPacketDeliverIOV) (VLANClientState *sender, - unsigned flags, - const struct iovec *iov, - int iovcnt, - void *opaque); +typedef void (NetPacketSent) (NetClientState *sender, ssize_t ret); #define QEMU_NET_PACKET_FLAG_NONE 0 #define QEMU_NET_PACKET_FLAG_RAW (1<<0) -NetQueue *qemu_new_net_queue(NetPacketDeliver *deliver, - NetPacketDeliverIOV *deliver_iov, - void *opaque); +NetQueue *qemu_new_net_queue(void *opaque); + void qemu_del_net_queue(NetQueue *queue); ssize_t qemu_net_queue_send(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const uint8_t *data, size_t size, NetPacketSent *sent_cb); ssize_t qemu_net_queue_send_iov(NetQueue *queue, - VLANClientState *sender, + NetClientState *sender, unsigned flags, const struct iovec *iov, int iovcnt, NetPacketSent *sent_cb); -void qemu_net_queue_purge(NetQueue *queue, VLANClientState *from); +void qemu_net_queue_purge(NetQueue *queue, NetClientState *from); void qemu_net_queue_flush(NetQueue *queue); #endif /* QEMU_NET_QUEUE_H */ diff --git a/net/slirp.c b/net/slirp.c index 5c2e6b2..08adb97 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -30,6 +30,7 @@ #include <sys/wait.h> #endif #include "net.h" +#include "net/hub.h" #include "monitor.h" #include "qemu_socket.h" #include "slirp/libslirp.h" @@ -67,7 +68,7 @@ struct slirp_config_str { }; typedef struct SlirpState { - VLANClientState nc; + NetClientState nc; QTAILQ_ENTRY(SlirpState) entry; Slirp *slirp; #ifndef _WIN32 @@ -96,13 +97,6 @@ static void slirp_smb_cleanup(SlirpState *s); static inline void slirp_smb_cleanup(SlirpState *s) { } #endif -int slirp_can_output(void *opaque) -{ - SlirpState *s = opaque; - - return qemu_can_send_packet(&s->nc); -} - void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) { SlirpState *s = opaque; @@ -110,7 +104,7 @@ void slirp_output(void *opaque, const uint8_t *pkt, int pkt_len) qemu_send_packet(&s->nc, pkt, pkt_len); } -static ssize_t net_slirp_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t net_slirp_receive(NetClientState *nc, const uint8_t *buf, size_t size) { SlirpState *s = DO_UPCAST(SlirpState, nc, nc); @@ -119,7 +113,7 @@ static ssize_t net_slirp_receive(VLANClientState *nc, const uint8_t *buf, size_t return size; } -static void net_slirp_cleanup(VLANClientState *nc) +static void net_slirp_cleanup(NetClientState *nc) { SlirpState *s = DO_UPCAST(SlirpState, nc, nc); @@ -135,7 +129,7 @@ static NetClientInfo net_slirp_info = { .cleanup = net_slirp_cleanup, }; -static int net_slirp_init(VLANState *vlan, const char *model, +static int net_slirp_init(NetClientState *peer, const char *model, const char *name, int restricted, const char *vnetwork, const char *vhost, const char *vhostname, const char *tftp_export, @@ -152,7 +146,7 @@ static int net_slirp_init(VLANState *vlan, const char *model, #ifndef _WIN32 struct in_addr smbsrv = { .s_addr = 0 }; #endif - VLANClientState *nc; + NetClientState *nc; SlirpState *s; char buf[20]; uint32_t addr; @@ -238,7 +232,7 @@ static int net_slirp_init(VLANState *vlan, const char *model, } #endif - nc = qemu_new_net_client(&net_slirp_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_slirp_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "net=%s,restrict=%s", inet_ntoa(net), @@ -274,7 +268,7 @@ static int net_slirp_init(VLANState *vlan, const char *model, return 0; error: - qemu_del_vlan_client(nc); + qemu_del_net_client(nc); return -1; } @@ -283,8 +277,8 @@ static SlirpState *slirp_lookup(Monitor *mon, const char *vlan, { if (vlan) { - VLANClientState *nc; - nc = qemu_find_vlan_client_by_name(mon, strtol(vlan, NULL, 0), stack); + NetClientState *nc; + nc = net_hub_find_client_by_name(strtol(vlan, NULL, 0), stack); if (!nc) { return NULL; } @@ -679,8 +673,10 @@ void do_info_usernet(Monitor *mon) SlirpState *s; QTAILQ_FOREACH(s, &slirp_stacks, entry) { + int id; + bool got_vlan_id = net_hub_id_for_client(&s->nc, &id) == 0; monitor_printf(mon, "VLAN %d (%s):\n", - s->nc.vlan ? s->nc.vlan->id : -1, + got_vlan_id ? id : -1, s->nc.name); slirp_connection_info(s->slirp, mon); } @@ -703,7 +699,7 @@ net_init_slirp_configs(const StringList *fwd, int flags) } int net_init_slirp(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { struct slirp_config_str *config; char *vnet; @@ -722,7 +718,7 @@ int net_init_slirp(const NetClientOptions *opts, const char *name, net_init_slirp_configs(user->hostfwd, SLIRP_CFG_HOSTFWD); net_init_slirp_configs(user->guestfwd, 0); - ret = net_slirp_init(vlan, "user", name, user->restrict, vnet, user->host, + ret = net_slirp_init(peer, "user", name, user->restrict, vnet, user->host, user->hostname, user->tftp, user->bootfile, user->dhcpstart, user->dns, user->smb, user->smbserver); diff --git a/net/slirp.h b/net/slirp.h index e2c71ee..5f685c4 100644 --- a/net/slirp.h +++ b/net/slirp.h @@ -32,7 +32,7 @@ #ifdef CONFIG_SLIRP int net_init_slirp(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict); void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict); diff --git a/net/socket.c b/net/socket.c index 600c287..c172c24 100644 --- a/net/socket.c +++ b/net/socket.c @@ -34,7 +34,8 @@ #include "qemu_socket.h" typedef struct NetSocketState { - VLANClientState nc; + NetClientState nc; + int listen_fd; int fd; int state; /* 0 = getting length, 1 = getting data */ unsigned int index; @@ -43,15 +44,10 @@ typedef struct NetSocketState { struct sockaddr_in dgram_dst; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */ } NetSocketState; -typedef struct NetSocketListenState { - VLANState *vlan; - char *model; - char *name; - int fd; -} NetSocketListenState; +static void net_socket_accept(void *opaque); /* XXX: we consider we can send the whole packet without blocking */ -static ssize_t net_socket_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t net_socket_receive(NetClientState *nc, const uint8_t *buf, size_t size) { NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); uint32_t len; @@ -61,7 +57,7 @@ static ssize_t net_socket_receive(VLANClientState *nc, const uint8_t *buf, size_ return send_all(s->fd, buf, size); } -static ssize_t net_socket_receive_dgram(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t net_socket_receive_dgram(NetClientState *nc, const uint8_t *buf, size_t size) { NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); @@ -86,7 +82,19 @@ static void net_socket_send(void *opaque) /* end of connection */ eoc: qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + if (s->listen_fd != -1) { + qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); + } closesocket(s->fd); + + s->fd = -1; + s->state = 0; + s->index = 0; + s->packet_len = 0; + s->nc.link_down = true; + memset(s->buf, 0, sizeof(s->buf)); + memset(s->nc.info_str, 0, sizeof(s->nc.info_str)); + return; } buf = buf1; @@ -231,11 +239,19 @@ fail: return -1; } -static void net_socket_cleanup(VLANClientState *nc) +static void net_socket_cleanup(NetClientState *nc) { NetSocketState *s = DO_UPCAST(NetSocketState, nc, nc); - qemu_set_fd_handler(s->fd, NULL, NULL, NULL); - close(s->fd); + if (s->fd != -1) { + qemu_set_fd_handler(s->fd, NULL, NULL, NULL); + close(s->fd); + s->fd = -1; + } + if (s->listen_fd != -1) { + qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); + closesocket(s->listen_fd); + s->listen_fd = -1; + } } static NetClientInfo net_dgram_socket_info = { @@ -245,7 +261,7 @@ static NetClientInfo net_dgram_socket_info = { .cleanup = net_socket_cleanup, }; -static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, +static NetSocketState *net_socket_fd_init_dgram(NetClientState *peer, const char *model, const char *name, int fd, int is_connected) @@ -253,7 +269,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, struct sockaddr_in saddr; int newfd; socklen_t saddr_len; - VLANClientState *nc; + NetClientState *nc; NetSocketState *s; /* fd passed: multicast: "learn" dgram_dst address from bound address and save it @@ -287,7 +303,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, } } - nc = qemu_new_net_client(&net_dgram_socket_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_dgram_socket_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (%s mcast=%s:%d)", @@ -297,11 +313,14 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; + s->listen_fd = -1; qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s); /* mcast: save bound address as dst */ - if (is_connected) s->dgram_dst=saddr; + if (is_connected) { + s->dgram_dst = saddr; + } return s; @@ -323,21 +342,22 @@ static NetClientInfo net_socket_info = { .cleanup = net_socket_cleanup, }; -static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, +static NetSocketState *net_socket_fd_init_stream(NetClientState *peer, const char *model, const char *name, int fd, int is_connected) { - VLANClientState *nc; + NetClientState *nc; NetSocketState *s; - nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_socket_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); s = DO_UPCAST(NetSocketState, nc, nc); s->fd = fd; + s->listen_fd = -1; if (is_connected) { net_socket_connect(s); @@ -347,7 +367,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, return s; } -static NetSocketState *net_socket_fd_init(VLANState *vlan, +static NetSocketState *net_socket_fd_init(NetClientState *peer, const char *model, const char *name, int fd, int is_connected) { @@ -362,60 +382,59 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, } switch(so_type) { case SOCK_DGRAM: - return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected); + return net_socket_fd_init_dgram(peer, model, name, fd, is_connected); case SOCK_STREAM: - return net_socket_fd_init_stream(vlan, model, name, fd, is_connected); + return net_socket_fd_init_stream(peer, model, name, fd, is_connected); default: /* who knows ... this could be a eg. a pty, do warn and continue as stream */ fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd); - return net_socket_fd_init_stream(vlan, model, name, fd, is_connected); + return net_socket_fd_init_stream(peer, model, name, fd, is_connected); } return NULL; } static void net_socket_accept(void *opaque) { - NetSocketListenState *s = opaque; - NetSocketState *s1; + NetSocketState *s = opaque; struct sockaddr_in saddr; socklen_t len; int fd; for(;;) { len = sizeof(saddr); - fd = qemu_accept(s->fd, (struct sockaddr *)&saddr, &len); + fd = qemu_accept(s->listen_fd, (struct sockaddr *)&saddr, &len); if (fd < 0 && errno != EINTR) { return; } else if (fd >= 0) { + qemu_set_fd_handler(s->listen_fd, NULL, NULL, NULL); break; } } - s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1); - if (s1) { - snprintf(s1->nc.info_str, sizeof(s1->nc.info_str), - "socket: connection from %s:%d", - inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); - } + + s->fd = fd; + s->nc.link_down = false; + net_socket_connect(s); + snprintf(s->nc.info_str, sizeof(s->nc.info_str), + "socket: connection from %s:%d", + inet_ntoa(saddr.sin_addr), ntohs(saddr.sin_port)); } -static int net_socket_listen_init(VLANState *vlan, +static int net_socket_listen_init(NetClientState *peer, const char *model, const char *name, const char *host_str) { - NetSocketListenState *s; - int fd, val, ret; + NetClientState *nc; + NetSocketState *s; struct sockaddr_in saddr; + int fd, val, ret; if (parse_host_port(&saddr, host_str) < 0) return -1; - s = g_malloc0(sizeof(NetSocketListenState)); - fd = qemu_socket(PF_INET, SOCK_STREAM, 0); if (fd < 0) { perror("socket"); - g_free(s); return -1; } socket_set_nonblock(fd); @@ -427,26 +446,27 @@ static int net_socket_listen_init(VLANState *vlan, ret = bind(fd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { perror("bind"); - g_free(s); closesocket(fd); return -1; } ret = listen(fd, 0); if (ret < 0) { perror("listen"); - g_free(s); closesocket(fd); return -1; } - s->vlan = vlan; - s->model = g_strdup(model); - s->name = name ? g_strdup(name) : NULL; - s->fd = fd; - qemu_set_fd_handler(fd, net_socket_accept, NULL, s); + + nc = qemu_new_net_client(&net_socket_info, peer, model, name); + s = DO_UPCAST(NetSocketState, nc, nc); + s->fd = -1; + s->listen_fd = fd; + s->nc.link_down = true; + + qemu_set_fd_handler(s->listen_fd, net_socket_accept, NULL, s); return 0; } -static int net_socket_connect_init(VLANState *vlan, +static int net_socket_connect_init(NetClientState *peer, const char *model, const char *name, const char *host_str) @@ -487,7 +507,7 @@ static int net_socket_connect_init(VLANState *vlan, break; } } - s = net_socket_fd_init(vlan, model, name, fd, connected); + s = net_socket_fd_init(peer, model, name, fd, connected); if (!s) return -1; snprintf(s->nc.info_str, sizeof(s->nc.info_str), @@ -496,7 +516,7 @@ static int net_socket_connect_init(VLANState *vlan, return 0; } -static int net_socket_mcast_init(VLANState *vlan, +static int net_socket_mcast_init(NetClientState *peer, const char *model, const char *name, const char *host_str, @@ -522,7 +542,7 @@ static int net_socket_mcast_init(VLANState *vlan, if (fd < 0) return -1; - s = net_socket_fd_init(vlan, model, name, fd, 0); + s = net_socket_fd_init(peer, model, name, fd, 0); if (!s) return -1; @@ -535,7 +555,7 @@ static int net_socket_mcast_init(VLANState *vlan, } -static int net_socket_udp_init(VLANState *vlan, +static int net_socket_udp_init(NetClientState *peer, const char *model, const char *name, const char *rhost, @@ -573,7 +593,7 @@ static int net_socket_udp_init(VLANState *vlan, return -1; } - s = net_socket_fd_init(vlan, model, name, fd, 0); + s = net_socket_fd_init(peer, model, name, fd, 0); if (!s) { return -1; } @@ -587,7 +607,7 @@ static int net_socket_udp_init(VLANState *vlan, } int net_init_socket(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { const NetdevSocketOptions *sock; @@ -610,21 +630,21 @@ int net_init_socket(const NetClientOptions *opts, const char *name, int fd; fd = net_handle_fd_param(cur_mon, sock->fd); - if (fd == -1 || !net_socket_fd_init(vlan, "socket", name, fd, 1)) { + if (fd == -1 || !net_socket_fd_init(peer, "socket", name, fd, 1)) { return -1; } return 0; } if (sock->has_listen) { - if (net_socket_listen_init(vlan, "socket", name, sock->listen) == -1) { + if (net_socket_listen_init(peer, "socket", name, sock->listen) == -1) { return -1; } return 0; } if (sock->has_connect) { - if (net_socket_connect_init(vlan, "socket", name, sock->connect) == + if (net_socket_connect_init(peer, "socket", name, sock->connect) == -1) { return -1; } @@ -634,7 +654,7 @@ int net_init_socket(const NetClientOptions *opts, const char *name, if (sock->has_mcast) { /* if sock->localaddr is missing, it has been initialized to "all bits * zero" */ - if (net_socket_mcast_init(vlan, "socket", name, sock->mcast, + if (net_socket_mcast_init(peer, "socket", name, sock->mcast, sock->localaddr) == -1) { return -1; } @@ -646,7 +666,7 @@ int net_init_socket(const NetClientOptions *opts, const char *name, error_report("localaddr= is mandatory with udp="); return -1; } - if (net_socket_udp_init(vlan, "udp", name, sock->udp, sock->localaddr) == + if (net_socket_udp_init(peer, "udp", name, sock->udp, sock->localaddr) == -1) { return -1; } diff --git a/net/socket.h b/net/socket.h index c4809ad..3f8a092 100644 --- a/net/socket.h +++ b/net/socket.h @@ -28,6 +28,6 @@ #include "qapi-types.h" int net_init_socket(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); #endif /* QEMU_NET_SOCKET_H */ diff --git a/net/tap-win32.c b/net/tap-win32.c index 2328072..c0ea954 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -630,11 +630,11 @@ static int tap_win32_open(tap_win32_overlapped_t **phandle, /********************************************/ typedef struct TAPState { - VLANClientState nc; + NetClientState nc; tap_win32_overlapped_t *handle; } TAPState; -static void tap_cleanup(VLANClientState *nc) +static void tap_cleanup(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -645,7 +645,7 @@ static void tap_cleanup(VLANClientState *nc) */ } -static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -673,10 +673,10 @@ static NetClientInfo net_tap_win32_info = { .cleanup = tap_cleanup, }; -static int tap_win32_init(VLANState *vlan, const char *model, +static int tap_win32_init(NetClientState *peer, const char *model, const char *name, const char *ifname) { - VLANClientState *nc; + NetClientState *nc; TAPState *s; tap_win32_overlapped_t *handle; @@ -685,7 +685,7 @@ static int tap_win32_init(VLANState *vlan, const char *model, return -1; } - nc = qemu_new_net_client(&net_tap_win32_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_tap_win32_info, peer, model, name); s = DO_UPCAST(TAPState, nc, nc); @@ -700,7 +700,7 @@ static int tap_win32_init(VLANState *vlan, const char *model, } int net_init_tap(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { const NetdevTapOptions *tap; @@ -712,19 +712,19 @@ int net_init_tap(const NetClientOptions *opts, const char *name, return -1; } - if (tap_win32_init(vlan, "tap", name, tap->ifname) == -1) { + if (tap_win32_init(peer, "tap", name, tap->ifname) == -1) { return -1; } return 0; } -int tap_has_ufo(VLANClientState *vc) +int tap_has_ufo(NetClientState *nc) { return 0; } -int tap_has_vnet_hdr(VLANClientState *vc) +int tap_has_vnet_hdr(NetClientState *nc) { return 0; } @@ -738,16 +738,16 @@ void tap_fd_set_vnet_hdr_len(int fd, int len) { } -void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr) +void tap_using_vnet_hdr(NetClientState *nc, int using_vnet_hdr) { } -void tap_set_offload(VLANClientState *vc, int csum, int tso4, +void tap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo) { } -struct vhost_net *tap_get_vhost_net(VLANClientState *nc) +struct vhost_net *tap_get_vhost_net(NetClientState *nc) { return NULL; } @@ -50,7 +50,7 @@ #define TAP_BUFSIZE (4096 + 65536) typedef struct TAPState { - VLANClientState nc; + NetClientState nc; int fd; char down_script[1024]; char down_script_arg[128]; @@ -115,7 +115,7 @@ static ssize_t tap_write_packet(TAPState *s, const struct iovec *iov, int iovcnt return len; } -static ssize_t tap_receive_iov(VLANClientState *nc, const struct iovec *iov, +static ssize_t tap_receive_iov(NetClientState *nc, const struct iovec *iov, int iovcnt) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -134,7 +134,7 @@ static ssize_t tap_receive_iov(VLANClientState *nc, const struct iovec *iov, return tap_write_packet(s, iovp, iovcnt); } -static ssize_t tap_receive_raw(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t tap_receive_raw(NetClientState *nc, const uint8_t *buf, size_t size) { TAPState *s = DO_UPCAST(TAPState, nc, nc); struct iovec iov[2]; @@ -154,7 +154,7 @@ static ssize_t tap_receive_raw(VLANClientState *nc, const uint8_t *buf, size_t s return tap_write_packet(s, iov, iovcnt); } -static ssize_t tap_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t tap_receive(NetClientState *nc, const uint8_t *buf, size_t size) { TAPState *s = DO_UPCAST(TAPState, nc, nc); struct iovec iov[1]; @@ -183,7 +183,7 @@ ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) } #endif -static void tap_send_completed(VLANClientState *nc, ssize_t len) +static void tap_send_completed(NetClientState *nc, ssize_t len) { TAPState *s = DO_UPCAST(TAPState, nc, nc); tap_read_poll(s, 1); @@ -214,7 +214,7 @@ static void tap_send(void *opaque) } while (size > 0 && qemu_can_send_packet(&s->nc)); } -int tap_has_ufo(VLANClientState *nc) +int tap_has_ufo(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -223,7 +223,7 @@ int tap_has_ufo(VLANClientState *nc) return s->has_ufo; } -int tap_has_vnet_hdr(VLANClientState *nc) +int tap_has_vnet_hdr(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -232,7 +232,7 @@ int tap_has_vnet_hdr(VLANClientState *nc) return !!s->host_vnet_hdr_len; } -int tap_has_vnet_hdr_len(VLANClientState *nc, int len) +int tap_has_vnet_hdr_len(NetClientState *nc, int len) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -241,7 +241,7 @@ int tap_has_vnet_hdr_len(VLANClientState *nc, int len) return tap_probe_vnet_hdr_len(s->fd, len); } -void tap_set_vnet_hdr_len(VLANClientState *nc, int len) +void tap_set_vnet_hdr_len(NetClientState *nc, int len) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -253,7 +253,7 @@ void tap_set_vnet_hdr_len(VLANClientState *nc, int len) s->host_vnet_hdr_len = len; } -void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr) +void tap_using_vnet_hdr(NetClientState *nc, int using_vnet_hdr) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -265,7 +265,7 @@ void tap_using_vnet_hdr(VLANClientState *nc, int using_vnet_hdr) s->using_vnet_hdr = using_vnet_hdr; } -void tap_set_offload(VLANClientState *nc, int csum, int tso4, +void tap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -276,7 +276,7 @@ void tap_set_offload(VLANClientState *nc, int csum, int tso4, tap_fd_set_offload(s->fd, csum, tso4, tso6, ecn, ufo); } -static void tap_cleanup(VLANClientState *nc) +static void tap_cleanup(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); @@ -296,14 +296,14 @@ static void tap_cleanup(VLANClientState *nc) s->fd = -1; } -static void tap_poll(VLANClientState *nc, bool enable) +static void tap_poll(NetClientState *nc, bool enable) { TAPState *s = DO_UPCAST(TAPState, nc, nc); tap_read_poll(s, enable); tap_write_poll(s, enable); } -int tap_get_fd(VLANClientState *nc) +int tap_get_fd(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP); @@ -322,16 +322,16 @@ static NetClientInfo net_tap_info = { .cleanup = tap_cleanup, }; -static TAPState *net_tap_fd_init(VLANState *vlan, +static TAPState *net_tap_fd_init(NetClientState *peer, const char *model, const char *name, int fd, int vnet_hdr) { - VLANClientState *nc; + NetClientState *nc; TAPState *s; - nc = qemu_new_net_client(&net_tap_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_tap_info, peer, model, name); s = DO_UPCAST(TAPState, nc, nc); @@ -514,7 +514,7 @@ static int net_bridge_run_helper(const char *helper, const char *bridge) } int net_init_bridge(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { const NetdevBridgeOptions *bridge; const char *helper, *br; @@ -537,7 +537,7 @@ int net_init_bridge(const NetClientOptions *opts, const char *name, vnet_hdr = tap_probe_vnet_hdr(fd); - s = net_tap_fd_init(vlan, "bridge", name, fd, vnet_hdr); + s = net_tap_fd_init(peer, "bridge", name, fd, vnet_hdr); if (!s) { close(fd); return -1; @@ -587,7 +587,7 @@ static int net_tap_init(const NetdevTapOptions *tap, int *vnet_hdr, } int net_init_tap(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { const NetdevTapOptions *tap; @@ -650,7 +650,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, model = "tap"; } - s = net_tap_fd_init(vlan, model, name, fd, vnet_hdr); + s = net_tap_fd_init(peer, model, name, fd, vnet_hdr); if (!s) { close(fd); return -1; @@ -708,7 +708,7 @@ int net_init_tap(const NetClientOptions *opts, const char *name, return 0; } -VHostNetState *tap_get_vhost_net(VLANClientState *nc) +VHostNetState *tap_get_vhost_net(NetClientState *nc) { TAPState *s = DO_UPCAST(TAPState, nc, nc); assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP); @@ -33,18 +33,18 @@ #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" int net_init_tap(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required); ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen); -int tap_has_ufo(VLANClientState *vc); -int tap_has_vnet_hdr(VLANClientState *vc); -int tap_has_vnet_hdr_len(VLANClientState *vc, int len); -void tap_using_vnet_hdr(VLANClientState *vc, int using_vnet_hdr); -void tap_set_offload(VLANClientState *vc, int csum, int tso4, int tso6, int ecn, int ufo); -void tap_set_vnet_hdr_len(VLANClientState *vc, int len); +int tap_has_ufo(NetClientState *nc); +int tap_has_vnet_hdr(NetClientState *nc); +int tap_has_vnet_hdr_len(NetClientState *nc, int len); +void tap_using_vnet_hdr(NetClientState *nc, int using_vnet_hdr); +void tap_set_offload(NetClientState *nc, int csum, int tso4, int tso6, int ecn, int ufo); +void tap_set_vnet_hdr_len(NetClientState *nc, int len); int tap_set_sndbuf(int fd, const NetdevTapOptions *tap); int tap_probe_vnet_hdr(int fd); @@ -53,12 +53,12 @@ int tap_probe_has_ufo(int fd); void tap_fd_set_offload(int fd, int csum, int tso4, int tso6, int ecn, int ufo); void tap_fd_set_vnet_hdr_len(int fd, int len); -int tap_get_fd(VLANClientState *vc); +int tap_get_fd(NetClientState *nc); struct vhost_net; -struct vhost_net *tap_get_vhost_net(VLANClientState *vc); +struct vhost_net *tap_get_vhost_net(NetClientState *nc); int net_init_bridge(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); #endif /* QEMU_NET_TAP_H */ @@ -33,7 +33,7 @@ #include "qemu-option.h" typedef struct VDEState { - VLANClientState nc; + NetClientState nc; VDECONN *vde; } VDEState; @@ -49,7 +49,7 @@ static void vde_to_qemu(void *opaque) } } -static ssize_t vde_receive(VLANClientState *nc, const uint8_t *buf, size_t size) +static ssize_t vde_receive(NetClientState *nc, const uint8_t *buf, size_t size) { VDEState *s = DO_UPCAST(VDEState, nc, nc); ssize_t ret; @@ -61,7 +61,7 @@ static ssize_t vde_receive(VLANClientState *nc, const uint8_t *buf, size_t size) return ret; } -static void vde_cleanup(VLANClientState *nc) +static void vde_cleanup(NetClientState *nc) { VDEState *s = DO_UPCAST(VDEState, nc, nc); qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL); @@ -75,11 +75,11 @@ static NetClientInfo net_vde_info = { .cleanup = vde_cleanup, }; -static int net_vde_init(VLANState *vlan, const char *model, +static int net_vde_init(NetClientState *peer, const char *model, const char *name, const char *sock, int port, const char *group, int mode) { - VLANClientState *nc; + NetClientState *nc; VDEState *s; VDECONN *vde; char *init_group = (char *)group; @@ -96,7 +96,7 @@ static int net_vde_init(VLANState *vlan, const char *model, return -1; } - nc = qemu_new_net_client(&net_vde_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_vde_info, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "sock=%s,fd=%d", sock, vde_datafd(vde)); @@ -111,7 +111,7 @@ static int net_vde_init(VLANState *vlan, const char *model, } int net_init_vde(const NetClientOptions *opts, const char *name, - VLANState *vlan) + NetClientState *peer) { const NetdevVdeOptions *vde; @@ -119,7 +119,7 @@ int net_init_vde(const NetClientOptions *opts, const char *name, vde = opts->vde; /* missing optional values have been initialized to "all bits zero" */ - if (net_vde_init(vlan, "vde", name, vde->sock, vde->port, vde->group, + if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group, vde->has_mode ? vde->mode : 0700) == -1) { return -1; } @@ -30,7 +30,7 @@ #ifdef CONFIG_VDE int net_init_vde(const NetClientOptions *opts, const char *name, - VLANState *vlan); + NetClientState *peer); #endif /* CONFIG_VDE */ |