@@ -158,26 +158,26 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
158
158
return fallbackOrder , nil
159
159
}
160
160
161
+ conf := getSystemDNSConfig ()
162
+ if (conf .err != nil && ! os .IsNotExist (conf .err ) &&
163
+ ! os .IsPermission (conf .err )) || (conf .err == nil && conf .unknownOpt ) {
164
+ // If we can't read the resolv.conf file or it has unsupported
165
+ // by net package options assume it had something important in it
166
+ // and defer to cgo. libc's resolver might then fail too, but at least
167
+ // it wasn't our fault.
168
+ return fallbackOrder , conf
169
+ }
170
+
161
171
// OpenBSD is unique and doesn't use nsswitch.conf.
162
172
// It also doesn't support mDNS.
163
173
if c .goos == "openbsd" {
164
- conf := getSystemDNSConfig ()
165
-
166
174
// OpenBSD's resolv.conf manpage says that a non-existent
167
175
// resolv.conf means "lookup" defaults to only "files",
168
176
// without DNS lookups.
169
177
if os .IsNotExist (conf .err ) {
170
178
return hostLookupFiles , conf
171
179
}
172
180
173
- if (conf .err != nil && ! os .IsPermission (conf .err )) || (conf .err == nil && conf .unknownOpt ) {
174
- // If we can't read the resolv.conf file or it has unsupported
175
- // by net package options assume it had something important in it
176
- // and defer to cgo. libc's resolver might then fail too, but at least
177
- // it wasn't our fault.
178
- return fallbackOrder , conf
179
- }
180
-
181
181
lookup := conf .lookup
182
182
if len (lookup ) == 0 {
183
183
// https://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/resolv.conf.5
@@ -220,7 +220,7 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
220
220
// because Go's native resolver doesn't do mDNS or
221
221
// similar local resolution mechanisms, assume that
222
222
// libc might (via Avahi, etc) and use cgo.
223
- return fallbackOrder , nil
223
+ return fallbackOrder , conf
224
224
}
225
225
226
226
nss := c .nss
@@ -230,43 +230,34 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
230
230
if os .IsNotExist (nss .err ) || (nss .err == nil && len (srcs ) == 0 ) {
231
231
if c .goos == "solaris" {
232
232
// illumos defaults to "nis [NOTFOUND=return] files"
233
- return fallbackOrder , nil
234
- }
235
-
236
- conf := getSystemDNSConfig ()
237
- if (conf .err != nil && ! os .IsNotExist (conf .err ) &&
238
- ! os .IsPermission (conf .err )) || (conf .err == nil && conf .unknownOpt ) {
239
- // If we can't read the resolv.conf file or it has unsupported
240
- // by net package options assume it had something important in it
241
- // and defer to cgo. libc's resolver might then fail too, but at least
242
- // it wasn't our fault.
243
233
return fallbackOrder , conf
244
234
}
235
+
245
236
return hostLookupFilesDNS , conf
246
237
}
247
238
if nss .err != nil {
248
239
// We failed to parse or open nsswitch.conf, so
249
240
// conservatively assume we should use cgo if it's
250
241
// available.
251
- return fallbackOrder , nil
242
+ return fallbackOrder , conf
252
243
}
253
244
254
245
var mdnsSource , filesSource , dnsSource bool
255
246
var first string
256
247
for _ , src := range srcs {
257
248
if src .source == "myhostname" {
258
249
if isLocalhost (hostname ) || isGateway (hostname ) {
259
- return fallbackOrder , nil
250
+ return fallbackOrder , conf
260
251
}
261
252
hn , err := getHostname ()
262
253
if err != nil || stringsEqualFold (hostname , hn ) {
263
- return fallbackOrder , nil
254
+ return fallbackOrder , conf
264
255
}
265
256
continue
266
257
}
267
258
if src .source == "files" || src .source == "dns" {
268
259
if ! src .standardCriteria () {
269
- return fallbackOrder , nil // non-standard; let libc deal with it.
260
+ return fallbackOrder , conf // non-standard; let libc deal with it.
270
261
}
271
262
if src .source == "files" {
272
263
filesSource = true
@@ -286,23 +277,13 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
286
277
continue
287
278
}
288
279
// Some source we don't know how to deal with.
289
- return fallbackOrder , nil
280
+ return fallbackOrder , conf
290
281
}
291
282
292
283
// We don't parse mdns.allow files. They're rare. If one
293
284
// exists, it might list other TLDs (besides .local) or even
294
285
// '*', so just let libc deal with it.
295
286
if mdnsSource && c .hasMDNSAllow {
296
- return fallbackOrder , nil
297
- }
298
-
299
- conf := getSystemDNSConfig ()
300
- if (conf .err != nil && ! os .IsNotExist (conf .err ) &&
301
- ! os .IsPermission (conf .err )) || (conf .err == nil && conf .unknownOpt ) {
302
- // If we can't read the resolv.conf file or it has unsupported
303
- // by net package options assume it had something important in it
304
- // and defer to cgo. libc's resolver might then fail too, but at least
305
- // it wasn't our fault.
306
287
return fallbackOrder , conf
307
288
}
308
289
0 commit comments