[netfilter-cvslog] r3613 - in trunk/nfsim: . kernelenv kernelenv/include

rusty at netfilter.org rusty at netfilter.org
Tue Jan 25 04:17:22 CET 2005


Author: rusty at netfilter.org
Date: 2005-01-25 04:17:22 +0100 (Tue, 25 Jan 2005)
New Revision: 3613

Added:
   trunk/nfsim/kernelenv/include/kernelenv_bigendian.h
   trunk/nfsim/kernelenv/include/kernelenv_littleendian.h
Modified:
   trunk/nfsim/Makefile.in
   trunk/nfsim/configure
   trunk/nfsim/kernelenv/include/kernelenv.h
   trunk/nfsim/kernelenv/kernelenv.c
Log:
Don't use asm/byteorder.h, it doesn't always work
(Bug report from Samir Bellabes sbellabes from mandrakesoft.com)


Modified: trunk/nfsim/Makefile.in
===================================================================
--- trunk/nfsim/Makefile.in	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/Makefile.in	2005-01-25 03:17:22 UTC (rev 3613)
@@ -101,6 +101,7 @@
 	rm -f tags
 	rm -f nfsim-*.tar.gz
 	rm -f Makefile
+	rm -f kernelenv/include/kernelenv_endian.h
 
 .PHONY:	tags
 tags:

Modified: trunk/nfsim/configure
===================================================================
--- trunk/nfsim/configure	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/configure	2005-01-25 03:17:22 UTC (rev 3613)
@@ -38,6 +38,23 @@
 [ -n "$BINDIR" ] || BINDIR="$PREFIX"/bin/
 [ -n "$LIBDIR" ] || LIBDIR="$PREFIX"/lib/
 
+link_bitfield()
+{
+    case `echo -n 'AB' | od -A n -x | tr -d ' '` in
+	4241)
+	    echo You are little endian...
+	    ln -sf kernelenv_littleendian.h kernelenv/include/kernelenv_endian.h
+	    ;;
+	4142)
+	    echo You are big endian...
+	    ln -sf kernelenv_bigeendian.h kernelenv/include/kernelenv_endian.h
+	    ;;
+	*)
+	    barf Cannot determine endianness of machine
+	    ;;
+    esac
+}
+
 SUB='s@%GCOVFLAGS%@'$GCOVFLAGS'@;s@%TYPE%@'$TYPE'@;s@%VERSION%@'$VERSION'@;s@%GCOV%@'$GCOV'@;s@%CC%@'$CC'@;s@%LIBDIR%@'$LIBDIR'@;s@%BINDIR%@'$BINDIR'@;s@%BASEDIR%@'$BASEDIR'@'
 
 [ -d $KERNELDIR/net/$TYPE/netfilter ] ||
@@ -48,6 +65,7 @@
     echo -n " $f"
     sed "$SUB" < $f > `echo $f | sed 's/.in$//'`
 done; echo
+link_bitfield
 
 echo Importing netfilter $TYPE code from $KERNELDIR
 

Modified: trunk/nfsim/kernelenv/include/kernelenv.h
===================================================================
--- trunk/nfsim/kernelenv/include/kernelenv.h	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/kernelenv/include/kernelenv.h	2005-01-25 03:17:22 UTC (rev 3613)
@@ -1,22 +1,20 @@
 /*
+ * Copyright (c) 2003,2004 Jeremy Kerr & Rusty Russell
+ This file is part of nfsim.
 
-Copyright (c) 2003,2004 Jeremy Kerr & Rusty Russell
+ nfsim is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2 of the License, or (at
+ your option) any later version.
 
-This file is part of nfsim.
+ nfsim is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ for more details.
 
-nfsim is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2 of the License, or
-(at your option) any later version.
-
-nfsim is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with nfsim; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ You should have received a copy of the GNU General Public License
+ along with nfsim; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */
 
 /**
@@ -42,8 +40,62 @@
 #include <ctype.h>
 #include <list.h>
 
-#include <asm/byteorder.h>
+/* Types */
+typedef uint8_t u8;
+typedef int8_t s8;
+typedef uint16_t u16;
+typedef int16_t s16;
+typedef uint32_t u32;
+typedef int32_t s32;
+typedef uint64_t u64;
+typedef int64_t s64;
+#define __u8 u8
+#define __s8 s8
+#define __u16 u16
+#define __s16 s16
+#define __u32 u32
+#define __s32 s32
+#define __u64 u64
+#define __s64 u64
 
+/* Hacky, but works for now */
+#define BITS_PER_LONG (ULONG_MAX == 0xFFFFFFFFUL ? 32 : 64)
+
+/* casts are necessary for constants, because we never know how for sure
+ * how U/UL/ULL map to u16, u32, u64. At least not in a portable way.
+ */
+#define swab16(x) \
+	((u16)( \
+		(((u16)(x) & (u16)0x00ffU) << 8) | \
+		(((u16)(x) & (u16)0xff00U) >> 8) ))
+#define swab32(x) \
+	((u32)( \
+		(((u32)(x) & (u32)0x000000ffUL) << 24) | \
+		(((u32)(x) & (u32)0x0000ff00UL) <<  8) | \
+		(((u32)(x) & (u32)0x00ff0000UL) >>  8) | \
+		(((u32)(x) & (u32)0xff000000UL) >> 24) ))
+#define swab64(x) \
+	((u64)( \
+		(u64)(((u64)(x) & (u64)0x00000000000000ffULL) << 56) | \
+		(u64)(((u64)(x) & (u64)0x000000000000ff00ULL) << 40) | \
+		(u64)(((u64)(x) & (u64)0x0000000000ff0000ULL) << 24) | \
+		(u64)(((u64)(x) & (u64)0x00000000ff000000ULL) <<  8) | \
+	        (u64)(((u64)(x) & (u64)0x000000ff00000000ULL) >>  8) | \
+		(u64)(((u64)(x) & (u64)0x0000ff0000000000ULL) >> 24) | \
+		(u64)(((u64)(x) & (u64)0x00ff000000000000ULL) >> 40) | \
+		(u64)(((u64)(x) & (u64)0xff00000000000000ULL) >> 56) ))
+
+#define swab16p(p) (swab16(*(p)))
+#define swab32p(p) (swab32(*(p)))
+#define swab64p(p) (swab64(*(p)))
+
+#include "kernelenv_endian.h"
+
+u32 htonl(u32 hostlong);
+u16 htons(u16 hostshort);
+u32 ntohl(u32 netlong);
+u16 ntohs(u16 netshort);
+
 #define smp_wmb()
 #define wmb()
 #define barrier()
@@ -96,11 +148,6 @@
 #define u_int32_t	uint32_t
 #define u_int64_t	uint64_t
 
-#define __u8		uint8_t
-#define __u16		uint16_t
-#define __u32		uint32_t
-#define __u64		uint64_t
-
 #define __init
 #define __inline
 #define ____cacheline_aligned __attribute__((aligned(8)))

Added: trunk/nfsim/kernelenv/include/kernelenv_bigendian.h
===================================================================
--- trunk/nfsim/kernelenv/include/kernelenv_bigendian.h	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/kernelenv/include/kernelenv_bigendian.h	2005-01-25 03:17:22 UTC (rev 3613)
@@ -0,0 +1,101 @@
+#ifndef _LINUX_BYTEORDER_BIG_ENDIAN_H
+#define _LINUX_BYTEORDER_BIG_ENDIAN_H
+
+#ifndef __BIG_ENDIAN
+#define __BIG_ENDIAN 4321
+#endif
+#ifndef __BIG_ENDIAN_BITFIELD
+#define __BIG_ENDIAN_BITFIELD
+#endif
+
+#define __constant_htonl(x) (x)
+#define __constant_ntohl(x) (x)
+#define __constant_htons(x) (x)
+#define __constant_ntohs(x) (x)
+#define __constant_cpu_to_le64(x) (swab64(x))
+#define __constant_le64_to_cpu(x) swab64((u64)(x))
+#define __constant_cpu_to_le32(x) (swab32(x))
+#define __constant_le32_to_cpu(x) swab32((u32)(x))
+#define __constant_cpu_to_le16(x) (swab16(x))
+#define __constant_le16_to_cpu(x) swab16((u16)(x))
+#define __constant_cpu_to_be64(x) (x)
+#define __constant_be64_to_cpu(x) (x)
+#define __constant_cpu_to_be32(x) (x)
+#define __constant_be32_to_cpu(x) (x)
+#define __constant_cpu_to_be16(x) (x)
+#define __constant_be16_to_cpu(x) (x)
+#define __cpu_to_le64(x) (swab64(x))
+#define __le64_to_cpu(x) swab64((u64)(x))
+#define __cpu_to_le32(x) (swab32(x))
+#define __le32_to_cpu(x) swab32((u32)(x))
+#define __cpu_to_le16(x) (swab16(x))
+#define __le16_to_cpu(x) swab16((u16)(x))
+#define __cpu_to_be64(x) (x)
+#define __be64_to_cpu(x) (x)
+#define __cpu_to_be32(x) (x)
+#define __be32_to_cpu(x) (x)
+#define __cpu_to_be16(x) (x)
+#define __be16_to_cpu(x) (x)
+
+static inline u64 __cpu_to_le64p(const u64 *p)
+{
+	return swab64p(p);
+}
+static inline u64 __le64_to_cpup(const u64 *p)
+{
+	return swab64p((u64 *)p);
+}
+static inline u32 __cpu_to_le32p(const u32 *p)
+{
+	return swab32p(p);
+}
+static inline u32 __le32_to_cpup(const u32 *p)
+{
+	return swab32p((u32 *)p);
+}
+static inline u16 __cpu_to_le16p(const u16 *p)
+{
+	return swab16p(p);
+}
+static inline u16 __le16_to_cpup(const u16 *p)
+{
+	return swab16p((u16 *)p);
+}
+static inline u64 __cpu_to_be64p(const u64 *p)
+{
+	return *p;
+}
+static inline u64 __be64_to_cpup(const __be64 *p)
+{
+	return *p;
+}
+static inline u32 __cpu_to_be32p(const u32 *p)
+{
+	return *p;
+}
+static inline u32 __be32_to_cpup(const __be32 *p)
+{
+	return *p;
+}
+static inline u16 __cpu_to_be16p(const u16 *p)
+{
+	return *p;
+}
+static inline u16 __be16_to_cpup(const __be16 *p)
+{
+	return *p;
+}
+#define __cpu_to_le64s(x) swab64s(x)
+#define __le64_to_cpus(x) swab64s(x)
+#define __cpu_to_le32s(x) swab32s(x)
+#define __le32_to_cpus(x) swab32s(x)
+#define __cpu_to_le16s(x) swab16s(x)
+#define __le16_to_cpus(x) swab16s(x)
+#define __cpu_to_be64s(x) do {} while (0)
+#define __be64_to_cpus(x) do {} while (0)
+#define __cpu_to_be32s(x) do {} while (0)
+#define __be32_to_cpus(x) do {} while (0)
+#define __cpu_to_be16s(x) do {} while (0)
+#define __be16_to_cpus(x) do {} while (0)
+
+#endif /* _LINUX_BYTEORDER_BIG_ENDIAN_H */

Added: trunk/nfsim/kernelenv/include/kernelenv_littleendian.h
===================================================================
--- trunk/nfsim/kernelenv/include/kernelenv_littleendian.h	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/kernelenv/include/kernelenv_littleendian.h	2005-01-25 03:17:22 UTC (rev 3613)
@@ -0,0 +1,101 @@
+#ifndef _LINUX_BYTEORDER_LITTLE_ENDIAN_H
+#define _LINUX_BYTEORDER_LITTLE_ENDIAN_H
+
+#ifndef __LITTLE_ENDIAN
+#define __LITTLE_ENDIAN 1234
+#endif
+#ifndef __LITTLE_ENDIAN_BITFIELD
+#define __LITTLE_ENDIAN_BITFIELD
+#endif
+
+#define __constant_htonl(x) (swab32(x))
+#define __constant_ntohl(x) swab32(x)
+#define __constant_htons(x) (swab16(x))
+#define __constant_ntohs(x) swab16(x)
+#define __constant_cpu_to_le64(x) (x)
+#define __constant_le64_to_cpu(x) (x)
+#define __constant_cpu_to_le32(x) (x)
+#define __constant_le32_to_cpu(x) (x)
+#define __constant_cpu_to_le16(x) (x)
+#define __constant_le16_to_cpu(x) (x)
+#define __constant_cpu_to_be64(x) (swab64(x))
+#define __constant_be64_to_cpu(x) swab64((u64)(x))
+#define __constant_cpu_to_be32(x) (swab32(x))
+#define __constant_be32_to_cpu(x) swab32((u32)(x))
+#define __constant_cpu_to_be16(x) (swab16(x))
+#define __constant_be16_to_cpu(x) swab16((u16)(x))
+#define __cpu_to_le64(x) (x)
+#define __le64_to_cpu(x) (x)
+#define __cpu_to_le32(x) (x)
+#define __le32_to_cpu(x) (x)
+#define __cpu_to_le16(x) (x)
+#define __le16_to_cpu(x) (x)
+#define __cpu_to_be64(x) (swab64(x))
+#define __be64_to_cpu(x) swab64((u64)(x))
+#define __cpu_to_be32(x) (swab32(x))
+#define __be32_to_cpu(x) swab32((u32)(x))
+#define __cpu_to_be16(x) (swab16(x))
+#define __be16_to_cpu(x) swab16((u16)(x))
+
+static inline u64 __cpu_to_le64p(const u64 *p)
+{
+	return *p;
+}
+static inline u64 __le64_to_cpup(const u64 *p)
+{
+	return *p;
+}
+static inline u32 __cpu_to_le32p(const u32 *p)
+{
+	return *p;
+}
+static inline u32 __le32_to_cpup(const u32 *p)
+{
+	return *p;
+}
+static inline u16 __cpu_to_le16p(const u16 *p)
+{
+	return *p;
+}
+static inline u16 __le16_to_cpup(const u16 *p)
+{
+	return *p;
+}
+static inline u64 __cpu_to_be64p(const u64 *p)
+{
+	return swab64p(p);
+}
+static inline u64 __be64_to_cpup(const u64 *p)
+{
+	return swab64p((u64 *)p);
+}
+static inline u32 __cpu_to_be32p(const u32 *p)
+{
+	return swab32p(p);
+}
+static inline u32 __be32_to_cpup(const u32 *p)
+{
+	return swab32p((u32 *)p);
+}
+static inline u16 __cpu_to_be16p(const u16 *p)
+{
+	return swab16p(p);
+}
+static inline u16 __be16_to_cpup(const u16 *p)
+{
+	return swab16p((u16 *)p);
+}
+#define __cpu_to_le64s(x) do {} while (0)
+#define __le64_to_cpus(x) do {} while (0)
+#define __cpu_to_le32s(x) do {} while (0)
+#define __le32_to_cpus(x) do {} while (0)
+#define __cpu_to_le16s(x) do {} while (0)
+#define __le16_to_cpus(x) do {} while (0)
+#define __cpu_to_be64s(x) swab64s(x)
+#define __be64_to_cpus(x) swab64s(x)
+#define __cpu_to_be32s(x) swab32s(x)
+#define __be32_to_cpus(x) swab32s(x)
+#define __cpu_to_be16s(x) swab16s(x)
+#define __be16_to_cpus(x) swab16s(x)
+
+#endif /* _LINUX_BYTEORDER_LITTLE_ENDIAN_H */

Modified: trunk/nfsim/kernelenv/kernelenv.c
===================================================================
--- trunk/nfsim/kernelenv/kernelenv.c	2005-01-23 17:38:51 UTC (rev 3612)
+++ trunk/nfsim/kernelenv/kernelenv.c	2005-01-25 03:17:22 UTC (rev 3613)
@@ -31,6 +31,26 @@
 
 unsigned long jiffies = INITIAL_JIFFIES;
 
+u32 htonl(u32 hostlong)
+{
+	return __cpu_to_be32(hostlong);
+}
+	
+u16 htons(u16 hostshort)
+{
+	return __cpu_to_be16(hostshort);
+}
+
+u32 ntohl(u32 netlong)
+{
+	return __be32_to_cpu(netlong);
+}
+
+u16 ntohs(u16 netshort)
+{
+	return __be16_to_cpu(netshort);
+}
+
 /* skbuff */
 static int nfsim_seq;
 




More information about the netfilter-cvslog mailing list