Skip to content

Commit

Permalink
handle CNAME records (#13)
Browse files Browse the repository at this point in the history
* handle CNAME records

* Type cast cname record
  • Loading branch information
cy-b committed May 18, 2020
1 parent 62a46c5 commit 1301800
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions dns/dns.go
Expand Up @@ -107,6 +107,25 @@ func HandleSingleQuestion(name string, qType uint16, r *dns.Msg, s *dnsStore) bo
}
}
}

// handle CNAME record
if !hasPreciseMatch && qType != dns.TypeCNAME {
cnameList := typeMap[dns.TypeCNAME]
if cnameList != nil && len(cnameList) != 0 {
// should only have one CNAME RR
cnameRR, err := dns.NewRR(cnameList[0])
if err == nil && cnameRR != nil {
r.Answer = append(r.Answer, cnameRR)
// get the canonical name for this request domain name
realCNameRR, ok := cnameRR.(*dns.CNAME)
if ok {
cnameData := realCNameRR.Target
// retry with canonical name
return HandleSingleQuestion(cnameData, qType, r, s)
}
}
}
}
}

// Has precise match, no need to scan further
Expand Down

0 comments on commit 1301800

Please sign in to comment.