Skip to content

Commit

Permalink
wsl: usernet: Don't always bind to port 2222
Browse files Browse the repository at this point in the history
podman-machine starts gvproxy without specifying -ssh-port.
This means it will always bind port 2222 (see
containers/gvisor-tap-vsock#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 containers#20327

Signed-off-by: Christophe Fergeau <cfergeau@redhat.com>
  • Loading branch information
cfergeau committed Sep 25, 2024
1 parent 8cc4781 commit af1270b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions pkg/machine/wsl/usermodenet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -168,15 +168,15 @@ 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)
if err != nil {
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)

Expand Down

0 comments on commit af1270b

Please # to comment.