Skip to content

Commit

Permalink
vhost: fix IPv4 checksum
Browse files Browse the repository at this point in the history
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: b08b8cf ("vhost: fix IP checksum")
Cc: stable@dpdk.org

Signed-off-by: Flavio Leitner <fbl@sysclose.org>
Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>
  • Loading branch information
fleitner authored and Ferruh Yigit committed Oct 25, 2019
1 parent 19b8d75 commit 84c39be
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/librte_vhost/virtio_net.c
Expand Up @@ -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);
}

Expand Down

0 comments on commit 84c39be

Please sign in to comment.