<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)"><<a href="mailto:htmldeveloper@gmail.com" target="_blank">htmldeveloper@gmail.com</a>></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've tested that, my hardware apparently doesn'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->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->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->check = csum_tcpudp_magic(iph->saddr, iph->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->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->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 "0" 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->len - (iph->ihl << 2));/* tcplen is the length of the skb - the ip-header length */</div>
<div class="gmail_extra"> tcph->check = 0;</div><div class="gmail_extra"> tcph->check = tcp_v4_check(tcplen,</div><div class="gmail_extra"> iph->saddr,</div>
<div class="gmail_extra"> iph->daddr,</div><div class="gmail_extra"> csum_partial((char*) tcph, tcplen, 0));</div><div class="gmail_extra"> skb->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>