Development discussion of WireGuard
 help / color / mirror / Atom feed
From: Dmitry Selivanov <dseliv@gmail.com>
To: wireguard@lists.zx2c4.com
Subject: [PATCH] wg-quick: add possibility to force use userspace implementation
Date: Sun, 19 Mar 2023 19:43:57 +0300	[thread overview]
Message-ID: <316d48cc-6abc-ede1-5344-26fb81d19439@gmail.com> (raw)

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


                 reply	other threads:[~2023-03-19 16:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=316d48cc-6abc-ede1-5344-26fb81d19439@gmail.com \
    --to=dseliv@gmail.com \
    --cc=wireguard@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).