Skip to content

Commit

Permalink
Disable ssh port forwarding when value of -ssh-port is -1
Browse files Browse the repository at this point in the history
Signed-off-by: Gunjan Vyas <[email protected]>
  • Loading branch information
vyasgun committed Oct 4, 2024
1 parent d1683b9 commit f49a19e
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cmd/gvproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
},
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit f49a19e

Please sign in to comment.