mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-06-27 05:34:15 +00:00
Refine DNS strategies
This commit is contained in:
parent
f4a048aa0c
commit
726a722019
21 changed files with 255 additions and 208 deletions
|
@ -37,8 +37,6 @@ type ownLinkVerifier interface {
|
|||
|
||||
type Handler struct {
|
||||
client dns.Client
|
||||
ipv4Lookup dns.IPv4Lookup
|
||||
ipv6Lookup dns.IPv6Lookup
|
||||
ownLinkVerifier ownLinkVerifier
|
||||
server net.Destination
|
||||
}
|
||||
|
@ -46,18 +44,6 @@ type Handler struct {
|
|||
func (h *Handler) Init(config *Config, dnsClient dns.Client) error {
|
||||
h.client = dnsClient
|
||||
|
||||
if ipv4lookup, ok := dnsClient.(dns.IPv4Lookup); ok {
|
||||
h.ipv4Lookup = ipv4lookup
|
||||
} else {
|
||||
return newError("dns.Client doesn't implement IPv4Lookup")
|
||||
}
|
||||
|
||||
if ipv6lookup, ok := dnsClient.(dns.IPv6Lookup); ok {
|
||||
h.ipv6Lookup = ipv6lookup
|
||||
} else {
|
||||
return newError("dns.Client doesn't implement IPv6Lookup")
|
||||
}
|
||||
|
||||
if v, ok := dnsClient.(ownLinkVerifier); ok {
|
||||
h.ownLinkVerifier = v
|
||||
}
|
||||
|
@ -213,21 +199,18 @@ func (h *Handler) handleIPQuery(id uint16, qType dnsmessage.Type, domain string,
|
|||
var err error
|
||||
|
||||
var ttl uint32 = 600
|
||||
|
||||
// Do NOT skip FakeDNS
|
||||
if c, ok := h.client.(dns.ClientWithIPOption); ok {
|
||||
c.SetFakeDNSOption(true)
|
||||
} else {
|
||||
newError("dns.Client doesn't implement ClientWithIPOption")
|
||||
}
|
||||
var opt = dns.LookupIP
|
||||
|
||||
switch qType {
|
||||
case dnsmessage.TypeA:
|
||||
ips, err = h.ipv4Lookup.LookupIPv4(domain)
|
||||
opt = dns.LookupIPv4
|
||||
case dnsmessage.TypeAAAA:
|
||||
ips, err = h.ipv6Lookup.LookupIPv6(domain)
|
||||
opt = dns.LookupIPv6
|
||||
}
|
||||
|
||||
opt.FakeEnable = true
|
||||
|
||||
ips, err = h.client.LookupOptions(domain, opt)
|
||||
rcode := dns.RCodeFromError(err)
|
||||
if rcode == 0 && len(ips) == 0 && err != dns.ErrEmptyResponse {
|
||||
newError("ip query").Base(err).WriteToLog()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue