Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 12 Mar 2003 14:45:17 +0100 (CET)
From:      Harti Brandt <brandt@fokus.fraunhofer.de>
To:        freebsd-atm@freebsd.org
Subject:   endian patch to NATM
Message-ID:  <20030312144011.N641@beagle.fokus.fraunhofer.de>

next in thread | raw e-mail | index | archive | help


Hi all,

there seems to be an endian related bug in NATM. The problem is, that
in contrast to the comments in if_atm.h, the ATM_LLC_SETTYPE macros
expects its V argument (the ethertype) in swapped host order (the
ATM_LLC_TYPE macros on the other hand returns host order). The code feeds
the htons'ed ethernet type into the macro, so that for i386 it happens to
work. On the sparc the ethernet type in the LLC/SNAP header is wrong.

The attached patch changes the macro to actually require host byte order
and the calling code to feed the ethertype in host byte order.

The patch has been verified by using IP between an i386 and a sparc64.

Comments? Ok to commit?

Regards,
harti

Index: if_atm.h
===================================================================
RCS file: /home/ncvs/src/sys/net/if_atm.h,v
retrieving revision 1.5
diff -u -r1.5 if_atm.h
--- if_atm.h	19 Mar 2002 21:54:16 -0000	1.5
+++ if_atm.h	12 Mar 2003 13:39:51 -0000
@@ -93,8 +93,8 @@
 /* ATM_LLC macros: note type code in host byte order */
 #define ATM_LLC_TYPE(X) (((X)->type[0] << 8) | ((X)->type[1]))
 #define ATM_LLC_SETTYPE(X,V) { \
-	(X)->type[1] = ((V) >> 8) & 0xff; \
-	(X)->type[0] = ((V) & 0xff); \
+	(X)->type[0] = ((V) >> 8) & 0xff; \
+	(X)->type[1] = ((V) & 0xff); \
 }

 #ifdef _KERNEL
Index: if_atmsubr.c
===================================================================
RCS file: /home/ncvs/src/sys/net/if_atmsubr.c,v
retrieving revision 1.23
diff -u -r1.23 if_atmsubr.c
--- if_atmsubr.c	4 Mar 2003 23:19:51 -0000	1.23
+++ if_atmsubr.c	12 Mar 2003 13:39:51 -0000
@@ -130,9 +130,9 @@
 		case AF_INET:
 		case AF_INET6:
 			if (dst->sa_family == AF_INET6)
-			        etype = htons(ETHERTYPE_IPV6);
+			        etype = ETHERTYPE_IPV6;
 			else
-			        etype = htons(ETHERTYPE_IP);
+			        etype = ETHERTYPE_IP;
 			if (!atmresolve(rt, m, dst, &atmdst)) {
 				m = NULL;
 				/* XXX: atmresolve already free'd it */
@@ -180,7 +180,7 @@
 			        bcopy(ATMLLC_HDR, atmllc->llchdr,
 				      sizeof(atmllc->llchdr));
 				ATM_LLC_SETTYPE(atmllc, etype);
-					/* note: already in network order */
+					/* note: in host order */
 			}
 			else
 			        bcopy(llc_hdr, atmllc, sizeof(struct atmllc));

-- 
harti brandt,
http://www.fokus.fraunhofer.de/research/cc/cats/employees/hartmut.brandt/private
brandt@fokus.fraunhofer.de, harti@freebsd.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-atm" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030312144011.N641>