From owner-freebsd-net@FreeBSD.ORG Thu Jul 10 21:06:33 2008 Return-Path: Delivered-To: net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 002171065672; Thu, 10 Jul 2008 21:06:32 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.freebsd.org (Postfix) with ESMTP id CF22E8FC1F; Thu, 10 Jul 2008 21:06:32 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 647D446B49; Thu, 10 Jul 2008 17:06:32 -0400 (EDT) Date: Thu, 10 Jul 2008 22:06:32 +0100 (BST) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: gnn@FreeBSD.org In-Reply-To: Message-ID: <20080710220201.K34050@fledge.watson.org> References: <20080710114028.T34050@fledge.watson.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: net@FreeBSD.org Subject: Re: What's the deal with hardware checksum and net.inet.udp.checksum? 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: Thu, 10 Jul 2008 21:06:33 -0000 On Thu, 10 Jul 2008, gnn@FreeBSD.org wrote: > If the sysctl it turned off on the transmitter then the receiving machine > sees UDP checksums of 0. Right. If you disable UDP checksumming, we don't generate checksums (hardware or software) in udp_output(): /* * Set up checksum and output datagram. */ if (udp_cksum) { if (inp->inp_flags & INP_ONESBCAST) faddr.s_addr = INADDR_BROADCAST; ui->ui_sum = in_pseudo(ui->ui_src.s_addr, faddr.s_addr, htons((u_short)len + sizeof(struct udphdr) + IPPROTO_UDP)); m->m_pkthdr.csum_flags = CSUM_UDP; m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); } else ui->ui_sum = 0; You can disable hardware checksums using the -txcsum flag on ifconfig for each interface -- once the above-generated mbuf header gets to the IP layer and the route out an interface is available, we on-demand generate checksum in software if hardware checksums aren't available or are administratively disabled. Vis ip_output(): m->m_pkthdr.csum_flags |= CSUM_IP; sw_csum = m->m_pkthdr.csum_flags & ~ifp->if_hwassist; if (sw_csum & CSUM_DELAY_DATA) { in_delayed_cksum(m); sw_csum &= ~CSUM_DELAY_DATA; } m->m_pkthdr.csum_flags &= ifp->if_hwassist; It's possible to imagine adding a global sysctl that has slightly different policy implications, such as globally disabling hardware checksums, or not generating full checksums if the interface doesn't support hardware checksums rather than generating them. Robert N M Watson Computer Laboratory University of Cambridge