@@ -171,7 +171,7 @@ func New(instName string, stdout io.Writer, sigintCh chan os.Signal, opts ...Opt
171
171
instName : instName ,
172
172
instSSHAddress : inst .SSHAddress ,
173
173
sshConfig : sshConfig ,
174
- portForwarder : newPortForwarder (sshConfig , sshLocalPort , rules , inst .VMType ),
174
+ portForwarder : newPortForwarder (sshConfig , inst . SSHAddress , sshLocalPort , rules , inst .VMType ),
175
175
driver : limaDriver ,
176
176
sigintCh : sigintCh ,
177
177
eventEnc : json .NewEncoder (stdout ),
@@ -559,7 +559,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
559
559
for _ , rule := range a .y .PortForwards {
560
560
if rule .GuestSocket != "" {
561
561
local := hostAddress (rule , guestagentapi.IPPort {})
562
- _ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
562
+ _ = forwardSSH (ctx , a .sshConfig , a .instSSHAddress , a . sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
563
563
}
564
564
}
565
565
}
@@ -571,7 +571,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
571
571
if rule .GuestSocket != "" {
572
572
local := hostAddress (rule , guestagentapi.IPPort {})
573
573
// using ctx.Background() because ctx has already been cancelled
574
- if err := forwardSSH (context .Background (), a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbCancel , rule .Reverse ); err != nil {
574
+ if err := forwardSSH (context .Background (), a .sshConfig , a .instSSHAddress , a . sshLocalPort , local , rule .GuestSocket , verbCancel , rule .Reverse ); err != nil {
575
575
errs = append (errs , err )
576
576
}
577
577
}
@@ -653,11 +653,11 @@ const (
653
653
verbCancel = "cancel"
654
654
)
655
655
656
- func executeSSH (ctx context.Context , sshConfig * ssh.SSHConfig , port int , command ... string ) error {
656
+ func executeSSH (ctx context.Context , sshConfig * ssh.SSHConfig , addr string , port int , command ... string ) error {
657
657
args := sshConfig .Args ()
658
658
args = append (args ,
659
659
"-p" , strconv .Itoa (port ),
660
- "127.0.0.1" ,
660
+ addr ,
661
661
"--" ,
662
662
)
663
663
args = append (args , command ... )
@@ -668,7 +668,7 @@ func executeSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, command
668
668
return nil
669
669
}
670
670
671
- func forwardSSH (ctx context.Context , sshConfig * ssh.SSHConfig , port int , local , remote string , verb string , reverse bool ) error {
671
+ func forwardSSH (ctx context.Context , sshConfig * ssh.SSHConfig , addr string , port int , local , remote string , verb string , reverse bool ) error {
672
672
args := sshConfig .Args ()
673
673
args = append (args ,
674
674
"-T" ,
@@ -687,15 +687,15 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
687
687
"-N" ,
688
688
"-f" ,
689
689
"-p" , strconv .Itoa (port ),
690
- "127.0.0.1" ,
690
+ addr ,
691
691
"--" ,
692
692
)
693
693
if strings .HasPrefix (local , "/" ) {
694
694
switch verb {
695
695
case verbForward :
696
696
if reverse {
697
697
logrus .Infof ("Forwarding %q (host) to %q (guest)" , local , remote )
698
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
698
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
699
699
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) before setting up forwarding" , remote )
700
700
}
701
701
} else {
@@ -710,7 +710,7 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
710
710
case verbCancel :
711
711
if reverse {
712
712
logrus .Infof ("Stopping forwarding %q (host) to %q (guest)" , local , remote )
713
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
713
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
714
714
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) after stopping forwarding" , remote )
715
715
}
716
716
} else {
@@ -730,7 +730,7 @@ func forwardSSH(ctx context.Context, sshConfig *ssh.SSHConfig, port int, local,
730
730
if verb == verbForward && strings .HasPrefix (local , "/" ) {
731
731
if reverse {
732
732
logrus .WithError (err ).Warnf ("Failed to set up forward from %q (host) to %q (guest)" , local , remote )
733
- if err := executeSSH (ctx , sshConfig , port , "rm" , "-f" , remote ); err != nil {
733
+ if err := executeSSH (ctx , sshConfig , addr , port , "rm" , "-f" , remote ); err != nil {
734
734
logrus .WithError (err ).Warnf ("Failed to clean up %q (guest) after forwarding failed" , remote )
735
735
}
736
736
} else {
0 commit comments