Date: Mon, 8 Jan 2007 23:28:59 +0000 From: Lee Brotherston <lee@nerds.org.uk> To: Julian Elischer <julian@elischer.org> Cc: freebsd-hackers@freebsd.org Subject: Re: TCP Checksums in mbufs Message-ID: <20070108232859.GI41066@nerds.org.uk> In-Reply-To: <45A2BEEE.5010202@elischer.org> References: <20070108203211.GF41066@nerds.org.uk> <45A2BEEE.5010202@elischer.org>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 08, 2007 at 02:00:14PM -0800, Julian Elischer wrote:
> there is an algorythm to recalculate the tcp/ip
> checksum when you replace a byte. you subtract the old value from the
> csum and add the new one, but not quite a as easy as that.
>
> I think it's given in one of the RFCs but I think it may also
> be used in the tcpmss port, or possibly the mss fixup code in ppp.
> I know I've used it somewhere but forget where :-)
Aha! Would it be this one per chance?
/*-
* The following macro is used to update an
* internet checksum. "acc" is a 32-bit
* accumulation of all the changes to the
* checksum (adding in old 16-bit words and
* subtracting out new words), and "cksum"
* is the checksum value to be updated.
*/
#define ADJUST_CHECKSUM(acc, cksum) { \
acc += cksum; \
if (acc < 0) { \
acc = -acc; \
acc = (acc >> 16) + (acc & 0xffff); \
acc += acc >> 16; \
cksum = (u_short) ~acc; \
} else { \
acc = (acc >> 16) + (acc & 0xffff); \
acc += acc >> 16; \
cksum = (u_short) acc; \
} \
}
If so I'll set about using this... once I work out what the 32-bit
accumulation bit is :)
Thanks!
Lee
--
Lee Brotherston - <lee@nerds.org.uk>
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070108232859.GI41066>
