More nameerror stuff

This commit is contained in:
Miek Gieben 2016-03-29 20:47:45 +01:00
parent b4242a7d5d
commit b67ecb3e55
2 changed files with 24 additions and 8 deletions

View file

@ -1,6 +1,8 @@
package file
import (
"fmt"
"github.com/miekg/coredns/middleware/file/tree"
"github.com/miekg/dns"
)
@ -35,6 +37,7 @@ func (z *Zone) Lookup(qname string, qtype uint16, do bool) ([]dns.RR, []dns.RR,
elem := z.Tree.Get(rr)
if elem == nil {
// wildcard lookup
return z.nameError(elem, rr, do)
}
@ -66,12 +69,16 @@ func (z *Zone) noData(elem *tree.Elem, do bool) ([]dns.RR, []dns.RR, []dns.RR, R
}
func (z *Zone) nameError(elem *tree.Elem, rr dns.RR, do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
ret := []dns.RR{}
if do {
ret := append([]dns.RR{z.SOA}, z.SIG...)
return nil, ret, nil, Success
ret = append(ret, z.SIG...)
// Now we need two NSEC, one to deny the wildcard and one to deny the name.
elem := z.Tree.Prev(rr)
fmt.Printf("%+v\n", elem.All())
elem = z.Tree.Prev(wildcard(rr))
fmt.Printf("%+v\n", elem.All())
}
// NSECs!
return nil, []dns.RR{z.SOA}, nil, NameError
return nil, ret, nil, NameError
}
func (z *Zone) lookupSOA(do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
@ -137,3 +144,12 @@ func signatureForSubType(rrs []dns.RR, subtype uint16) []dns.RR {
}
return sigs
}
// wildcard returns rr with the first label exchanged for a wildcard '*'.
func wildcard(rr dns.RR) dns.RR {
// root label, TODO(miek)
s := rr.Header().Name
i, _ := dns.NextLabel(s, 0)
rr.Header().Name = "*" + s[i:]
return rr
}

View file

@ -492,8 +492,8 @@ func (n *Node) max() *Node {
return n
}
// Floor returns the greatest value equal to or less than the rr according to Less().
func (t *Tree) Floor(rr dns.RR) *Elem {
// Prev returns the greatest value equal to or less than the rr according to Less().
func (t *Tree) Prev(rr dns.RR) *Elem {
if t.Root == nil {
return nil
}
@ -521,8 +521,8 @@ func (n *Node) floor(rr dns.RR) *Node {
return n
}
// Ceil returns the smallest value equal to or greater than the rr according to Less().
func (t *Tree) Ceil(rr dns.RR) *Elem {
// Next returns the smallest value equal to or greater than the rr according to Less().
func (t *Tree) Next(rr dns.RR) *Elem {
if t.Root == nil {
return nil
}