dns/update.go

182 lines
6.4 KiB
Go
Raw Normal View History

2011-09-11 18:47:25 +00:00
// DYNAMIC UPDATES
//
// Dynamic updates reuses the DNS message format, but renames the three of
// the sections. Question is Zone, Answer is Prerequisite, Authority is
// Update, only the Additional is not renamed. See RFC 2136 for the gory details.
//
// You can set a rather complex set of rules for the existence of absence of
// certain resource records or names in a zone to specify if resource records
// should be added or removed. The table from RFC 2136 supplemented with the Go
// DNS function shows which functions exist to specify the prerequisites.
//
// 3.2.4 - Table Of Metavalues Used In Prerequisite Section
//
// CLASS TYPE RDATA Meaning Function
// ----------------------------------------------------------------------------
// ANY ANY empty Name is in use NameUsed
// ANY rrset empty RRset exists (value independent) RRsetUsedNoRdata
// NONE ANY empty Name is not in use NameNotUsed
// NONE rrset empty RRset does not exist RRsetNotUsed
// zone rrset rr RRset exists (value dependent) RRsetUsedRdata
//
// The prerequisite section can also be left empty.
// If you have decided an the prerequisites you can tell what RRs should
// be added or deleted. The next table shows the options you have and
// what function to call.
// 3.4.2.6 - Table Of Metavalues Used In Update Section
//
// CLASS TYPE RDATA Meaning Function
// -------------------------------------------------------------------------
// ANY ANY empty Delete all RRsets from a name NameDelete
// ANY rrset empty Delete an RRset RRsetDelete
// NONE rrset rr Delete an RR from an RRset RRsetDeleteRR
// zone rrset rr Add to an RRset RRsetAddRdata
//
2011-08-22 12:51:10 +00:00
package dns
type Update struct{ Msg }
func (u *Update) Zone() []Question {
return u.Msg.Question
}
func (u *Update) Prereq() []RR {
return u.Msg.Answer
}
func (u *Update) Update() []RR {
return u.Msg.Ns
}
func (u *Update) Additional() []RR {
return u.Msg.Extra
}
2011-08-22 13:16:24 +00:00
// NewUpdate creats a new DNS update packet.
func NewUpdate(zone string, class uint16) *Update {
2011-08-22 13:43:52 +00:00
u := new(Update)
u.MsgHdr.Opcode = OpcodeUpdate
u.Question = make([]Question, 1)
u.Question[0] = Question{zone, TypeSOA, class}
return u
2011-08-22 13:16:24 +00:00
}
2011-09-11 18:47:25 +00:00
// The table from RFC 2136 supplemented with the Go DNS function.
//
2011-08-22 12:51:10 +00:00
// 3.2.4 - Table Of Metavalues Used In Prerequisite Section
//
2011-09-11 18:47:25 +00:00
// CLASS TYPE RDATA Meaning Function
// ----------------------------------------------------------------------
// ANY ANY empty Name is in use NameUsed
// ANY rrset empty RRset exists (value independent) RRsetUsedNoRdata
// NONE ANY empty Name is not in use NameNotUsed
// NONE rrset empty RRset does not exist RRsetNotUsed
// zone rrset rr RRset exists (value dependent) RRsetUsedRdata
2011-08-22 12:51:10 +00:00
2011-08-22 13:16:24 +00:00
// NameUsed sets the RRs in the prereq section to
2011-08-22 12:51:10 +00:00
// "Name is in use" RRs. RFC 2136 section 2.4.4.
2011-08-22 13:16:24 +00:00
func (u *Update) NameUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
2011-08-22 12:51:10 +00:00
for i, r := range rr {
2011-08-22 13:16:24 +00:00
u.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}
2011-08-22 12:51:10 +00:00
}
}
2011-08-22 13:16:24 +00:00
// NameNotUsed sets the RRs in the prereq section to
2011-08-22 12:51:10 +00:00
// "Name is in not use" RRs. RFC 2136 section 2.4.5.
2011-08-22 13:16:24 +00:00
func (u *Update) NameNotUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
2011-08-22 12:51:10 +00:00
for i, r := range rr {
2011-08-22 13:43:52 +00:00
u.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassNONE}}
2011-08-22 12:51:10 +00:00
}
}
2011-09-11 18:47:25 +00:00
// RRsetUsedRdata sets the RRs in the prereq section to
2011-08-22 12:51:10 +00:00
// "RRset exists (value dependent -- with rdata)" RRs. RFC 2136 section 2.4.2.
2011-09-11 18:47:25 +00:00
func (u *Update) RRsetUsedRdata(rr []RR) {
2011-09-08 17:41:26 +00:00
if len(u.Msg.Question) == 0 {
panic("empty question section")
}
2011-08-22 13:16:24 +00:00
u.Answer = make([]RR, len(rr))
2011-08-22 12:51:10 +00:00
for i, r := range rr {
2011-08-22 13:43:52 +00:00
u.Answer[i] = r
u.Answer[i].Header().Class = u.Msg.Question[0].Qclass
2011-08-22 12:51:10 +00:00
}
}
2011-09-11 18:47:25 +00:00
// RRsetUsedNoRdata sets the RRs in the prereq section to
2011-08-22 12:51:10 +00:00
// "RRset exists (value independent -- no rdata)" RRs. RFC 2136 section 2.4.1.
2011-09-11 18:47:25 +00:00
func (u *Update) RRsetUsedNoRdata(rr []RR) {
2011-08-22 13:16:24 +00:00
u.Answer = make([]RR, len(rr))
2011-08-22 12:51:10 +00:00
for i, r := range rr {
2011-08-22 13:43:52 +00:00
u.Answer[i] = r
u.Answer[i].Header().Class = ClassANY
u.Answer[i].Header().Ttl = 0
u.Answer[i].Header().Rdlength = 0
2011-08-22 12:51:10 +00:00
}
}
2011-08-22 13:16:24 +00:00
// RRsetNotUsed sets the RRs in the prereq section to
2011-08-22 12:51:10 +00:00
// "RRset does not exist" RRs. RFC 2136 section 2.4.3.
2011-08-22 13:16:24 +00:00
func (u *Update) RRsetNotUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
2011-08-22 12:51:10 +00:00
for i, r := range rr {
2011-08-22 13:43:52 +00:00
u.Answer[i] = r
u.Answer[i].Header().Class = ClassNONE
u.Answer[i].Header().Rdlength = 0
u.Answer[i].Header().Ttl = 0
2011-08-22 12:51:10 +00:00
}
}
2011-08-22 13:35:52 +00:00
2011-09-11 18:47:25 +00:00
// The table from RFC 2136 supplemented with the Go DNS function.
//
2011-08-22 13:35:52 +00:00
// 3.4.2.6 - Table Of Metavalues Used In Update Section
//
2011-09-11 18:47:25 +00:00
// CLASS TYPE RDATA Meaning Function
// --------------------------------------------------------------------------
// ANY ANY empty Delete all RRsets from a name NameDelete
// ANY rrset empty Delete an RRset RRsetDelete
// NONE rrset rr Delete an RR from an RRset RRsetDeleteRR
// zone rrset rr Add to an RRset RRsetAddRdata
// RRsetAddRdata adds an complete RRset, see RFC 2136 section 2.5.1
func (u *Update) RRsetAddRdata(rr []RR) {
2011-09-08 17:41:26 +00:00
if len(u.Msg.Question) == 0 {
panic("empty question section")
}
2011-08-22 13:43:52 +00:00
u.Ns = make([]RR, len(rr))
for i, r := range rr {
u.Ns[i] = r
u.Ns[i].Header().Class = u.Msg.Question[0].Qclass
2011-08-22 13:43:52 +00:00
}
2011-08-22 13:35:52 +00:00
}
2011-09-11 18:47:25 +00:00
// RRsetDelete deletes an RRset, see RFC 2136 section 2.5.2
2011-08-22 13:43:52 +00:00
func (u *Update) RRsetDelete(rr []RR) {
u.Ns = make([]RR, len(rr))
for i, r := range rr {
u.Ns[i] = r
u.Ns[i].Header().Class = ClassANY
u.Ns[i].Header().Rdlength = 0
u.Ns[i].Header().Ttl = 0
}
2011-08-22 13:35:52 +00:00
}
2011-08-22 13:43:52 +00:00
// NameDelete deletes all RRsets of a name, see RFC 2136 section 2.5.3
func (u *Update) NameDelete(rr []RR) {
u.Ns = make([]RR, len(rr))
for i, r := range rr {
u.Ns[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}
}
}
// RRsetDeleteRR deletes RR from the RRSset, see RFC 2136 section 2.5.4
func (u *Update) RRsetDeleteRR(rr []RR) {
u.Ns = make([]RR, len(rr))
for i, r := range rr {
u.Ns[i] = r
u.Ns[i].Header().Class = ClassNONE
u.Ns[i].Header().Ttl = 0
2011-08-22 13:43:52 +00:00
}
2011-08-22 13:35:52 +00:00
}