Add nsec3 stuff
This commit is contained in:
parent
709d11aa2c
commit
49ffb70c33
59
zone.go
59
zone.go
|
@ -16,13 +16,16 @@ import (
|
|||
// Zone represents a DNS zone. It's safe for concurrent use by
|
||||
// multilpe goroutines.
|
||||
type Zone struct {
|
||||
Origin string // Origin of the zone
|
||||
olabels []string // origin cut up in labels, just to speed up the isSubDomain method
|
||||
Wildcard int // Whenever we see a wildcard name, this is incremented
|
||||
expired bool // Slave zone is expired
|
||||
ModTime time.Time // When is the zone last modified
|
||||
Names map[string]*ZoneData // Zone data, indexed by name
|
||||
sortedNames []string // All names in the zone, but sorted (for nsec)
|
||||
Origin string // Origin of the zone
|
||||
olabels []string // origin cut up in labels, just to speed up the isSubDomain method
|
||||
Wildcard int // Whenever we see a wildcard name, this is incremented
|
||||
expired bool // Slave zone is expired
|
||||
Dnssec bool // This zone has signatures
|
||||
ModTime time.Time // When is the zone last modified
|
||||
Names map[string]*ZoneData // Zone data, indexed by name
|
||||
nextNames []string // All names in the zone, but sorted (for NSEC)
|
||||
next3Names []string // All hashed names in the zone, but sorted (for NSEC3)
|
||||
nsec3Param *NSEC3PARAM // The NSEC3 parameters for this zone (if applicable), when nil -> NSEC
|
||||
*sync.RWMutex
|
||||
}
|
||||
|
||||
|
@ -86,7 +89,7 @@ func NewZone(origin string) *Zone {
|
|||
z.Names = make(map[string]*ZoneData)
|
||||
z.RWMutex = new(sync.RWMutex)
|
||||
z.ModTime = time.Now().UTC()
|
||||
z.sortedNames = make([]string, 0)
|
||||
z.nextNames = make([]string, 0)
|
||||
return z
|
||||
}
|
||||
|
||||
|
@ -185,10 +188,10 @@ func (z *Zone) Insert(r RR) error {
|
|||
zd.RR[t] = append(zd.RR[t], r)
|
||||
}
|
||||
z.Names[r.Header().Name] = zd
|
||||
i := sort.SearchStrings(z.sortedNames, r.Header().Name)
|
||||
z.sortedNames = append(z.sortedNames, "")
|
||||
copy(z.sortedNames[i+1:], z.sortedNames[i:])
|
||||
z.sortedNames[i] = r.Header().Name
|
||||
i := sort.SearchStrings(z.nextNames, r.Header().Name)
|
||||
z.nextNames = append(z.nextNames, "")
|
||||
copy(z.nextNames[i+1:], z.nextNames[i:])
|
||||
z.nextNames[i] = r.Header().Name
|
||||
return nil
|
||||
}
|
||||
// Name already there
|
||||
|
@ -242,11 +245,11 @@ func (z *Zone) Remove(r RR) error {
|
|||
if len(zd.RR) == 0 && len(zd.Signatures) == 0 {
|
||||
// Entire node is empty, remove it from the Zone too
|
||||
delete(z.Names, r.Header().Name)
|
||||
i := sort.SearchStrings(z.sortedNames, r.Header().Name)
|
||||
i := sort.SearchStrings(z.nextNames, r.Header().Name)
|
||||
// we actually removed something if we are here, so i must be something sensible
|
||||
copy(z.sortedNames[i:], z.sortedNames[i+1:])
|
||||
z.sortedNames[len(z.sortedNames)-1] = ""
|
||||
z.sortedNames = z.sortedNames[:len(z.sortedNames)-1]
|
||||
copy(z.nextNames[i:], z.nextNames[i+1:])
|
||||
z.nextNames[len(z.nextNames)-1] = ""
|
||||
z.nextNames = z.nextNames[:len(z.nextNames)-1]
|
||||
if len(r.Header().Name) > 1 && r.Header().Name[0] == '*' && r.Header().Name[1] == '.' {
|
||||
z.Wildcard--
|
||||
if z.Wildcard < 0 {
|
||||
|
@ -268,10 +271,10 @@ func (z *Zone) RemoveName(s string) error {
|
|||
}
|
||||
z.ModTime = time.Now().UTC()
|
||||
delete(z.Names, s)
|
||||
i := sort.SearchStrings(z.sortedNames, s)
|
||||
copy(z.sortedNames[i:], z.sortedNames[i+1:])
|
||||
z.sortedNames[len(z.sortedNames)-1] = ""
|
||||
z.sortedNames = z.sortedNames[:len(z.sortedNames)-1]
|
||||
i := sort.SearchStrings(z.nextNames, s)
|
||||
copy(z.nextNames[i:], z.nextNames[i+1:])
|
||||
z.nextNames[len(z.nextNames)-1] = ""
|
||||
z.nextNames = z.nextNames[:len(z.nextNames)-1]
|
||||
if len(s) > 1 && s[0] == '*' && s[1] == '.' {
|
||||
z.Wildcard--
|
||||
if z.Wildcard < 0 {
|
||||
|
@ -306,11 +309,11 @@ func (z *Zone) RemoveRRset(s string, t uint16) error {
|
|||
if len(zd.RR) == 0 && len(zd.Signatures) == 0 {
|
||||
// Entire node is empty, remove it from the Zone too
|
||||
delete(z.Names, s)
|
||||
i := sort.SearchStrings(z.sortedNames, s)
|
||||
i := sort.SearchStrings(z.nextNames, s)
|
||||
// we actually removed something if we are here, so i must be something sensible
|
||||
copy(z.sortedNames[i:], z.sortedNames[i+1:])
|
||||
z.sortedNames[len(z.sortedNames)-1] = ""
|
||||
z.sortedNames = z.sortedNames[:len(z.sortedNames)-1]
|
||||
copy(z.nextNames[i:], z.nextNames[i+1:])
|
||||
z.nextNames[len(z.nextNames)-1] = ""
|
||||
z.nextNames = z.nextNames[:len(z.nextNames)-1]
|
||||
if len(s) > 1 && s[0] == '*' && s[1] == '.' {
|
||||
z.Wildcard--
|
||||
if z.Wildcard < 0 {
|
||||
|
@ -428,12 +431,12 @@ func signerRoutine(z *Zone, wg *sync.WaitGroup, keys map[*DNSKEY]PrivateKey, key
|
|||
name = node.RR[x][0].Header().Name
|
||||
break
|
||||
}
|
||||
i := sort.SearchStrings(z.sortedNames, name)
|
||||
if z.sortedNames[i] == name {
|
||||
if i+1 > len(z.sortedNames) {
|
||||
i := sort.SearchStrings(z.nextNames, name)
|
||||
if z.nextNames[i] == name {
|
||||
if i+1 > len(z.nextNames) {
|
||||
next = z.Origin
|
||||
} else {
|
||||
next = z.sortedNames[i+1]
|
||||
next = z.nextNames[i+1]
|
||||
}
|
||||
}
|
||||
e := node.Sign(next, keys, keytags, config)
|
||||
|
|
Loading…
Reference in New Issue