From 0dacea92d26c31d453c58de2e99c178fee554166 Mon Sep 17 00:00:00 2001 From: Ed Swierk Date: Thu, 16 Nov 2017 06:06:06 -0800 Subject: net: Transmit zero UDP checksum as 0xFFFF The checksum algorithm used by IPv4, TCP and UDP allows a zero value to be represented by either 0x0000 and 0xFFFF. But per RFC 768, a zero UDP checksum must be transmitted as 0xFFFF because 0x0000 is a special value meaning no checksum. Substitute 0xFFFF whenever a checksum is computed as zero when modifying a UDP datagram header. Doing this on IPv4 and TCP checksums is unnecessary but legal. Add a wrapper for net_checksum_finish() that makes the substitution. (We can't just change net_checksum_finish(), as that function is also used by receivers to verify checksums, and in that case the expected value is always 0x0000.) Signed-off-by: Ed Swierk Signed-off-by: Jason Wang --- hw/net/vmxnet3.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'hw/net/vmxnet3.c') diff --git a/hw/net/vmxnet3.c b/hw/net/vmxnet3.c index 8c4bae5394..cdc307dd04 100644 --- a/hw/net/vmxnet3.c +++ b/hw/net/vmxnet3.c @@ -972,7 +972,8 @@ static void vmxnet3_rx_need_csum_calculate(struct NetRxPkt *pkt, data = (uint8_t *)pkt_data + vhdr->csum_start; len = pkt_len - vhdr->csum_start; /* Put the checksum obtained into the packet */ - stw_be_p(data + vhdr->csum_offset, net_raw_checksum(data, len)); + stw_be_p(data + vhdr->csum_offset, + net_checksum_finish_nozero(net_checksum_add(len, data))); vhdr->flags &= ~VIRTIO_NET_HDR_F_NEEDS_CSUM; vhdr->flags |= VIRTIO_NET_HDR_F_DATA_VALID; -- cgit v1.2.3