[Netkit.users] Netkit and Kernel module

Massimo Rimondini rimondin at dia.uniroma3.it
Thu Mar 2 23:44:30 CET 2017


Dear Youri,

indeed the source package for the exact kernel version that is used by
the latest release of Netkit (2.6.26.5) has been withdrawn from the
official archives at www.kernel.org. Added to this, recent versions of
GNU make complain about the format used for targets inside the Makefile,
preventing the compilation from even starting. Even after fixing this,
further errors are raised due to outdated includes in the kernel source
tree.

The good news are that none of these problems is related with the issue
you are experiencing. Instead, what I suspect from your report is that
you are just attempting to apply the patches from an incorrect path:
your current directory when doing that should correspond to the kernel
source tree.

The bad news are that getting the whole compilation process to work
nowadays requires a little more fiddling. Assuming that you are
attempting to compile the kernel on an Ubuntu workstation (I am using
16.04 here), to make things (hopefully) simpler you first of all need to
install a few packages (besides the standard compilation tools):

> sudo apt install libc6-dev:i386libvdeplug-dev:i386libpcap0.8-dev:i386
> gcc-multilib


After that, download and save in a directory of your choice the patch
attached to this e-mail. Finally, from the same directory where you have
saved the patch, runthe followingcommands. If everything succeeds (I
have just tested the whole sequence), itshould be all you need to get a
freshly compiled kernelinside linux-2.6.26.5/linux.

> KERNEL_URL=http://web.archive.org/web/20100621080829/http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.26.5.tar.bz2
> KERNEL_FILE=$(basename $KERNEL_URL)
> KERNEL_DIR=${KERNEL_FILE%.tar.bz2}
>
> wget $KERNEL_URL && \
> tar xjf $KERNEL_FILE && \
> cd $KERNEL_DIR && \
> patch -p1 <../fix_outdated_chunks.diff && \
> for CURRENT_PATCH in $NETKIT_HOME/kernel/patches/*.diff; do patch -p1
> <$CURRENT_PATCH; done && \
> cp $NETKIT_HOME/kernel/netkit-kernel-config-i386 .config && \
> make silentoldconfig ARCH=um SUBARCH=i386 && \
> make all modules modules_install ARCH=um SUBARCH=i386 \
>       INSTALL_MOD_PATH=$NETKIT_HOME/kernel/modules

Concerning the way to "plug" your custom kernel module, there is no UML-
or Netkit-specific way of accomplishing this. I suggest you start from
having a look at http://www.tldp.org/LDP/lkmpg/2.6/html/lkmpg.html.
Possibly, it is not the best of simplest reading for what you are trying
to achieve, but at least it is a little starting point. Unfortunately, I
do not have others readily available.

Regards,
Massimo



Il 25/02/17 23:35, Youri Korostelev ha scritto:
> Hello Massimo,
>
> I've been trying to apply your advice, however i'm encountering
> difficulties, after downloading, and unpacking the kernel (i followed
> the readme, the manual part), i tried to apply the patches and i get
> the following error on all the hunks:
> youri a Workstation:~/opt/netkit_install/netkit/kernel$    for
> CURRENT_PATCH in $NETKIT_HOME/kernel/patches/*.diff; do \
>>       patch -p1 < $CURRENT_PATCH; done
> patching file arch/um/drivers/Makefile
> Hunk #1 FAILED at 17.
> 1 out of 1 hunk FAILED -- saving rejects to file arch/um/drivers/Makefile.rej
> patching file include/linux/genetlink.h
> Hunk #1 FAILED at 79.
> 1 out of 1 hunk FAILED -- saving rejects to file include/linux/genetlink.h.rej
> patching file include/linux/if_arp.h
> Hunk #1 FAILED at 86.
> 1 out of 1 hunk FAILED -- saving rejects to file include/linux/if_arp.h.rej
> The next patch would create the file include/linux/mpls.h,
> which already exists!  Assume -R? [n] y
> patching file include/linux/mpls.h
> patching file include/linux/netdevice.h
> Hunk #1 FAILED at 613.
> 1 out of 1 hunk FAILED -- saving rejects to file include/linux/netdevice.h.rej
> The next patch would create the file include/linux/netfilter/xt_mpls.h,
> which already exists!  Assume -R? [n] y
> patching file include/linux/netfilter/xt_mpls.h
> patching file include/linux/ppp_defs.h
> Hunk #1 FAILED at 82.
> 1 out of 1 hunk FAILED -- saving rejects to file include/linux/ppp_defs.h.rej
> patching file include/linux/rtnetlink.h
> Hunk #1 FAILED at 274.
> 1 out of 1 hunk FAILED -- saving rejects to file include/linux/rtnetlink.h.rej
> The next patch would create the file include/linux/shim.h,
> which already exists!  Assume -R? [n] y
> patching file include/linux/shim.h
> patching file include/linux/socket.h
> Hunk #1 FAILED at 184.
> Hunk #2 FAILED at 220.
> 2 out of 2 hunks FAILED -- saving rejects to file include/linux/socket.h.rej
> patching file include/linux/sysctl.h
> Hunk #1 FAILED at 231.
> Hunk #2 FAILED at 789.
> Hunk #3 FAILED at 807.
> 3 out of 3 hunks FAILED -- saving rejects to file include/linux/sysctl.h.rej
> patching file include/net/ip6_fib.h
> Hunk #1 FAILED at 21.
> Hunk #2 FAILED at 43.
> Hunk #3 FAILED at 114.
> 3 out of 3 hunks FAILED -- saving rejects to file include/net/ip6_fib.h.rej
> patching file include/net/ip_fib.h
> Hunk #1 FAILED at 19.
> Hunk #2 FAILED at 41.
> Hunk #3 FAILED at 60.
> Hunk #4 FAILED at 141.
> (and the list goes on)
>
> Is it usual ?
> And I don't see where i should insert the kernel module as a feature
> in this kernel while reading the readme (i'm not quite used to making
> kernels), could you help me out ?
>
> Thanks a lot
>
> 2017-02-14 22:13 GMT+01:00 Massimo Rimondini <rimondin a dia.uniroma3.it>:
>
>> Hi Youri,
>>
>> what you are trying to achieve is not very easy, considering that some of
>> the Netkit components are, unfortunately yet undoubtedly, a bit outdated,
>> and this applies also to the kernel.
>>
>> It is a good choice to build your custom module by relying on an already
>> installed kernel source tree but, as you see, you may encounter two
>> mismatches:
>> - on the kernel release
>> - on the kernel target architecture (supposedly the host's)
>>
>> Instead, I suggest you to download the correct version of the kernel
>> sources from https://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.
>> 26.tar.xz, recompile it for the User Mode architecture (see the
>> instructions at http://wiki.netkit.org/download/netkit-kernel/README),
>> then add your custom module to this build.
>>
>> Regards,
>> Massimo
>>
>>
>> Il 14/02/2017 10:56, Youri Korostelev ha scritto:
>>
>>
>> Hello,
>>
>> I am currently working on netkit for a project,on a ubuntu virtualbox with
>> the  2.6.32-74 version.
>> I've written a kernel module to hook packets with netfilter, and i'd like
>> to load it on my netkit routers.
>> However, i get the following error: (Version magic '2.6.32-74-generic SMP
>> mod_unload modversions 586 ' should be '2.6.26.5-netkit-K2.8 mod_unload")
>> whenever i try the insmod command, since the kernel versions are different.
>> I am looking for a way to build my kernel module for the netkit kernel,
>> from my host machine.
>> Is it possible and how can i do so ? i've tried modifying the makefile in
>> usr/src/ but it did not change the issue, maybe i haven't tried the right
>> things.
>>
>> Thanks for you advice and help.
>>
>>
>> The error:
>>  [image: Images intégrées 1]
>> --
>> -------------------------------------------------------------
>> Youri Korostelev
>> Élève Ingénieur 3ème année
>> ​​
>> ​, spécialisé en logiciel embarqué
>> Telecom Nancy - Université de Lorraine
>> Responsable Bar & Staff - Club Intégration (2015)
>> Responsable Communication - Club Cinéma (2015)
>> Responsable Partenariats - Bureau des élèves
>> Responsable Communication -Club Événements
>>
>> Tél : 06 14 07 95 08
>>
>>
>> _______________________________________________
>> Netkit.users mailing listNetkit.users a list.dia.uniroma3.ithttp://list.dia.uniroma3.it/mailman/listinfo/netkit.users
>>
>>
>>
>> _______________________________________________
>> Netkit.users mailing list
>> Netkit.users a list.dia.uniroma3.it
>> http://list.dia.uniroma3.it/mailman/listinfo/netkit.users
>>
>>
>

-------------- parte successiva --------------
diff -Naur linux-2.6.26.5-original/arch/um/include/init.h linux-2.6.26.5-patched/arch/um/include/init.h
--- linux-2.6.26.5-original/arch/um/include/init.h	2008-09-08 19:40:20.000000000 +0200
+++ linux-2.6.26.5-patched/arch/um/include/init.h	2017-03-02 22:28:07.860178337 +0100
@@ -54,7 +54,7 @@
 #endif
 
 #else
-#if __GNUC__ == 4
+#if __GNUC__ >= 4
 # define __used			__attribute__((__used__))
 #endif
 #endif
diff -Naur linux-2.6.26.5-original/arch/um/os-Linux/mem.c linux-2.6.26.5-patched/arch/um/os-Linux/mem.c
--- linux-2.6.26.5-original/arch/um/os-Linux/mem.c	2008-09-08 19:40:20.000000000 +0200
+++ linux-2.6.26.5-patched/arch/um/os-Linux/mem.c	2017-03-02 22:30:21.106768336 +0100
@@ -12,6 +12,7 @@
 #include <string.h>
 #include <sys/mman.h>
 #include <sys/param.h>
+#include <sys/stat.h>
 #include "init.h"
 #include "kern_constants.h"
 #include "os.h"
diff -Naur linux-2.6.26.5-original/arch/um/os-Linux/start_up.c linux-2.6.26.5-patched/arch/um/os-Linux/start_up.c
--- linux-2.6.26.5-original/arch/um/os-Linux/start_up.c	2008-09-08 19:40:20.000000000 +0200
+++ linux-2.6.26.5-patched/arch/um/os-Linux/start_up.c	2017-03-02 22:31:31.029712336 +0100
@@ -16,6 +16,7 @@
 #include <sys/ptrace.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
+#include <sys/resource.h>
 #include <asm/unistd.h>
 #include "init.h"
 #include "kern_constants.h"
diff -Naur linux-2.6.26.5-original/kernel/timeconst.pl linux-2.6.26.5-patched/kernel/timeconst.pl
--- linux-2.6.26.5-original/kernel/timeconst.pl	2008-09-08 19:40:20.000000000 +0200
+++ linux-2.6.26.5-patched/kernel/timeconst.pl	2017-03-02 22:32:30.563464336 +0100
@@ -370,7 +370,7 @@
 	}
 
 	@val = @{$canned_values{$hz}};
-	if (!defined(@val)) {
+	if (!@val) {
 		@val = compute_values($hz);
 	}
 	output($hz, @val);
diff -Naur linux-2.6.26.5-original/Makefile linux-2.6.26.5-patched/Makefile
--- linux-2.6.26.5-original/Makefile	2008-09-08 19:40:20.000000000 +0200
+++ linux-2.6.26.5-patched/Makefile	2017-03-02 22:22:43.281970336 +0100
@@ -431,7 +431,10 @@
 include $(srctree)/arch/$(SRCARCH)/Makefile
 export KBUILD_DEFCONFIG
 
-config %config: scripts_basic outputmakefile FORCE
+config: scripts_basic outputmakefile FORCE
+	$(Q)mkdir -p include/linux include/config
+	$(Q)$(MAKE) $(build)=scripts/kconfig $@
+%config: scripts_basic outputmakefile FORCE
 	$(Q)mkdir -p include/linux include/config
 	$(Q)$(MAKE) $(build)=scripts/kconfig $@
 
@@ -1548,7 +1551,11 @@
 	$(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
 
 # Modules
-/ %/: prepare scripts FORCE
+/: prepare scripts FORCE
+	$(cmd_crmodverdir)
+	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
+	$(build)=$(build-dir)
+%/: prepare scripts FORCE
 	$(cmd_crmodverdir)
 	$(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
 	$(build)=$(build-dir)


More information about the Netkit.users mailing list