more server stuff
This commit is contained in:
parent
0ffb28d3d9
commit
21e2f63b4c
|
@ -12,6 +12,8 @@ import (
|
||||||
"net"
|
"net"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// how to do Tsig here?? TODO(mg)
|
||||||
|
|
||||||
type Handler interface {
|
type Handler interface {
|
||||||
ServeDNS(w ResponseWriter, r *Msg)
|
ServeDNS(w ResponseWriter, r *Msg)
|
||||||
// IP based ACL mapping. The contains the string representation
|
// IP based ACL mapping. The contains the string representation
|
||||||
|
@ -27,6 +29,7 @@ type ResponseWriter interface {
|
||||||
Write([]byte) (int, os.Error)
|
Write([]byte) (int, os.Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// port?
|
||||||
type conn struct {
|
type conn struct {
|
||||||
remoteAddr net.Addr // address of remote side (sans port)
|
remoteAddr net.Addr // address of remote side (sans port)
|
||||||
handler Handler // request handler
|
handler Handler // request handler
|
||||||
|
|
77
xfr.go
77
xfr.go
|
@ -4,12 +4,8 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fix the sending function to work on messages, keep the size
|
|
||||||
// of the callers contral
|
|
||||||
|
|
||||||
// XfrReceives requests an incoming Ixfr or Axfr. If the message q's question
|
// XfrReceives requests an incoming Ixfr or Axfr. If the message q's question
|
||||||
// section contains an AXFR type an Axfr is performed, if it is IXFR it does
|
// section contains an AXFR type an Axfr is performed, if it is IXFR it does an Ixfr.
|
||||||
// an Ixfr.
|
|
||||||
// Each message will be send along the Client's reply channel as it is received.
|
// Each message will be send along the Client's reply channel as it is received.
|
||||||
// The last message send has Exchange.Error set to ErrXfrLast
|
// The last message send has Exchange.Error set to ErrXfrLast
|
||||||
// to signal there is nothing more to come.
|
// to signal there is nothing more to come.
|
||||||
|
@ -18,9 +14,9 @@ func (c *Client) XfrReceive(q *Msg, a string) os.Error {
|
||||||
w.client = c
|
w.client = c
|
||||||
w.addr = a
|
w.addr = a
|
||||||
w.req = q
|
w.req = q
|
||||||
if err := w.Dial(); err != nil {
|
if err := w.Dial(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := w.Send(q); err != nil {
|
if err := w.Send(q); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -29,23 +25,23 @@ func (c *Client) XfrReceive(q *Msg, a string) os.Error {
|
||||||
go w.axfrReceive()
|
go w.axfrReceive()
|
||||||
case TypeIXFR:
|
case TypeIXFR:
|
||||||
go w.ixfrReceive()
|
go w.ixfrReceive()
|
||||||
default:
|
default:
|
||||||
return ErrXfrType
|
return ErrXfrType
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *reply) axfrReceive() {
|
func (w *reply) axfrReceive() {
|
||||||
first := true
|
first := true
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
for {
|
for {
|
||||||
in, err := w.Receive()
|
in, err := w.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.req.Id != in.Id {
|
if w.req.Id != in.Id {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +56,7 @@ func (w *reply) axfrReceive() {
|
||||||
if !first {
|
if !first {
|
||||||
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
||||||
if checkXfrSOA(in, false) {
|
if checkXfrSOA(in, false) {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
||||||
|
@ -73,23 +69,23 @@ func (w *reply) axfrReceive() {
|
||||||
func (w *reply) ixfrReceive() {
|
func (w *reply) ixfrReceive() {
|
||||||
var serial uint32 // The first serial seen is the current server serial
|
var serial uint32 // The first serial seen is the current server serial
|
||||||
first := true
|
first := true
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
for {
|
for {
|
||||||
in, err := w.Receive()
|
in, err := w.Receive()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
w.Client().ReplyChan <- &Exchange{w.req, in, err}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if w.req.Id != in.Id {
|
if w.req.Id != in.Id {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
w.Client().ReplyChan <- &Exchange{w.req, in, ErrId}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if first {
|
if first {
|
||||||
// A single SOA RR signals "no changes"
|
// A single SOA RR signals "no changes"
|
||||||
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if the returned answer is ok
|
// Check if the returned answer is ok
|
||||||
|
@ -104,14 +100,14 @@ func (w *reply) ixfrReceive() {
|
||||||
|
|
||||||
// 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
|
||||||
if !first {
|
if !first {
|
||||||
w.tsigTimersOnly = true
|
w.tsigTimersOnly = true
|
||||||
// If the last record in the IXFR contains the servers' SOA, we should quit
|
// If the last record in the IXFR contains the servers' SOA, we should quit
|
||||||
if v, ok := in.Answer[len(in.Answer)-1].(*RR_SOA); ok {
|
if v, ok := in.Answer[len(in.Answer)-1].(*RR_SOA); ok {
|
||||||
if v.Serial == serial {
|
if v.Serial == serial {
|
||||||
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
w.Client().ReplyChan <- &Exchange{w.req, in, ErrXfrLast}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
w.Client().ReplyChan <- &Exchange{Request: w.req, Reply: in}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,19 +115,16 @@ func (w *reply) ixfrReceive() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// XfrSend performs an outgoing Ixfr or Axfr. If the message q's question
|
// XfrSend performs an outgoing Ixfr or Axfr. The function is xfr agnostic, it is
|
||||||
// section contains an AXFR type an Axfr is performed. If it is IXFR
|
// up to the caller to correctly send the sequence of messages.
|
||||||
// it does an Ixfr.
|
|
||||||
func XfrSend(w ResponseWriter, q *Msg, a string) os.Error {
|
func XfrSend(w ResponseWriter, q *Msg, a string) os.Error {
|
||||||
switch q.Question[0].Qtype {
|
switch q.Question[0].Qtype {
|
||||||
case TypeAXFR:
|
case TypeAXFR, TypeIXFR:
|
||||||
// go d.axfrWrite(q, m, e)
|
// go d.xfrWrite(q, m, e)
|
||||||
case TypeIXFR:
|
default:
|
||||||
// go d.ixfrWrite(q, m)
|
return ErrXfrType
|
||||||
default:
|
|
||||||
return ErrXfrType
|
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue