Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Commit

Permalink
Return NOTIMP for some unimplemented query types, NXDOMAIN otherwise
Browse files Browse the repository at this point in the history
  • Loading branch information
inercia committed Apr 23, 2015
1 parent 3ad186d commit a99ae96
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
5 changes: 5 additions & 0 deletions nameserver/dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const (
maxUDPSize = 65535
)

// query types we currently do not implement
var notImplementedQTypes = map[uint16]struct{} {
dns.TypeANY: struct{}{},
}

func makeHeader(r *dns.Msg, q *dns.Question) *dns.RR_Header {
return &dns.RR_Header{
Name: q.Name, Rrtype: q.Qtype,
Expand Down
26 changes: 22 additions & 4 deletions nameserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,24 @@ func (s *DNSServer) queryHandler(proto dnsProtocol) dns.HandlerFunc {
return
}

// catch unsupported queries
if q.Qtype != dns.TypeA {
Debug.Printf("[dns msgid %d] Unsuported query type %s", r.MsgHdr.Id, dns.TypeToString[q.Qtype])
// catch queries that are not implemented
if _, notImpl := notImplementedQTypes[q.Qtype]; notImpl {
Debug.Printf("[dns msgid %d] Unimplemented query type %s", r.MsgHdr.Id, dns.TypeToString[q.Qtype])
m := makeDNSNotImplResponse(r)
s.cache.Put(r, m, negLocalTTL, 0, now)
w.WriteMsg(m)
return
}

// catch queries that will not be responsed here...
if q.Qtype != dns.TypeA {
Debug.Printf("[dns msgid %d] Unexpected query type %s", r.MsgHdr.Id, dns.TypeToString[q.Qtype])
m := makeDNSFailResponse(r)
s.cache.Put(r, m, negLocalTTL, 0, now)
w.WriteMsg(m)
return
}

for _, lookup := range lookups {
if ip, err := lookup.LookupName(q.Name); err == nil {
m := makeAddressReply(r, &q, []net.IP{ip})
Expand Down Expand Up @@ -297,7 +306,16 @@ func (s *DNSServer) rdnsHandler(proto dnsProtocol) dns.HandlerFunc {
return
}

// catch unsupported queries
// catch queries that are not implemented
if _, notImpl := notImplementedQTypes[q.Qtype]; notImpl {
Debug.Printf("[dns msgid %d] Unimplemented query type %s", r.MsgHdr.Id, dns.TypeToString[q.Qtype])
m := makeDNSNotImplResponse(r)
s.cache.Put(r, m, negLocalTTL, 0, now)
w.WriteMsg(m)
return
}

// catch queries that will not be responsed here...
if q.Qtype != dns.TypePTR {
Warning.Printf("[dns msgid %d] Unexpected reverse query type %s: %+v",
r.MsgHdr.Id, dns.TypeToString[q.Qtype], q)
Expand Down
7 changes: 5 additions & 2 deletions nameserver/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,11 @@ func TestUDPDNSServer(t *testing.T) {

assertExchange(t, testRDNSfail, dns.TypePTR, 0, 0, dns.RcodeNameError)

// This should fail because we don't handle MX records
assertExchange(t, successTestName, dns.TypeMX, 0, 0, dns.RcodeNotImplemented)
// This should fail because we don't have information about MX records
assertExchange(t, successTestName, dns.TypeMX, 0, 0, dns.RcodeNameError)

// This should fail because we don't support SOA records
assertExchange(t, successTestName, dns.TypeANY, 0, 0, dns.RcodeNotImplemented)

// This non-local query for an MX record should succeed by being
// passed on to the fallback server
Expand Down

0 comments on commit a99ae96

Please sign in to comment.