First, you need the linux-headers for your kernel. I spent a long time searching the net before finding a .deb in /opt. Try to install the .deb sudo dpkg -i linux-headers*deb. Likely some things will be missing. I had to install the obvious and also lirc. Finally the deb will install.
Now get tun.c and compile the module tun.ko
Go to https://github.com/orangepi-xunlong/linux-orangepi and click your exact kernel under branches (see uname -r)
Navigate to drivers/net and click the file tun.c
Copy the raw link and use it in place of URL below.
Change to root
sudo su -
Make a temp folder (or use something like /usr/local/src/tun so can revisit later easily), and cd to it
mkdir /tmp/x; cd tmp/x
Download tun.c (use the correct URL for your kernel version)
wget https://raw.githubusercontent.com/orangepi-xunlong/linux-orangepi/refs/heads/orange-pi-5.15-sun60iw2/drivers/net/tun.c
Create a Makefile
obj-m += tun.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
Attempt compile
make
Likely you will need to do the following in tun.c, adding the #if 0 and #endif lines to hide the function and the export that follows:
#if 0
void tun_ptr_free(void *ptr)
{
// ... existing code ...
}
EXPORT_SYMBOL_GPL(tun_ptr_free);
#endif
Do the same for the tun_get_socket and tun_get_tx_ring functions.
Now it will compile and create tun.ko
Move it to your net modules folder
mv tun.ko /lib/modules/$(uname -r)/kernel/drivers/net/
Update depmod
depmod -a
Install the module (should work)
insmod tun
Make it load on boot
echo "tun" | sudo tee /etc/modules-load.d/tun.conf
Note: If you run apt upgrade and it installs a new kernel version, your tun.ko will stop working because it was compiled specifically for your version. If that happens, you'll need to recompile against the new headers and put the file in the drivers/net folder for the new version.