From 15d84f0d7d806313643538da7a3ab7612d8705a7 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Wed, 30 Mar 2011 17:50:07 +0200 Subject: [PATCH] Fix xfrprg -- needs testing --- _examples/q/q.go | 2 -- _examples/xfrprx/xfr.go | 21 ++++++++++++++++++--- _examples/xfrprx/xfrprx.go | 24 ++++++++++++------------ defaults.go | 4 ++-- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/_examples/q/q.go b/_examples/q/q.go index 58159213..bb28ae7b 100644 --- a/_examples/q/q.go +++ b/_examples/q/q.go @@ -124,7 +124,6 @@ func query(tcp string, e chan os.Error) { err := dns.QueryAndServeUDP(qhandle) e <- err } - return } // reply checking 'n stuff @@ -132,7 +131,6 @@ func qhandle(d *dns.Conn, i *dns.Msg) { o, err := d.ExchangeMsg(i, false) dns.QueryReply <- &dns.Query{Query: i, Reply: o, Conn: d, Err: err} d.Close() - return } func newConnMsg(qname, nameserver string, attempts int, qtype, qclass uint16, aa, ad, cd, rd, dnssec, nsid bool) (*dns.Conn, *dns.Msg) { diff --git a/_examples/xfrprx/xfr.go b/_examples/xfrprx/xfr.go index 9691c8a1..9fbe911e 100644 --- a/_examples/xfrprx/xfr.go +++ b/_examples/xfrprx/xfr.go @@ -6,11 +6,18 @@ import ( "fmt" ) -func handleXfr(d *dns.Conn, i *dns.Msg) os.Error { +func handleXfrOut(d *dns.Conn, i *dns.Msg) os.Error { if i.IsAxfr() { fmt.Printf("Axfr request seen\n") if i.Question[0].Name == Zone.name { fmt.Printf("Matching current zone\n") + if !Zone.correct { + fmt.Printf("Zone was not deemed correct\n") + // Deny it + d.Close() + return nil + } + m := make(chan *dns.Xfr) e := make(chan os.Error) defer close(m) @@ -37,12 +44,12 @@ func handleNotify(d *dns.Conn, i *dns.Msg) os.Error { if err != nil { return err } - doXfrIn(i) + handleXfrIn(i) } return nil } -func doXfrIn(i *dns.Msg) ([]dns.RR, os.Error) { +func handleXfrIn(i *dns.Msg) ([]dns.RR, os.Error) { q := new(dns.Msg) q.SetAxfr(i.Question[0].Name) @@ -70,3 +77,11 @@ func doXfrIn(i *dns.Msg) ([]dns.RR, os.Error) { Zone.size = j return nil, nil } + +func sendNotify(addr, zone string) { + d := new(dns.Conn) + d.RemoteAddr = addr + m := new(dns.Msg) + m.SetNotify(zone) + dns.QueryRequest <- &dns.Query{Conn: d, Query: m} +} diff --git a/_examples/xfrprx/xfrprx.go b/_examples/xfrprx/xfrprx.go index 112b0758..55beefcf 100644 --- a/_examples/xfrprx/xfrprx.go +++ b/_examples/xfrprx/xfrprx.go @@ -23,27 +23,29 @@ type zone struct { name string rrs [10000]dns.RR size int + correct bool } var Zone zone func handle(d *dns.Conn, i *dns.Msg) { -/* send response here, how ??? */ if i.MsgHdr.Response == true { return } handleNotify(d, i) - handleXfr(d, i) + + if Zone.name != "" { + // We have received something, assume ok for now + Zone.correct = true + sendNotify("127.0.0.1:53", Zone.name) + } + handleXfrOut(d, i) } func qhandle(d *dns.Conn, i *dns.Msg) { - // We should send i to d.RemoteAddr - // simpleQuery here - - // what do we do with the reply - ///handle HERE!!?? Need globals or stuff in d... - - // in/out channel must be accessible + o, err := d.ExchangeMsg(i, false) + dns.QueryReply <- &dns.Query{Query: i, Reply: o, Conn: d, Err: err} + d.Close() } func listen(addr string, e chan os.Error, tcp string) { @@ -94,10 +96,8 @@ forever: fmt.Printf("Signal received, stopping") break forever case q := <-dns.QueryReply: - var _ = q - /* ... */ + fmt.Printf("Query received: %v\n", q) } } close(err) - } diff --git a/defaults.go b/defaults.go index fff872aa..5787d8e5 100644 --- a/defaults.go +++ b/defaults.go @@ -15,12 +15,12 @@ func (dns *Msg) SetReply(request *Msg) { } // Create a notify packet. -func (dns *Msg) SetNotify(z string, class uint16) { +func (dns *Msg) SetNotify(z string) { dns.MsgHdr.Opcode = OpcodeNotify dns.MsgHdr.Authoritative = true dns.MsgHdr.Id = Id() dns.Question = make([]Question, 1) - dns.Question[0] = Question{z, TypeSOA, class} + dns.Question[0] = Question{z, TypeSOA, ClassINET} } // Is the message a dynamic update packet?