Subject: kern/7953: IPv6 checksum calculation incorrect on alpha
To: None <gnats-bugs@gnats.netbsd.org>
From: Dave Huang <khym@bga.com>
List: netbsd-bugs
Date: 07/09/1999 22:23:46
>Number:         7953
>Category:       kern
>Synopsis:       IPv6 checksum calculation incorrect on alpha
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Jul  9 22:05:00 1999
>Last-Modified:
>Originator:     Dave Huang
>Organization:
Name: Dave Huang     |   Mammal, mammal / their names are called /
INet: khym@bga.com   |   they raise a paw / the bat, the cat /
FurryMUCK: Dahan     |   dolphin and dog / koala bear and hog -- TMBG
Dahan: Hani G Y+C 23 Y++ L+++ W- C++ T++ A+ E+ S++ V++ F- Q+++ P+ B+ PA+ PL++
>Release:        NetBSD-current as of July 9, 1999
>Environment:
	
System: NetBSD yerfable.metonymy.com 1.4F NetBSD 1.4F (YERFABLE) #14: Fri Jul 9 23:31:43 CDT 1999 khym@yerfable.metonymy.com:/usr/src.local/sys/arch/alpha/compile/YERFABLE alpha


>Description:
	The IPv6 checksum is calculated incorrectly on the alpha.
>How-To-Repeat:
	ping6 another machine and watch it complain:
ICMP6 checksum error(135|c5ff) fe80:0001::0280:c8ff:fef7:c696

>Fix:
Perhaps there are other char/short/longs that should be changed to
appropriate fixed size types?

--- /usr/src/sys/netinet6/in6_cksum.c	Tue Jul  6 06:19:48 1999
+++ in6_cksum.c	Fri Jul  9 23:30:59 1999
@@ -81,11 +81,11 @@
 #define REDUCE {l_util.l = sum; sum = l_util.s[0] + l_util.s[1]; ADDCARRY(sum);}
 
 static union {
-	u_short phs[4];
+	u_int16_t phs[4];
 	struct {
-		u_long	ph_len;
-		u_char	ph_zero[3];
-		u_char	ph_nxt;
+		u_int32_t	ph_len;
+		u_int8_t	ph_zero[3];
+		u_int8_t	ph_nxt;
 	} ph;
 } uph;
 
@@ -102,7 +102,7 @@
 	u_int8_t nxt;
 	register int off, len;
 {
-	register u_short *w;
+	register u_int16_t *w;
 	register int sum = 0;
 	register int mlen = 0;
 	int byte_swapped = 0;
@@ -112,12 +112,12 @@
 	struct ip6_hdr *ip6;	
 	
 	union {
-		char	c[2];
-		u_short	s;
+		u_int8_t	c[2];
+		u_int16_t	s;
 	} s_util;
 	union {
-		u_short s[2];
-		long	l;
+		u_int16_t s[2];
+		u_int32_t l;
 	} l_util;
 
 	/* sanity check */
@@ -140,7 +140,7 @@
 		ip6->ip6_dst.s6_addr16[1] = 0;
 	}
 #endif
-	w = (u_short *)&ip6->ip6_src;
+	w = (u_int16_t *)&ip6->ip6_src;
 	uph.ph.ph_len = htonl(len);
 	uph.ph.ph_nxt = nxt;
 
@@ -176,7 +176,7 @@
 			break;
 		m = m->m_next;
 	}
-	w = (u_short *)(mtod(m, u_char *) + off);
+	w = (u_int16_t *)(mtod(m, u_char *) + off);
 	mlen = m->m_len - off;
 	if (len < mlen)
 		mlen = len;
@@ -188,7 +188,7 @@
 		REDUCE;
 		sum <<= 8;
 		s_util.c[0] = *(u_char *)w;
-		w = (u_short *)((char *)w + 1);
+		w = (u_int16_t *)((char *)w + 1);
 		mlen--;
 		byte_swapped = 1;
 	}
@@ -237,7 +237,7 @@
 	for (;m && len; m = m->m_next) {
 		if (m->m_len == 0)
 			continue;
-		w = mtod(m, u_short *);
+		w = mtod(m, u_int16_t *);
 		if (mlen == -1) {
 			/*
 			 * The first byte of this mbuf is the continuation
@@ -249,7 +249,7 @@
 			 */
 			s_util.c[1] = *(char *)w;
 			sum += s_util.s;
-			w = (u_short *)((char *)w + 1);
+			w = (u_int16_t *)((char *)w + 1);
 			mlen = m->m_len - 1;
 			len--;
 		} else
@@ -264,7 +264,7 @@
 			REDUCE;
 			sum <<= 8;
 			s_util.c[0] = *(u_char *)w;
-			w = (u_short *)((char *)w + 1);
+			w = (u_int16_t *)((char *)w + 1);
 			mlen--;
 			byte_swapped = 1;
 		}

>Audit-Trail:
>Unformatted: