Skip to content

feat: try IPv6 when dialing IPv4 loopback #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions wgengine/netstack/netstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -1000,8 +1000,24 @@ func (ns *Impl) forwardTCP(getClient func(...tcpip.SettableSocketOption) *gonet.
var stdDialer net.Dialer
server, err := stdDialer.DialContext(ctx, "tcp", dialAddrStr)
if err != nil {
ns.logf("netstack: could not connect to local server at %s: %v", dialAddr.String(), err)
return
// 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 {
if debugNetstack() {
ns.logf("[coder] netstack: successful IPv4 loopback => IPv6 loopback redirect: original = %s, new = %s", dialAddrStr, ipv6DialAddr.String())
}
dialAddr = ipv6DialAddr
dialAddrStr = ipv6DialAddr.String()
} else {
ns.logf("netstack: could not connect to local server at %s (or %s)", dialAddrStr, ipv6DialAddr.String(), err)
return
}
} else {
ns.logf("netstack: could not connect to local server at %s: %v", dialAddr.String(), err)
return
}
}
defer server.Close()

Expand Down
Loading