Re: [SOLVED] Re: webserver stalls [was Re: bug in (linux) slattach]

jb1
2002-10-23T09:37:40Z

On 22 Oct 2002, Harry Kalogirou wrote:

> Actualy the quest is over now... as previously I managed to commit half
> the patch to the CVS...

Maybe not. I found ip.c Version 1.9 by browsing the CVS repository and, as
far as I can tell, the only change was that you moved the first "dec cx";
this will have *no* effect. The algorithm can still fail if the carry flag
happens to be set going into the routine, or if there is a carry generated
the last time "adc [di]" is executed. I suggest something like this for
_ip_calc_chksum:

push bp
mov bp,sp
push di

mov cx, 6[bp]
sar cx, 1
dec cx
xor ax,ax ; clear carry flag (as well as AX)
mov di, 4[bp]
mov ax, [di]
inc di
inc di
loop1:
adc ax, [di]
inc di
inc di

loop loop1; ; a byte shorter and a clock faster
; than DEC CX/JNZ LOOP1

adc ax,0 ; add (just) the final carry
not ax

pop di
pop bp

ret

Of course, this algorithm is valid only if the length (6[bp]) is an even
number of bytes. While this is always true for IP headers, for TCP packet
checksums there would have to be a final test of the length's low bit and
appropriate handling of an additional odd byte.

I ran the original routine on my "defective" packet IP Header using
MSDOS' "debug" (with the carry initially clear and the data
byte-swapped in memory) and got the correct checksum. Were there any other
updated files I should have downloaded from the CVS repository?