summaryrefslogtreecommitdiffstats
path: root/sys/net/if_gre.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2012-10-22 21:09:03 +0000
committerglebius <glebius@FreeBSD.org>2012-10-22 21:09:03 +0000
commit5cc3ac590262ed14bfbf8392f27f90923b7cc7a1 (patch)
tree6e8c53bf2442763edea3176e3bef68bfec20a183 /sys/net/if_gre.c
parentaef46581d91a912fc587677321f83f81ce6df527 (diff)
downloadFreeBSD-src-5cc3ac590262ed14bfbf8392f27f90923b7cc7a1.zip
FreeBSD-src-5cc3ac590262ed14bfbf8392f27f90923b7cc7a1.tar.gz
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>
Diffstat (limited to 'sys/net/if_gre.c')
-rw-r--r--sys/net/if_gre.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/net/if_gre.c b/sys/net/if_gre.c
index 0a0857b..b72f064 100644
--- a/sys/net/if_gre.c
+++ b/sys/net/if_gre.c
@@ -356,7 +356,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
* RFC2004 specifies that fragmented diagrams shouldn't
* be encapsulated.
*/
- if (ip->ip_off & (IP_MF | IP_OFFMASK)) {
+ if (ip->ip_off & htons(IP_MF | IP_OFFMASK)) {
_IF_DROP(&ifp->if_snd);
m_freem(m);
error = EINVAL; /* is there better errno? */
@@ -410,7 +410,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
}
ip = mtod(m, struct ip *);
memcpy((caddr_t)(ip + 1), &mob_h, (unsigned)msiz);
- ip->ip_len = ntohs(ip->ip_len) + msiz;
+ ip->ip_len = htons(ntohs(ip->ip_len) + msiz);
} else { /* AF_INET */
_IF_DROP(&ifp->if_snd);
m_freem(m);
@@ -493,7 +493,7 @@ gre_output(struct ifnet *ifp, struct mbuf *m, struct sockaddr *dst,
((struct ip*)gh)->ip_ttl = GRE_TTL;
((struct ip*)gh)->ip_tos = gre_ip_tos;
((struct ip*)gh)->ip_id = gre_ip_id;
- gh->gi_len = m->m_pkthdr.len;
+ gh->gi_len = htons(m->m_pkthdr.len);
}
ifp->if_opackets++;
OpenPOWER on IntegriCloud