Skip to content

Commit 20a3664

Browse files
committed
better checks and tests
1 parent 04f9946 commit 20a3664

7 files changed

Lines changed: 455 additions & 148 deletions

File tree

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ The `wsl-vpnkit` script can be installed and run in your existing distro. The fo
4747

4848
```sh
4949
# install dependencies
50-
sudo apt-get install iproute2 iptables iputils-ping dnsutils wget jq yq
50+
sudo apt-get install iproute2 iptables iputils-ping dnsutils curl jq yq
5151

5252
# download wsl-vpnkit and unpack
53-
wget https://github.com/sakai135/wsl-vpnkit/releases/latest/download/wsl-vpnkit-amd64.wsl -O wsl-vpnkit.wsl
53+
curl -L https://github.com/sakai135/wsl-vpnkit/releases/latest/download/wsl-vpnkit-amd64.wsl -o wsl-vpnkit.wsl
5454
tar --strip-components=1 -xf wsl-vpnkit.wsl app/wsl-vpnkit app/wsl-vpnkit.yaml app/wsl-gvproxy.exe app/wsl-vm app/wsl-vpnkit.service
5555
rm wsl-vpnkit.wsl
5656
sudo mv wsl-vpnkit wsl-gvproxy.exe wsl-vm /usr/local/bin/
@@ -74,8 +74,7 @@ The `wsl-vpnkit` script supports the following environment variables. For the fu
7474
| Variable (default value) | Description |
7575
| --- | --- |
7676
| `DEBUG` (`0`) | Enables debug output when set to `1`. |
77-
| `CHECK_HOST` (`example.com`) | Host used for the DNS and HTTP(S) diagnostic checks. Use a host that is reachable and serves HTTP(S). |
78-
| `CHECK_DNS` (`1.1.1.1`) | DNS server used for the external DNS diagnostic checks. Set this to a DNS server reachable on your network. |
77+
| `CHECK_HOST` (`host.containers.internal`) | Host name used by startup DNS diagnostics. |
7978
| `GVPROXY_PATH` (`wsl-gvproxy.exe` from `PATH`) | Path to the `wsl-gvproxy.exe` executable. |
8079
| `VMEXEC_PATH` (`wsl-vm` from `PATH`) | Path to the `wsl-vm` executable. |
8180
| `WSL2_GATEWAY_IP` (detected from the default route or resolver configuration) | WSL 2 gateway IP address. |
@@ -163,7 +162,6 @@ wsl.exe -d wsl-vpnkit --cd /app DEBUG=1 wsl-vpnkit
163162
* For corporate DNS servers or suffixes, see [WSL network settings](https://learn.microsoft.com/en-us/windows/wsl/wsl-config#network-settings).
164163
* For HTTP(S) proxies, see WSL's [`autoProxy` setting](https://learn.microsoft.com/en-us/windows/wsl/troubleshooting#considerations-when-using-autoproxy-for-httpproxy-mirroring-in-wsl). You may need to configure the proxies manually.
165164
* For HTTPS certificate failures, [install your organization's root CA in your distro](https://documentation.ubuntu.com/server/how-to/security/install-a-root-ca-certificate-in-the-trust-store/).
166-
* On start, `wsl-vpnkit` will do simple checks using `example.com` and `1.1.1.1` by default. While these checks do not block any functionality, you can set `CHECK_HOST` and `CHECK_DNS` to use values that are more relevant to you.
167165
* Ports on the WSL 2 VM are [accessible from the Windows host using `localhost`](https://learn.microsoft.com/en-us/windows/wsl/networking#accessing-linux-networking-apps-from-windows-localhost).
168166
* Ports on the Windows host are accessible from WSL 2 using `host.containers.internal`, `192.168.127.254` or [the IP address of the host machine](https://docs.microsoft.com/en-us/windows/wsl/networking#accessing-windows-networking-apps-from-linux-host-ip).
169167
* [ICMP is not forwarded outside the network](https://github.com/containers/gvisor-tap-vsock/#limitations)

distro/fedora.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FROM docker.io/library/fedora:44
2222
ARG TARGETARCH
2323
RUN dnf update -y && \
2424
dnf upgrade -y && \
25-
dnf install -y iproute iptables-legacy iputils bind-utils wget jq yq && \
25+
dnf install -y iproute iptables-legacy iputils bind-utils jq yq && \
2626
dnf clean all
2727
WORKDIR /app
2828
COPY --from=gvisor-tap-vsock /app/bin/${TARGETARCH}/gvforwarder ./wsl-vm

distro/ubuntu.dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ FROM docker.io/library/ubuntu:26.04
2222
ARG TARGETARCH
2323
RUN apt-get update && \
2424
apt-get upgrade -y && \
25-
apt-get install -y iproute2 iptables iputils-ping dnsutils wget jq yq && \
25+
apt-get install -y iproute2 iptables iputils-ping dnsutils jq yq && \
2626
apt-get clean
2727
WORKDIR /app
2828
COPY --from=gvisor-tap-vsock /app/bin/${TARGETARCH}/gvforwarder ./wsl-vm

tests/docker/mock-vm

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,29 @@ log_dir=${MOCK_LOG_DIR:-/run/wsl-vpnkit-test}
44
printf '%s\n' "$*" >> "$log_dir/vm.log"
55

66
preexisting=0
7-
dhcp=0
7+
tap_name=wsltap
8+
tap_mac=
89
for arg do
910
[ "$arg" = "-preexisting=1" ] && preexisting=1
10-
case "$arg" in -mac=*) dhcp=1 ;; esac
11+
case "$arg" in
12+
-iface=*) tap_name=${arg#-iface=} ;;
13+
-mac=*) tap_mac=${arg#-mac=} ;;
14+
esac
1115
done
1216
if [ "$preexisting" -eq 0 ]; then
13-
ip tuntap add wsltap mode tap
14-
ip link set dev wsltap up
15-
if [ "$dhcp" -eq 0 ] || [ "${MOCK_DHCP_MODE:-success}" = success ]; then
16-
ip addr add 192.168.127.2/24 dev wsltap
17-
ip route add default via 192.168.127.1 dev wsltap
18-
elif [ "${MOCK_DHCP_MODE:-}" = wrong ]; then
19-
ip addr add 192.168.127.99/24 dev wsltap
20-
ip route add default via 192.168.127.1 dev wsltap
17+
ip tuntap add "$tap_name" mode tap
18+
[ -n "$tap_mac" ] && ip link set dev "$tap_name" address "$tap_mac"
19+
ip link set dev "$tap_name" up
20+
if [ -n "${MOCK_DHCP_IP:-}" ]; then
21+
ip addr add "${MOCK_DHCP_IP}/${MOCK_DHCP_MASK:-24}" dev "$tap_name"
22+
ip route add default via "$MOCK_DHCP_GATEWAY" dev "$tap_name"
2123
fi
22-
trap 'ip route del default via 192.168.127.1 dev wsltap 2>/dev/null || :; ip tuntap del wsltap mode tap 2>/dev/null || :; exit 0' INT TERM
24+
trap 'ip tuntap del "$tap_name" mode tap 2>/dev/null || :; exit 0' INT TERM
2325
fi
2426

2527
if [ "${MOCK_VM_MODE:-run}" = "exit" ]; then
2628
[ "$preexisting" -eq 0 ] && {
27-
ip route del default via 192.168.127.1 dev wsltap 2>/dev/null || :
28-
ip tuntap del wsltap mode tap 2>/dev/null || :
29+
ip tuntap del "$tap_name" mode tap 2>/dev/null || :
2930
}
3031
exit 1
3132
fi

0 commit comments

Comments
 (0)