diff options
author | 2016-11-05 14:39:49 +0000 | |
---|---|---|
committer | 2016-11-05 14:39:49 +0000 | |
commit | 2cca527d9f17fd1595366545c47630bf35591873 (patch) | |
tree | d9cda7808a085db5705bdbbffc7bc8e36824356e /middleware/file/closest.go | |
parent | d6902cd7a1e70149268925453289681536b88195 (diff) | |
download | coredns-2cca527d9f17fd1595366545c47630bf35591873.tar.gz coredns-2cca527d9f17fd1595366545c47630bf35591873.tar.zst coredns-2cca527d9f17fd1595366545c47630bf35591873.zip |
middleware/file: fix delegations (#376)
Fix the delegation handling in the *file* and *dnssec* middleware.
Refactor tests a bit and show that they are failling.
Add a Tree printer, cleanups and tests.
Fix wildcard test - should get no answer from empty-non-terminal
Diffstat (limited to 'middleware/file/closest.go')
-rw-r--r-- | middleware/file/closest.go | 62 |
1 files changed, 10 insertions, 52 deletions
diff --git a/middleware/file/closest.go b/middleware/file/closest.go index 741327fde..2ee14e6d8 100644 --- a/middleware/file/closest.go +++ b/middleware/file/closest.go @@ -1,66 +1,24 @@ package file -import "github.com/miekg/dns" +import ( + "github.com/miekg/coredns/middleware/file/tree" + + "github.com/miekg/dns" +) // ClosestEncloser returns the closest encloser for rr. -func (z *Zone) ClosestEncloser(qname string, qtype uint16) string { - // tree/tree.go does not store a parent *Node pointer, so we can't - // just follow up the tree. TODO(miek): fix. +func (z *Zone) ClosestEncloser(qname string) (*tree.Elem, bool) { + offset, end := dns.NextLabel(qname, 0) for !end { - elem, _ := z.Tree.Search(qname, qtype) + elem, _ := z.Tree.Search(qname) if elem != nil { - return elem.Name() + return elem, true } qname = qname[offset:] offset, end = dns.NextLabel(qname, offset) } - return z.Apex.SOA.Header().Name -} - -// nameErrorProof finds the closest encloser and return an NSEC that proofs -// the wildcard does not exist and an NSEC that proofs the name does no exist. -func (z *Zone) nameErrorProof(qname string, qtype uint16) []dns.RR { - elem := z.Tree.Prev(qname) - if elem == nil { - return nil - } - nsec := z.lookupNSEC(elem, true) - nsecIndex := 0 - for i := 0; i < len(nsec); i++ { - if nsec[i].Header().Rrtype == dns.TypeNSEC { - nsecIndex = i - break - } - } - - // We do this lookup twice, once for wildcard and once for the name proof. TODO(miek): fix - ce := z.ClosestEncloser(qname, qtype) - elem = z.Tree.Prev("*." + ce) - if elem == nil { - // Root? - return nil - } - nsec1 := z.lookupNSEC(elem, true) - nsec1Index := 0 - for i := 0; i < len(nsec1); i++ { - if nsec1[i].Header().Rrtype == dns.TypeNSEC { - nsec1Index = i - break - } - } - - if len(nsec) == 0 || len(nsec1) == 0 { - return nsec - } - - // Check for duplicate NSEC. - if nsec[nsecIndex].Header().Name == nsec1[nsec1Index].Header().Name && - nsec[nsecIndex].(*dns.NSEC).NextDomain == nsec1[nsec1Index].(*dns.NSEC).NextDomain { - return nsec - } - - return append(nsec, nsec1...) + return z.Tree.Search(z.origin) } |