cloudflare / boringtun

Userspace WireGuard® Implementation in Rust
BSD 3-Clause "New" or "Revised" License
6.12k stars 415 forks source link

WG_QUICK_USERSPACE_IMPLEMENTATION=boringtun doesn't appear to do anything #238

Open greg-hydrogen opened 2 years ago

greg-hydrogen commented 2 years ago

Hello Everyone,

I was looking to test boringtun and I followed the instructions provided in the README

when running the following: WG_QUICK_USERSPACE_IMPLEMENTATION=boringtun WG_SUDO=1 wg-quick up wg0

It doesn't appear to do anything, I don't see any process for boringtun started

How does the WG_QUICK_USERSPACE_IMPLEMENTATION variable understand that boringtun exists, is there a specific folder it needs to be placed?

Any logs that I can be provided?

Thanks, Greg

Noah-Kennedy commented 2 years ago

You should use the path to the installed boringtun binary for that variable.

greg-hydrogen commented 2 years ago

@Noah-Kennedy - changing the variable to the location of the binary hasn't changed the behavior WG_QUICK_USERSPACE_IMPLEMENTATION=/usr/bin/boringtun WG_SUDO=1 wg-quick up wg0

Anything else I can check?

Noah-Kennedy commented 2 years ago

@greg-hydrogen I am not familiar with this environment variable. Can you point me towards documentation on it?

greg-hydrogen commented 2 years ago

@Noah-Kennedy - I just got this information from the main page https://github.com/cloudflare/boringtun under the "Runniing" section of the README

Noah-Kennedy commented 2 years ago

:facepalm: how did I forget that lol!

Did you install from the master branch or did you do cargo install boringtun?

greg-hydrogen commented 2 years ago

I built it from git master using cargo build --bin boringtun-cli --release

and then copying the binary to /usr/bin/

OothecaPickle commented 2 years ago

you have to use sudo WG_QUICK_USERSPACE_IMPLEMENTATION=/usr/bin/boringtun WG_SUDO=1 wg-quick up wg0

wg-quick runs as root anyway, but executes sudo without inheriting environment variables. running WG_QUICK_USERSPACE_IMPLEMENTATION=/usr/bin/boringtun WG_SUDO=1 wg-quick up wg0 and passing -E to sudo in that line also works

greg-hydrogen commented 2 years ago

running with sudo, and sudo -E doesn't change the behaviour, I also modified the wg-quick script on the line you identified and added -E after sudo and that didn't change anything as well

I must be doing something wrong, but I don't see it, is there anything else I should try?

paletteOvO commented 2 years ago

I also faced the same problem, so I checked the source code of wg-quick and found that line would unconditionally use the kernel module if it existed. Modify it to something like this will work

add_if() {
    local ret
    if [ ! -z "${WG_QUICK_USERSPACE_IMPLEMENTATION}" ]; then
        echo "[!] Found WG_QUICK_USERSPACE_IMPLEMENTATION. Use userspace implementation instead." >&2
        cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
    elif ! 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
        echo "[!] Missing WireGuard kernel module. Falling back to slow userspace implementation." >&2
        cmd "${WG_QUICK_USERSPACE_IMPLEMENTATION:-wireguard-go}" "$INTERFACE"
    fi
}
wangzheng00 commented 2 years ago

@greg-hydrogen any update? I have the same problem, I use version: boringtun-0.5.2, then run: sudo WG_QUICK_USERSPACE_IMPLEMENTATION=boringtun-cli WG_SUDO=1 wg-quick up ./w02.conf