summaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authorMark McLoughlin <markmc@redhat.com>2009-10-08 19:58:30 +0100
committerAnthony Liguori <aliguori@us.ibm.com>2009-10-15 09:32:02 -0500
commit283c7c63f5c56c4d0340fb39093fb47e75cb122e (patch)
treec07299f36322356dac05fb41d3059e614e0073a2 /net.c
parent5869c4d515128cd3a938a7346a8037abcc232220 (diff)
downloadqemu-283c7c63f5c56c4d0340fb39093fb47e75cb122e.tar.gz
net: allow NICs to be connected to netdevs
Introduce a 'peer' member to VLANClientState as an alternative to a vlan. The idea being that packets are transfered directly from peer clients rather than going through a vlan. Patchworks-ID: 35516 Signed-off-by: Mark McLoughlin <markmc@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'net.c')
-rw-r--r--net.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/net.c b/net.c
index 3f997cc8e0..5d78f04e04 100644
--- a/net.c
+++ b/net.c
@@ -302,6 +302,7 @@ static char *assign_name(VLANClientState *vc1, const char *model)
}
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+ VLANClientState *peer,
const char *model,
const char *name,
NetCanReceive *can_receive,
@@ -326,9 +327,14 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
vc->opaque = opaque;
if (vlan) {
+ assert(!peer);
vc->vlan = vlan;
QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
} else {
+ if (peer) {
+ vc->peer = peer;
+ peer->peer = vc;
+ }
QTAILQ_INSERT_TAIL(&non_vlan_clients, vc, next);
}
@@ -341,6 +347,9 @@ void qemu_del_vlan_client(VLANClientState *vc)
QTAILQ_REMOVE(&vc->vlan->clients, vc, next);
} else {
QTAILQ_REMOVE(&non_vlan_clients, vc, next);
+ if (vc->peer) {
+ vc->peer->peer = NULL;
+ }
}
if (vc->cleanup) {
@@ -866,7 +875,8 @@ static int net_slirp_init(VLANState *vlan, const char *model,
}
#endif
- s->vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive, NULL,
+ s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+ slirp_receive, NULL,
net_slirp_cleanup, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"net=%s, restricted=%c", inet_ntoa(net), restricted ? 'y' : 'n');
@@ -1426,8 +1436,9 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
s = qemu_mallocz(sizeof(TAPState));
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive,
- tap_receive_iov, tap_cleanup, s);
+ s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+ tap_receive, tap_receive_iov,
+ tap_cleanup, s);
tap_read_poll(s, 1);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
return s;
@@ -1760,8 +1771,9 @@ static int net_vde_init(VLANState *vlan, const char *model,
free(s);
return -1;
}
- s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_receive,
- NULL, vde_cleanup, s);
+ s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+ vde_receive, NULL,
+ vde_cleanup, s);
qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
sock, vde_datafd(s->vde));
@@ -1999,8 +2011,9 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
s = qemu_mallocz(sizeof(NetSocketState));
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan, model, name, NULL, net_socket_receive_dgram,
- NULL, net_socket_cleanup, s);
+ s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+ net_socket_receive_dgram, NULL,
+ net_socket_cleanup, s);
qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
/* mcast: save bound address as dst */
@@ -2027,8 +2040,9 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
NetSocketState *s;
s = qemu_mallocz(sizeof(NetSocketState));
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan, model, name, NULL, net_socket_receive,
- NULL, net_socket_cleanup, s);
+ s->vc = qemu_new_vlan_client(vlan, NULL, model, name, NULL,
+ net_socket_receive, NULL,
+ net_socket_cleanup, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"socket: fd=%d", fd);
if (is_connected) {
@@ -2308,7 +2322,8 @@ static int net_dump_init(VLANState *vlan, const char *device,
return -1;
}
- s->pcap_vc = qemu_new_vlan_client(vlan, device, name, NULL, dump_receive, NULL,
+ s->pcap_vc = qemu_new_vlan_client(vlan, NULL, device, name, NULL,
+ dump_receive, NULL,
net_dump_cleanup, s);
snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
"dump to %s (len=%d)", filename, len);