Skip to contentSkip to conversation

port nfsim to Linux 2.6.14-rc2

PATCH In review Max Kellermann 2 participants 3 messages Sep 22, 2005 – Sep 23, 2005 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 port nfsim to Linux 2.6.14-rc2

Hi,

this patch makes nfsim compile with Linux 2.6.14-rc2. It uses #ifdefs to keep it compatible with the older kernels. The changes were mostly copy+paste from the original kernel headers to core/core.h etc.

With 2.6.14-rc2, a lot of header code was moved around, creating the new files net/ipv[46]/netfilter.c, and removing the file net/core/netfilter.c. My fixes for that need a bit of cleanup, because the current nfsim structure cannot import net/ipv[46]/*.c in a clean way, it only knows net/ipv[46]/netfilter/*.c. There should probably be a more generic approach to importing Linux sources into the nfsim tree, no matter which original subdirectory they came from.

Max

Thu Sep 22 10:13:41 CEST 2005 [email protected]
* port to Linux 2.6.14-rc2 II

.links +1 -0
diff -rN -u old-nfsim-0/.links new-nfsim-0/.links
@@ -53,6 +53,7 @@
 ./asm/softirq.h
 ./asm/statfs.h
 ./asm/page.h
+./asm/types.h
 ./net/tcp.h
 ./net/checksum.h
 ./net/route.h
configure +30 -3
diff -rN -u old-nfsim-0/configure new-nfsim-0/configure
@@ -71,9 +71,25 @@
 rm -f Makefile.import
 
 [ -d netfilter/$TYPE ] ||  mkdir -p netfilter/$TYPE
-echo "netfilter/core/netfilter.c: $KERNELDIR/net/core/netfilter.c" >> Makefile.import
-echo '	@sed -f netfilter.c.sed $^ > $@ && chmod a-w $@' >> Makefile.import
-echo "import: netfilter/core/netfilter.c" >> Makefile.import
+if [ -f $KERNELDIR/net/core/netfilter.c ]; then
+    # < Linux 2.6.14
+    echo "netfilter/core/netfilter.c: $KERNELDIR/net/core/netfilter.c" >> Makefile.import
+    echo '	@sed -f netfilter.c.sed $^ > $@ && chmod a-w $@' >> Makefile.import
+    echo "import: netfilter/core/netfilter.c" >> Makefile.import
+else
+    # >= Linux 2.6.14
+    for i in core.c nf_log.c nf_queue.c nf_sockopt.c nf_internals.h; do
+        echo "netfilter/$i: $KERNELDIR/net/netfilter/$i" >> Makefile.import
+        echo '	@sed -f netfilter.c.sed $^ > $@ && chmod a-w $@' >> Makefile.import
+        echo "import: netfilter/$i" >> Makefile.import
+    done
+    # XXX this one imports net/ipv4/netfilter.c to
+    # netfilter/core/netfilter.c... this is actually wrong, and will be
+    # corrected in a later patch
+    echo "netfilter/core/netfilter.c: $KERNELDIR/net/$TYPE/netfilter.c" >> Makefile.import
+    echo '	@sed -f netfilter.c.sed $^ > $@ && chmod a-w $@' >> Makefile.import
+    echo "import: netfilter/core/netfilter.c" >> Makefile.import
+fi
 
 files=$(cd $KERNELDIR/net/$TYPE/netfilter/; \
 	find . -name '*.[ch]' ! -name '*.mod.c' | grep -vE '/(SCCS|RCS)/')
@@ -101,6 +117,17 @@
     echo '	@cp $^ $@ && chmod a-w $@' >> Makefile.import
     echo "import: netfilter/include/linux/netfilter_$TYPE/$f" >> Makefile.import
 done
+if [ -d $KERNELDIR/include/linux/netfilter ]; then
+    # present in Linux 2.6.14+
+    files=$(cd $KERNELDIR/include/linux/netfilter; \
+	find . -name '*.[ch]' | grep -vE '/(SCCS|RCS)/')
+    for f in $files; do
+        mkdir -p $(dirname netfilter/include/linux/netfilter/$f)
+        echo "netfilter/include/linux/netfilter/$f":"$KERNELDIR/include/linux/netfilter/$f" >> Makefile.import
+        echo '	@cp $^ $@ && chmod a-w $@' >> Makefile.import
+        echo "import: netfilter/include/linux/netfilter/$f" >> Makefile.import
+    done
+fi
 echo "netfilter/include/linux/netfilter_$TYPE.h":"$KERNELDIR/include/linux/netfilter_$TYPE.h" >> Makefile.import
 echo '	@cp $^ $@ && chmod a-w $@' >> Makefile.import
 echo "import: netfilter/include/linux/netfilter_$TYPE.h" >> Makefile.import
core/core.c +11 -0
diff -rN -u old-nfsim-0/core/core.c new-nfsim-0/core/core.c
@@ -127,6 +127,13 @@
 
 	return 0;
 }
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
+static struct nf_queue_handler enqueue_packet_h = {
+	.outfn = enqueue_packet,
+	.data = NULL,
+	.name = "core.c:enqueue_packet",
+};
+#endif
 
 /* We want logging for every hook */
 unsigned int call_elem_hook(struct nf_hook_ops *ops,
@@ -485,7 +492,11 @@
 	if (load_modules && !load_all_modules())
 		barf("Module loading failed\n");
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
+	nf_register_queue_handler(PF_INET, &enqueue_packet_h);
+#else
 	nf_register_queue_handler(PF_INET, enqueue_packet, NULL);
+#endif
 	
 	nfsim_log(LOG_UI, "initialisation done");
 
core/core.h +96 -0

138 lines not on this page · raw message

kernelenv/include/kernelenv.h +3 -0
diff -rN -u old-nfsim-0/kernelenv/include/kernelenv.h new-nfsim-0/kernelenv/include/kernelenv.h
@@ -181,6 +181,9 @@
 #define num_possible_cpus() 1
 #define for_each_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++)
 #define  SMP_CACHE_BYTES (1<<7)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14)
+#define __read_mostly
+#endif
 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
 #define cpu_possible(cpu)	((cpu) == 0)
 #endif
netfilter/Makefile +6 -1
diff -rN -u old-nfsim-0/netfilter/Makefile new-nfsim-0/netfilter/Makefile
@@ -1,7 +1,12 @@
 
 all: dummy.o modules netfilter.o 
 
-netfilter.o: $(TYPE)/$(TYPE).o core/netfilter.o
+# XXX a hack to see if we're >= 2.6.14 - please rewrite
+ifeq ($(shell ls nf_queue.c 2>/dev/null),nf_queue.c)
+MORE_OBJ = core.o nf_log.o nf_queue.o nf_sockopt.o
+endif
+
+netfilter.o: $(TYPE)/$(TYPE).o core/netfilter.o $(MORE_OBJ)
 	ld -r -o $@ $^
 
 $(TYPE)/$(TYPE).o: $(TYPE)/
#1 lore raw
Quoted 3 lines · Max Kellermann

this patch makes nfsim compile with Linux 2.6.14-rc2. It uses #ifdefs to keep it compatible with the older kernels. The changes were mostly copy+paste from the original kernel headers to core/core.h etc.

By the way, my patch is not complete. I just tried to run my test suite, and it failed whenever ip_nat_mangle_tcp_packet() was called. 2.6.14 changes the way skb_ip_make_writable() / skb_make_writable() work. I am already working on an additional patch which correctly implements skb_make_writable() in nfsim.

Max

#2 lore raw

What is the comparing sequence of user defined module?

Hello folks,

I am trying to know what is the ordering of module comparing in the kernel.
Is it by alphabet of module name? Or by loading module sequence?

What I want to know is the comparing sequence of do_match function in the ip_tables.c ?

Thanks in advance

Vincent