Skip to content
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

net: add Resolver.Dial hook to allow specifying source address, etc #17404

Closed
Tevic opened this issue Oct 11, 2016 · 12 comments

Comments

Projects
None yet
7 participants
@Tevic
Copy link
Contributor

commented Oct 11, 2016

If use custome LocalAddr in Dialer, the localaddr changed,but the remoteaddr according to dns resolve is not changed.
For example: two different ip IpA and IpB belongs to different isp in my computer. DomainC is what i want to send request to. So i use custome Dialer to choose which ip i want to use as my localaddr. Linux dig tool can resolve different ip use -b option sets the source IP address to IpA or IpB of the query. But in golang the ip resolved is the same. I use httptrace to find localaddr changed but remote ip is the same.

@quentinmit

This comment has been minimized.

Copy link
Contributor

commented Oct 12, 2016

I'm afraid this is not how any resolver library actually works. dig is very special in that it is a debugging tool that sends DNS requests itself.

You'll need to explicitly send DNS requests yourself if you want to have this behavior. Perhaps using a library like https://godoc.org/github.com/miekg/dns

@quentinmit quentinmit closed this Oct 12, 2016

@Tevic

This comment has been minimized.

Copy link
Contributor Author

commented Oct 12, 2016

This is a reasonable request,i use ip of ispA, why the resolver resolve ip belongs to ispB ?

@mikioh mikioh changed the title net/dial:Dialer should use specific LocalAddr to do dns resolve net: Dialer should use specific LocalAddr to do dns resolve Oct 12, 2016

@SunRunAway

This comment has been minimized.

Copy link

commented Oct 12, 2016

        // LocalAddr is the local address to use when dialing an
        // address. The address must be of a compatible type for the
        // network being dialed.
        // If nil, a local address is automatically chosen.
        LocalAddr Addr

Perharps it should do every net request using LocalAddr, including dns query.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Oct 12, 2016

This seems like a reasonable request. Or something in the new Resolver type.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Oct 12, 2016

/cc @mikioh

@mikioh

This comment has been minimized.

Copy link
Contributor

commented Oct 18, 2016

I think it's reasonable to support this feature because unlike conventional DNS APIs we can provide both DNS RR exchange control and DNS transport control through the combination of Dialer and Resolver structs. If there is a reason to hesitate to do this it must be overkill, but nowadays we see the complicated circumstances; multiple IP links/interfaces, two IP address spaces. Probably just following the existing APIs/behaviors wouldn't be much help for the circumstances.

@nerdatmath

This comment has been minimized.

Copy link
Contributor

commented Feb 20, 2017

I'm working on this - specifically I'm working on a way to configure the Dialer that a Resolver will use for to make its connections. Note that this can only work when the go (not cgo) resolver is used, and that's not available on some platforms.

@gopherbot

This comment has been minimized.

Copy link

commented Feb 20, 2017

CL https://golang.org/cl/37260 mentions this issue.

@bradfitz bradfitz modified the milestones: Go1.9Maybe, Unplanned Feb 24, 2017

@nerdatmath

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2017

@Tevic, can you clarify your situation? What platform are you on, and what does your DNS configuration look like (/etc/resolv.conf)? When you look up domainC on ispA (using dig), do you get an IP address back? What about on ispB? If both lookups succeed, do you get the same or different IP addresses?

@Tevic

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2017

A domain set two A Records : ispA->ipA, ispB->ipB
A Server with 2 IPs: ip1(belongs ispA), ip2(belongs ispB). Default route is ip1.
Golang Behavior: Set LocalAddr: ip1,RemoteAddr get ipA. Set LocalAddr: ip2,RemoteAddr still get ipA.
Expected Behavior: Set LocalAddr: ip1,RemoteAddr get ipA. Set LocalAddr: ip2,RemoteAddr still get ipB.
Using dig's -b option get the expected behavior.

@nerdatmath

This comment has been minimized.

Copy link
Contributor

commented Mar 12, 2017

@Tevic, please understand that what you are asking for is very unusual behavior. DNS is not designed to work the way you are requesting. We are working on a way to allow you to get that behavior, but I don't think we can make it the default. You would need to create a Dialer, set a custom Resolver in that Dialer, and use that Dialer to make your connection. As long as you own the code doing the dialing, that should work out OK.

@Tevic

This comment has been minimized.

Copy link
Contributor Author

commented Mar 12, 2017

Yes,you're right. Thanks for your working on custom resolver. Previous golang has no resolver option.

@bradfitz bradfitz changed the title net: Dialer should use specific LocalAddr to do dns resolve net: add Resolver.Dial hook to allow specifying source address, etc May 12, 2017

@gopherbot gopherbot closed this in 380aa88 May 12, 2017

@golang golang locked and limited conversation to collaborators May 12, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.