update.go: make RemoveRRset as dumb as the rest.
The RemoveRRset method was the only one that had a check for RRsets. While adding multiple identical RRs is an error, there should be now check for that at this level.
This commit is contained in:
parent
a07be6b2c1
commit
f5bc1323a1
15
update.go
15
update.go
|
@ -104,18 +104,9 @@ func (u *Msg) Insert(rr []RR) {
|
||||||
|
|
||||||
// RemoveRRset creates a dynamic update packet that deletes an RRset, see RFC 2136 section 2.5.2.
|
// RemoveRRset creates a dynamic update packet that deletes an RRset, see RFC 2136 section 2.5.2.
|
||||||
func (u *Msg) RemoveRRset(rr []RR) {
|
func (u *Msg) RemoveRRset(rr []RR) {
|
||||||
m := make(map[RR_Header]struct{})
|
u.Ns = make([]RR, len(rr))
|
||||||
u.Ns = make([]RR, 0, len(rr))
|
for i, r := range rr {
|
||||||
for _, r := range rr {
|
u.Ns[i] = &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassANY}}
|
||||||
h := *r.Header().copyHeader()
|
|
||||||
h.Class = ClassANY
|
|
||||||
h.Ttl = 0
|
|
||||||
h.Rdlength = 0
|
|
||||||
if _, ok := m[h]; ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
m[h] = struct{}{}
|
|
||||||
u.Ns = append(u.Ns, &ANY{h})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,20 +86,4 @@ func TestRemoveRRset(t *testing.T) {
|
||||||
t.Logf("Actual msg:\n%v", tmp)
|
t.Logf("Actual msg:\n%v", tmp)
|
||||||
t.Fail()
|
t.Fail()
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Ns = nil
|
|
||||||
m.RemoveRRset([]RR{rr, rr})
|
|
||||||
actual, err = m.Pack()
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("Error packing actual msg: %v", err)
|
|
||||||
}
|
|
||||||
if !bytes.Equal(actual, expect) {
|
|
||||||
tmp := new(Msg)
|
|
||||||
if err := tmp.Unpack(actual); err != nil {
|
|
||||||
t.Fatalf("Error unpacking actual msg: %v", err)
|
|
||||||
}
|
|
||||||
t.Logf("Expected msg:\n%v", expectstr)
|
|
||||||
t.Logf("Actual msg:\n%v", tmp)
|
|
||||||
t.Fail()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue