dns/defaults.go

114 lines
2.9 KiB
Go
Raw Normal View History

2011-03-16 22:19:15 +11:00
package dns
// Everything is assumed in the ClassINET class. If
// you need other classes you are on your own.
2011-03-23 06:12:36 +11:00
2011-03-25 00:29:23 +11:00
// Create a reply packet from a request message.
2011-03-23 19:50:38 +11:00
func (dns *Msg) SetReply(request *Msg) {
2011-03-24 19:24:24 +11:00
dns.MsgHdr.Id = request.MsgHdr.Id
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Response = true
dns.MsgHdr.Opcode = OpcodeQuery
dns.MsgHdr.Rcode = RcodeSuccess
dns.Question = make([]Question, 1)
dns.Question[0] = request.Question[0]
2011-03-22 08:53:15 +11:00
}
2011-06-14 16:32:03 +10:00
// Create a question packet.
2011-04-15 06:22:24 +10:00
func (dns *Msg) SetQuestion(z string, t uint16) {
dns.MsgHdr.Id = Id()
dns.MsgHdr.RecursionDesired = true
2011-04-15 06:22:24 +10:00
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, t, ClassINET}
}
2011-03-17 03:28:35 +11:00
// Create a notify packet.
2011-03-31 02:50:07 +11:00
func (dns *Msg) SetNotify(z string) {
2011-03-16 22:19:15 +11:00
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Id = Id()
dns.Question = make([]Question, 1)
2011-03-31 02:50:07 +11:00
dns.Question[0] = Question{z, TypeSOA, ClassINET}
2011-03-16 22:19:15 +11:00
}
2011-03-25 20:16:55 +11:00
// Is the message a dynamic update packet?
func (dns *Msg) IsUpdate() (ok bool) {
if len(dns.Question) == 0 {
return false
}
ok = dns.MsgHdr.Opcode == OpcodeUpdate
ok = ok && dns.Question[0].Qtype == TypeSOA
return
2011-03-25 20:16:55 +11:00
}
2011-03-25 00:29:23 +11:00
// Is the message a valid notify packet?
2011-03-23 19:50:38 +11:00
func (dns *Msg) IsNotify() (ok bool) {
2011-03-16 22:19:15 +11:00
if len(dns.Question) == 0 {
2011-03-23 19:50:38 +11:00
return false
2011-03-16 22:19:15 +11:00
}
2011-03-23 19:50:38 +11:00
ok = dns.MsgHdr.Opcode == OpcodeNotify
2011-03-16 22:19:15 +11:00
ok = ok && dns.Question[0].Qclass == ClassINET
ok = ok && dns.Question[0].Qtype == TypeSOA
2011-04-19 06:08:12 +10:00
return
2011-03-16 22:19:15 +11:00
}
2011-03-17 03:28:35 +11:00
// Create a dns msg suitable for requesting an ixfr.
2011-03-23 06:12:36 +11:00
func (dns *Msg) SetIxfr(z string, serial uint32) {
dns.MsgHdr.Id = Id()
2011-03-16 22:19:15 +11:00
dns.Question = make([]Question, 1)
dns.Ns = make([]RR, 1)
s := new(RR_SOA)
2011-03-26 03:47:35 +11:00
s.Hdr = RR_Header{z, TypeSOA, ClassINET, DefaultTTL, 0}
2011-03-16 22:19:15 +11:00
s.Serial = serial
2011-03-23 06:12:36 +11:00
dns.Question[0] = Question{z, TypeIXFR, ClassINET}
2011-03-24 19:24:24 +11:00
dns.Ns[0] = s
2011-03-16 22:19:15 +11:00
}
2011-03-17 03:28:35 +11:00
// Create a dns msg suitable for requesting an axfr.
2011-03-23 06:12:36 +11:00
func (dns *Msg) SetAxfr(z string) {
dns.MsgHdr.Id = Id()
2011-03-16 22:19:15 +11:00
dns.Question = make([]Question, 1)
2011-03-23 06:12:36 +11:00
dns.Question[0] = Question{z, TypeAXFR, ClassINET}
2011-03-16 22:19:15 +11:00
}
2011-03-23 20:48:21 +11:00
2011-03-25 00:29:23 +11:00
// Is the message a valid axfr request packet?
2011-03-23 20:48:21 +11:00
func (dns *Msg) IsAxfr() (ok bool) {
if len(dns.Question) == 0 {
return false
}
ok = dns.MsgHdr.Opcode == OpcodeQuery
ok = ok && dns.Question[0].Qclass == ClassINET
ok = ok && dns.Question[0].Qtype == TypeAXFR
2011-04-19 06:08:12 +10:00
return
2011-03-23 20:48:21 +11:00
}
2011-03-25 00:29:23 +11:00
// Is the message a valid ixfr request packet?
2011-03-23 20:48:21 +11:00
func (dns *Msg) IsIxfr() (ok bool) {
if len(dns.Question) == 0 {
return false
}
ok = dns.MsgHdr.Opcode == OpcodeQuery
ok = ok && dns.Question[0].Qclass == ClassINET
ok = ok && dns.Question[0].Qtype == TypeIXFR
2011-04-19 06:08:12 +10:00
return
}
2011-07-24 07:32:42 +10:00
// Has the message a TSIG record as the last record?
2011-04-19 06:08:12 +10:00
func (dns *Msg) IsTsig() (ok bool) {
if len(dns.Extra) > 0 {
return dns.Extra[0].Header().Rrtype == TypeTSIG
}
return
2011-04-19 06:08:12 +10:00
}
2011-07-24 07:32:42 +10:00
// SetTsig Calculates and appends a TSIG RR on the message.
2011-04-19 06:08:12 +10:00
func (dns *Msg) SetTsig(z, algo string, fudge uint16, timesigned uint64) {
t := new(RR_TSIG)
t.Hdr = RR_Header{z, TypeTSIG, ClassANY, 0, 0}
t.Algorithm = algo
t.Fudge = fudge
t.TimeSigned = timesigned
dns.Extra = append(dns.Extra, t)
2011-03-23 20:48:21 +11:00
}