Re: icmp checksum with build_data()s
Frédéric Raynal <[email protected]> Fri, 21 May 2004 20:17:06 +0200
| Newsgroups | gmane.comp.security.libnet |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I am currently at Berlin (others there ?)
As far as I can tell, you sould not use it that way: the checksums are
computed according to what is in the pblock, not after.
But you are right here: this problem is also present for all other
packets that do include paylaod in the checksum computation :(
raynal@Joker:~/LIBNET/libnet/src$ grep "h =" *c|grep payload
libnet_build_cdp.c: h = LIBNET_CDP_H + len + payload_s;
libnet_build_icmp.c: h = LIBNET_ICMPV4_ECHO_H + payload_s; /* hl for checksum */
libnet_build_icmp.c: h = LIBNET_ICMPV4_MASK_H + payload_s; /* hl for checksum */
libnet_build_icmp.c: h = LIBNET_ICMPV4_TS_H + payload_s; /* hl for checksum */
libnet_build_icmp.c: h = LIBNET_ICMPV4_UNREACH_H + payload_s + l->total_size;
libnet_build_icmp.c: h = LIBNET_ICMPV4_TIMXCEED_H + payload_s + l->total_size;
libnet_build_icmp.c: h = LIBNET_ICMPV4_REDIRECT_H + payload_s + l->total_size;
libnet_build_ospf.c: h = LIBNET_OSPF_H + payload_s + len;
libnet_build_ospf.c: h = len + payload_s;
libnet_build_vrrp.c: h = LIBNET_VRRP_H + payload_s;
Without any garantee, the solution might be to systematically include
"+ l->total_size;" so that the data is included each time it is
required for the checksum.
Fred Raynal
On Fri, May 21, 2004 at 10:10:03AM +0200, sandr8 wrote:
> i jot down the pseudocode for my unlucky program:
>
> 8<----------------------------
> libnet_init();
>
> for(;;){
> ~ libnet_build_data(payload_s=len_a);
> ~ libnet_build_data(payload_s=len_b);
> ~ libnet_build_data(payload_s=len_c);
> ~ libnet_build_icmpv4_echo(payload=NULL, payload_s=0);
> ~ libnet_build_ip();
> ~ libnet_write();
> }
> 8<----------------------------
>
> i've digged into what's happening and the problem is that the icmp
> checksum computed appears wrong.
> when it is computed against the icmp pblock, q->h_len is 8, while i'd
> really like it to be (8+len_c+len_b+len_a).
>
> i guess this should be the contract with the user programmers, but if
> it is done this way on purpose, then how should i do to precompute the
> checksum on my own and feed the result to libnet_build_icmpv4_echo()?
> is it possible to do it given the three payloads c, b, a without
> putting them together? otherwise i should need to join them together
> and then i would not even use libnet_build_data but just give the
> concatenated buffer to libnet_build_icmpv4_echo(). This would slow me
> down a bit, because of a double copy of data instead of the single one
> that libnet_pblock_coalesce() would perform when issued by libnet_write().
> please also CC me because i haven't been receiving mails from the list
> for a very long time.
> thank you in advance
> sandr8)
>