From 393719d659f2634e1558cd7b1bcb031b15845b5a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 16 Jul 2012 08:51:39 +0200 Subject: [PATCH 1/3] Add LenLabels function - no allocations --- labels.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/labels.go b/labels.go index aa43a303..ad190927 100644 --- a/labels.go +++ b/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 +} From 01846073875199cc5b7c20be18eae59f9eed2b03 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 16 Jul 2012 13:31:18 +0200 Subject: [PATCH 2/3] More radix stuff and think about glue detection --- zone.go | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/zone.go b/zone.go index 24bcbb76..f552e746 100644 --- a/zone.go +++ b/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. @@ -44,20 +44,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) } - // TODO(mg): Glue 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) { } From 46c5f66169828b04b88a6162ad75118cd22d2eb6 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 16 Jul 2012 19:11:04 +0200 Subject: [PATCH 3/3] more glue check stuf --- zone.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/zone.go b/zone.go index f552e746..7ce14e3d 100644 --- a/zone.go +++ b/zone.go @@ -32,6 +32,8 @@ func NewZone(name 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 {