-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
proposal: net: an easy way to make Dialer.Dial("tcp", "DNS reg-name") prefer IPv4 to IPv6 or vice versa #14760
Comments
/cc @mikioh for thoughts |
I suppose that the existing Dialer is designed for handling a single pair of DNS reg-name and address literal or address literals. For handling multiple address families, endpoints and subflows, I'd prefer a new API rather than modifying the existing Dialer, the same as #9334. |
I don't think we want to add more dialing API when we already have Dialer. Dialer seems like the natural place to extend, and was made exactly to provide a place to extend. |
Fair enough. Can you please elaborate on your problem?
In general, the additional fields would look like the following:
Most hard part would be to write test cases and to prepare test environment. |
@mikioh sure. I set my LocalAddr to a IPv4 Address assigned to one local interface
I configure the client to use it:
... and decide also to accept connections to ipv6 hosts ("tcp" instead of "tcp4")
I connect to a IPv6 only host:
... which succeeds ("fallback" to ipv6) but uses an IP address I could not choose, since I could only specify one LocalAddr for one IP family. I do not know in advance whether a host is ipv6 only and I want to prefer v4 if it's supported. I do not want to use any ipv6 address to connect. To your Question "Does the list of addresses need to support multiple address families?":
|
I think you misunderstand what Dialer.DualStack is. It just enables "Happy Eyeballs" dialing defined in RFC 6555. Even if DualStack is false, Dialer.Dial tries to connect a list of destination addresses when network is "tcp". I'm still not sure what you want to do, but it looks like you simply want to prefer IPv4 to IPv6. If so, you can write your favorite dial function like the following:
|
I suppose that what @bong0 wants is just to make Dialer.Dial("tcp", "DNS reg-name") prefer IPv4 to IPv6 or vice versa without writing own connection setup logic. I'm not sure whether adding LocalAddrs and LocalInterfaces to Dialer is sufficient to achieve that purpose. |
@mikioh sorry for the delay. I looked at your proposal and it sort of solves what I want to do in the end (just not such a low level). |
If #16672 were implemented, could you just do it yourself? |
Now that we have a |
Add two bools, |
Does Resolver.PreferIPv4 give preference to A-record or preference to IPv4 DNS transport, or both? |
Go 1.8 will introduce a net.Resolver type that lets you do a name resolution with a timeout (or if you don't care about a timeout, Go 1.7 already had that), so you could do the conversion from host name to IP addresses with (*Resolver).LookupHost and then prioritize the results however you like, including by starting some v4 attempts and then timing out or kicking off new v6 attempts after a certain time. It doesn't seem like Dialer or anything else in package net needs to change to support this. Please reopen if this doesn't solve your use case. Thanks. |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.5.3 linux/amd64
go env
)?I tried to provide a IPv4 and IPv6 address for
LocalAddr
of anet.Dialer
but the model doesn't allow it for now.LocalAddr should be either
The text was updated successfully, but these errors were encountered: