From owner-freebsd-net@FreeBSD.ORG Thu Oct 11 02:07:14 2012 Return-Path: Delivered-To: net@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C63D2A2A; Thu, 11 Oct 2012 02:07:14 +0000 (UTC) (envelope-from mdounin@mdounin.ru) Received: from mdounin.cust.ramtel.ru (mdounin.cust.ramtel.ru [81.19.69.81]) by mx1.freebsd.org (Postfix) with ESMTP id 78AC88FC1B; Thu, 11 Oct 2012 02:07:14 +0000 (UTC) Received: from mdounin.ru (mdounin.cust.ramtel.ru [81.19.69.81]) by mdounin.cust.ramtel.ru (Postfix) with ESMTP id E0C0C1702D; Thu, 11 Oct 2012 06:07:12 +0400 (MSK) Date: Thu, 11 Oct 2012 06:07:12 +0400 From: Maxim Dounin To: Gleb Smirnoff Subject: Re: [CFT/Review] net byte order for AF_INET Message-ID: <20121011020712.GU40452@mdounin.ru> References: <20121009154128.GU34622@FreeBSD.org> <20121010195842.GH34622@FreeBSD.org> <20121010222651.GR40452@mdounin.ru> <20121010233404.GI34622@glebius.int.ru> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20121010233404.GI34622@glebius.int.ru> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: net@FreeBSD.org X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.14 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, 11 Oct 2012 02:07:14 -0000 Hello! On Thu, Oct 11, 2012 at 03:34:04AM +0400, Gleb Smirnoff wrote: [...] > This is de facto standard for raw sockets in most OS-es. Byte order > in raw socket is host. And this is the same behavior we had before > the patch. So no reason for extra comments. As I already pointed out (in an off-list message), many consider this as a "known bug" in many OSes instead. E.g. here is a quote from /usr/ports/net/openospfd/files/patch-ospfd_packet.c patch: @@ -70,7 +70,12 @@ ip_hdr.ip_v = IPVERSION; ip_hdr.ip_hl = sizeof(ip_hdr) >> 2; ip_hdr.ip_tos = IPTOS_PREC_INTERNETCONTROL; +#if defined(__FreeBSD__) || defined(__NetBSD__) + /* FreeBSD/NetBSD wants the length in the native host byte order. */ + ip_hdr.ip_len = len + sizeof(ip_hdr); +#else ip_hdr.ip_len = htons(len + sizeof(ip_hdr)); +#endif I would suggests it at least deserves a comment, and probably API change/fix too. [...] > --- sys/netinet/raw_ip.c (revision 241405) > +++ sys/netinet/raw_ip.c (working copy) > @@ -292,7 +292,7 @@ > * not modify the packet except for some > * byte order swaps. > */ > - ip->ip_len += off; > + ip->ip_len = ntohs(ip->ip_len) + off; So, you've moved a switch to host byteorder into rip_input(). What about ip->ip_off then? Note that this may also need some adjustments for protocols which use rip_output() but not rip_input() (or vice versa). [...] -- Maxim Dounin