<div dir="ltr"><span style="color:rgb(80,0,80)">On Tue, Jun 25, 2013 at 6:19 AM, Peter Teoh </span><span dir="ltr" style="color:rgb(80,0,80)">&lt;<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>&gt;</span><span style="color:rgb(80,0,80)"> wrote:</span><br>

<div class="gmail_quote"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div>c.   if your hardware is not capable to do TCP offloading, then the LONG way is to start from beginning of packet to end of packet, and calculate checksum.</div>


</blockquote></div><div>I&#39;ve tested that, my hardware apparently doesn&#39;t support TCP offloading.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">

<div>d.   if u keep the previous checksum, ie (th-&gt;checksum=0 is not needed at all), and u know exactly which byte u modify, then just do a xor of the modified byte with the previous checksum, and u get the new checksum.....this is the preferred and fastest way.</div>



<div><br></div><div>so in summary:</div><div><br></div><span style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">th-&gt;check = 0;</span><br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">



<span style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">th-&gt;check = csum_tcpudp_magic(iph-&gt;saddr, iph-&gt;daddr,</span><br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">



<span style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">datalen, iph-&gt;protocol,</span><br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">



<span style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">csum_partial((char *)th, datalen, 0));</span><br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">



<span style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">skb-&gt;ip_summed = CHECKSUM_UNNECESSARY;</span><br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif">



<br style="line-height:16px;color:rgb(38,38,38);font-size:12.800000190734863px;font-family:arial,sans-serif"><div><font color="#262626" face="arial, sans-serif"><span style="line-height:16px">your setting of &quot;0&quot; above is correct, is because u want to calculate the checksum OVERALL....ie, packet start to packet end......demarcate correctly and u should get the answer....NOT csum_partial().....partial checksumming does not apply here.</span></font></div>



<div><br></div></div><div><span><font color="#888888">-- <br>Regards,<br>Peter Teoh
</font></span></div>
</blockquote></div><br></div><div class="gmail_extra">Well, the problem is now solved, it seems that the error was with the fact that some skbs are not linear and I was ignoring this fact.</div><div class="gmail_extra">
Fixed it by the following:<br><br></div><div class="gmail_extra"><div class="gmail_extra">                tcph = tcp_hdr(skb);</div><div class="gmail_extra">                if(skb_is_nonlinear(skb))</div><div class="gmail_extra">


                                 skb_linearize(skb)</div><div class="gmail_extra"><br></div><div class="gmail_extra">                tcplen = (skb-&gt;len - (iph-&gt;ihl &lt;&lt; 2));/* tcplen is the length of the skb - the ip-header length */</div>


<div class="gmail_extra">                tcph-&gt;check = 0;</div><div class="gmail_extra">                tcph-&gt;check = tcp_v4_check(tcplen,</div><div class="gmail_extra">                                iph-&gt;saddr,</div>


<div class="gmail_extra">                                iph-&gt;daddr,</div><div class="gmail_extra">                                csum_partial((char*) tcph, tcplen, 0));</div><div class="gmail_extra">                skb-&gt;ip_summed = CHECKSUM_NONE;/* in case another hardware has TCP offloading */</div>


<div class="gmail_extra"><br></div><div class="gmail_extra">Thanks a lot, anyhow :D </div><div><br></div></div></div>
</div><br></div>