From 8368f4ce60728325914bd654a09f83c4e647ee3a Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Mon, 4 Jul 2011 20:19:44 +0200 Subject: [PATCH] Actually remove resolver.go --- client.go | 3 +- dns_test.go | 102 ----------------------------------- dnssec_test.go | 2 +- nsec3_test.go | 4 +- resolver.go | 107 ------------------------------------- resolver_test.go | 136 ----------------------------------------------- server_test.go | 125 ------------------------------------------- 7 files changed, 5 insertions(+), 474 deletions(-) delete mode 100644 dns_test.go delete mode 100644 resolver.go delete mode 100644 resolver_test.go delete mode 100644 server_test.go diff --git a/client.go b/client.go index 329be6ba..40dcefd4 100644 --- a/client.go +++ b/client.go @@ -189,7 +189,8 @@ func (c *Client) Do(m *Msg, a string) { } } -// A sync query +// Perform an synchronize query. Send the message m to the address +// contained in a func (c *Client) Exchange(m *Msg, a string) *Msg { w := new(reply) w.client = c diff --git a/dns_test.go b/dns_test.go deleted file mode 100644 index 596d9f41..00000000 --- a/dns_test.go +++ /dev/null @@ -1,102 +0,0 @@ -package dns - -import ( - "testing" - "time" -) - -func TestPackUnpack(t *testing.T) { - out := new(Msg) - out.Answer = make([]RR, 1) - key := new(RR_DNSKEY) - key.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeDNSKEY, Class: ClassINET, Ttl: 3600} - key = &RR_DNSKEY{Flags: 257, Protocol: 3, Algorithm: AlgRSASHA1} - key.PublicKey = "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFqNDzr//kZ" - - out.Answer[0] = key - msg, ok := out.Pack() - if !ok { - t.Log("Failed to pack msg with DNSKEY") - t.Fail() - } - - in := new(Msg) - if !in.Unpack(msg) { - t.Log("Failed to unpack msg with DNSKEY") - t.Fail() - } - - sig := new(RR_RRSIG) - sig.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeRRSIG, Class: ClassINET, Ttl: 3600} - sig = &RR_RRSIG{TypeCovered: TypeDNSKEY, Algorithm: AlgRSASHA1, Labels: 2, - OrigTtl: 3600, Expiration: 4000, Inception: 4000, KeyTag: 34641, SignerName: "miek.nl.", - Signature: "AwEAAaHIwpx3w4VHKi6i1LHnTaWeHCL154Jug0Rtc9ji5qwPXpBo6A5sRv7cSsPQKPIwxLpyCrbJ4mr2L0EPOdvP6z6YfljK2ZmTbogU9aSU2fiq/4wjxbdkLyoDVgtO+JsxNN4bjr4WcWhsmk1Hg93FV9ZpkWb0Tbad8DFqNDzr//kZ"} - - out.Answer[0] = sig - msg, ok = out.Pack() - if !ok { - t.Log("Failed to pack msg with RRSIG") - t.Fail() - } - - if !in.Unpack(msg) { - t.Log("Failed to unpack msg with RRSIG") - t.Fail() - } -} - -func TestEDNS_RR(t *testing.T) { - edns := new(RR_OPT) - edns.Hdr.Name = "." // must . be for edns - edns.Hdr.Rrtype = TypeOPT - edns.Hdr.Class = ClassINET - edns.Hdr.Ttl = 3600 - edns.Option = make([]Option, 1) - edns.Option[0].Code = OptionCodeNSID - edns.Option[0].Data = "lalalala" - //t..Logf("%v\n", edns) -} - -func TestTsig(t *testing.T) { - tsig := new(Tsig) - tsig.Name = "axfr." - tsig.Algorithm = HmacMD5 - tsig.Fudge = 300 - tsig.TimeSigned = uint64(time.Seconds()) - tsig.Secret = "so6ZGir4GPAqINNh9U5c3A==" - - // Perform a TSIG from miek.nl - m := new(Msg) - m.Question = make([]Question, 1) - m.Question[0] = Question{"miek.nl.", TypeAXFR, ClassINET} - m.Id = Id() - - res := new(Resolver) - res.FromFile("/etc/resolv.conf") - res.Servers = []string{"85.223.71.124"} - res.Tcp = true - - c := make(chan Xfr) - go res.XfrTsig(m, tsig, c) - for x := range c { - if x.Err != nil { - t.Logf("Failed Xfr from miek.nl %v\n", x.Err) - t.Fail() - } - } - - tsig.Secret = "ZGZqc2tmZAo=" - // Do it again, must fail - c = make(chan Xfr) // Reopen the channel - go res.XfrTsig(m, tsig, c) - ok := false - for x := range c { - if x.Err != nil { - ok = true - } - } - if ok == true { - t.Logf("AXFR with wrong secret should fail") - t.Fail() - } -} diff --git a/dnssec_test.go b/dnssec_test.go index 91fbd079..0b6c89e6 100644 --- a/dnssec_test.go +++ b/dnssec_test.go @@ -100,7 +100,7 @@ func TestSignVerify(t *testing.T) { sig := new(RR_RRSIG) sig.Hdr = RR_Header{"miek.nl.", TypeRRSIG, ClassINET, 14400, 0} sig.TypeCovered = soa.Hdr.Rrtype - sig.Labels = LabelCount(soa.Hdr.Name) + sig.Labels = labelCount(soa.Hdr.Name) sig.OrigTtl = soa.Hdr.Ttl sig.Expiration = 1296534305 // date -u '+%s' -d"2011-02-01 04:25:05" sig.Inception = 1293942305 // date -u '+%s' -d"2011-01-02 04:25:05" diff --git a/nsec3_test.go b/nsec3_test.go index ec8250bb..5aa3ba8d 100644 --- a/nsec3_test.go +++ b/nsec3_test.go @@ -5,13 +5,13 @@ import ( ) func TestPackNsec3(t *testing.T) { - nsec3 := HashName("dnsex.nl",HashSHA1 , 0, "DEAD") + nsec3 := hashName("dnsex.nl",HashSHA1 , 0, "DEAD") if nsec3 != "ROCCJAE8BJJU7HN6T7NG3TNM8ACRS87J" { t.Logf("%v\n", nsec3) t.Fail() } - nsec3 = HashName("a.b.c.example.org",HashSHA1 , 2, "DEAD") + nsec3 = hashName("a.b.c.example.org",HashSHA1 , 2, "DEAD") if nsec3 != "6LQ07OAHBTOOEU2R9ANI2AT70K5O0RCG" { t.Logf("%v\n", nsec3) t.Fail() diff --git a/resolver.go b/resolver.go deleted file mode 100644 index dddbe46d..00000000 --- a/resolver.go +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright 2011 Miek Gieben. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// DNS resolver client: see RFC 1035. - -package dns - -import ( - "os" -) - -// These channels are global so that all parts of the application -// can send queries (or even pick them up). -var ( - // Request an async query by sending to this channel. - QueryRequest chan *Query - // Listen for replies to previously sent queries on this channel. - QueryReply chan *Query -) - -// Query is used to communicate with the Query* functions. -type Query struct { - // The query message which is to be send. - Query *Msg - - // Any reply message that came back from the wire. - Reply *Msg - - // It is only required to fill out Conn.RemoteAddr. - // Optionally you may set Conn.Tsig if TSIG is required. - // The rest of the structure is filled by the Query functions. - Conn *Conn - - // If there are any errors there Err is not nil - Err os.Error -} - -// Initialize the QueryRequest and QueryReply channels. This -// is only required when async. queries are wanted. -func InitQueryChannels() { - QueryRequest = make(chan *Query) - QueryReply = make(chan *Query) -} - -// QueryAndServeTCP listens for incoming requests on channel in and then calls f. -// The function f is executed in a seperate goroutine and performs the actual -// TCP query and should return the result on the QueryReply channel. -func QueryAndServeTCP(f func(*Conn, *Msg)) os.Error { - if f == nil { - return ErrHandle - } - if QueryReply == nil || QueryRequest == nil { - return ErrChan - } - query("tcp", f) - return nil -} - -// QueryAndServeUDP listens for incoming requests on channel in and then calls f. -// The function f is executed in a seperate goroutine and performs the actual -// UDP query and should return the result on the QueryReply channel. -func QueryAndServeUDP(f func(*Conn, *Msg)) os.Error { - if f == nil { - return ErrHandle - } - if QueryReply == nil || QueryRequest == nil { - return ErrChan - } - query("udp", f) - return nil -} - -func query(n string, f func(*Conn, *Msg)) { - for { - select { - case q := <-QueryRequest: - err := q.Conn.Dial(n) - if err != nil { - QueryReply <- &Query{Err: err} - } - go f(q.Conn, q.Query) - } - } - panic("not reached") -} - -// SimpleQuery performs a query and waits for the reply before -// returning. -func SimpleQuery(n string, d *Conn, m *Msg) (*Msg, os.Error) { - err := d.Dial(n) - if err != nil { - return nil, err - } - o, err := d.ExchangeMsg(m, false) - d.Close() - return o, err -} - -// HandleQuery can be used as a default query handler. It -// fires of the querie, wait for a response and sends the -// response back on the QueryReply channel. HandleQuery closes d. -func HandleQuery(d *Conn, i *Msg) { - o, e := d.ExchangeMsg(i, false) - QueryReply <- &Query{Query: i, Reply: o, Conn: d, Err: e} - d.Close() -} diff --git a/resolver_test.go b/resolver_test.go deleted file mode 100644 index a73e10bc..00000000 --- a/resolver_test.go +++ /dev/null @@ -1,136 +0,0 @@ -package dns - -import ( - "time" - "testing" -) - -func TestResolver(t *testing.T) { - res := new(Resolver) - res.Servers = []string{"127.0.0.1"} - - m := new(Msg) - m.MsgHdr.RecursionDesired = true //only set this bit - m.Question = make([]Question, 1) - - // ask something - m.Question[0] = Question{"miek.nl", TypeSOA, ClassINET} - in, _ := res.Query(m) - - if in != nil && in.Rcode != RcodeSuccess { - t.Log("Failed to get an valid answer") - t.Fail() - t.Logf("%v\n", in) - } - - // ask something - m.Question[0] = Question{"www.nlnetlabs.nl", TypeRRSIG, ClassINET} - in, _ = res.Query(m) - - if in != nil && in.Rcode != RcodeSuccess { - t.Log("Failed to get an valid answer") - t.Fail() - t.Logf("%v\n", in) - } -} - -func TestResolverEdns(t *testing.T) { - res := new(Resolver) - res.Servers = []string{"127.0.0.1"} - res.Timeout = 2 - res.Attempts = 1 - - m := new(Msg) - m.MsgHdr.RecursionDesired = true //only set this bit - m.Question = make([]Question, 1) - - // Add EDNS rr - edns := new(RR_OPT) - edns.Hdr.Name = "." // must . be for edns - edns.Hdr.Rrtype = TypeOPT - // You can handle an OTP RR as any other, but there - // are some convience functions - edns.SetUDPSize(2048) - edns.SetDo() - edns.Option = make([]Option, 1) - edns.SetNsid("") // Empty to request it - - // ask something - m.Question[0] = Question{"powerdns.nl", TypeDNSKEY, ClassINET} - m.Extra = make([]RR, 1) - m.Extra[0] = edns - - in, _ := res.Query(m) - if in != nil { - if in.Rcode != RcodeSuccess { - t.Logf("%v\n", in) - t.Log("Failed to get an valid answer") - t.Fail() - } - } -} - -func TestResolverTsig(t *testing.T) { - res := new(Resolver) - res.Servers = []string{"127.0.0.1"} - res.Timeout = 2 - res.Attempts = 1 - - m := new(Msg) - m.MsgHdr.RecursionDesired = true //only set this bit - m.Question = make([]Question, 1) - - // ask something - m.Question[0] = Question{"powerdns.nl", TypeDNSKEY, ClassINET} - m.Extra = make([]RR, 1) - m.Id = Id() - - - tsig := new(Tsig) - tsig.Name = "miek.nl." - tsig.Algorithm = HmacMD5 - tsig.Fudge = 300 - tsig.TimeSigned = uint64(time.Seconds()) - tsig.Secret = "ZGZqc2tmZAo=" - - in, _ := res.QueryTsig(m,tsig) - if in != nil { - if in.Rcode != RcodeSuccess { - t.Logf("%v\n", in) - t.Log("Failed to get an valid answer") - // t.Fail() - } - } -} - -func TestAXFR(t *testing.T) { - res := new(Resolver) - res.Servers = []string{"127.0.0.1"} - m := new(Msg) - m.Question = make([]Question, 1) - m.Question[0] = Question{"miek.nl", TypeAXFR, ClassINET} - - ch := make(chan Xfr) - go res.Xfr(m, ch) - for x := range ch { - var _ = x - /* fmt.Printf("%v\n",dm.Dns) */ - } - /* channel is closed by Axfr() */ -} - -func TestFromFile(t *testing.T) { - res := new(Resolver) - res.FromFile("/etc/resolv.conf") - m := new(Msg) - m.Question = make([]Question, 1) - m.Question[0] = Question{"a.miek.nl", TypeA, ClassINET} - - in, _ := res.Query(m) - if in != nil { - if in.Rcode != RcodeSuccess { - t.Log("Failed to get an valid answer") - t.Fail() - } - } -} diff --git a/server_test.go b/server_test.go deleted file mode 100644 index 9d701108..00000000 --- a/server_test.go +++ /dev/null @@ -1,125 +0,0 @@ -package dns - -import ( - "testing" - "time" -) - -func createpkg(id uint16, tcp bool) *Msg { - m := new(Msg) - m.MsgHdr.Id = id - m.MsgHdr.Authoritative = true - m.MsgHdr.AuthenticatedData = false - m.MsgHdr.RecursionAvailable = true - m.MsgHdr.Response = true - m.MsgHdr.Opcode = OpcodeQuery - m.MsgHdr.Rcode = RcodeSuccess - m.Question = make([]Question, 1) - m.Question[0] = Question{"miek.nl.", TypeTXT, ClassINET} - m.Answer = make([]RR, 1) - t := new(RR_TXT) - t.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeTXT, Class: ClassINET, Ttl: 3600} - if tcp { - t.Txt = "Dit is iets anders TCP" - } else { - t.Txt = "Dit is iets anders UDP" - } - m.Answer[0] = t - return m -} - -func handle(c *Conn, in *Msg) { - if in.MsgHdr.Response == true { - return - } - out := createpkg(in.MsgHdr.Id, true) - c.WriteMsg(out) -} - -func TestResponder(t *testing.T) { -// ListenAndServeTCP("127.0.0.1:8053", replyTCP) - time.Sleep(2 * 1e9) -} - -/* -type servtsig Server - -func createpkgtsig(id uint16, tcp bool, remove net.Addr) []byte { - m := new(Msg) - m.MsgHdr.Id = id - m.MsgHdr.Authoritative = true - m.MsgHdr.AuthenticatedData = false - m.MsgHdr.RecursionAvailable = true - m.MsgHdr.Response = true - m.MsgHdr.Opcode = OpcodeQuery - m.MsgHdr.Rcode = RcodeSuccess - m.Question = make([]Question, 1) - m.Question[0] = Question{"miek.nl.", TypeTXT, ClassINET} - m.Answer = make([]RR, 1) - t := new(RR_TXT) - t.Hdr = RR_Header{Name: "miek.nl.", Rrtype: TypeTXT, Class: ClassINET, Ttl: 3600} - if tcp { - t.Txt = "Dit is iets anders TCP" - } else { - t.Txt = "Dit is iets anders UDP" - } - m.Answer[0] = t - out, _ := m.Pack() - return out -} - -func (s *servtsig) ResponderUDP(c *net.UDPConn, a net.Addr, in []byte) { - inmsg := new(Msg) - inmsg.Unpack(in) - fmt.Printf("%v\n", inmsg) - if inmsg.MsgHdr.Response == true { - // Uh... answering to an response?? - // dont think so - return - } - rr := inmsg.Extra[len(inmsg.Extra)-1] - switch t := rr.(type) { - case *RR_TSIG: - v := t.Verify(inmsg, "awwLOtRfpGE+rRKF2+DEiw==") - println(v) - } - - - out := createpkgtsig(inmsg.MsgHdr.Id, false, a) - SendUDP(out, c, a) - // Meta.QLen/RLen/QueryStart/QueryEnd can be filled in at - // this point for logging purposses or anything else -} - -func (s *servtsig) ResponderTCP(c *net.TCPConn, in []byte) { - inmsg := new(Msg) - inmsg.Unpack(in) - if inmsg.MsgHdr.Response == true { - // Uh... answering to an response?? - // dont think so - return - } - out := createpkgtsig(inmsg.MsgHdr.Id, true, c.RemoteAddr()) - SendTCP(out, c) -} - -func TestResponderTsig(t *testing.T) { - su := new(Server) - su.Address = "127.0.0.1" - su.Port = "8053" - var us *servtsig - uch := make(chan os.Error) - go su.NewResponder(us, uch) - - st := new(Server) - st.Address = "127.0.0.1" - st.Port = "8053" - st.Tcp = true - var ts *servtsig - tch := make(chan os.Error) - go st.NewResponder(ts, tch) - time.Sleep(1 * 1e9) - uch <- nil - tch <- nil -} -*/