wg-quick: Add flag `WG_QUICK_PREFER_USERSPACE_IMPLEMENTATION`

Nicolai S wg at xn--sb-lka.org
Fri Jan 9 14:41:33 UTC 2026


While developing a userspace implementation of wireguard, or if users have
special requirements for which implementation of wg to use, etc, it would be
nice to be able to force `wg-quick` to use `WG_QUICK_USERSPACE_IMPLEMENTATION`.

But currently, if your kernel supports wireguard, then `wg-quick` will ignore
the `WG_QUICK_USERSPACE_IMPLEMENTATION` environment variable (on linux).

This patch introduces `WG_QUICK_PREFER_USERSPACE_IMPLEMENTATION` to get `wg-quick`
to use the userspace implementation.

Note that `darwin.bash` already prefers `WG_QUICK_USERSPACE_IMPLEMENTATION` if set.

If we instead want the darwin behavior in `linux.bash` then I suggest merging
this patch: https://lists.zx2c4.com/pipermail/wireguard/2025-March/008773.html

Signed-off-by: Nicolai Søborg <wg @ xn--sb-lka.org>
---
 src/wg-quick/linux.bash   | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletions(-)

diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash
index 34fa5f9..be867d5 100755
--- a/src/wg-quick/linux.bash
+++ b/src/wg-quick/linux.bash
@@ -88,7 +88,10 @@ auto_su() {
 
 add_if() {
 	local ret
-	if ! cmd ip link add dev "$INTERFACE" type wireguard; then
+	if [[ -n "$WG_QUICK_PREFER_USERSPACE_IMPLEMENTATION" ]]; then
+		echo "[!] Forcing userspace implementation." >&2
+		cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
+	elif ! cmd ip link add dev "$INTERFACE" type wireguard; then
 		ret=$?
 		[[ -e /sys/module/wireguard ]] || ! command -v "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" >/dev/null && exit $ret
 		echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2


More information about the WireGuard mailing list