title: TCP checksum error for fragmented packets
body: <p>I'm working on a server/client socket application that is using Linux TUN interface.</p>
  
  <p>Server gets packets directly from TUN interface and pass them to clients and clients put received packets directly in the TUN interface.</p>
  
  <pre><code>&lt;Server_TUN---&gt;&lt;---Server---&gt;&lt;---Clients---&gt;&lt;---Client_TUN---&gt;
  </code></pre>
  
  <p>Sometimes the packets from Server_TUN need to be fragmented in IP layer before transmitting to a client. </p>
  
  <p>So at the server I read a packet from TUN, start fragmenting it in the IP layer and send them via socket to clients.</p>
  
  <p>When the fragmentation logic was implemented, the solution did not work well. </p>
  
  <p>After starting Wireshark on Client_TUN I noticed for all incoming fragmented packets I get TCP Checksum error.</p>
  
  <p><a href="https://i.stack.imgur.com/AIxiz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AIxiz.png" alt="wireshark capture"></a></p>
  
  <p>At the given screenshot, frame number 154 is claimed to be reassembled in in 155.</p>
  
  <p>But TCP checksum is claimed to be incorrect!</p>
  
  <p>At server side, I keep tcp data intact and for the given example, while you see the reverse in Wireshark, I've split a packet with 1452 bytes (including IP header) and 30 bytes (Including IP header)</p>
  
  <p>I've also checked the TCP checksum value at the server and its exactly is 0x935e and while I did not think that Checksum offloading matters for incoming packets, I checked offloading at the client and it was off.</p>
  
  <pre><code>$ sudo ethtool -k tun0 | grep ": on"
  scatter-gather: on
  tx-scatter-gather: on
  tx-scatter-gather-fraglist: on
  generic-segmentation-offload: on
  generic-receive-offload: on
  tx-vlan-offload: on
  tx-vlan-stag-hw-insert: on
  </code></pre>
  
  <p>Despite that, because of the solution is not working now, I don't think its caused by offload effect.</p>
  
  <p>Do you have any idea why TCP checksum could be incorrect for fragmented packets?</p>