I'm sorry for all the fuzz. I'm really nagging the list.
I'm wondering what is the best way to calculate the IP checksum on the
microengines? As I'm aware, there are ways to optimize this calculation
for routers, as they usually only lower the ttl field, but I'm altering
the ip addresses. So I guess I'll have to recalculate the whole thing?
This function does this on the StrongARM:
ix_16bit_t CalcChecksum(ix_8bit_t *addr, ix_16bit_t size) {
ix_32bit_t sum = 0;
while ( size > 1 ) {
sum += *(unsigned short *)(void *)addr;
addr += 2;
size -= 2;
}
if ( size > 0 ) {
sum += *(unsigned char *)addr;
}
while ( sum >> 16 ) {
sum = ( sum & 0xffff ) + ( sum >> 16 );
}
return (~sum);
};
Now, how do I translate this function to microcode? Should I write my
values to memory, reread the header and calculate the checksum and then
write the checksum? Or should I calculate the checksum from GPRs holding
the values I want to write?
Sorry for another, prossibly stupid, question. I'm in a bit of a hurry u
see.
--
Øyvind Hvamstad
On Mon, 21 Jun 2004, Øyvind Hvamstad wrote:
As I'm aware, there are ways to optimize this calculation for routers, as they usually only lower the ttl field, but I'm altering the ip addresses. So I guess I'll have to recalculate the whole thing?
No. The properties of the IP checksum are such that if you modify a 16-bit value in the packet the new checksum is: newsum = ~(~oldsum + ~oldvalue + newvalue) see RFC 1624. Also, if you can precompute the difference you can eliminate an addition. Zuki -- Yitzchak Gottlieb zuki@CS.Princeton.EDU
On man, 2004-06-21 at 17:26, Yitzchak M. Gottlieb wrote:
No. The properties of the IP checksum are such that if you modify a 16-bit value in the packet the new checksum is:
newsum = ~(~oldsum + ~oldvalue + newvalue)
see RFC 1624. Also, if you can precompute the difference you can eliminate an addition.
Thanks, this is great! I am however having some problems when trying to verify that this is correct. It may be my lack in C knowledge or that I'm failing to do this correctly. My test program (attached source) spits out different values when doing the checksum incrementally compared to calculating the whole thing. I'm sure it my mistake, please correct me! Test output: Incremental checksum: f5a9 Header checksum after change: f5a8 Difference (incr - calc): 1 Incremental checksum: 26aa Header checksum after change: 26a9 Difference (incr - calc): 1 Incremental checksum: 23aa Header checksum after change: 23a8 Difference (incr - calc): 2 Incremental checksum: 54ab Header checksum after change: 54a8 Difference (incr - calc): 3
Zuki -- Øyvind Hvamstad
Not sure if the attachment was sucessfully applied. Here the test case
is inline:
#include
participants (2)
-
Yitzchak M. Gottlieb
-
Øyvind Hvamstad