bug in Packet::take() ?
Juan Luis Baptiste
juancho at linuxmail.org
Thu Oct 31 12:37:22 EST 2002
Hi Eddie,
>Did you change the length(s) declared in the IP header (ip6_plen or
>ip_len)? You'll need to do that as well -- and update the IP checksum.
Yes I do, but after doing the take() part, as it is in ftpportmapper.cc. Here is that part of the code:
WritablePacket *wp;
unsigned port_arg_len = pos - port_arg_offset;
int newlen = strlen(buf);
if (len < newlen)
wp = p->put(newlen - len);
else
{
wp = p->uniqueify();
wp->take(len - newlen);
}
memmove(wp->data() + data_offset + newlen,wp->data() + data_offset + len,len - pos);
memcpy(wp->data() + data_offset,buf,newlen);
// set IP length field, incrementally update IP checksum according to RFC1624
// new_sum = ~(~old_sum + ~old_halfword + new_halfword)
click_ip *wp_iph = wp->ip_header();
unsigned short old_ip_hw = ((unsigned short *)wp_iph)[1];
//UPDATING IP_LEN
wp_iph->ip_len = htons(wp->length() - wp->ip_header_offset());
unsigned short new_ip_hw = ((unsigned short *)wp_iph)[1];
//UPDATING IP CHECKSUM
unsigned ip_sum =
(~wp_iph->ip_sum & 0xFFFF) + (~old_ip_hw & 0xFFFF) + new_ip_hw;
while (ip_sum >> 16) // XXX necessary?
ip_sum = (ip_sum & 0xFFFF) + (ip_sum >> 16);
wp_iph->ip_sum = ~ip_sum;
[...]
Then I update seq numbers and recalculate TCP checksum.
Thanks,
Juan Luis
--
Powered by Outblaze
More information about the click
mailing list