Fix xfrprg -- needs testing

This commit is contained in:
Miek Gieben 2011-03-30 17:50:07 +02:00
parent 63c47a698e
commit 15d84f0d7d
4 changed files with 32 additions and 19 deletions

View File

@ -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) {

View File

@ -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}
}

View File

@ -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)
}

View File

@ -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?