Add axfr/ixfr support to q

This commit is contained in:
Miek Gieben 2012-09-03 19:08:21 +02:00
parent ec1f57db6c
commit 13a1e4a4ae
3 changed files with 12 additions and 50 deletions

View File

@ -1,46 +0,0 @@
package main
import (
"flag"
"fmt"
"github.com/miekg/dns"
"strings"
"time"
)
func main() {
serial := flag.Int("serial", 0, "Perform an IXFR with the given serial")
nameserver := flag.String("ns", "127.0.0.1:53", "Query this nameserver")
tsig := flag.String("tsig", "", "request tsig with key: name:key (only hmac-md5)")
flag.Parse()
zone := flag.Arg(flag.NArg() - 1)
client := new(dns.Client)
client.Net = "tcp"
m := new(dns.Msg)
if *serial > 0 {
m.SetIxfr(dns.Fqdn(zone), uint32(*serial))
} else {
m.SetAxfr(dns.Fqdn(zone))
}
if *tsig != "" {
a := strings.SplitN(*tsig, ":", 2)
name, secret := a[0], a[1]
client.TsigSecret = map[string]string{dns.Fqdn(name): secret}
m.SetTsig(name, dns.HmacMD5, 300, time.Now().Unix())
}
if t, e := client.XfrReceive(m, *nameserver); e == nil {
for r := range t {
if r.Error == nil {
for _, rr := range r.RR {
fmt.Printf("%v\n", rr)
}
} else {
fmt.Printf("error: %s\n", r.Error.Error())
}
}
} else {
fmt.Printf("Error %v\n", e)
}
}

View File

@ -187,7 +187,12 @@ Flags:
return
}
}
if qtype == dns.TypeAXFR || qtype == dns.TypeIXFR {
if qtype == dns.TypeAXFR {
c.Net = "tcp"
doXfr(c, m, nameserver)
continue
}
if qtype == dns.TypeIXFR {
doXfr(c, m, nameserver)
continue
}
@ -246,7 +251,10 @@ Flags:
fmt.Printf("\n;; query time: %.3d µs, server: %s(%s), size: %d bytes\n", rtt/1e3, nameserver, c.Net, r.Size)
})
}
select {}
if qtype != dns.TypeAXFR && qtype != dns.TypeIXFR {
// xfr don't start any goroutines
select {}
}
}
@ -425,6 +433,6 @@ func doXfr(c *dns.Client, m *dns.Msg, nameserver string) {
}
}
} else {
fmt.Printf("Error %v\n", e)
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", e.Error())
}
}

2
xfr.go
View File

@ -52,7 +52,7 @@ func (w *reply) axfrReceive(q *Msg, c chan *XfrToken) {
for {
in, err := w.receive()
if err != nil {
c <- &XfrToken{in.Answer, err}
c <- &XfrToken{nil, err}
return
}
if in.Id != q.Id {