1package dns 2 3// NameUsed sets the RRs in the prereq section to 4// "Name is in use" RRs. RFC 2136 section 2.4.4. 5func (u *Msg) NameUsed(rr []RR) { 6 if u.Answer == nil { 7 u.Answer = make([]RR, 0, len(rr)) 8 } 9 for _, r := range rr { 10 u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}) 11 } 12} 13 14// NameNotUsed sets the RRs in the prereq section to 15// "Name is in not use" RRs. RFC 2136 section 2.4.5. 16func (u *Msg) NameNotUsed(rr []RR) { 17 if u.Answer == nil { 18 u.Answer = make([]RR, 0, len(rr)) 19 } 20 for _, r := range rr { 21 u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassNONE}}) 22 } 23} 24 25// Used sets the RRs in the prereq section to 26// "RRset exists (value dependent -- with rdata)" RRs. RFC 2136 section 2.4.2. 27func (u *Msg) Used(rr []RR) { 28 if len(u.Question) == 0 { 29 panic("dns: empty question section") 30 } 31 if u.Answer == nil { 32 u.Answer = make([]RR, 0, len(rr)) 33 } 34 for _, r := range rr { 35 r.Header().Class = u.Question[0].Qclass 36 u.Answer = append(u.Answer, r) 37 } 38} 39 40// RRsetUsed sets the RRs in the prereq section to 41// "RRset exists (value independent -- no rdata)" RRs. RFC 2136 section 2.4.1. 42func (u *Msg) RRsetUsed(rr []RR) { 43 if u.Answer == nil { 44 u.Answer = make([]RR, 0, len(rr)) 45 } 46 for _, r := range rr { 47 u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassANY}}) 48 } 49} 50 51// RRsetNotUsed sets the RRs in the prereq section to 52// "RRset does not exist" RRs. RFC 2136 section 2.4.3. 53func (u *Msg) RRsetNotUsed(rr []RR) { 54 if u.Answer == nil { 55 u.Answer = make([]RR, 0, len(rr)) 56 } 57 for _, r := range rr { 58 u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassNONE}}) 59 } 60} 61 62// Insert creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1. 63func (u *Msg) Insert(rr []RR) { 64 if len(u.Question) == 0 { 65 panic("dns: empty question section") 66 } 67 if u.Ns == nil { 68 u.Ns = make([]RR, 0, len(rr)) 69 } 70 for _, r := range rr { 71 r.Header().Class = u.Question[0].Qclass 72 u.Ns = append(u.Ns, r) 73 } 74} 75 76// RemoveRRset creates a dynamic update packet that deletes an RRset, see RFC 2136 section 2.5.2. 77func (u *Msg) RemoveRRset(rr []RR) { 78 if u.Ns == nil { 79 u.Ns = make([]RR, 0, len(rr)) 80 } 81 for _, r := range rr { 82 u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: r.Header().Rrtype, Class: ClassANY}}) 83 } 84} 85 86// RemoveName creates a dynamic update packet that deletes all RRsets of a name, see RFC 2136 section 2.5.3 87func (u *Msg) RemoveName(rr []RR) { 88 if u.Ns == nil { 89 u.Ns = make([]RR, 0, len(rr)) 90 } 91 for _, r := range rr { 92 u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}) 93 } 94} 95 96// Remove creates a dynamic update packet deletes RR from a RRSset, see RFC 2136 section 2.5.4 97func (u *Msg) Remove(rr []RR) { 98 if u.Ns == nil { 99 u.Ns = make([]RR, 0, len(rr)) 100 } 101 for _, r := range rr { 102 r.Header().Class = ClassNONE 103 r.Header().Ttl = 0 104 u.Ns = append(u.Ns, r) 105 } 106} 107