Envelope is the correct term in the context of transfers
This commit is contained in:
parent
a115d2230a
commit
724a156794
46
xfr.go
46
xfr.go
|
@ -1,13 +1,13 @@
|
|||
package dns
|
||||
|
||||
// XfrMsg is used when doing [IA]xfr with a remote server.
|
||||
type XfrMsg struct {
|
||||
// Envelope is used when doing [IA]xfr with a remote server.
|
||||
type Envelope struct {
|
||||
RR []RR // The set of RRs in the answer section of the AXFR reply message.
|
||||
Error error // If something went wrong, this contains the error.
|
||||
}
|
||||
|
||||
// XfrReceive performs a [AI]xfr request (depends on the message's Qtype). It returns
|
||||
// a channel of *XfrMsg on which the replies from the server are sent. At the end of
|
||||
// a channel of *Envelope on which the replies from the server are sent. At the end of
|
||||
// the transfer the channel is closed.
|
||||
// The messages are TSIG checked if
|
||||
// needed, no other post-processing is performed. The caller must dissect the returned
|
||||
|
@ -20,7 +20,7 @@ type XfrMsg struct {
|
|||
// for r := range t {
|
||||
// // ... deal with r.RR or r.Error
|
||||
// }
|
||||
func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrMsg, error) {
|
||||
func (c *Client) XfrReceive(q *Msg, a string) (chan *Envelope, error) {
|
||||
w := new(reply)
|
||||
w.client = c
|
||||
w.addr = a
|
||||
|
@ -31,7 +31,7 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrMsg, error) {
|
|||
if err := w.send(q); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
e := make(chan *XfrMsg)
|
||||
e := make(chan *Envelope)
|
||||
switch q.Question[0].Qtype {
|
||||
case TypeAXFR:
|
||||
go w.axfrReceive(q, e)
|
||||
|
@ -45,23 +45,23 @@ func (c *Client) XfrReceive(q *Msg, a string) (chan *XfrMsg, error) {
|
|||
panic("dns: not reached")
|
||||
}
|
||||
|
||||
func (w *reply) axfrReceive(q *Msg, c chan *XfrMsg) {
|
||||
func (w *reply) axfrReceive(q *Msg, c chan *Envelope) {
|
||||
first := true
|
||||
defer w.conn.Close()
|
||||
defer close(c)
|
||||
for {
|
||||
in, err := w.receive()
|
||||
if err != nil {
|
||||
c <- &XfrMsg{nil, err}
|
||||
c <- &Envelope{nil, err}
|
||||
return
|
||||
}
|
||||
if in.Id != q.Id {
|
||||
c <- &XfrMsg{in.Answer, ErrId}
|
||||
c <- &Envelope{in.Answer, ErrId}
|
||||
return
|
||||
}
|
||||
if first {
|
||||
if !checkXfrSOA(in, true) {
|
||||
c <- &XfrMsg{in.Answer, ErrSoa}
|
||||
c <- &Envelope{in.Answer, ErrSoa}
|
||||
return
|
||||
}
|
||||
first = !first
|
||||
|
@ -70,16 +70,16 @@ func (w *reply) axfrReceive(q *Msg, c chan *XfrMsg) {
|
|||
if !first {
|
||||
w.tsigTimersOnly = true // Subsequent envelopes use this.
|
||||
if checkXfrSOA(in, false) {
|
||||
c <- &XfrMsg{in.Answer, nil}
|
||||
c <- &Envelope{in.Answer, nil}
|
||||
return
|
||||
}
|
||||
c <- &XfrMsg{in.Answer, nil}
|
||||
c <- &Envelope{in.Answer, nil}
|
||||
}
|
||||
}
|
||||
panic("dns: not reached")
|
||||
}
|
||||
|
||||
func (w *reply) ixfrReceive(q *Msg, c chan *XfrMsg) {
|
||||
func (w *reply) ixfrReceive(q *Msg, c chan *Envelope) {
|
||||
var serial uint32 // The first serial seen is the current server serial
|
||||
first := true
|
||||
defer w.conn.Close()
|
||||
|
@ -87,23 +87,23 @@ func (w *reply) ixfrReceive(q *Msg, c chan *XfrMsg) {
|
|||
for {
|
||||
in, err := w.receive()
|
||||
if err != nil {
|
||||
c <- &XfrMsg{in.Answer, err}
|
||||
c <- &Envelope{in.Answer, err}
|
||||
return
|
||||
}
|
||||
if q.Id != in.Id {
|
||||
c <- &XfrMsg{in.Answer, ErrId}
|
||||
c <- &Envelope{in.Answer, ErrId}
|
||||
return
|
||||
}
|
||||
if first {
|
||||
// A single SOA RR signals "no changes"
|
||||
if len(in.Answer) == 1 && checkXfrSOA(in, true) {
|
||||
c <- &XfrMsg{in.Answer, nil}
|
||||
c <- &Envelope{in.Answer, nil}
|
||||
return
|
||||
}
|
||||
|
||||
// Check if the returned answer is ok
|
||||
if !checkXfrSOA(in, true) {
|
||||
c <- &XfrMsg{in.Answer, ErrSoa}
|
||||
c <- &Envelope{in.Answer, ErrSoa}
|
||||
return
|
||||
}
|
||||
// This serial is important
|
||||
|
@ -117,11 +117,11 @@ func (w *reply) ixfrReceive(q *Msg, c chan *XfrMsg) {
|
|||
// 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.Serial == serial {
|
||||
c <- &XfrMsg{in.Answer, nil}
|
||||
c <- &Envelope{in.Answer, nil}
|
||||
return
|
||||
}
|
||||
}
|
||||
c <- &XfrMsg{in.Answer, nil}
|
||||
c <- &Envelope{in.Answer, nil}
|
||||
}
|
||||
}
|
||||
panic("dns: not reached")
|
||||
|
@ -143,7 +143,7 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
|||
|
||||
// XfrSend performs an outgoing [AI]xfr depending on the request message. The
|
||||
// caller is responsible for sending the correct sequence of RR sets through
|
||||
// the channel c. For reasons of symmetry XfrMsg is re-used.
|
||||
// the channel c. For reasons of symmetry Envelope is re-used.
|
||||
// Errors are signaled via the error pointer, when an error occurs the function
|
||||
// sets the error and returns (it does not close the channel).
|
||||
// TSIG and enveloping is handled by XfrSend.
|
||||
|
@ -151,19 +151,19 @@ func checkXfrSOA(in *Msg, first bool) bool {
|
|||
// Basic use pattern for sending an AXFR:
|
||||
//
|
||||
// // q contains the AXFR request
|
||||
// c := make(chan *XfrMsg)
|
||||
// c := make(chan *Envelope)
|
||||
// var e *error
|
||||
// err := XfrSend(w, q, c, e)
|
||||
// w.Hijack() // hijack the connection so that the library doesn't close it
|
||||
// for _, rrset := range rrsets { // rrset is a []RR
|
||||
// c <- &{XfrMsg{RR: rrset}
|
||||
// c <- &{Envelope{RR: rrset}
|
||||
// if e != nil {
|
||||
// close(c)
|
||||
// break
|
||||
// }
|
||||
// }
|
||||
// // w.Close() // Don't! Let the client close the connection
|
||||
func XfrSend(w ResponseWriter, q *Msg, c chan *XfrMsg, e *error) error {
|
||||
func XfrSend(w ResponseWriter, q *Msg, c chan *Envelope, e *error) error {
|
||||
switch q.Question[0].Qtype {
|
||||
case TypeAXFR, TypeIXFR:
|
||||
go axfrSend(w, q, c, e)
|
||||
|
@ -175,7 +175,7 @@ func XfrSend(w ResponseWriter, q *Msg, c chan *XfrMsg, e *error) error {
|
|||
}
|
||||
|
||||
// TODO(mg): count the RRs and the resulting size.
|
||||
func axfrSend(w ResponseWriter, req *Msg, c chan *XfrMsg, e *error) {
|
||||
func axfrSend(w ResponseWriter, req *Msg, c chan *Envelope, e *error) {
|
||||
rep := new(Msg)
|
||||
rep.SetReply(req)
|
||||
rep.Authoritative = true
|
||||
|
|
Loading…
Reference in New Issue