vhost: fix IPv4 csum calculation
PATCH 1/1 vhost: fix IPv4 csum calculation
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.
--- lib/librte_vhost/virtio_net.c | 1 + 1 file changed, 1 insertion(+)
lib/librte_vhost/virtio_net.c +1 -0
@@ -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); }
Signature · 1 line
2.20.1
Hi Flavio,
Quoted 8 lines · Flavio Leitner
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
Quoted 6 lines
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.
I think we need Fixes tag:
Also adding stable in Cc.
Quoted 11 lines
Signed-off-by Flavio Leitner <[email protected]>--- lib/librte_vhost/virtio_net.c | 1 + 1 file changed, 1 insertion(+)lib/librte_vhost/virtio_net.c +0
-0
lib/librte_vhost/virtio_net.c virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr) · line 451
Quoted 7 lines
lib/librte_vhost/virtio_net.c +1
-0@@ -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); }
Other than that:
I'll add the Fixes tag while applying.
Thanks!
Maxime
Quoted 47 lines · On Thu, 24 Oct 2019 16:32:43 +0200 Maxime Coquelin…
Hi Flavio,
Quoted 8 lines · Flavio Leitner
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 bitsQuoted 6 lines
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.
I think we need Fixes tag:
Fixes b08b8cfeb2ae ("vhost: fix IP checksum")Also adding stable in Cc.
Quoted 11 lines
Signed-off-by Flavio Leitner <[email protected]>--- lib/librte_vhost/virtio_net.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/lib/librte_vhost/virtio_net.cindexeae7825f04..cde7498c76100644lib/librte_vhost/virtio_net.c virtio_enqueue_offload(struct rte_mbuf *m_buf, · line 451
Quoted 7 lines
lib/librte_vhost/virtio_net.c +1
-0@@ -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); }Other than that:
Quoted 3 lines
Reviewed-by Maxime Coquelin <[email protected]>I'll add the Fixes tag while applying.
Not sure if you will send to stable, so I did v2 just in case. Feel free to drop either one if you took care of those items already. Thanks!
fbl
Quoted 50 lines · Flavio Leitner
Quoted 47 lines · On Thu, 24 Oct 2019 16:32:43 +0200 Maxime Coquelin…
Hi Flavio,
Quoted 8 lines · Flavio Leitner
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 bitsQuoted 6 lines
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.
I think we need Fixes tag:
Fixes b08b8cfeb2ae ("vhost: fix IP checksum")Also adding stable in Cc.
Quoted 11 lines
Signed-off-by Flavio Leitner <[email protected]>--- lib/librte_vhost/virtio_net.c | 1 + 1 file changed, 1 insertion(+)(quoted diff) +0
-0
b/lib/librte_vhost/virtio_net.cindexeae7825f04..cde7498c76100644lib/librte_vhost/virtio_net.c virtio_enqueue_offload(struct rte_mbuf *m_buf, · line 451
Quoted 7 lines
lib/librte_vhost/virtio_net.c +1
-0@@ -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); }Other than that:
Quoted 10 lines
Quoted 3 lines
Reviewed-by Maxime Coquelin <[email protected]>I'll add the Fixes tag while applying.
Not sure if you will send to stable, so I did v2 just in case. Feel free to drop either one if you took care of those items already. Thanks!
fbl
I synced with Ferruh, and he proposed to pick it directly for -rc1.
Thanks!
Maxime
PATCH v2 1/1 vhost: fix IPv4 csum calculation
In reply to Flavio LeitnerCurrently 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.
--- lib/librte_vhost/virtio_net.c | 1 + 1 file changed, 1 insertion(+)
v2:
CC stable
Added 'Fixes:' line.
lib/librte_vhost/virtio_net.c +1 -0
@@ -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); }
Signature · 1 line
2.20.1
Ferruh Yigit
AppliedQuoted 13 lines · Flavio Leitner
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 bitsThe 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.
Quoted 6 lines
Thus force the csum field to always be zero.
Fixes b08b8cfeb2ae ("vhost: fix IP checksum")Signed-off-by Flavio Leitner <[email protected]>
Applied to dpdk-next-net/master, thanks.