Skip to content

Commit d145c23

Browse files
committed
update
1 parent 0f686bf commit d145c23

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

src/net/conf.go

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -158,26 +158,26 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
158158
return fallbackOrder, nil
159159
}
160160

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+
161171
// OpenBSD is unique and doesn't use nsswitch.conf.
162172
// It also doesn't support mDNS.
163173
if c.goos == "openbsd" {
164-
conf := getSystemDNSConfig()
165-
166174
// OpenBSD's resolv.conf manpage says that a non-existent
167175
// resolv.conf means "lookup" defaults to only "files",
168176
// without DNS lookups.
169177
if os.IsNotExist(conf.err) {
170178
return hostLookupFiles, conf
171179
}
172180

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-
181181
lookup := conf.lookup
182182
if len(lookup) == 0 {
183183
// 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
220220
// because Go's native resolver doesn't do mDNS or
221221
// similar local resolution mechanisms, assume that
222222
// libc might (via Avahi, etc) and use cgo.
223-
return fallbackOrder, nil
223+
return fallbackOrder, conf
224224
}
225225

226226
nss := c.nss
@@ -230,43 +230,34 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
230230
if os.IsNotExist(nss.err) || (nss.err == nil && len(srcs) == 0) {
231231
if c.goos == "solaris" {
232232
// 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.
243233
return fallbackOrder, conf
244234
}
235+
245236
return hostLookupFilesDNS, conf
246237
}
247238
if nss.err != nil {
248239
// We failed to parse or open nsswitch.conf, so
249240
// conservatively assume we should use cgo if it's
250241
// available.
251-
return fallbackOrder, nil
242+
return fallbackOrder, conf
252243
}
253244

254245
var mdnsSource, filesSource, dnsSource bool
255246
var first string
256247
for _, src := range srcs {
257248
if src.source == "myhostname" {
258249
if isLocalhost(hostname) || isGateway(hostname) {
259-
return fallbackOrder, nil
250+
return fallbackOrder, conf
260251
}
261252
hn, err := getHostname()
262253
if err != nil || stringsEqualFold(hostname, hn) {
263-
return fallbackOrder, nil
254+
return fallbackOrder, conf
264255
}
265256
continue
266257
}
267258
if src.source == "files" || src.source == "dns" {
268259
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.
270261
}
271262
if src.source == "files" {
272263
filesSource = true
@@ -286,23 +277,13 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
286277
continue
287278
}
288279
// Some source we don't know how to deal with.
289-
return fallbackOrder, nil
280+
return fallbackOrder, conf
290281
}
291282

292283
// We don't parse mdns.allow files. They're rare. If one
293284
// exists, it might list other TLDs (besides .local) or even
294285
// '*', so just let libc deal with it.
295286
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.
306287
return fallbackOrder, conf
307288
}
308289

0 commit comments

Comments
 (0)