[dpdk-dev,2/2] vhost: fix IP csum not calculated

Message ID 1496817697-49130-3-git-send-email-jianfeng.tan@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Yuanhan Liu
Headers

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation success Compilation OK

Commit Message

Jianfeng Tan June 7, 2017, 6:41 a.m. UTC
  There is no way to bypass IP checksum verification in Linux
kernel, no matter skb->ip_summed is assigned as CHECKSUM_UNNECESSARY
or CHECKSUM_PARTIAL.

So any packets with bad IP checksum will be dropped at VM IP layer.

To correct, we check this flag PKT_TX_IP_CKSUM to calculate IP csum.

Fixes: 859b480d5afd ("vhost: add guest offload setting")
Cc: stable@dpdk.org

Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
Cc: Jiayu Hu <jiayu.hu@intel.com>
Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
---
 lib/librte_vhost/virtio_net.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Maxime Coquelin June 7, 2017, 7:28 p.m. UTC | #1
On 06/07/2017 08:41 AM, Jianfeng Tan wrote:
> There is no way to bypass IP checksum verification in Linux
> kernel, no matter skb->ip_summed is assigned as CHECKSUM_UNNECESSARY
> or CHECKSUM_PARTIAL.
> 
> So any packets with bad IP checksum will be dropped at VM IP layer.
> 
> To correct, we check this flag PKT_TX_IP_CKSUM to calculate IP csum.
> 
> Fixes: 859b480d5afd ("vhost: add guest offload setting")
> Cc: stable@dpdk.org
> 
> Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>
> Cc: Jiayu Hu <jiayu.hu@intel.com>
> Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
> ---
>   lib/librte_vhost/virtio_net.c | 9 +++++++++
>   1 file changed, 9 insertions(+)


Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime

> 
> diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
> index 0a7e023..cf7c5ac 100644
> --- a/lib/librte_vhost/virtio_net.c
> +++ b/lib/librte_vhost/virtio_net.c
> @@ -143,6 +143,15 @@ virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
>   		ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0);
>   	}
>   
> +	/* IP cksum verification cannot be bypassed, then calculate here */
> +	if (m_buf->ol_flags & PKT_TX_IP_CKSUM) {
> +		struct ipv4_hdr *ipv4_hdr;
> +
> +		ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct ipv4_hdr *,
> +						   m_buf->l2_len);
> +		ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
> +	}
> +
>   	if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
>   		if (m_buf->ol_flags & PKT_TX_IPV4)
>   			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;
>
  

Patch

diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index 0a7e023..cf7c5ac 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -143,6 +143,15 @@  virtio_enqueue_offload(struct rte_mbuf *m_buf, struct virtio_net_hdr *net_hdr)
 		ASSIGN_UNLESS_EQUAL(net_hdr->flags, 0);
 	}
 
+	/* IP cksum verification cannot be bypassed, then calculate here */
+	if (m_buf->ol_flags & PKT_TX_IP_CKSUM) {
+		struct ipv4_hdr *ipv4_hdr;
+
+		ipv4_hdr = rte_pktmbuf_mtod_offset(m_buf, struct ipv4_hdr *,
+						   m_buf->l2_len);
+		ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
+	}
+
 	if (m_buf->ol_flags & PKT_TX_TCP_SEG) {
 		if (m_buf->ol_flags & PKT_TX_IPV4)
 			net_hdr->gso_type = VIRTIO_NET_HDR_GSO_TCPV4;