From 496ab892d84ed87ab942acfe0933fdefe4a19fe5 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sun, 13 Mar 2011 14:51:02 +0100 Subject: [PATCH] New does help --- TODO | 3 +++ dns.go | 1 + new.go | 28 ++++++++++++++++++++++++++++ resolver.go | 4 +++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 new.go diff --git a/TODO b/TODO index 5b6e3fe2..7d60e98d 100644 --- a/TODO +++ b/TODO @@ -4,6 +4,9 @@ Todo: * encoding NSEC3/NSEC bitmaps, DEcoding works * AXFR/IXFR with TSIG validation * Failed Xfr triggers nil error? +* Use callback in IXFR/AXFR to make tsig happen (and other cool stuff in FunkenSturm) +* A New for all type with some defaults filled in +* Take a good look at hash.Hash take over the digest sizes and names * HIP RR (needs list of domain names, need slice stuff for that) Issues: diff --git a/dns.go b/dns.go index eebfda83..8b04e843 100644 --- a/dns.go +++ b/dns.go @@ -23,6 +23,7 @@ const ( Year68 = 2 << (32 - 1) // For RFC1982 (Serial Arithmetic) calculations in 32 bits. DefaultMsgSize = 4096 // A standard default for larger than 512 packets. MaxMsgSize = 65536 // Largest possible DNS packet. + DefaultTtl = 3600 // Default Ttl, used in New() for instance. ) // Error represents a DNS error diff --git a/new.go b/new.go new file mode 100644 index 00000000..8c785997 --- /dev/null +++ b/new.go @@ -0,0 +1,28 @@ +package dns + +func New(i int) RR { + var rr RR + mk, known := rr_mk[i] + if !known { + rr = new(RR_RFC3597) + } else { + rr = mk() + } + + switch t := rr.(type) { + case *RR_RFC3597: + t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} + case *RR_TSIG: + t.Hdr = RR_Header{Ttl: 0, Class: ClassANY, Rrtype: uint16(i)} + t.Fudge = 300 + case *RR_OPT: + t.Hdr = RR_Header{Name: "", Ttl: 0, Class: 0, Rrtype: uint16(i)} + t.SetVersion(0) + t.SetUDPSize(DefaultMsgSize) + case *RR_A: + t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} + case *RR_AAAA: + t.Hdr = RR_Header{Ttl: DefaultTtl, Class: ClassINET, Rrtype: uint16(i)} + } + return rr +} diff --git a/resolver.go b/resolver.go index cb956a95..5a32b71f 100644 --- a/resolver.go +++ b/resolver.go @@ -219,7 +219,9 @@ Server: // returned over the channel, so the caller will receive // the zone as-is. Xfr.Add is always true. // The channel is closed to signal the end of the AXFR. -func (res *Resolver) Axfr(q *Msg, m chan Xfr) { +// f is a callback function called after every message has been +// received. +func (res *Resolver) Axfr(q *Msg, m chan Xfr, f func(*Msg) bool) { var port string var in *Msg if res.Port == "" {