]> Cypherpunks repositories - gostls13.git/commitdiff
net: don't force cgo resolver for .local subdomain queries
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Tue, 20 Feb 2024 17:15:43 +0000 (17:15 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 26 Feb 2024 20:46:36 +0000 (20:46 +0000)
The cgo resolver sends DNS queries for .local subdomain
lookups, just as we do in the go resolver.
We don't need to fallback to the cgo resolver for this
domains when nsswitch.conf uses only file and dns modules.

This has a benefit that we select a consistent resolver,
that is only based on the system configuration, regardless
of the queried domain.

Updates #63978

Change-Id: I9166103adb94d7ab52992925f413f361130e7c52
GitHub-Last-Rev: e2bc5874cb5c9165e3cc058e9effe36d0ce68cd6
GitHub-Pull-Request: golang/go#63986
Reviewed-on: https://go-review.googlesource.com/c/go/+/540555
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
src/net/conf.go
src/net/conf_test.go
src/net/net.go

index 15d73cf6ce1a45aadb2b24594d4711b9a145408c..6fe1e4725ac476ff6ce0c3ddf3b1ab6f04a57094 100644 (file)
@@ -338,13 +338,6 @@ func (c *conf) lookupOrder(r *Resolver, hostname string) (ret hostLookupOrder, d
        if stringsHasSuffix(hostname, ".") {
                hostname = hostname[:len(hostname)-1]
        }
-       if canUseCgo && stringsHasSuffixFold(hostname, ".local") {
-               // Per RFC 6762, the ".local" TLD is special. And
-               // because Go's native resolver doesn't do mDNS or
-               // similar local resolution mechanisms, assume that
-               // libc might (via Avahi, etc) and use cgo.
-               return hostLookupCgo, dnsConf
-       }
 
        nss := getSystemNSS()
        srcs := nss.sources["hosts"]
@@ -404,9 +397,13 @@ func (c *conf) lookupOrder(r *Resolver, hostname string) (ret hostLookupOrder, d
                                }
                                continue
                        case hostname != "" && stringsHasPrefix(src.source, "mdns"):
-                               // e.g. "mdns4", "mdns4_minimal"
-                               // We already returned true before if it was *.local.
-                               // libc wouldn't have found a hit on this anyway.
+                               if stringsHasSuffixFold(hostname, ".local") {
+                                       // Per RFC 6762, the ".local" TLD is special. And
+                                       // because Go's native resolver doesn't do mDNS or
+                                       // similar local resolution mechanisms, assume that
+                                       // libc might (via Avahi, etc) and use cgo.
+                                       return hostLookupCgo, dnsConf
+                               }
 
                                // We don't parse mdns.allow files. They're rare. If one
                                // exists, it might list other TLDs (besides .local) or even
index 0f324b245aef12269d3160a97879317ac9803c5f..6ebd6be635c95ad7a4379eb2d4d5c82f9574d832 100644 (file)
@@ -257,7 +257,7 @@ func TestConfHostLookupOrder(t *testing.T) {
                        hostTests: []nssHostTest{
                                {"x.com", "myhostname", hostLookupFilesDNS},
                                {"x", "myhostname", hostLookupFilesDNS},
-                               {"x.local", "myhostname", hostLookupCgo},
+                               {"x.local", "myhostname", hostLookupFilesDNS},
                        },
                },
                {
@@ -268,7 +268,7 @@ func TestConfHostLookupOrder(t *testing.T) {
                        hostTests: []nssHostTest{
                                {"x.com", "myhostname", hostLookupDNSFiles},
                                {"x", "myhostname", hostLookupDNSFiles},
-                               {"x.local", "myhostname", hostLookupCgo},
+                               {"x.local", "myhostname", hostLookupDNSFiles},
                        },
                },
                {
index b5f7303db34dae489310b29a01cb3b892b07cf25..d0db65286b180c5f141ab1108351c416331821a8 100644 (file)
@@ -54,8 +54,7 @@ when the LOCALDOMAIN environment variable is present (even if empty),
 when the RES_OPTIONS or HOSTALIASES environment variable is non-empty,
 when the ASR_CONFIG environment variable is non-empty (OpenBSD only),
 when /etc/resolv.conf or /etc/nsswitch.conf specify the use of features that the
-Go resolver does not implement, and when the name being looked up ends in .local
-or is an mDNS name.
+Go resolver does not implement.
 
 On all systems (except Plan 9), when the cgo resolver is being used
 this package applies a concurrent cgo lookup limit to prevent the system