-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
dns: add setLocalAddress to Resolver #34824
Conversation
Review requested:
|
7c36555
to
26704d0
Compare
Thanks for the reviews. My schedule got a little busy; I'll address them later this week. One thing that has occurred to me: I think I misunderstood the exact behavior of node/deps/cares/src/ares_process.c Lines 1018 to 1037 in 4cfcaae
If you wanted to set both IPv4 and v6 source addresses with the current implementation of this PR, one could do something like resolver.setLocalAddress('127.0.0.1');
resolver.setLocalAddress('::1'); …but that seems a little goofy. Any suggestions for a good API? I'm thinking: resolver.setLocalAddress('127.0.0.1'); // sets IPv4, clears IPv6
resolver.setLocalAddress('::1'); // sets IPv6, clears IPv4
resolver.setLocalAddress('127.0.0.1', '::1'); // sets both
resolver.setLocalAddress(null); // clears both? or just '0.0.0.0' instead of null?
// or should we require both v4 and v6 args to avoid ambiguity when calling with a single arg? |
That's a good point. Borrowing from python, explicit > implicit, so maybe this? resolver.setLocalAddressIPv4('127.0.0.1')
resolver.setLocalAddressIPv6('::1')
resolver.setLocalAddressIPv4('::1') // throws
resolver.setLocalAddressIPv6('127.0.0.1') // ditto |
Should probably add this as
Why would you want to do that? a packet can only have one source address. |
Our handling of the differences between ipv4 and ipv6 are way too consistent across the codebase. Sometimes we use argument/option values like resolver.setLocalAddress('127.0.0.1') // defaults to ipv4
resolver.setLocalAddress('127.0.0.1', 'ipv4')
resolver.setLocalAddress('::1', 'ipv6') |
I've pushed commits addressing the review comments above. On the topic of what exactly the JS API should look like, I'm not in love with the idea of calling the same method multiple times since it is ambiguous to the caller how exactly the internals handle those calls. Does the IPv6 call replace the IPv4 setting or are they managed separately? If a user only sets an IPv4 address, will they be surprised when a v6 request goes over the default interface? This could be solved in the documentation, but I think it's preferable to have an interface works without ambiguity in the first place. That's why I proposed having a call that always sets IP 4 and 6, perhaps making it mandatory to specify both so there are no surprises.
|
There's already hundrets of such possibilities in various Node.js API, having one more probably does not hurt. Users concerned about it can use
If it's not too much work, I would suggest having it available. As for API, how about .setSourceAddress('1.2.3.4')
.setSourceAddress('1.2.3.4:1234')
.setSourceAddress('1.2.3.4', '1:2:3:4::')
.setSourceAddress('1.2.3.4', '[1:2:3:4::]:1234')
.setSourceAddress('1.2.3.4:1234', '[1:2:3:4::]:1234') First argument is IPv4, second IPv6 in I have to disagree with suggested |
c-ares does not provide an API for changing the source port option after initialization, so we can't change it from an instance method — ie, we can't do |
Happy to omit a port option in that case as it's a rather obscure option anyways. |
987294a2264e9cf750ebf226cbd6c2a85c2c57e5 clarifies the API's handling of IPv4 and IPv6 source addresses. The signature is now
Regarding making this available on the default resolver (ie After some investigation, it looks like doing so is not trivial. This is because ares does not provide a way to get the current local IP configuration, so we'd have to maintain additional state regarding the local address and then make sure it is re-applied whenever the global It's doable, but I'd personally prefer to avoid the extra complexity. |
I think everything outstanding has been resolved (unless anyone still thinks the API needs some work). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with 2 comments (we always use error codes for new errors)
src/cares_wrap.cc
Outdated
ares_set_local_ip6(channel->cares_channel(), addr0); | ||
type0 = 6; | ||
} else { | ||
return env->ThrowError("Invalid IP address."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to do the input validation in JS?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be redundant since we need to parse the strings in C land anyway and call ares_set_local_ip4
/ares_set_local_ip6
as appropriate.
0c8b43f
to
4b1c360
Compare
The merge commit was breaking our tools, I've rebased it against master to allow it to land cleanly. |
This comment has been minimized.
This comment has been minimized.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #34824 +/- ##
==========================================
- Coverage 88.21% 87.90% -0.31%
==========================================
Files 479 477 -2
Lines 113942 113132 -810
Branches 25649 24648 -1001
==========================================
- Hits 100509 99453 -1056
- Misses 7676 7961 +285
+ Partials 5757 5718 -39
|
Landed in 3e10ce3 |
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: TODO
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Notable changes: child_process: * (SEMVER-MINOR) add ChildProcess 'spawn' event (Matthew Francis Brunetti) #35369 dns: * (SEMVER-MINOR) add setLocalAddress to Resolver (Josh Dague) #34824 http: * (SEMVER-MINOR) report request start and end with diagnostics_channel (Stephen Belanger) #34895 http2: * (SEMVER-MINOR) add updateSettings to both http2 servers (Vincent Boivin) #35383 lib: * (SEMVER-MINOR) create diagnostics_channel module (Stephen Belanger) #34895 src: * (SEMVER-MINOR) add --heapsnapshot-near-heap-limit option (Joyee Cheung) #33010 v8: * (SEMVER-MINOR) implement v8.stopCoverage() (Joyee Cheung) #33807 * (SEMVER-MINOR) implement v8.takeCoverage() (Joyee Cheung) #33807 worker: * (SEMVER-MINOR) add eventLoopUtilization() (Trevor Norris) #35664 PR-URL: #35948
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesThis allows users to specify the (local source) IP address used when a
dns.Resolver
instance makes DNS requests.Closes #34818