examples/vhost: fix offload settings
authorYuanhan Liu <yuanhan.liu@linux.intel.com>
Fri, 25 Mar 2016 07:58:51 +0000 (15:58 +0800)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Fri, 25 Mar 2016 18:53:00 +0000 (19:53 +0100)
Comments for PKT_TX_TCP_SEG at rte_mbuf says that we should only set
PKT_TX_IP_CKSUM and reset ip hdr checksum for IPv4:

  - if it's IPv4, set the PKT_TX_IP_CKSUM flag and write the IP checksum
    to 0 in the packet

Fixes: 9fd72e3cbd29 ("examples/vhost: add virtio offload")

Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
examples/vhost/main.c

index ceabbce..86e5c24 100644 (file)
@@ -1163,10 +1163,13 @@ static void virtio_tx_offload(struct rte_mbuf *m)
 
        l3_hdr = (char *)eth_hdr + m->l2_len;
 
 
        l3_hdr = (char *)eth_hdr + m->l2_len;
 
-       ipv4_hdr = (struct ipv4_hdr *)l3_hdr;
+       if (m->ol_flags & PKT_TX_IPV4) {
+               ipv4_hdr = l3_hdr;
+               ipv4_hdr->hdr_checksum = 0;
+               m->ol_flags |= PKT_TX_IP_CKSUM;
+       }
+
        tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + m->l3_len);
        tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + m->l3_len);
-       m->ol_flags |= PKT_TX_IP_CKSUM;
-       ipv4_hdr->hdr_checksum = 0;
        tcp_hdr->cksum = get_psd_sum(l3_hdr, m->ol_flags);
 }
 
        tcp_hdr->cksum = get_psd_sum(l3_hdr, m->ol_flags);
 }