From owner-freebsd-hackers Wed May 17 22:50:44 2000 Delivered-To: freebsd-hackers@freebsd.org Received: from kbgroup.co.nz (gateway.kbgroup.co.nz [203.96.151.81]) by hub.freebsd.org (Postfix) with ESMTP id 09F7037BC48 for ; Wed, 17 May 2000 22:50:37 -0700 (PDT) (envelope-from dave.preece@kbgroup.co.nz) Received: from kb_exchange.kbgroup.co.nz ([202.202.203.10]) by gateway.kbgroup.co.nz with ESMTP id <115201>; Thu, 18 May 2000 18:06:03 +1200 Received: by internet.kbgroup.co.nz with Internet Mail Service (5.5.2650.21) id ; Thu, 18 May 2000 17:59:22 +1200 Message-ID: <67B808B0DD93D211ABEE0000B498356B02BBF9@internet.kbgroup.co.nz> From: Dave Preece To: hackers@freebsd.org Subject: Musings on ip checksumming MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: text/plain; charset="iso-8859-1" Date: Thu, 18 May 2000 18:05:56 +1200 Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG I'm trying to write a simple static NAT, and have got a bit stuck with the new checksum in the IP header.... thing with me is that I'm not happy about something till I understand it (and it appears that the IP stack is well behaved and won't send something unless the IP checksum is right either). Looking into ping.c for an example we have a checksum calculator (in_cksum) that I have been trying to understand. It takes a header and adds all the 16 bit words to a 32 bit acumulator. Fine. It then takes the top 16 bits and adds them to the bottom 16, (adding an additional one if this operation itself takes the resulting number to 17). Not what I understand as a checksum, but none the less a perfectly valid algorithm. What I *don't* understand is this: The routine appears to be written as if would only work on a big endian system i.e. this would only work if u_short's and int's were stored most significant byte first. This impression is further underscored by using >> 16 to fold the top 16 bits into the lower 16 bits. The pile of htons calls and ntohs calls I was expecting to see is simply not there. So, how come it works? Dave :) (but a bit confused) Ref: /usr/src/sbin/ping/ping.c /usr/src/lib/libalias/alias_local.h (ADJUST_CHECKSUM) To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message