From ee54a89ff957f6b5e465ee4d0fe109f6f9071324 Mon Sep 17 00:00:00 2001 From: Josh Dague Date: Mon, 17 Aug 2020 23:23:25 -0700 Subject: [PATCH 01/11] dns: add setLocalAddress to Resolver Fixes: https://github.com/nodejs/node/issues/34818 --- doc/api/dns.md | 9 ++++++++ lib/internal/dns/promises.js | 1 + lib/internal/dns/utils.js | 8 +++++++ src/cares_wrap.cc | 24 +++++++++++++++++++++ test/parallel/test-dns-setlocaladdress.js | 26 +++++++++++++++++++++++ 5 files changed, 68 insertions(+) create mode 100644 test/parallel/test-dns-setlocaladdress.js diff --git a/doc/api/dns.md b/doc/api/dns.md index a1f4240981f6cf..6480deeba7a01e 100644 --- a/doc/api/dns.md +++ b/doc/api/dns.md @@ -117,6 +117,15 @@ added: v8.3.0 Cancel all outstanding DNS queries made by this resolver. The corresponding callbacks will be called with an error with code `ECANCELLED`. +### `resolver.setLocalAddress(addr)` + + +* `addr` {string} A string representation of an IPv4 or IPv6 address. + +The resolver instance will send its requests from the specified IP address. This allows programs to specify outbound interfaces when used on multi-homed systems. + ## `dns.getServers()` * `addr` {string} A string representation of an IPv4 or IPv6 address. -The resolver instance will send its requests from the specified IP address. This allows programs to specify outbound interfaces when used on multi-homed systems. +The resolver instance will send its requests from the specified IP address. +This allows programs to specify outbound interfaces when used on multi-homed +systems. ## `dns.getServers()` -* `addr` {string} A string representation of an IPv4 or IPv6 address. +* `ipv4` {string} A string representation of an IPv4 address. + **Default:** `'0.0.0.0'` +* `ipv6` {string} A string representation of an IPv6 address. + **Default:** `'::0'` The resolver instance will send its requests from the specified IP address. This allows programs to specify outbound interfaces when used on multi-homed systems. +If a v4 or v6 address is not specified, it is set to `0.0.0.0` or `::0` +respectively, which is the default and means "choose automatically from +available IP addresses". + +The resolver will use the v4 local address when making requests to IPv4 DNS +servers, and the v6 local address when making requests to IPv6 DNS servers. +The `rrtype` of resolution requests has no impact on the local address used. + ## `dns.getServers()`