From 837235f51f92f6dfb8b46822de38cd060ce9e06a Mon Sep 17 00:00:00 2001 From: Mark Puha Date: Thu, 28 Sep 2023 13:37:52 +0200 Subject: [PATCH] wg-quick for linux and openbsd --- src/wg-quick/freebsd.bash | 19 ++++++++++++++++++- src/wg-quick/linux.bash | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/wg-quick/freebsd.bash b/src/wg-quick/freebsd.bash index f72daf6..d02c910 100755 --- a/src/wg-quick/freebsd.bash +++ b/src/wg-quick/freebsd.bash @@ -28,6 +28,8 @@ CONFIG_FILE="" PROGRAM="${0##*/}" ARGS=( "$@" ) +IS_ASESCURITY_ON=0 + cmd() { echo "[#] $*" >&3 "$@" @@ -96,6 +98,17 @@ parse_options() { PostDown) POST_DOWN+=( "$value" ); continue ;; SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;; esac + case "$key" in + Jc);& + Jmin);& + Jmax);& + S1);& + S2);& + H1);& + H2);& + H3);& + H4) IS_ASESCURITY_ON=1;; + esac fi WG_CONFIG+="$line"$'\n' done < "$CONFIG_FILE" @@ -116,7 +129,11 @@ auto_su() { add_if() { local ret rc - if ret="$(cmd ifconfig wg create name "$INTERFACE" 2>&1 >/dev/null)"; then + local cmd="ifconfig wg create name "$INTERFACE"" + if [[ $IS_ASESCURITY_ON == 1 ]]; then + cmd="wireguard-go "$INTERFACE""; + fi + if ret="$(cmd $cmd 2>&1 >/dev/null)"; then return 0 fi rc=$? diff --git a/src/wg-quick/linux.bash b/src/wg-quick/linux.bash index 4193ce5..1a4b731 100755 --- a/src/wg-quick/linux.bash +++ b/src/wg-quick/linux.bash @@ -26,6 +26,7 @@ SAVE_CONFIG=0 CONFIG_FILE="" PROGRAM="${0##*/}" ARGS=( "$@" ) +IS_ASESCURITY_ON=0 cmd() { echo "[#] $*" >&2 @@ -37,6 +38,7 @@ die() { exit 1 } + parse_options() { local interface_section=0 line key value stripped v CONFIG_FILE="$1" @@ -67,6 +69,17 @@ parse_options() { PostDown) POST_DOWN+=( "$value" ); continue ;; SaveConfig) read_bool SAVE_CONFIG "$value"; continue ;; esac + case "$key" in + Jc);& + Jmin);& + Jmax);& + S1);& + S2);& + H1);& + H2);& + H3);& + H4) IS_ASESCURITY_ON=1;; + esac fi WG_CONFIG+="$line"$'\n' done < "$CONFIG_FILE" @@ -87,7 +100,11 @@ auto_su() { add_if() { local ret - if ! cmd ip link add "$INTERFACE" type wireguard; then + local cmd="ip link add "$INTERFACE" type wireguard" + if [[ $IS_ASESCURITY_ON == 1 ]]; then + cmd="wireguard-go "$INTERFACE""; + fi + if ! cmd $cmd; 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