update.go 3.1 KB

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