Compiling IPv6 modules from source for DD-WRT

DD-WRT provides a lot of builds for different flash chip sizes. Sometimes though, you might need a module or two that isn’t included in the compiled firmware. Fortunately because of the way DD-WRT is developed (open source) you are able to grab the DD-WRT kernel sources from SVN and do a bit of DIY kernel module compiling. Though its not as simple as it sounds, but hopefully this general guide you get you on your way in compiling kernel modules. For this specific guide I am demonstrating how to compile IPv6 modules.
My setup:
- Ubuntu 12.10 (Virtual Machine)
- Compiling for ASUS RT N66U, 3.10.2 kernel and revision 22118
Acknowledgements:
This guide wouldn’t of been possible without the following websites that allowed me to learn how to do this myself:
- http://blog.dest-unreach.be/2010/12/01/compiling-custom-dd-wrt-kernel-modules
- http://www.jonisdumb.com/2011/02/compiling-ip6tables-dd-wrt.html
Installing some development tools:
sudo apt-get install gcc g++ binutils patch bzip2 flex bison make gettext unzip zlib1g-dev libc6 subversion ncurses-dev ccache
These will be required during compiling kernel modules
Getting the required kernel source
Start by creating a directory to hold the kernel source:
cd ~ mkdir -p DD-WRT cd DD-WRT
Here I created a containing folder, in case you may want to checkout multiple kernel sources in the future.
Now you will need to pull the appropriate kernel source and revision number to match your current DD-WRT firmware via SVN. You can find your kernel version via:
uname -r
You will the need to match the reported number with the correct kernel source within SVN at /src/linux/universal:
svn checkout svn://svn.dd-wrt.com/DD-WRT/src/linux/universal/linux-3.10 -r 22118
Apart from the kernel source, its also important to get the matching SVN revision that your currently running. In my case the revision number is 22118. It will take a bit of time to download everything.
Getting the DD-WRT toolchain(s) for compiling
cd /opt wget http://www.dd-wrt.com/dd-wrtv2/downloads/others/sourcecode/toolchains/current-toolchains.tar.bz2 tar jxvf current-toolchains.tar.bz2
The toolchain tar.bz2 package is about 1.3 GB in size, so grab a drink, do something else for while as it might take a while depending on your internet connection. Once the download is complete it will also take some time to extract as well. Once that’s completed its time to setup the make file.
Adding toolchain to $PATH
Before compiling you’ll need to use the correct toolchain, in my case I used the following:
PATH=$PATH:/opt/toolchain-mipsel_gcc4.1.2/bin
Creating a .config file
Now you need to create a .config file in order to specify the modules you want to compile. The kernel source actually contains a lot of default config files for different builds. In my case there is a .config_bcmmips config in there that is perfect for my router. Switch into your kernel source directory:
cd ~/DD-WRT/linux-3.10
Change the kernel version to the one you actually downloaded from SVN.
The .config files are on the root of the kernel source, but take note, they are dot files. You simply need to copy the config that matches your router, in my case this config will be fine:
cp .config_bcmmips .config
Regarding what IPv6 modules to compile, its really up to you, but here is a good set below, it provides the IPv6 modules and various modules for ip6tables to work effectively:
CONFIG_NF_CONNTRACK_IPV6=m CONFIG_IP6_NF_IPTABLES=m CONFIG_IP6_NF_MATCH_RT=m CONFIG_IP6_NF_MATCH_OPTS=m CONFIG_IP6_NF_MATCH_FRAG=m CONFIG_IP6_NF_MATCH_HL=m CONFIG_IP6_NF_MATCH_OWNER=m CONFIG_IP6_NF_MATCH_IPV6HEADER=m CONFIG_IP6_NF_MATCH_AH=m CONFIG_IP6_NF_MATCH_MH=m CONFIG_IP6_NF_MATCH_EUI64=m CONFIG_IP6_NF_FILTER=m CONFIG_IP6_NF_TARGET_LOG=m CONFIG_IP6_NF_TARGET_REJECT=m CONFIG_IP6_NF_MANGLE=m CONFIG_IP6_NF_TARGET_HL=m CONFIG_IP6_NF_RAW=m
Save this file then run:
make modules ARCH=mips
Older guides on compiling don’t mention the ARCH parameter, but it is now required, otherwise the modules cannot be built. “mips” is likely the arch you want to compile for, but adjust this by all means if mips is not what you want.
You might receive the following error when you do this for the first time:
drivers/net/wireless/Kconfig:284: can't open file "drivers/net/wireless/rt3352/rt2860v2_ap/Kconfig" make[1]: *** [config] Error 1 make: *** [config] Error 2
The error is referring to Ralink drivers that don’t appear to exist in SVN. I have no need for them, hence I did the most basic of fixes and simply edited the drivers/net/wireless/Kconfig file and commented out the following lines:
#if RALINK_DEVICE #source "drivers/net/wireless/rt3352/rt2860v2_ap/Kconfig" #source "drivers/net/wireless/rt3352/rt2860v2_sta/Kconfig" #endif
Now re-run the same make command, it should now build the request modules, plus others listed in the default bcmmips config. You may get asked a couple more prompts regarding IPv6 modules, just press enter to advance through the config and continue to the compiling. Compiling will take a bit of time, so be patient.
Finding the compiled IPv6 modules
So everything compiled successfully, now what? Well you need to grab the modules! An easy way to do this is to run a couple of simple find commands such as:
find . -name '6*.ko' find . -name 'ip6*.ko' find . -name 'nf*.ko'
You should now copy these out of the kernel source and onto your router on jffs and then insmod the modules one by one. Be careful of dependencies, the order of loading modules can be very important, a good order to use would be:
ip_tunnel sit ipv6 ip6_tables ip6t_REJECT ip6table_filter nf_defrag_ipv6 nf_conntrack_ipv6 ip6t_rt
Your kernel may already contain some of these modules, you should check out my other article on getting an IPv6 tunnel working on K3.x builds to get a better understanding.
That’s pretty much, this has been a semi-generic guide, you may have to adapt some parts slightly if you are not using a Broadcom router for example, but hopefully its been helpful to you!