diff --git a/client_test.go b/client_test.go index c8dc8f3e..739c27c1 100644 --- a/client_test.go +++ b/client_test.go @@ -107,7 +107,7 @@ func TestUpdateLeaseTSIG(t *testing.T) { rr, _ := NewRR("t.local.ip6.io. 30 A 127.0.0.1") rrs := make([]RR, 1) rrs[0] = rr - m.AddRR(rrs) + m.Insert(rrs) lease_rr := new(RR_OPT) lease_rr.Hdr.Name = "." diff --git a/dyn_test.go b/dyn_test.go index 8620ac4d..1bfa4caa 100644 --- a/dyn_test.go +++ b/dyn_test.go @@ -1,66 +1,2 @@ package dns - // 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()) -} -*/ diff --git a/update.go b/update.go index 61d91dee..1b989691 100644 --- a/update.go +++ b/update.go @@ -17,7 +17,7 @@ // ANY rrset empty RRset exists (value indep) RRsetUsed // NONE ANY empty Name is not in use NameNotUsed // 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. // 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 rrset empty Delete an RRset RemoveRRset -// NONE rrset rr Delete an RR from RRset RemoveRR -// zone rrset rr Add to an RRset AddRR +// NONE rrset rr Delete an RR from RRset Remove +// zone rrset rr Add to an RRset Insert // 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. -func (u *Msg) RRUsed(rr []RR) { +func (u *Msg) Used(rr []RR) { if len(u.Question) == 0 { 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. -func (u *Msg) AddRR(rr []RR) { +// Insert creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1. +func (u *Msg) Insert(rr []RR) { if len(u.Question) == 0 { 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 -func (u *Msg) RemoveRR(rr []RR) { +// Remove creates a dynamic update packet deletes RR from the RRSset, see RFC 2136 section 2.5.4 +func (u *Msg) Remove(rr []RR) { u.Ns = make([]RR, len(rr)) for i, r := range rr { u.Ns[i] = r diff --git a/zone.go b/zone.go index c694ba67..ecfea35e 100644 --- a/zone.go +++ b/zone.go @@ -269,16 +269,16 @@ func (z *Zone) Remove(r RR) error { switch t := r.Header().Rrtype; t { case TypeRRSIG: 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 { - 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 } } if remove { // If every Signature of the covering type is removed, removed the type from the map - if len(zd.Value.(*ZoneData).RR[sigtype]) == 0 { - delete(zd.Value.(*ZoneData).RR, sigtype) + if len(zd.Value.(*ZoneData).Signatures[sigtype]) == 0 { + delete(zd.Value.(*ZoneData).Signatures, sigtype) } } 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 -// 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 { key := toRadixName(s) z.Lock() @@ -329,6 +329,33 @@ func (z *Zone) RemoveName(s string) error { 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 // 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