diff --git a/builder/xenserver/common/ssh.go b/builder/xenserver/common/ssh.go index 8500a58..77e03e6 100644 --- a/builder/xenserver/common/ssh.go +++ b/builder/xenserver/common/ssh.go @@ -142,7 +142,7 @@ func forward(local_conn net.Conn, config *gossh.ClientConfig, server, remote_des return nil } -func ssh_port_forward(local_port uint, remote_port uint, remote_dest, host, username, password string) error { +func ssh_port_forward(local_listener net.Listener, remote_port uint, remote_dest, host, username, password string) error { config := &gossh.ClientConfig{ User: username, @@ -151,16 +151,6 @@ func ssh_port_forward(local_port uint, remote_port uint, remote_dest, host, user }, } - // Listen on a local port - local_listener, err := net.Listen("tcp", - fmt.Sprintf("%s:%d", - "127.0.0.1", - local_port)) - if err != nil { - log.Printf("Local listen failed: %s", err) - return err - } - for { local_connection, err := local_listener.Accept() diff --git a/builder/xenserver/common/step_forward_port_over_ssh.go b/builder/xenserver/common/step_forward_port_over_ssh.go index da3078c..3931e0b 100644 --- a/builder/xenserver/common/step_forward_port_over_ssh.go +++ b/builder/xenserver/common/step_forward_port_over_ssh.go @@ -30,14 +30,12 @@ func (self *StepForwardPortOverSSH) Run(state multistep.StateBag) multistep.Step return multistep.ActionHalt } - l.Close() - ui.Say(fmt.Sprintf("Creating a local port forward over SSH on local port %d", sshHostPort)) remotePort, _ := self.RemotePort(state) remoteDest, _ := self.RemoteDest(state) - go ssh_port_forward(sshHostPort, remotePort, remoteDest, config.HostIp, config.Username, config.Password) + go ssh_port_forward(l, remotePort, remoteDest, config.HostIp, config.Username, config.Password) ui.Say(fmt.Sprintf("Port forward setup. %d ---> %s:%d on %s", sshHostPort, remoteDest, remotePort, config.HostIp)) // Provide the local port to future steps.