tsdns: lowercase the name in parseQuery.

Domains in DNS should be case-insensitive.

Signed-off-by: Dmytro Shynkevych <dmytro@tailscale.com>
pull/701/head
Dmytro Shynkevych 4 years ago
parent 309c15dfdd
commit 1886dfdca3
No known key found for this signature in database
GPG Key ID: FF5E2F3DAD97EA23

@ -293,6 +293,14 @@ func (r *Resolver) parseQuery(query []byte, resp *response) error {
return err
}
// Lowercase the name: DOMAIN.COM. should resolve the same as domain.com.
name := resp.Question.Name.Data[:resp.Question.Name.Length]
for i, b := range name {
if 'A' <= b && b <= 'Z' {
name[i] = b - 'A' + 'a'
}
}
return nil
}

@ -550,6 +550,7 @@ func TestFull(t *testing.T) {
}{
{"ipv4", dnspacket("test1.ipn.dev.", dns.TypeA), validIPv4Response},
{"ipv6", dnspacket("test2.ipn.dev.", dns.TypeAAAA), validIPv6Response},
{"upper", dnspacket("TEST1.IPN.DEV.", dns.TypeA), validIPv4Response},
{"ptr", dnspacket("4.3.2.1.in-addr.arpa.", dns.TypePTR), validPTRResponse},
{"error", dnspacket("test3.ipn.dev.", dns.TypeA), nxdomainResponse},
}

Loading…
Cancel
Save