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

wsl: usernet: Don't always bind to port 2222 #24070

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are using the machine SSH port there I'm afraid there will be a conflict between gvproxy and win-sshproxy

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