Rename dynamic update functions (again)

* Use simple names and add zone Remove function for dynamic update use.
* Locking 'n stuff is all taken care off
* TSIG is working and the duplicate code is removed.
* readClient and writeClient are renamed read and write, because that is
  what they do.
This commit is contained in:
Miek Gieben 2012-10-16 10:41:20 +02:00
parent d8dc03bdba
commit 9ca924a069
4 changed files with 42 additions and 79 deletions

View File

@ -107,7 +107,7 @@ func TestUpdateLeaseTSIG(t *testing.T) {
rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1") rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1")
rrs := make([]RR, 1) rrs := make([]RR, 1)
rrs[0] = rr rrs[0] = rr
m.AddRR(rrs) m.Insert(rrs)
lease_rr := new(RR_OPT) lease_rr := new(RR_OPT)
lease_rr.Hdr.Name = "." lease_rr.Hdr.Name = "."

View File

@ -1,66 +1,2 @@
package dns package dns
// Find better solution // Find better solution
/*
import (
"net"
"testing"
)
func sendit(u *Msg) (r *Msg, e error) {
c := new(Client)
r, e = c.Exchange(u, "127.0.0.1:53")
return r, e
}
*/
/*
func TestUpdateAdd(t *testing.T) {
u := new(Msg)
u.SetUpdate("dyn.atoom.net.")
a := new(RR_A)
a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0}
a.A = net.IPv4(127, 0, 0, 1)
rr := make([]RR, 1)
rr[0] = a
u.RRsetAddRdata(rr)
t.Log(u.String())
r, e := sendit(u)
if e != nil {
t.Log("Failed: " + e.Error())
t.Fail()
}
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed: " + r.String())
t.Fail()
}
t.Log(r.String())
}
func TestUpdateDelete(t *testing.T) {
u := new(Msg)
u.SetUpdate("dyn.atoom.net.")
a := new(RR_A)
a.Hdr = RR_Header{"miek2.dyn.atoom.net.", TypeA, ClassINET, 1000, 0}
a.A = nil
rr := make([]RR, 1)
rr[0] = a
u.RRsetDelete(rr)
t.Log(u.String())
r, e := sendit(u)
if e != nil {
t.Log("Failed: " + e.Error())
t.Fail()
return
}
if r != nil && r.Rcode != RcodeSuccess {
t.Log("Failed: " + r.String())
t.Fail()
return
}
t.Log(r.String())
}
*/

View File

@ -17,7 +17,7 @@
// ANY rrset empty RRset exists (value indep) RRsetUsed // ANY rrset empty RRset exists (value indep) RRsetUsed
// NONE ANY empty Name is not in use NameNotUsed // NONE ANY empty Name is not in use NameNotUsed
// NONE rrset empty RRset does not exist RRsetNotUsed // NONE rrset empty RRset does not exist RRsetNotUsed
// zone rrset rr RRset exists (value dep) RRUsed // zone rrset rr RRset exists (value dep) Used
// //
// The prerequisite section can also be left empty. // The prerequisite section can also be left empty.
// If you have decided on the prerequisites you can tell what RRs should // If you have decided on the prerequisites you can tell what RRs should
@ -30,8 +30,8 @@
// --------------------------------------------------------------- // ---------------------------------------------------------------
// ANY ANY empty Delete all RRsets from name RemoveName // ANY ANY empty Delete all RRsets from name RemoveName
// ANY rrset empty Delete an RRset RemoveRRset // ANY rrset empty Delete an RRset RemoveRRset
// NONE rrset rr Delete an RR from RRset RemoveRR // NONE rrset rr Delete an RR from RRset Remove
// zone rrset rr Add to an RRset AddRR // zone rrset rr Add to an RRset Insert
// //
package dns package dns
@ -53,9 +53,9 @@ func (u *Msg) NameNotUsed(rr []RR) {
} }
} }
// RRUsed sets the RRs in the prereq section to // Used sets the RRs in the prereq section to
// "RRset exists (value dependent -- with rdata)" RRs. RFC 2136 section 2.4.2. // "RRset exists (value dependent -- with rdata)" RRs. RFC 2136 section 2.4.2.
func (u *Msg) RRUsed(rr []RR) { func (u *Msg) Used(rr []RR) {
if len(u.Question) == 0 { if len(u.Question) == 0 {
panic("dns: empty question section") panic("dns: empty question section")
} }
@ -90,8 +90,8 @@ func (u *Msg) RRsetNotUsed(rr []RR) {
} }
} }
// AddRR creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1. // Insert creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1.
func (u *Msg) AddRR(rr []RR) { func (u *Msg) Insert(rr []RR) {
if len(u.Question) == 0 { if len(u.Question) == 0 {
panic("dns: empty question section") panic("dns: empty question section")
} }
@ -121,8 +121,8 @@ func (u *Msg) RemoveName(rr []RR) {
} }
} }
// RRsetRemoveRR creates a dynamic update packet deletes RR from the RRSset, see RFC 2136 section 2.5.4 // Remove creates a dynamic update packet deletes RR from the RRSset, see RFC 2136 section 2.5.4
func (u *Msg) RemoveRR(rr []RR) { func (u *Msg) Remove(rr []RR) {
u.Ns = make([]RR, len(rr)) u.Ns = make([]RR, len(rr))
for i, r := range rr { for i, r := range rr {
u.Ns[i] = r u.Ns[i] = r

37
zone.go
View File

@ -269,16 +269,16 @@ func (z *Zone) Remove(r RR) error {
switch t := r.Header().Rrtype; t { switch t := r.Header().Rrtype; t {
case TypeRRSIG: case TypeRRSIG:
sigtype := r.(*RR_RRSIG).TypeCovered sigtype := r.(*RR_RRSIG).TypeCovered
for i, zr := range zd.Value.(*ZoneData).RR[sigtype] { for i, zr := range zd.Value.(*ZoneData).Signatures[sigtype] {
if r == zr { if r == zr {
zd.Value.(*ZoneData).RR[sigtype] = append(zd.Value.(*ZoneData).RR[sigtype][:i], zd.Value.(*ZoneData).RR[sigtype][i+1:]...) zd.Value.(*ZoneData).Signatures[sigtype] = append(zd.Value.(*ZoneData).Signatures[sigtype][:i], zd.Value.(*ZoneData).Signatures[sigtype][i+1:]...)
remove = true remove = true
} }
} }
if remove { if remove {
// If every Signature of the covering type is removed, removed the type from the map // If every Signature of the covering type is removed, removed the type from the map
if len(zd.Value.(*ZoneData).RR[sigtype]) == 0 { if len(zd.Value.(*ZoneData).Signatures[sigtype]) == 0 {
delete(zd.Value.(*ZoneData).RR, sigtype) delete(zd.Value.(*ZoneData).Signatures, sigtype)
} }
} }
default: default:
@ -314,7 +314,7 @@ func (z *Zone) Remove(r RR) error {
} }
// RemoveName removes all the RRs with ownername matching s from the zone. Typical use of this // RemoveName removes all the RRs with ownername matching s from the zone. Typical use of this
// function is when processing a RemoveName dynamic update packet. // method is when processing a RemoveName dynamic update packet.
func (z *Zone) RemoveName(s string) error { func (z *Zone) RemoveName(s string) error {
key := toRadixName(s) key := toRadixName(s)
z.Lock() z.Lock()
@ -329,6 +329,33 @@ func (z *Zone) RemoveName(s string) error {
return nil return nil
} }
// RemoveRRset removes all the RRs with the ownername matching s and the type matching t from the zone.
// Typical use of this method is when processing a RemoveRRset dynamic update packet.
func (z *Zone) RemoveRRset(s string, t uint16) error {
z.Lock()
zd, exact := z.Radix.Find(toRadixName(s))
if !exact {
defer z.Unlock()
return nil
}
z.Unlock()
zd.Value.(*ZoneData).mutex.Lock()
defer zd.Value.(*ZoneData).mutex.Unlock()
switch t {
case TypeRRSIG:
// empty all signature maps
for covert, _ := range zd.Value.(*ZoneData).Signatures {
delete(zd.Value.(*ZoneData).Signatures, covert)
}
default:
// empty all rr maps
for t, _ := range zd.Value.(*ZoneData).RR {
delete(zd.Value.(*ZoneData).RR, t)
}
}
return nil
}
// Find looks up the ownername s in the zone and returns the // Find looks up the ownername s in the zone and returns the
// data and true when an exact match is found. If an exact find isn't // data and true when an exact match is found. If an exact find isn't
// possible the first parent node with a non-nil Value is returned and // possible the first parent node with a non-nil Value is returned and