Development discussion of WireGuard
 help / color / mirror / Atom feed
* [PATCH] wg-quick: add possibility to force use userspace implementation
@ 2023-03-19 16:43 Dmitry Selivanov
  0 siblings, 0 replies; only message in thread
From: Dmitry Selivanov @ 2023-03-19 16:43 UTC (permalink / raw)
  To: wireguard

This patch allows to use userspace implementation with 
"WG_QUICK_USERSPACE_IMPLEMENTATION" env variable even if kernel
driver is installed. Quotes around program name are removed 
to run like this:
WG_QUICK_USERSPACE_IMPLEMENTATION="setfib 1 wireguard-go" wg-quick up wg0
on FreeBSD or with "ip netns exec" on Linux. This can move
wireguard traffic to non-default routing table or namespace.

Signed-off-by: Dmitry Selivanov <dseliv@gmail.com>
---
 src/wg-quick/freebsd.bash | 6 +++++-
 src/wg-quick/linux.bash   | 8 ++++++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash
index b529ab2..663af48 100755
--- a/src/wg-quick/freebsd.bash
+++ b/src/wg-quick/freebsd.bash
@@ -116,6 +116,10 @@ auto_su() {
 
 add_if() {
 	local ret rc
+	if [[ -n $WG_QUICK_USERSPACE_IMPLEMENTATION ]]; then
+		cmd $WG_QUICK_USERSPACE_IMPLEMENTATION "$INTERFACE"
+		return
+	fi
 	if ret="$(cmd ifconfig wg create name "$INTERFACE" 2>&1 >/dev/null)"; then
 		return 0
 	fi
@@ -125,7 +129,7 @@ add_if() {
 		return $rc
 	fi
 	echo "[!] Missing WireGuard kernel support ($ret). Falling back to slow userspace implementation." >&3
-	cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
+	cmd wireguard-go "$INTERFACE"
 }
 
 del_routes() {
diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index 69e5bef..a883df9 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -87,11 +87,15 @@ auto_su() {
 
 add_if() {
 	local ret
+	if [[ -n $WG_QUICK_USERSPACE_IMPLEMENTATION ]]; then
+		cmd $WG_QUICK_USERSPACE_IMPLEMENTATION "$INTERFACE"
+		return
+	fi
 	if ! cmd ip link add "$INTERFACE" type wireguard; then
 		ret=$?
-		[[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
+		[[ -e /sys/module/wireguard ]] || ! command -v "wireguard-go" >/dev/null && exit $ret
 		echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2
-		cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
+		cmd wireguard-go "$INTERFACE"
 	fi
 }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-03-19 16:45 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-19 16:43 [PATCH] wg-quick: add possibility to force use userspace implementation Dmitry Selivanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).