included for ipv6, thus means ipv6 can carry a real '65535' payload.
Signed-off-by: Wei Xu <address@hidden>
---
hw/net/virtio-net.c | 147
+++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 141 insertions(+), 6 deletions(-)
diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 81e8e71..2d09352 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -50,6 +50,10 @@
/* header lenght value in ip header without option */
#define VIRTIO_NET_IP4_HEADER_LENGTH 5
+#define ETH_IP6_HDR_SZ (ETH_HDR_SZ + IP6_HDR_SZ)
+#define VIRTIO_NET_IP6_ADDR_SIZE 32 /* ipv6 saddr + daddr */
+#define VIRTIO_NET_MAX_IP6_PAYLOAD VIRTIO_NET_MAX_TCP_PAYLOAD
+
/* Purge coalesced packets timer interval */
#define VIRTIO_NET_RSC_INTERVAL 300000
@@ -1725,6 +1729,25 @@ static void
virtio_net_rsc_extract_unit4(NetRscChain *chain,
unit->payload = htons(*unit->ip_plen) - ip_hdrlen -
unit->tcp_hdrlen;
}
+static void virtio_net_rsc_extract_unit6(NetRscChain *chain,
+ const uint8_t *buf,
NetRscUnit* unit)
+{
+ uint16_t hdr_len;
+ struct ip6_header *ip6;
+
+ hdr_len = ((VirtIONet *)(chain->n))->guest_hdr_len;
+ ip6 = (struct ip6_header *)(buf + hdr_len + sizeof(struct
eth_header));
+ unit->ip = ip6;
+ unit->ip_plen = &(ip6->ip6_ctlun.ip6_un1.ip6_un1_plen);
+ unit->tcp = (struct tcp_header *)(((uint8_t *)unit->ip)\
+ + sizeof(struct ip6_header));
+ unit->tcp_hdrlen = (htons(unit->tcp->th_offset_flags) & 0xF000)
10;
+
+ /* There is a difference between payload lenght in ipv4 and v6,
+ ip header is excluded in ipv6 */
+ unit->payload = htons(*unit->ip_plen) - unit->tcp_hdrlen;
+}
+
static void virtio_net_rsc_ipv4_checksum(struct ip_header *ip)
{
uint32_t sum;
@@ -1738,7 +1761,9 @@ static size_t
virtio_net_rsc_drain_seg(NetRscChain *chain, NetRscSeg *seg)
{
int ret;
- virtio_net_rsc_ipv4_checksum(seg->unit.ip);
+ if ((chain->proto == ETH_P_IP) && seg->is_coalesced) {
+ virtio_net_rsc_ipv4_checksum(seg->unit.ip);
+ }