More dyn update stuff

This commit is contained in:
Miek Gieben 2011-08-22 15:16:24 +02:00
parent 9fcbef5edc
commit 1ebb11deaf
1 changed files with 32 additions and 28 deletions

View File

@ -1,7 +1,5 @@
package dns
import ()
// Implements wrapper functions for dealing with dynamic update packets.
// Dynamic update packets are identical to normal DNS messages, but the
// names are redefined. See RFC 2136 for the details.
@ -27,6 +25,15 @@ func (u *Update) Additional() []RR {
return u.Msg.Extra
}
// NewUpdate creats a new DNS update packet.
func NewUpdate(zone string, class uint16) *Update {
u := new(Update)
u.MsgHdr.Opcode = OpcodeUpdate
u.Question = make([]Question, 1)
u.Question[0] = Question{zone, TypeSOA, class}
return u
}
// 3.2.4 - Table Of Metavalues Used In Prerequisite Section
//
// CLASS TYPE RDATA Meaning
@ -37,55 +44,52 @@ func (u *Update) Additional() []RR {
// NONE rrset empty RRset does not exist
// zone rrset rr RRset exists (value dependent)
// PrereqNameUsed sets the RRs in the prereq section to
// NameUsed sets the RRs in the prereq section to
// "Name is in use" RRs. RFC 2136 section 2.4.4.
func (u *Update) PrereqNameUsed(rr []RR) {
u.Msg.Answer = make([]RR, len(rr))
func (u *Update) NameUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
for i, r := range rr {
u.Msg.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}
u.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassANY}}
}
}
// PrereqNameNotUsed sets the RRs in the prereq section to
// NameNotUsed sets the RRs in the prereq section to
// "Name is in not use" RRs. RFC 2136 section 2.4.5.
func (u *Update) PrereqNameNotUsed(rr []RR) {
u.Msg.Answer = make([]RR, len(rr))
func (u *Update) NameNotUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
for i, r := range rr {
u.Msg.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassNONE}}
u.Answer[i] = &RR_ANY{Hdr: RR_Header{Name: r.Header().Name, Ttl: 0, Rrtype: TypeANY, Class: ClassNONE}}
}
}
// PrereqRRsetUsedFull sets the RRs in the prereq section to
// RRsetUsedFull sets the RRs in the prereq section to
// "RRset exists (value dependent -- with rdata)" RRs. RFC 2136 section 2.4.2.
func (u *Update) PrereqRRsetUsedFull(rr []RR) {
u.Msg.Answer = make([]RR, len(rr))
func (u *Update) RRsetUsedFull(rr []RR) {
u.Answer = make([]RR, len(rr))
for i, r := range rr {
u.Msg.Answer[i] = r
u.Msg.Answer[i].Header().Class = u.Msg.Question[0].Qclass // TODO crashes if question is zero
u.Answer[i] = r
u.Answer[i].Header().Class = u.Msg.Question[0].Qclass // TODO crashes if question is zero
}
}
// PrereqRRsetUsed sets the RRs in the prereq section to
// RRsetUsed sets the RRs in the prereq section to
// "RRset exists (value independent -- no rdata)" RRs. RFC 2136 section 2.4.1.
func (u *Update) PrereqRRsetUsed(rr []RR) {
u.Msg.Answer = make([]RR, len(rr))
func (u *Update) RRsetUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
for i, r := range rr {
u.Msg.Answer[i] = r
u.Msg.Answer[i].Header().Class = ClassANY
u.Answer[i] = r
u.Answer[i].Header().Class = ClassANY
/* rdata should be cleared */
}
}
// PrereqRRsetNotUsed sets the RRs in the prereq section to
// RRsetNotUsed sets the RRs in the prereq section to
// "RRset does not exist" RRs. RFC 2136 section 2.4.3.
func (u *Update) PrereqRRsetNotUsed(rr []RR) {
u.Msg.Answer = make([]RR, len(rr))
func (u *Update) RRsetNotUsed(rr []RR) {
u.Answer = make([]RR, len(rr))
for i, r := range rr {
u.Msg.Answer[i] = r
u.Msg.Answer[i].Header().Class = ClassNONE
u.Answer[i] = r
u.Answer[i].Header().Class = ClassNONE
/* rdata should be cleared */
}
}