[v2] vhost: fix IPv4 csum calculation

Message ID 20191024162919.15009-1-fbl@sysclose.org (mailing list archive)
State Accepted, archived
Delegated to: Ferruh Yigit
Headers
Series [v2] vhost: fix IPv4 csum calculation |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-compilation success Compile Testing PASS
ci/travis-robot success Travis build: passed
ci/Intel-compilation success Compilation OK

Commit Message

Flavio Leitner Oct. 24, 2019, 4:29 p.m. UTC
  Currently the IPv4 header checksum is calculated including its
current value, which can be a valid checksum or just garbage.
In any case, if the original value is not zero, then the result
is always wrong.

The IPv4 checksum is defined in RFC791, page 14 says:
  Header Checksum:  16 bits

  The checksum algorithm is:
  The checksum field is the 16 bit one's complement of the one's
  complement sum of all 16 bit words in the header.  For purposes of
  computing the checksum, the value of the checksum field is zero.

Thus force the csum field to always be zero.

Fixes: b08b8cfeb2ae ("vhost: fix IP checksum")
Cc: stable@dpdk.org

Signed-off-by: Flavio Leitner <fbl@sysclose.org>
---
 lib/librte_vhost/virtio_net.c | 1 +
 1 file changed, 1 insertion(+)

v2:
  CC stable
  Added 'Fixes:' line.
  

Comments

Ferruh Yigit Oct. 24, 2019, 5:40 p.m. UTC | #1
On 10/24/2019 5:29 PM, Flavio Leitner wrote:
> Currently the IPv4 header checksum is calculated including its
> current value, which can be a valid checksum or just garbage.
> In any case, if the original value is not zero, then the result
> is always wrong.
> 
> The IPv4 checksum is defined in RFC791, page 14 says:
>   Header Checksum:  16 bits
> 
>   The checksum algorithm is:
>   The checksum field is the 16 bit one's complement of the one's
>   complement sum of all 16 bit words in the header.  For purposes of
>   computing the checksum, the value of the checksum field is zero.
> 
> Thus force the csum field to always be zero.
> 
> Fixes: b08b8cfeb2ae ("vhost: fix IP checksum")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Flavio Leitner <fbl@sysclose.org>

Applied to dpdk-next-net/master, thanks.
  

Patch

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index eae7825f04..cde7498c76 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -445,6 +445,7 @@  virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 
 		ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct rte_ipv4_hdr *,
 						   m_buf->l2_len);
+		ipv4_hdr->hdr_checksum = 0;
 		ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
 	}