Adapt for CloudFlare DNS service

This commit is contained in:
Star Brilliant
2018-04-01 22:57:18 +08:00
parent 68c3f30d14
commit 8b45c99dfc
4 changed files with 12 additions and 8 deletions

View File

@@ -178,21 +178,21 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
requestType := ""
if len(c.conf.UpstreamIETF) == 0 {
requestType = "application/x-www-form-urlencoded"
requestType = "application/dns-json"
} else if len(c.conf.UpstreamGoogle) == 0 {
requestType = "application/dns-udpwireformat"
} else {
numServers := len(c.conf.UpstreamGoogle) + len(c.conf.UpstreamIETF)
random := rand.Intn(numServers)
if random < len(c.conf.UpstreamGoogle) {
requestType = "application/x-www-form-urlencoded"
requestType = "application/dns-json"
} else {
requestType = "application/dns-udpwireformat"
}
}
var req *DNSRequest
if requestType == "application/x-www-form-urlencoded" {
if requestType == "application/dns-json" {
req = c.generateRequestGoogle(w, r, isTCP)
} else if requestType == "application/dns-udpwireformat" {
req = c.generateRequestIETF(w, r, isTCP)
@@ -211,7 +211,7 @@ func (c *Client) handlerFunc(w dns.ResponseWriter, r *dns.Msg, isTCP bool) {
} else if candidateType == "application/dns-udpwireformat" {
contentType = "application/dns-udpwireformat"
} else {
if requestType == "application/x-www-form-urlencoded" {
if requestType == "application/dns-json" {
contentType = "application/json"
} else if requestType == "application/dns-udpwireformat" {
contentType = "application/dns-udpwireformat"

View File

@@ -5,9 +5,11 @@ listen = "127.0.0.1:53"
# If multiple servers are specified, a random one will be chosen each time.
upstream_google = [
"https://dns.google.com/resolve",
#"https://cloudflare-dns.com/dns-query",
]
upstream_ietf = [
#"https://dns.google.com/experimental",
#"https://cloudflare-dns.com/dns-query",
]
# Bootstrap DNS server to resolve the address of the upstream resolver
@@ -16,6 +18,8 @@ upstream_ietf = [
bootstrap = [
"8.8.8.8:53",
"8.8.4.4:53",
#"1.1.1.1:53",
#"1.0.0.1:53",
]
# Timeout for upstream request

View File

@@ -66,7 +66,7 @@ func (c *Client) generateRequestGoogle(w dns.ResponseWriter, r *dns.Msg, isTCP b
numServers := len(c.conf.UpstreamGoogle)
upstream := c.conf.UpstreamGoogle[rand.Intn(numServers)]
requestURL := fmt.Sprintf("%s?name=%s&type=%s", upstream, url.QueryEscape(questionName), url.QueryEscape(questionType))
requestURL := fmt.Sprintf("%s?ct=application/dns-json&name=%s&type=%s", upstream, url.QueryEscape(questionName), url.QueryEscape(questionType))
if r.CheckingDisabled {
requestURL += "&cd=1"

View File

@@ -96,7 +96,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
if contentType == "" {
// Guess request Content-Type based on other parameters
if r.FormValue("name") != "" {
contentType = "application/x-www-form-urlencoded"
contentType = "application/dns-json"
} else if r.FormValue("dns") != "" {
contentType = "application/dns-udpwireformat"
}
@@ -114,7 +114,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
}
if responseType == "" {
// Guess response Content-Type based on request Content-Type
if contentType == "application/x-www-form-urlencoded" {
if contentType == "application/dns-json" {
responseType = "application/json"
} else if contentType == "application/dns-udpwireformat" {
responseType = "application/dns-udpwireformat"
@@ -122,7 +122,7 @@ func (s *Server) handlerFunc(w http.ResponseWriter, r *http.Request) {
}
var req *DNSRequest
if contentType == "application/x-www-form-urlencoded" {
if contentType == "application/dns-json" {
req = s.parseRequestGoogle(w, r)
} else if contentType == "application/dns-udpwireformat" {
req = s.parseRequestIETF(w, r)