From a71df7630e63de98bd88bbbd7171a8ffbd7850ef Mon Sep 17 00:00:00 2001 From: Ouyang Yadong Date: Tue, 6 Apr 2021 16:09:11 +0800 Subject: [PATCH] dns: allow `--dns-result-order` to change default dns verbatim Allow the `--dns-result-order` option to change the default value of verbatim in `dns.lookup()`. This is useful when running Node.js in ipv6-only environments to avoid possible ENETUNREACH errors. PR-URL: https://github.com/nodejs/node/pull/38099 Refs: https://github.com/nodejs/node/issues/31566 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Antoine du Hamel Reviewed-By: Anna Henningsen --- doc/api/cli.md | 17 ++++ doc/api/dns.md | 48 +++++++++- lib/dns.js | 10 +- lib/internal/dns/promises.js | 8 +- lib/internal/dns/utils.js | 21 +++++ src/node_options.cc | 7 ++ src/node_options.h | 1 + .../test-dns-default-verbatim-false.js | 51 ++++++++++ .../test-dns-default-verbatim-true.js | 51 ++++++++++ test/parallel/test-dns-set-default-order.js | 93 +++++++++++++++++++ 10 files changed, 298 insertions(+), 9 deletions(-) create mode 100644 test/parallel/test-dns-default-verbatim-false.js create mode 100644 test/parallel/test-dns-default-verbatim-true.js create mode 100644 test/parallel/test-dns-set-default-order.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 8fce8ac430da1e..23c54f2e3bfb95 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -187,6 +187,19 @@ Make built-in language features like `eval` and `new Function` that generate code from strings throw an exception instead. This does not affect the Node.js `vm` module. +### `--dns-result-order=order` + + +Set the default value of `verbatim` in [`dns.lookup()`][] and +[`dnsPromises.lookup()`][]. The value could be: +* `ipv4first`: sets default `verbatim` `false`. +* `verbatim`: sets default `verbatim` `true`. + +The default is `ipv4first` and [`dns.setDefaultResultOrder()`][] have higher +priority than `--dns-result-order`. + ### `--enable-fips` + +* `order` {string} must be `'ipv4first'` or `'verbatim'`. + +Set the default value of `verbatim` in [`dns.lookup()`][] and +[`dnsPromises.lookup()`][]. The value could be: +* `ipv4first`: sets default `verbatim` `false`. +* `verbatim`: sets default `verbatim` `true`. + +The default is `ipv4first` and [`dns.setDefaultResultOrder()`][] have higher +priority than [`--dns-result-order`][]. When using [worker threads][], +[`dns.setDefaultResultOrder()`][] from the main thread won't affect the default +dns orders in workers. + ## `dns.setServers(servers)` + +* `order` {string} must be `'ipv4first'` or `'verbatim'`. + +Set the default value of `verbatim` in [`dns.lookup()`][] and +[`dnsPromises.lookup()`][]. The value could be: +* `ipv4first`: sets default `verbatim` `false`. +* `verbatim`: sets default `verbatim` `true`. + +The default is `ipv4first` and [`dnsPromises.setDefaultResultOrder()`][] have +higher priority than [`--dns-result-order`][]. When using [worker threads][], +[`dnsPromises.setDefaultResultOrder()`][] from the main thread won't affect the +default dns orders in workers. + ### `dnsPromises.setServers(servers)`