From ffcc6608b35490b8e554081d62c37952daf34571 Mon Sep 17 00:00:00 2001 From: Gunjan Vyas Date: Fri, 4 Oct 2024 17:45:31 +0530 Subject: [PATCH] Disable ssh port forwarding when value of -ssh-port is -1 Signed-off-by: Gunjan Vyas --- cmd/gvproxy/main.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/gvproxy/main.go b/cmd/gvproxy/main.go index 13e92c292..09d7931d6 100644 --- a/cmd/gvproxy/main.go +++ b/cmd/gvproxy/main.go @@ -167,7 +167,7 @@ func main() { // If the given port is not between the privileged ports // and the oft considered maximum port, return an error. - if sshPort < 1024 || sshPort > 65535 { + if sshPort != -1 && sshPort < 1024 || sshPort > 65535 { exitWithError(errors.New("ssh-port value must be between 1024 and 65535")) } protocol := types.HyperKitProtocol @@ -250,9 +250,7 @@ func main() { }, }, DNSSearchDomains: searchDomains(), - Forwards: map[string]string{ - fmt.Sprintf("127.0.0.1:%d", sshPort): sshHostPort, - }, + Forwards: getForwardsMap(sshPort, sshHostPort), NAT: map[string]string{ hostIP: "127.0.0.1", }, @@ -285,6 +283,15 @@ func main() { } } +func getForwardsMap(sshPort int, sshHostPort string) map[string]string { + if sshPort == -1 { + return map[string]string{} + } + return map[string]string{ + fmt.Sprintf("127.0.0.1:%d", sshPort): sshHostPort, + } +} + type arrayFlags []string func (i *arrayFlags) String() string {