Subject: getting rid of NTOHS() in ip_input()
To: None <tech-net@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@iijlab.net>
List: tech-net
Date: 08/13/2002 07:57:34
this patch will get rid of NTOHS() in ip_input(), and tries to
keep mbuf left unmodified. this is needed to make M_LEADINGSPACE
optimization added in sys/sys/mbuf.h 1.59 (2001/7/26) to work
properly.
i tried not to touch any of ipfilter stuff.
comments/suggestions are welcome.
itojun
Index: net/if_gre.c
===================================================================
RCS file: /cvsroot/syssrc/sys/net/if_gre.c,v
retrieving revision 1.41
diff -u -1 -r1.41 if_gre.c
--- net/if_gre.c 2002/08/12 05:22:57 1.41
+++ net/if_gre.c 2002/08/12 22:57:49
@@ -276,4 +276,3 @@
memcpy((caddr_t)(ip + 1), &mob_h, (unsigned)msiz);
- NTOHS(ip->ip_len);
- ip->ip_len += msiz;
+ ip->ip_len = htons(ntohs(ip->ip_len) + msiz);
} else { /* AF_INET */
Index: net/if_stf.c
===================================================================
RCS file: /cvsroot/syssrc/sys/net/if_stf.c,v
retrieving revision 1.28
diff -u -1 -r1.28 if_stf.c
--- net/if_stf.c 2002/08/06 04:58:57 1.28
+++ net/if_stf.c 2002/08/12 22:57:49
@@ -436,3 +436,3 @@
ip->ip_ttl = ip_gif_ttl; /*XXX*/
- ip->ip_len = m->m_pkthdr.len; /*host order*/
+ ip->ip_len = htons(m->m_pkthdr.len);
if (ifp->if_flags & IFF_LINK1)
Index: netinet/igmp.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/igmp.c,v
retrieving revision 1.30
diff -u -1 -r1.30 igmp.c
--- netinet/igmp.c 2002/06/30 22:40:33 1.30
+++ netinet/igmp.c 2002/08/12 22:57:49
@@ -162,3 +162,3 @@
minlen = iphlen + IGMP_MINLEN;
- if (ip->ip_len < minlen) {
+ if (ntohs(ip->ip_len) < minlen) {
++igmpstat.igps_rcv_tooshort;
@@ -183,3 +183,3 @@
/* No need to assert alignment here. */
- if (in_cksum(m, ip->ip_len - iphlen)) {
+ if (in_cksum(m, ntohs(ip->ip_len) - iphlen)) {
++igmpstat.igps_rcv_badsum;
@@ -528,4 +528,4 @@
ip->ip_tos = 0;
- ip->ip_len = sizeof(struct ip) + IGMP_MINLEN;
- ip->ip_off = 0;
+ ip->ip_len = htons(sizeof(struct ip) + IGMP_MINLEN);
+ ip->ip_off = htons(0);
ip->ip_p = IPPROTO_IGMP;
Index: netinet/in_gif.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/in_gif.c,v
retrieving revision 1.28
diff -u -1 -r1.28 in_gif.c
--- netinet/in_gif.c 2002/07/14 21:09:17 1.28
+++ netinet/in_gif.c 2002/08/12 22:57:49
@@ -172,3 +172,3 @@
iphdr.ip_ttl = ip_gif_ttl;
- iphdr.ip_len = m->m_pkthdr.len + sizeof(struct ip);
+ iphdr.ip_len = htons(m->m_pkthdr.len + sizeof(struct ip));
if (ifp->if_flags & IFF_LINK1)
Index: netinet/ip_frag.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_frag.c,v
retrieving revision 1.31
diff -u -1 -r1.31 ip_frag.c
--- netinet/ip_frag.c 2002/06/09 16:33:40 1.31
+++ netinet/ip_frag.c 2002/08/12 22:57:49
@@ -219,3 +219,3 @@
*/
- off = ip->ip_off & IP_OFFMASK;
+ off = ntohs(ip->ip_off) & IP_OFFMASK;
if (!off)
@@ -353,3 +353,3 @@
if (off == f->ipfr_off) {
- if (!(ip->ip_off & IP_MF))
+ if (!(ip->ip_off & htons(IP_MF)))
f->ipfr_ttl = 1;
Index: netinet/ip_gre.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_gre.c,v
retrieving revision 1.20
diff -u -1 -r1.20 ip_gre.c
--- netinet/ip_gre.c 2002/08/10 05:40:54 1.20
+++ netinet/ip_gre.c 2002/08/12 22:57:49
@@ -299,4 +299,3 @@
m->m_len -= msiz;
- ip->ip_len -= msiz;
- HTONS(ip->ip_len);
+ ip->ip_len = htons(ntohs(ip->ip_len) - msiz);
m->m_pkthdr.len -= msiz;
Index: netinet/ip_icmp.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_icmp.c,v
retrieving revision 1.69
diff -u -1 -r1.69 ip_icmp.c
--- netinet/ip_icmp.c 2002/06/30 22:40:34 1.69
+++ netinet/ip_icmp.c 2002/08/12 22:57:50
@@ -250,3 +250,3 @@
goto freeit;
- if (oip->ip_off &~ (IP_MF|IP_DF))
+ if (oip->ip_off &~ htons(IP_MF|IP_DF))
goto freeit;
@@ -273,3 +273,4 @@
*/
- icmplen = oiplen + min(icmpreturndatabytes, oip->ip_len - oiplen);
+ icmplen = oiplen + min(icmpreturndatabytes,
+ ntohs(oip->ip_len) - oiplen);
/*
@@ -330,4 +331,2 @@
- HTONS(oip->ip_off);
- HTONS(oip->ip_len);
icp->icmp_code = code;
@@ -350,5 +349,5 @@
nip->ip_tos = 0;
- nip->ip_len = m->m_len;
+ nip->ip_len = htons(m->m_len);
/* ip_id set in ip_output */
- nip->ip_off = 0;
+ nip->ip_off = htons(0);
/* ip_ttl set in icmp_reflect */
@@ -401,3 +400,3 @@
*/
- icmplen = ip->ip_len - hlen;
+ icmplen = ntohs(ip->ip_len) - hlen;
#ifdef ICMPPRINTFS
@@ -504,3 +503,2 @@
goto badcode;
- NTOHS(icp->icmp_ip.ip_len);
#ifdef ICMPPRINTFS
@@ -823,3 +821,3 @@
*/
- ip->ip_len -= optlen;
+ ip->ip_len = htons(ntohs(ip->ip_len) - optlen);
ip->ip_hl = sizeof(struct ip) >> 2;
@@ -857,3 +855,3 @@
icp->icmp_cksum = 0;
- icp->icmp_cksum = in_cksum(m, ip->ip_len - hlen);
+ icp->icmp_cksum = in_cksum(m, ntohs(ip->ip_len) - hlen);
m->m_data -= hlen;
@@ -993,3 +991,3 @@
- mtu = icp->icmp_ip.ip_len; /* NTOHS happened in deliver: */
+ mtu = ntohs(icp->icmp_ip.ip_len);
/* Some 4.2BSD-based routers incorrectly adjust the ip_len */
Index: netinet/ip_input.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_input.c,v
retrieving revision 1.154
diff -u -1 -r1.154 ip_input.c
--- netinet/ip_input.c 2002/06/30 22:40:34 1.154
+++ netinet/ip_input.c 2002/08/12 22:57:50
@@ -574,8 +574,2 @@
/*
- * Convert fields to host representation.
- */
- NTOHS(ip->ip_len);
- NTOHS(ip->ip_off);
-
- /*
* Process options and, if not destined for us,
@@ -724,3 +718,3 @@
*/
- if (ip->ip_off & ~(IP_DF|IP_RF)) {
+ if (ntohs(ip->ip_off) & ~(IP_DF|IP_RF)) {
/*
@@ -744,4 +738,4 @@
*/
- ip->ip_len -= hlen;
- mff = (ip->ip_off & IP_MF) != 0;
+ ip->ip_len = htons(ntohs(ip->ip_len) - hlen);
+ mff = (ntohs(ip->ip_off) & IP_MF) != 0;
if (mff) {
@@ -751,3 +745,4 @@
*/
- if (ip->ip_len == 0 || (ip->ip_len & 0x7) != 0) {
+ if (ntohs(ip->ip_len) == 0 ||
+ (ntohs(ip->ip_len) & 0x7) != 0) {
ipstat.ips_badfrags++;
@@ -757,3 +752,3 @@
}
- ip->ip_off <<= 3;
+ ip->ip_off = htons((ntohs(ip->ip_off) & 0x1fff) << 3);
@@ -764,3 +759,3 @@
*/
- if (mff || ip->ip_off) {
+ if (mff || ntohs(ip->ip_off)) {
ipstat.ips_fragments++;
@@ -783,3 +778,3 @@
hlen = ip->ip_hl << 2;
- ip->ip_len += hlen;
+ ip->ip_len = htons(ntohs(ip->ip_len) + hlen);
} else
@@ -808,3 +803,3 @@
if (ia && ip)
- ia->ia_ifa.ifa_data.ifad_inbytes += ip->ip_len;
+ ia->ia_ifa.ifa_data.ifad_inbytes += ntohs(ip->ip_len);
#endif
@@ -888,3 +883,3 @@
p = q, q = TAILQ_NEXT(q, ipqe_q))
- if (q->ipqe_ip->ip_off > ipqe->ipqe_ip->ip_off)
+ if (ntohs(q->ipqe_ip->ip_off) > ntohs(ipqe->ipqe_ip->ip_off))
break;
@@ -897,10 +892,12 @@
if (p != NULL) {
- i = p->ipqe_ip->ip_off + p->ipqe_ip->ip_len -
- ipqe->ipqe_ip->ip_off;
+ i = ntohs(p->ipqe_ip->ip_off) + ntohs(p->ipqe_ip->ip_len) -
+ ntohs(ipqe->ipqe_ip->ip_off);
if (i > 0) {
- if (i >= ipqe->ipqe_ip->ip_len)
+ if (i >= ntohs(ipqe->ipqe_ip->ip_len))
goto dropfrag;
m_adj(ipqe->ipqe_m, i);
- ipqe->ipqe_ip->ip_off += i;
- ipqe->ipqe_ip->ip_len -= i;
+ ipqe->ipqe_ip->ip_off =
+ htons(ntohs(ipqe->ipqe_ip->ip_off) + i);
+ ipqe->ipqe_ip->ip_len =
+ htons(ntohs(ipqe->ipqe_ip->ip_len) - i);
}
@@ -912,9 +909,12 @@
*/
- for (; q != NULL && ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len >
- q->ipqe_ip->ip_off; q = nq) {
- i = (ipqe->ipqe_ip->ip_off + ipqe->ipqe_ip->ip_len) -
- q->ipqe_ip->ip_off;
- if (i < q->ipqe_ip->ip_len) {
- q->ipqe_ip->ip_len -= i;
- q->ipqe_ip->ip_off += i;
+ for (; q != NULL &&
+ ntohs(ipqe->ipqe_ip->ip_off) + ntohs(ipqe->ipqe_ip->ip_len) >
+ ntohs(q->ipqe_ip->ip_off); q = nq) {
+ i = (ntohs(ipqe->ipqe_ip->ip_off) +
+ ntohs(ipqe->ipqe_ip->ip_len)) - ntohs(q->ipqe_ip->ip_off);
+ if (i < ntohs(q->ipqe_ip->ip_len)) {
+ q->ipqe_ip->ip_len =
+ htons(ntohs(q->ipqe_ip->ip_len) - i);
+ q->ipqe_ip->ip_off =
+ htons(ntohs(q->ipqe_ip->ip_off) + i);
m_adj(q->ipqe_m, i);
@@ -941,5 +941,5 @@
p = q, q = TAILQ_NEXT(q, ipqe_q)) {
- if (q->ipqe_ip->ip_off != next)
+ if (ntohs(q->ipqe_ip->ip_off) != next)
return (0);
- next += q->ipqe_ip->ip_len;
+ next += ntohs(q->ipqe_ip->ip_len);
}
@@ -978,3 +978,3 @@
*/
- ip->ip_len = next;
+ ip->ip_len = htons(next);
ip->ip_src = fp->ipq_src;
@@ -1461,3 +1461,3 @@
m->m_pkthdr.len -= olen;
- ip->ip_len -= olen;
+ ip->ip_len = htons(ntohs(ip->ip_len) - olen);
ip->ip_hl = sizeof (struct ip) >> 2;
@@ -1551,3 +1551,3 @@
*/
- mcopy = m_copym(m, 0, imin((int)ip->ip_len, 68), M_DONTWAIT);
+ mcopy = m_copym(m, 0, imin(ntohs(ip->ip_len), 68), M_DONTWAIT);
if (mcopy)
Index: netinet/ip_mroute.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_mroute.c,v
retrieving revision 1.61
diff -u -1 -r1.61 ip_mroute.c
--- netinet/ip_mroute.c 2002/07/31 04:07:20 1.61
+++ netinet/ip_mroute.c 2002/08/12 22:57:50
@@ -1446,3 +1446,4 @@
else
- tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *), ip->ip_len);
+ tbf_control(vifp, mb_copy, mtod(mb_copy, struct ip *),
+ ntohs(ip->ip_len));
}
@@ -1457,3 +1458,3 @@
struct ip *ip_copy;
- int i, len = ip->ip_len + sizeof(multicast_encap_iphdr);
+ int i, len = ntohs(ip->ip_len) + sizeof(multicast_encap_iphdr);
@@ -1488,3 +1489,3 @@
ip_copy->ip_id = htons(ip_id++);
- ip_copy->ip_len = len;
+ ip_copy->ip_len = htons(len);
ip_copy->ip_src = vifp->v_lcl_addr;
@@ -1497,4 +1498,2 @@
--ip->ip_ttl;
- HTONS(ip->ip_len);
- HTONS(ip->ip_off);
ip->ip_sum = 0;
@@ -1507,3 +1506,3 @@
else
- tbf_control(vifp, mb_copy, ip, ip_copy->ip_len);
+ tbf_control(vifp, mb_copy, ip, ntohs(ip_copy->ip_len));
}
@@ -1697,3 +1696,3 @@
m = vifp->tbf_q) {
- len = mtod(m, struct ip *)->ip_len;
+ len = ntohs(mtod(m, struct ip *)->ip_len);
Index: netinet/ip_output.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/ip_output.c,v
retrieving revision 1.99
diff -u -1 -r1.99 ip_output.c
--- netinet/ip_output.c 2002/06/24 08:11:30 1.99
+++ netinet/ip_output.c 2002/08/12 22:57:50
@@ -218,3 +218,3 @@
ip->ip_v = IPVERSION;
- ip->ip_off = 0;
+ ip->ip_off = htons(0);
ip->ip_id = htons(ip_id++);
@@ -427,3 +427,3 @@
/* don't allow broadcast messages to be fragmented */
- if ((u_int16_t)ip->ip_len > ifp->if_mtu) {
+ if (ntohs(ip->ip_len) > ifp->if_mtu) {
error = EMSGSIZE;
@@ -442,12 +442,6 @@
(ro->ro_rt->rt_rmx.rmx_locks & RTV_MTU) == 0)
- ip->ip_off |= IP_DF;
+ ip->ip_off |= htons(IP_DF);
- /*
- * Remember the current ip_len and ip_off, and swap them into
- * network order.
- */
- ip_len = ip->ip_len;
-
- HTONS(ip->ip_len);
- HTONS(ip->ip_off);
+ /* Remember the current ip_len */
+ ip_len = ntohs(ip->ip_len);
@@ -659,11 +653,4 @@
* Must be able to put at least 8 bytes per fragment.
- *
- * Note we swap ip_len and ip_off into host order to make
- * the logic below a little simpler.
*/
-
- NTOHS(ip->ip_len);
- NTOHS(ip->ip_off);
-
- if (ip->ip_off & IP_DF) {
+ if (ntohs(ip->ip_off) & IP_DF) {
if (flags & IP_RETURNMTU)
@@ -692,3 +679,3 @@
mhlen = sizeof (struct ip);
- for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) {
+ for (off = hlen + len; off < ntohs(ip->ip_len); off += len) {
MGETHDR(m, M_DONTWAIT, MT_HEADER);
@@ -714,6 +701,7 @@
mhip->ip_off |= IP_MF;
- if (off + len >= (u_int16_t)ip->ip_len)
- len = (u_int16_t)ip->ip_len - off;
+ if (off + len >= ntohs(ip->ip_len))
+ len = ntohs(ip->ip_len) - off;
else
mhip->ip_off |= IP_MF;
+ HTONS(mhip->ip_off);
mhip->ip_len = htons((u_int16_t)(len + mhlen));
@@ -727,3 +715,2 @@
m->m_pkthdr.rcvif = (struct ifnet *)0;
- HTONS(mhip->ip_off);
mhip->ip_sum = 0;
@@ -738,7 +725,6 @@
m = m0;
- m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len);
+ m_adj(m, hlen + firstlen - ntohs(ip->ip_len));
m->m_pkthdr.len = hlen + firstlen;
ip->ip_len = htons((u_int16_t)m->m_pkthdr.len);
- ip->ip_off |= IP_MF;
- HTONS(ip->ip_off);
+ ip->ip_off |= htons(IP_MF);
ip->ip_sum = 0;
@@ -766,3 +752,3 @@
ia->ia_ifa.ifa_data.ifad_outbytes +=
- ntohs(ip->ip_len);
+ ntohs(ip->ip_len);
}
@@ -864,3 +850,3 @@
optlen = opt->m_len - sizeof(p->ipopt_dst);
- if (optlen + (u_int16_t)ip->ip_len > IP_MAXPACKET)
+ if (optlen + ntohs(ip->ip_len) > IP_MAXPACKET)
return (m); /* XXX should fail */
@@ -890,3 +876,3 @@
*phlen = sizeof(struct ip) + optlen;
- ip->ip_len += optlen;
+ ip->ip_len = htons(ntohs(ip->ip_len) + optlen);
return (m);
@@ -1657,4 +1643,2 @@
ip = mtod(copym, struct ip *);
- HTONS(ip->ip_len);
- HTONS(ip->ip_off);
Index: netinet/raw_ip.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/raw_ip.c,v
retrieving revision 1.61
diff -u -1 -r1.61 raw_ip.c
--- netinet/raw_ip.c 2002/06/09 16:33:43 1.61
+++ netinet/raw_ip.c 2002/08/12 22:57:50
@@ -165,5 +165,7 @@
* XXX Compatibility: programs using raw IP expect ip_len
- * XXX to have the header length subtracted.
+ * XXX to have the header length subtracted, and in host order.
+ * XXX ip_off is also expected to be host order.
*/
- ip->ip_len -= ip->ip_hl << 2;
+ ip->ip_len = ntohs(ip->ip_len) - (ip->ip_hl << 2);
+ NTOHS(ip->ip_off);
@@ -337,5 +339,5 @@
ip->ip_tos = 0;
- ip->ip_off = 0;
+ ip->ip_off = htons(0);
ip->ip_p = inp->inp_ip.ip_p;
- ip->ip_len = m->m_pkthdr.len;
+ ip->ip_len = htons(m->m_pkthdr.len);
ip->ip_src = inp->inp_laddr;
@@ -350,2 +352,3 @@
ip = mtod(m, struct ip *);
+ /* XXX userland passes ip_len and ip_off in host order */
if (m->m_pkthdr.len != ip->ip_len) {
@@ -354,2 +357,4 @@
}
+ HTONS(ip->ip_len);
+ HTONS(ip->ip_off);
if (ip->ip_id == 0)
@@ -367,3 +372,4 @@
#endif /*IPSEC*/
- return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions, &inp->inp_errormtu));
+ return (ip_output(m, opts, &inp->inp_route, flags, inp->inp_moptions,
+ &inp->inp_errormtu));
}
Index: netinet/tcp_input.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/tcp_input.c,v
retrieving revision 1.149
diff -u -1 -r1.149 tcp_input.c
--- netinet/tcp_input.c 2002/07/18 03:23:01 1.149
+++ netinet/tcp_input.c 2002/08/12 22:57:51
@@ -855,3 +855,3 @@
/* We do the checksum after PCB lookup... */
- len = ip->ip_len;
+ len = ntohs(ip->ip_len);
tlen = len - toff;
@@ -3748,3 +3748,3 @@
case AF_INET:
- ip->ip_len = tlen;
+ ip->ip_len = htons(tlen);
ip->ip_ttl = ip_defttl;
Index: netinet/tcp_output.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/tcp_output.c,v
retrieving revision 1.83
diff -u -1 -r1.83 tcp_output.c
--- netinet/tcp_output.c 2002/06/13 16:31:05 1.83
+++ netinet/tcp_output.c 2002/08/12 22:57:51
@@ -1075,3 +1075,3 @@
case AF_INET:
- ip->ip_len = m->m_pkthdr.len;
+ ip->ip_len = htons(m->m_pkthdr.len);
if (tp->t_inpcb) {
Index: netinet/tcp_subr.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/tcp_subr.c,v
retrieving revision 1.132
diff -u -1 -r1.132 tcp_subr.c
--- netinet/tcp_subr.c 2002/07/01 20:51:25 1.132
+++ netinet/tcp_subr.c 2002/08/12 22:57:52
@@ -763,3 +763,3 @@
th->th_sum = in_cksum(m, hlen + tlen);
- ip->ip_len = hlen + tlen; /*will be flipped on output*/
+ ip->ip_len = htons(hlen + tlen);
ip->ip_ttl = ip_defttl;
Index: netinet/udp_usrreq.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet/udp_usrreq.c,v
retrieving revision 1.95
diff -u -1 -r1.95 udp_usrreq.c
--- netinet/udp_usrreq.c 2002/06/30 22:40:37 1.95
+++ netinet/udp_usrreq.c 2002/08/12 22:57:52
@@ -275,4 +275,5 @@
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 (ntohs(ip->ip_len) != iphlen + len) {
+ if (ntohs(ip->ip_len) < iphlen + len ||
+ len < sizeof(struct udphdr)) {
udpstat.udps_badlen++;
@@ -280,3 +281,3 @@
}
- m_adj(m, iphlen + len - ip->ip_len);
+ m_adj(m, iphlen + len - ntohs(ip->ip_len));
}
@@ -894,3 +895,3 @@
*/
- if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) {
+ if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
error = EMSGSIZE;
@@ -926,3 +927,3 @@
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 */
Index: netinet6/ah_input.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet6/ah_input.c,v
retrieving revision 1.34
diff -u -1 -r1.34 ah_input.c
--- netinet6/ah_input.c 2002/06/09 14:43:10 1.34
+++ netinet6/ah_input.c 2002/08/12 22:57:52
@@ -84,3 +84,3 @@
-#define IPLEN_FLIPPED
+/*#define IPLEN_FLIPPED*/
@@ -277,3 +277,3 @@
{
-#if 1
+#if 0
/*
@@ -290,3 +290,3 @@
ipsecstat.in_ahhist[sav->alg_auth]++;
-#if 1
+#if 0
/*
Index: netinet6/esp_input.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet6/esp_input.c,v
retrieving revision 1.22
diff -u -1 -r1.22 esp_input.c
--- netinet6/esp_input.c 2002/06/08 20:06:44 1.22
+++ netinet6/esp_input.c 2002/08/12 22:57:52
@@ -84,3 +84,3 @@
-#define IPLEN_FLIPPED
+/*#define IPLEN_FLIPPED*/
Index: netinet6/ipcomp_input.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet6/ipcomp_input.c,v
retrieving revision 1.18
diff -u -1 -r1.18 ipcomp_input.c
--- netinet6/ipcomp_input.c 2001/11/13 00:57:03 1.18
+++ netinet6/ipcomp_input.c 2002/08/12 22:57:54
@@ -80,3 +80,3 @@
-#define IPLEN_FLIPPED
+/*#define IPLEN_FLIPPED*/
Index: netinet6/ipsec.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet6/ipsec.c,v
retrieving revision 1.64
diff -u -1 -r1.64 ipsec.c
--- netinet6/ipsec.c 2002/08/01 05:17:47 1.64
+++ netinet6/ipsec.c 2002/08/12 22:57:55
@@ -896,4 +896,3 @@
m_copydata(m, 0, sizeof(ip), (caddr_t)&ip);
- /* ip_input() flips it into host endian XXX need more checking */
- if (ip.ip_off & (IP_MF | IP_OFFMASK))
+ if (ip.ip_off & htons(IP_MF | IP_OFFMASK))
return;
@@ -2089,3 +2088,3 @@
ipseclog((LOG_ERR, "IPv4 ipsec: size exceeds limit: "
- "leave ip_len as is (invalid packet)\n"));
+ "leave ip_len as is (invalid packet)\n"));
}
Index: netinet6/udp6_output.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netinet6/udp6_output.c,v
retrieving revision 1.7
diff -u -1 -r1.7 udp6_output.c
--- netinet6/udp6_output.c 2002/06/08 20:06:45 1.7
+++ netinet6/udp6_output.c 2002/08/12 22:57:55
@@ -384,7 +384,5 @@
- ip->ip_len = hlen + plen;
+ ip->ip_len = htons(hlen + plen);
ip->ip_ttl = in6_selecthlim(in6p, NULL); /* XXX */
ip->ip_tos = 0; /* XXX */
-
- ip->ip_len = hlen + plen; /* XXX */
Index: netiso/if_eon.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netiso/if_eon.c,v
retrieving revision 1.37
diff -u -1 -r1.37 if_eon.c
--- netiso/if_eon.c 2002/07/29 22:54:38 1.37
+++ netiso/if_eon.c 2002/08/12 22:57:55
@@ -427,5 +427,11 @@
datalen = m->m_pkthdr.len + EONIPLEN;
+ if (datalen > IP_MAXPACKET) {
+ error = EMSGSIZE;
+ goto flush;
+ }
MGETHDR(mh, M_DONTWAIT, MT_HEADER);
- if (mh == (struct mbuf *) 0)
+ if (mh == (struct mbuf *) 0) {
+ error = ENOBUFS;
goto flush;
+ }
mh->m_next = m;
@@ -434,4 +440,5 @@
m->m_len = sizeof(struct eon_iphdr);
- ifp->if_obytes +=
- (ei->ei_ip.ip_len = (u_short) (m->m_pkthdr.len = datalen));
+ m->m_pkthdr.len = datalen;
+ ei->ei_ip.ip_len = htons(datalen);
+ ifp->if_obytes += datalen;
*mtod(m, struct eon_iphdr *) = *ei;
Index: netiso/tp_inet.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netiso/tp_inet.c,v
retrieving revision 1.21
diff -u -1 -r1.21 tp_inet.c
--- netiso/tp_inet.c 2001/11/13 01:10:50 1.21
+++ netiso/tp_inet.c 2002/08/12 22:57:55
@@ -469,3 +469,8 @@
ip->ip_p = IPPROTO_TP;
- m->m_pkthdr.len = ip->ip_len = sizeof(struct ip) + datalen;
+ if (sizeof(struct ip) + datalen > IP_MAXPACKET) {
+ error = EMSGSIZE;
+ goto bad;
+ }
+ m->m_pkthdr.len = sizeof(struct ip) + datalen;
+ ip->ip_len = htons(sizeof(struct ip) + datalen);
ip->ip_ttl = MAXTTL;
Index: netns/ns_ip.c
===================================================================
RCS file: /cvsroot/syssrc/sys/netns/ns_ip.c,v
retrieving revision 1.29
diff -u -1 -r1.29 ns_ip.c
--- netns/ns_ip.c 2001/11/13 01:08:11 1.29
+++ netns/ns_ip.c 2002/08/12 22:57:55
@@ -241,4 +241,4 @@
if (len & 1) len++; /* Preserve Garbage Byte */
- if (ip->ip_len != len) {
- if (len > ip->ip_len) {
+ if (ntohs(ip->ip_len) != len) {
+ if (len > ntohs(ip->ip_len)) {
nsipif.if_ierrors++;
@@ -325,3 +325,7 @@
ip->ip_dst = ifn->ifen_dst;
- ip->ip_len = (u_int16_t)len + sizeof (struct ip);
+ if (len + sizeof (struct ip) > IP_MAXPACKET) {
+ m_freem(m);
+ return (EMSGSIZE);
+ }
+ ip->ip_len = htons(len + sizeof (struct ip));
ip->ip_ttl = MAXTTL;
@@ -331,3 +335,3 @@
*/
- error = (ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST, NULL));
+ error = ip_output(m, (struct mbuf *)0, ro, SO_BROADCAST, NULL);
if (error) {