From fbe78f4f55c6fdf1f8df3d82bf31835de9283fa3 Mon Sep 17 00:00:00 2001 From: aliguori Date: Wed, 17 Dec 2008 19:13:11 +0000 Subject: 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 git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6073 c046a42c-6fe2-441c-8c8c-71466251a162 --- net.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'net.c') 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 */ -- cgit v1.2.3