Simplifies the current code, but more especially, the code
in the next patch.
Signed-off-by: Mark McLoughlin <[EMAIL PROTECTED]>
---
qemu/hw/virtio-net.c | 32 +++++++++++++++++++++-----------
1 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/qemu/hw/virtio-net.c b/qemu/hw/virtio-net.c
index 4b4c48b..403247b 100644
--- a/qemu/hw/virtio-net.c
+++ b/qemu/hw/virtio-net.c
@@ -183,12 +183,27 @@ static void work_around_broken_dhclient(struct
virtio_net_hdr *hdr,
}
}
+static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
+{
+ int offset, i;
+
+ offset = i = 0;
+ while (offset < count && i < iovcnt) {
+ int len = MIN(iov[i].iov_len, count - offset);
+ memcpy(iov[i].iov_base, buf + offset, len);
+ offset += len;
+ i++;
+ }
+
+ return offset;
+}
+
static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
{
VirtIONet *n = opaque;
VirtQueueElement elem;
struct virtio_net_hdr *hdr;
- int offset, i;
+ int offset;
int total;
if (virtqueue_pop(n->rx_vq, &elem) == 0)
@@ -204,23 +219,18 @@ static void virtio_net_receive(void *opaque, const
uint8_t *buf, int size)
hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
offset = 0;
- total = sizeof(*hdr);
+ total = size + sizeof(*hdr);
if (tap_has_vnet_hdr(n->vc->vlan->first_client)) {
memcpy(hdr, buf, sizeof(*hdr));
- offset += total;
+ offset += sizeof(*hdr);
+ total -= offset;
work_around_broken_dhclient(hdr, buf + offset, size - offset);
}
/* copy in packet. ugh */
- i = 1;
- while (offset < size && i < elem.in_num) {
- int len = MIN(elem.in_sg[i].iov_len, size - offset);
- memcpy(elem.in_sg[i].iov_base, buf + offset, len);
- offset += len;
- total += len;
- i++;
- }
+ iov_fill(&elem.in_sg[1], elem.in_num - 1,
+ buf + offset, size - offset);
/* signal other side */
virtqueue_push(n->rx_vq, &elem, total);
--
1.5.4.3
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at http://vger.kernel.org/majordomo-info.html