Date: Thu, 11 Oct 2012 06:07:12 +0400 From: Maxim Dounin <mdounin@mdounin.ru> To: Gleb Smirnoff <glebius@FreeBSD.org> Cc: net@FreeBSD.org Subject: Re: [CFT/Review] net byte order for AF_INET Message-ID: <20121011020712.GU40452@mdounin.ru> In-Reply-To: <20121010233404.GI34622@glebius.int.ru> References: <20121009154128.GU34622@FreeBSD.org> <20121010195842.GH34622@FreeBSD.org> <20121010222651.GR40452@mdounin.ru> <20121010233404.GI34622@glebius.int.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20121011020712.GU40452>
