Add defaults.go for easy pkt making

This commit is contained in:
Miek Gieben 2011-03-16 12:19:15 +01:00
parent f065fb7f5f
commit a5f78d235c
5 changed files with 52 additions and 21 deletions

View File

@ -8,12 +8,12 @@ include $(GOROOT)/src/Make.inc
TARG=dns
GOFILES=\
config.go\
defaults.go\
dns.go\
dnssec.go\
edns.go\
keygen.go\
msg.go\
notify.go\
nsec3.go \
resolver.go\
server.go \

1
TODO
View File

@ -8,6 +8,7 @@ Issues:
* Make the testsuite work with public DNS servers
* pack/Unpack smaller. EDNS 'n stuff can be folded in
* SetDefaults() for *all* types?
* Closing of tcp connections?
* Refacter the IXFR/AXFR/TSIG code

49
defaults.go Normal file
View File

@ -0,0 +1,49 @@
package dns
// Create a notify request packet.
func (dns *Msg) SetNotifyRequest(z string, class uint16) {
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Id = Id()
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, class}
}
// Create a notify reply packet.
func (dns *Msg) SetNotifyReply(z string, class, id uint16) {
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Response = true
dns.MsgHdr.Id = id
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, class}
}
// Is a dns msg a valid notify packet?
func (dns *Msg) IsNotify() bool {
ok := dns.MsgHdr.Opcode == OpcodeNotify
if len(dns.Question) == 0 {
ok = false
}
ok = ok && dns.Question[0].Qclass == ClassINET
ok = ok && dns.Question[0].Qtype == TypeSOA
return ok
}
func (dns *Msg) SetIxfrRequest(z string, class uint16, serial uint32) {
dns.Question = make([]Question, 1)
dns.Ns = make([]RR, 1)
s := new(RR_SOA)
s.Hdr = RR_Header{z, TypeSOA, class, DefaultTtl, 0}
s.Serial = serial
dns.Question[0] = Question{z, TypeIXFR, class}
dns.Ns[0] = s
}
func (dns *Msg) SetAxfrRequest(z string, class uint16) {
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeAXFR, class}
}
// IsIxfr/IsAxfr?

View File

@ -1,20 +0,0 @@
package dns
// Create a notify request packet.
func (dns *Msg) SetNotifyRequest(z string, class uint16) {
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Id = Id()
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, class}
}
// Create a notify reply packet.
func (dns *Msg) SetNotifyReply(z string, class, id uint16) {
dns.MsgHdr.Opcode = OpcodeNotify
dns.MsgHdr.Authoritative = true
dns.MsgHdr.Response = true
dns.MsgHdr.Id = id
dns.Question = make([]Question, 1)
dns.Question[0] = Question{z, TypeSOA, class}
}

View File

@ -34,6 +34,7 @@ func (rr *RR_TSIG) Header() *RR_Header {
return &rr.Hdr
}
// move to defaults.go?
func (rr *RR_TSIG) SetDefaults() {
rr.Header().Ttl = 0
rr.Header().Class = ClassANY