aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--middleware/file/lookup.go25
-rw-r--r--middleware/file/tree/tree.go8
2 files changed, 25 insertions, 8 deletions
diff --git a/middleware/file/lookup.go b/middleware/file/lookup.go
index 34fb0252c..8ca652918 100644
--- a/middleware/file/lookup.go
+++ b/middleware/file/lookup.go
@@ -1,6 +1,8 @@
package file
import (
+ "fmt"
+
"github.com/miekg/coredns/middleware/file/tree"
"github.com/miekg/dns"
)
@@ -34,6 +36,7 @@ func (z *Zone) Lookup(qname string, qtype uint16, do bool) ([]dns.RR, []dns.RR,
rr.Header().Name = qname
elem := z.Tree.Get(rr)
if elem == nil {
+ // wildcard lookup
return z.nameError(elem, rr, do)
}
@@ -64,12 +67,17 @@ 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, Success
+
+ return nil, ret, nil, Success
}
func (z *Zone) lookupSOA(do bool) ([]dns.RR, []dns.RR, []dns.RR, Result) {
@@ -136,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
+}
diff --git a/middleware/file/tree/tree.go b/middleware/file/tree/tree.go
index 7f51b89f0..342bcefa8 100644
--- a/middleware/file/tree/tree.go
+++ b/middleware/file/tree/tree.go
@@ -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
}