From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 8 23:29:03 2007 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BD1BF16A40F for ; Mon, 8 Jan 2007 23:29:03 +0000 (UTC) (envelope-from lee@nerds.org.uk) Received: from furby.nerds.org.uk (furby.nerds.org.uk [82.70.196.65]) by mx1.freebsd.org (Postfix) with ESMTP id 7244B13C44B for ; Mon, 8 Jan 2007 23:29:03 +0000 (UTC) (envelope-from lee@nerds.org.uk) Received: from lee by furby.nerds.org.uk with local (Exim 4.65 (FreeBSD)) (envelope-from ) id 1H43vH-000BQH-9y; Mon, 08 Jan 2007 23:28:59 +0000 Date: Mon, 8 Jan 2007 23:28:59 +0000 From: Lee Brotherston To: Julian Elischer Message-ID: <20070108232859.GI41066@nerds.org.uk> References: <20070108203211.GF41066@nerds.org.uk> <45A2BEEE.5010202@elischer.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <45A2BEEE.5010202@elischer.org> User-Agent: Mutt/1.5.13 (2006-08-11) X-Mailman-Approved-At: Tue, 09 Jan 2007 01:53:54 +0000 Cc: freebsd-hackers@freebsd.org Subject: Re: TCP Checksums in mbufs X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Jan 2007 23:29:03 -0000 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 -