[Click] Stupid question: Crafting packets with correct checksums...

Nicholas Weaver nweaver at ICSI.Berkeley.EDU
Mon May 19 12:15:32 EDT 2008


I figured it out.  I was being bad at setting the IPheader pointer  
correctly.  Changing it to a "don't bother in my code, passthrough  
MarkIPHeader and the sets and it works"

Again, I knew I was being stupid somehow.


On May 18, 2008, at 6:16 PM, Eddie Kohler wrote:

> Well, without seeing more of your code it'd be hard to tell.  I  
> think the SetTCPChecksum->SetIPChecksum pipeline should work,  
> assuming the IP header anntoation has been correctly set; tested:
>
> -----/tmp/x------
> !data src dst proto sport dport payload
> 1.0.0.1 2.0.0.2 T 10 20 "abcdefghijklmn"
>
> -----without checksum------
> % click -e 'FromIPSummaryDump(/tmp/x, STOP true) -> ToDump(-, ENCAP  
> IP)' | tcpdump -vnr -
> reading from file -, link-type RAW (Raw IP)
> 18:12:24.969786 IP (tos 0x0, id 0, offset 0, flags [none], proto TCP  
> (6), length 54, bad cksum 0 (->b7c0)!) 1.0.0.1.10 > 2.0.0.2.ftp- 
> data: ., cksum 0x0000 (incorrect (-> 0xd8db), 0:14(14) win 0
>
> -----with checksum------
> % click -e 'FromIPSummaryDump(/tmp/x, STOP true) -> SetTCPChecksum - 
> > SetIPChecksum -> ToDump(-, ENCAP IP)' | tcpdump -vnr -
> reading from file -, link-type RAW (Raw IP)
> 18:12:34.788939 IP (tos 0x0, id 0, offset 0, flags [none], proto TCP  
> (6), length 54) 1.0.0.1.10 > 2.0.0.2.ftp-data: ., cksum 0xd8db  
> (correct), 0:14(14) win 0
>
> Eddie
>
>
> Nicholas Weaver wrote:
>> I'm doing a little hacking where I'm crafting raw TCP packets.
>> Things seem to be going well looking at the data received on the  
>> other  side looking at TCPdump, except I can't seem to generate  
>> proper TCP  checksums, either with raw code or a pipeline of
>> SetTCPChecksum->SetIPChecksum
>> or with code in the file.  If it helps, this is on OS-X.  I feel  
>> like  I'm doing something incredibly stupid here, and I'm just  
>> missing  something obvious.
>> Suggestions?
>> I'm using the following code (taken from SetTCPChecksum and   
>> SetIPChecksum), where
>> dst_iph and dst_tcph as appropriate are pointing into a buffer of   
>> bytes I'm using to construct the packet.
>>     dst_iph->ip_len = htons(strlen(reply_string) + (dst_tcph- 
>> >th_off  << 2) +
>>                             (dst_iph->ip_hl << 2));
>>     unsigned plen, csum;
>>     dst_tcph->th_sum = 0;
>>     plen = ntohs(dst_iph->ip_len) - (dst_iph->ip_hl << 2);
>>     csum = click_in_cksum((unsigned char *) tcph, plen);
>>     dst_tcph->th_sum = click_in_cksum_pseudohdr(csum, dst_iph, plen);
>>     dst_iph->ip_sum = 0;
>>     dst_iph->ip_sum = click_in_cksum((unsigned char *)dst_iph,
>>                                      dst_iph->ip_hl << 2);
>>     WritablePacket * dst = Packet::make(data, ntohs(dst_iph- 
>> >ip_len)  + 14);
>>     dst->set_ip_header(dst_iph, dst_iph->ip_hl << 2);
>>     output(0).push(dst);
>> _______________________________________________
>> click mailing list
>> click at amsterdam.lcs.mit.edu
>> https://amsterdam.lcs.mit.edu/mailman/listinfo/click



More information about the click mailing list