Skip to content

Commit

Permalink
Merge pull request #19 from tianon/always-answer-cname
Browse files Browse the repository at this point in the history
Fix CNAME handling a bit
  • Loading branch information
tianon authored Jan 20, 2017
2 parents d38f4a7 + c0a41f8 commit 3494a13
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/cmd/rawdns/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func dnsAppend(q dns.Question, m *dns.Msg, rr dns.RR) {
return
}

if q.Qtype == dns.TypeANY || q.Qtype == rr.Header().Rrtype {
if q.Qtype == dns.TypeANY || q.Qtype == rr.Header().Rrtype || rr.Header().Rrtype == dns.TypeCNAME {
m.Answer = append(m.Answer, rr)
} else {
m.Extra = append(m.Extra, rr)
Expand Down Expand Up @@ -240,20 +240,23 @@ func handleStaticRequest(config DomainConfig, w dns.ResponseWriter, r *dns.Msg)
dnsAppend(q, m, &dns.CNAME{Target: cname})

if r.RecursionDesired && len(config.Nameservers) > 0 {
recQ := dns.Question{
Name: cname,
Qtype: q.Qtype,
Qclass: q.Qclass,
}
recR := &dns.Msg{
MsgHdr: dns.MsgHdr{
Id: dns.Id(),
},
Question: []dns.Question{
{Name: cname, Qtype: q.Qtype, Qclass: q.Qclass},
},
Question: []dns.Question{recQ},
}
recM := handleForwardingRaw(config.Nameservers, recR, w.RemoteAddr())
for _, rr := range recM.Answer {
dnsAppend(q, m, rr)
dnsAppend(recQ, m, rr)
}
for _, rr := range recM.Extra {
dnsAppend(q, m, rr)
dnsAppend(recQ, m, rr)
}
}
}
Expand Down

0 comments on commit 3494a13

Please sign in to comment.