start fixing xfr and fold TSIG back in
This commit is contained in:
parent
13ace2687a
commit
e46a5e9908
3
Makefile
3
Makefile
|
@ -20,8 +20,7 @@ GOFILES=\
|
||||||
server.go \
|
server.go \
|
||||||
tsig.go\
|
tsig.go\
|
||||||
types.go\
|
types.go\
|
||||||
|
xfr.go\
|
||||||
# xfr.go\
|
|
||||||
|
|
||||||
include $(GOROOT)/src/Make.pkg
|
include $(GOROOT)/src/Make.pkg
|
||||||
|
|
||||||
|
|
138
xfr.go
138
xfr.go
|
@ -4,50 +4,64 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Xfr is used in communicating with Xfr* functions.
|
|
||||||
type Xfr struct {
|
|
||||||
// If Add is true the resource record in RR must be added to
|
|
||||||
// the zone. If Add is false the resource record must be removed.
|
|
||||||
// be considered to have failed.
|
|
||||||
Add bool
|
|
||||||
// The RR that should be added or removed.
|
|
||||||
RR
|
|
||||||
// If err in non nil some error occurred and the transfer must
|
|
||||||
// be considered to have faild.
|
|
||||||
Err os.Error
|
|
||||||
}
|
|
||||||
// todo maybe add the SOA serial too?
|
|
||||||
|
|
||||||
// Perform an incoming Ixfr or Axfr. If the message q's question
|
// Perform an incoming Ixfr or Axfr. If the message q's question
|
||||||
// section contains an AXFR type an Axfr is performed. If q's question
|
// section contains an AXFR type an Axfr is performed. If q's question
|
||||||
// section contains an IXFR type an Ixfr is performed.
|
// section contains an IXFR type an Ixfr is performed.
|
||||||
func (d *Conn) XfrRead(q *Msg, m chan *Xfr) {
|
func (c *Client) XfrReceive(q *Msg, a string) ([]*Msg, os.Error) {
|
||||||
if d.TCP == nil && d.UDP == nil {
|
w := new(reply)
|
||||||
// No connection yet
|
w.client = c
|
||||||
if err := d.Dial("tcp"); err != nil {
|
w.addr = a
|
||||||
m <- &Xfr{true, nil, err}
|
w.req = q // is this needed??
|
||||||
close(m)
|
|
||||||
return
|
if err := w.Send(q); err != nil {
|
||||||
}
|
return nil, err
|
||||||
}
|
}
|
||||||
// Send q now.
|
// conn should be set now
|
||||||
err := d.WriteMsg(q)
|
|
||||||
if err != nil {
|
|
||||||
m <- &Xfr{true, nil, err}
|
|
||||||
close(m)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
switch q.Question[0].Qtype {
|
switch q.Question[0].Qtype {
|
||||||
case TypeAXFR:
|
case TypeAXFR:
|
||||||
d.axfrRead(q, m)
|
return w.axfrReceive()
|
||||||
case TypeIXFR:
|
case TypeIXFR:
|
||||||
d.ixfrRead(q, m)
|
// return w.ixfrReceive()
|
||||||
default:
|
|
||||||
m <- &Xfr{true, nil, &Error{Error: "Xfr Qtype not recognized"}}
|
|
||||||
close(m)
|
|
||||||
}
|
}
|
||||||
|
panic("not reached")
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *reply) axfrReceive() ([]*Msg, os.Error) {
|
||||||
|
axfr := make([]*Msg, 1) // use append ALL the time?
|
||||||
|
first := true
|
||||||
|
for {
|
||||||
|
in, err := w.Receive()
|
||||||
|
if err != nil {
|
||||||
|
return axfr, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if first {
|
||||||
|
if !checkXfrSOA(in, true) {
|
||||||
|
return axfr, ErrXfrSoa
|
||||||
|
}
|
||||||
|
first = !first
|
||||||
|
}
|
||||||
|
|
||||||
|
if !first {
|
||||||
|
//if d.Tsig != nil {
|
||||||
|
// d.Tsig.TimersOnly = true // Subsequent envelopes use this.
|
||||||
|
//}
|
||||||
|
if !checkXfrSOA(in, false) {
|
||||||
|
// Soa record not the last one
|
||||||
|
axfr = append(axfr, in)
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
axfr = append(axfr, in)
|
||||||
|
return axfr, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic("not reached")
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
|
||||||
// Perform an outgoing Ixfr or Axfr. If the message q's question
|
// Perform an outgoing Ixfr or Axfr. If the message q's question
|
||||||
// section contains an AXFR type an Axfr is performed. If q's question
|
// section contains an AXFR type an Axfr is performed. If q's question
|
||||||
// section contains an IXFR type an Ixfr is performed.
|
// section contains an IXFR type an Ixfr is performed.
|
||||||
|
@ -65,47 +79,6 @@ func (d *Conn) XfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Conn) axfrRead(q *Msg, m chan *Xfr) {
|
|
||||||
defer close(m)
|
|
||||||
first := true
|
|
||||||
in := new(Msg)
|
|
||||||
for {
|
|
||||||
err := d.ReadMsg(in)
|
|
||||||
if err != nil {
|
|
||||||
m <- &Xfr{true, nil, err}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if in.Id != q.Id {
|
|
||||||
m <- &Xfr{true, nil, ErrId}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if first {
|
|
||||||
if !checkXfrSOA(in, true) {
|
|
||||||
m <- &Xfr{true, nil, ErrXfrSoa}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
first = !first
|
|
||||||
}
|
|
||||||
|
|
||||||
if !first {
|
|
||||||
if d.Tsig != nil {
|
|
||||||
d.Tsig.TimersOnly = true // Subsequent envelopes use this.
|
|
||||||
}
|
|
||||||
if !checkXfrSOA(in, false) {
|
|
||||||
// Soa record not the last one
|
|
||||||
sendMsg(in, m, false)
|
|
||||||
continue
|
|
||||||
} else {
|
|
||||||
sendMsg(in, m, true)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
panic("not reached")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Just send the zone
|
// Just send the zone
|
||||||
func (d *Conn) axfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
|
func (d *Conn) axfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
|
||||||
out := new(Msg)
|
out := new(Msg)
|
||||||
|
@ -155,7 +128,7 @@ func (d *Conn) axfrWrite(q *Msg, m chan *Xfr, e chan os.Error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Conn) ixfrRead(q *Msg, m chan *Xfr) {
|
func (d *Conn) ixfrReceive(q *Msg, m chan *Xfr) {
|
||||||
defer close(m)
|
defer close(m)
|
||||||
var serial uint32 // The first serial seen is the current server serial
|
var serial uint32 // The first serial seen is the current server serial
|
||||||
var x *Xfr
|
var x *Xfr
|
||||||
|
@ -223,6 +196,7 @@ func (d *Conn) ixfrRead(q *Msg, m chan *Xfr) {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Check if he SOA record exists in the Answer section of
|
// Check if he SOA record exists in the Answer section of
|
||||||
// the packet. If first is true the first RR must be a soa
|
// the packet. If first is true the first RR must be a soa
|
||||||
|
@ -237,15 +211,3 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the answer section to the channel
|
|
||||||
func sendMsg(in *Msg, c chan *Xfr, nosoa bool) {
|
|
||||||
for k, r := range in.Answer {
|
|
||||||
x := &Xfr{Add: true}
|
|
||||||
if nosoa && k == len(in.Answer)-1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
x.RR = r
|
|
||||||
c <- x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue