From: Mateusz Poliwczak Date: Fri, 11 Nov 2022 07:34:15 +0000 (+0000) Subject: net: handle correctly the _gateway and _outbound hostnames for nss myhostname X-Git-Tag: go1.20rc1~298 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=c3aac6c010f9293319ae5dbe0592bc7706b6a161;p=gostls13.git net: handle correctly the _gateway and _outbound hostnames for nss myhostname Fixes #56387 Change-Id: If412134344600caefec425699398522399986d4d GitHub-Last-Rev: f33540ef8f90e9a8c09f3947aba8c01155516d39 GitHub-Pull-Request: golang/go#56388 Reviewed-on: https://go-review.googlesource.com/c/go/+/445075 TryBot-Result: Gopher Robot Reviewed-by: Damien Neil Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Heschi Kreinick Auto-Submit: Ian Lance Taylor --- diff --git a/src/net/conf.go b/src/net/conf.go index 6854f46658..77099ca100 100644 --- a/src/net/conf.go +++ b/src/net/conf.go @@ -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") } diff --git a/src/net/conf_test.go b/src/net/conf_test.go index 86fc4797b9..c059c3670a 100644 --- a/src/net/conf_test.go +++ b/src/net/conf_test.go @@ -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},