summaryrefslogtreecommitdiffhomepage
path: root/net/dns/resolver/tsdns_server_test.go
diff options
context:
space:
mode:
authorAdrian Dewhurst <adrian@tailscale.com>2021-08-06 11:46:33 -0400
committerAdrian Dewhurst <sailor@sailorfrag.net>2021-08-06 14:56:11 -0400
commit8bdf8788329876281dd55cf02a7e2a675c24ec35 (patch)
treeabcea10ca31519dfa5d92381e483b9b7b8f0061d /net/dns/resolver/tsdns_server_test.go
parent360223fccbbf66c0fa36783ecaf813939b0ed188 (diff)
downloadtailscale-Aadi/speedtest-tailscaled.tar.xz
tailscale-Aadi/speedtest-tailscaled.zip
net/dns/resolver: use forwarded dns txid directlyAadi/speedtest-tailscaled
Previously, we hashed the question and combined it with the original txid which was useful when concurrent queries were multiplexed on a single local source port. We encountered some situations where the DNS server canonicalizes the question in the response (uppercase converted to lowercase in this case), which resulted in responses that we couldn't match to the original request due to hash mismatches. This includes a new test to cover that situation. Fixes #2597 Signed-off-by: Adrian Dewhurst <adrian@tailscale.com>
Diffstat (limited to 'net/dns/resolver/tsdns_server_test.go')
-rw-r--r--net/dns/resolver/tsdns_server_test.go53
1 files changed, 53 insertions, 0 deletions
diff --git a/net/dns/resolver/tsdns_server_test.go b/net/dns/resolver/tsdns_server_test.go
index e0d8c40c5..675892a6e 100644
--- a/net/dns/resolver/tsdns_server_test.go
+++ b/net/dns/resolver/tsdns_server_test.go
@@ -6,6 +6,7 @@ package resolver
import (
"fmt"
+ "strings"
"testing"
"github.com/miekg/dns"
@@ -66,6 +67,58 @@ func resolveToIP(ipv4, ipv6 netaddr.IP, ns string) dns.HandlerFunc {
}
}
+// resolveToIPLowercase returns a handler function which canonicalizes responses
+// by lowercasing the question and answer names, and responds
+// to queries of type A it receives with an A record containing ipv4,
+// to queries of type AAAA with an AAAA record containing ipv6,
+// to queries of type NS with an NS record containg name.
+func resolveToIPLowercase(ipv4, ipv6 netaddr.IP, ns string) dns.HandlerFunc {
+ return func(w dns.ResponseWriter, req *dns.Msg) {
+ m := new(dns.Msg)
+ m.SetReply(req)
+
+ if len(req.Question) != 1 {
+ panic("not a single-question request")
+ }
+ m.Question[0].Name = strings.ToLower(m.Question[0].Name)
+ question := req.Question[0]
+
+ var ans dns.RR
+ switch question.Qtype {
+ case dns.TypeA:
+ ans = &dns.A{
+ Hdr: dns.RR_Header{
+ Name: question.Name,
+ Rrtype: dns.TypeA,
+ Class: dns.ClassINET,
+ },
+ A: ipv4.IPAddr().IP,
+ }
+ case dns.TypeAAAA:
+ ans = &dns.AAAA{
+ Hdr: dns.RR_Header{
+ Name: question.Name,
+ Rrtype: dns.TypeAAAA,
+ Class: dns.ClassINET,
+ },
+ AAAA: ipv6.IPAddr().IP,
+ }
+ case dns.TypeNS:
+ ans = &dns.NS{
+ Hdr: dns.RR_Header{
+ Name: question.Name,
+ Rrtype: dns.TypeNS,
+ Class: dns.ClassINET,
+ },
+ Ns: ns,
+ }
+ }
+
+ m.Answer = append(m.Answer, ans)
+ w.WriteMsg(m)
+ }
+}
+
// resolveToTXT returns a handler function which responds to queries of type TXT
// it receives with the strings in txts.
func resolveToTXT(txts []string, ednsMaxSize uint16) dns.HandlerFunc {