aboutsummaryrefslogtreecommitdiff
path: root/net.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-12-17 19:13:11 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2008-12-17 19:13:11 +0000
commitfbe78f4f55c6fdf1f8df3d82bf31835de9283fa3 (patch)
treee56c27af0fd2bb0b2116779e556f51a2a019f9e6 /net.c
parentfc9902d9c7793a5b854df126a059cce14ecc29f3 (diff)
virtio-net support
This adds virtio-net support. This is based on the virtio-net driver that exists in kvm-userspace. This also adds a new qemu_sendv_packet which virtio-net requires. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6073 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'net.c')
-rw-r--r--net.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/net.c b/net.c
index cbf1cdf35c..e18e36b20e 100644
--- a/net.c
+++ b/net.c
@@ -369,6 +369,50 @@ void qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size)
}
}
+static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
+ int iovcnt)
+{
+ uint8_t buffer[4096];
+ size_t offset = 0;
+ int i;
+
+ for (i = 0; i < iovcnt; i++) {
+ size_t len;
+
+ len = MIN(sizeof(buffer) - offset, iov[i].iov_len);
+ memcpy(buffer + offset, iov[i].iov_base, len);
+ offset += len;
+ }
+
+ vc->fd_read(vc->opaque, buffer, offset);
+
+ return offset;
+}
+
+ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov,
+ int iovcnt)
+{
+ VLANState *vlan = vc1->vlan;
+ VLANClientState *vc;
+ ssize_t max_len = 0;
+
+ for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
+ ssize_t len = 0;
+
+ if (vc == vc1)
+ continue;
+
+ if (vc->fd_readv)
+ len = vc->fd_readv(vc->opaque, iov, iovcnt);
+ else if (vc->fd_read)
+ len = vc_sendv_compat(vc, iov, iovcnt);
+
+ max_len = MAX(max_len, len);
+ }
+
+ return max_len;
+}
+
#if defined(CONFIG_SLIRP)
/* slirp network adapter */