update.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. hdr := r.Header()
  33. hdr.Class = u.Question[0].Qclass
  34. hdr.Ttl = 0
  35. u.Answer = append(u.Answer, r)
  36. }
  37. }
  38. // RRsetUsed sets the RRs in the prereq section to
  39. // "RRset exists (value independent -- no rdata)" RRs. RFC 2136 section 2.4.1.
  40. func (u *Msg) RRsetUsed(rr []RR) {
  41. if u.Answer == nil {
  42. u.Answer = make([]RR, 0, len(rr))
  43. }
  44. for _, r := range rr {
  45. h := r.Header()
  46. u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassANY}})
  47. }
  48. }
  49. // RRsetNotUsed sets the RRs in the prereq section to
  50. // "RRset does not exist" RRs. RFC 2136 section 2.4.3.
  51. func (u *Msg) RRsetNotUsed(rr []RR) {
  52. if u.Answer == nil {
  53. u.Answer = make([]RR, 0, len(rr))
  54. }
  55. for _, r := range rr {
  56. h := r.Header()
  57. u.Answer = append(u.Answer, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassNONE}})
  58. }
  59. }
  60. // Insert creates a dynamic update packet that adds an complete RRset, see RFC 2136 section 2.5.1.
  61. func (u *Msg) Insert(rr []RR) {
  62. if len(u.Question) == 0 {
  63. panic("dns: empty question section")
  64. }
  65. if u.Ns == nil {
  66. u.Ns = make([]RR, 0, len(rr))
  67. }
  68. for _, r := range rr {
  69. r.Header().Class = u.Question[0].Qclass
  70. u.Ns = append(u.Ns, r)
  71. }
  72. }
  73. // RemoveRRset creates a dynamic update packet that deletes an RRset, see RFC 2136 section 2.5.2.
  74. func (u *Msg) RemoveRRset(rr []RR) {
  75. if u.Ns == nil {
  76. u.Ns = make([]RR, 0, len(rr))
  77. }
  78. for _, r := range rr {
  79. h := r.Header()
  80. u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: h.Name, Ttl: 0, Rrtype: h.Rrtype, Class: ClassANY}})
  81. }
  82. }
  83. // RemoveName creates a dynamic update packet that deletes all RRsets of a name, see RFC 2136 section 2.5.3
  84. func (u *Msg) RemoveName(rr []RR) {
  85. if u.Ns == nil {
  86. u.Ns = make([]RR, 0, len(rr))
  87. }
  88. for _, r := range rr {
  89. u.Ns = append(u.Ns, &ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}})
  90. }
  91. }
  92. // Remove creates a dynamic update packet deletes RR from a RRSset, see RFC 2136 section 2.5.4
  93. func (u *Msg) Remove(rr []RR) {
  94. if u.Ns == nil {
  95. u.Ns = make([]RR, 0, len(rr))
  96. }
  97. for _, r := range rr {
  98. h := r.Header()
  99. h.Class = ClassNONE
  100. h.Ttl = 0
  101. u.Ns = append(u.Ns, r)
  102. }
  103. }