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 package file
import ( import (
"fmt"
"github.com/miekg/coredns/middleware/file/tree" "github.com/miekg/coredns/middleware/file/tree"
"github.com/miekg/dns" "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) elem := z.Tree.Get(rr)
if elem == nil { if elem == nil {
// wildcard lookup
return z.nameError(elem, rr, do) 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) { func (z *Zone) nameError(elem *tree.Elem, rr dns.RR, do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
ret := []dns.RR{}
if do { if do {
ret := append([]dns.RR{z.SOA}, z.SIG...) ret = append(ret, z.SIG...)
return nil, ret, nil, Success // 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, ret, nil, NameError
return nil, []dns.RR{z.SOA}, nil, NameError
} }
func (z *Zone) lookupSOA(do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) { 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 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 return n
} }
// Floor returns the greatest value equal to or less than the rr according to Less(). // Prev returns the greatest value equal to or less than the rr according to Less().
func (t *Tree) Floor(rr dns.RR) *Elem { func (t *Tree) Prev(rr dns.RR) *Elem {
if t.Root == nil { if t.Root == nil {
return nil return nil
} }
@ -521,8 +521,8 @@ func (n *Node) floor(rr dns.RR) *Node {
return n return n
} }
// Ceil returns the smallest value equal to or greater than the rr according to Less(). // Next returns the smallest value equal to or greater than the rr according to Less().
func (t *Tree) Ceil(rr dns.RR) *Elem { func (t *Tree) Next(rr dns.RR) *Elem {
if t.Root == nil { if t.Root == nil {
return nil return nil
} }