Blame SOURCES/kvm-net-Transmit-zero-UDP-checksum-as-0xFFFF.patch

c461a1
From 58d702589fd93689c142e8cb48d51877a8de3a93 Mon Sep 17 00:00:00 2001
c461a1
From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= <philmd@redhat.com>
c461a1
Date: Sat, 13 Jul 2019 12:38:02 +0200
c461a1
Subject: [PATCH 3/4] net: Transmit zero UDP checksum as 0xFFFF
c461a1
MIME-Version: 1.0
c461a1
Content-Type: text/plain; charset=UTF-8
c461a1
Content-Transfer-Encoding: 8bit
c461a1
c461a1
RH-Author: Philippe Mathieu-Daudé <philmd@redhat.com>
c461a1
Message-id: <20190713123802.23932-3-philmd@redhat.com>
c461a1
Patchwork-id: 89509
c461a1
O-Subject: [RHEL-7.7 qemu-kvm PATCH 2/2] net: Transmit zero UDP checksum as 0xFFFF
c461a1
Bugzilla: 1270166
c461a1
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
c461a1
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
c461a1
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
c461a1
c461a1
From: Ed Swierk <eswierk@skyportsystems.com>
c461a1
c461a1
The checksum algorithm used by IPv4, TCP and UDP allows a zero value
c461a1
to be represented by either 0x0000 and 0xFFFF. But per RFC 768, a zero
c461a1
UDP checksum must be transmitted as 0xFFFF because 0x0000 is a special
c461a1
value meaning no checksum.
c461a1
c461a1
Substitute 0xFFFF whenever a checksum is computed as zero when
c461a1
modifying a UDP datagram header. Doing this on IPv4 and TCP checksums
c461a1
is unnecessary but legal. Add a wrapper for net_checksum_finish() that
c461a1
makes the substitution.
c461a1
c461a1
(We can't just change net_checksum_finish(), as that function is also
c461a1
used by receivers to verify checksums, and in that case the expected
c461a1
value is always 0x0000.)
c461a1
c461a1
Signed-off-by: Ed Swierk <eswierk@skyportsystems.com>
c461a1
Signed-off-by: Jason Wang <jasowang@redhat.com>
c461a1
(cherry picked from commit 0dacea92d26c31d453c58de2e99c178fee554166)
c461a1
[PMD: conflicts: hw/net/net_rx_pkt.c hw/net/vmxnet3.c]
c461a1
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
c461a1
c461a1
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
c461a1
---
c461a1
 hw/net/e1000.c         | 2 +-
c461a1
 hw/net/vmxnet_tx_pkt.c | 2 +-
c461a1
 include/net/checksum.h | 6 ++++++
c461a1
 3 files changed, 8 insertions(+), 2 deletions(-)
c461a1
c461a1
diff --git a/hw/net/e1000.c b/hw/net/e1000.c
c461a1
index 711d369..d876949 100644
c461a1
--- a/hw/net/e1000.c
c461a1
+++ b/hw/net/e1000.c
c461a1
@@ -442,7 +442,7 @@ putsum(uint8_t *data, uint32_t n, uint32_t sloc, uint32_t css, uint32_t cse)
c461a1
         n = cse + 1;
c461a1
     if (sloc < n-1) {
c461a1
         sum = net_checksum_add(n-css, data+css);
c461a1
-        stw_be_p(data + sloc, net_checksum_finish(sum));
c461a1
+        stw_be_p(data + sloc, net_checksum_finish_nozero(sum));
c461a1
     }
c461a1
 }
c461a1
 
c461a1
diff --git a/hw/net/vmxnet_tx_pkt.c b/hw/net/vmxnet_tx_pkt.c
c461a1
index fc01e4d..03f34cf 100644
c461a1
--- a/hw/net/vmxnet_tx_pkt.c
c461a1
+++ b/hw/net/vmxnet_tx_pkt.c
c461a1
@@ -437,7 +437,7 @@ static void vmxnet_tx_pkt_do_sw_csum(struct VmxnetTxPkt *pkt)
c461a1
     csum_cntr += eth_calc_pseudo_hdr_csum(iphdr, csl);
c461a1
 
c461a1
     /* Put the checksum obtained into the packet */
c461a1
-    csum = cpu_to_be16(net_checksum_finish(csum_cntr));
c461a1
+    csum = cpu_to_be16(net_checksum_finish_nozero(csum_cntr));
c461a1
     iov_from_buf(iov, iov_len, csum_offset, &csum, sizeof csum);
c461a1
 }
c461a1
 
c461a1
diff --git a/include/net/checksum.h b/include/net/checksum.h
c461a1
index 80203fb..78b7d9b 100644
c461a1
--- a/include/net/checksum.h
c461a1
+++ b/include/net/checksum.h
c461a1
@@ -33,6 +33,12 @@ net_checksum_add(int len, uint8_t *buf)
c461a1
 }
c461a1
 
c461a1
 static inline uint16_t
c461a1
+net_checksum_finish_nozero(uint32_t sum)
c461a1
+{
c461a1
+    return net_checksum_finish(sum) ?: 0xFFFF;
c461a1
+}
c461a1
+
c461a1
+static inline uint16_t
c461a1
 net_raw_checksum(uint8_t *data, int length)
c461a1
 {
c461a1
     return net_checksum_finish(net_checksum_add(length, data));
c461a1
-- 
c461a1
1.8.3.1
c461a1