qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] net: Transmit zero UDP checksum as 0xFFFF


From: Jason Wang
Subject: Re: [Qemu-devel] [PATCH] net: Transmit zero UDP checksum as 0xFFFF
Date: Wed, 15 Nov 2017 10:10:53 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0



On 2017年11月15日 07:25, Ed Swierk wrote:
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, as 0x0000 is a special
value meaning no checksum.

Substitute 0xFFFF whenever a checksum is computed as zero on a UDP
datagram. Doing this on IPv4 packets and TCP segments is unnecessary
but legal.

(While it is tempting to make the substitution in
net_checksum_finish(), that function is also used by receivers to
verify checksums, and in that case the expected value is always
0x0000.)

Then looks like you'd better have an wrapper for net_checksum_finish() and do things there.


Signed-off-by: Ed Swierk <address@hidden>
---
  hw/net/e1000.c      | 5 +++--
  hw/net/net_rx_pkt.c | 3 +++
  hw/net/net_tx_pkt.c | 6 ++++++
  hw/net/vmxnet3.c    | 7 +++++--
  4 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/hw/net/e1000.c b/hw/net/e1000.c
index d642314..97242a1 100644
--- a/hw/net/e1000.c
+++ b/hw/net/e1000.c
@@ -505,8 +505,9 @@ putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t 
css, uint32_t cse)
      if (cse && cse < n)
          n = cse + 1;
      if (sloc < n-1) {
-        sum = net_checksum_add(n-css, data+css);
-        stw_be_p(data + sloc, net_checksum_finish(sum));
+        sum = net_raw_checksum(data + css, n - css);
+        /* For UDP, zero checksum must be sent as 0xFFFF */
+        stw_be_p(data + sloc, sum ? sum : 0xffff);
      }
  }
diff --git a/hw/net/net_rx_pkt.c b/hw/net/net_rx_pkt.c
index 1019b50..e820132 100644
--- a/hw/net/net_rx_pkt.c
+++ b/hw/net/net_rx_pkt.c
@@ -588,6 +588,9 @@ bool net_rx_pkt_fix_l4_csum(struct NetRxPkt *pkt)
/* Calculate L4 checksum */
      csum = cpu_to_be16(_net_rx_pkt_calc_l4_csum(pkt));
+    if (!csum) {
+        csum = 0xFFFF; /* For UDP, zero checksum must be sent as 0xFFFF */
+    }

I thought we should only do this for tx?

Thanks



reply via email to

[Prev in Thread] Current Thread [Next in Thread]