mirror of
https://github.com/miekg/dns.git
synced 2025-08-20 00:11:00 +02:00
Merge branch 'dev' of github.com:miekg/dns into dev
This commit is contained in:
commit
b5720f99ed
27
labels.go
27
labels.go
@ -38,6 +38,9 @@ func SplitLabels(s string) []string {
|
||||
//
|
||||
// www.miek.nl. and miek.nl. have two labels in common: miek and nl
|
||||
// www.miek.nl. and www.bla.nl. have one label in common: nl
|
||||
//
|
||||
// Domain s1 is a subdomain of s2 if
|
||||
// CompareLabels(s1, s2) == LenLabels(s1)
|
||||
func CompareLabels(s1, s2 string) (n int) {
|
||||
l1 := SplitLabels(s1)
|
||||
l2 := SplitLabels(s2)
|
||||
@ -58,3 +61,27 @@ func CompareLabels(s1, s2 string) (n int) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LenLabels returns the number of labels in a domain name
|
||||
func LenLabels(s string) (labels int) {
|
||||
if s == "." {
|
||||
return
|
||||
}
|
||||
last := byte('.')
|
||||
lastlast := byte('.')
|
||||
s = Fqdn(s) // Make fully qualified
|
||||
for i := 0; i < len(s); i++ {
|
||||
if s[i] == '.' {
|
||||
if last == '\\' {
|
||||
if lastlast != '\\' {
|
||||
// do nothing
|
||||
continue
|
||||
}
|
||||
}
|
||||
labels++
|
||||
}
|
||||
lastlast = last
|
||||
last = s[i]
|
||||
}
|
||||
return
|
||||
}
|
||||
|
18
zone.go
18
zone.go
@ -3,7 +3,7 @@ package dns
|
||||
// A structure for handling zone data
|
||||
|
||||
import (
|
||||
"github.com/sauerbraten/radix"
|
||||
"radix"
|
||||
)
|
||||
|
||||
// Zone represents a DNS zone.
|
||||
@ -34,6 +34,8 @@ func NewZone(origin string) *Zone {
|
||||
}
|
||||
|
||||
// Insert inserts an RR into the zone. Overwrites.
|
||||
// Out-of-zone data
|
||||
// Glue
|
||||
func (z *Zone) Insert(r RR) {
|
||||
zd := z.Radix.Find(r.Header().Name)
|
||||
if zd == nil {
|
||||
@ -46,19 +48,29 @@ func (z *Zone) Insert(r RR) {
|
||||
zd.Signatures = append(zd.Signatures, r.(*RR_RRSIG))
|
||||
default:
|
||||
zd.RR[t] = append(zd.RR[t], r)
|
||||
glueCheck(r)
|
||||
}
|
||||
z.Radix.Insert(r.Header().Name, zd)
|
||||
return
|
||||
}
|
||||
switch t := r.Header().Rrtype; t {
|
||||
case TypeRRSIG:
|
||||
zd.(*ZoneData).Signatures = append(zd.(*ZoneData).Signatures, r.(*RR_RRSIG))
|
||||
zd.Value.(*ZoneData).Signatures = append(zd.Value.(*ZoneData).Signatures, r.(*RR_RRSIG))
|
||||
default:
|
||||
zd.(*ZoneData).RR[t] = append(zd.(*ZoneData).RR[t], r)
|
||||
zd.Value.(*ZoneData).RR[t] = append(zd.Value.(*ZoneData).RR[t], r)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func glueCheck(r RR) {
|
||||
if n, ok := r.(*RR_NS); ok {
|
||||
// Check if glue would be needed
|
||||
if CompareLabels(r.Header().Name, n.Ns) == LenLabels(r.Header().Name) {
|
||||
println("glue needed?", r.Header().Name, n.Ns)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (z *Zone) Remove(r RR) {
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user