From owner-freebsd-hackers@FreeBSD.ORG Mon Jan 8 22:24: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 D875E16A403 for ; Mon, 8 Jan 2007 22:24:03 +0000 (UTC) (envelope-from lgusenet@be-well.ilk.org) Received: from mail1.sea5.speakeasy.net (mail1.sea5.speakeasy.net [69.17.117.3]) by mx1.freebsd.org (Postfix) with ESMTP id B677A13C458 for ; Mon, 8 Jan 2007 22:24:03 +0000 (UTC) (envelope-from lgusenet@be-well.ilk.org) Received: (qmail 29423 invoked from network); 8 Jan 2007 22:17:23 -0000 Received: from dsl092-078-145.bos1.dsl.speakeasy.net (HELO be-well.ilk.org) ([66.92.78.145]) (envelope-sender ) by mail1.sea5.speakeasy.net (qmail-ldap-1.03) with SMTP for ; 8 Jan 2007 22:17:23 -0000 Received: by be-well.ilk.org (Postfix, from userid 1147) id CCCB02842F; Mon, 8 Jan 2007 17:17:22 -0500 (EST) To: freebsd-hackers@freebsd.org References: <20070108203211.GF41066@nerds.org.uk> <45A2BEEE.5010202@elischer.org> From: Lowell Gilbert In-Reply-To: <45A2BEEE.5010202@elischer.org> (Julian Elischer's message of "Mon, 08 Jan 2007 14:00:14 -0800") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (berkeley-unix) Date: Mon, 08 Jan 2007 17:17:22 -0500 Message-ID: <44fyal88p9.fsf@be-well.ilk.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailman-Approved-At: Tue, 09 Jan 2007 01:52:15 +0000 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 22:24:03 -0000 Julian Elischer writes: > Lee Brotherston wrote: >> Hi, >> >> I have a bit of code I have written that uses pfil to access network >> traffic as it passes between interfaces on a FreeBSD router. One of >> the functions it performs is some incredibly basic rewrites of certain >> packets (keeping the same length, so no issues about sequence >> numbers), but it does alter the payload. >> >> I just wanted to check what is the "proper" way to be going about >> recalculating the checksums on the packet? I can write a function to >> do this and write this into the packet stored in the mbuf directly, >> however I wasn't sure if there was a more acceptable method such as >> flagging it to be re-checksum'd as it's routed, or to offload the >> computation to the NIC or something? >> >> Any thoughts, suggestions, etc very welcome! >> >> By the way, I'm not subscribed to the list right now, so I'd >> appreciate it if people could CC me on replies. >> >> Many thanks >> >> Lee > > 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. Actually, it is as easy as that (once you handle the possible overflow). And it's exactly the way this kind of case is usually handled. > 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 :-) RFC 1071, but that doesn't include the code. Just the one-sentence explanation of what to do. [And several more sentences of explanation...]