update.go 2.8 KB

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