Fix #706 -- rDNS for DOH/DOT clients
This commit is contained in:
parent
3454bf9243
commit
a3b8d4d923
14
dns.go
14
dns.go
|
@ -154,10 +154,18 @@ func asyncRDNSLoop() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func onDNSRequest(d *proxy.DNSContext) {
|
func onDNSRequest(d *proxy.DNSContext) {
|
||||||
if d.Req.Question[0].Qtype == dns.TypeA {
|
qType := d.Req.Question[0].Qtype
|
||||||
ip, _, _ := net.SplitHostPort(d.Addr.String())
|
if qType != dns.TypeA && qType != dns.TypeAAAA {
|
||||||
beginAsyncRDNS(ip)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ip := dnsforward.GetIPString(d.Addr)
|
||||||
|
if ip == "" {
|
||||||
|
// This would be quite weird if we get here
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
beginAsyncRDNS(ip)
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateServerConfig() dnsforward.ServerConfig {
|
func generateServerConfig() dnsforward.ServerConfig {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
func TestResolveRDNS(t *testing.T) {
|
func TestResolveRDNS(t *testing.T) {
|
||||||
config.DNS.BindHost = "1.1.1.1"
|
config.DNS.BindHost = "1.1.1.1"
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package dnsforward
|
||||||
|
|
||||||
|
import "net"
|
||||||
|
|
||||||
|
// GetIPString is a helper function that extracts IP address from net.Addr
|
||||||
|
func GetIPString(addr net.Addr) string {
|
||||||
|
switch addr := addr.(type) {
|
||||||
|
case *net.UDPAddr:
|
||||||
|
return addr.IP.String()
|
||||||
|
case *net.TCPAddr:
|
||||||
|
return addr.IP.String()
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
|
@ -61,7 +61,7 @@ func (l *queryLog) logRequest(question *dns.Msg, answer *dns.Msg, result *dnsfil
|
||||||
var q []byte
|
var q []byte
|
||||||
var a []byte
|
var a []byte
|
||||||
var err error
|
var err error
|
||||||
ip := getIPString(addr)
|
ip := GetIPString(addr)
|
||||||
|
|
||||||
if question != nil {
|
if question != nil {
|
||||||
q, err = question.Pack()
|
q, err = question.Pack()
|
||||||
|
@ -244,14 +244,3 @@ func answerToMap(a *dns.Msg) []map[string]interface{} {
|
||||||
|
|
||||||
return answers
|
return answers
|
||||||
}
|
}
|
||||||
|
|
||||||
// getIPString is a helper function that extracts IP address from net.Addr
|
|
||||||
func getIPString(addr net.Addr) string {
|
|
||||||
switch addr := addr.(type) {
|
|
||||||
case *net.UDPAddr:
|
|
||||||
return addr.IP.String()
|
|
||||||
case *net.TCPAddr:
|
|
||||||
return addr.IP.String()
|
|
||||||
}
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue