Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt the wsl-vpnkit, so it makes use of WSL_INTEROP variable #250

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions wsl-vpnkit
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ fi
WSL2_RESOLVCONF=${WSL2_RESOLVCONF:-$WSL2_RESOLVCONF_DEFAULT}
WSL2_GATEWAY_IP_FROM_RESOLVCONF="$(cat $WSL2_RESOLVCONF | awk '/^nameserver/ {print $2}')"
WSL2_GATEWAY_IP=${WSL2_GATEWAY_IP:-$WSL2_GATEWAY_IP_FROM_RESOLVCONF}
export WSL_INTEROP=${WSL_INTEROP:-"/run/WSL/$(ls /run/WSL | sort -n | tail -n 1)"}

set -x

# show values
WSL2_TAP_NAME=$WSL2_TAP_NAME
WSL2_GATEWAY_IP=$WSL2_GATEWAY_IP
WSL_INTEROP=$WSL_INTEROP

if [ "$DEBUG" -eq 0 ]; then
set +x
Expand Down Expand Up @@ -120,6 +122,33 @@ check () {
check_https "https://$CHECK_HOST"
}

start () {
# run cleanup to restore any leftover configuration changes
cleanup
wsl2tap_down
run
iptables_set A
check
}

monitor () {
while true
do
if ss -elx | grep -q $WSL_INTEROP &&
[ $WSL_INTEROP = "/run/WSL/$(ls /run/WSL | sort -n | tail -n 1)" ]; then
: #everything is going well, socket still valid, no action to do
else
echo "Something is going bad, socket $WSL_INTEROP broken, trying to repair..."
echo "killing all subprcesses from this wsl-vpnkit-script"
pstree -p $$ | grep -Eow "[0-9]+" | tail -n +2 | xargs kill
echo "setting new Interop-variable"
export WSL_INTEROP="/run/WSL/$(ls /run/WSL | sort -n | tail -n 1)"
start
fi
sleep 1
done
}

cleanup () {
iptables_set D 2>/dev/null
wsl2tap_up
Expand Down Expand Up @@ -158,11 +187,5 @@ fi
trap close exit
trap exit int term

# run cleanup to restore any leftover configuration changes
cleanup

wsl2tap_down
run
iptables_set A
check
wait
start
monitor
3 changes: 2 additions & 1 deletion wsl-vpnkit.service
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[Unit]
Description=wsl-vpnkit
After=network.target

[Service]
# Run as one of last services to start up
Type=idle
# for wsl-vpnkit setup as a distro
ExecStart=/mnt/c/Windows/system32/wsl.exe -d wsl-vpnkit --cd /app wsl-vpnkit

Expand Down