resolv-conf 1.0.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/README.md +21 -13
- package/lib/defaults.d.ts +314 -0
- package/lib/defaults.js +302 -77
- package/lib/index.d.ts +20 -0
- package/lib/index.js +31 -29
- package/lib/resolv.peg.d.ts +11 -0
- package/lib/resolv.peg.js +1505 -478
- package/package.json +18 -14
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
# Parse resolv.conf
|
|
2
2
|
|
|
3
|
-
This repo uses the Linux documentation for
|
|
3
|
+
This repo uses the Linux documentation for
|
|
4
|
+
[resolv.conf(5)](https://man7.org/linux/man-pages/man5/resolv.conf.5.html) to
|
|
5
|
+
parse the configuration for DNS resolution on your system. Windows uses a
|
|
6
|
+
different approach, so the best you can do is likely the Node built-in
|
|
7
|
+
[`dns.getServers()`](https://nodejs.org/api/dns.html#dns_dns_getservers).
|
|
4
8
|
|
|
5
|
-
Note that the defaults and environment variables listed in the docs were also
|
|
9
|
+
Note that the defaults and environment variables listed in the docs were also
|
|
10
|
+
implemented.
|
|
6
11
|
|
|
7
12
|
## Install
|
|
8
13
|
|
|
@@ -13,8 +18,8 @@ npm install resolv-conf
|
|
|
13
18
|
## Usage
|
|
14
19
|
|
|
15
20
|
```js
|
|
16
|
-
|
|
17
|
-
await
|
|
21
|
+
import {parseFile, parse} from 'resolv-conf';
|
|
22
|
+
const config = await parseFile(); // filename is optional
|
|
18
23
|
|
|
19
24
|
// returns:
|
|
20
25
|
// {
|
|
@@ -26,21 +31,24 @@ await resolv.parseFile() // filename is optional
|
|
|
26
31
|
// }
|
|
27
32
|
|
|
28
33
|
// if you already have text from the file:
|
|
29
|
-
|
|
34
|
+
const config2 = parse(text);
|
|
30
35
|
```
|
|
31
36
|
|
|
32
|
-
##
|
|
37
|
+
## Options
|
|
33
38
|
|
|
34
|
-
|
|
39
|
+
Options will have dashes turned into underscores. For example, `no-aaaa` will be
|
|
40
|
+
available as `config.options.no_aaaa`.
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
## Errors
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
Unrecoverable parse errors will throw an exception with `location`,
|
|
45
|
+
`expected`, `found`, and `message` properties.
|
|
39
46
|
|
|
40
|
-
|
|
47
|
+
Recoverable errors (e.g. invalid IP addresses) will show up in the result
|
|
48
|
+
object in the `errors` property, and valid defaults will be chosen for that
|
|
49
|
+
option if need be.
|
|
41
50
|
|
|
42
51
|
## Status
|
|
43
52
|
|
|
44
|
-
[](https://runkit.com/hildjj/5feaeb406e1b55001a1211f9)
|
|
53
|
+
[](https://github.com/hildjj/resolv-conf/actions/workflows/node.js.yml)
|
|
54
|
+
[](https://codecov.io/gh/hildjj/resolv-conf)
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Add default parameters to a parsed resolv.conf file.
|
|
3
|
+
*
|
|
4
|
+
* @param {GatheredLines} parsed Just what was in the file.
|
|
5
|
+
* @param {Record<string, number>} port The ports detected in the file.
|
|
6
|
+
* @returns {ResolvResults} With the defaults and environment variables filled
|
|
7
|
+
* in.
|
|
8
|
+
*/
|
|
9
|
+
export function resolv(parsed: GatheredLines, port: Record<string, number>): ResolvResults;
|
|
10
|
+
/**
|
|
11
|
+
* Convert a string to a number, if possible.
|
|
12
|
+
*
|
|
13
|
+
* @param {string | null} val
|
|
14
|
+
* @returns {boolean | string | number}
|
|
15
|
+
*/
|
|
16
|
+
export function maybeNum(val: string | null): boolean | string | number;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param {object[]} list
|
|
20
|
+
* @returns {GatheredLines}
|
|
21
|
+
*/
|
|
22
|
+
export function gather(list: object[]): GatheredLines;
|
|
23
|
+
/**
|
|
24
|
+
* The v4/v6 address and netmask.
|
|
25
|
+
*/
|
|
26
|
+
export type AddrMask = {
|
|
27
|
+
/**
|
|
28
|
+
* IP address.
|
|
29
|
+
*/
|
|
30
|
+
address: string;
|
|
31
|
+
/**
|
|
32
|
+
* Netmask for the address.
|
|
33
|
+
*/
|
|
34
|
+
mask?: string | undefined;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Options parsed from resolv.conf. Note that option names have dashes ('-')
|
|
38
|
+
* converted to underscores ('_') for easier use in JS.
|
|
39
|
+
*/
|
|
40
|
+
export type KnownResolvOptions = {
|
|
41
|
+
/**
|
|
42
|
+
* Sets RES_DEBUG.
|
|
43
|
+
*/
|
|
44
|
+
debug?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* Sets a threshold for the number of dots which must
|
|
47
|
+
* appear in a name given to query before an initial absolute query will be
|
|
48
|
+
* made. The default for n is 1, meaning that if there are any dots in a
|
|
49
|
+
* name, the name will be tried first as an absolute name before any search
|
|
50
|
+
* list elements are appended to it. The value for this option is silently
|
|
51
|
+
* capped to 15.
|
|
52
|
+
*/
|
|
53
|
+
ndots: number;
|
|
54
|
+
/**
|
|
55
|
+
* Sets the amount of time the resolver will wait for
|
|
56
|
+
* a response from a remote name server before retrying the query via a
|
|
57
|
+
* different name server. This may not be the total time taken by any
|
|
58
|
+
* resolver API call and there is no guarantee that a single resolver API
|
|
59
|
+
* call maps to a single timeout. Measured in seconds, the default is
|
|
60
|
+
* RES_TIMEOUT (currently 5). The value for this option is silently capped
|
|
61
|
+
* to 30.
|
|
62
|
+
*/
|
|
63
|
+
timeout?: number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the number of times the resolver will send a
|
|
66
|
+
* query to its name servers before giving up and returning an error to the
|
|
67
|
+
* calling application. The default is RES_DFLRETRY (currently 2). The
|
|
68
|
+
* value for this option is silently capped to 5.
|
|
69
|
+
*/
|
|
70
|
+
attempts?: number | undefined;
|
|
71
|
+
/**
|
|
72
|
+
* Sets RES_ROTATE, which causes round-robin
|
|
73
|
+
* selection of name servers from among those listed. This has the effect
|
|
74
|
+
* of spreading the query load among all listed servers, rather than having
|
|
75
|
+
* all clients try the first listed server first every time.
|
|
76
|
+
*/
|
|
77
|
+
rotate?: boolean | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* Sets RES_NOAAAA in _res.options, which suppresses
|
|
80
|
+
* AAAA queries made by the stub resolver, including AAAA lookups triggered
|
|
81
|
+
* by NSS-based interfaces such as getaddrinfo(3). Only DNS lookups are
|
|
82
|
+
* affected: IPv6 data in hosts(5) is still used, getaddrinfo(3) with
|
|
83
|
+
* AI_PASSIVE will still produce IPv6 addresses, and configured IPv6 name
|
|
84
|
+
* servers are still used. To produce correct Name Error (NXDOMAIN) results,
|
|
85
|
+
* AAAA queries are translated to A queries. This option is intended
|
|
86
|
+
* preliminary for diagnostic purposes, to rule out that AAAA DNS queries
|
|
87
|
+
* have adverse impact. It is incompatible with EDNS0 usage and DNSSEC
|
|
88
|
+
* validation by applications.
|
|
89
|
+
*/
|
|
90
|
+
no_aaaa?: boolean | undefined;
|
|
91
|
+
/**
|
|
92
|
+
* Sets RES_NOCHECKNAME, which disables the
|
|
93
|
+
* modern BIND checking of incoming hostnames and mail names for invalid
|
|
94
|
+
* characters such as underscore (_), non-ASCII, or control characters.
|
|
95
|
+
*/
|
|
96
|
+
no_check_names?: boolean | undefined;
|
|
97
|
+
/**
|
|
98
|
+
* Sets RES_USE_INET6. This has the effect of trying
|
|
99
|
+
* an AAAA query before an A query inside the gethostbyname(3) function, and
|
|
100
|
+
* of mapping IPv4 responses in IPv6 "tunneled form" if no AAAA records are
|
|
101
|
+
* found but an A record set exists. Since glibc 2.25, this option is
|
|
102
|
+
* deprecated; applications should use getaddrinfo(3), rather than
|
|
103
|
+
* gethostbyname(3).
|
|
104
|
+
*/
|
|
105
|
+
inet6?: boolean | undefined;
|
|
106
|
+
/**
|
|
107
|
+
* Sets RES_USE_EDNS0. This enables support for the
|
|
108
|
+
* DNS extensions described in RFC 2671.
|
|
109
|
+
*/
|
|
110
|
+
edns0?: boolean | undefined;
|
|
111
|
+
/**
|
|
112
|
+
* Sets RES_SNGLKUP. By default, glibc
|
|
113
|
+
* performs IPv4 and IPv6 lookups in parallel since glibc 2.9. Some
|
|
114
|
+
* appliance DNS servers cannot handle these queries properly and make the
|
|
115
|
+
* requests time out. This option disables the behavior and makes glibc
|
|
116
|
+
* perform the IPv6 and IPv4 requests sequentially (at the cost of some
|
|
117
|
+
* slowdown of the resolving process).
|
|
118
|
+
*/
|
|
119
|
+
single_request?: boolean | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* Sets RES_SNGLKUPREOP. The resolver
|
|
122
|
+
* uses the same socket for the A and AAAA requests. Some hardware
|
|
123
|
+
* mistakenly sends back only one reply. When that happens the client system
|
|
124
|
+
* will sit and wait for the second reply. Turning this option on changes
|
|
125
|
+
* this behavior so that if two requests from the same port are not handled
|
|
126
|
+
* correctly it will close the socket and open a new one before sending the
|
|
127
|
+
* second request.
|
|
128
|
+
*/
|
|
129
|
+
single_request_reopen?: boolean | undefined;
|
|
130
|
+
/**
|
|
131
|
+
* Sets RES_NOTLDQUERY. This option causes
|
|
132
|
+
* res_nsearch() to not attempt to resolve an unqualified name as if it were
|
|
133
|
+
* a top level domain (TLD). This option can cause problems if the site has
|
|
134
|
+
* ``localhost'' as a TLD rather than having localhost on one or more
|
|
135
|
+
* elements of the search list. This option has no effect if neither
|
|
136
|
+
* RES_DEFNAMES or RES_DNSRCH is set.
|
|
137
|
+
*/
|
|
138
|
+
no_tld_query?: boolean | undefined;
|
|
139
|
+
/**
|
|
140
|
+
* Sets RES_USEVC. This option forces the use of TCP
|
|
141
|
+
* for DNS resolutions.
|
|
142
|
+
*/
|
|
143
|
+
use_vc?: boolean | undefined;
|
|
144
|
+
/**
|
|
145
|
+
* Sets RES_NORELOAD in _res.options. This option
|
|
146
|
+
* disables automatic reloading of a changed configuration file.
|
|
147
|
+
*/
|
|
148
|
+
no_reload?: boolean | undefined;
|
|
149
|
+
/**
|
|
150
|
+
* Sets RES_TRUSTAD in _res.options. This option
|
|
151
|
+
* controls the AD bit behavior of the stub resolver. If a validating
|
|
152
|
+
* resolver sets the AD bit in a response, it indicates that the data in the
|
|
153
|
+
* response was verified according to the DNSSEC protocol. In order to rely
|
|
154
|
+
* on the AD bit, the local system has to trust both the DNSSEC- validating
|
|
155
|
+
* resolver and the network path to it, which is why an explicit opt-in is
|
|
156
|
+
* required. If the trust-ad option is active, the stub resolver sets the
|
|
157
|
+
* AD bit in outgoing DNS queries (to enable AD bit support), and preserves
|
|
158
|
+
* the AD bit in responses. Without this option, the AD bit is not set in
|
|
159
|
+
* queries, and it is always removed from responses before they are returned
|
|
160
|
+
* to the application. This means that applications can trust the AD bit in
|
|
161
|
+
* responses if the trust-ad option has been set correctly.
|
|
162
|
+
*/
|
|
163
|
+
trust_ad?: boolean | undefined;
|
|
164
|
+
/**
|
|
165
|
+
* Do not require IP source address on the reply
|
|
166
|
+
* packet to be equal to the server's address. BSD only.
|
|
167
|
+
*/
|
|
168
|
+
insecure1?: boolean | undefined;
|
|
169
|
+
/**
|
|
170
|
+
* Do not check if the query section of the reply
|
|
171
|
+
* packet is equal to that of the query packet. For testing purposes only.
|
|
172
|
+
* BSD only.
|
|
173
|
+
*/
|
|
174
|
+
insecure2?: boolean | undefined;
|
|
175
|
+
/**
|
|
176
|
+
* Forces the use of TCP for queries. Normal behaviour
|
|
177
|
+
* is to query via UDP but fall back to TCP on failure. BSD only.
|
|
178
|
+
*/
|
|
179
|
+
tcp?: boolean | undefined;
|
|
180
|
+
};
|
|
181
|
+
export type ResolvOptions = KnownResolvOptions & Record<string, any>;
|
|
182
|
+
export type ResolvError = {
|
|
183
|
+
text: string;
|
|
184
|
+
location: import('peggy').LocationRange;
|
|
185
|
+
};
|
|
186
|
+
export type GatheredLines = {
|
|
187
|
+
/**
|
|
188
|
+
* The nameserver IP addresses to try,
|
|
189
|
+
* in order.
|
|
190
|
+
*/
|
|
191
|
+
nameserver?: string[] | undefined;
|
|
192
|
+
/**
|
|
193
|
+
* Ports to use when talking to each
|
|
194
|
+
* nameserver. The default is in the "" key. A key will be added for each
|
|
195
|
+
* nameserver.
|
|
196
|
+
*/
|
|
197
|
+
port?: Record<string, number> | undefined;
|
|
198
|
+
/**
|
|
199
|
+
* The domains to search if the target
|
|
200
|
+
* doesn't have at least options.ndots dots in it.
|
|
201
|
+
*/
|
|
202
|
+
search?: string[] | undefined;
|
|
203
|
+
/**
|
|
204
|
+
* Sort the results according to these
|
|
205
|
+
* addresses and netmasks.
|
|
206
|
+
*/
|
|
207
|
+
sortlist?: AddrMask[] | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* Various options. Things
|
|
210
|
+
* that can be converted to numbers will have been, and things that are
|
|
211
|
+
* flags will have the value true.
|
|
212
|
+
*/
|
|
213
|
+
options?: [name: string, value: any][] | undefined;
|
|
214
|
+
/**
|
|
215
|
+
* Errors encountered while parsing the
|
|
216
|
+
* file, extracted here rather than causing overall parsing to fail.
|
|
217
|
+
*/
|
|
218
|
+
errors?: ResolvError[] | undefined;
|
|
219
|
+
/**
|
|
220
|
+
* Specifies the total amount of time allowed for
|
|
221
|
+
* a name resolution. This time interval is divided by the number of
|
|
222
|
+
* nameservers and the number of retries allowed for each nameserver. Only
|
|
223
|
+
* on MacOS.
|
|
224
|
+
*/
|
|
225
|
+
timeout?: number | undefined;
|
|
226
|
+
/**
|
|
227
|
+
* Only required for those clients that
|
|
228
|
+
* share a domain name with other clients. Queries will be sent to these
|
|
229
|
+
* clients in order by ascending search_order value. For example, this
|
|
230
|
+
* allows two clients for the ".local" domain, which is used by Apple's
|
|
231
|
+
* multicast DNS, but which may also be used at some sites as private DNS
|
|
232
|
+
* domain name. Only on MacOS.
|
|
233
|
+
*/
|
|
234
|
+
search_order?: number | undefined;
|
|
235
|
+
/**
|
|
236
|
+
* Specify which type of Internet
|
|
237
|
+
* protocol family to prefer, if a host is reachable using different address
|
|
238
|
+
* families. By default IPv4 addresses are queried first, and then IPv6
|
|
239
|
+
* addresses. Only on BSD.
|
|
240
|
+
*/
|
|
241
|
+
family?: ("inet4" | "inet6")[] | undefined;
|
|
242
|
+
/**
|
|
243
|
+
* This keyword is used by the
|
|
244
|
+
* library routines gethostbyname(3) and gethostbyaddr(3). It specifies
|
|
245
|
+
* which databases should be searched, and the order to do so. Only on BSD.
|
|
246
|
+
*/
|
|
247
|
+
lookup?: ("file" | "yp" | "bind")[] | undefined;
|
|
248
|
+
};
|
|
249
|
+
/**
|
|
250
|
+
* The results from parsing a resolv.conf file.
|
|
251
|
+
*/
|
|
252
|
+
export type ResolvResults = {
|
|
253
|
+
/**
|
|
254
|
+
* The nameserver IP addresses to try, in
|
|
255
|
+
* order.
|
|
256
|
+
*/
|
|
257
|
+
nameserver: Array<string>;
|
|
258
|
+
/**
|
|
259
|
+
* Ports to use when talking to each
|
|
260
|
+
* nameserver. The default is in the "" key. A key will be added for each
|
|
261
|
+
* nameserver.
|
|
262
|
+
*/
|
|
263
|
+
port: Record<string, number>;
|
|
264
|
+
/**
|
|
265
|
+
* The domains to search if the target
|
|
266
|
+
* doesn't have at least options.ndots dots in it.
|
|
267
|
+
*/
|
|
268
|
+
search: Array<string>;
|
|
269
|
+
/**
|
|
270
|
+
* Sort the results according to these
|
|
271
|
+
* addresses and netmasks.
|
|
272
|
+
*/
|
|
273
|
+
sortlist?: AddrMask[] | undefined;
|
|
274
|
+
/**
|
|
275
|
+
* Specifies the total amount of time allowed for
|
|
276
|
+
* a name resolution. This time interval is divided by the number of
|
|
277
|
+
* nameservers and the number of retries allowed for each nameserver. Only
|
|
278
|
+
* on MacOS.
|
|
279
|
+
*/
|
|
280
|
+
timeout?: number | undefined;
|
|
281
|
+
/**
|
|
282
|
+
* Only required for those clients that
|
|
283
|
+
* share a domain name with other clients. Queries will be sent to these
|
|
284
|
+
* clients in order by ascending search_order value. For example, this
|
|
285
|
+
* allows two clients for the ".local" domain, which is used by Apple's
|
|
286
|
+
* multicast DNS, but which may also be used at some sites as private DNS
|
|
287
|
+
* domain name. Only on MacOS.
|
|
288
|
+
*/
|
|
289
|
+
search_order?: number | undefined;
|
|
290
|
+
/**
|
|
291
|
+
* This keyword is used by the
|
|
292
|
+
* library routines gethostbyname(3) and gethostbyaddr(3). It specifies
|
|
293
|
+
* which databases should be searched, and the order to do so. Only on BSD.
|
|
294
|
+
*/
|
|
295
|
+
lookup?: ("file" | "yp" | "bind")[] | undefined;
|
|
296
|
+
/**
|
|
297
|
+
* Specify which type of Internet
|
|
298
|
+
* protocol family to prefer, if a host is reachable using different address
|
|
299
|
+
* families. By default IPv4 addresses are queried first, and then IPv6
|
|
300
|
+
* addresses. Only on BSD.
|
|
301
|
+
*/
|
|
302
|
+
family?: ("inet4" | "inet6")[] | undefined;
|
|
303
|
+
/**
|
|
304
|
+
* Various options. Things that can be
|
|
305
|
+
* converted to numbers will have been, and things that are flags will have
|
|
306
|
+
* the value true.
|
|
307
|
+
*/
|
|
308
|
+
options: ResolvOptions;
|
|
309
|
+
/**
|
|
310
|
+
* Errors encountered while parsing the
|
|
311
|
+
* file, extracted here rather than causing overall parsing to fail.
|
|
312
|
+
*/
|
|
313
|
+
errors?: ResolvError[] | undefined;
|
|
314
|
+
};
|