Skip to content

Commit

Permalink
feat: try IPv6 when dialing IPv4 loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
deansheather committed Apr 30, 2024
1 parent f586aa4 commit db9caca
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wgengine/netstack/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,22 @@ func (ns *Impl) forwardTCP(getClient func(...tcpip.SettableSocketOption) *gonet.
var stdDialer net.Dialer
server, err := stdDialer.DialContext(ctx, "tcp", dialAddrStr)
if err != nil {
// Coder: Retry with loopback IPv6 if the dial was for 127.0.0.1.
if dialAddr.Addr().Is4() && dialAddr.Addr().String() == "127.0.0.1" {
ipv6DialAddr := netip.AddrPortFrom(netip.IPv6Loopback(), dialAddr.Port())
server, err = stdDialer.DialContext(ctx, "tcp", ipv6DialAddr.String())
if err == nil {
dialAddr = ipv6DialAddr
dialAddrStr = ipv6DialAddr.String()
if debugNetstack() {
ns.logf("[coder] netstack: successful IPv4 loopback => IPv6 loopback hit: original = %s, new = %s", dialAddrStr, ipv6DialAddr.String())
}
} else {
ns.logf("netstack: could not connect to local server at %s (or %s)", dialAddrStr, ipv6DialAddr.String(), err)
return
}
}

ns.logf("netstack: could not connect to local server at %s: %v", dialAddr.String(), err)
return
}
Expand Down

0 comments on commit db9caca

Please sign in to comment.