1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Fix a panic in handling forwarded queries

Signed-off-by: Santhosh Manohar <santhosh@docker.com>
This commit is contained in:
Santhosh Manohar 2016-04-15 23:12:27 -07:00
parent 5108711b88
commit 6a96717344

View file

@ -305,6 +305,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
extConn net.Conn extConn net.Conn
resp *dns.Msg resp *dns.Msg
err error err error
writer dns.ResponseWriter
) )
if query == nil || len(query.Question) == 0 { if query == nil || len(query.Question) == 0 {
@ -342,7 +343,9 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
if resp.Len() > maxSize { if resp.Len() > maxSize {
truncateResp(resp, maxSize, proto == "tcp") truncateResp(resp, maxSize, proto == "tcp")
} }
writer = w
} else { } else {
queryID := query.Id
for i := 0; i < maxExtDNS; i++ { for i := 0; i < maxExtDNS; i++ {
extDNS := &r.extDNSList[i] extDNS := &r.extDNSList[i]
if extDNS.ipStr == "" { if extDNS.ipStr == "" {
@ -388,7 +391,7 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// forwardQueryStart stores required context to mux multiple client queries over // forwardQueryStart stores required context to mux multiple client queries over
// one connection; and limits the number of outstanding concurrent queries. // one connection; and limits the number of outstanding concurrent queries.
if r.forwardQueryStart(w, query) == false { if r.forwardQueryStart(w, query, queryID) == false {
old := r.tStamp old := r.tStamp
r.tStamp = time.Now() r.tStamp = time.Now()
if r.tStamp.Sub(old) > logInterval { if r.tStamp.Sub(old) > logInterval {
@ -418,32 +421,33 @@ func (r *resolver) ServeDNS(w dns.ResponseWriter, query *dns.Msg) {
// Retrieves the context for the forwarded query and returns the client connection // Retrieves the context for the forwarded query and returns the client connection
// to send the reply to // to send the reply to
w = r.forwardQueryEnd(w, resp) writer = r.forwardQueryEnd(w, resp)
if w == nil { if writer == nil {
continue continue
} }
resp.Compress = true resp.Compress = true
break break
} }
if resp == nil || writer == nil {
if resp == nil || w == nil {
return return
} }
} }
err = w.WriteMsg(resp) if writer == nil {
if err != nil { return
}
if err = writer.WriteMsg(resp); err != nil {
log.Errorf("error writing resolver resp, %s", err) log.Errorf("error writing resolver resp, %s", err)
} }
} }
func (r *resolver) forwardQueryStart(w dns.ResponseWriter, msg *dns.Msg) bool { func (r *resolver) forwardQueryStart(w dns.ResponseWriter, msg *dns.Msg, queryID uint16) bool {
proto := w.LocalAddr().Network() proto := w.LocalAddr().Network()
dnsID := uint16(rand.Intn(maxDNSID)) dnsID := uint16(rand.Intn(maxDNSID))
cc := clientConn{ cc := clientConn{
dnsID: msg.Id, dnsID: queryID,
respWriter: w, respWriter: w,
} }