commit f4876efbc3377d66fa4e941bd7a9d74ff292c6e4 Author: Andreas Runfalk Date: Sun Mar 17 16:02:37 2019 +0100 Initial commit Signed-off-by: Andreas Runfalk diff --git a/INFO.sh b/INFO.sh new file mode 100755 index 0000000..96a095a --- /dev/null +++ b/INFO.sh @@ -0,0 +1,11 @@ +#!/bin/bash +source /pkgscripts-ng/include/pkg_util.sh + +package="WireGuard" +version="0.0.20190227" +displayname="WireGuard" +maintainer="Andreas Runfalk" +arch="$(pkg_get_platform)" +description="Adds WireGuard support for your Synology NAS." +[ "$(caller)" != "0 NULL" ] && return 0 +pkg_dump_info diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..dce6e54 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2019 Andreas Runfalk. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software") +, to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included +in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM +, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +IN THE SOFTWARE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..13f49d0 --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +WIREGUARD_VERSION ?= 0.0.20190227 +LIBMNL_VERSION ?= 1.0.4 + +LIBMNL_TAR = libmnl-$(LIBMNL_VERSION).tar.bz2 +LIBMNL_DIR = libmnl-$(LIBMNL_VERSION) + +WIREGUARD_TAR = WireGuard-$(WIREGUARD_VERSION).tar.xz +WIREGUARD_DIR = WireGuard-$(WIREGUARD_VERSION) + +WG_TARGET = $(WIREGUARD_DIR)/src/tools/wg +WG_QUICK_TARGET = $(WIREGUARD_DIR)/wg-quick +WG_MODULE_TARGET = $(WIREGUARD_DIR)/src/wireguard.ko + +ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) + +all: $(WG_TARGET) $(WG_QUICK_TARGET) $(WG_MODULE_TARGET) + +$(LIBMNL_TAR): + wget https://netfilter.org/projects/libmnl/files/$(LIBMNL_TAR) + +$(LIBMNL_DIR)/Makefile: $(LIBMNL_TAR) + tar -xf $(LIBMNL_TAR) + (cd $(LIBMNL_DIR) && ./configure --host=x86_64-unknown-linux-gnu --enable-static --target=arm-unknown-linux-gnueabi CC=$(CROSS_COMPILE)-gcc) + +$(LIBMNL_DIR)/src/.libs/libmnl.a: $(LIBMNL_DIR)/Makefile + make -C $(LIBMNL_DIR) + +$(WIREGUARD_TAR): + wget https://git.zx2c4.com/WireGuard/snapshot/$(WIREGUARD_TAR) + +$(WIREGUARD_DIR)/src/Makefile: $(WIREGUARD_TAR) + tar -xf $(WIREGUARD_TAR) + +$(WG_TARGET): $(LIBMNL_DIR)/src/.libs/libmnl.a $(WIREGUARD_DIR)/src/Makefile + CFLAGS=-I$(ROOT_DIR)/$(LIBMNL_DIR)/include LDFLAGS=-L$(ROOT_DIR)/$(LIBMNL_DIR)/src/.libs make -C $(WIREGUARD_DIR)/src/tools CC=$(CROSS_COMPILE)-gcc + +$(WG_QUICK_TARGET): $(WIREGUARD_DIR)/src/Makefile + cp $(WIREGUARD_DIR)/src/tools/wg-quick/linux.bash $(WG_QUICK_TARGET) + +$(WG_MODULE_TARGET): + make -C $(WIREGUARD_DIR)/src module ARCH=arm KERNELDIR=$(KSRC) EXTRA_CFLAGS="-DCONFIG_SYNO_BACKPORT_ARM_CRYPTO=1" + +install: all + mkdir -p $(DESTDIR)/wireguard/ + install $(WG_TARGET) $(DESTDIR)/wireguard/ + install $(WG_QUICK_TARGET) $(DESTDIR)/wireguard/ + install $(WG_MODULE_TARGET) $(DESTDIR)/wireguard/ + +clean: + rm -rf $(LIBMNL_TAR) $(LIBMNL_DIR) $(WIREGUARD_TAR) $(WIREGUARD_DIR) diff --git a/PACKAGE_ICON.PNG b/PACKAGE_ICON.PNG new file mode 100644 index 0000000..9863a22 Binary files /dev/null and b/PACKAGE_ICON.PNG differ diff --git a/PACKAGE_ICON_256.PNG b/PACKAGE_ICON_256.PNG new file mode 100755 index 0000000..623316a Binary files /dev/null and b/PACKAGE_ICON_256.PNG differ diff --git a/README.rst b/README.rst new file mode 100644 index 0000000..c267c1a --- /dev/null +++ b/README.rst @@ -0,0 +1,67 @@ +WireGuard support for Synology NAS +================================== +This package adds WireGuard support for Synology NAS drives. + + +Disclaimer +---------- +You use everything here at your own risk. I am responsible if this breaks your +NAS. + + +Compatibility list +------------------ +The following drives have been tested: + +===== ========= =========== =========== +Model Platform DSM Version Is working? +----- --------- ----------- ----------- +D218j armada38x 6.2 Yes +===== ========= =========== =========== + + +Compiling +--------- +I've used docker to compile everything as ``pkgscripts-ng`` clutters the file +system quite a bit. Start by setting up a new docker container and enter a bash +prompt inside it: + +.. code-block:: bash + + sudo docker create -it --privileged --name synobuild ubuntu + sudo docker start synobuild + sudo docker exec -it synobuild bash + +Now we can setup the build toolchain inside the Docker container: + +.. code-block:: bash + + apt-get update + apt-get install git python3 wget ca-certificates + git clone https://github.com/SynologyOpenSource/pkgscripts-ng + mkdir source + git clone https://github.com/runfalk/synology-wireguard /source/WireGuard + +The next step is figuring out which platform and DSM version to compile for. +Using `this table `_ +you can figure out how the next command should look like. In my case it's: + +.. code-block:: bash + + pkgscripts-ng/EnvDeploy -p armada38x -v 6.2 + +Now we can build an SPK package: + +.. code-block:: bash + + pkgscripts-ng/PkgCreate.py -p armada38x -v 6.2 -S --build-opt=-J --print-log -c WireGuard + +There should now be an SPK in ``/result_spk`` + +Credits +------- +I based a lot of this work on +`this guide `_ +by Reddit user `akhener `_. However, I had +to modify their instructions a lot since my NAS has an ARM which made cross +compilation a lot trickier. diff --git a/SynoBuildConf/build b/SynoBuildConf/build new file mode 100644 index 0000000..375dabd --- /dev/null +++ b/SynoBuildConf/build @@ -0,0 +1,8 @@ +#!/bin/bash +case ${MakeClean} in + [Yy][Ee][Ss]) + make clean + ;; +esac + +make ${MAKE_FLAGS} KSRC=$KSRC CROSS_COMPILE=$CROSS_COMPILE ARCH=$ARCH diff --git a/SynoBuildConf/depends b/SynoBuildConf/depends new file mode 100644 index 0000000..e0fd3dd --- /dev/null +++ b/SynoBuildConf/depends @@ -0,0 +1,2 @@ +[default] +all="6.2" diff --git a/SynoBuildConf/install b/SynoBuildConf/install new file mode 100644 index 0000000..0af48cc --- /dev/null +++ b/SynoBuildConf/install @@ -0,0 +1,50 @@ +#!/bin/bash +### Use PKG_DIR as working directory. +PKG_DIR=/tmp/_test_spk +rm -rf $PKG_DIR +mkdir -p $PKG_DIR + +### get spk packing functions +source /pkgscripts-ng/include/pkg_util.sh + +create_package_tgz() { + local package_tgz_dir=/tmp/_package_tgz + + ### clear destination directory + rm -rf $package_tgz_dir && mkdir -p $package_tgz_dir + + ### install needed file into PKG_DIR + make install DESTDIR="$package_tgz_dir" + + ### create package.tgz $1: source_dir $2: dest_dir + pkg_make_package $package_tgz_dir "${PKG_DIR}" +} + +create_spk(){ + local scripts_dir=$PKG_DIR/scripts + + ### Copy package center scripts to PKG_DIR + mkdir -p $scripts_dir + cp -av scripts/* $scripts_dir + + ### Copy package icon + cp -av PACKAGE_ICON*.PNG $PKG_DIR + + ### Generate INFO file + ./INFO.sh > INFO + cp INFO $PKG_DIR/INFO + + ### Create the final spk. + # pkg_make_spk + # Please put the result spk into /image/packages + # spk name functions: pkg_get_spk_name pkg_get_spk_unified_name pkg_get_spk_family_name + mkdir -p /image/packages + pkg_make_spk ${PKG_DIR} "/image/packages" $(pkg_get_spk_name) +} + +main() { + create_package_tgz + create_spk +} + +main "$@" diff --git a/scripts/start-stop-status b/scripts/start-stop-status new file mode 100755 index 0000000..767443f --- /dev/null +++ b/scripts/start-stop-status @@ -0,0 +1,20 @@ +#!/bin/sh +case $1 in + start) + /sbin/insmod $SYNOPKG_PKGDEST/wireguard/wireguard.ko + exit 0 + ;; + stop) + /sbin/rmmod $SYNOPKG_PKGDEST/wireguard/wireguard.ko + exit 0 + ;; + status) + /sbin/lsmod | grep wireguard && exit 0 || exit 3 + ;; + killall) + ;; + log) + exit 0 + ;; +esac +