From 15a0bc24ccf6d49ac419b40c65ec8eed37c04d44 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sat, 17 Nov 2018 00:30:08 +0100 Subject: [PATCH] virtio_net: Use proper frame length in receive path. Previously the frame length was set to the allocation size of the buffer itself, which is constant. Use the length returned on dequeing instead, which tells how much of the buffer was actually filled. Fixes overly long frames that lead to various problems along the receive path. --- src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp index f79977b5a8..c1d19a9115 100644 --- a/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp +++ b/src/add-ons/kernel/drivers/network/virtio/virtio_net.cpp @@ -46,6 +46,7 @@ struct BufInfo : DoublyLinkedListLinkImpl { struct virtio_net_hdr* hdr; physical_entry entry; physical_entry hdrEntry; + uint32 rxUsedLength; }; @@ -549,17 +550,20 @@ virtio_net_read(void* cookie, off_t pos, void* buffer, size_t* _length) mutex_lock(&info->rxLock); while (info->rxDone != -1) { + uint32 usedLength = 0; BufInfo* buf = (BufInfo*)info->virtio->queue_dequeue( - info->rxQueues[0], NULL); + info->rxQueues[0], &usedLength); if (buf == NULL) break; + + buf->rxUsedLength = usedLength; info->rxFullList.Add(buf); } TRACE("virtio_net_read: finished waiting\n"); } BufInfo* buf = info->rxFullList.RemoveHead(); - *_length = MIN(buf->entry.size, *_length); + *_length = MIN(buf->rxUsedLength, *_length); memcpy(buffer, buf->buffer, *_length); virtio_net_rx_enqueue_buf(info, buf); mutex_unlock(&info->rxLock);