Add defaults.go for easy pkt making
This commit is contained in:
parent
f065fb7f5f
commit
a5f78d235c
2
Makefile
2
Makefile
|
@ -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
1
TODO
|
@ -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
|
||||
|
||||
|
|
|
@ -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?
|
20
notify.go
20
notify.go
|
@ -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}
|
||||
}
|
Loading…
Reference in New Issue