From a5f78d235c16eb286d8a43053a260c32623fedd2 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 16 Mar 2011 12:19:15 +0100 Subject: [PATCH] Add defaults.go for easy pkt making --- Makefile | 2 +- TODO | 1 + defaults.go | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ notify.go | 20 -------------------- tsig.go | 1 + 5 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 defaults.go delete mode 100644 notify.go diff --git a/Makefile b/Makefile index a58b8cbf..e153d20b 100644 --- a/Makefile +++ b/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 \ diff --git a/TODO b/TODO index d5f42318..ed2acc68 100644 --- a/TODO +++ b/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 diff --git a/defaults.go b/defaults.go new file mode 100644 index 00000000..9bbf50e6 --- /dev/null +++ b/defaults.go @@ -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? diff --git a/notify.go b/notify.go deleted file mode 100644 index 1d09bab4..00000000 --- a/notify.go +++ /dev/null @@ -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} -} diff --git a/tsig.go b/tsig.go index d1797abd..0c16032d 100644 --- a/tsig.go +++ b/tsig.go @@ -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