From af1270b7d85d11c7009f8abb64979de24d15d81a Mon Sep 17 00:00:00 2001 From: Christophe Fergeau Date: Wed, 25 Sep 2024 14:06:35 +0200 Subject: [PATCH] wsl: usernet: Don't always bind to port 2222 podman-machine starts gvproxy without specifying -ssh-port. This means it will always bind port 2222 (see https://github.com/containers/gvisor-tap-vsock/issues/402), effectively bypassing the dynamic ssh port allocation. I don't think wsl needs this port to be opened/bound on the host, but this commit starts gvproxy with -ssh-port set to the dynamic SSH port to avoid port conflicts with crc. When gvproxy allows to disable this port forwarding entirely, we can revise this. This should fix #20327 Signed-off-by: Christophe Fergeau --- pkg/machine/wsl/usermodenet.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/machine/wsl/usermodenet.go b/pkg/machine/wsl/usermodenet.go index 0f09874e0f..d3b6c24403 100644 --- a/pkg/machine/wsl/usermodenet.go +++ b/pkg/machine/wsl/usermodenet.go @@ -32,7 +32,7 @@ fi if [[ ! $ROUTE =~ default\ via ]]; then exit 3 fi -nohup $GVFORWARDER -iface podman-usermode -stop-if-exist ignore -url "stdio:$GVPROXY?listen-stdio=accept" > /var/log/vm.log 2> /var/log/vm.err < /dev/null & +nohup $GVFORWARDER -iface podman-usermode -stop-if-exist ignore -url "stdio:$GVPROXY?listen-stdio=accept&ssh-port=$GVSSHPORT" > /var/log/vm.log 2> /var/log/vm.err < /dev/null & echo $! > $STATE/vm.pid sleep 1 ps -eo args | grep -q -m1 ^$GVFORWARDER || exit 42 @@ -99,7 +99,7 @@ func startUserModeNetworking(mc *vmconfigs.MachineConfig) error { // Start or reuse if !running { - if err := launchUserModeNetDist(exe); err != nil { + if err := launchUserModeNetDist(exe, mc.SSH.Port); err != nil { return err } } @@ -168,7 +168,7 @@ func isGvProxyVMRunning() bool { return wslInvoke(userModeDist, "bash", "-c", cmd) == nil } -func launchUserModeNetDist(exeFile string) error { +func launchUserModeNetDist(exeFile string, sshPort int) error { fmt.Println("Starting user-mode networking...") exe, err := specgen.ConvertWinMountPath(exeFile) @@ -176,7 +176,7 @@ func launchUserModeNetDist(exeFile string) error { return err } - cmdStr := fmt.Sprintf("GVPROXY=%q\nGVFORWARDER=%q\n%s", exe, gvForwarderPath, startUserModeNet) + cmdStr := fmt.Sprintf("GVPROXY=%q\nGVFORWARDER=%q\nGVSSHPORT=%d\n%s", exe, gvForwarderPath, sshPort, startUserModeNet) if err := wslPipe(cmdStr, userModeDist, "bash"); err != nil { _ = terminateDist(userModeDist)