thebeanogamer / rpms / qemu-kvm

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