summaryrefslogtreecommitdiffstats
path: root/sys/netinet/udp_usrreq.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/netinet/udp_usrreq.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/netinet/udp_usrreq.c')
-rw-r--r--sys/netinet/udp_usrreq.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index ff52577..2576cf5 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -338,7 +338,7 @@ udp_input(struct mbuf *m, int off)
struct udphdr *uh;
struct ifnet *ifp;
struct inpcb *inp;
- int len;
+ uint16_t len, ip_len;
struct ip save_ip;
struct sockaddr_in udp_in;
#ifdef IPFIREWALL_FORWARD
@@ -392,13 +392,13 @@ udp_input(struct mbuf *m, int off)
* reflect UDP length, drop.
*/
len = ntohs((u_short)uh->uh_ulen);
- if (ip->ip_len != len) {
- if (len > ip->ip_len || len < sizeof(struct udphdr)) {
+ ip_len = ntohs(ip->ip_len);
+ if (ip_len != len) {
+ if (len > ip_len || len < sizeof(struct udphdr)) {
UDPSTAT_INC(udps_badlen);
goto badunlocked;
}
- m_adj(m, len - ip->ip_len);
- /* ip->ip_len = len; */
+ m_adj(m, len - ip_len);
}
/*
@@ -601,7 +601,7 @@ udp_input(struct mbuf *m, int off)
if (badport_bandlim(BANDLIM_ICMP_UNREACH) < 0)
goto badunlocked;
*ip = save_ip;
- ip->ip_len += iphlen;
+ ip->ip_len = htons(ip_len + iphlen);
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
return;
}
@@ -1206,7 +1206,7 @@ udp_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr,
struct ip *ip;
ip = (struct ip *)&ui->ui_i;
- ip->ip_off |= IP_DF;
+ ip->ip_off |= htons(IP_DF);
}
ipflags = 0;
@@ -1233,7 +1233,7 @@ udp_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr,
m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
} else
ui->ui_sum = 0;
- ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len;
+ ((struct ip *)ui)->ip_len = htons(sizeof(struct udpiphdr) + len);
((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */
((struct ip *)ui)->ip_tos = tos; /* XXX */
UDPSTAT_INC(udps_opackets);
@@ -1383,7 +1383,7 @@ udp4_espdecap(struct inpcb *inp, struct mbuf *m, int off)
m_adj(m, skip);
ip = mtod(m, struct ip *);
- ip->ip_len -= skip;
+ ip->ip_len = htons(ntohs(ip->ip_len) - skip);
ip->ip_p = IPPROTO_ESP;
/*
OpenPOWER on IntegriCloud