diff options
author | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2012-07-24 16:35:05 +0100 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> | 2012-08-01 12:28:51 +0100 |
commit | d33d93b2c40b820c2cfab1e2e6da631f12091957 (patch) | |
tree | a63f93f8c768b451774c11b59c41dc074d2d22a0 /net | |
parent | f6c874e3002b944f83d887b84051654e5c5b7821 (diff) | |
download | qemu-d33d93b2c40b820c2cfab1e2e6da631f12091957.tar.gz qemu-d33d93b2c40b820c2cfab1e2e6da631f12091957.tar.bz2 qemu-d33d93b2c40b820c2cfab1e2e6da631f12091957.zip |
net: Use hubs for the vlan feature
Stop using the special-case vlan code in net.c. Instead use the hub net
client to implement the vlan feature. The next patch will remove vlan
code from net.c completely.
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/dump.c | 19 | ||||
-rw-r--r-- | net/dump.h | 2 | ||||
-rw-r--r-- | net/hub.c | 6 | ||||
-rw-r--r-- | net/hub.h | 2 | ||||
-rw-r--r-- | net/slirp.c | 8 | ||||
-rw-r--r-- | net/slirp.h | 2 | ||||
-rw-r--r-- | net/socket.c | 48 | ||||
-rw-r--r-- | net/socket.h | 2 | ||||
-rw-r--r-- | net/tap-win32.c | 8 | ||||
-rw-r--r-- | net/tap.c | 12 | ||||
-rw-r--r-- | net/tap.h | 4 | ||||
-rw-r--r-- | net/vde.c | 8 | ||||
-rw-r--r-- | net/vde.h | 2 |
13 files changed, 65 insertions, 58 deletions
diff --git a/net/dump.c b/net/dump.c index b575430787..9d7bf3be4d 100644 --- a/net/dump.c +++ b/net/dump.c @@ -27,6 +27,7 @@ #include "qemu-error.h" #include "qemu-log.h" #include "qemu-timer.h" +#include "hub.h" typedef struct DumpState { VLANClientState nc; @@ -99,7 +100,7 @@ static NetClientInfo net_dump_info = { .cleanup = dump_cleanup, }; -static int net_dump_init(VLANState *vlan, const char *device, +static int net_dump_init(VLANClientState *peer, const char *device, const char *name, const char *filename, int len) { struct pcap_file_hdr hdr; @@ -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, NULL, 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) + VLANClientState *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); } diff --git a/net/dump.h b/net/dump.h index 0fa2dd72ca..9d70195a8b 100644 --- a/net/dump.h +++ b/net/dump.h @@ -28,6 +28,6 @@ #include "qapi-types.h" int net_init_dump(const NetClientOptions *opts, const char *name, - VLANState *vlan); + VLANClientState *peer); #endif /* QEMU_NET_DUMP_H */ @@ -206,15 +206,15 @@ int net_hub_id_for_client(VLANClientState *nc, int *id) } int net_init_hubport(const NetClientOptions *opts, const char *name, - VLANState *vlan) + VLANClientState *peer) { const NetdevHubPortOptions *hubport; assert(opts->kind == NET_CLIENT_OPTIONS_KIND_HUBPORT); hubport = opts->hubport; - /* The hub is a "vlan" so this option makes no sense. */ - if (vlan) { + /* Treat hub port like a backend, NIC must be the one to peer */ + if (peer) { return -EINVAL; } @@ -18,7 +18,7 @@ #include "qemu-common.h" int net_init_hubport(const NetClientOptions *opts, const char *name, - VLANState *vlan); + VLANClientState *peer); VLANClientState *net_hub_add_port(int hub_id, const char *name); void net_hub_info(Monitor *mon); int net_hub_id_for_client(VLANClientState *nc, int *id); diff --git a/net/slirp.c b/net/slirp.c index 5c2e6b2cec..97e380cb27 100644 --- a/net/slirp.c +++ b/net/slirp.c @@ -135,7 +135,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(VLANClientState *peer, const char *model, const char *name, int restricted, const char *vnetwork, const char *vhost, const char *vhostname, const char *tftp_export, @@ -238,7 +238,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, NULL, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "net=%s,restrict=%s", inet_ntoa(net), @@ -703,7 +703,7 @@ net_init_slirp_configs(const StringList *fwd, int flags) } int net_init_slirp(const NetClientOptions *opts, const char *name, - VLANState *vlan) + VLANClientState *peer) { struct slirp_config_str *config; char *vnet; @@ -722,7 +722,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 e2c71eeca0..1ff21b064a 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); + VLANClientState *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 600c287d79..09bdc66e10 100644 --- a/net/socket.c +++ b/net/socket.c @@ -44,7 +44,7 @@ typedef struct NetSocketState { } NetSocketState; typedef struct NetSocketListenState { - VLANState *vlan; + VLANClientState *peer; char *model; char *name; int fd; @@ -245,7 +245,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(VLANClientState *peer, const char *model, const char *name, int fd, int is_connected) @@ -287,7 +287,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, NULL, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d (%s mcast=%s:%d)", @@ -323,7 +323,7 @@ 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(VLANClientState *peer, const char *model, const char *name, int fd, int is_connected) @@ -331,7 +331,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, VLANClientState *nc; NetSocketState *s; - nc = qemu_new_net_client(&net_socket_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_socket_info, NULL, peer, model, name); snprintf(nc->info_str, sizeof(nc->info_str), "socket: fd=%d", fd); @@ -347,7 +347,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(VLANClientState *peer, const char *model, const char *name, int fd, int is_connected) { @@ -362,13 +362,13 @@ 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; } @@ -390,7 +390,7 @@ static void net_socket_accept(void *opaque) break; } } - s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1); + s1 = net_socket_fd_init(s->peer, s->model, s->name, fd, 1); if (s1) { snprintf(s1->nc.info_str, sizeof(s1->nc.info_str), "socket: connection from %s:%d", @@ -398,7 +398,7 @@ static void net_socket_accept(void *opaque) } } -static int net_socket_listen_init(VLANState *vlan, +static int net_socket_listen_init(VLANClientState *peer, const char *model, const char *name, const char *host_str) @@ -438,7 +438,7 @@ static int net_socket_listen_init(VLANState *vlan, closesocket(fd); return -1; } - s->vlan = vlan; + s->peer = peer; s->model = g_strdup(model); s->name = name ? g_strdup(name) : NULL; s->fd = fd; @@ -446,7 +446,7 @@ static int net_socket_listen_init(VLANState *vlan, return 0; } -static int net_socket_connect_init(VLANState *vlan, +static int net_socket_connect_init(VLANClientState *peer, const char *model, const char *name, const char *host_str) @@ -487,7 +487,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 +496,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(VLANClientState *peer, const char *model, const char *name, const char *host_str, @@ -522,7 +522,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 +535,7 @@ static int net_socket_mcast_init(VLANState *vlan, } -static int net_socket_udp_init(VLANState *vlan, +static int net_socket_udp_init(VLANClientState *peer, const char *model, const char *name, const char *rhost, @@ -573,7 +573,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 +587,7 @@ static int net_socket_udp_init(VLANState *vlan, } int net_init_socket(const NetClientOptions *opts, const char *name, - VLANState *vlan) + VLANClientState *peer) { const NetdevSocketOptions *sock; @@ -610,21 +610,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 +634,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 +646,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 c4809ad0d9..82b4d169d9 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); + VLANClientState *peer); #endif /* QEMU_NET_SOCKET_H */ diff --git a/net/tap-win32.c b/net/tap-win32.c index 232807236a..0e3b883c00 100644 --- a/net/tap-win32.c +++ b/net/tap-win32.c @@ -673,7 +673,7 @@ static NetClientInfo net_tap_win32_info = { .cleanup = tap_cleanup, }; -static int tap_win32_init(VLANState *vlan, const char *model, +static int tap_win32_init(VLANClientState *peer, const char *model, const char *name, const char *ifname) { VLANClientState *nc; @@ -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, NULL, 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) + VLANClientState *peer) { const NetdevTapOptions *tap; @@ -712,7 +712,7 @@ 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; } @@ -322,7 +322,7 @@ static NetClientInfo net_tap_info = { .cleanup = tap_cleanup, }; -static TAPState *net_tap_fd_init(VLANState *vlan, +static TAPState *net_tap_fd_init(VLANClientState *peer, const char *model, const char *name, int fd, @@ -331,7 +331,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, VLANClientState *nc; TAPState *s; - nc = qemu_new_net_client(&net_tap_info, vlan, NULL, model, name); + nc = qemu_new_net_client(&net_tap_info, NULL, 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) + VLANClientState *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) + VLANClientState *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; @@ -33,7 +33,7 @@ #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" int net_init_tap(const NetClientOptions *opts, const char *name, - VLANState *vlan); + VLANClientState *peer); int tap_open(char *ifname, int ifname_size, int *vnet_hdr, int vnet_hdr_required); @@ -59,6 +59,6 @@ struct vhost_net; struct vhost_net *tap_get_vhost_net(VLANClientState *vc); int net_init_bridge(const NetClientOptions *opts, const char *name, - VLANState *vlan); + VLANClientState *peer); #endif /* QEMU_NET_TAP_H */ @@ -75,7 +75,7 @@ static NetClientInfo net_vde_info = { .cleanup = vde_cleanup, }; -static int net_vde_init(VLANState *vlan, const char *model, +static int net_vde_init(VLANClientState *peer, const char *model, const char *name, const char *sock, int port, const char *group, int mode) { @@ -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, NULL, 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) + VLANClientState *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); + VLANClientState *peer); #endif /* CONFIG_VDE */ |