Merge branch 'master' of github.com:miekg/dns

This commit is contained in:
Miek Gieben 2012-09-07 20:38:30 +02:00
commit 0351cc0ded
5 changed files with 32 additions and 32 deletions

View File

@ -13,11 +13,11 @@ const hexDigit = "0123456789abcdef"
// SetReply creates a reply packet from a request message.
func (dns *Msg) SetReply(request *Msg) *Msg {
dns.MsgHdr.Id = request.MsgHdr.Id
dns.MsgHdr.RecursionDesired = request.MsgHdr.RecursionDesired // Copy rd bit
dns.MsgHdr.Response = true
dns.MsgHdr.Opcode = OpcodeQuery
dns.MsgHdr.Rcode = RcodeSuccess
dns.Id = request.Id
dns.RecursionDesired = request.RecursionDesired // Copy rd bit
dns.Response = true
dns.Opcode = OpcodeQuery
dns.Rcode = RcodeSuccess
if len(request.Question) > 0 {
dns.Question = make([]Question, 1)
dns.Question[0] = request.Question[0]
@ -27,8 +27,8 @@ func (dns *Msg) SetReply(request *Msg) *Msg {
// SetQuestion creates a question packet.
func (dns *Msg) SetQuestion(z string, t uint16) *Msg {
dns.MsgHdr.Id = Id()
dns.MsgHdr.RecursionDesired = true
dns.Id = Id()
dns.RecursionDesired = true
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, t, ClassINET}
return dns
@ -36,9 +36,9 @@ func (dns *Msg) SetQuestion(z string, t uint16) *Msg {
// SetNotify creates a notify packet.
func (dns *Msg) SetNotify(z string) *Msg {
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Id = Id()
dns.Opcode = OpcodeNotify
dns.Authoritative = true
dns.Id = Id()
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, ClassINET}
return dns
@ -46,10 +46,10 @@ func (dns *Msg) SetNotify(z string) *Msg {
// SetRcode creates an error packet suitable for the request.
func (dns *Msg) SetRcode(request *Msg, rcode int) *Msg {
dns.MsgHdr.Rcode = rcode
dns.MsgHdr.Opcode = OpcodeQuery
dns.MsgHdr.Response = true
dns.MsgHdr.Id = request.MsgHdr.Id
dns.Rcode = rcode
dns.Opcode = OpcodeQuery
dns.Response = true
dns.Id = request.Id
// Note that this is actually a FORMERR
if len(request.Question) > 0 {
dns.Question = make([]Question, 1)
@ -60,20 +60,20 @@ func (dns *Msg) SetRcode(request *Msg, rcode int) *Msg {
// SetRcodeFormatError creates a packet with FormError set.
func (dns *Msg) SetRcodeFormatError(request *Msg) *Msg {
dns.MsgHdr.Rcode = RcodeFormatError
dns.MsgHdr.Opcode = OpcodeQuery
dns.MsgHdr.Response = true
dns.MsgHdr.Authoritative = false
dns.MsgHdr.Id = request.MsgHdr.Id
dns.Rcode = RcodeFormatError
dns.Opcode = OpcodeQuery
dns.Response = true
dns.Authoritative = false
dns.Id = request.Id
return dns
}
// SetUpdate makes the message a dynamic update packet. It
// sets the ZONE section to: z, TypeSOA, ClassINET.
func (dns *Msg) SetUpdate(z string) *Msg {
dns.MsgHdr.Id = Id()
dns.MsgHdr.Response = false
dns.MsgHdr.Opcode = OpcodeUpdate
dns.Id = Id()
dns.Response = false
dns.Opcode = OpcodeUpdate
dns.Compress = false // BIND9 cannot handle compression
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, ClassINET}
@ -82,7 +82,7 @@ func (dns *Msg) SetUpdate(z string) *Msg {
// SetIxfr creates dns msg suitable for requesting an ixfr.
func (dns *Msg) SetIxfr(z string, serial uint32) *Msg {
dns.MsgHdr.Id = Id()
dns.Id = Id()
dns.Question = make([]Question, 1)
dns.Ns = make([]RR, 1)
s := new(RR_SOA)
@ -95,7 +95,7 @@ func (dns *Msg) SetIxfr(z string, serial uint32) *Msg {
// SetAxfr creates dns msg suitable for requesting an axfr.
func (dns *Msg) SetAxfr(z string) *Msg {
dns.MsgHdr.Id = Id()
dns.Id = Id()
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeAXFR, ClassINET}
return dns
@ -110,7 +110,7 @@ func (dns *Msg) SetTsig(z, algo string, fudge, timesigned int64) *Msg {
t.Algorithm = algo
t.Fudge = 300
t.TimeSigned = uint64(timesigned)
t.OrigId = dns.MsgHdr.Id
t.OrigId = dns.Id
dns.Extra = append(dns.Extra, t)
return dns
}

4
dns.go
View File

@ -49,8 +49,8 @@
// The following is slightly more verbose, but more flexible:
//
// m1 := new(dns.Msg)
// m1.MsgHdr.Id = Id()
// m1.MsgHdr.RecursionDesired = true
// m1.Id = Id()
// m1.RecursionDesired = true
// m1.Question = make([]Question, 1)
// m1.Question[0] = dns.Question{"miek.nl.", dns.TypeMX, dns.ClassINET}
//

View File

@ -204,7 +204,7 @@ func (m *Msg) Nsec3Verify(q Question) (int, error) {
}
}
if !ncdenied {
if m.MsgHdr.Rcode == RcodeNameError {
if m.Rcode == RcodeNameError {
// For NXDOMAIN this is a problem
return 0, ErrDenialNc // add next closer name here
}
@ -222,7 +222,7 @@ func (m *Msg) Nsec3Verify(q Question) (int, error) {
return 0, ErrDenialSo
}
// The message headers claims something different!
if m.MsgHdr.Rcode != RcodeNameError {
if m.Rcode != RcodeNameError {
return 0, ErrDenialHdr
}
@ -255,7 +255,7 @@ NoData:
}
}
}
if m.MsgHdr.Rcode == RcodeNameError {
if m.Rcode == RcodeNameError {
return 0, ErrDenialHdr
}
return _NSEC3_NODATA, nil

View File

@ -191,7 +191,7 @@ func TsigGenerate(m *Msg, secret, requestMAC string, timersOnly bool) ([]byte, s
t.Fudge = rr.Fudge
t.TimeSigned = rr.TimeSigned
t.Algorithm = rr.Algorithm
t.OrigId = m.MsgHdr.Id
t.OrigId = m.Id
tbuf := make([]byte, t.Len())
if off, ok := PackRR(t, tbuf, 0, nil, false); ok {

2
xfr.go
View File

@ -180,7 +180,7 @@ func XfrSend(w ResponseWriter, q *Msg, c chan *XfrToken, e *error) error {
func axfrSend(w ResponseWriter, req *Msg, c chan *XfrToken, e *error) {
rep := new(Msg)
rep.SetReply(req)
rep.MsgHdr.Authoritative = true
rep.Authoritative = true
for x := range c {
// assume it fits