diff options
author | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-12-17 19:13:11 +0000 |
---|---|---|
committer | aliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162> | 2008-12-17 19:13:11 +0000 |
commit | fbe78f4f55c6fdf1f8df3d82bf31835de9283fa3 (patch) | |
tree | e56c27af0fd2bb0b2116779e556f51a2a019f9e6 /net.c | |
parent | fc9902d9c7793a5b854df126a059cce14ecc29f3 (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.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -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 */ |