Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,38 @@ The tar file in this repository is a collection of binaries that can be loaded o
Please see below for instructions on how to install the prebuilt kernel module and associated utils.
## Table of Contents

* [Install](#install)
* [Install with script](#install-with-script)
* [Install manually](#install-manually)
* [Build from source](#build-from-source)
* [Surviving Reboots](#surviving-reboots)
* [Upgrades](#upgrades)
* [Issues loading module](#issues-loading-module)
* [Configuration](#configuration)
* [Start tunnel](#start-tunnel)
* [Stop tunnel](#stop-tunnel)
* [Uninstall](#uninstall)
* [FAQ](#faq)

The Unifi UDM is built on a powerful quad core ARM64 CPU that can sustain up to 800Mb/sec throughput through an IPSec tunnel. There has been a large interest in a kernel port of WireGuard since performance is expected to be similar if not more. This kernel module was built using the WireGuard backport as the UDM runs an older kernel(4.1.37). If you want to compile your own version, there will be a seperate build page posted soon. This was built from the GPL sources Ubiquiti sent me. I have a seperate github page for the Ubiquiti UDM GPL source code: https://github.com/tusc/UDM-source-code/blob/main/README.md


## Install
1. We first need to download the tar file onto the UDM. Connect to it via SSH and type the following command to download the tar file. You need to download the following tar file. NOTE: always check [this link](https://github.com/tusc/wireguard-kmod/releases) for the latest release.
## Install with script

1. On UDM/P install [on_boot.d](https://github.com/boostchicken/udm-utilities/tree/master/on-boot-script) to make the changes persistent after reboots. If you have UDM-SE or UDR go step 2.

2. Install by using the script

```sh
/usr/bin/curl -fsL "https://github.com/tusc/wireguard-kmod/HEAD/install" | /bin/sh
```

3. Place your wg0.conf file in the given path printed when the script has finished (normally in `/etc/wireguard`).

The tar file includes other useful utils such as htop, iftop and [qrencode.](#faq)

## Install manually

1. We first need to download the tar file onto the UDM. Connect to it via SSH and type the following command to download the tar file. You need to download the following tar file. NOTE: always [this link](https://github.com/tusc/wireguard-kmod/releases) check for the latest release.

```sh
curl -LJo wireguard-kmod.tar.Z https://github.com/tusc/wireguard-kmod/releases/download/v09-24-22/wireguard-kmod-09-24-22.tar.Z
Expand Down Expand Up @@ -169,6 +186,15 @@ I'm currently testing throughput using iperf3 between a UDM Pro and an Ubuntu cl
# wg-quick down wg0
```

## Uninstall

```sh
/usr/bin/curl -fsL "https://github.com/tusc/wireguard-kmod/HEAD/uninstall" | /bin/sh
```

By default does not remove `/data/wireguard` or `/mnt/data/wireguard`, you can remove it after executing the script or do it manually by using `rm -rf /mnt/data/wireguard /data/wireguard` or download the script and use argument `--purge`.


## FAQ

<details>
Expand Down
140 changes: 140 additions & 0 deletions install
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
#!/bin/sh

{
GITHUB_API_URL="https://api.github.com/repos"
GITHUB_REPOSITORY="tusc/wireguard-kmod"

TMP_WIREGUARD_FILE="/tmp/wireguard-kmod.tar.Z"

ON_BOOT_PATH="/mnt/data/on_boot.d"
ON_BOOT_D_WG_PATH="/mnt/data/wireguard/on_boot.d"
ON_BOOT_D_WG_FILENAME="20-wireguard.sh"

WG_SERVICE_URL="https://raw.githubusercontent.com/tusc/wireguard-kmod/main/src/boot/setup-wireguard.service"
WG_SERVICE_PATH="/etc/systemd/system/setup-wireguard.service"

check_dependency() {
for dep in "$@"; do
[ -n "$(command -v "$dep")" ] ||
echo "\`${dep}\` is not installed"

done

unset dep
}

udm_model() {
case "$(ubnt-device-info model || true)" in
"UniFi Dream Machine SE")
echo "udmse"
;;
"UniFi Dream Machine Pro")
echo "udmpro"
;;
"UniFi Dream Machine")
echo "udm"
;;
"UniFi Dream Router")
echo "udr"
;;
*)
echo "unknown"
;;
esac
}

get_latest_download_url() {
check_dependency curl

curl -fsL "${GITHUB_API_URL}/${GITHUB_REPOSITORY}/releases/latest" |
awk '$0 ~ /"browser_download_url"/ {sub(/.*:\s*"/,"",$0); gsub("\"", "", $0); print $0}'
}

get_persistent_path() {
if [ -n "$(command -v ubnt-device-info)" ]; then
case "$(ubnt-device-info summary | awk '$1 ~ /^Model:$/ {gsub(/[\(\)*]/, "", $NF); print $NF}')" in
UDR)
echo "/data${1:+/$1}"
;;
*)
echo "/mnt/data${1:+/$1}"
;;
esac
fi
}

on_boot_script() {
cat << EOF
#!/usr/bin/env bash

WG_INTERFACE="wg0"


if [ -d "/data/wireguard" ]; then
[[ -x "/data/wireguard/setup_wireguard.sh" ]] && "/data/wireguard/setup_wireguard.sh" >&2
elif [ -d "/mnt/data/wireguard" ]; then
[[ -x "/mnt/data/wireguard/setup_wireguard.sh" ]] && "/mnt/data/wireguard/setup_wireguard.sh" >&2
else
exit 1
fi

if [[ -n "/usr/bin/wg-quick" ]]; then
/usr/bin/wg-quick up "\$WG_INTERFACE"
else
# You can add whatever here like a telegram script to notify that wg could not start
echo "Wireguard could not be started \$(date +%s)" >> /var/log/wg-startup.log
fi

EOF
}

echo "Downloading wireguard-kmod"
curl -sLJo "$TMP_WIREGUARD_FILE" "$(get_latest_download_url)"
sleep 1

if [ ! -f "$TMP_WIREGUARD_FILE" ]; then
echo "Wireguard downloaded file could not be found."
exit 4
fi

echo "Unzipping wireguard-kmod"
tar -C "$(get_persistent_path)" -xzf "$TMP_WIREGUARD_FILE"
sleep 1

if [ ! -d "$(get_persistent_path "wireguard")" ]; then
echo "Wireguard-kmod was not downloaded"
exit 4
fi

echo "Moving to $(get_persistent_path "wireguard")"
cd "$(get_persistent_path "wireguard")" || exit 4
echo "Execution permissions"
chmod +x "$(get_persistent_path "wireguard")/setup_wireguard.sh"
"$(get_persistent_path "wireguard")/setup_wireguard.sh"

case "$(udm_model)" in
udm|udmpro)
echo "Creating on boot script for wireguard setup"
mkdir -p "$ON_BOOT_D_WG_PATH"
rm -f "${ON_BOOT_D_WG_PATH}/${ON_BOOT_D_WG_FILENAME}"
[ ! -f "${ON_BOOT_D_WG_PATH}/${ON_BOOT_D_WG_FILENAME}" ] && on_boot_script > "${ON_BOOT_D_WG_PATH}/${ON_BOOT_D_WG_FILENAME}"
chmod +x "${ON_BOOT_D_WG_PATH}/${ON_BOOT_D_WG_FILENAME}"
ln -s "${ON_BOOT_D_WG_PATH}/${ON_BOOT_D_WG_FILENAME}" "$ON_BOOT_PATH"
;;
*)
check_dependency systemctl

echo "Creating system startup script for wireguard"
curl -sLo "$WG_SERVICE_PATH" "$WG_SERVICE_URL"
systemctl daemon-reload
systemctl enable "$(basename "${WG_SERVICE_PATH%.*}")"
;;
esac

echo
echo "Installation has finished sucessfully!"
echo
echo "Wireguard configuration path"
echo " $(get_persistent_path "wireguard")/etc/wireguard"
echo
}
48 changes: 48 additions & 0 deletions uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env sh

purge=false
DATA_DIR=""
WG_SERVICE_PATH="/etc/systemd/system/setup-wireguard.service"

case " $* " in
*" --help "*)
cat << EOF

Remove wireguard-kmod installation files

Usage:
${BASH_SOURCE} [--purge]

Options:
--purge Delete {/mnt/data,/data}/wireguard path
EOF
exit
;;
*" --purge "*)
purge=true
;;
esac

if [ -d "/mnt/data" ]; then
DATA_DIR="/mnt/data"
elif [ -d "/data" ]; then
DATA_DIR="/data"
fi

if ${purge:-false}; then
echo "Removing wireguard files and configuration"
rm -rf "${DATA_DIR}/wireguard"
fi

echo "Removing files"
rm -rf "/usr/bin/wg-quick" "/usr/bin/wg" "/usr/bin/bash" "/usr/bin/qrencode" "/usr/bin/htop" "/usr/sbin/iftop" "/sbin/resolvconf" "/etc/wireguard" "/etc/resolvconf.conf" "/mnt/data/on_boot.d/20-wireguard.sh"

case "$(ubnt-device-info summary | awk '$1 ~ /^Model:$/ {gsub(/[\(\)*]/, "", $NF); print $NF}')" in
UDM|UDM-Pro)
;;
*)
systemctl disable "$(basename "${WG_SERVICE_PATH%.*}")"
systemctl daemon-reload
rm -f "$WG_SERVICE_PATH"
;;
esac