summaryrefslogtreecommitdiff
path: root/sys/netinet/udp_usrreq.c
diff options
context:
space:
mode:
authoritojun <itojun@NetBSD.org>2002-08-14 00:23:27 +0000
committeritojun <itojun@NetBSD.org>2002-08-14 00:23:27 +0000
commitc00fa8dfd94473cd4d82faf337bc894fd05b1788 (patch)
treeaed1c45a959ac358e9e677f0a0eb639a23390106 /sys/netinet/udp_usrreq.c
parentf5435ff1382d4883cd1fc56ae5cdd40fff8de1fd (diff)
avoid swapping endian of ip_len and ip_off on mbuf, to meet with M_LEADINGSPACE
optimization made last year. should solve PR 17867 and 10195. IP_HDRINCL behavior of raw ip socket is kept unchanged. we may want to provide IP_HDRINCL variant that does not swap endian.
Diffstat (limited to 'sys/netinet/udp_usrreq.c')
-rw-r--r--sys/netinet/udp_usrreq.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/sys/netinet/udp_usrreq.c b/sys/netinet/udp_usrreq.c
index b57a8fac66a..3c6150692e5 100644
--- a/sys/netinet/udp_usrreq.c
+++ b/sys/netinet/udp_usrreq.c
@@ -1,4 +1,4 @@
-/* $NetBSD: udp_usrreq.c,v 1.95 2002/06/30 22:40:37 thorpej Exp $ */
+/* $NetBSD: udp_usrreq.c,v 1.96 2002/08/14 00:23:36 itojun Exp $ */
/*
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.95 2002/06/30 22:40:37 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.96 2002/08/14 00:23:36 itojun Exp $");
#include "opt_inet.h"
#include "opt_ipsec.h"
@@ -216,6 +216,7 @@ udp_input(m, va_alist)
int iphlen, proto;
int len;
int n;
+ u_int16_t ip_len;
va_start(ap, m);
iphlen = va_arg(ap, int);
@@ -272,13 +273,14 @@ udp_input(m, va_alist)
* Make mbuf data length reflect UDP length.
* If not enough data to reflect UDP length, drop.
*/
+ ip_len = ntohs(ip->ip_len);
len = ntohs((u_int16_t)uh->uh_ulen);
- if (ip->ip_len != iphlen + len) {
- if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) {
+ if (ip_len != iphlen + len) {
+ if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
udpstat.udps_badlen++;
goto bad;
}
- m_adj(m, iphlen + len - ip->ip_len);
+ m_adj(m, iphlen + len - ip_len);
}
/*
@@ -892,7 +894,7 @@ udp_output(m, va_alist)
* Compute the packet length of the IP header, and
* punt if the length looks bogus.
*/
- if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) {
+ if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
error = EMSGSIZE;
goto release;
}
@@ -924,7 +926,7 @@ udp_output(m, va_alist)
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.ip_ttl; /* XXX */
((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */
udpstat.udps_opackets++;