net: handle correctly the _gateway and _outbound hostnames for nss myhostname

Fixes #56387

Change-Id: If412134344600caefec425699398522399986d4d
GitHub-Last-Rev: f33540ef8f
GitHub-Pull-Request: golang/go#56388
Reviewed-on: https://go-review.googlesource.com/c/go/+/445075
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Mateusz Poliwczak 2022-11-11 07:34:15 +00:00 committed by Gopher Robot
parent 5a3243e6b6
commit c3aac6c010
2 changed files with 12 additions and 4 deletions

View File

@ -241,7 +241,7 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde
var first string
for _, src := range srcs {
if src.source == "myhostname" {
if isLocalhost(hostname) || isGateway(hostname) {
if isLocalhost(hostname) || isGateway(hostname) || isOutbound(hostname) {
return fallbackOrder
}
hn, err := getHostname()
@ -343,5 +343,11 @@ func isLocalhost(h string) bool {
// isGateway reports whether h should be considered a "gateway"
// name for the myhostname NSS module.
func isGateway(h string) bool {
return stringsEqualFold(h, "gateway")
return stringsEqualFold(h, "_gateway")
}
// isOutbound reports whether h should be considered a "outbound"
// name for the myhostname NSS module.
func isOutbound(h string) bool {
return stringsEqualFold(h, "_outbound")
}

View File

@ -271,8 +271,10 @@ func TestConfHostLookupOrder(t *testing.T) {
{"myHostname", "myhostname", hostLookupCgo},
{"myhostname.dot", "myhostname.dot", hostLookupCgo},
{"myHostname.dot", "myhostname.dot", hostLookupCgo},
{"gateway", "myhostname", hostLookupCgo},
{"Gateway", "myhostname", hostLookupCgo},
{"_gateway", "myhostname", hostLookupCgo},
{"_Gateway", "myhostname", hostLookupCgo},
{"_outbound", "myhostname", hostLookupCgo},
{"_Outbound", "myhostname", hostLookupCgo},
{"localhost", "myhostname", hostLookupCgo},
{"Localhost", "myhostname", hostLookupCgo},
{"anything.localhost", "myhostname", hostLookupCgo},