aboutsummaryrefslogtreecommitdiff
path: root/sys/netinet/ip_options.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_options.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_options.c')
-rw-r--r--sys/netinet/ip_options.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/sys/netinet/ip_options.c b/sys/netinet/ip_options.c
index c3c3535e3208..54a66b6930ca 100644
--- a/sys/netinet/ip_options.c
+++ b/sys/netinet/ip_options.c
@@ -490,7 +490,7 @@ ip_insertoptions(struct mbuf *m, struct mbuf *opt, int *phlen)
unsigned optlen;
optlen = opt->m_len - sizeof(p->ipopt_dst);
- if (optlen + ip->ip_len > IP_MAXPACKET) {
+ if (optlen + ntohs(ip->ip_len) > IP_MAXPACKET) {
*phlen = 0;
return (m); /* XXX should fail */
}
@@ -523,7 +523,7 @@ ip_insertoptions(struct mbuf *m, struct mbuf *opt, int *phlen)
*phlen = sizeof(struct ip) + optlen;
ip->ip_v = IPVERSION;
ip->ip_hl = *phlen >> 2;
- ip->ip_len += optlen;
+ ip->ip_len = htons(ntohs(ip->ip_len) + optlen);
return (m);
}