examples/tep_term: fix inner L4 checksum
authorJianfeng Tan <jianfeng.tan@intel.com>
Thu, 4 Aug 2016 07:58:49 +0000 (07:58 +0000)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Thu, 13 Oct 2016 12:37:48 +0000 (14:37 +0200)
When sending packets from virtual machine which in need of TSO
by hardware NIC, the inner L4 checksum is not correct on the
other side of the cable.

It's because get_psd_sum() depends on PKT_TX_TCP_SEG to calculate
pseudo-header checksum, but currently this bit is set after the
function get_psd_sum() is called. The fix is straightforward.
Move the bit setting before get_psd_sum() is called.

Fixes: a50245ede72a ("examples/tep_term: initialize VXLAN sample")

Signed-off-by: Jianfeng Tan <jianfeng.tan@intel.com>
examples/tep_termination/vxlan.c

index 4bad33d..155415c 100644 (file)
@@ -141,14 +141,17 @@ process_inner_cksums(struct ether_hdr *eth_hdr, union tunnel_offload_info *info)
                                ethertype, ol_flags);
        } else if (l4_proto == IPPROTO_TCP) {
                tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + info->l3_len);
-               ol_flags |= PKT_TX_TCP_CKSUM;
-               tcp_hdr->cksum = get_psd_sum(l3_hdr, ethertype,
-                               ol_flags);
+               /* Put PKT_TX_TCP_SEG bit setting before get_psd_sum(), because
+                * it depends on PKT_TX_TCP_SEG to calculate pseudo-header
+                * checksum.
+                */
                if (tso_segsz != 0) {
                        ol_flags |= PKT_TX_TCP_SEG;
                        info->tso_segsz = tso_segsz;
                        info->l4_len = sizeof(struct tcp_hdr);
                }
+               ol_flags |= PKT_TX_TCP_CKSUM;
+               tcp_hdr->cksum = get_psd_sum(l3_hdr, ethertype, ol_flags);
 
        } else if (l4_proto == IPPROTO_SCTP) {
                sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);