Create qnamelist for nsec/nsec3 handling
This commit is contained in:
parent
e016536cdc
commit
05b7ac53dd
1
Makefile
1
Makefile
|
@ -22,6 +22,7 @@ GOFILES=\
|
|||
types.go\
|
||||
xfr.go\
|
||||
zone.go\
|
||||
qnamestring.go\
|
||||
zparse.go\
|
||||
|
||||
|
||||
|
|
|
@ -93,6 +93,9 @@ func handleQuery(w dns.ResponseWriter, req *dns.Msg) {
|
|||
m.Ns[0] = soa
|
||||
m.MsgHdr.Rcode = dns.RcodeNameError
|
||||
send(w, m)
|
||||
// Lookup the previous name in the Nxt list for this zone
|
||||
// and insert the nsec/nsec3 from that. Also give the nsec
|
||||
// that proofs there is no wildcard
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -175,6 +175,6 @@ func TestZoneParsing(t *testing.T) {
|
|||
t.Fail()
|
||||
}
|
||||
delta := time.Nanoseconds() - start
|
||||
t.Logf("%v", z.Nxt)
|
||||
t.Logf("%s", z.Nxt)
|
||||
t.Logf("%d RRs parsed in %.2f s (%.2f RR/s)", z.Len(), float32(delta)/1e9, float32(z.Len())/(float32(delta)/1e9))
|
||||
}
|
||||
|
|
31
zone.go
31
zone.go
|
@ -7,7 +7,6 @@ package dns
|
|||
import (
|
||||
"os"
|
||||
"sort"
|
||||
"container/vector"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -36,15 +35,15 @@ func NewZRRset() *ZRRset {
|
|||
// Zone implements the concept of RFC 1035 master zone files.
|
||||
// This will be converted to some kind of tree structure
|
||||
type Zone struct {
|
||||
Zone map[string]map[int]*ZRRset // the contents of the zone
|
||||
Nxt *vector.StringVector // sorted list of owernames in the zone
|
||||
Zone map[string]map[int]*ZRRset // the contents of the zone
|
||||
Nxt *QnameString // sorted list of owernames in the zone
|
||||
}
|
||||
|
||||
// NewZone returns a new *Zone
|
||||
func NewZone() *Zone {
|
||||
z := new(Zone)
|
||||
z.Zone = make(map[string]map[int]*ZRRset)
|
||||
z.Nxt = new(vector.StringVector)
|
||||
z := new(Zone)
|
||||
z.Zone = make(map[string]map[int]*ZRRset)
|
||||
z.Nxt = NewQnameString()
|
||||
return z
|
||||
}
|
||||
|
||||
|
@ -109,8 +108,8 @@ func (z *Zone) PushRR(r RR) {
|
|||
if s == nil {
|
||||
s = NewZRRset()
|
||||
}
|
||||
// Add the sorted ownernames list
|
||||
SortInsert(z.Nxt, r.Header().Name)
|
||||
// Add to the sorted ownernames list
|
||||
SortInsert(z.Nxt, r.Header().Name)
|
||||
|
||||
switch r.Header().Rrtype {
|
||||
case TypeRRSIG:
|
||||
|
@ -188,10 +187,9 @@ func intval(c, t uint16) int {
|
|||
|
||||
// SortInsert insert the string s in the already sorted
|
||||
// vector p. If s is already present it is not inserted again.
|
||||
func SortInsert(p *vector.StringVector, s string) {
|
||||
sa := sort.StringArray(*p)
|
||||
i := sa.Search(s)
|
||||
if i < p.Len() && p.At(i) == s {
|
||||
func SortInsert(p *QnameString, s string) {
|
||||
i := sort.Search(len(*p), func(i int) bool { return (*p)[i] >= s })
|
||||
if i < len(*p) && (*p)[i] == s {
|
||||
// element already there
|
||||
return
|
||||
}
|
||||
|
@ -200,15 +198,14 @@ func SortInsert(p *vector.StringVector, s string) {
|
|||
|
||||
// Search searches the sorted vector p using binary search. If
|
||||
// the element s can not be found, the previous element is returned.
|
||||
func SortSearch(p *vector.StringVector, s string) string {
|
||||
sa := sort.StringArray(*p)
|
||||
i := sa.Search(s)
|
||||
func SortSearch(p *QnameString, s string) string {
|
||||
i := sort.Search(len(*p), func(i int) bool { return (*p)[i] >= s })
|
||||
// with zones there must always be one before
|
||||
if p.At(i) == s {
|
||||
if (*p)[i] == s {
|
||||
return s
|
||||
}
|
||||
if i > 0 {
|
||||
i--
|
||||
}
|
||||
return p.At(i)
|
||||
return (*p)[i]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue