Tiny Core Linux

General TC => Programming & Scripting - Unofficial => Topic started by: GNUser on May 15, 2020, 09:12:54 AM

Title: how to compile wireguard kernel module for TCL
Post by: GNUser on May 15, 2020, 09:12:54 AM
I need wireguard for my wireless router, which is powered by TCL10 32-bit.

In case it's helpful to anyone, here's how I created the wireguard kernel module:
Code: [Select]
$ tce-load -i compiletc perl5 bash ncursesw-dev bc glibc_apps elfutils-dev git
$ cd $HOME/Downloads
$ git clone https://git.zx2c4.com/wireguard-linux-compat
$ wget http://tinycorelinux.net/10.x/x86/release/src/kernel/linux-4.19.10-patched.txz
$ wget http://tinycorelinux.net/10.x/x86/release/src/kernel/config-4.19.10-tinycore
$ tar -xvf linux-4.19.10-patched.txz
$ cd linux-4.19.10
$ cp $HOME/Downloads/config-4.19.10-tinycore .config
$ $HOME/Downloads/wireguard-linux-compat/kernel-tree-scripts/jury-rig.sh $HOME/Downloads/linux-4.19.10
$ make oldconfig
-> when asked about CONFIG_WIREGUARD choose M, when asked about CONFIG_WIREGUARD_DEBUG choose as you like (I went with y)
$ make prepare scripts
$ make M=net/wireguard modules
Now $HOME/Downloads/linux-4.19.10/net/wireguard/wireguard.ko exists and can be copied to my router as /lib/modules/4.19.10-tinycore/kernel/net/wireguard/wireguard.ko

To use it, just run depmod then load the module. Note that the ipv6 module is required. So, assuming wireguard.ko has already been copied over to the router, these are the final commands to run in the router:
Code: [Select]
$ tce-load -wi ipv6-4.19.10-tinycore
$ sudo modprobe ipv6
$ sudo depmod
$ sudo modprobe wireguard
Done! Now the wireguard kernel module is loaded and ready to go.

Note that in order to do anything useful with the module, you need wireguard-tools (wg and wg-quick), which can be found at https://www.wireguard.com/compilation and are trivial to compile.

I found out the hard way that  wg-quick  requires resolvconf or openresolv (neither of which is available in the TCL repository) and a newer version of iproute2 (for some newfangled options to the  ip  command) than what's available in the repository, but it was pretty easy to compile openresolv and iproute2.


Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on May 15, 2020, 09:50:57 AM
I'm going to submit wireguard.tcz, openresolv.tcz and updated iproute2.tcz extensions for TCL10 32bit so that other users of this TCL version don't have to redo any of the above. All they'll need to do is this:
Code: [Select]
$ tce-load -wi wireguard
P.S. The extensions were submitted :)
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on May 16, 2020, 04:39:34 AM
I also submitted the extensions for TCL11 64-bit.
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 05:42:24 AM
juanito: I separated wireguard.tcz into two separate extensions as you suggested (wireguard-tools.tcz and wireguard-KERNEL.tcz). I submitted the extensions for both TCL11 64-bit and TCL10 32-bit.

Fellow users: wireguard-tools.tcz is now the main extension that pulls in everything you need. So, assuming your (client) config file is /etc/wireguard/wg0.conf, this is how to create a VPN tunnel on TCL:

Code: [Select]
$ tce-load -wi wireguard-tools
$ sudo wg-quick up wg0

P.S. Interface name is based on the conf file (so wg0.conf creates an interface called wg0). If you prefer the interface to be named tun0, simply name the config file tun0.conf. Also, the config file can be in any location. If you use a location other than the default /etc/wireguard directory, you have to specify full path to the config file. For example:

Code: [Select]
$ sudo wg-quick up /opt/goodies/wg0.conf
Title: Re: how to compile wireguard kernel module for TCL
Post by: Rich on June 05, 2020, 05:56:27 AM
Hi GNUser
... If you prefer the interface to be named tun0, simply name the config file tun0.conf. ...
Just a heads up, if you run:
Code: [Select]
ifconfig -aone of the interface names returned is called  tunl0.  I don't really know what its purpose is, just wanted to point it out.
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 06:05:50 AM
Thanks for the heads-up, Rich. I have tunl0, too, even when no vpn interface exists. I'm not sure what tunl0's purpose is, but it doesn't seem to have anything to do with vpn.

The reason I mention  tun0  is that the venerable openvpn creates tun0 by default. Because I used openvpn for a long time, all my firewall/networking scripts assume the vpn interface is named tun0. By having wireguard name its interface tun0, wireguard has been for me a drop-in replacement for openvpn :)

P.S. In my limited experience, I've found that a vpn connection created with wireguard is more stable than one created with openvpn. I used to have a script in my router that would kill openvpn and restart it every six hours, since after six hours there would sometimes be dropped connections. With wireguard, my router connected to vpn provider 10 days ago and the connection has been solid for 240 hours and counting!
Title: Re: how to compile wireguard kernel module for TCL
Post by: Juanito on June 05, 2020, 06:13:33 AM
Posted - thanks for your contribution  :)
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 06:14:39 AM
You're welcome. It's my pleasure to contribute to such a fine project :)
Title: Re: how to compile wireguard kernel module for TCL
Post by: Rich on June 05, 2020, 06:18:07 AM
Hi GNUser
Thanks for the heads-up, Rich. I have tunl0, too, even when no vpn interface exists. I'm not sure what tunl0's purpose is, but it doesn't seem to have anything to do with vpn. ...
I mention it on the off chance someone decides to name their interface  tunl0  and it results in a conflict.
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 06:56:17 AM
juanito - When you have time, please also post the extensions for TCL10 32-bit. My local mirror is restless until it is in sync with the official repository ;)
Title: Re: how to compile wireguard kernel module for TCL
Post by: Juanito on June 05, 2020, 07:37:48 AM
I didn't see any wireguard extensions for 32-bit?
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 07:40:23 AM
Hmmm. Maybe it got lost in transit. I just re-submitted it.
Title: Re: how to compile wireguard kernel module for TCL
Post by: hiro on June 05, 2020, 04:58:06 PM
small tip after wasting some of my time with this: you really only need wg.
wg-quick doesn't support most scenarios...
the only thing you lose is the automatically added ip address and route, but that's only 2 lines of shell script ;)
Title: Re: how to compile wireguard kernel module for TCL
Post by: GNUser on June 05, 2020, 05:15:23 PM
Very true. wg is the main tool. wg-quick is just a simple shell script that automates the steps required for typical/basic usage.
Title: Re: how to compile wireguard kernel module for TCL
Post by: ramblurr on October 21, 2020, 01:46:11 AM
Any chance we could get the wireguard tczs for arm (rpi in my case)?
Title: Re: how to compile wireguard kernel module for TCL
Post by: ramblurr on October 21, 2020, 02:41:54 AM
I'm trying to follow the original topic's instructions, but it seems several extensions and the kernel config are missing for the arm6 release:

ncursesw-dev
elfutils-dev

and the kernel config at http://tinycorelinux.net/11.x/armv6/releases/RPi/src/

Is it possible to compile wireguard for tinycore arm6?
Title: Re: how to compile wireguard kernel module for TCL
Post by: Rich on October 21, 2020, 05:57:39 AM
Hi ramblurr
Welcome to the forum.

...  the kernel config are missing for the arm6  ...
Courtesy of Paul_123:
Code: [Select]
sudo modprobe configs
zcat /proc/config.gz > <path to kernel source>/.config

Quote
... ncursesw-dev ...
The static libraries listed here and the shared objects in ncurses.tcz.list all have a  w  suffix:
http://tinycorelinux.net/11.x/armv6/tcz/ncurses-dev.tcz.list
http://tinycorelinux.net/11.x/armv6/tcz/ncurses.tcz.list
Title: Re: how to compile wireguard kernel module for TCL
Post by: Paul_123 on October 21, 2020, 07:08:57 AM
AFAIK, Wireguard did not make it into the official kernel until 5.9.y (Maybe not until 5.10.y).  And has not been officially backported.   I realize there are wireguard supported backports, but I'm not willing to deal with those.

If someone wants to take on creating the kernel modules and utils, we would gladly accept the contribution.

Title: Re: how to compile wireguard kernel module for TCL
Post by: Juanito on October 22, 2020, 01:37:03 AM
ncursesw-dev
elfutils-dev

The piCore equivalents are ncurses-dev and libelf-dev