net/dns/resolver: make hasRDNSBonjourPrefix match shorter queries too

Fixes tailscale/corp#2886
Updates tailscale/corp#2820
Updates #2442

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
(cherry picked from commit 676fb458c3)
This commit is contained in:
Brad Fitzpatrick 2021-10-13 15:44:20 -07:00
parent 6421ee22f6
commit 784ce7c97c
2 changed files with 1 additions and 5 deletions

View File

@ -598,11 +598,6 @@ func marshalResponse(resp *response) ([]byte, error) {
// dr._dns-sd._udp.<domain>.
// lb._dns-sd._udp.<domain>.
func hasRDNSBonjourPrefix(name dnsname.FQDN) bool {
// Even the shortest name containing a Bonjour prefix is long,
// so check length (cheap) and bail early if possible.
if len(name) < len("*._dns-sd._udp.0.0.0.0.in-addr.arpa.") {
return false
}
s := name.WithTrailingDot()
dot := strings.IndexByte(s, '.')
if dot == -1 {

View File

@ -985,6 +985,7 @@ func TestTrimRDNSBonjourPrefix(t *testing.T) {
{"lb._dns-sd._udp.0.10.20.172.in-addr.arpa.", true},
{"qq._dns-sd._udp.0.10.20.172.in-addr.arpa.", false},
{"0.10.20.172.in-addr.arpa.", false},
{"lb._dns-sd._udp.ts-dns.test.", true},
}
for _, test := range tests {