2021-01-04 18:39:58 +07:00
|
|
|
APPLY_MEMNEQ_PATCH ?= 0
|
2021-01-21 07:45:49 +07:00
|
|
|
APPLY_SPINLOCK_PATCH ?= 0
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
LIBMNL_TAR := libmnl-$(LIBMNL_VERSION).tar.bz2
|
|
|
|
LIBMNL_DIR := libmnl-$(LIBMNL_VERSION)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-12-29 04:37:29 +07:00
|
|
|
WIREGUARD_TAR := wireguard-linux-compat-$(WIREGUARD_VERSION).tar.xz
|
|
|
|
WIREGUARD_DIR := wireguard-linux-compat-$(WIREGUARD_VERSION)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-12-29 04:37:29 +07:00
|
|
|
WIREGUARD_TOOLS_TAR := wireguard-tools-$(WIREGUARD_TOOLS_VERSION).tar.xz
|
|
|
|
WIREGUARD_TOOLS_DIR := wireguard-tools-$(WIREGUARD_TOOLS_VERSION)
|
|
|
|
|
|
|
|
WG_TARGET := $(WIREGUARD_TOOLS_DIR)/src/wg
|
|
|
|
WG_QUICK_TARGET := $(WIREGUARD_TOOLS_DIR)/wg-quick
|
2019-03-17 22:48:12 +07:00
|
|
|
WG_MODULE_TARGET := $(WIREGUARD_DIR)/src/wireguard.ko
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
GCC := $(CROSS_COMPILE)gcc
|
2019-03-20 02:54:29 +07:00
|
|
|
TARGET_TRIPLE := $(shell echo $(CROSS_COMPILE)|cut -f4 -d/ -)
|
2019-03-17 22:48:12 +07:00
|
|
|
|
|
|
|
ROOT_DIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
|
2019-03-17 22:02:37 +07:00
|
|
|
|
|
|
|
all: $(WG_TARGET) $(WG_QUICK_TARGET) $(WG_MODULE_TARGET)
|
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Download libmnl source tarball
|
2019-03-17 22:02:37 +07:00
|
|
|
$(LIBMNL_TAR):
|
2023-09-22 23:01:23 +07:00
|
|
|
wget --no-check-certificate https://netfilter.org/projects/libmnl/files/$(LIBMNL_TAR)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Prepare libmnl for building
|
2019-03-17 22:02:37 +07:00
|
|
|
$(LIBMNL_DIR)/Makefile: $(LIBMNL_TAR)
|
|
|
|
tar -xf $(LIBMNL_TAR)
|
2019-03-20 02:54:29 +07:00
|
|
|
(cd $(LIBMNL_DIR) && ./configure --host=$(shell gcc -dumpmachine) --enable-static --target=$(TARGET_TRIPLE) CC=$(GCC))
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Compile libmnl static lib
|
2019-03-17 22:02:37 +07:00
|
|
|
$(LIBMNL_DIR)/src/.libs/libmnl.a: $(LIBMNL_DIR)/Makefile
|
|
|
|
make -C $(LIBMNL_DIR)
|
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Download WireGuard source tarball
|
2019-03-17 22:02:37 +07:00
|
|
|
$(WIREGUARD_TAR):
|
2023-09-22 23:01:23 +07:00
|
|
|
wget --no-check-certificate https://git.zx2c4.com/wireguard-linux-compat/snapshot/$(WIREGUARD_TAR)
|
2019-12-29 04:37:29 +07:00
|
|
|
|
|
|
|
$(WIREGUARD_TOOLS_TAR):
|
2023-09-22 23:01:23 +07:00
|
|
|
wget --no-check-certificate https://git.zx2c4.com/wireguard-tools/snapshot/$(WIREGUARD_TOOLS_TAR)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2021-01-21 07:45:49 +07:00
|
|
|
# Unpack WireGuard source tarball. Patch the wireguard interface verification
|
|
|
|
# due to the unavailability of rtnl_link_ops structure in the network device on DSM 7.0.
|
|
|
|
# If required, patch the compatibility layer to always use memneq implementation
|
|
|
|
# and patch the spinlock implementation.
|
2019-03-17 22:02:37 +07:00
|
|
|
$(WIREGUARD_DIR)/src/Makefile: $(WIREGUARD_TAR)
|
|
|
|
tar -xf $(WIREGUARD_TAR)
|
2021-01-21 07:45:49 +07:00
|
|
|
patch $(WIREGUARD_DIR)/src/netlink.c $(ROOT_DIR)/patch/netlink.patch
|
|
|
|
patch $(WIREGUARD_DIR)/src/peerlookup.c $(ROOT_DIR)/patch/peerlookup.patch
|
2022-02-09 15:56:35 +07:00
|
|
|
patch $(WIREGUARD_DIR)/src/compat/siphash/siphash.c $(ROOT_DIR)/patch/siphash.patch
|
2021-01-04 18:39:58 +07:00
|
|
|
ifeq ($(APPLY_MEMNEQ_PATCH), 1)
|
2021-01-21 07:45:49 +07:00
|
|
|
patch $(WIREGUARD_DIR)/src/compat/Kbuild.include $(ROOT_DIR)/patch/memneq.patch
|
|
|
|
endif
|
|
|
|
ifeq ($(APPLY_SPINLOCK_PATCH), 1)
|
|
|
|
patch $(WIREGUARD_DIR)/src/ratelimiter.c $(ROOT_DIR)/patch/spinlock.patch
|
2019-03-22 22:11:03 +07:00
|
|
|
endif
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-12-29 04:37:29 +07:00
|
|
|
$(WIREGUARD_TOOLS_DIR)/src/Makefile: $(WIREGUARD_TOOLS_TAR)
|
|
|
|
tar -xf $(WIREGUARD_TOOLS_TAR)
|
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Build the wg command line tool
|
2019-12-29 04:37:29 +07:00
|
|
|
$(WG_TARGET): $(LIBMNL_DIR)/src/.libs/libmnl.a $(WIREGUARD_TOOLS_DIR)/src/Makefile
|
|
|
|
CFLAGS=-I$(ROOT_DIR)/$(LIBMNL_DIR)/include LDFLAGS=-L$(ROOT_DIR)/$(LIBMNL_DIR)/src/.libs make -C $(WIREGUARD_TOOLS_DIR)/src CC=$(GCC)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Choose the correct wg-quick implementation
|
2019-12-29 04:37:29 +07:00
|
|
|
$(WG_QUICK_TARGET): $(WIREGUARD_TOOLS_DIR)/src/Makefile
|
|
|
|
cp $(WIREGUARD_TOOLS_DIR)/src/wg-quick/linux.bash $(WG_QUICK_TARGET)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
2019-03-17 22:48:12 +07:00
|
|
|
# Build wireguard.ko kernel module
|
2019-12-29 04:37:29 +07:00
|
|
|
$(WG_MODULE_TARGET): $(WIREGUARD_DIR)/src/Makefile
|
2019-03-20 02:54:29 +07:00
|
|
|
make -C $(WIREGUARD_DIR)/src module ARCH=$(ARCH) KERNELDIR=$(KSRC)
|
2019-03-17 22:02:37 +07:00
|
|
|
|
|
|
|
install: all
|
|
|
|
mkdir -p $(DESTDIR)/wireguard/
|
|
|
|
install $(WG_TARGET) $(DESTDIR)/wireguard/
|
|
|
|
install $(WG_QUICK_TARGET) $(DESTDIR)/wireguard/
|
|
|
|
install $(WG_MODULE_TARGET) $(DESTDIR)/wireguard/
|
2021-02-07 01:51:59 +07:00
|
|
|
install $(ROOT_DIR)/wireguard/wg-autostart $(DESTDIR)/wireguard/
|
2019-03-17 22:02:37 +07:00
|
|
|
|
|
|
|
clean:
|
2019-12-29 04:37:29 +07:00
|
|
|
rm -rf $(LIBMNL_TAR) $(LIBMNL_DIR) $(WIREGUARD_TAR) $(WIREGUARD_DIR) $(WIREGUARD_TOOLS_TAR) $(WIREGUARD_TOOLS_DIR)
|