[CFT/Review] net byte order for AF_INET
Maxim Dounin
mdounin at mdounin.ru
Thu Oct 11 02:07:14 UTC 2012
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
More information about the freebsd-net
mailing list