aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/ip_gre.c
diff options
context:
space:
mode:
authorGleb Smirnoff <glebius@FreeBSD.org>2012-10-22 21:09:03 +0000
committerGleb Smirnoff <glebius@FreeBSD.org>2012-10-22 21:09:03 +0000
commit8f134647ca14b930e2ab01b4192ce895127a6e02 (patch)
tree6e8c53bf2442763edea3176e3bef68bfec20a183 /sys/netinet/ip_gre.c
parentcb554de22232dd60f35883efa86e9470022a4569 (diff)
downloadsrc-8f134647ca14b930e2ab01b4192ce895127a6e02.tar.gz
src-8f134647ca14b930e2ab01b4192ce895127a6e02.zip
Switch the entire IPv4 stack to keep the IP packet header
in network byte order. Any host byte order processing is done in local variables and host byte order values are never[1] written to a packet. After this change a packet processed by the stack isn't modified at all[2] except for TTL. After this change a network stack hacker doesn't need to scratch his head trying to figure out what is the byte order at the given place in the stack. [1] One exception still remains. The raw sockets convert host byte order before pass a packet to an application. Probably this would remain for ages for compatibility. [2] The ip_input() still subtructs header len from ip->ip_len, but this is planned to be fixed soon. Reviewed by: luigi, Maxim Dounin <mdounin mdounin.ru> Tested by: ray, Olivier Cochard-Labbe <olivier cochard.me>
Notes
Notes: svn path=/head/; revision=241913
Diffstat (limited to 'sys/netinet/ip_gre.c')
-rw-r--r--sys/netinet/ip_gre.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/sys/netinet/ip_gre.c b/sys/netinet/ip_gre.c
index d0274decec44..07353111fa38 100644
--- a/sys/netinet/ip_gre.c
+++ b/sys/netinet/ip_gre.c
@@ -274,12 +274,10 @@ gre_mobile_input(struct mbuf *m, int hlen)
/*
* On FreeBSD, rip_input() supplies us with ip->ip_len
- * already converted into host byteorder and also decreases
- * it by the lengh of IP header, however, ip_input() expects
- * that this field is in the original format (network byteorder
- * and full size of IP packet), so that adjust accordingly.
+ * decreased by the lengh of IP header, however, ip_input()
+ * expects it to be full size of IP packet, so adjust accordingly.
*/
- ip->ip_len = htons(ip->ip_len + sizeof(struct ip) - msiz);
+ ip->ip_len = htons(ntohs(ip->ip_len) + sizeof(struct ip) - msiz);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, (ip->ip_hl << 2));