mirror of
https://github.com/m13253/dns-over-https.git
synced 2026-03-30 03:10:24 +00:00
Print upstream information if error happens
This commit is contained in:
@@ -58,6 +58,7 @@ type DNSRequest struct {
|
||||
udpSize uint16
|
||||
ednsClientAddress net.IP
|
||||
ednsClientNetmask uint8
|
||||
currentUpstream string
|
||||
err error
|
||||
}
|
||||
|
||||
|
||||
@@ -115,12 +115,13 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) parseResponseGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP bool, req *DNSRequest) {
|
||||
if req.response.StatusCode != 200 {
|
||||
log.Printf("HTTP error: %s\n", req.response.Status)
|
||||
log.Printf("HTTP error from upstream %s: %s\n", req.currentUpstream, req.response.Status)
|
||||
req.reply.Rcode = dns.RcodeServerFailure
|
||||
contentType := req.response.Header.Get("Content-Type")
|
||||
if contentType != "application/json" && !strings.HasPrefix(contentType, "application/json;") {
|
||||
|
||||
@@ -175,12 +175,13 @@ func (c *Client) generateRequestIETF(w dns.ResponseWriter, r *dns.Msg, isTCP boo
|
||||
udpSize: udpSize,
|
||||
ednsClientAddress: ednsClientAddress,
|
||||
ednsClientNetmask: ednsClientNetmask,
|
||||
currentUpstream: upstream,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Client) parseResponseIETF(w dns.ResponseWriter, r *dns.Msg, isTCP bool, req *DNSRequest) {
|
||||
if req.response.StatusCode != 200 {
|
||||
log.Printf("HTTP error: %s\n", req.response.Status)
|
||||
log.Printf("HTTP error from upstream %s: %s\n", req.currentUpstream, req.response.Status)
|
||||
req.reply.Rcode = dns.RcodeServerFailure
|
||||
contentType := req.response.Header.Get("Content-Type")
|
||||
if contentType != "application/dns-message" && !strings.HasPrefix(contentType, "application/dns-message;") {
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
VERSION = "1.3.6"
|
||||
VERSION = "1.3.7"
|
||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||
)
|
||||
|
||||
@@ -46,11 +46,12 @@ type Server struct {
|
||||
}
|
||||
|
||||
type DNSRequest struct {
|
||||
request *dns.Msg
|
||||
response *dns.Msg
|
||||
isTailored bool
|
||||
errcode int
|
||||
errtext string
|
||||
request *dns.Msg
|
||||
response *dns.Msg
|
||||
currentUpstream string
|
||||
isTailored bool
|
||||
errcode int
|
||||
errtext string
|
||||
}
|
||||
|
||||
func NewServer(conf *config) (s *Server) {
|
||||
@@ -164,7 +165,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
var err error
|
||||
req.response, err = s.doDNSQuery(req.request)
|
||||
req, err = s.doDNSQuery(req)
|
||||
if err != nil {
|
||||
jsonDNS.FormatError(w, fmt.Sprintf("DNS query failure (%s)", err.Error()), 503)
|
||||
return
|
||||
@@ -208,23 +209,23 @@ func (s *Server) findClientIP(r *http.Request) net.IP {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Server) doDNSQuery(msg *dns.Msg) (resp *dns.Msg, err error) {
|
||||
func (s *Server) doDNSQuery(req *DNSRequest) (resp *DNSRequest, err error) {
|
||||
numServers := len(s.conf.Upstream)
|
||||
for i := uint(0); i < s.conf.Tries; i++ {
|
||||
server := s.conf.Upstream[rand.Intn(numServers)]
|
||||
req.currentUpstream = s.conf.Upstream[rand.Intn(numServers)]
|
||||
if !s.conf.TCPOnly {
|
||||
resp, _, err = s.udpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.udpClient.Exchange(req.request, req.currentUpstream)
|
||||
if err == dns.ErrTruncated {
|
||||
log.Println(err)
|
||||
resp, _, err = s.tcpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||
}
|
||||
} else {
|
||||
resp, _, err = s.tcpClient.Exchange(msg, server)
|
||||
req.response, _, err = s.tcpClient.Exchange(req.request, req.currentUpstream)
|
||||
}
|
||||
if err == nil {
|
||||
return
|
||||
return req, nil
|
||||
}
|
||||
log.Println(err)
|
||||
log.Printf("DNS error from upstream %s: %s\n", req.currentUpstream, err.Error())
|
||||
}
|
||||
return
|
||||
return req, err
|
||||
}
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
package main
|
||||
|
||||
const (
|
||||
VERSION = "1.3.6"
|
||||
VERSION = "1.3.7"
|
||||
USER_AGENT = "DNS-over-HTTPS/" + VERSION + " (+https://github.com/m13253/dns-over-https)"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user