NetBSD Problem Report #6602
Received: (qmail 4041 invoked from network); 16 Dec 1998 20:43:06 -0000
Message-Id: <199812162041.HAA20711@avalon.reed.wattle.id.au>
Date: Thu, 17 Dec 1998 07:41:59 +1100 (EST)
From: Darren Reed <darrenr@reed.wattle.id.au>
To: gnats-bugs@gnats.netbsd.org
Subject: ICMP packets with wrong byte ordering
>Number: 6602
>Category: kern
>Synopsis: byte ordering wrong in ICMP error replies
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: kern-bug-people
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Dec 16 12:50:01 +0000 1998
>Closed-Date: Mon Jan 11 22:38:09 +0000 1999
>Last-Modified: Mon Jan 11 22:38:22 +0000 1999
>Originator: Darren Reed
>Release: NetBSD-current snapshot 110898
>Organization:
Darren Reed
>Environment:
System: NetBSD merlin 1.3G NetBSD 1.3G (SHARK) #1: Tue Aug 11 00:23:35 BST 1998 netbsd@loneshark.brini.demon.co.uk:/home/voyager/altroot/usr/users/netbsd/src/sys/arch/arm32/compile/SHARK arm32
>Description:
ICMP replies, in some cases, return with a copy of the IP header
which has fields post-adjusting for local processing. The ip_len field
is adjusted for UDP handling and in other cases, ip_id/ip_off are not
converted back from host byte ordering.
>How-To-Repeat:
Cause a ICMP reply to be generated.
>Fix:
The patch below should correct the problem but is currently
untested. It also fixes up some htons/HTONS usage (which is somewhat
inconsistant).
*** ip_icmp.c.orig Sun Dec 6 17:04:21 1998
--- ip_icmp.c Sun Dec 6 17:46:24 1998
***************
*** 159,165 ****
m = m_gethdr(M_DONTWAIT, MT_HEADER);
if (m == NULL)
goto freeit;
! icmplen = oiplen + min(8, oip->ip_len);
m->m_len = icmplen + ICMP_MINLEN;
MH_ALIGN(m, m->m_len);
icp = mtod(m, struct icmp *);
--- 159,165 ----
m = m_gethdr(M_DONTWAIT, MT_HEADER);
if (m == NULL)
goto freeit;
! icmplen = oiplen + min(8, oip->ip_len - oiplen);
m->m_len = icmplen + ICMP_MINLEN;
MH_ALIGN(m, m->m_len);
icp = mtod(m, struct icmp *);
***************
*** 183,188 ****
--- 183,191 ----
icp->icmp_nextmtu = htons(destifp->if_mtu);
}
+ HTONS(oip->ip_id);
+ HTONS(oip->ip_off);
+ HTONS(oip->ip_len);
icp->icmp_code = code;
bcopy((caddr_t)oip, (caddr_t)&icp->icmp_ip, icmplen);
nip = &icp->icmp_ip;
*** ip_input.c.orig Sun Aug 9 21:11:14 1998
--- ip_input.c Sun Dec 6 17:26:31 1998
***************
*** 1139,1145 ****
m_freem(m);
return;
}
- HTONS(ip->ip_id);
if (ip->ip_ttl <= IPTTLDEC) {
icmp_error(m, ICMP_TIMXCEED, ICMP_TIMXCEED_INTRANS, dest, 0);
return;
--- 1139,1144 ----
***************
*** 1186,1201 ****
if (rt->rt_ifa &&
(ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
ifatoia(rt->rt_ifa)->ia_subnet) {
! if (rt->rt_flags & RTF_GATEWAY)
! dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
! else
! dest = ip->ip_dst.s_addr;
! /* Router requirements says to only send host redirects */
! type = ICMP_REDIRECT;
! code = ICMP_REDIRECT_HOST;
#ifdef DIAGNOSTIC
! if (ipprintfs)
! printf("redirect (%d) to %x\n", code, (u_int32_t)dest);
#endif
}
}
--- 1185,1201 ----
if (rt->rt_ifa &&
(ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
ifatoia(rt->rt_ifa)->ia_subnet) {
! if (rt->rt_flags & RTF_GATEWAY)
! dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
! else
! dest = ip->ip_dst.s_addr;
! /* Router requirements says only send host redirects */
! type = ICMP_REDIRECT;
! code = ICMP_REDIRECT_HOST;
#ifdef DIAGNOSTIC
! if (ipprintfs)
! printf("redirect (%d) to %x\n", code,
! (u_int32_t)dest);
#endif
}
}
*** ip_output.c.orig Sun Aug 9 21:11:14 1998
--- ip_output.c Sun Dec 6 17:26:11 1998
***************
*** 172,177 ****
--- 172,178 ----
ipstat.ips_localout++;
} else {
hlen = ip->ip_hl << 2;
+ HTONS(ip->ip_id);
}
/*
* Route packet.
***************
*** 368,375 ****
* If small enough for mtu of path, can just send directly.
*/
if ((u_int16_t)ip->ip_len <= mtu) {
! ip->ip_len = htons((u_int16_t)ip->ip_len);
! ip->ip_off = htons((u_int16_t)ip->ip_off);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
error = (*ifp->if_output)(ifp, m, sintosa(dst), ro->ro_rt);
--- 369,376 ----
* If small enough for mtu of path, can just send directly.
*/
if ((u_int16_t)ip->ip_len <= mtu) {
! HTONS(ip->ip_len);
! HTONS(ip->ip_off);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
error = (*ifp->if_output)(ifp, m, sintosa(dst), ro->ro_rt);
***************
*** 437,443 ****
}
m->m_pkthdr.len = mhlen + len;
m->m_pkthdr.rcvif = (struct ifnet *)0;
! mhip->ip_off = htons((u_int16_t)mhip->ip_off);
mhip->ip_sum = 0;
mhip->ip_sum = in_cksum(m, mhlen);
ipstat.ips_ofragments++;
--- 438,444 ----
}
m->m_pkthdr.len = mhlen + len;
m->m_pkthdr.rcvif = (struct ifnet *)0;
! HTONS(mhip->ip_off);
mhip->ip_sum = 0;
mhip->ip_sum = in_cksum(m, mhlen);
ipstat.ips_ofragments++;
***************
*** 451,457 ****
m_adj(m, hlen + firstlen - (u_int16_t)ip->ip_len);
m->m_pkthdr.len = hlen + firstlen;
ip->ip_len = htons((u_int16_t)m->m_pkthdr.len);
! ip->ip_off = htons((u_int16_t)(ip->ip_off | IP_MF));
ip->ip_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
sendorfree:
--- 452,459 ----
m_adj(m, hlen + firstlen - (u_int16_t)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_sum = 0;
ip->ip_sum = in_cksum(m, hlen);
sendorfree:
***************
*** 1222,1229 ****
* than the interface's MTU. Can this possibly matter?
*/
ip = mtod(copym, struct ip *);
! ip->ip_len = htons((u_int16_t)ip->ip_len);
! ip->ip_off = htons((u_int16_t)ip->ip_off);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(copym, ip->ip_hl << 2);
(void) looutput(ifp, copym, sintosa(dst), NULL);
--- 1224,1231 ----
* than the interface's MTU. Can this possibly matter?
*/
ip = mtod(copym, struct ip *);
! HTONS(ip->ip_len);
! HTONS(ip->ip_off);
ip->ip_sum = 0;
ip->ip_sum = in_cksum(copym, ip->ip_hl << 2);
(void) looutput(ifp, copym, sintosa(dst), NULL);
*** udp_usrreq.c.orig Wed Jan 14 01:41:37 1998
--- udp_usrreq.c Sun Dec 6 17:44:53 1998
***************
*** 303,308 ****
--- 303,309 ----
/* It was a debugger connect packet, just drop it now */
goto bad;
#endif
+ ip->ip_len += ip->ip_hl << 2;
icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
return;
}
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: thorpej
State-Changed-When: Mon Jan 11 14:38:09 PST 1999
State-Changed-Why:
Applied, thanks!
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.