More xfr fixes, does not work yet
This commit is contained in:
parent
05e5e586b5
commit
77d78f3218
|
@ -14,7 +14,7 @@ import (
|
||||||
|
|
||||||
const dnsTimeout time.Duration = 2 * 1e9
|
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 {
|
type Conn struct {
|
||||||
net.Conn // a net.Conn holding the connection
|
net.Conn // a net.Conn holding the connection
|
||||||
UDPSize uint16 // Minimum receive buffer for UDP messages
|
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.
|
// 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) {
|
func (co *Conn) ReadMsg() (*Msg, error) {
|
||||||
var p []byte
|
var p []byte
|
||||||
m := new(Msg)
|
m := new(Msg)
|
||||||
|
@ -198,7 +200,7 @@ func (co *Conn) Read(p []byte) (n int, err error) {
|
||||||
return n, err
|
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
|
// If the message m contains a TSIG record the transaction
|
||||||
// signature is calculated.
|
// signature is calculated.
|
||||||
func (co *Conn) WriteMsg(m *Msg) (err error) {
|
func (co *Conn) WriteMsg(m *Msg) (err error) {
|
||||||
|
|
57
ex/q/q.go
57
ex/q/q.go
|
@ -135,6 +135,14 @@ Flags:
|
||||||
nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
|
nameserver = dns.Fqdn(nameserver) + ":" + strconv.Itoa(*port)
|
||||||
}
|
}
|
||||||
c := new(dns.Client)
|
c := new(dns.Client)
|
||||||
|
t := new(dns.Transfer)
|
||||||
|
c.Net = "udp"
|
||||||
|
if *four {
|
||||||
|
c.Net = "udp4"
|
||||||
|
}
|
||||||
|
if *six {
|
||||||
|
c.Net = "udp6"
|
||||||
|
}
|
||||||
if *tcp {
|
if *tcp {
|
||||||
c.Net = "tcp"
|
c.Net = "tcp"
|
||||||
if *four {
|
if *four {
|
||||||
|
@ -143,14 +151,6 @@ Flags:
|
||||||
if *six {
|
if *six {
|
||||||
c.Net = "tcp6"
|
c.Net = "tcp6"
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
c.Net = "udp"
|
|
||||||
if *four {
|
|
||||||
c.Net = "udp4"
|
|
||||||
}
|
|
||||||
if *six {
|
|
||||||
c.Net = "udp6"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m := new(dns.Msg)
|
m := new(dns.Msg)
|
||||||
|
@ -206,6 +206,7 @@ Flags:
|
||||||
if algo, name, secret, ok := tsigKeyParse(*tsig); ok {
|
if algo, name, secret, ok := tsigKeyParse(*tsig); ok {
|
||||||
m.SetTsig(name, algo, 300, time.Now().Unix())
|
m.SetTsig(name, algo, 300, time.Now().Unix())
|
||||||
c.TsigSecret = map[string]string{name: secret}
|
c.TsigSecret = map[string]string{name: secret}
|
||||||
|
t.TsigSecret = map[string]string{name: secret}
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintf(os.Stderr, "TSIG key data error\n")
|
fmt.Fprintf(os.Stderr, "TSIG key data error\n")
|
||||||
return
|
return
|
||||||
|
@ -215,13 +216,15 @@ Flags:
|
||||||
fmt.Printf("%s", m.String())
|
fmt.Printf("%s", m.String())
|
||||||
fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
|
fmt.Printf("\n;; size: %d bytes\n\n", m.Len())
|
||||||
}
|
}
|
||||||
if qtype == dns.TypeAXFR {
|
if qtype == dns.TypeAXFR || qtype == dns.TypeIXFR {
|
||||||
c.Net = "tcp"
|
env, err := t.In(m, nameserver)
|
||||||
doXfr(c, m, nameserver)
|
if err != nil {
|
||||||
continue
|
fmt.Printf(";; %s\n", err.Error())
|
||||||
}
|
continue
|
||||||
if qtype == dns.TypeIXFR {
|
}
|
||||||
doXfr(c, m, nameserver)
|
for e := range env {
|
||||||
|
fmt.Printf("%s\n", e.RR)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
r, rtt, e := c.Exchange(m, nameserver)
|
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) {
|
func doXfr(c *dns.Client, m *dns.Msg, nameserver string) {
|
||||||
/*
|
/*
|
||||||
if t, e := c.TransferIn(m, nameserver); e == nil {
|
if t, e := c.TransferIn(m, nameserver); e == nil {
|
||||||
for r := range t {
|
for r := range t {
|
||||||
if r.Error == nil {
|
if r.Error == nil {
|
||||||
for _, rr := range r.RR {
|
for _, rr := range r.RR {
|
||||||
if *short {
|
if *short {
|
||||||
rr = shortRR(rr)
|
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
12
xfr.go
|
@ -16,7 +16,7 @@ type Envelope struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Transfer struct {
|
type Transfer struct {
|
||||||
Conn
|
*Conn
|
||||||
DialTimeout time.Duration // net.DialTimeout (ns), defaults to 2 * 1e9
|
DialTimeout time.Duration // net.DialTimeout (ns), defaults to 2 * 1e9
|
||||||
ReadTimeout time.Duration // net.Conn.SetReadTimeout value for connections (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
|
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.
|
// In performs an incoming transfer with the server in a.
|
||||||
func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {
|
func (t *Transfer) In(q *Msg, a string) (env chan *Envelope, err error) {
|
||||||
co := new(Conn)
|
t.Conn = new(Conn)
|
||||||
timeout := dnsTimeout
|
timeout := dnsTimeout
|
||||||
if t.DialTimeout != 0 {
|
if t.DialTimeout != 0 {
|
||||||
timeout = t.DialTimeout
|
timeout = t.DialTimeout
|
||||||
}
|
}
|
||||||
co.Conn, err = net.DialTimeout("tcp", a, timeout)
|
t.Conn, err = net.DialTimeout("tcp", a, timeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ func (t *Transfer) inIxfr(id uint16, c chan *Envelope) {
|
||||||
// This serial is important
|
// This serial is important
|
||||||
serial = in.Answer[0].(*SOA).Serial
|
serial = in.Answer[0].(*SOA).Serial
|
||||||
first = !first
|
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
|
// 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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
func isSOAFirst(in *Msg) bool {
|
func isSOAFirst(in *Msg) bool {
|
||||||
if len(in.Answer) > 0 {
|
if len(in.Answer) > 0 {
|
||||||
return in.Answer[0].Header().Rrtype == TypeSOA
|
return in.Answer[0].Header().Rrtype == TypeSOA
|
||||||
|
|
Loading…
Reference in New Issue