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