More xfr fixes, does not work yet

This commit is contained in:
Miek Gieben 2013-10-11 22:34:04 +01:00
parent 05e5e586b5
commit 77d78f3218
3 changed files with 38 additions and 37 deletions

View File

@ -14,7 +14,7 @@ import (
const dnsTimeout time.Duration = 2 * 1e9
// A Conn represents a connection (which may be short lived) to a DNS server.
// A Conn represents a connection to a DNS server.
type Conn struct {
net.Conn // a net.Conn holding the connection
UDPSize uint16 // Minimum receive buffer for UDP messages
@ -124,6 +124,8 @@ func (c *Client) exchange(m *Msg, a string) (r *Msg, rtt time.Duration, err erro
}
// ReadMsg reads a message from the connection co.
// If the received message contains a TSIG record the transaction
// signature is verified.
func (co *Conn) ReadMsg() (*Msg, error) {
var p []byte
m := new(Msg)
@ -198,7 +200,7 @@ func (co *Conn) Read(p []byte) (n int, err error) {
return n, err
}
// WriteMsg send a message throught the connection co.
// WriteMsg sends a message throught the connection co.
// If the message m contains a TSIG record the transaction
// signature is calculated.
func (co *Conn) WriteMsg(m *Msg) (err error) {

View File

@ -135,6 +135,14 @@ Flags:
nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
}
c := new(dns.Client)
t := new(dns.Transfer)
c.Net = "udp"
if *four {
c.Net = "udp4"
}
if *six {
c.Net = "udp6"
}
if *tcp {
c.Net = "tcp"
if *four {
@ -143,14 +151,6 @@ Flags:
if *six {
c.Net = "tcp6"
}
} else {
c.Net = "udp"
if *four {
c.Net = "udp4"
}
if *six {
c.Net = "udp6"
}
}
m := new(dns.Msg)
@ -206,6 +206,7 @@ Flags:
if algo, name, secret, ok := tsigKeyParse(*tsig); ok {
m.SetTsig(name, algo, 300, time.Now().Unix())
c.TsigSecret = map[string]string{name: secret}
t.TsigSecret = map[string]string{name: secret}
} else {
fmt.Fprintf(os.Stderr, "TSIG key data error\n")
return
@ -215,13 +216,15 @@ Flags:
fmt.Printf("%s", m.String())
fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
}
if qtype == dns.TypeAXFR {
c.Net = "tcp"
doXfr(c, m, nameserver)
continue
}
if qtype == dns.TypeIXFR {
doXfr(c, m, nameserver)
if qtype == dns.TypeAXFR || qtype == dns.TypeIXFR {
env, err := t.In(m, nameserver)
if err != nil {
fmt.Printf(";; %s\n", err.Error())
continue
}
for e := range env {
fmt.Printf("%s\n", e.RR)
}
continue
}
r, rtt, e := c.Exchange(m, nameserver)
@ -397,21 +400,21 @@ func shortRR(r dns.RR) dns.RR {
func doXfr(c *dns.Client, m *dns.Msg, nameserver string) {
/*
if t, e := c.TransferIn(m, nameserver); e == nil {
for r := range t {
if r.Error == nil {
for _, rr := range r.RR {
if *short {
rr = shortRR(rr)
if t, e := c.TransferIn(m, nameserver); e == nil {
for r := range t {
if r.Error == nil {
for _, rr := range r.RR {
if *short {
rr = shortRR(rr)
}
fmt.Printf("%v\n", rr)
}
fmt.Printf("%v\n", rr)
} else {
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", r.Error.Error())
}
} else {
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", r.Error.Error())
}
} else {
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", e.Error())
}
} else {
fmt.Fprintf(os.Stderr, "Failure to read XFR: %s\n", e.Error())
}
*/
}

12
xfr.go
View File

@ -16,7 +16,7 @@ type Envelope struct {
}
type Transfer struct {
Conn
*Conn
DialTimeout time.Duration // net.DialTimeout (ns), defaults to 2 * 1e9
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections (ns), defaults to 2 * 1e9
WriteTimeout time.Duration // net.Conn.SetWriteTimeout value for connections (ns), defaults to 2 * 1e9
@ -25,12 +25,12 @@ type Transfer struct {
// In performs an incoming transfer with the server in a.
func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {
co := new(Conn)
t.Conn = new(Conn)
timeout := dnsTimeout
if t.DialTimeout != 0 {
timeout = t.DialTimeout
}
co.Conn, err = net.DialTimeout("tcp", a, timeout)
t.Conn, err = net.DialTimeout("tcp", a, timeout)
if err != nil {
return nil, err
}
@ -128,7 +128,7 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) {
// This serial is important
serial = in.Answer[0].(*SOA).Serial
first = !first
// continue // TODO(miek)
// continue // TODO(miek): ?
}
// Now we need to check each message for SOA records, to see what we need to do
@ -207,10 +207,6 @@ func (t *Transfer) WriteMsg(m *Msg) (err error) {
return nil
}
/*
*/
func isSOAFirst(in *Msg) bool {
if len(in.Answer) > 0 {
return in.Answer[0].Header().Rrtype == TypeSOA