Fix xfrprx

This commit is contained in:
Miek Gieben 2011-03-30 19:06:44 +02:00
parent 7deb2afceb
commit 9582fd005a
4 changed files with 23 additions and 17 deletions

2
TODO
View File

@ -8,6 +8,8 @@ Todo:
* HIP RR (needs list of domain names, need slice stuff for that)
* Is subdomain, is glue helper functions for this kind of stuff
* Make QuerySimple even simpler??
* Think about who closes who d.Close() and where
* Cleanups
Issues:
* FunkenSturm is kaput.

View File

@ -13,15 +13,13 @@ func handleXfrOut(d *dns.Conn, i *dns.Msg) os.Error {
fmt.Printf("Matchies current zone\n")
if !Zone.correct {
fmt.Printf("Zone was not deemed correct\n")
// Deny it
d.Close()
return nil
} else {
fmt.Printf("Zone was correct\n")
}
m := make(chan *dns.Xfr)
e := make(chan os.Error)
defer close(m)
defer close(e)
go d.XfrWrite(i, m, e)
for j := 0; j < Zone.size; j++ {
select {
@ -30,7 +28,10 @@ func handleXfrOut(d *dns.Conn, i *dns.Msg) os.Error {
return err
}
}
}
close(m)
} else {
fmt.Printf("No matching zone found\n")
}
}
return nil
}
@ -70,19 +71,22 @@ func handleXfrIn(i *dns.Msg) ([]dns.RR, os.Error) {
Zone.name = i.Question[0].Name
j := 0
for x := range m {
fmt.Printf("%v %v\n", x.Add, x.RR)
Zone.rrs[j] = x.RR
j++
}
fmt.Printf("Success retrieved %s\n", Zone.name)
Zone.size = j
return nil, nil
}
func sendNotify(addr, zone string) {
func handleNotifyOut(addr string) {
if Zone.name == "" || !Zone.correct {
return
}
d := new(dns.Conn)
d.RemoteAddr = addr
m := new(dns.Msg)
m.SetNotify(zone)
println("Sending notifies: zone is ok")
m.SetNotify(Zone.name)
fmt.Printf("Sending notifies: zone is ok\n")
dns.QueryRequest <- &dns.Query{Conn: d, Query: m}
}

View File

@ -33,13 +33,12 @@ func handle(d *dns.Conn, i *dns.Msg) {
return
}
handleNotify(d, i)
if Zone.name != "" {
// We have received something, assume ok for now
Zone.correct = true
sendNotify("127.0.0.1:53", Zone.name)
}
// handleNotifyOut("127.0.0.1:53") //
handleXfrOut(d, i)
if Zone.name != "" {
// We have transfered a zone and can check it. For now assume ok.
Zone.correct = true
}
}
func qhandle(d *dns.Conn, i *dns.Msg) {

5
xfr.go
View File

@ -60,7 +60,7 @@ func (d *Conn) XfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
case TypeIXFR:
// d.ixfrWrite(q, m)
default:
e <- &Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
e <- &Error{Error: "Xfr Qtype not recognized"}
close(m)
}
}
@ -149,6 +149,7 @@ func (d *Conn) axfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
// Everything is sent, only the closing soa is left.
out.Answer[i] = soa
out.Answer = out.Answer[:i+1]
println("Sending", out.String())
err := d.WriteMsg(out)
if err != nil {
e <- err
@ -240,8 +241,8 @@ func checkXfrSOA(in *Msg, first bool) bool {
// Send the answer section to the channel
func sendMsg(in *Msg, c chan *Xfr, nosoa bool) {
x := &Xfr{Add: true}
for k, r := range in.Answer {
x := &Xfr{Add: true}
if nosoa && k == len(in.Answer)-1 {
continue
}