From owner-freebsd-net@FreeBSD.ORG Tue Jul 17 14:18:03 2007 Return-Path: X-Original-To: freebsd-net@freebsd.org Delivered-To: freebsd-net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 0420B16A401 for ; Tue, 17 Jul 2007 14:18:03 +0000 (UTC) (envelope-from raj@thenewfront.us) Received: from an-out-0708.google.com (an-out-0708.google.com [209.85.132.248]) by mx1.freebsd.org (Postfix) with ESMTP id C310113C4A6 for ; Tue, 17 Jul 2007 14:18:02 +0000 (UTC) (envelope-from raj@thenewfront.us) Received: by an-out-0708.google.com with SMTP id c14so359658anc for ; Tue, 17 Jul 2007 07:18:02 -0700 (PDT) Received: by 10.100.95.19 with SMTP id s19mr201596anb.1184680186173; Tue, 17 Jul 2007 06:49:46 -0700 (PDT) Received: from ?10.10.2.161? ( [67.90.137.89]) by mx.google.com with ESMTP id c39sm14222789anc.2007.07.17.06.49.42 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Jul 2007 06:49:42 -0700 (PDT) User-Agent: Microsoft-Entourage/11.0.0.040405 Date: Tue, 17 Jul 2007 09:49:35 -0400 From: Raj To: Message-ID: In-Reply-To: <20070717120011.4E14D16A419@hub.freebsd.org> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit Subject: Tcp checksum calculation wrong by 2 X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 17 Jul 2007 14:18:03 -0000 Hi Folks, This problem is related to Mac OS X 10.3. Please accept my apologies for posting here , as I thought this is one avenue I could explore to get an answer and also OS X has some freebsd core too! I am looking at a driver code for OS X 10.3 where the checksum is being calculated on an inbound syn-ack. First by zeroing out the checksum, then calculating the checksum of the pseudo header and finally calculating the checksum. The checksum functions used are available in the xnu sources. Here is the snippet printf("tcplen =%x",tcplen); printf(" checksum Before=%x,\n",tcph->th_sum); tcph->th_sum=0; tcph->th_sum = in_pseudo(iph->ip_src.s_addr, iph->ip_dst.s_addr, htonl((iph->ip_p << 16) | (tcplen & 0xffff))); tcph->th_sum = in_cksum_skip(mbuf, packet_len, iph->ip_hl << 2); printf("final checksum tcph=%x,\n",tcph->th_sum); The final checksum is less by 2 than the original. Here is the sample output tcplen=26 checksum before =7182 final checksum=7180 tcplen=26 checksum before =2d87 final checksum=2d85 tcplen=26 checksum before =5ab0 final checksum=5aae I have also observed that the checksum is calculated correctly when the length of the tcp segment in the packet is 40. tcplen=40 checksum before =d1cf final checksum=d1cf tcplen=40 checksum before =e237 final checksum=e237 Can someone be kind enough to give me an idea on why I am getting the wrong checksum? TIA Raj